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