Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleLine.java @ 11055

History | View | Annotate | Download (6.15 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: SimpleLine.java 11055 2007-04-04 16:01:14Z jaume $
45
* $Log$
46
* Revision 1.5  2007-04-04 16:01:13  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.4  2007/03/26 15:05:26  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.3  2007/03/21 08:03:03  jaume
53
* refactored to use ISymbol instead of FSymbol
54
*
55
* Revision 1.2  2007/03/09 11:25:00  jaume
56
* Advanced symbology (start committing)
57
*
58
* Revision 1.1.2.6  2007/02/21 07:35:14  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.1.2.5  2007/02/12 15:14:41  jaume
62
* refactored interval legend and added graduated symbol legend
63
*
64
* Revision 1.1.2.4  2007/02/09 11:05:16  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.1.2.3  2007/02/09 11:00:02  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.1.2.2  2007/02/08 15:43:05  jaume
71
* some bug fixes in the editor and removed unnecessary imports
72
*
73
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
74
* *** empty log message ***
75
*
76
*
77
*/
78
package com.iver.cit.gvsig.gui.styling;
79

    
80
import java.awt.BasicStroke;
81
import java.awt.BorderLayout;
82
import java.awt.Color;
83
import java.awt.Component;
84
import java.awt.Dimension;
85
import java.awt.FlowLayout;
86
import java.awt.Graphics2D;
87
import java.awt.Rectangle;
88
import java.awt.event.ActionEvent;
89
import java.awt.event.ActionListener;
90
import java.awt.geom.AffineTransform;
91
import java.text.NumberFormat;
92
import java.util.ArrayList;
93

    
94
import javax.swing.DefaultListCellRenderer;
95
import javax.swing.JList;
96
import javax.swing.JPanel;
97

    
98
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
99

    
100
import com.iver.andami.PluginServices;
101
import com.iver.andami.messages.NotificationManager;
102
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
103
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle;
104
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
105
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle;
106
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
107
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol;
108
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
109
import com.iver.utiles.swing.JComboBox;
110

    
111
import de.ios.framework.swing.JDecimalField;
112

    
113
/**
114
*
115
* @author jaume dominguez faus - jaume.dominguez@iver.es
116
*
117
*/
118
public class SimpleLine extends AbstractTypeSymbolEditorPanel implements ActionListener {
119

    
120
        private ColorChooserPanel jccColor;
121
        private JDecimalField txtWidth;
122
        // TODO faltar?a el style
123
        private ArrayList tabs = new ArrayList();
124
        private JLineStyleComboBox cmbLineStyles;
125

    
126

    
127
        public SimpleLine(SymbolEditor owner) {
128
                super(owner);
129
                initialize();
130
        }
131

    
132
        private void initialize() {
133
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
134
                myTab.setName(PluginServices.getText(this, "simple_line"));
135
                JPanel aux2 = new JPanel(new BorderLayout(5,5));
136
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
137

    
138
                // color chooser
139
                jccColor = new ColorChooserPanel();
140
                jccColor.setAlpha(255);
141

    
142
                aux.addComponent(PluginServices.getText(this, "color")+":",
143
                                jccColor        );
144

    
145
                // line width
146
                txtWidth = new JDecimalField(25);
147
                aux.addComponent(PluginServices.getText(this, "width")+":",
148
                                txtWidth );
149
                aux.setPreferredSize(new Dimension(300, 300));
150

    
151
                // line style combo
152
                cmbLineStyles = new JLineStyleComboBox();
153

    
154
                aux2.add(aux);
155
                myTab.add(aux2);
156
                aux.addComponent(PluginServices.getText(this, "style")+":",
157
                                cmbLineStyles);
158

    
159

    
160
                // initialize defaults
161
                jccColor.setColor(Color.BLACK);
162
                txtWidth.setText(NumberFormat.getInstance().format(1.0));
163

    
164
                jccColor.addActionListener(this);
165
                txtWidth.addActionListener(this);
166
                tabs.add(myTab);
167
        }
168

    
169

    
170
        public ISymbol getLayer() {
171
                SimpleLineSymbol s = new SimpleLineSymbol();
172
                s.setLineColor(jccColor.getColor());
173
                s.setIsShapeVisible(true);
174
                // clone the selected style in the combo box
175
                ILineStyle sty = (ILineStyle) SymbologyFactory.createStyleFromXML(
176
                                ((IStyle) cmbLineStyles.getSelectedItem()).getXMLEntity(), null);
177
                sty.setLineWidth(txtWidth.getValue().floatValue());
178
                s.setLineStyle(sty);
179
                return s;
180
        }
181

    
182
        public String getName() {
183
                return PluginServices.getText(this, "simple_line");
184
        }
185

    
186
        public JPanel[] getTabs() {
187
                return (JPanel[]) tabs.toArray(new JPanel[0]);
188
        }
189

    
190
        public void refreshControls(ISymbol layer) {
191
                SimpleLineSymbol sym;
192
                try {
193
                        if (layer == null) {
194
                                // initialize defaults
195
                                System.err.println("SimpleLine.java:: should be unreachable code");
196
                                jccColor.setColor(Color.BLACK);
197
                                txtWidth.setText(NumberFormat.getInstance().format(1.0));
198
                        } else {
199
                                sym = (SimpleLineSymbol) layer;
200
                                jccColor.setColor(sym.getColor());
201
                                txtWidth.setText(String.valueOf(
202
                                                sym.getLineStyle().getLineWidth()));
203
                        }
204
                } catch (IndexOutOfBoundsException ioEx) {
205
                        NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
206
                } catch (ClassCastException ccEx) {
207
                        NotificationManager.addWarning("Illegal casting from " +
208
                                        layer.getClassName() + " to " + getSymbolClass().
209
                                        getName() + ".", ccEx);
210
                }
211
        }
212

    
213
        public Class getSymbolClass() {
214
                return SimpleLineSymbol.class;
215
        }
216

    
217
        public void actionPerformed(ActionEvent e) {
218
                cmbLineStyles.setLineWidth((int) txtWidth.getValue().floatValue());
219
                fireSymbolChangedEvent();
220
        }
221
}