Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleMarker.java @ 11055

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

    
68
import java.awt.BasicStroke;
69
import java.awt.Color;
70
import java.awt.Dimension;
71
import java.awt.FlowLayout;
72
import java.awt.event.ActionEvent;
73
import java.awt.event.ActionListener;
74
import java.awt.geom.Point2D;
75
import java.text.NumberFormat;
76
import java.util.ArrayList;
77

    
78
import javax.swing.JPanel;
79

    
80
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
81

    
82
import com.iver.andami.PluginServices;
83
import com.iver.andami.messages.NotificationManager;
84
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
85
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol;
86
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol;
87
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
88

    
89
import de.ios.framework.swing.JDecimalField;
90

    
91
/**
92
*
93
* @author jaume dominguez faus - jaume.dominguez@iver.es
94
*
95
*/
96
public class SimpleMarker extends AbstractTypeSymbolEditorPanel implements ActionListener{
97

    
98
        private ArrayList tabs = new ArrayList();
99
        private ColorChooserPanel jccColor;
100
        private JDecimalField txtSize;
101
        private JDecimalField txtXOffset;
102
        private JDecimalField txtYOffset;
103

    
104
        public SimpleMarker(SymbolEditor owner) {
105
                super(owner);
106
                initialize();
107
        }
108

    
109
        private void initialize() {
110
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
111
                myTab.setName(PluginServices.getText(this, "simple_marker"));
112
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
113

    
114
                // color chooser
115
                jccColor = new ColorChooserPanel();
116
                jccColor.setAlpha(255);
117

    
118
                aux.addComponent(PluginServices.getText(this, "color")+":",
119
                                jccColor        );
120

    
121
                // marker width
122
                txtSize = new JDecimalField(25);
123
                aux.addComponent(PluginServices.getText(this, "width")+":",
124
                                txtSize );
125

    
126
                // marker xOffset
127
                txtXOffset = new JDecimalField(25);
128
                aux.addComponent(PluginServices.getText(this, "x_offset")+":",
129
                                txtXOffset );
130

    
131

    
132
                // marker width
133
                txtYOffset = new JDecimalField(25);
134
                aux.addComponent(PluginServices.getText(this, "y_offset")+":",
135
                                txtYOffset );
136

    
137
                aux.setPreferredSize(new Dimension(300, 300));
138
                myTab.add(aux);
139

    
140
                // initialize defaults
141
                jccColor.setColor(Color.BLACK);
142
                txtSize.setText(NumberFormat.getInstance().format(1.0));
143
                txtXOffset.setText(NumberFormat.getInstance().format(0));
144
                txtYOffset.setText(NumberFormat.getInstance().format(0));
145

    
146
                jccColor.addActionListener(this);
147
                txtSize.addActionListener(this);
148
                tabs.add(myTab);
149
        }
150

    
151
        public ISymbol getLayer() {
152
                SimpleMarkerSymbol sms = new SimpleMarkerSymbol();
153
                sms.setColor(jccColor.getColor());
154
                sms.setIsShapeVisible(true);
155
                sms.setSize(txtSize.getValue().doubleValue());
156
                sms.setOffset(new Point2D.Double(
157
                                txtXOffset.getValue().doubleValue(),
158
                                txtYOffset.getValue().doubleValue()));
159
                return sms;
160
        }
161

    
162
        public String getName() {
163
                return PluginServices.getText(this, "simple_marker_symbol");
164
        }
165

    
166
        public JPanel[] getTabs() {
167
                return (JPanel[]) tabs.toArray(new JPanel[0]);
168
        }
169

    
170
        public void refreshControls(ISymbol layer) {
171
                SimpleMarkerSymbol sym;
172
                try {
173
                        if (layer == null) {
174
                                // initialize defaults
175
                                System.err.println("SimpleLine.java:: should be unreachable code");
176
                                jccColor.setColor(Color.BLACK);
177
                                txtSize.setText(NumberFormat.getInstance().format(1.0));
178
                                txtSize.setText(NumberFormat.getInstance().format(0.0));
179
                                txtSize.setText(NumberFormat.getInstance().format(0.0));
180
                        } else {
181
                                sym = (SimpleMarkerSymbol) layer;
182
                                jccColor.setColor(sym.getColor());
183
                                txtSize.setText(String.valueOf(sym.getSize()));
184
                                txtSize.setText(String.valueOf(sym.getOffset().getX()));
185
                                txtSize.setText(String.valueOf(sym.getOffset().getY()));
186
                        }
187
                } catch (IndexOutOfBoundsException ioEx) {
188
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
189
                } catch (ClassCastException ccEx) {
190
                        NotificationManager.addWarning("Illegal casting from " +
191
                                        layer.getClassName() + " to " + getSymbolClass().
192
                                        getName() + ".", ccEx);
193

    
194
                }
195
        }
196

    
197
        public Class getSymbolClass() {
198
                return SimpleMarkerSymbol.class;
199
        }
200

    
201
        public void actionPerformed(ActionEvent e) {
202
                fireSymbolChangedEvent();
203
        }
204

    
205
}