Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / ArrowDecorator.java @ 34291

History | View | Annotate | Download (8.95 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 org.gvsig.app.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.andami.PluginServices;
56
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
57
import org.gvsig.fmap.geom.Geometry;
58
import org.gvsig.gui.beans.DefaultBean;
59
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
60
import org.gvsig.gui.beans.swing.JButton;
61
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
62
import org.gvsig.gui.beans.swing.ValidatingTextField;
63
import org.gvsig.i18n.Messages;
64
import org.gvsig.symbology.SymbologyLocator;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IArrowMarkerSymbol;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
67
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IArrowDecoratorStyle;
68

    
69

    
70
/**
71
 * Implements a tab to modify attributes of an arrow decorator (size,
72
 * arrow sharpnss, symbol, number of symbols to draw in the same line and options
73
 * for flip and rotate the arrow)which allows the user to insert a symbol in the
74
 * line (for example an arrow to specify its orientation)and to modify it.
75
 *
76
 * <p>
77
 * This tab is used several times in different places in our applicattion .For
78
 * this reason, in order to avoid the repetition of code, this class has been
79
 * created (instead of treat it like a simple tab). With this solution, the user
80
 * only has to refer it to use it (and do not need to create a tab and fill it again
81
 * and so on).
82

83
 * @autor jaume dominguez faus - jaume.dominguez@iver.es
84
 */
85
public class ArrowDecorator extends DefaultBean implements ActionListener {
86

    
87
        private JCheckBox chkFlipAll;
88
        private JCheckBox chkFlipFirst;
89
        private JRadioButton rdBtnFollowLine;
90
        private JRadioButton rdBtnFixedAngle;
91
        private JIncrementalNumberField incrPositionCount;
92
        private JIncrementalNumberField incrSharpness;
93
        private JCheckBox chkUseDecorator;
94
        private IMarkerSymbol marker;
95
        private JIncrementalNumberField incrSize;
96
        private JButton btnOpenSymbolSelector;
97

    
98
        public ArrowDecorator() {
99
                super();
100
                initialize();
101
        }
102

    
103
        private void initialize() {
104
                setName(Messages.getText("arrow_decorator"));
105
                setLayout(new BorderLayout(10, 10));
106

    
107
                chkUseDecorator = new JCheckBox(Messages.getText("use_decorator"));
108

    
109
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEFT));
110
                GridBagLayoutPanel pnlTopOptions = new GridBagLayoutPanel();
111
                pnlTopOptions.addComponent(chkUseDecorator);
112
                pnlTopOptions.addComponent(Messages.getText("size"),
113
                                incrSize = new  JIncrementalNumberField(
114
                                                "0",
115
                                                5,
116
                                                ValidatingTextField.DOUBLE_VALIDATOR,
117
                                                ValidatingTextField.NUMBER_CLEANER,
118
                                                0,
119
                                                Integer.MAX_VALUE,
120
                                                1)
121
                );
122
                pnlTopOptions.addComponent(Messages.getText("arrow_sharpness"),
123
                                incrSharpness = new  JIncrementalNumberField(
124
                                                "0",
125
                                                5,
126
                                                ValidatingTextField.DOUBLE_VALIDATOR,
127
                                                ValidatingTextField.NUMBER_CLEANER,
128
                                                0,
129
                                                Integer.MAX_VALUE,
130
                                                1)
131
                );
132
                JPanel aux2 = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
133
                aux2.add(        incrPositionCount = new JIncrementalNumberField(
134
                                "0",
135
                                5,
136
                                ValidatingTextField.INTEGER_VALIDATOR,
137
                                ValidatingTextField.NUMBER_CLEANER,
138
                                0,
139
                                Integer.MAX_VALUE,
140
                                1)
141
                );
142
//                JButton btnChooseSymbol = new JButton(Messages.getText("symbol"));
143
//                JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT,5, 0));
144
//                aux3.add(btnChooseSymbol);
145
//                aux2.add(aux3);
146

    
147

    
148
                JPanel aux3 = new JPanel(new FlowLayout(FlowLayout.LEFT,5, 0));
149
                aux3.add(getBtnOpenSymbolSelector());
150
                aux2.add(aux3);
151

    
152
                pnlTopOptions.addComponent(Messages.getText("number_of_positions")+":", aux2);
153
                aux.add(pnlTopOptions);
154
                add(aux, BorderLayout.NORTH);
155

    
156
                aux = new JPanel(new BorderLayout(5,5));
157
                aux2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
158
                GridBagLayoutPanel pnlFlip = new GridBagLayoutPanel();
159
                pnlFlip.setBorder(BorderFactory.createTitledBorder(Messages.getText("flip")+":"));
160
                pnlFlip.addComponent(chkFlipAll = new JCheckBox(Messages.getText("flip_all")));
161
                pnlFlip.addComponent(chkFlipFirst = new JCheckBox(Messages.getText("flip_first")));
162

    
163

    
164
                aux2.add(pnlFlip);
165

    
166
                GridBagLayoutPanel pnlRotation = new GridBagLayoutPanel();
167
                pnlRotation.setBorder(BorderFactory.createTitledBorder(Messages.getText("rotation")+":"));
168
                pnlRotation.addComponent(rdBtnFollowLine = new JRadioButton(Messages.getText("rotate_symbol_to_follow_line_angle")));
169
                pnlRotation.addComponent(rdBtnFixedAngle = new JRadioButton(Messages.getText("keep_symbol_at_fixed_angle_to_page")));
170
                ButtonGroup group = new ButtonGroup();
171
                group.add(rdBtnFixedAngle);
172
                group.add(rdBtnFollowLine);
173
                aux2.add(pnlRotation);
174

    
175
                chkUseDecorator.addActionListener(this);
176
                incrPositionCount.addActionListener(this);
177
                incrSharpness.addActionListener(this);
178
                incrSize.addActionListener(this);
179
                chkFlipFirst.addActionListener(this);
180
                chkFlipAll.addActionListener(this);
181
                rdBtnFixedAngle.addActionListener(this);
182
                rdBtnFollowLine.addActionListener(this);
183

    
184
                aux.add(aux2, BorderLayout.CENTER);
185
                add(aux, BorderLayout.CENTER);
186
        }
