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