svn-gvsig-desktop / branches / simbologia / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / JSymbolPreviewButton.java @ 10315
History | View | Annotate | Download (3.76 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: JSymbolPreviewButton.java 10315 2007-02-14 09:59:17Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.2 2007-02-14 09:59:17 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1.2.1 2007/02/13 16:19:19 jaume
|
50 |
* graduated symbol legends (start commiting)
|
51 |
*
|
52 |
*
|
53 |
*/
|
54 |
package com.iver.cit.gvsig.project.documents.view.legend.gui; |
55 |
|
56 |
import java.awt.BasicStroke; |
57 |
import java.awt.Color; |
58 |
import java.awt.Graphics; |
59 |
import java.awt.Graphics2D; |
60 |
import java.awt.LayoutManager; |
61 |
import java.awt.Rectangle; |
62 |
import java.awt.event.ActionListener; |
63 |
import java.awt.event.MouseEvent; |
64 |
import java.awt.event.MouseListener; |
65 |
import java.awt.geom.Rectangle2D; |
66 |
import java.util.ArrayList; |
67 |
|
68 |
import javax.swing.BorderFactory; |
69 |
import javax.swing.JComponent; |
70 |
|
71 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
72 |
|
73 |
public class JSymbolPreviewButton extends JComponent implements MouseListener { |
74 |
private ISymbol prev;
|
75 |
private ArrayList listeners = new ArrayList(); |
76 |
private boolean pressed; |
77 |
|
78 |
|
79 |
public JSymbolPreviewButton() {
|
80 |
super();
|
81 |
addMouseListener(this);
|
82 |
mouseExited(null);
|
83 |
|
84 |
} |
85 |
|
86 |
public JSymbolPreviewButton(LayoutManager layout) { |
87 |
this();
|
88 |
} |
89 |
|
90 |
public void paint(Graphics g) { |
91 |
Rectangle bounds = getBounds();
|
92 |
Graphics2D g2 = (Graphics2D) g; |
93 |
if (g2 != null) { |
94 |
g2.setStroke(new BasicStroke(2)); |
95 |
g2.setColor(pressed ? Color.GRAY : Color.WHITE); |
96 |
g2.drawLine(0, 0, (int) bounds.getWidth(), 0); |
97 |
g2.drawLine(0, 0, 0, (int) bounds.getHeight()); |
98 |
g2.setColor(pressed ? Color.WHITE : Color.GRAY); |
99 |
g2.drawLine(2, (int) bounds.getHeight(), (int) bounds.getWidth(), (int) bounds.getHeight()); |
100 |
g2.drawLine((int) bounds.getWidth(), 0, (int) bounds.getWidth(), (int) bounds.getHeight()); |
101 |
|
102 |
Rectangle2D r = new Rectangle2D.Double(3, 3, bounds.getWidth()-3, bounds.getHeight()-6); |
103 |
|
104 |
if (prev!=null) { |
105 |
prev.drawInsideRectangle(g2, g2.getTransform(), r.getBounds()); |
106 |
} |
107 |
} |
108 |
} |
109 |
|
110 |
public void setSymbol(ISymbol symbol) { |
111 |
this.prev = symbol;
|
112 |
mouseExited(null);
|
113 |
} |
114 |
|
115 |
public void mouseClicked(MouseEvent e) { |
116 |
for (int i = 0; i < listeners.size(); i++) { |
117 |
((ActionListener) listeners .get(i)).actionPerformed(null); |
118 |
} |
119 |
} |
120 |
|
121 |
public void mouseEntered(MouseEvent e) {} |
122 |
|
123 |
public void mouseExited(MouseEvent e) { |
124 |
setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
125 |
pressed = false;
|
126 |
paint(getGraphics()); |
127 |
} |
128 |
|
129 |
public void mousePressed(MouseEvent e) { |
130 |
|
131 |
setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
132 |
pressed = true;
|
133 |
paint(getGraphics()); |
134 |
} |
135 |
|
136 |
public void mouseReleased(MouseEvent e) { |
137 |
if (pressed)
|
138 |
mouseClicked(e); |
139 |
mouseExited(e); |
140 |
} |
141 |
|
142 |
public void addActionListener(ActionListener l) { |
143 |
listeners.add(l); |
144 |
} |
145 |
|
146 |
|
147 |
} |