187

    
188
        /**
189
         * Defines  the attributes that appear in the arrow decorator tab and will
190
         * determine the arrow decorator style.If this style has not been created previosly,
191
         * it will be done.
192
         * @param ads
193
         */
194
        public void setArrowDecoratorStyle(IArrowDecoratorStyle ads) {
195
                chkUseDecorator.setSelected(ads!=null);
196

    
197
                if (ads == null) {
198
                        ads = SymbologyLocator.getSymbologyManager().createArrowDecoratorStyle();
199
                }
200

    
201
                marker = ads.getMarker();
202
                if (marker instanceof IArrowMarkerSymbol) {
203
                        IArrowMarkerSymbol arrow = (IArrowMarkerSymbol) marker;
204
                        incrSharpness.setDouble(arrow.getSharpness());
205
                }
206
                incrSize.setDouble(marker.getSize());
207
                incrPositionCount.setInteger(ads.getArrowMarkerCount());
208
                chkFlipAll.setSelected(ads.isFlipAll());
209
                chkFlipFirst.setSelected(ads.isFlipFirst());
210
                rdBtnFollowLine.setSelected(ads.isFollowLineAngle());
211

    
212
        }
213
        /**
214
         * Obtains the values of the attributes of an arrow decorator.This attributes
215
         * will be different depending on the type of the symbol that the user had selected
216
         * (because if for example the arrow is changed into a square the sharpness won't
217
         * necessary and so on)
218
         *
219
         * @return
220
         */
221
        public IArrowDecoratorStyle getArrowDecoratorStyle() {
222
                if (!chkUseDecorator.isSelected()) return null;
223

    
224
                IArrowDecoratorStyle ads = SymbologyLocator.getSymbologyManager().createArrowDecoratorStyle();
225
                if (marker == null) {
226
                        marker = ads.getMarker();
227
                }
228

    
229
                if (marker instanceof IArrowMarkerSymbol) {
230
                        IArrowMarkerSymbol arrow = (IArrowMarkerSymbol) marker;
231
                        arrow.setSharpness(incrSharpness.getDouble());
232
                }
233
                marker.setSize(incrSize.getDouble());
234
                ads.setMarker(marker);
235
                ads.setArrowMarkerCount(incrPositionCount.getInteger());
236
                ads.setFlipAll(chkFlipAll.isSelected());
237
                ads.setFlipFirst(chkFlipFirst.isSelected());
238
                ads.setFollowLineAngle(rdBtnFollowLine.isSelected());
239
                return ads;
240
        }
241

    
242

    
243
        public void actionPerformed(ActionEvent e) {
244
                JComponent c = (JComponent) e.getSource();
245
                if (c.equals(getBtnOpenSymbolSelector())) {
246
                        ISymbolSelector se = SymbolSelector.createSymbolSelector(marker, Geometry.TYPES.POINT);
247
                        PluginServices.getMDIManager().addWindow(se);
248
                        marker = (IMarkerSymbol) se.getSelectedObject();
249

    
250
                }
251
                boolean isArrow = marker instanceof IArrowMarkerSymbol;
252
                incrSharpness.setEnabled(isArrow);
253

    
254
                callValueChanged(getArrowDecoratorStyle());
255
        }
256

    
257
        private JButton getBtnOpenSymbolSelector() {
258
                if (btnOpenSymbolSelector == null) {
259
                        btnOpenSymbolSelector = new JButton();
260
                        btnOpenSymbolSelector.setText(Messages.getText("choose_symbol"));
261
                        btnOpenSymbolSelector.addActionListener(this);
262
                }
263
                return btnOpenSymbolSelector;
264
        }
265
}