Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleMarker.java @ 11548

History | View | Annotate | Download (6.24 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 11548 2007-05-09 16:08:14Z jaume $
45
* $Log$
46
* Revision 1.6  2007-05-09 16:08:14  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.5  2007/04/27 12:10:17  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.4  2007/04/05 16:08:34  jaume
53
* Styled labeling stuff
54
*
55
* Revision 1.3  2007/04/04 16:01:14  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.2  2007/03/09 11:25:00  jaume
59
* Advanced symbology (start committing)
60
*
61
* Revision 1.1.2.4  2007/02/21 07:35:14  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.1.2.3  2007/02/08 15:43:04  jaume
65
* some bug fixes in the editor and removed unnecessary imports
66
*
67
* Revision 1.1.2.2  2007/01/30 18:10:10  jaume
68
* start commiting labeling stuff
69
*
70
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
71
* *** empty log message ***
72
*
73
*
74
*/
75
package com.iver.cit.gvsig.gui.styling;
76

    
77
import java.awt.Color;
78
import java.awt.Dimension;
79
import java.awt.FlowLayout;
80
import java.awt.event.ActionEvent;
81
import java.awt.event.ActionListener;
82
import java.awt.geom.Point2D;
83
import java.text.NumberFormat;
84
import java.util.ArrayList;
85

    
86
import javax.swing.JPanel;
87

    
88
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
89

    
90
import com.iver.andami.PluginServices;
91
import com.iver.andami.messages.NotificationManager;
92
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
93
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol;
94
import com.iver.cit.gvsig.gui.IncrementalNumberField;
95
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
96

    
97
/**
98
*
99
* @author jaume dominguez faus - jaume.dominguez@iver.es
100
*
101
*/
102
public class SimpleMarker extends AbstractTypeSymbolEditorPanel implements ActionListener{
103

    
104
        private ArrayList tabs = new ArrayList();
105
        private ColorChooserPanel jccColor;
106
        private IncrementalNumberField txtSize;
107
        private IncrementalNumberField txtXOffset;
108
        private IncrementalNumberField txtYOffset;
109
        private Mask mask;
110

    
111
        public SimpleMarker(SymbolEditor owner) {
112
                super(owner);
113
                initialize();
114
        }
115

    
116
        private void initialize() {
117
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
118
                myTab.setName(PluginServices.getText(this, "simple_marker"));
119
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
120

    
121
                // color chooser
122
                jccColor = new ColorChooserPanel();
123
                jccColor.setAlpha(255);
124

    
125
                aux.addComponent(PluginServices.getText(this, "color")+":",
126
                                jccColor        );
127

    
128
                // marker width
129
                txtSize = new IncrementalNumberField("3", 25);
130
                aux.addComponent(PluginServices.getText(this, "width")+":",
131
                                txtSize );
132

    
133
                // marker xOffset
134
                txtXOffset = new IncrementalNumberField("0", 25);
135
                aux.addComponent(PluginServices.getText(this, "x_offset")+":",
136
                                txtXOffset );
137

    
138

    
139
                // marker width
140
                txtYOffset = new IncrementalNumberField("0", 25);
141
                aux.addComponent(PluginServices.getText(this, "y_offset")+":",
142
                                txtYOffset );
143

    
144
                aux.setPreferredSize(new Dimension(300, 300));
145
                myTab.add(aux);
146

    
147
                // initialize defaults
148
                jccColor.setColor(Color.BLACK);
149
//                txtSize.setText(NumberFormat.getInstance().format(1.0));
150
//                txtXOffset.setText(NumberFormat.getInstance().format(0));
151
//                txtYOffset.setText(NumberFormat.getInstance().format(0));
152

    
153
                jccColor.addActionListener(this);
154
                txtSize.addActionListener(this);
155

    
156
                tabs.add(myTab);
157

    
158
                mask = new Mask(this);
159
                tabs.add(mask);
160
        }
161

    
162
        public ISymbol getLayer() {
163
                SimpleMarkerSymbol sms = new SimpleMarkerSymbol();
164
                sms.setColor(jccColor.getColor());
165
                sms.setIsShapeVisible(true);
166
                sms.setSize(txtSize.getDouble());
167
                sms.setOffset(new Point2D.Double(
168
                                txtXOffset.getDouble(),
169
                                txtYOffset.getDouble()));
170
                sms.setMask(mask.getMask());
171
                return sms;
172
        }
173

    
174
        public String getName() {
175
                return PluginServices.getText(this, "simple_marker_symbol");
176
        }
177

    
178
        public JPanel[] getTabs() {
179
                return (JPanel[]) tabs.toArray(new JPanel[0]);
180
        }
181

    
182
        public void refreshControls(ISymbol layer) {
183
                SimpleMarkerSymbol sym;
184
                try {
185
                        if (layer == null) {
186
                                // initialize defaults
187
                                System.err.println("SimpleLine.java:: should be unreachable code");
188
                                jccColor.setColor(Color.BLACK);
189
//                                txtSize.setText(NumberFormat.getInstance().format(1.0));
190
//                                txtXOffset.setText(NumberFormat.getInstance().format(0.0));
191
//                                txtYOffset.setText(NumberFormat.getInstance().format(0.0));
192
                                txtSize.setDouble(1.0);
193
                                txtXOffset.setDouble(0.0);
194
                                txtYOffset.setDouble(0.0);
195
                        } else {
196
                                sym = (SimpleMarkerSymbol) layer;
197
                                jccColor.setColor(sym.getColor());
198
//                                txtSize.setText(String.valueOf(sym.getSize()));
199
//                                txtXOffset.setText(String.valueOf(sym.getOffset().getX()));
200
//                                txtYOffset.setText(String.valueOf(sym.getOffset().getY()));
201
                                txtSize.setDouble(sym.getSize());
202
                                txtXOffset.setDouble(sym.getOffset().getX());
203
                                txtYOffset.setDouble(sym.getOffset().getY());
204

    
205
                        }
206
                } catch (IndexOutOfBoundsException ioEx) {
207
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
208
                } catch (ClassCastException ccEx) {
209
                        NotificationManager.addWarning("Illegal casting from " +
210
                                        layer.getClassName() + " to " + getSymbolClass().
211
                                        getName() + ".", ccEx);
212

    
213
                }
214
        }
215

    
216
        public Class getSymbolClass() {
217
                return SimpleMarkerSymbol.class;
218
        }
219

    
220
        public void actionPerformed(ActionEvent e) {
221
                fireSymbolChangedEvent();
222
        }
223

    
224
        public EditorTool getEditorTool() {
225
                return null;
226
        }
227
}