1 | package fr.mael.jiwigo.ui.mainframe; |
---|
2 | |
---|
3 | import java.awt.Cursor; |
---|
4 | import java.awt.Dimension; |
---|
5 | import java.awt.Graphics; |
---|
6 | import java.awt.Graphics2D; |
---|
7 | import java.awt.RenderingHints; |
---|
8 | import java.awt.event.MouseEvent; |
---|
9 | import java.awt.event.MouseListener; |
---|
10 | |
---|
11 | import javax.swing.JLabel; |
---|
12 | |
---|
13 | import fr.mael.jiwigo.om.Image; |
---|
14 | import fr.mael.jiwigo.transverse.util.Messages; |
---|
15 | import fr.mael.jiwigo.ui.ImagesManagement; |
---|
16 | import fr.mael.jiwigo.ui.browser.BrowserFrame; |
---|
17 | |
---|
18 | /** |
---|
19 | Copyright (c) 2010, Mael |
---|
20 | All rights reserved. |
---|
21 | |
---|
22 | Redistribution and use in source and binary forms, with or without |
---|
23 | modification, are permitted provided that the following conditions are met: |
---|
24 | * Redistributions of source code must retain the above copyright |
---|
25 | notice, this list of conditions and the following disclaimer. |
---|
26 | * Redistributions in binary form must reproduce the above copyright |
---|
27 | notice, this list of conditions and the following disclaimer in the |
---|
28 | documentation and/or other materials provided with the distribution. |
---|
29 | * Neither the name of jiwigo nor the |
---|
30 | names of its contributors may be used to endorse or promote products |
---|
31 | derived from this software without specific prior written permission. |
---|
32 | |
---|
33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
---|
34 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
---|
35 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
36 | DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY |
---|
37 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
38 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
39 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
40 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
41 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
42 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
43 | |
---|
44 | * @author mael |
---|
45 | * Panel contenant la miniature d'une image. |
---|
46 | * C'est un panel "cliquable", qui permet d'afficher l'image à taille réelle |
---|
47 | */ |
---|
48 | public class ThumbnailPanel extends JLabel implements MouseListener { |
---|
49 | /** |
---|
50 | * Logger |
---|
51 | */ |
---|
52 | public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory |
---|
53 | .getLog(ThumbnailPanel.class); |
---|
54 | /** |
---|
55 | * l'image |
---|
56 | */ |
---|
57 | private Image image; |
---|
58 | |
---|
59 | /** |
---|
60 | * Constructeur |
---|
61 | * @param image l'image |
---|
62 | * @param imagesPanel le panel |
---|
63 | */ |
---|
64 | public ThumbnailPanel(Image image) { |
---|
65 | this.image = image; |
---|
66 | setToolTipText("<html><center>" + image.getName() + "<br/>" + image.getVue() + " " |
---|
67 | + Messages.getMessage("hits") + "</center></html>"); |
---|
68 | this.addMouseListener(this); |
---|
69 | } |
---|
70 | |
---|
71 | protected void paintComponent(Graphics g) { |
---|
72 | super.paintComponent(g); |
---|
73 | Graphics2D g2 = (Graphics2D) g; |
---|
74 | g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); |
---|
75 | double x = (getWidth() * ImagesManagement.getMiniatureBufferedImage(image).getWidth()) / 2; |
---|
76 | double y = (getHeight() * ImagesManagement.getMiniatureBufferedImage(image).getHeight()) / 2; |
---|
77 | g2.drawRenderedImage(ImagesManagement.getMiniatureBufferedImage(image), null); |
---|
78 | } |
---|
79 | |
---|
80 | /* (non-Javadoc) |
---|
81 | * @see javax.swing.JComponent#getPreferredSize() |
---|
82 | */ |
---|
83 | public Dimension getPreferredSize() { |
---|
84 | int w = (int) (ImagesManagement.getMiniatureBufferedImage(image).getWidth()); |
---|
85 | int h = (int) (ImagesManagement.getMiniatureBufferedImage(image).getHeight() + 10); |
---|
86 | return new Dimension(w, h); |
---|
87 | } |
---|
88 | |
---|
89 | @Override |
---|
90 | public void mouseClicked(MouseEvent paramMouseEvent) { |
---|
91 | // on affiche l'image en grand |
---|
92 | ImagesManagement.setCurrentImage(image); |
---|
93 | try { |
---|
94 | new BrowserFrame(image); |
---|
95 | } catch (Exception e) { |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | } |
---|
100 | |
---|
101 | @Override |
---|
102 | public void mouseEntered(MouseEvent paramMouseEvent) { |
---|
103 | //changement du curseur, pour signifier à l'utilisateur que l'image est cliquable |
---|
104 | this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
105 | } |
---|
106 | |
---|
107 | @Override |
---|
108 | public void mouseExited(MouseEvent paramMouseEvent) { |
---|
109 | } |
---|
110 | |
---|
111 | @Override |
---|
112 | public void mousePressed(MouseEvent paramMouseEvent) { |
---|
113 | // TODO Auto-generated method stub |
---|
114 | |
---|
115 | } |
---|
116 | |
---|
117 | @Override |
---|
118 | public void mouseReleased(MouseEvent paramMouseEvent) { |
---|
119 | // TODO Auto-generated method stub |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | } |
---|