Changeset 6958 for extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo
- Timestamp:
- Sep 19, 2010, 1:33:27 AM (14 years ago)
- Location:
- extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/util/ImagesUtil.java
r6821 r6958 1 1 package fr.mael.jiwigo.transverse.util; 2 2 3 import java.awt.Graphics; 3 4 import java.awt.Graphics2D; 4 5 import java.awt.GraphicsConfiguration; 5 6 import java.awt.GraphicsDevice; 6 7 import java.awt.GraphicsEnvironment; 8 import java.awt.HeadlessException; 7 9 import java.awt.Image; 8 10 import java.awt.RenderingHints; 11 import java.awt.Transparency; 9 12 import java.awt.image.BufferedImage; 13 import java.awt.image.ColorModel; 14 import java.awt.image.PixelGrabber; 10 15 import java.io.BufferedInputStream; 11 16 import java.io.File; 12 17 import java.io.FileInputStream; 13 import java.io.File OutputStream;18 import java.io.FileNotFoundException; 14 19 import java.io.IOException; 15 20 import java.io.InputStream; 16 21 import java.util.Iterator; 22 23 import javax.imageio.IIOImage; 17 24 import javax.imageio.ImageIO; 25 import javax.imageio.ImageWriteParam; 26 import javax.imageio.ImageWriter; 27 import javax.imageio.stream.FileImageOutputStream; 28 import javax.swing.ImageIcon; 18 29 19 30 /** … … 123 134 graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 124 135 graphics2D.drawImage(image, 0, 0, width, height, null); 125 ImageIO.write(thumbImage, "jpg", new FileOutputStream(System.getProperty("java.io.tmpdir") + "/" + tempName)); 136 137 // ImageIO.write(thumbImage, "jpg", new FileOutputStream(System.getProperty("java.io.tmpdir") + "/" + tempName)); 138 saveImage(System.getProperty("java.io.tmpdir") + "/" + tempName, thumbImage); 126 139 return true; 127 140 128 141 } 142 143 private static void saveImage(String fileName, BufferedImage img) throws FileNotFoundException, IOException { 144 Iterator iter = ImageIO.getImageWritersByFormatName("jpeg"); 145 ImageWriter writer = (ImageWriter) iter.next(); 146 ImageWriteParam iwp = writer.getDefaultWriteParam(); 147 iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); 148 iwp.setCompressionQuality(1); 149 File outputfile = new File(fileName); 150 FileImageOutputStream output = new FileImageOutputStream(outputfile); 151 writer.setOutput(output); 152 IIOImage outimage = new IIOImage(img, null, null); 153 writer.write(null, outimage, iwp); 154 writer.dispose(); 155 } 156 157 // This method returns a buffered image with the contents of an image 158 public static BufferedImage toBufferedImage(Image image) { 159 if (image instanceof BufferedImage) { 160 return (BufferedImage) image; 161 } 162 163 // This code ensures that all the pixels in the image are loaded 164 image = new ImageIcon(image).getImage(); 165 166 // Determine if the image has transparent pixels; for this method's 167 // implementation, see Determining If an Image Has Transparent Pixels 168 boolean hasAlpha = hasAlpha(image); 169 170 // Create a buffered image with a format that's compatible with the screen 171 BufferedImage bimage = null; 172 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 173 try { 174 // Determine the type of transparency of the new buffered image 175 int transparency = Transparency.OPAQUE; 176 if (hasAlpha) { 177 transparency = Transparency.BITMASK; 178 } 179 180 // Create the buffered image 181 GraphicsDevice gs = ge.getDefaultScreenDevice(); 182 GraphicsConfiguration gc = gs.getDefaultConfiguration(); 183 bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency); 184 } catch (HeadlessException e) { 185 // The system does not have a screen 186 } 187 188 if (bimage == null) { 189 // Create a buffered image using the default color model 190 int type = BufferedImage.TYPE_INT_RGB; 191 if (hasAlpha) { 192 type = BufferedImage.TYPE_INT_ARGB; 193 } 194 bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); 195 } 196 197 // Copy image to buffered image 198 Graphics g = bimage.createGraphics(); 199 200 // Paint the image onto the buffered image 201 g.drawImage(image, 0, 0, null); 202 g.dispose(); 203 204 return bimage; 205 } 206 207 // This method returns true if the specified image has transparent pixels 208 public static boolean hasAlpha(Image image) { 209 // If buffered image, the color model is readily available 210 if (image instanceof BufferedImage) { 211 BufferedImage bimage = (BufferedImage) image; 212 return bimage.getColorModel().hasAlpha(); 213 } 214 215 // Use a pixel grabber to retrieve the image's color model; 216 // grabbing a single pixel is usually sufficient 217 PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); 218 try { 219 pg.grabPixels(); 220 } catch (InterruptedException e) { 221 } 222 223 // Get the image's color model 224 ColorModel cm = pg.getColorModel(); 225 return cm.hasAlpha(); 226 } 227 129 228 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/util/Outil.java
r6840 r6958 105 105 public static Document stringToDocument(String string) throws JDOMException, IOException { 106 106 SAXBuilder sb = new SAXBuilder(); 107 System.out.println(string); 107 108 Document doc = sb.build(new StringReader(string)); 108 109 return doc; -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/ImagesManagement.java
r6821 r6958 75 75 */ 76 76 public static Image getCurrentImage() { 77 return LIST_IMAGE.get(CURRENT_IMAGE_INDEX); 77 //return LIST_IMAGE.get(CURRENT_IMAGE_INDEX); 78 return CURRENT_IMAGE; 78 79 } 79 80 -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/browser/BrowserFrame.java
r6831 r6958 104 104 105 105 /** 106 * rogner l'image 107 */ 108 private JButton cut = new JButton(); 109 110 /** 106 111 * Panel qui contient l'image 107 112 */ … … 137 142 save.setIcon(new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/save.png"))); 138 143 comment.setIcon(new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/comment.png"))); 144 cut.setIcon(new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/cut.png"))); 139 145 //on rend les boutons invisibles, pour ne voir que l'image 140 146 next.setFocusPainted(false); … … 156 162 comment.setBorderPainted(false); 157 163 comment.setContentAreaFilled(false); 164 cut.setFocusPainted(false); 165 cut.setBorderPainted(false); 166 cut.setContentAreaFilled(false); 158 167 //ajout des action listeners 159 168 comment.addActionListener(this); … … 163 172 previous.addActionListener(this); 164 173 next.addActionListener(this); 174 cut.addActionListener(this); 165 175 //ajout des boutons 166 176 panelBoutons.add(previous); … … 168 178 panelBoutons.add(rotateLeft); 169 179 panelBoutons.add(rotateRight); 180 panelBoutons.add(cut); 170 181 panelBoutons.add(save); 171 182 panelBoutons.add(comment); … … 368 379 } else if (e.getSource().equals(menuItemNormal)) { 369 380 imagePanel.zoomNormal(); 381 } else if (e.getSource().equals(cut)) { 382 imagePanel.rogner(); 370 383 } 371 384 -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/browser/BrowserImagePanel.java
r6833 r6958 5 5 import java.awt.Graphics2D; 6 6 import java.awt.RenderingHints; 7 import java.awt.event.MouseEvent; 8 import java.awt.event.MouseListener; 9 import java.awt.event.MouseMotionListener; 7 10 import java.awt.event.MouseWheelEvent; 8 11 import java.awt.event.MouseWheelListener; … … 15 18 16 19 import javax.swing.JLabel; 20 import javax.swing.JOptionPane; 17 21 import javax.swing.JPanel; 18 22 import javax.swing.JSlider; … … 21 25 22 26 import fr.mael.jiwigo.transverse.util.ImagesUtil; 27 import fr.mael.jiwigo.transverse.util.Messages; 23 28 24 29 /** … … 52 57 * 53 58 */ 54 public class BrowserImagePanel extends JPanel implements MouseWheelListener, Printable { 59 public class BrowserImagePanel extends JPanel implements MouseWheelListener, Printable, MouseMotionListener, 60 MouseListener { 55 61 private BufferedImage image; 56 62 private double scale = 1.0; … … 58 64 boolean flipV = false; 59 65 private int valueSlider = 16; 66 private boolean clicked = false; 67 private int xTopPosition; 68 private int yTopPosition; 69 private int xDragPosition; 70 private int yDragPosition; 71 private boolean drawSelection = false; 60 72 61 73 /** … … 66 78 this.image = image; 67 79 this.addMouseWheelListener(this); 80 this.addMouseMotionListener(this); 81 this.addMouseListener(this); 68 82 } 69 83 … … 90 104 at.scale(scale, scale); 91 105 } 92 93 106 g2.drawRenderedImage(image, at); 107 if (drawSelection) { 108 g2.drawRect(xTopPosition, yTopPosition, xDragPosition - xTopPosition, yDragPosition - yTopPosition); 109 } 94 110 95 111 } … … 102 118 int h = (int) (scale * image.getHeight()); 103 119 return new Dimension(w, h); 120 } 121 122 public void rogner() { 123 if (scale == 1.0) { 124 //récupération des dimensions de l'image 125 Double width = getSize().getWidth(); 126 Double height = getSize().getHeight(); 127 //recuperation du coin haut gauche de l'image 128 Double xZeroImage = ((width - image.getWidth()) / 2); 129 Double yZeroImage = ((height - image.getHeight()) / 2); 130 //les positions du premier clic 131 //sur l'image. Les positions récupérées précédemment étaient 132 //les positions sur le panel, il faut donc calculer les positions sur l'image 133 int positionX, positionY; 134 //largeur et longueur du rognage sur l'image 135 int largeur, longueur; 136 //si jamais la sélection commence avant le début de l'image 137 //en x, on prend comme position 0, sinon, on calcule la position 138 //du clic selon le calcul position sur l'image = position sur le panel - position du x de l'image 139 if (xTopPosition - xZeroImage.intValue() < 0) { 140 positionX = 0; 141 } else { 142 positionX = xTopPosition - xZeroImage.intValue(); 143 } 144 //si jamais la sélection commence avant le début de l'image 145 //en y, on prend comme position 0, sinon, on calcule la position 146 //du clic selon le calcul position sur l'image = position sur le panel - position du y de l'image 147 if (yTopPosition - yZeroImage.intValue() < 0) { 148 positionY = 0; 149 } else { 150 positionY = yTopPosition - yZeroImage.intValue(); 151 } 152 //on calcule la largeur 153 largeur = xDragPosition - xTopPosition; 154 //si ça dépasse de l'image 155 if ((positionX + largeur) > image.getWidth()) { 156 //on recalcule la largeur 157 largeur = image.getWidth() - positionX; 158 } 159 //on calcule la longueur 160 longueur = yDragPosition - yTopPosition; 161 //si ça dépasse en hauteur 162 if ((positionY + longueur) > image.getHeight()) { 163 //on recalcule la hauteur 164 longueur = image.getHeight() - positionY; 165 } 166 //recuperation de l'image coupée 167 image = image.getSubimage(positionX, positionY, largeur, longueur); 168 repaint(); 169 revalidate(); 170 drawSelection = false; 171 } else { 172 JOptionPane.showMessageDialog(this, Messages.getMessage("clippingError"), Messages.getMessage("info"), 173 JOptionPane.INFORMATION_MESSAGE); 174 } 104 175 } 105 176 … … 237 308 } 238 309 310 @Override 311 public void mouseDragged(MouseEvent arg0) { 312 if (clicked) { 313 xDragPosition = arg0.getX(); 314 yDragPosition = arg0.getY(); 315 repaint(); 316 revalidate(); 317 } 318 } 319 320 @Override 321 public void mouseMoved(MouseEvent arg0) { 322 } 323 324 public void mouseClicked(MouseEvent arg0) { 325 } 326 327 public void mouseEntered(MouseEvent arg0) { 328 } 329 330 public void mouseExited(MouseEvent arg0) { 331 } 332 333 public void mousePressed(MouseEvent arg0) { 334 clicked = true; 335 xTopPosition = arg0.getX(); 336 yTopPosition = arg0.getY(); 337 drawSelection = true; 338 } 339 340 public void mouseReleased(MouseEvent arg0) { 341 clicked = false; 342 } 343 239 344 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/CategoriesTree.java
r6831 r6958 124 124 Object catSelectionnee = node.getUserObject(); 125 125 Category category = (Category) catSelectionnee; 126 MainFrame.imagesPanel.rafraichir(category.getIdentifiant(), false); 126 //MainFrame.imagesPanel.rafraichir(category.getIdentifiant(), false); 127 MainFrame.getInstance().addTabb(new ThumbnailCategoryPanel(category)); 127 128 } 128 129 -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/MainFrame.java
r6833 r6958 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.ActionListener; 8 8 import java.util.HashMap; 9 10 import javax.swing.ImageIcon; 9 11 import javax.swing.JComponent; 10 12 import javax.swing.JFrame; … … 20 22 import fr.mael.jiwigo.transverse.util.Messages; 21 23 import fr.mael.jiwigo.transverse.util.Outil; 24 import fr.mael.jiwigo.ui.mainframe.tab.JTabbedPaneWithCloseIcons; 22 25 23 26 /** … … 100 103 private JProgressBar progressBar; 101 104 105 private JTabbedPaneWithCloseIcons tabbedPane; 106 107 private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>(); 108 102 109 /** 103 110 * @return le singleton … … 114 121 */ 115 122 private MainFrame() { 116 this.setTitle(" Piwigo v" + Messages.getMessage("version"));123 this.setTitle("Jiwigo v" + Messages.getMessage("version")); 117 124 this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png"))); 118 125 this.setLayout(new BorderLayout()); … … 122 129 categoriesTree = new CategoriesTree(); 123 130 splitPane.setLeftComponent(categoriesTree); 124 imagesPanel = new ThumbnailCategoryPanel(null); 125 reduceSizeOfComponent(imagesPanel); 126 scrollPaneImagesPanel = new JScrollPane(imagesPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 127 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 128 scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 700)); 129 splitPane.setRightComponent(scrollPaneImagesPanel); 130 131 this.add(splitPane, BorderLayout.WEST); 131 // imagesPanel = new ThumbnailCategoryPanel(null); 132 // reduceSizeOfComponent(imagesPanel); 133 // scrollPaneImagesPanel = new JScrollPane(imagesPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 134 // JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 135 // scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600)); 136 137 tabbedPane = new JTabbedPaneWithCloseIcons(); 138 // tabbedPane.add(scrollPaneImagesPanel); 139 splitPane.setRightComponent(tabbedPane); 140 141 this.add(splitPane, BorderLayout.CENTER); 132 142 JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 133 143 progressBar = new JProgressBar(0, 100); … … 143 153 this.setJMenuBar(jMenuBar); 144 154 this.add(panel, BorderLayout.SOUTH); 145 this.pack(); 155 // this.pack(); 156 this.setSize(900, 600); 146 157 this.setLocationRelativeTo(null); 147 158 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 148 this.setResizable(false); 159 this.setResizable(true); 160 } 161 162 public void addTabb(ThumbnailCategoryPanel panel) { 163 JScrollPane scrollPaneImagesPanel = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 164 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 165 scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600)); 166 boolean found = false; 167 for (int i = 0; i < tabbedPane.getTabCount(); i++) { 168 JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i); 169 ThumbnailCategoryPanel thumbPan = (ThumbnailCategoryPanel) scroll.getViewport().getComponents()[0]; 170 if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) { 171 tabbedPane.setSelectedIndex(i); 172 found = true; 173 break; 174 } 175 } 176 if (!found) { 177 tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel, new ImageIcon(Outil 178 .getURL("fr/mael/jiwigo/img/closetab.png"))); 179 } 180 181 // if (mapsIdPos.get(panel.getCategory().getIdentifiant()) == null) { 182 // tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel); 183 // mapsIdPos.put(panel.getCategory().getIdentifiant(), tabbedPane.getTabCount() - 1); 184 // } else { 185 // tabbedPane.setSelectedIndex(mapsIdPos.get(panel.getCategory().getIdentifiant())); 186 // } 187 149 188 } 150 189 … … 191 230 } 192 231 232 /** 233 * @return the mapsIdPos 234 */ 235 public HashMap<Integer, Integer> getMapsIdPos() { 236 return mapsIdPos; 237 } 238 193 239 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailCategoryPanel.java
r6839 r6958 7 7 import javax.swing.JPanel; 8 8 9 import fr.mael.jiwigo.om.Category; 9 10 import fr.mael.jiwigo.om.Image; 10 11 import fr.mael.jiwigo.service.ImageService; … … 54 55 */ 55 56 private Integer categoryId; 57 58 private Category category; 59 60 public ThumbnailCategoryPanel(Category category) { 61 this(category.getIdentifiant()); 62 this.category = category; 63 } 56 64 57 65 /** … … 111 119 public void setCategoryId(Integer categoryId) { 112 120 this.categoryId = categoryId; 121 } 122 123 /** 124 * @return the category 125 */ 126 public Category getCategory() { 127 return category; 128 } 129 130 /** 131 * @param category the category to set 132 */ 133 public void setCategory(Category category) { 134 this.category = category; 113 135 } 114 136 -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailPanel.java
r6833 r6958 94 94 new BrowserFrame(image); 95 95 } catch (Exception e) { 96 96 e.printStackTrace(); 97 97 } 98 98
Note: See TracChangeset
for help on using the changeset viewer.