svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / LineProperties.java @ 27580
History | View | Annotate | Download (9.18 KB)
1 |
package com.iver.cit.gvsig.gui.styling; |
---|---|
2 |
|
3 |
import java.awt.BasicStroke; |
4 |
import java.awt.BorderLayout; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
|
10 |
import javax.swing.BorderFactory; |
11 |
import javax.swing.BoxLayout; |
12 |
import javax.swing.ButtonGroup; |
13 |
import javax.swing.ImageIcon; |
14 |
import javax.swing.JButton; |
15 |
import javax.swing.JLabel; |
16 |
import javax.swing.JPanel; |
17 |
import javax.swing.JRadioButton; |
18 |
|
19 |
import org.gvsig.gui.beans.DefaultBean; |
20 |
import org.gvsig.gui.beans.swing.JBlank; |
21 |
|
22 |
import com.iver.andami.PluginServices; |
23 |
|
24 |
public class LineProperties extends DefaultBean implements ActionListener { |
25 |
|
26 |
private JRadioButton joinBevel; |
27 |
private JRadioButton joinMiter; |
28 |
private JRadioButton joinRound; |
29 |
private JRadioButton capBut; |
30 |
private JRadioButton capRound; |
31 |
private JRadioButton capSquare; |
32 |
private PatternEditor pe;
|
33 |
private JButton clearButton; |
34 |
private float width; |
35 |
|
36 |
|
37 |
public LineProperties(float lineWidth) { |
38 |
super();
|
39 |
this.width=lineWidth;
|
40 |
initialize(); |
41 |
} |
42 |
|
43 |
private void initialize() { |
44 |
setName(PluginServices.getText(this, "line_properties")); |
45 |
setLayout(new BorderLayout(10, 10)); |
46 |
|
47 |
JPanel aux2 = new JPanel(); |
48 |
JPanel pnlJoin = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 0)); |
49 |
|
50 |
|
51 |
pnlJoin.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), PluginServices.getText(this, "join_style")+":")); |
52 |
|
53 |
//////////
|
54 |
PluginServices.getIconTheme().registerDefault( |
55 |
"join-bevel",
|
56 |
this.getClass().getClassLoader().getResource("images/join_bevel.png")); |
57 |
PluginServices.getIconTheme().registerDefault( |
58 |
"join-bevel-selected",
|
59 |
this.getClass().getClassLoader().getResource("images/join_bevel-selected.png")); |
60 |
ImageIcon img= PluginServices.getIconTheme().get("join-bevel"); |
61 |
|
62 |
JPanel d = new JPanel(); |
63 |
JPanel toCenter;
|
64 |
d.setLayout(new BoxLayout(d, BoxLayout.Y_AXIS)); |
65 |
joinBevel = new JRadioButton(img); |
66 |
joinBevel.setSelectedIcon(PluginServices.getIconTheme().get("join-bevel-selected"));
|
67 |
FlowLayout flowCenteredLayout = new FlowLayout(FlowLayout.CENTER, 0, 0); |
68 |
toCenter = new JPanel(flowCenteredLayout); |
69 |
toCenter.add(joinBevel); |
70 |
d.add(toCenter); |
71 |
|
72 |
toCenter = new JPanel(flowCenteredLayout); |
73 |
toCenter.add(new JLabel(PluginServices.getText(this, "join_bevel"))); |
74 |
d.add(toCenter); |
75 |
|
76 |
pnlJoin.add(d); |
77 |
|
78 |
PluginServices.getIconTheme().registerDefault( |
79 |
"join-miter",
|
80 |
this.getClass().getClassLoader().getResource("images/join_miter.png")); |
81 |
PluginServices.getIconTheme().registerDefault( |
82 |
"join-miter-selected",
|
83 |
this.getClass().getClassLoader().getResource("images/join_miter-selected.png")); |
84 |
|
85 |
img= PluginServices.getIconTheme().get("join-miter");
|
86 |
|
87 |
d = new JPanel(); |
88 |
d.setLayout(new BoxLayout(d, BoxLayout.Y_AXIS)); |
89 |
joinMiter = new JRadioButton(img); |
90 |
joinMiter.setSelectedIcon(PluginServices.getIconTheme().get("join-miter-selected"));
|
91 |
toCenter = new JPanel(flowCenteredLayout); |
92 |
toCenter.add(joinMiter); |
93 |
d.add(toCenter); |
94 |
|
95 |
toCenter = new JPanel(flowCenteredLayout); |
96 |
toCenter.add(new JLabel(PluginServices.getText(this, "join_miter"))); |
97 |
d.add(toCenter); |
98 |
pnlJoin.add(d); |
99 |
|
100 |
PluginServices.getIconTheme().registerDefault( |
101 |
"join-round",
|
102 |
this.getClass().getClassLoader().getResource("images/join_round.png")); |
103 |
PluginServices.getIconTheme().registerDefault( |
104 |
"join-round-selected",
|
105 |
this.getClass().getClassLoader().getResource("images/join_round-selected.png")); |
106 |
img= PluginServices.getIconTheme().get("join-round");
|
107 |
|
108 |
d = new JPanel(); |
109 |
d.setLayout(new BoxLayout(d, BoxLayout.Y_AXIS)); |
110 |
joinRound = new JRadioButton(img); |
111 |
joinRound.setSelectedIcon(PluginServices.getIconTheme().get("join-round-selected"));
|
112 |
toCenter = new JPanel(flowCenteredLayout); |
113 |
toCenter.add(joinRound); |
114 |
d.add(toCenter); |
115 |
toCenter = new JPanel(flowCenteredLayout); |
116 |
toCenter.add(new JLabel(PluginServices.getText(this, "join_round"))); |
117 |
d.add(toCenter); |
118 |
pnlJoin.add(d); |
119 |
|
120 |
|
121 |
ButtonGroup groupJoin = new ButtonGroup(); |
122 |
groupJoin.add(joinBevel); |
123 |
groupJoin.add(joinMiter); |
124 |
groupJoin.add(joinRound); |
125 |
aux2.add(pnlJoin); |
126 |
|
127 |
JPanel aux3 = new JPanel(); |
128 |
|
129 |
JPanel pnlCap = new JPanel(new FlowLayout(FlowLayout.LEFT, 30, 0)); |
130 |
pnlCap.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), PluginServices.getText(this, "end_style")+":")); |
131 |
|
132 |
PluginServices.getIconTheme().registerDefault( |
133 |
"cap-butt",
|
134 |
this.getClass().getClassLoader().getResource("images/cap_butt.png")); |
135 |
PluginServices.getIconTheme().registerDefault( |
136 |
"cap-butt-selected",
|
137 |
this.getClass().getClassLoader().getResource("images/cap_butt-selected.png")); |
138 |
img= PluginServices.getIconTheme().get("cap-butt");
|
139 |
|
140 |
JPanel c = new JPanel(); |
141 |
c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); |
142 |
capBut = new JRadioButton(img); |
143 |
capBut.setSelectedIcon(PluginServices.getIconTheme().get("cap-butt-selected"));
|
144 |
toCenter = new JPanel(flowCenteredLayout); |
145 |
toCenter.add(capBut); |
146 |
c.add(toCenter); |
147 |
toCenter = new JPanel(flowCenteredLayout); |
148 |
toCenter.add(new JLabel(PluginServices.getText(this, "cap_butt"))); |
149 |
c.add(toCenter); |
150 |
pnlCap.add(c); |
151 |
|
152 |
PluginServices.getIconTheme().registerDefault( |
153 |
"cap-round",
|
154 |
this.getClass().getClassLoader().getResource("images/cap_round.png")); |
155 |
PluginServices.getIconTheme().registerDefault( |
156 |
"cap-round-selected",
|
157 |
this.getClass().getClassLoader().getResource("images/cap_round-selected.png")); |
158 |
img= PluginServices.getIconTheme().get("cap-round");
|
159 |
|
160 |
|
161 |
JPanel a = new JPanel(); |
162 |
a.setLayout(new BoxLayout(a, BoxLayout.Y_AXIS)); |
163 |
capRound = new JRadioButton(img); |
164 |
capRound.setSelectedIcon(PluginServices.getIconTheme().get("cap-round-selected"));
|
165 |
toCenter = new JPanel(flowCenteredLayout); |
166 |
toCenter.add(capRound); |
167 |
a.add(toCenter); |
168 |
toCenter = new JPanel(flowCenteredLayout); |
169 |
toCenter.add(new JLabel(PluginServices.getText(this, "cap_round"))); |
170 |
a.add(toCenter); |
171 |
pnlCap.add(a); |
172 |
|
173 |
PluginServices.getIconTheme().registerDefault( |
174 |
"cap-square",
|
175 |
this.getClass().getClassLoader().getResource("images/cap_square.png")); |
176 |
PluginServices.getIconTheme().registerDefault( |
177 |
"cap-square-selected",
|
178 |
this.getClass().getClassLoader().getResource("images/cap_square-selected.png")); |
179 |
img= PluginServices.getIconTheme().get("cap-square");
|
180 |
|
181 |
JPanel b = new JPanel(); |
182 |
b.setLayout(new BoxLayout(b, BoxLayout.Y_AXIS)); |
183 |
capSquare = new JRadioButton(img); |
184 |
capSquare.setSelectedIcon(PluginServices.getIconTheme().get("cap-square-selected"));
|
185 |
toCenter = new JPanel(flowCenteredLayout); |
186 |
toCenter.add(capSquare); |
187 |
|
188 |
b.add(toCenter); |
189 |
toCenter = new JPanel(flowCenteredLayout); |
190 |
toCenter.add(new JLabel(PluginServices.getText(this, "cap_square"))); |
191 |
b.add(toCenter); |
192 |
pnlCap.add(b); |
193 |
|
194 |
ButtonGroup groupCap = new ButtonGroup(); |
195 |
groupCap.add(capBut); |
196 |
groupCap.add(capRound); |
197 |
groupCap.add(capSquare); |
198 |
aux3.add(pnlCap); |
199 |
|
200 |
JPanel aux4 = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
201 |
aux4.add(new JBlank(5,40)); |
202 |
pe = new PatternEditor();
|
203 |
pe.setPreferredSize(new Dimension(440,40)); |
204 |
aux4.add(pe); |
205 |
aux4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), PluginServices.getText(this, "fill_pattern")+":")); |
206 |
|
207 |
JPanel aux5 = new JPanel(new FlowLayout(FlowLayout.LEFT,15, 0)); |
208 |
clearButton = new JButton(PluginServices.getText(this, "clear")); |
209 |
aux5.add(clearButton); |
210 |
|
211 |
joinBevel.addActionListener(this);
|
212 |
joinMiter.addActionListener(this);
|
213 |
joinRound.addActionListener(this);
|
214 |
capBut.addActionListener(this);
|
215 |
capRound.addActionListener(this);
|
216 |
capSquare.addActionListener(this);
|
217 |
clearButton.addActionListener(clear); |
218 |
pe.addActionListener(patternChange); |
219 |
|
220 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
221 |
aux.add(aux2, BorderLayout.CENTER);
|
222 |
aux.add(aux3, BorderLayout.CENTER);
|
223 |
aux.add(aux4, BorderLayout.CENTER);
|
224 |
aux.add(aux5, BorderLayout.WEST);
|
225 |
add(aux, BorderLayout.CENTER);
|
226 |
} |
227 |
|
228 |
public void actionPerformed(ActionEvent e) { |
229 |
callValueChanged(getLinePropertiesStyle()); |
230 |
} |
231 |
|
232 |
private ActionListener patternChange = new ActionListener() { |
233 |
public void actionPerformed(ActionEvent e) { |
234 |
callValueChanged(getLinePropertiesStyle()); |
235 |
} |
236 |
}; |
237 |
|
238 |
private ActionListener clear = new ActionListener() { |
239 |
public void actionPerformed(ActionEvent e) { |
240 |
pe.clear_Dash(); |
241 |
callValueChanged(getLinePropertiesStyle()); |
242 |
} |
243 |
}; |
244 |
|
245 |
|
246 |
|
247 |
public void setLinePropertiesStyle(BasicStroke str) { |
248 |
|
249 |
if (str == null) { |
250 |
str = new BasicStroke(); |
251 |
} |
252 |
|
253 |
switch(str.getLineJoin()) {
|
254 |
case 0: |
255 |
joinMiter.setSelected(true);
|
256 |
break;
|
257 |
case 1: |
258 |
joinRound.setSelected(true);
|
259 |
break;
|
260 |
case 2: |
261 |
joinBevel.setSelected(true);
|
262 |
break;
|
263 |
} |
264 |
|
265 |
switch(str.getEndCap()) {
|
266 |
case 0: |
267 |
capBut.setSelected(true);
|
268 |
break;
|
269 |
case 1: |
270 |
capRound.setSelected(true);
|
271 |
break;
|
272 |
case 2: |
273 |
capSquare.setSelected(true);
|
274 |
break;
|
275 |
} |
276 |
|
277 |
pe.setDash(str.getDashArray()); |
278 |
pe.repaint(); |
279 |
} |
280 |
|
281 |
public BasicStroke getLinePropertiesStyle() { |
282 |
int capType=0, joinType=0; |
283 |
|
284 |
|
285 |
if (capBut.isSelected()) capType = 0; |
286 |
else if (capRound.isSelected()) capType = 1; |
287 |
else if (capSquare.isSelected()) capType = 2; |
288 |
|
289 |
if (joinMiter.isSelected()) joinType = 0; |
290 |
else if (joinRound.isSelected()) joinType = 1; |
291 |
else if (joinBevel.isSelected()) joinType = 2; |
292 |
|
293 |
float [] dash = pe.getDash(); |
294 |
|
295 |
BasicStroke str = new BasicStroke(width, capType, joinType, 10, pe.getDash(), 0); |
296 |
pe.setDash(dash); |
297 |
return str;
|
298 |
} |
299 |
} |