Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / styling / SimpleMarker.java @ 29596

History | View | Annotate | Download (9.17 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

    
42
/* CVS MESSAGES:
43
 *
44
 * $Id: SimpleMarker.java 29596 2009-06-29 16:02:00Z jpiera $
45
 * $Log$
46
 * Revision 1.15  2007-08-14 11:10:20  jvidal
47
 * javadoc updated
48
 *
49
 * Revision 1.14  2007/08/08 11:49:15  jaume
50
 * refactored to avoid provide more than one EditorTool
51
 *
52
 * Revision 1.13  2007/08/07 11:20:11  jvidal
53
 * javadoc
54
 *
55
 * Revision 1.12  2007/08/03 11:29:13  jaume
56
 * refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
57
 *
58
 * Revision 1.11  2007/07/18 06:56:03  jaume
59
 * continuing with cartographic support
60
 *
61
 * Revision 1.10  2007/07/12 10:43:55  jaume
62
 * *** empty log message ***
63
 *
64
 * Revision 1.9  2007/05/31 09:36:22  jaume
65
 * *** empty log message ***
66
 *
67
 * Revision 1.8  2007/05/29 15:47:06  jaume
68
 * *** empty log message ***
69
 *
70
 * Revision 1.7  2007/05/21 10:38:27  jaume
71
 * *** empty log message ***
72
 *
73
 * Revision 1.6  2007/05/09 16:08:14  jaume
74
 * *** empty log message ***
75
 *
76
 * Revision 1.5  2007/04/27 12:10:17  jaume
77
 * *** empty log message ***
78
 *
79
 * Revision 1.4  2007/04/05 16:08:34  jaume
80
 * Styled labeling stuff
81
 *
82
 * Revision 1.3  2007/04/04 16:01:14  jaume
83
 * *** empty log message ***
84
 *
85
 * Revision 1.2  2007/03/09 11:25:00  jaume
86
 * Advanced symbology (start committing)
87
 *
88
 * Revision 1.1.2.4  2007/02/21 07:35:14  jaume
89
 * *** empty log message ***
90
 *
91
 * Revision 1.1.2.3  2007/02/08 15:43:04  jaume
92
 * some bug fixes in the editor and removed unnecessary imports
93
 *
94
 * Revision 1.1.2.2  2007/01/30 18:10:10  jaume
95
 * start commiting labeling stuff
96
 *
97
 * Revision 1.1.2.1  2007/01/26 13:49:03  jaume
98
 * *** empty log message ***
99
 *
100
 *
101
 */
102
package org.gvsig.app.gui.styling;
103

    
104
import java.awt.Color;
105
import java.awt.Dimension;
106
import java.awt.FlowLayout;
107
import java.awt.event.ActionEvent;
108
import java.awt.event.ActionListener;
109
import java.awt.event.FocusEvent;
110
import java.awt.event.FocusListener;
111
import java.awt.geom.Point2D;
112
import java.util.ArrayList;
113

    
114
import javax.swing.JCheckBox;
115
import javax.swing.JPanel;
116

    
117
import org.gvsig.andami.PluginServices;
118
import org.gvsig.andami.messages.NotificationManager;
119
import org.gvsig.app.gui.panels.ColorChooserPanel;
120
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
121
import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleMarkerSymbol;
122
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
123
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
124

    
125

    
126
/**
127
 * SimpleMarker allows the user to store and modify the main properties that
128
 * define a <b>simple marker</b>.<p>
129
 * <p>
130
 * This functionality is carried out thanks to a tab (simple marker and mask)
131
 * which are included in the panel to edit the properities of a symbol (SymbolEditor)
132
 * how is explained in AbstractTypeSymbolEditor.<p>
133
 * <p>
134
 * This tab (Simple Marker)allows the user to change the different attributes
135
 * which are color (<b>jccColor</b>),text size (<b>txtSize</b>),text offset
136
 * (<b>txtXOffset</b> and <b>txtXOffset</b>), style of the marker (<b></b>)
137
 * the width (<b>txtWidth</b>) and the style of the line (<b>cmbStyle</b>)
138
 * and the color of the outline(<b>jccOutlineColor</b>).<p>
139
 *
140
 *@see Mask
141
 *@see AbstractTypeSymbolEditor
142
 *@author jaume dominguez faus - jaume.dominguez@iver.es
143
 */
144
public class SimpleMarker extends AbstractTypeSymbolEditor implements ActionListener, FocusListener{
145

    
146
        private ArrayList tabs = new ArrayList();
147
        private ColorChooserPanel jccColor;
148
        private JIncrementalNumberField txtSize;
149
        private JIncrementalNumberField txtXOffset;
150
        private JIncrementalNumberField txtYOffset;
151
        //TODO: Comentarizado hasta que mask est? acabado
152
//        private Mask mask;
153
        private JComboBoxSimpleMarkeStyles cmbStyle;
154
        private JCheckBox chkUseOutline;
155
        private ColorChooserPanel jccOutlineColor;
156

    
157
        public SimpleMarker(SymbolEditor owner) {
158
                super(owner);
159
                initialize();
160
        }
161
        /**
162
         * Initializes the parameters that define a simplemarker.To do it,
163
         * a tab is created inside the SymbolEditor panel with default values
164
         *  for the different attributes of the simple marker.Also, a mask will be
165
         *  added as a new tab.
166
         */
167

    
168
        private void initialize() {
169
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
170
                myTab.setName(PluginServices.getText(this, "simple_marker"));
171
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
172

    
173
                // color chooser
174
                jccColor = new ColorChooserPanel(true);
175
                jccColor.setAlpha(255);
176

    
177
                aux.addComponent(PluginServices.getText(this, "color")+":",
178
                                jccColor        );
179

    
180
                // marker width
181
                txtSize = new JIncrementalNumberField("5", 25);
182
                aux.addComponent(PluginServices.getText(this, "size")+":",
183
                                txtSize );
184
                txtSize.setDouble(5);
185

    
186
                // marker xOffset
187
                txtXOffset = new JIncrementalNumberField("0", 25);
188
                aux.addComponent(PluginServices.getText(this, "x_offset")+":",
189
                                txtXOffset );
190

    
191

    
192
                // marker width
193
                txtYOffset = new JIncrementalNumberField("0", 25);
194
                aux.addComponent(PluginServices.getText(this, "y_offset")+":",
195
                                txtYOffset );
196

    
197
                // marker style
198
                cmbStyle = new JComboBoxSimpleMarkeStyles();
199
                aux.addComponent(PluginServices.getText(this, "marker_style")+":",
200
                                cmbStyle);
201

    
202
                // use outline
203
                chkUseOutline = new JCheckBox(PluginServices.getText(this, "use_outline"));
204
                aux.addComponent(chkUseOutline);
205

    
206
                // outline color
207
                jccOutlineColor = new ColorChooserPanel(true);
208
                jccOutlineColor.setAlpha(255);
209
                aux.addComponent(PluginServices.getText(this, "outline_color"), jccOutlineColor);
210

    
211
                aux.setPreferredSize(new Dimension(300, 300));
212
                myTab.add(aux);
213

    
214
                // initialize defaults
215
                jccColor.setColor(Color.BLACK);
216
                cmbStyle.setSymbolColor(jccColor.getColor());
217

    
218

    
219
                jccColor.addActionListener(this);
220
                txtSize.addActionListener(this);
221
                txtSize.addFocusListener(this);
222
                txtXOffset.addActionListener(this);
223
                txtXOffset.addFocusListener(this);
224
                txtYOffset.addActionListener(this);
225
                txtYOffset.addFocusListener(this);
226
                cmbStyle.addActionListener(this);
227
                chkUseOutline.addActionListener(this);
228
                jccOutlineColor.addActionListener(this);
229

    
230
                tabs.add(myTab);
231

    
232
//                mask = new Mask(this);
233
//                tabs.add(mask);
234
        }
235

    
236
        public ISymbol getLayer() {
237
                SimpleMarkerSymbol layer = new SimpleMarkerSymbol();
238
                layer.setColor(jccColor.getColor());
239
                layer.setIsShapeVisible(true);
240
                layer.setSize(txtSize.getDouble());
241
//                layer.setUnit(owner.getUnit());
242
//                layer.setReferenceSystem(owner.getUnitsReferenceSystem());
243
                layer.setOffset(new Point2D.Double(
244
                                txtXOffset.getDouble(),
245
                                txtYOffset.getDouble()));
246
//                layer.setMask(mask.getMask());
247
                layer.setStyle(((Integer) cmbStyle.getSelectedItem()).intValue());
248
                layer.setOutlined(chkUseOutline.isSelected());
249
                layer.setOutlineColor(jccOutlineColor.getColor());
250
                return layer;
251
        }
252

    
253
        public String getName() {
254
                return PluginServices.getText(this, "simple_marker_symbol");
255
        }
256

    
257
        public JPanel[] getTabs() {
258
                return (JPanel[]) tabs.toArray(new JPanel[0]);
259
        }
260

    
261
        public void refreshControls(ISymbol layer) {
262
                SimpleMarkerSymbol sym;
263
                try {
264
                        if (layer == null) {
265
                                // initialize defaults
266
                                System.err.println("SimpleLine.java:: should be unreachable code");
267
                                jccColor.setColor(Color.BLACK);
268

    
269
                                txtSize.setDouble(1.0);
270
                                txtXOffset.setDouble(0.0);
271
                                txtYOffset.setDouble(0.0);
272
                        } else {
273
                                sym = (SimpleMarkerSymbol) layer;
274
                                jccColor.setColor(sym.getColor());
275

    
276
                                txtSize.setDouble(sym.getSize());
277
                                txtXOffset.setDouble(sym.getOffset().getX());
278
                                txtYOffset.setDouble(sym.getOffset().getY());
279
                                cmbStyle.setSymbolColor(sym.getColor());
280
                                chkUseOutline.setSelected(sym.hasOutline());
281
                                cmbStyle.setOutlineColor(sym.getOutlineColor());
282
                                cmbStyle.setSelectedItem(new Integer(sym.getStyle()));
283
                        }
284
                } catch (IndexOutOfBoundsException ioEx) {
285
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
286
                } catch (ClassCastException ccEx) {
287
                        NotificationManager.addWarning("Illegal casting from " +
288
                                        layer.getClassName() + " to " + getSymbolClass().
289
                                        getName() + ".", ccEx);
290

    
291
                }
292
        }
293

    
294
        public Class getSymbolClass() {
295
                return SimpleMarkerSymbol.class;
296
        }
297

    
298
        public void actionPerformed(ActionEvent e) {
299
                fireSymbolChangedEvent();
300
        }
301

    
302
        public EditorTool[] getEditorTools() {
303
                return null;
304
        }
305
        public void focusGained(FocusEvent arg0) {
306
                // TODO Auto-generated method stub
307

    
308
        }
309
        public void focusLost(FocusEvent arg0) {
310
                fireSymbolChangedEvent();
311

    
312
        }
313
}