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