svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / legend / edition / gui / PreviewIcon.java @ 40558
History | View | Annotate | Download (2.5 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.legend.edition.gui; |
25 |
import java.awt.Color; |
26 |
import java.awt.Graphics; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.event.MouseListener; |
29 |
|
30 |
import javax.swing.ImageIcon; |
31 |
import javax.swing.JPanel; |
32 |
|
33 |
|
34 |
public class PreviewIcon extends JPanel { |
35 |
private ImageIcon icon; |
36 |
private boolean isSelected; |
37 |
|
38 |
/**
|
39 |
*
|
40 |
*/
|
41 |
public PreviewIcon() {
|
42 |
super();
|
43 |
initialize(); |
44 |
} |
45 |
|
46 |
|
47 |
/**
|
48 |
* This method initializes this
|
49 |
*
|
50 |
* @return void
|
51 |
*/
|
52 |
private void initialize() { |
53 |
this.setSize(70, 52); |
54 |
|
55 |
} |
56 |
protected void paintComponent(Graphics g) { |
57 |
super.paintComponent(g);
|
58 |
if (icon == null) |
59 |
return;
|
60 |
|
61 |
Graphics2D g2 = (Graphics2D) g; |
62 |
//g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
63 |
//g.setClip(0,0,getWidth(), getHeight());
|
64 |
//Rectangle r = g.getClipBounds(); //getClipRect();
|
65 |
if (isSelected)
|
66 |
g2.setColor(Color.blue);
|
67 |
else
|
68 |
g2.setColor(Color.white);
|
69 |
|
70 |
//g2.setColor(color);
|
71 |
g2.fillRect(0,0,getWidth(),getHeight()); |
72 |
g2.drawImage(icon.getImage(),0,0,this); |
73 |
|
74 |
} |
75 |
public void setSelected(boolean b) { |
76 |
isSelected=b; |
77 |
} |
78 |
public void setIcon(ImageIcon icon) { |
79 |
this.icon=icon;
|
80 |
repaint(); |
81 |
} |
82 |
public ImageIcon getIcon() { |
83 |
return icon;
|
84 |
} |
85 |
|
86 |
/* (non-Javadoc)
|
87 |
* @see java.awt.Component#isShowing()
|
88 |
*/
|
89 |
public boolean isShowing() { |
90 |
return true; // super.isShowing(); |
91 |
} |
92 |
|
93 |
|
94 |
public boolean isSelected() { |
95 |
return isSelected;
|
96 |
} |
97 |
|
98 |
|
99 |
public synchronized void addMouseListener(MouseListener arg0) { |
100 |
super.addMouseListener(arg0);
|
101 |
|
102 |
} |
103 |
} // @jve:visual-info decl-index=0 visual-constraint="10,10"
|