Changeset 7221 for extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailPanel.java
- Timestamp:
- Oct 16, 2010, 1:08:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailPanel.java
r7070 r7221 14 14 import java.io.IOException; 15 15 import java.util.List; 16 17 16 import javax.swing.JButton; 18 17 import javax.swing.JDialog; … … 25 24 import javax.swing.JScrollPane; 26 25 import javax.swing.ListSelectionModel; 27 28 26 import fr.mael.jiwigo.om.Image; 29 27 import fr.mael.jiwigo.om.Tag; … … 34 32 import fr.mael.jiwigo.ui.browser.BrowserFrame; 35 33 import fr.mael.jiwigo.ui.layout.VerticalLayout; 34 36 35 37 36 /** … … 65 64 */ 66 65 public class ThumbnailPanel extends JLabel implements MouseListener, ActionListener { 67 /** 68 * Logger 69 */ 70 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory 71 .getLog(ThumbnailPanel.class); 72 /** 73 * the image 74 */ 75 private Image image; 76 77 /** 78 * Popup menu to edit images info 79 */ 80 private JMenuItem menuAjouterTag; 81 82 /** 83 * Button to add tags 84 */ 85 private JButton boutonOkAjouterTag; 86 87 /** 88 * List of tags 89 */ 90 private JList listTags; 91 92 /** 93 * Dialog that allows to choose tags 94 */ 95 private JDialog dialogChoixTags; 96 97 /** 98 * Constructeur 99 * @param image the image 100 * @param imagesPanel the panel 101 */ 102 public ThumbnailPanel(Image image) { 103 this.image = image; 104 setToolTipText("<html><center>" + image.getName() + "<br/>" + image.getVue() + " " 105 + Messages.getMessage("hits") + "</center></html>"); 106 this.addMouseListener(this); 107 } 108 109 protected void paintComponent(Graphics g) { 110 super.paintComponent(g); 111 Graphics2D g2 = (Graphics2D) g; 112 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 113 double x = (getWidth() * ImagesManagement.getMiniatureBufferedImage(image).getWidth()) / 2; 114 double y = (getHeight() * ImagesManagement.getMiniatureBufferedImage(image).getHeight()) / 2; 115 g2.drawRenderedImage(ImagesManagement.getMiniatureBufferedImage(image), null); 116 } 117 118 /* (non-Javadoc) 119 * @see javax.swing.JComponent#getPreferredSize() 120 */ 121 public Dimension getPreferredSize() { 122 int w = (int) (ImagesManagement.getMiniatureBufferedImage(image).getWidth()); 123 int h = (int) (ImagesManagement.getMiniatureBufferedImage(image).getHeight() + 10); 124 return new Dimension(w, h); 125 } 126 127 @Override 128 public void mouseClicked(MouseEvent paramMouseEvent) { 129 // on affiche l'image en grand 130 ImagesManagement.setCurrentImage(image); 131 try { 132 if (paramMouseEvent.getButton() == 1) { 133 new BrowserFrame(image); 134 } else if (paramMouseEvent.getButton() == 3) { 135 JPopupMenu popup = new JPopupMenu(); 136 menuAjouterTag = new JMenuItem(Messages.getMessage("thumbviewer_addTag")); 137 menuAjouterTag.addActionListener(this); 138 popup.add(menuAjouterTag); 139 popup.show(this, paramMouseEvent.getX(), paramMouseEvent.getY()); 140 } 141 } catch (Exception e) { 142 e.printStackTrace(); 143 } 144 145 } 146 147 @Override 148 public void mouseEntered(MouseEvent paramMouseEvent) { 149 this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 150 } 151 152 @Override 153 public void mouseExited(MouseEvent paramMouseEvent) { 154 } 155 156 @Override 157 public void mousePressed(MouseEvent paramMouseEvent) { 158 // TODO Auto-generated method stub 159 160 } 161 162 @Override 163 public void mouseReleased(MouseEvent paramMouseEvent) { 164 // TODO Auto-generated method stub 165 166 } 167 168 @Override 169 public void actionPerformed(ActionEvent arg0) { 170 if (arg0.getSource().equals(menuAjouterTag)) { 171 try { 172 //getting the list of tags 173 List<Tag> tagsDispo = TagService.getInstance().lister(); 174 //list to array (cause fucking JList does not support Lists) 175 Tag[] tableauTagDispo = (Tag[]) tagsDispo.toArray(new Tag[tagsDispo.size()]); 176 //getting the image's tags to preselect them 177 List<Tag> tagsDeLimage = TagService.getInstance().tagsForImage(image); 178 listTags = new JList(tableauTagDispo); 179 //multiple selection is allowed 180 listTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 181 listTags.setPreferredSize(new Dimension(100, 200)); 182 //construct an array of the indices to select in the jlist 183 int[] indices = new int[tagsDeLimage.size()]; 184 int compteur = 0; 185 for (int i = 0; i < tableauTagDispo.length; i++) { 186 for (Tag tag : tagsDeLimage) { 187 if (tag.getId().equals(tableauTagDispo[i].getId())) { 188 indices[compteur++] = i; 189 190 } 191 } 66 67 /** 68 * Logger 69 */ 70 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(ThumbnailPanel.class); 71 /** 72 * the image 73 */ 74 private Image image; 75 76 /** 77 * Popup menu to edit images info 78 */ 79 private JMenuItem menuAjouterTag; 80 81 /** 82 * Button to add tags 83 */ 84 private JButton boutonOkAjouterTag; 85 86 /** 87 * List of tags 88 */ 89 private JList listTags; 90 91 /** 92 * Dialog that allows to choose tags 93 */ 94 private JDialog dialogChoixTags; 95 96 97 /** 98 * Constructeur 99 * @param image the image 100 * @param imagesPanel the panel 101 */ 102 public ThumbnailPanel(Image image) { 103 this.image = image; 104 setToolTipText("<html><center>" + image.getName() + "<br/>" + image.getVue() + " " + Messages.getMessage("hits") 105 + "</center></html>"); 106 this.addMouseListener(this); 107 } 108 109 110 protected void paintComponent(Graphics g) { 111 super.paintComponent(g); 112 Graphics2D g2 = (Graphics2D) g; 113 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 114 double x = (getWidth() * ImagesManagement.getMiniatureBufferedImage(image).getWidth()) / 2; 115 double y = (getHeight() * ImagesManagement.getMiniatureBufferedImage(image).getHeight()) / 2; 116 g2.drawRenderedImage(ImagesManagement.getMiniatureBufferedImage(image), null); 117 } 118 119 120 /* (non-Javadoc) 121 * @see javax.swing.JComponent#getPreferredSize() 122 */ 123 public Dimension getPreferredSize() { 124 int w = (int) (ImagesManagement.getMiniatureBufferedImage(image).getWidth()); 125 int h = (int) (ImagesManagement.getMiniatureBufferedImage(image).getHeight() + 10); 126 return new Dimension(w, h); 127 } 128 129 130 @Override 131 public void mouseClicked(MouseEvent paramMouseEvent) { 132 // on affiche l'image en grand 133 ImagesManagement.setCurrentImage(image); 134 try { 135 if (paramMouseEvent.getButton() == 1) { 136 new BrowserFrame(image); 137 } else if (paramMouseEvent.getButton() == 3) { 138 JPopupMenu popup = new JPopupMenu(); 139 menuAjouterTag = new JMenuItem(Messages.getMessage("thumbviewer_addTag")); 140 menuAjouterTag.addActionListener(this); 141 popup.add(menuAjouterTag); 142 popup.show(this, paramMouseEvent.getX(), paramMouseEvent.getY()); 143 } 144 } catch (Exception e) { 145 e.printStackTrace(); 192 146 } 193 listTags.setSelectedIndices(indices); 194 195 JScrollPane scrollPane = new JScrollPane(listTags); 196 dialogChoixTags = new JDialog(); 197 dialogChoixTags.setLayout(new BorderLayout()); 198 JPanel panelNorth = new JPanel(new VerticalLayout()); 199 panelNorth.add(new JLabel(Messages.getMessage("thumbviewer_selectTag"))); 200 panelNorth.add(scrollPane); 201 dialogChoixTags.add(panelNorth, BorderLayout.NORTH); 202 JPanel panelBouton = new JPanel(new FlowLayout()); 203 boutonOkAjouterTag = new JButton("Ok"); 204 panelBouton.add(boutonOkAjouterTag); 205 boutonOkAjouterTag.addActionListener(this); 206 dialogChoixTags.add(panelBouton, BorderLayout.CENTER); 207 dialogChoixTags.setSize(new Dimension(400, 280)); 208 dialogChoixTags.setLocationRelativeTo(null); 209 dialogChoixTags.setVisible(true); 210 } catch (IOException e) { 211 e.printStackTrace(); 212 } 213 } else if (arg0.getSource().equals(boutonOkAjouterTag)) { 214 StringBuffer tagIds = new StringBuffer(""); 215 for (Object object : listTags.getSelectedValues()) { 216 Tag tag = (Tag) object; 217 tagIds.append(tag.getId() + ","); 218 } 219 tagIds.deleteCharAt(tagIds.lastIndexOf(",")); 220 try { 221 if (!ImageService.getInstance().addTags(image, tagIds.toString())) { 222 JOptionPane.showMessageDialog(this, Messages.getMessage("addingTagsError"), Messages 223 .getMessage("error"), JOptionPane.ERROR_MESSAGE); 224 } else { 225 dialogChoixTags.dispose(); 147 148 } 149 150 151 @Override 152 public void mouseEntered(MouseEvent paramMouseEvent) { 153 this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 154 } 155 156 157 @Override 158 public void mouseExited(MouseEvent paramMouseEvent) { 159 } 160 161 162 @Override 163 public void mousePressed(MouseEvent paramMouseEvent) { 164 // TODO Auto-generated method stub 165 166 } 167 168 169 @Override 170 public void mouseReleased(MouseEvent paramMouseEvent) { 171 // TODO Auto-generated method stub 172 173 } 174 175 176 @Override 177 public void actionPerformed(ActionEvent arg0) { 178 if (arg0.getSource().equals(menuAjouterTag)) { 179 try { 180 //getting the list of tags 181 List<Tag> tagsDispo = TagService.getInstance().lister(); 182 //list to array (cause fucking JList does not support Lists) 183 Tag[] tableauTagDispo = (Tag[]) tagsDispo.toArray(new Tag[tagsDispo.size()]); 184 //getting the image's tags to preselect them 185 List<Tag> tagsDeLimage = TagService.getInstance().tagsForImage(image); 186 listTags = new JList(tableauTagDispo); 187 //multiple selection is allowed 188 listTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 189 listTags.setPreferredSize(new Dimension(100, 200)); 190 //construct an array of the indices to select in the jlist 191 int[] indices = new int[tagsDeLimage.size()]; 192 int compteur = 0; 193 for (int i = 0; i < tableauTagDispo.length; i++) { 194 for (Tag tag : tagsDeLimage) { 195 if (tag.getId().equals(tableauTagDispo[i].getId())) { 196 indices[compteur++] = i; 197 198 } 199 } 200 } 201 listTags.setSelectedIndices(indices); 202 203 JScrollPane scrollPane = new JScrollPane(listTags); 204 dialogChoixTags = new JDialog(); 205 dialogChoixTags.setLayout(new BorderLayout()); 206 JPanel panelNorth = new JPanel(new VerticalLayout()); 207 panelNorth.add(new JLabel(Messages.getMessage("thumbviewer_selectTag"))); 208 panelNorth.add(scrollPane); 209 dialogChoixTags.add(panelNorth, BorderLayout.NORTH); 210 JPanel panelBouton = new JPanel(new FlowLayout()); 211 boutonOkAjouterTag = new JButton("Ok"); 212 panelBouton.add(boutonOkAjouterTag); 213 boutonOkAjouterTag.addActionListener(this); 214 dialogChoixTags.add(panelBouton, BorderLayout.CENTER); 215 dialogChoixTags.setSize(new Dimension(400, 280)); 216 dialogChoixTags.setLocationRelativeTo(null); 217 dialogChoixTags.setVisible(true); 218 } catch (IOException e) { 219 e.printStackTrace(); 220 } 221 } else if (arg0.getSource().equals(boutonOkAjouterTag)) { 222 StringBuffer tagIds = new StringBuffer(""); 223 for (Object object : listTags.getSelectedValues()) { 224 Tag tag = (Tag) object; 225 tagIds.append(tag.getId() + ","); 226 } 227 tagIds.deleteCharAt(tagIds.lastIndexOf(",")); 228 try { 229 if (!ImageService.getInstance().addTags(image, tagIds.toString())) { 230 JOptionPane.showMessageDialog(this, Messages.getMessage("addingTagsError"), Messages.getMessage("error"), 231 JOptionPane.ERROR_MESSAGE); 232 } else { 233 dialogChoixTags.dispose(); 234 } 235 } catch (IOException e) { 236 e.printStackTrace(); 237 } 238 226 239 } 227 } catch (IOException e) { 228 e.printStackTrace(); 229 } 230 231 } 232 } 240 } 233 241 }
Note: See TracChangeset
for help on using the changeset viewer.