Statistics
| Revision:

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

History | View | Annotate | Download (5.85 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 10679 2007-03-09 11:25:01Z jaume $
45
* $Log$
46
* Revision 1.2  2007-03-09 11:25:00  jaume
47
* Advanced symbology (start committing)
48
*
49
* Revision 1.1.2.6  2007/02/21 07:35:14  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1.2.5  2007/02/12 15:14:41  jaume
53
* refactored interval legend and added graduated symbol legend
54
*
55
* Revision 1.1.2.4  2007/02/09 11:05:16  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.1.2.3  2007/02/09 11:00:02  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.1.2.2  2007/02/08 15:43:05  jaume
62
* some bug fixes in the editor and removed unnecessary imports
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.BorderLayout;
73
import java.awt.Color;
74
import java.awt.Component;
75
import java.awt.Dimension;
76
import java.awt.FlowLayout;
77
import java.awt.Graphics2D;
78
import java.awt.Rectangle;
79
import java.awt.event.ActionEvent;
80
import java.awt.event.ActionListener;
81
import java.awt.geom.AffineTransform;
82
import java.text.NumberFormat;
83
import java.util.ArrayList;
84

    
85
import javax.swing.DefaultListCellRenderer;
86
import javax.swing.JList;
87
import javax.swing.JPanel;
88

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

    
91
import com.iver.andami.PluginServices;
92
import com.iver.andami.messages.NotificationManager;
93
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
94
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle;
95
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
96
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle;
97
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
98
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol;
99
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
100
import com.iver.utiles.swing.JComboBox;
101

    
102
import de.ios.framework.swing.JDecimalField;
103

    
104
public class SimpleLine extends AbstractTypeSymbolEditorPanel implements ActionListener {
105
        
106
        private ColorChooserPanel jccColor;
107
        private JDecimalField txtWidth;
108
        // TODO faltar?a el style
109
        private ArrayList tabs = new ArrayList();
110
        private JLineStyleComboBox cmbLineStyles;
111
        
112

    
113
        public SimpleLine(SymbolEditor owner) {
114
                super(owner);
115
                initialize();
116
        }
117

    
118
        private void initialize() {
119
                JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5));
120
                myTab.setName(PluginServices.getText(this, "simple_fill"));
121
                JPanel aux2 = new JPanel(new BorderLayout(5,5));
122
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
123

    
124
                // color chooser
125
                jccColor = new ColorChooserPanel();
126
                jccColor.setAlpha(255);
127

    
128
                aux.addComponent(PluginServices.getText(this, "color")+":",
129
                                jccColor        );
130

    
131
                // line width
132
                txtWidth = new JDecimalField(25);
133
                aux.addComponent(PluginServices.getText(this, "width")+":",
134
                                txtWidth );
135
                aux.setPreferredSize(new Dimension(300, 300));
136

    
137
                // line style combo
138
                cmbLineStyles = new JLineStyleComboBox();
139
                
140
                aux2.add(aux);
141
                myTab.add(aux2);
142
                aux.addComponent(PluginServices.getText(this, "style")+":",
143
                                cmbLineStyles);
144

    
145

    
146
                // initialize defaults
147
                jccColor.setColor(Color.BLACK);
148
                txtWidth.setText(NumberFormat.getInstance().format(1.0));
149

    
150
                jccColor.addActionListener(this);
151
                txtWidth.addActionListener(this);
152
                tabs.add(myTab);
153
        }
154

    
155

    
156
        public ISymbol getLayer() {
157
                SimpleLineSymbol s = new SimpleLineSymbol();
158
                s.setColor(jccColor.getColor());
159
                s.setIsShapeVisible(true);
160
                // clone the selected style in the combo box
161
                ILineStyle sty = (ILineStyle) SymbologyFactory.createStyleFromXML(
162
                                ((IStyle) cmbLineStyles.getSelectedItem()).getXMLEntity(), null);
163
                sty.setLineWidth(txtWidth.getValue().floatValue());
164
                s.setLineStyle(sty);
165
                return s;
166
        }
167

    
168
        public String getName() {
169
                return PluginServices.getText(this, "simple_line");
170
        }
171

    
172
        public JPanel[] getTabs() {
173
                return (JPanel[]) tabs.toArray(new JPanel[0]);
174
        }
175

    
176
        public void refreshControls(ISymbol layer) {
177
                SimpleLineSymbol sym;
178
                try {
179
                        if (layer == null) {
180
                                // initialize defaults
181
                                System.err.println("SimpleLine.java:: should be unreachable code");
182
                                jccColor.setColor(Color.BLACK);
183
                                txtWidth.setText(NumberFormat.getInstance().format(1.0));
184
                        } else {
185
                                sym = (SimpleLineSymbol) layer;
186
                                jccColor.setColor(sym.getColor());
187
                                txtWidth.setText(String.valueOf(
188
                                                sym.getLineStyle().getLineWidth()));
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
        public Class getSymbolClass() {
200
                return SimpleLineSymbol.class;
201
        }
202

    
203
        public void actionPerformed(ActionEvent e) {
204
                cmbLineStyles.setLineWidth((int) txtWidth.getValue().floatValue());
205
                fireSymbolChangedEvent();
206
        }
207
}