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