Changeset 6833


Ignore:
Timestamp:
Sep 1, 2010, 11:59:17 PM (14 years ago)
Author:
mlg
Message:

Features implementation :
feature:0001829 : the user is now informed that the application is performing an action. It displays what action it is and also a progress bar for time consuming actions like sending images. (calls to jiwigo's webservice are done in threads).

Location:
extensions/jiwigo/trunk/src/main
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/service/ImageService.java

    r6831 r6833  
    99import fr.mael.jiwigo.transverse.enumeration.PreferencesEnum;
    1010import fr.mael.jiwigo.transverse.util.ImagesUtil;
     11import fr.mael.jiwigo.transverse.util.Messages;
    1112import fr.mael.jiwigo.transverse.util.Outil;
    1213import fr.mael.jiwigo.transverse.util.preferences.PreferencesManagement;
     14import fr.mael.jiwigo.ui.mainframe.MainFrame;
    1315
    1416/**
     
    7577     */
    7678    public boolean creer(String filePath, Integer idCategory) throws Exception {
     79        MainFrame.getInstance().setReussiteMessage(Messages.getMessage("mainFrame_resizing"));
    7780        //get the byte array of the original file, to keep metadata
    7881        byte[] bytesFichierOriginal = Outil.getBytesFromFile(new File(filePath));
     
    9598            //I use here a try catch because if the original file isn't a jpeg
    9699            //the methode Outil.enrich will fail, but the procedure has to continue
     100            MainFrame.getInstance().setReussiteMessage(Messages.getMessage("mainFrame_addMetadata"));
    97101            try {
    98102                byte[] fichierEnrichi = Outil.enrich(bytesFichierOriginal, Outil.getBytesFromFile(new File(System
     
    111115        image.setOriginale(originale);
    112116        image.setIdCategory(idCategory);
     117        MainFrame.getInstance().setReussiteMessage(Messages.getMessage("mainFrame_sendingFiles"));
    113118        //now we call the dao to send the image to the webservice
    114119        return ImageDao.getInstance().creer(image);
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/browser/BrowserImagePanel.java

    r6831 r6833  
    9090            at.scale(scale, scale);
    9191        }
    92         System.out.println(scale);
    9392
    9493        g2.drawRenderedImage(image, at);
     
    138137
    139138    public void zoomOut() {
    140 
    141         scale = (--valueSlider + 4) / 20.0;
    142         revalidate();
    143         repaint();
     139        if (scale > 0) {
     140            scale = (--valueSlider + 4) / 20.0;
     141            revalidate();
     142            repaint();
     143        }
    144144    }
    145145
     
    203203        String newline = "\n";
    204204        if (notches < 0) {
    205             message = "Mouse wheel moved UP " + -notches + " notch(es)" + newline;
     205            zoomIn();
     206
    206207        } else {
    207             message = "Mouse wheel moved DOWN " + notches + " notch(es)" + newline;
    208         }
    209         if (arg0.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
    210             message += "    Scroll amount: " + arg0.getScrollAmount() + " unit increments per notch" + newline;
    211             message += "    Units to scroll: " + arg0.getUnitsToScroll() + " unit increments" + newline;
    212         } else { //scroll type == MouseWheelEvent.WHEEL_BLOCK_SCROLL
    213             message += "    Scroll type: WHEEL_BLOCK_SCROLL" + newline;
     208            zoomOut();
    214209        }
    215210
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/MainFrame.java

    r6832 r6833  
    1414import javax.swing.JMenuItem;
    1515import javax.swing.JPanel;
     16import javax.swing.JProgressBar;
    1617import javax.swing.JScrollPane;
    1718import javax.swing.JSplitPane;
     
    9798    private static MainFrame instance;
    9899
     100    private JProgressBar progressBar;
     101
    99102    /**
    100103     * @return le singleton
     
    128131        this.add(splitPane, BorderLayout.WEST);
    129132        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
     133        progressBar = new JProgressBar(0, 100);
     134        panel.add(progressBar);
    130135        panel.add(labelMessage);
    131136
     
    175180    }
    176181
    177     public static void reduceHeightOfComponent(JComponent comp) {
    178         comp.setMaximumSize(new Dimension(comp.getMaximumSize().width, comp.getPreferredSize().height));
    179     }
    180 
    181     public static void reduceWidthOfComponent(JComponent comp) {
    182         comp.setMaximumSize(new Dimension(comp.getPreferredSize().width, comp.getMaximumSize().height));
    183     }
    184 
    185182    public static void reduceSizeOfComponent(JComponent comp) {
    186183        comp.setMaximumSize(comp.getPreferredSize());
    187184    }
    188185
     186    /**
     187     * @return the progressBar
     188     */
     189    public JProgressBar getProgressBar() {
     190        return progressBar;
     191    }
     192
    189193}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailCategoryPanel.java

    r6832 r6833  
    22
    33import java.awt.FlowLayout;
     4import java.io.File;
    45
    56import javax.swing.BoxLayout;
     
    6970        new FileDrop(System.out, this, new FileDrop.Listener() {
    7071            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) {
    72176                    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
    76188                    } 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
    81190                    }
    82191                }
    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"));
    84203            }
    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    }
    140207}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailPanel.java

    r6831 r6833  
    1212
    1313import fr.mael.jiwigo.om.Image;
     14import fr.mael.jiwigo.transverse.util.Messages;
    1415import fr.mael.jiwigo.ui.ImagesManagement;
    1516import fr.mael.jiwigo.ui.browser.BrowserFrame;
     
    6364    public ThumbnailPanel(Image image) {
    6465        this.image = image;
     66        setToolTipText("<html><center>" + image.getName() + "<br/>" + image.getVue() + " "
     67                + Messages.getMessage("hits") + "</center></html>");
    6568        this.addMouseListener(this);
    6669    }
     
    8083    public Dimension getPreferredSize() {
    8184        int w = (int) (ImagesManagement.getMiniatureBufferedImage(image).getWidth());
    82         int h = (int) (ImagesManagement.getMiniatureBufferedImage(image).getHeight());
     85        int h = (int) (ImagesManagement.getMiniatureBufferedImage(image).getHeight() + 10);
    8386        return new Dimension(w, h);
    8487    }
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages.properties

    r6831 r6833  
    99titleBrowser=Jiwigo :: Files browser
    1010cancel=Cancel
     11hits=Hits
     12loadingOk=Loading ok
    1113
    1214#####################################################
     
    1517mainFrame_editionMenu=Edition
    1618mainFrame_preferencesMenu=Preferences
     19mainFrame_resizing=Resizing...
     20mainFrame_addMetadata=Adding metadata...
     21mainFrame_sendingFiles=Sending files...
    1722
    1823#####################################################
     
    2328preferences_chunkSize=Chunks size (Mb)
    2429
     30#####################################################
     31############### Thumbnail viewer ####################
     32#####################################################
     33thumbviewer_loading=Loading thumbnails. Please wait...
    2534
    2635#####################################################
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages_fr.properties

    r6831 r6833  
    99titleBrowser=Jiwigo :: Navigateur de fichiers
    1010cancel=Annuler
     11hits=Hits
     12loadingOk=Chargement réussi
    1113
    1214#####################################################
     
    1517mainFrame_editionMenu=Edition
    1618mainFrame_preferencesMenu=Préférences
     19mainFrame_resizing=Redimensionnements...
     20mainFrame_addMetadata=Ajout des métadonnées...
     21mainFrame_sendingFiles=Envoi des fichiers...
    1722
    1823#####################################################
     
    2227preferences_imagesSize=Taille des images
    2328preferences_chunkSize=Taille des "morceaux" (en Mo)
     29
     30#####################################################
     31############### Thumbnail viewer ####################
     32#####################################################
     33thumbviewer_loading=Chargement des miniatures, veuillez patienter
    2434
    2535
Note: See TracChangeset for help on using the changeset viewer.