Statistics
| Revision:

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

History | View | Annotate | Download (5.8 KB)

1 10679 jaume
/* 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$
45
* $Log$
46 11073 jaume
* Revision 1.4  2007-04-05 16:08:34  jaume
47
* Styled labeling stuff
48
*
49
* Revision 1.3  2007/04/04 16:01:14  jaume
50 11055 jaume
* *** empty log message ***
51
*
52
* Revision 1.2  2007/03/09 11:25:00  jaume
53 10679 jaume
* Advanced symbology (start committing)
54
*
55
* Revision 1.1.2.4  2007/02/21 07:35:14  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.1.2.3  2007/02/08 15:43:04  jaume
59
* some bug fixes in the editor and removed unnecessary imports
60
*
61
* Revision 1.1.2.2  2007/01/30 18:10:10  jaume
62
* start commiting labeling stuff
63
*
64
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
65
* *** empty log message ***
66
*
67
*
68
*/
69
package com.iver.cit.gvsig.gui.styling;
70
71
import java.awt.BasicStroke;
72
import java.awt.Color;
73
import java.awt.Dimension;
74
import java.awt.FlowLayout;
75
import java.awt.event.ActionEvent;
76
import java.awt.event.ActionListener;
77
import java.awt.geom.Point2D;
78
import java.text.NumberFormat;
79
import java.util.ArrayList;
80
81
import javax.swing.JPanel;
82
83
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
84
85
import com.iver.andami.PluginServices;
86
import com.iver.andami.messages.NotificationManager;
87
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
88
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol;
89
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol;
90
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
91
92
import de.ios.framework.swing.JDecimalField;
93
94 11055 jaume
/**
95
*
96
* @author jaume dominguez faus - jaume.dominguez@iver.es
97
*
98
*/
99 10679 jaume
public class SimpleMarker extends AbstractTypeSymbolEditorPanel implements ActionListener{
100
101
        private ArrayList tabs = new ArrayList();
102
        private ColorChooserPanel jccColor;
103
        private JDecimalField txtSize;
104
        private JDecimalField txtXOffset;
105
        private JDecimalField txtYOffset;
106
107
        public SimpleMarker(SymbolEditor owner) {
108
                super(owner);
109
                initialize();
110
        }
111
112
        private void initialize() {
113
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
114
                myTab.setName(PluginServices.getText(this, "simple_marker"));
115
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
116
117
                // color chooser
118
                jccColor = new ColorChooserPanel();
119
                jccColor.setAlpha(255);
120
121
                aux.addComponent(PluginServices.getText(this, "color")+":",
122
                                jccColor        );
123
124
                // marker width
125
                txtSize = new JDecimalField(25);
126
                aux.addComponent(PluginServices.getText(this, "width")+":",
127
                                txtSize );
128
129
                // marker xOffset
130
                txtXOffset = new JDecimalField(25);
131
                aux.addComponent(PluginServices.getText(this, "x_offset")+":",
132
                                txtXOffset );
133
134
135
                // marker width
136
                txtYOffset = new JDecimalField(25);
137
                aux.addComponent(PluginServices.getText(this, "y_offset")+":",
138
                                txtYOffset );
139
140
                aux.setPreferredSize(new Dimension(300, 300));
141
                myTab.add(aux);
142
143
                // initialize defaults
144
                jccColor.setColor(Color.BLACK);
145
                txtSize.setText(NumberFormat.getInstance().format(1.0));
146
                txtXOffset.setText(NumberFormat.getInstance().format(0));
147
                txtYOffset.setText(NumberFormat.getInstance().format(0));
148
149
                jccColor.addActionListener(this);
150
                txtSize.addActionListener(this);
151
                tabs.add(myTab);
152
        }
153
154
        public ISymbol getLayer() {
155
                SimpleMarkerSymbol sms = new SimpleMarkerSymbol();
156
                sms.setColor(jccColor.getColor());
157
                sms.setIsShapeVisible(true);
158
                sms.setSize(txtSize.getValue().doubleValue());
159
                sms.setOffset(new Point2D.Double(
160
                                txtXOffset.getValue().doubleValue(),
161
                                txtYOffset.getValue().doubleValue()));
162
                return sms;
163
        }
164
165
        public String getName() {
166
                return PluginServices.getText(this, "simple_marker_symbol");
167
        }
168
169
        public JPanel[] getTabs() {
170
                return (JPanel[]) tabs.toArray(new JPanel[0]);
171
        }
172
173
        public void refreshControls(ISymbol layer) {
174
                SimpleMarkerSymbol sym;
175
                try {
176
                        if (layer == null) {
177
                                // initialize defaults
178
                                System.err.println("SimpleLine.java:: should be unreachable code");
179
                                jccColor.setColor(Color.BLACK);
180
                                txtSize.setText(NumberFormat.getInstance().format(1.0));
181
                                txtSize.setText(NumberFormat.getInstance().format(0.0));
182
                                txtSize.setText(NumberFormat.getInstance().format(0.0));
183
                        } else {
184
                                sym = (SimpleMarkerSymbol) layer;
185
                                jccColor.setColor(sym.getColor());
186
                                txtSize.setText(String.valueOf(sym.getSize()));
187
                                txtSize.setText(String.valueOf(sym.getOffset().getX()));
188
                                txtSize.setText(String.valueOf(sym.getOffset().getY()));
189
                        }
190
                } catch (IndexOutOfBoundsException ioEx) {
191
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
192
                } catch (ClassCastException ccEx) {
193
                        NotificationManager.addWarning("Illegal casting from " +
194
                                        layer.getClassName() + " to " + getSymbolClass().
195
                                        getName() + ".", ccEx);
196
197
                }
198
        }
199
200
        public Class getSymbolClass() {
201
                return SimpleMarkerSymbol.class;
202
        }
203
204
        public void actionPerformed(ActionEvent e) {
205
                fireSymbolChangedEvent();
206
        }
207
208 11073 jaume
        public EditorTool getEditorTool() {
209
                return null;
210
        }
211 10679 jaume
}