root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / ArrowDecorator.java @ 21299
History | View | Annotate | Download (8.9 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 |
package com.iver.cit.gvsig.gui.styling; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.FlowLayout; |
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
|
48 |
import javax.swing.BorderFactory; |
49 |
import javax.swing.ButtonGroup; |
50 |
import javax.swing.JCheckBox; |
51 |
import javax.swing.JComponent; |
52 |
import javax.swing.JPanel; |
53 |
import javax.swing.JRadioButton; |
54 |
|
55 |
import org.gvsig.fmap.geom.Geometry; |
56 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ArrowMarkerSymbol; |
57 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMarkerSymbol; |
58 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.ArrowDecoratorStyle; |
59 |
import org.gvsig.gui.beans.DefaultBean; |
60 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
61 |
import org.gvsig.gui.beans.swing.JButton; |
62 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
63 |
import org.gvsig.gui.beans.swing.ValidatingTextField; |
64 |
|
65 |
import com.iver.andami.PluginServices; |
66 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ISymbolSelector; |
67 |
|
68 |
/**
|
69 |
* Implements a tab to modify attributes of an arrow decorator (size,
|
70 |
* arrow sharpnss, symbol, number of symbols to draw in the same line and options
|
71 |
* for flip and rotate the arrow)which allows the user to insert a symbol in the
|
72 |
* line (for example an arrow to specify its orientation)and to modify it.
|
73 |
*
|
74 |
* <p>
|
75 |
* This tab is used several times in different places in our applicattion .For
|
76 |
* this reason, in order to avoid the repetition of code, this class has been
|
77 |
* created (instead of treat it like a simple tab). With this solution, the user
|
78 |
* only has to refer it to use it (and do not need to create a tab and fill it again
|
79 |
* and so on).
|
80 |
|
81 |
* @autor jaume dominguez faus - jaume.dominguez@iver.es
|
82 |
*/
|
83 |
public class ArrowDecorator extends DefaultBean implements ActionListener { |
84 |
|
85 |
private JCheckBox chkFlipAll; |
86 |
private JCheckBox chkFlipFirst; |
87 |
private JRadioButton rdBtnFollowLine; |
88 |
private JRadioButton rdBtnFixedAngle; |
89 |
private JIncrementalNumberField incrPositionCount;
|
90 |
private JIncrementalNumberField incrSharpness;
|
91 |
private JCheckBox chkUseDecorator; |
92 |
private IMarkerSymbol marker;
|
93 |
private JIncrementalNumberField incrSize;
|
94 |
private JButton btnOpenSymbolSelector; |
95 |
|
96 |
public ArrowDecorator() {
|
97 |
super();
|
98 |
initialize(); |
99 |
} |
100 |
|
101 |
private void initialize() { |
102 |
setName(PluginServices.getText(this, "arrow_decorator")); |
103 |
setLayout(new BorderLayout(10, 10)); |
104 |
|
105 |
chkUseDecorator = new JCheckBox(PluginServices.getText(this, "use_decorator")); |
106 |
|
107 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
108 |
GridBagLayoutPanel pnlTopOptions = new GridBagLayoutPanel();
|
109 |
pnlTopOptions.addComponent(chkUseDecorator); |
110 |
pnlTopOptions.addComponent(PluginServices.getText(this, "size"), |
111 |
incrSize = new JIncrementalNumberField(
|
112 |
"0",
|
113 |
5,
|
114 |
ValidatingTextField.DOUBLE_VALIDATOR, |
115 |
ValidatingTextField.NUMBER_CLEANER, |
116 |
0,
|
117 |
Integer.MAX_VALUE,
|
118 |
1)
|
119 |
); |
120 |
pnlTopOptions.addComponent(PluginServices.getText(this, "arrow_sharpness"), |
121 |
incrSharpness = new JIncrementalNumberField(
|
122 |
"0",
|
123 |
5,
|
124 |
ValidatingTextField.DOUBLE_VALIDATOR, |
125 |
ValidatingTextField.NUMBER_CLEANER, |
126 |
0,
|
127 |
Integer.MAX_VALUE,
|
128 |
1)
|
129 |
); |
130 |
JPanel aux2 = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
131 |
aux2.add( incrPositionCount = new JIncrementalNumberField(
|
132 |
"0",
|
133 |
5,
|
134 |
ValidatingTextField.INTEGER_VALIDATOR, |
135 |
ValidatingTextField.NUMBER_CLEANER, |
136 |
0,
|
137 |
Integer.MAX_VALUE,
|
138 |
1)
|
139 |
); |
140 |
// JButton btnChooseSymbol = new JButton(PluginServices.getText(this, "symbol"));
|
141 |
// JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT,5, 0));
|
142 |
// aux3.add(btnChooseSymbol);
|
143 |
// aux2.add(aux3);
|
144 |
|
145 |
|
146 |
JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT,5, 0)); |
147 |
aux3.add(getBtnOpenSymbolSelector()); |
148 |
aux2.add(aux3); |
149 |
|
150 |
pnlTopOptions.addComponent(PluginServices.getText(this, "number_of_positions")+":", aux2); |
151 |
aux.add(pnlTopOptions); |
152 |
add(aux, BorderLayout.NORTH);
|
153 |
|
154 |
aux = new JPanel(new BorderLayout(5,5)); |
155 |
aux2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
156 |
GridBagLayoutPanel pnlFlip = new GridBagLayoutPanel();
|
157 |
pnlFlip.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "flip")+":")); |
158 |
pnlFlip.addComponent(chkFlipAll = new JCheckBox(PluginServices.getText(this, "flip_all"))); |
159 |
pnlFlip.addComponent(chkFlipFirst = new JCheckBox(PluginServices.getText(this, "flip_first"))); |
160 |
|
161 |
|
162 |
aux2.add(pnlFlip); |
163 |
|
164 |
GridBagLayoutPanel pnlRotation = new GridBagLayoutPanel();
|
165 |
pnlRotation.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "rotation")+":")); |
166 |
pnlRotation.addComponent(rdBtnFollowLine = new JRadioButton(PluginServices.getText(this, "rotate_symbol_to_follow_line_angle"))); |
167 |
pnlRotation.addComponent(rdBtnFixedAngle = new JRadioButton(PluginServices.getText(this, "keep_symbol_at_fixed_angle_to_page"))); |
168 |
ButtonGroup group = new ButtonGroup(); |
169 |
group.add(rdBtnFixedAngle); |
170 |
group.add(rdBtnFollowLine); |
171 |
aux2.add(pnlRotation); |
172 |
|
173 |
chkUseDecorator.addActionListener(this);
|
174 |
incrPositionCount.addActionListener(this);
|
175 |
incrSharpness.addActionListener(this);
|
176 |
incrSize.addActionListener(this);
|
177 |
chkFlipFirst.addActionListener(this);
|
178 |
chkFlipAll.addActionListener(this);
|
179 |
rdBtnFixedAngle.addActionListener(this);
|
180 |
rdBtnFollowLine.addActionListener(this);
|
181 |
|
182 |
aux.add(aux2, BorderLayout.CENTER);
|
183 |
add(aux, BorderLayout.CENTER);
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* Defines the attributes that appear in the arrow decorator tab and will
|
188 |
* determine the arrow decorator style.If this style has not been created previosly,
|
189 |
* it will be done.
|
190 |
* @param ads
|
191 |
*/
|
192 |
public void setArrowDecoratorStyle(ArrowDecoratorStyle ads) { |
193 |
chkUseDecorator.setSelected(ads!=null);
|
194 |
|
195 |
if (ads == null) { |
196 |
ads = new ArrowDecoratorStyle();
|
197 |
} |
198 |
|
199 |
marker = ads.getMarker(); |
200 |
if (marker instanceof ArrowMarkerSymbol) { |
201 |
ArrowMarkerSymbol arrow = (ArrowMarkerSymbol) marker; |
202 |
incrSharpness.setDouble(arrow.getSharpness()); |
203 |
} |
204 |
incrSize.setDouble(marker.getSize()); |
205 |
incrPositionCount.setInteger(ads.getArrowMarkerCount()); |
206 |
chkFlipAll.setSelected(ads.isFlipAll()); |
207 |
chkFlipFirst.setSelected(ads.isFlipFirst()); |
208 |
rdBtnFollowLine.setSelected(ads.isFollowLineAngle()); |
209 |
|
210 |
} |
211 |
/**
|
212 |
* Obtains the values of the attributes of an arrow decorator.This attributes
|
213 |
* will be different depending on the type of the symbol that the user had selected
|
214 |
* (because if for example the arrow is changed into a square the sharpness won't
|
215 |
* necessary and so on)
|
216 |
*
|
217 |
* @return
|
218 |
*/
|
219 |
public ArrowDecoratorStyle getArrowDecoratorStyle() {
|
220 |
if (!chkUseDecorator.isSelected()) return null; |
221 |
|
222 |
ArrowDecoratorStyle ads = new ArrowDecoratorStyle();
|
223 |
if (marker == null) { |
224 |
marker = ads.getMarker(); |
225 |
} |
226 |
|
227 |
if (marker instanceof ArrowMarkerSymbol) { |
228 |
ArrowMarkerSymbol arrow = (ArrowMarkerSymbol) marker; |
229 |
arrow.setSharpness(incrSharpness.getDouble()); |
230 |
} |
231 |
marker.setSize(incrSize.getDouble()); |
232 |
ads.setMarker(marker); |
233 |
ads.setArrowMarkerCount(incrPositionCount.getInteger()); |
234 |
ads.setFlipAll(chkFlipAll.isSelected()); |
235 |
ads.setFlipFirst(chkFlipFirst.isSelected()); |
236 |
ads.setFollowLineAngle(rdBtnFollowLine.isSelected()); |
237 |
return ads;
|
238 |
} |
239 |
|
240 |
|
241 |
public void actionPerformed(ActionEvent e) { |
242 |
JComponent c = (JComponent) e.getSource(); |
243 |
if (c.equals(getBtnOpenSymbolSelector())) {
|
244 |
ISymbolSelector se = SymbolSelector.createSymbolSelector(marker, Geometry.TYPES.POINT); |
245 |
PluginServices.getMDIManager().addWindow(se); |
246 |
marker = (IMarkerSymbol) se.getSelectedObject(); |
247 |
|
248 |
} |
249 |
boolean isArrow = marker instanceof ArrowMarkerSymbol; |
250 |
incrSharpness.setEnabled(isArrow); |
251 |
|
252 |
callValueChanged(getArrowDecoratorStyle()); |
253 |
} |
254 |
|
255 |
private JButton getBtnOpenSymbolSelector() { |
256 |
if (btnOpenSymbolSelector == null) { |
257 |
btnOpenSymbolSelector = new JButton(); |
258 |
btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol")); |
259 |
btnOpenSymbolSelector.addActionListener(this);
|
260 |
} |
261 |
return btnOpenSymbolSelector;
|
262 |
} |
263 |
} |