Revision 10315 branches/simbologia/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/JSymbolPreviewButton.java
JSymbolPreviewButton.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.1.2.1 2007-02-13 16:19:19 jaume |
|
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 |
|
47 | 50 |
* graduated symbol legends (start commiting) |
48 | 51 |
* |
49 | 52 |
* |
50 | 53 |
*/ |
51 | 54 |
package com.iver.cit.gvsig.project.documents.view.legend.gui; |
52 | 55 |
|
56 |
import java.awt.BasicStroke; |
|
57 |
import java.awt.Color; |
|
53 | 58 |
import java.awt.Graphics; |
54 | 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; |
|
55 | 67 |
|
56 |
import org.gvsig.gui.beans.swing.JButton; |
|
68 |
import javax.swing.BorderFactory; |
|
69 |
import javax.swing.JComponent; |
|
57 | 70 |
|
58 | 71 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
59 | 72 |
|
60 |
public class JSymbolPreviewButton extends JButton {
|
|
73 |
public class JSymbolPreviewButton extends JComponent implements MouseListener {
|
|
61 | 74 |
private ISymbol prev; |
75 |
private ArrayList listeners = new ArrayList(); |
|
76 |
private boolean pressed; |
|
62 | 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 |
|
|
63 | 90 |
public void paint(Graphics g) { |
64 |
super.paint(g); |
|
65 |
if (prev!=null) { |
|
66 |
Graphics2D g2 = (Graphics2D) g; |
|
67 |
prev.drawInsideRectangle(g2, g2.getTransform(), getBounds()); |
|
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 |
} |
|
68 | 107 |
} |
69 | 108 |
} |
70 | 109 |
|
71 | 110 |
public void setSymbol(ISymbol symbol) { |
72 | 111 |
this.prev = symbol; |
73 |
repaint();
|
|
112 |
mouseExited(null);
|
|
74 | 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 |
|
|
75 | 147 |
} |
Also available in: Unified diff