Changeset 6833 for extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailCategoryPanel.java
- Timestamp:
- Sep 1, 2010, 11:59:17 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailCategoryPanel.java
r6832 r6833 2 2 3 3 import java.awt.FlowLayout; 4 import java.io.File; 4 5 5 6 import javax.swing.BoxLayout; … … 69 70 new FileDrop(System.out, this, new FileDrop.Listener() { 70 71 public void filesDropped(final java.io.File[] files) { 71 for (int i = 0; i < files.length; i++) { 72 new Thread(new ThreadEnvoiPhoto(files)).start(); 73 // for (int i = 0; i < files.length; i++) { 74 // try { 75 // ImageService.getInstance().creer(files[i].getCanonicalPath(), getCategoryId()); 76 // //on rafraichit 77 // rafraichir(getCategoryId(), true); 78 // } catch (Exception e) { 79 // LOG.error(Outil.getStackTrace(e)); 80 // //s'il y a une erreur lors de l'envoi 81 // JOptionPane.showMessageDialog(null, Messages.getMessage("sendingError") + files[i].getName(), 82 // Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 83 // } 84 // } 85 86 } 87 }); 88 89 } 90 91 /** 92 * rafraichissement, afin d'afficher les nouvelles images 93 * @param categoryId 94 */ 95 public void rafraichir(Integer categoryId, boolean rafraichir) { 96 this.categoryId = categoryId; 97 new Thread(new ThreadLoadThumb(this, rafraichir)).start(); 98 } 99 100 /** 101 * @return the categoryId 102 */ 103 public Integer getCategoryId() { 104 return categoryId; 105 } 106 107 /** 108 * @param categoryId the categoryId to set 109 */ 110 public void setCategoryId(Integer categoryId) { 111 this.categoryId = categoryId; 112 } 113 114 /** 115 * @author mael 116 * Thread that send the photos 117 */ 118 public class ThreadEnvoiPhoto implements Runnable { 119 private File[] files; 120 121 public ThreadEnvoiPhoto(File[] files) { 122 this.files = files; 123 } 124 125 @Override 126 public void run() { 127 128 for (int i = 0; i < files.length; i++) { 129 int nbProgressBar = ((i + 1) * 100) / files.length; 130 try { 131 132 ImageService.getInstance().creer(files[i].getCanonicalPath(), categoryId); 133 //on rafraichit 134 rafraichir(categoryId, true); 135 MainFrame.getInstance().setReussiteMessage( 136 files[i].getName() + " " + Messages.getMessage("sendingSuccess")); 137 } catch (Exception e) { 138 LOG.error(Outil.getStackTrace(e)); 139 //s'il y a une erreur lors de l'envoi 140 JOptionPane.showMessageDialog(null, Messages.getMessage("sendingError") + files[i].getName(), 141 Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 142 MainFrame.getInstance().setErrorMessage( 143 Messages.getMessage("sendingError") + " " + files[i].getName()); 144 } finally { 145 MainFrame.getInstance().getProgressBar().setValue(nbProgressBar); 146 } 147 } 148 MainFrame.getInstance().getProgressBar().setValue(0); 149 } 150 } 151 152 /** 153 * 154 * @author mael 155 * Thread that loads the thumbs and fills the thumb panel 156 */ 157 public class ThreadLoadThumb implements Runnable { 158 ThumbnailCategoryPanel panel; 159 boolean rafraichir; 160 161 public ThreadLoadThumb(ThumbnailCategoryPanel panel, boolean rafraichir) { 162 this.panel = panel; 163 this.rafraichir = rafraichir; 164 } 165 166 @Override 167 public void run() { 168 169 panel.removeAll(); 170 int nb = 1; 171 JPanel panelh = new JPanel(new FlowLayout()); 172 try { 173 MainFrame.getInstance().setReussiteMessage(Messages.getMessage("thumbviewer_loading")); 174 ImagesManagement.LIST_IMAGE = ImageService.getInstance().listerParCategory(categoryId, rafraichir); 175 for (Image image : ImagesManagement.LIST_IMAGE) { 72 176 try { 73 ImageService.getInstance().creer(files[i].getCanonicalPath(), getCategoryId()); 74 //on rafraichit 75 rafraichir(getCategoryId(), true); 177 178 if (nb == 7) { 179 panel.add(panelh); 180 panelh = new JPanel(new FlowLayout()); 181 nb = 0; 182 } else { 183 ThumbnailPanel panel = new ThumbnailPanel(image); 184 panelh.add(panel); 185 } 186 nb++; 187 76 188 } catch (Exception e) { 77 LOG.error(Outil.getStackTrace(e)); 78 //s'il y a une erreur lors de l'envoi 79 JOptionPane.showMessageDialog(null, Messages.getMessage("sendingError") + files[i].getName(), 80 Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 189 81 190 } 82 191 } 83 192 if (nb != 8) { 193 panel.add(panelh); 194 } 195 panel.repaint(); 196 panel.revalidate(); 197 MainFrame.getInstance().setReussiteMessage(Messages.getMessage("loadingOk")); 198 } catch (Exception e) { 199 LOG.error(Outil.getStackTrace(e)); 200 JOptionPane.showMessageDialog(null, Messages.getMessage("imagesListingError"), Messages 201 .getMessage("error"), JOptionPane.ERROR_MESSAGE); 202 MainFrame.getInstance().setErrorMessage(Messages.getMessage("imagesListingError")); 84 203 } 85 }); 86 87 } 88 89 /** 90 * rafraichissement, afin d'afficher les nouvelles images 91 * @param categoryId 92 */ 93 public void rafraichir(Integer categoryId, boolean rafraichir) { 94 this.categoryId = categoryId; 95 this.removeAll(); 96 int nb = 1; 97 JPanel panelh = new JPanel(new FlowLayout()); 98 try { 99 ImagesManagement.LIST_IMAGE = ImageService.getInstance().listerParCategory(categoryId, rafraichir); 100 for (Image image : ImagesManagement.LIST_IMAGE) { 101 try { 102 103 if (nb == 7) { 104 this.add(panelh); 105 panelh = new JPanel(new FlowLayout()); 106 nb = 0; 107 } else { 108 ThumbnailPanel panel = new ThumbnailPanel(image); 109 panelh.add(panel); 110 } 111 nb++; 112 113 } catch (Exception e) { 114 115 } 116 } 117 this.repaint(); 118 this.revalidate(); 119 } catch (Exception e) { 120 LOG.error(Outil.getStackTrace(e)); 121 JOptionPane.showMessageDialog(null, Messages.getMessage("imagesListingError"), 122 Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 123 } 124 } 125 126 /** 127 * @return the categoryId 128 */ 129 public Integer getCategoryId() { 130 return categoryId; 131 } 132 133 /** 134 * @param categoryId the categoryId to set 135 */ 136 public void setCategoryId(Integer categoryId) { 137 this.categoryId = categoryId; 138 } 139 204 205 } 206 } 140 207 }
Note: See TracChangeset
for help on using the changeset viewer.