Statistics
| Revision:

svn-gvsig-desktop / branches / simbologia / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleMarker.java @ 10437

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

    
62
import java.awt.BasicStroke;
63
import java.awt.Color;
64
import java.awt.Dimension;
65
import java.awt.FlowLayout;
66
import java.awt.event.ActionEvent;
67
import java.awt.event.ActionListener;
68
import java.awt.geom.Point2D;
69
import java.text.NumberFormat;
70
import java.util.ArrayList;
71

    
72
import javax.swing.JPanel;
73

    
74
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
75

    
76
import com.iver.andami.PluginServices;
77
import com.iver.andami.messages.NotificationManager;
78
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
79
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol;
80
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol;
81
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
82

    
83
import de.ios.framework.swing.JDecimalField;
84

    
85
public class SimpleMarker extends AbstractTypeSymbolEditorPanel implements ActionListener{
86

    
87
        private ArrayList tabs = new ArrayList();
88
        private ColorChooserPanel jccColor;
89
        private JDecimalField txtSize;
90
        private JDecimalField txtXOffset;
91
        private JDecimalField txtYOffset;
92

    
93
        public SimpleMarker(SymbolEditor owner) {
94
                super(owner);
95
                initialize();
96
        }
97

    
98
        private void initialize() {
99
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
100
                myTab.setName(PluginServices.getText(this, "simple_marker"));
101
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
102

    
103
                // color chooser
104
                jccColor = new ColorChooserPanel();
105
                jccColor.setAlpha(255);
106

    
107
                aux.addComponent(PluginServices.getText(this, "color")+":",
108
                                jccColor        );
109

    
110
                // marker width
111
                txtSize = new JDecimalField(25);
112
                aux.addComponent(PluginServices.getText(this, "width")+":",
113
                                txtSize );
114

    
115
                // marker xOffset
116
                txtXOffset = new JDecimalField(25);
117
                aux.addComponent(PluginServices.getText(this, "x_offset")+":",
118
                                txtXOffset );
119

    
120

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

    
126
                aux.setPreferredSize(new Dimension(300, 300));
127
                myTab.add(aux);
128

    
129
                // initialize defaults
130
                jccColor.setColor(Color.BLACK);
131
                txtSize.setText(NumberFormat.getInstance().format(1.0));
132
                txtXOffset.setText(NumberFormat.getInstance().format(0));
133
                txtYOffset.setText(NumberFormat.getInstance().format(0));
134

    
135
                jccColor.addActionListener(this);
136
                txtSize.addActionListener(this);
137
                tabs.add(myTab);
138
        }
139

    
140
        public ISymbol getLayer() {
141
                SimpleMarkerSymbol sms = new SimpleMarkerSymbol();
142
                sms.setColor(jccColor.getColor());
143
                sms.setIsShapeVisible(true);
144
                sms.setSize(txtSize.getValue().doubleValue());
145
                sms.setOffset(new Point2D.Double(
146
                                txtXOffset.getValue().doubleValue(),
147
                                txtYOffset.getValue().doubleValue()));
148
                return sms;
149
        }
150

    
151
        public String getName() {
152
                return PluginServices.getText(this, "simple_marker_symbol");
153
        }
154

    
155
        public JPanel[] getTabs() {
156
                return (JPanel[]) tabs.toArray(new JPanel[0]);
157
        }
158

    
159
        public void refreshControls(ISymbol layer) {
160
                SimpleMarkerSymbol sym;
161
                try {
162
                        if (layer == null) {
163
                                // initialize defaults
164
                                System.err.println("SimpleLine.java:: should be unreachable code");
165
                                jccColor.setColor(Color.BLACK);
166
                                txtSize.setText(NumberFormat.getInstance().format(1.0));
167
                                txtSize.setText(NumberFormat.getInstance().format(0.0));
168
                                txtSize.setText(NumberFormat.getInstance().format(0.0));
169
                        } else {
170
                                sym = (SimpleMarkerSymbol) layer;
171
                                jccColor.setColor(sym.getColor());
172
                                txtSize.setText(String.valueOf(sym.getSize()));
173
                                txtSize.setText(String.valueOf(sym.getOffset().getX()));
174
                                txtSize.setText(String.valueOf(sym.getOffset().getY()));
175
                        }
176
                } catch (IndexOutOfBoundsException ioEx) {
177
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
178
                } catch (ClassCastException ccEx) {
179
                        NotificationManager.addWarning("Illegal casting from " +
180
                                        layer.getClassName() + " to " + getSymbolClass().
181
                                        getName() + ".", ccEx);
182

    
183
                }
184
        }
185

    
186
        public Class getSymbolClass() {
187
                return SimpleMarkerSymbol.class;
188
        }
189

    
190
        public void actionPerformed(ActionEvent e) {
191
                fireSymbolChangedEvent();
192
        }
193

    
194
}