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