svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / ArrowDecorator.java @ 27580
History | View | Annotate | Download (8.92 KB)
1 | 12729 | jaume | /* 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 | 12805 | jaume | import java.awt.event.ActionEvent; |
46 | import java.awt.event.ActionListener; |
||
47 | 12729 | jaume | |
48 | import javax.swing.BorderFactory; |
||
49 | import javax.swing.ButtonGroup; |
||
50 | import javax.swing.JCheckBox; |
||
51 | 13939 | jvidal | import javax.swing.JComponent; |
52 | 12729 | jaume | import javax.swing.JPanel; |
53 | import javax.swing.JRadioButton; |
||
54 | |||
55 | 12805 | jaume | import org.gvsig.gui.beans.DefaultBean; |
56 | 12729 | jaume | 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 | 13939 | jvidal | import com.iver.cit.gvsig.fmap.core.FShape; |
63 | 12729 | jaume | import com.iver.cit.gvsig.fmap.core.styles.ArrowDecoratorStyle; |
64 | 12805 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.ArrowMarkerSymbol; |
65 | import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
||
66 | 18623 | jdominguez | import com.iver.cit.gvsig.gui.styling.SymbolSelector; |
67 | 13939 | jvidal | import com.iver.cit.gvsig.project.documents.view.legend.gui.ISymbolSelector; |
68 | 12729 | jaume | |
69 | /**
|
||
70 | 13072 | jvidal | * Implements a tab to modify attributes of an arrow decorator (size,
|
71 | 13004 | jaume | * arrow sharpnss, symbol, number of symbols to draw in the same line and options
|
72 | 12937 | jvidal | * 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 | 12729 | jaume | * @autor jaume dominguez faus - jaume.dominguez@iver.es
|
83 | */
|
||
84 | 12805 | jaume | public class ArrowDecorator extends DefaultBean implements ActionListener { |
85 | 12729 | jaume | |
86 | private JCheckBox chkFlipAll; |
||
87 | private JCheckBox chkFlipFirst; |
||
88 | private JRadioButton rdBtnFollowLine; |
||
89 | private JRadioButton rdBtnFixedAngle; |
||
90 | private JIncrementalNumberField incrPositionCount;
|
||
91 | 13004 | jaume | private JIncrementalNumberField incrSharpness;
|
92 | 12729 | jaume | private JCheckBox chkUseDecorator; |
93 | 12805 | jaume | private IMarkerSymbol marker;
|
94 | private JIncrementalNumberField incrSize;
|
||
95 | 13939 | jvidal | private JButton btnOpenSymbolSelector; |
96 | 12729 | jaume | |
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 | 12937 | jvidal | |
106 | 12729 | jaume | chkUseDecorator = new JCheckBox(PluginServices.getText(this, "use_decorator")); |
107 | 12937 | jvidal | |
108 | 12729 | jaume | JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
109 | 12805 | jaume | GridBagLayoutPanel pnlTopOptions = new GridBagLayoutPanel();
|
110 | pnlTopOptions.addComponent(chkUseDecorator); |
||
111 | pnlTopOptions.addComponent(PluginServices.getText(this, "size"), |
||
112 | incrSize = new JIncrementalNumberField(
|
||
113 | 12937 | jvidal | "0",
|
114 | 12805 | jaume | 5,
|
115 | ValidatingTextField.DOUBLE_VALIDATOR, |
||
116 | ValidatingTextField.NUMBER_CLEANER, |
||
117 | 0,
|
||
118 | Integer.MAX_VALUE,
|
||
119 | 1)
|
||
120 | ); |
||
121 | 13004 | jaume | pnlTopOptions.addComponent(PluginServices.getText(this, "arrow_sharpness"), |
122 | incrSharpness = new JIncrementalNumberField(
|
||
123 | 12937 | jvidal | "0",
|
124 | 12805 | jaume | 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 | 12937 | jvidal | "0",
|
134 | 12729 | jaume | 5,
|
135 | ValidatingTextField.INTEGER_VALIDATOR, |
||
136 | ValidatingTextField.NUMBER_CLEANER, |
||
137 | 0,
|
||
138 | Integer.MAX_VALUE,
|
||
139 | 12805 | jaume | 1)
|
140 | ); |
||
141 | 13939 | jvidal | // 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 | 12805 | jaume | JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT,5, 0)); |
148 | 13939 | jvidal | aux3.add(getBtnOpenSymbolSelector()); |
149 | 12805 | jaume | aux2.add(aux3); |
150 | 13939 | jvidal | |
151 | 12805 | jaume | pnlTopOptions.addComponent(PluginServices.getText(this, "number_of_positions")+":", aux2); |
152 | aux.add(pnlTopOptions); |
||
153 | add(aux, BorderLayout.NORTH);
|
||
154 | 12937 | jvidal | |
155 | 12805 | jaume | aux = new JPanel(new BorderLayout(5,5)); |
156 | 12729 | jaume | 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 | 12937 | jvidal | |
162 | |||
163 | 12729 | jaume | aux2.add(pnlFlip); |
164 | 12937 | jvidal | |
165 | 12729 | jaume | 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 | 12937 | jvidal | |
174 | 12805 | jaume | chkUseDecorator.addActionListener(this);
|
175 | incrPositionCount.addActionListener(this);
|
||
176 | 13004 | jaume | incrSharpness.addActionListener(this);
|
177 | 12805 | jaume | incrSize.addActionListener(this);
|
178 | chkFlipFirst.addActionListener(this);
|
||
179 | chkFlipAll.addActionListener(this);
|
||
180 | rdBtnFixedAngle.addActionListener(this);
|
||
181 | rdBtnFollowLine.addActionListener(this);
|
||
182 | 12937 | jvidal | |
183 | 12729 | jaume | aux.add(aux2, BorderLayout.CENTER);
|
184 | add(aux, BorderLayout.CENTER);
|
||
185 | } |
||
186 | 12937 | jvidal | |
187 | 13072 | jvidal | /**
|
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 | 12729 | jaume | public void setArrowDecoratorStyle(ArrowDecoratorStyle ads) { |
194 | chkUseDecorator.setSelected(ads!=null);
|
||
195 | 12937 | jvidal | |
196 | 12729 | jaume | if (ads == null) { |
197 | ads = new ArrowDecoratorStyle();
|
||
198 | } |
||
199 | 12937 | jvidal | |
200 | 12805 | jaume | marker = ads.getMarker(); |
201 | if (marker instanceof ArrowMarkerSymbol) { |
||
202 | ArrowMarkerSymbol arrow = (ArrowMarkerSymbol) marker; |
||
203 | 13004 | jaume | incrSharpness.setDouble(arrow.getSharpness()); |
204 | 12805 | jaume | } |
205 | incrSize.setDouble(marker.getSize()); |
||
206 | 12729 | jaume | incrPositionCount.setInteger(ads.getArrowMarkerCount()); |
207 | chkFlipAll.setSelected(ads.isFlipAll()); |
||
208 | chkFlipFirst.setSelected(ads.isFlipFirst()); |
||
209 | rdBtnFollowLine.setSelected(ads.isFollowLineAngle()); |
||
210 | |||
211 | } |
||
212 | 13072 | jvidal | /**
|
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 | 12729 | jaume | public ArrowDecoratorStyle getArrowDecoratorStyle() {
|
221 | if (!chkUseDecorator.isSelected()) return null; |
||
222 | 12937 | jvidal | |
223 | 12729 | jaume | ArrowDecoratorStyle ads = new ArrowDecoratorStyle();
|
224 | 12980 | jaume | if (marker == null) { |
225 | marker = ads.getMarker(); |
||
226 | } |
||
227 | 13072 | jvidal | |
228 | 12805 | jaume | if (marker instanceof ArrowMarkerSymbol) { |
229 | ArrowMarkerSymbol arrow = (ArrowMarkerSymbol) marker; |
||
230 | 13004 | jaume | arrow.setSharpness(incrSharpness.getDouble()); |
231 | 12805 | jaume | } |
232 | marker.setSize(incrSize.getDouble()); |
||
233 | ads.setMarker(marker); |
||
234 | 12729 | jaume | ads.setArrowMarkerCount(incrPositionCount.getInteger()); |
235 | ads.setFlipAll(chkFlipAll.isSelected()); |
||
236 | ads.setFlipFirst(chkFlipFirst.isSelected()); |
||
237 | ads.setFollowLineAngle(rdBtnFollowLine.isSelected()); |
||
238 | return ads;
|
||
239 | } |
||
240 | 12937 | jvidal | |
241 | 13939 | jvidal | |
242 | 12805 | jaume | public void actionPerformed(ActionEvent e) { |
243 | 13939 | jvidal | 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 | 12805 | jaume | boolean isArrow = marker instanceof ArrowMarkerSymbol; |
251 | 13004 | jaume | incrSharpness.setEnabled(isArrow); |
252 | 12937 | jvidal | |
253 | 12805 | jaume | callValueChanged(getArrowDecoratorStyle()); |
254 | } |
||
255 | 13939 | jvidal | |
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 | 12729 | jaume | } |