root / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / LineProperties.java @ 38608
History | View | Annotate | Download (7.4 KB)
1 |
package org.gvsig.app.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.JButton; |
14 |
import javax.swing.JLabel; |
15 |
import javax.swing.JPanel; |
16 |
import javax.swing.JRadioButton; |
17 |
|
18 |
import org.gvsig.andami.IconThemeHelper; |
19 |
import org.gvsig.gui.beans.DefaultBean; |
20 |
import org.gvsig.gui.beans.swing.JBlank; |
21 |
import org.gvsig.i18n.Messages; |
22 |
|
23 |
|
24 |
public class LineProperties extends DefaultBean implements ActionListener { |
25 |
|
26 |
/**
|
27 |
*
|
28 |
*/
|
29 |
private static final long serialVersionUID = 6356385079456043011L; |
30 |
private JRadioButton joinBevel; |
31 |
private JRadioButton joinMiter; |
32 |
private JRadioButton joinRound; |
33 |
private JRadioButton capBut; |
34 |
private JRadioButton capRound; |
35 |
private JRadioButton capSquare; |
36 |
private PatternEditor pe;
|
37 |
private JButton clearButton; |
38 |
private float width; |
39 |
|
40 |
|
41 |
public LineProperties(float lineWidth) { |
42 |
super();
|
43 |
this.width=lineWidth;
|
44 |
initialize(); |
45 |
} |
46 |
|
47 |
private void initialize() { |
48 |
setName(Messages.getText("line_properties"));
|
49 |
setLayout(new BorderLayout(10, 10)); |
50 |
|
51 |
JPanel aux2 = new JPanel(); |
52 |
JPanel pnlJoin = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 0)); |
53 |
|
54 |
|
55 |
pnlJoin.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), Messages.getText("join_style")+":")); |
56 |
|
57 |
JPanel d = new JPanel(); |
58 |
JPanel toCenter;
|
59 |
d.setLayout(new BoxLayout(d, BoxLayout.Y_AXIS)); |
60 |
joinBevel = new JRadioButton(IconThemeHelper.getImageIcon("line-properties-join-bevel")); |
61 |
joinBevel.setSelectedIcon(IconThemeHelper.getImageIcon("line-properties-join-bevel-selected"));
|
62 |
FlowLayout flowCenteredLayout = new FlowLayout(FlowLayout.CENTER, 0, 0); |
63 |
toCenter = new JPanel(flowCenteredLayout); |
64 |
toCenter.add(joinBevel); |
65 |
d.add(toCenter); |
66 |
|
67 |
toCenter = new JPanel(flowCenteredLayout); |
68 |
toCenter.add(new JLabel(Messages.getText("join_bevel"))); |
69 |
d.add(toCenter); |
70 |
|
71 |
pnlJoin.add(d); |
72 |
|
73 |
|
74 |
d = new JPanel(); |
75 |
d.setLayout(new BoxLayout(d, BoxLayout.Y_AXIS)); |
76 |
joinMiter = new JRadioButton(IconThemeHelper.getImageIcon("line-properties-join-miter")); |
77 |
joinMiter.setSelectedIcon(IconThemeHelper.getImageIcon("line-properties-join-miter-selected"));
|
78 |
toCenter = new JPanel(flowCenteredLayout); |
79 |
toCenter.add(joinMiter); |
80 |
d.add(toCenter); |
81 |
|
82 |
toCenter = new JPanel(flowCenteredLayout); |
83 |
toCenter.add(new JLabel(Messages.getText("join_miter"))); |
84 |
d.add(toCenter); |
85 |
pnlJoin.add(d); |
86 |
|
87 |
|
88 |
|
89 |
d = new JPanel(); |
90 |
d.setLayout(new BoxLayout(d, BoxLayout.Y_AXIS)); |
91 |
joinRound = new JRadioButton(IconThemeHelper.getImageIcon("line-properties-join-round")); |
92 |
joinRound.setSelectedIcon(IconThemeHelper.getImageIcon("line-properties-join-round-selected"));
|
93 |
toCenter = new JPanel(flowCenteredLayout); |
94 |
toCenter.add(joinRound); |
95 |
d.add(toCenter); |
96 |
toCenter = new JPanel(flowCenteredLayout); |
97 |
toCenter.add(new JLabel(Messages.getText("join_round"))); |
98 |
d.add(toCenter); |
99 |
pnlJoin.add(d); |
100 |
|
101 |
|
102 |
ButtonGroup groupJoin = new ButtonGroup(); |
103 |
groupJoin.add(joinBevel); |
104 |
groupJoin.add(joinMiter); |
105 |
groupJoin.add(joinRound); |
106 |
aux2.add(pnlJoin); |
107 |
|
108 |
JPanel aux3 = new JPanel(); |
109 |
|
110 |
JPanel pnlCap = new JPanel(new FlowLayout(FlowLayout.LEFT, 30, 0)); |
111 |
pnlCap.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), Messages.getText("end_style")+":")); |
112 |
|
113 |
JPanel c = new JPanel(); |
114 |
c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); |
115 |
capBut = new JRadioButton(IconThemeHelper.getImageIcon("line-properties-cap-butt")); |
116 |
capBut.setSelectedIcon(IconThemeHelper.getImageIcon("line-properties-cap-butt-selected"));
|
117 |
toCenter = new JPanel(flowCenteredLayout); |
118 |
toCenter.add(capBut); |
119 |
c.add(toCenter); |
120 |
toCenter = new JPanel(flowCenteredLayout); |
121 |
toCenter.add(new JLabel(Messages.getText("cap_butt"))); |
122 |
c.add(toCenter); |
123 |
pnlCap.add(c); |
124 |
|
125 |
JPanel a = new JPanel(); |
126 |
a.setLayout(new BoxLayout(a, BoxLayout.Y_AXIS)); |
127 |
capRound = new JRadioButton(IconThemeHelper.getImageIcon("line-properties-cap-round")); |
128 |
capRound.setSelectedIcon(IconThemeHelper.getImageIcon("line-properties-cap-round-selected"));
|
129 |
toCenter = new JPanel(flowCenteredLayout); |
130 |
toCenter.add(capRound); |
131 |
a.add(toCenter); |
132 |
toCenter = new JPanel(flowCenteredLayout); |
133 |
toCenter.add(new JLabel(Messages.getText("cap_round"))); |
134 |
a.add(toCenter); |
135 |
pnlCap.add(a); |
136 |
|
137 |
|
138 |
JPanel b = new JPanel(); |
139 |
b.setLayout(new BoxLayout(b, BoxLayout.Y_AXIS)); |
140 |
capSquare = new JRadioButton(IconThemeHelper.getImageIcon("line-properties-cap-square")); |
141 |
capSquare.setSelectedIcon(IconThemeHelper.getImageIcon("line-properties-cap-square-selected"));
|
142 |
toCenter = new JPanel(flowCenteredLayout); |
143 |
toCenter.add(capSquare); |
144 |
|
145 |
b.add(toCenter); |
146 |
toCenter = new JPanel(flowCenteredLayout); |
147 |
toCenter.add(new JLabel(Messages.getText("cap_square"))); |
148 |
b.add(toCenter); |
149 |
pnlCap.add(b); |
150 |
|
151 |
ButtonGroup groupCap = new ButtonGroup(); |
152 |
groupCap.add(capBut); |
153 |
groupCap.add(capRound); |
154 |
groupCap.add(capSquare); |
155 |
aux3.add(pnlCap); |
156 |
|
157 |
JPanel aux4 = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
158 |
aux4.add(new JBlank(5,40)); |
159 |
pe = new PatternEditor();
|
160 |
pe.setPreferredSize(new Dimension(440,40)); |
161 |
aux4.add(pe); |
162 |
aux4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), Messages.getText("fill_pattern")+":")); |
163 |
|
164 |
JPanel aux5 = new JPanel(new FlowLayout(FlowLayout.LEFT,15, 0)); |
165 |
clearButton = new JButton(Messages.getText("clear")); |
166 |
aux5.add(clearButton); |
167 |
|
168 |
joinBevel.addActionListener(this);
|
169 |
joinMiter.addActionListener(this);
|
170 |
joinRound.addActionListener(this);
|
171 |
capBut.addActionListener(this);
|
172 |
capRound.addActionListener(this);
|
173 |
capSquare.addActionListener(this);
|
174 |
clearButton.addActionListener(clear); |
175 |
pe.addActionListener(patternChange); |
176 |
|
177 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
178 |
aux.add(aux2, BorderLayout.CENTER);
|
179 |
aux.add(aux3, BorderLayout.CENTER);
|
180 |
aux.add(aux4, BorderLayout.CENTER);
|
181 |
aux.add(aux5, BorderLayout.WEST);
|
182 |
add(aux, BorderLayout.CENTER);
|
183 |
} |
184 |
|
185 |
public void actionPerformed(ActionEvent e) { |
186 |
callValueChanged(getLinePropertiesStyle()); |
187 |
} |
188 |
|
189 |
private ActionListener patternChange = new ActionListener() { |
190 |
public void actionPerformed(ActionEvent e) { |
191 |
callValueChanged(getLinePropertiesStyle()); |
192 |
} |
193 |
}; |
194 |
|
195 |
private ActionListener clear = new ActionListener() { |
196 |
public void actionPerformed(ActionEvent e) { |
197 |
pe.clear_Dash(); |
198 |
callValueChanged(getLinePropertiesStyle()); |
199 |
} |
200 |
}; |
201 |
|
202 |
|
203 |
|
204 |
public void setLinePropertiesStyle(BasicStroke str) { |
205 |
|
206 |
if (str == null) { |
207 |
str = new BasicStroke(); |
208 |
} |
209 |
|
210 |
switch(str.getLineJoin()) {
|
211 |
case 0: |
212 |
joinMiter.setSelected(true);
|
213 |
break;
|
214 |
case 1: |
215 |
joinRound.setSelected(true);
|
216 |
break;
|
217 |
case 2: |
218 |
joinBevel.setSelected(true);
|
219 |
break;
|
220 |
} |
221 |
|
222 |
switch(str.getEndCap()) {
|
223 |
case 0: |
224 |
capBut.setSelected(true);
|
225 |
break;
|
226 |
case 1: |
227 |
capRound.setSelected(true);
|
228 |
break;
|
229 |
case 2: |
230 |
capSquare.setSelected(true);
|
231 |
break;
|
232 |
} |
233 |
|
234 |
pe.setDash(str.getDashArray()); |
235 |
pe.repaint(); |
236 |
} |
237 |
|
238 |
public BasicStroke getLinePropertiesStyle() { |
239 |
int capType=0, joinType=0; |
240 |
|
241 |
|
242 |
if (capBut.isSelected()) capType = 0; |
243 |
else if (capRound.isSelected()) capType = 1; |
244 |
else if (capSquare.isSelected()) capType = 2; |
245 |
|
246 |
if (joinMiter.isSelected()) joinType = 0; |
247 |
else if (joinRound.isSelected()) joinType = 1; |
248 |
else if (joinBevel.isSelected()) joinType = 2; |
249 |
|
250 |
float [] dash = pe.getDash(); |
251 |
|
252 |
BasicStroke str = new BasicStroke(width, capType, joinType, 10, pe.getDash(), 0); |
253 |
pe.setDash(dash); |
254 |
return str;
|
255 |
} |
256 |
} |