Changeset 6958 for extensions/jiwigo


Ignore:
Timestamp:
Sep 19, 2010, 1:33:27 AM (14 years ago)
Author:
mlg
Message:

New features

  • When clicking on a category, the category is opened in a tab. When clicking on the same category again, no tab is opened but the previously opened tab is shown. The user can close the tabs (close current tab, close others, close all).
  • Ability to clip the images. There are still some bugs (unable to clip the images when zooming, and the rectangle stays when changing the image).
Location:
extensions/jiwigo/trunk/src/main
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/util/ImagesUtil.java

    r6821 r6958  
    11package fr.mael.jiwigo.transverse.util;
    22
     3import java.awt.Graphics;
    34import java.awt.Graphics2D;
    45import java.awt.GraphicsConfiguration;
    56import java.awt.GraphicsDevice;
    67import java.awt.GraphicsEnvironment;
     8import java.awt.HeadlessException;
    79import java.awt.Image;
    810import java.awt.RenderingHints;
     11import java.awt.Transparency;
    912import java.awt.image.BufferedImage;
     13import java.awt.image.ColorModel;
     14import java.awt.image.PixelGrabber;
    1015import java.io.BufferedInputStream;
    1116import java.io.File;
    1217import java.io.FileInputStream;
    13 import java.io.FileOutputStream;
     18import java.io.FileNotFoundException;
    1419import java.io.IOException;
    1520import java.io.InputStream;
    16 
     21import java.util.Iterator;
     22
     23import javax.imageio.IIOImage;
    1724import javax.imageio.ImageIO;
     25import javax.imageio.ImageWriteParam;
     26import javax.imageio.ImageWriter;
     27import javax.imageio.stream.FileImageOutputStream;
     28import javax.swing.ImageIcon;
    1829
    1930/**
     
    123134        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    124135        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);
    126139        return true;
    127140
    128141    }
     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
    129228}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/util/Outil.java

    r6840 r6958  
    105105    public static Document stringToDocument(String string) throws JDOMException, IOException {
    106106        SAXBuilder sb = new SAXBuilder();
     107        System.out.println(string);
    107108        Document doc = sb.build(new StringReader(string));
    108109        return doc;
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/ImagesManagement.java

    r6821 r6958  
    7575     */
    7676    public static Image getCurrentImage() {
    77         return LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
     77        //return LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
     78        return CURRENT_IMAGE;
    7879    }
    7980
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/browser/BrowserFrame.java

    r6831 r6958  
    104104
    105105    /**
     106     * rogner l'image
     107     */
     108    private JButton cut = new JButton();
     109
     110    /**
    106111     * Panel qui contient l'image
    107112     */
     
    137142        save.setIcon(new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/save.png")));
    138143        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")));
    139145        //on rend les boutons invisibles, pour ne voir que l'image
    140146        next.setFocusPainted(false);
     
    156162        comment.setBorderPainted(false);
    157163        comment.setContentAreaFilled(false);
     164        cut.setFocusPainted(false);
     165        cut.setBorderPainted(false);
     166        cut.setContentAreaFilled(false);
    158167        //ajout des action listeners
    159168        comment.addActionListener(this);
     
    163172        previous.addActionListener(this);
    164173        next.addActionListener(this);
     174        cut.addActionListener(this);
    165175        //ajout des boutons
    166176        panelBoutons.add(previous);
     
    168178        panelBoutons.add(rotateLeft);
    169179        panelBoutons.add(rotateRight);
     180        panelBoutons.add(cut);
    170181        panelBoutons.add(save);
    171182        panelBoutons.add(comment);
     
    368379        } else if (e.getSource().equals(menuItemNormal)) {
    369380            imagePanel.zoomNormal();
     381        } else if (e.getSource().equals(cut)) {
     382            imagePanel.rogner();
    370383        }
    371384
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/browser/BrowserImagePanel.java

    r6833 r6958  
    55import java.awt.Graphics2D;
    66import java.awt.RenderingHints;
     7import java.awt.event.MouseEvent;
     8import java.awt.event.MouseListener;
     9import java.awt.event.MouseMotionListener;
    710import java.awt.event.MouseWheelEvent;
    811import java.awt.event.MouseWheelListener;
     
    1518
    1619import javax.swing.JLabel;
     20import javax.swing.JOptionPane;
    1721import javax.swing.JPanel;
    1822import javax.swing.JSlider;
     
    2125
    2226import fr.mael.jiwigo.transverse.util.ImagesUtil;
     27import fr.mael.jiwigo.transverse.util.Messages;
    2328
    2429/**
     
    5257 *
    5358 */
    54 public class BrowserImagePanel extends JPanel implements MouseWheelListener, Printable {
     59public class BrowserImagePanel extends JPanel implements MouseWheelListener, Printable, MouseMotionListener,
     60        MouseListener {
    5561    private BufferedImage image;
    5662    private double scale = 1.0;
     
    5864    boolean flipV = false;
    5965    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;
    6072
    6173    /**
     
    6678        this.image = image;
    6779        this.addMouseWheelListener(this);
     80        this.addMouseMotionListener(this);
     81        this.addMouseListener(this);
    6882    }
    6983
     
    90104            at.scale(scale, scale);
    91105        }
    92 
    93106        g2.drawRenderedImage(image, at);
     107        if (drawSelection) {
     108            g2.drawRect(xTopPosition, yTopPosition, xDragPosition - xTopPosition, yDragPosition - yTopPosition);
     109        }
    94110
    95111    }
     
    102118        int h = (int) (scale * image.getHeight());
    103119        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        }
    104175    }
    105176
     
    237308    }
    238309
     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
    239344}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/CategoriesTree.java

    r6831 r6958  
    124124        Object catSelectionnee = node.getUserObject();
    125125        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));
    127128    }
    128129
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/MainFrame.java

    r6833 r6958  
    66import java.awt.event.ActionEvent;
    77import java.awt.event.ActionListener;
    8 
     8import java.util.HashMap;
     9
     10import javax.swing.ImageIcon;
    911import javax.swing.JComponent;
    1012import javax.swing.JFrame;
     
    2022import fr.mael.jiwigo.transverse.util.Messages;
    2123import fr.mael.jiwigo.transverse.util.Outil;
     24import fr.mael.jiwigo.ui.mainframe.tab.JTabbedPaneWithCloseIcons;
    2225
    2326/**
     
    100103    private JProgressBar progressBar;
    101104
     105    private JTabbedPaneWithCloseIcons tabbedPane;
     106
     107    private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>();
     108
    102109    /**
    103110     * @return le singleton
     
    114121     */
    115122    private MainFrame() {
    116         this.setTitle("Piwigo v" + Messages.getMessage("version"));
     123        this.setTitle("Jiwigo v" + Messages.getMessage("version"));
    117124        this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png")));
    118125        this.setLayout(new BorderLayout());
     
    122129        categoriesTree = new CategoriesTree();
    123130        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);
    132142        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    133143        progressBar = new JProgressBar(0, 100);
     
    143153        this.setJMenuBar(jMenuBar);
    144154        this.add(panel, BorderLayout.SOUTH);
    145         this.pack();
     155        //      this.pack();
     156        this.setSize(900, 600);
    146157        this.setLocationRelativeTo(null);
    147158        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
    149188    }
    150189
     
    191230    }
    192231
     232    /**
     233     * @return the mapsIdPos
     234     */
     235    public HashMap<Integer, Integer> getMapsIdPos() {
     236        return mapsIdPos;
     237    }
     238
    193239}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailCategoryPanel.java

    r6839 r6958  
    77import javax.swing.JPanel;
    88
     9import fr.mael.jiwigo.om.Category;
    910import fr.mael.jiwigo.om.Image;
    1011import fr.mael.jiwigo.service.ImageService;
     
    5455     */
    5556    private Integer categoryId;
     57
     58    private Category category;
     59
     60    public ThumbnailCategoryPanel(Category category) {
     61        this(category.getIdentifiant());
     62        this.category = category;
     63    }
    5664
    5765    /**
     
    111119    public void setCategoryId(Integer categoryId) {
    112120        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;
    113135    }
    114136
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailPanel.java

    r6833 r6958  
    9494            new BrowserFrame(image);
    9595        } catch (Exception e) {
    96 
     96            e.printStackTrace();
    9797        }
    9898
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages.properties

    r6842 r6958  
    1111hits=Hits
    1212loadingOk=Loading ok
     13info=Info
    1314
    1415#####################################################
     
    3233#####################################################
    3334thumbviewer_loading=Loading thumbnails. Please wait...
     35thumbviewer_close=Close
     36thumbviewer_closeOthers=Close others
     37thumbviewer_closeAll=Close all
    3438
    3539#####################################################
     
    4650preferencesCheckValues=Please check the values
    4751preferencesUnexpectedError=<html>An unexpected error happened. Preferences won't be updated</html>
     52clippingError=Clipping does not work with zoom
    4853
    4954#####################################################
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages_en.properties

    r6842 r6958  
    1111hits=Hits
    1212loadingOk=Loading ok
     13info=Info
    1314
    1415#####################################################
     
    3233#####################################################
    3334thumbviewer_loading=Loading thumbnails. Please wait...
     35thumbviewer_close=Close
     36thumbviewer_closeOthers=Close others
     37thumbviewer_closeAll=Close all
    3438
    3539#####################################################
     
    4650preferencesCheckValues=Please check the values
    4751preferencesUnexpectedError=<html>An unexpected error happened. Preferences won't be updated</html>
     52clippingError=Clipping does not work with zoom
    4853
    4954#####################################################
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages_fr.properties

    r6840 r6958  
    33#####################################################
    44error=Erreur
    5 welcomeMessage=Bienvenue dans jiwigo
     5welcomeMessage=Bienvenue dans Jiwigo
    66version=0.11b
    77commentaires=Commentaires
     
    1111hits=Hits
    1212loadingOk=Chargement réussi
     13info=Info
    1314
    1415#####################################################
     
    3233#####################################################
    3334thumbviewer_loading=Chargement des miniatures, veuillez patienter
     35thumbviewer_close=Fermer
     36thumbviewer_closeOthers=Fermer les autres
     37thumbviewer_closeAll=Fermer tous
    3438
    3539
     
    4751preferencesCheckValues=Veuillez vérifier les valeurs entrées
    4852preferencesUnexpectedError=<html>Une erreur inattendue s'est produite. Les préférences ne seront<br/>probablement pas mises à jour</html>
     53clippingError=Le rognage ne fonctionne pas avec le zoom
    4954
    5055#####################################################
Note: See TracChangeset for help on using the changeset viewer.