Statistics
| Revision:

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

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

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

    
97
import javax.swing.DefaultListCellRenderer;
98
import javax.swing.JList;
99
import javax.swing.JPanel;
100

    
101
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
102

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

    
114
import de.ios.framework.swing.JDecimalField;
115

    
116
/**
117
*
118
* @author jaume dominguez faus - jaume.dominguez@iver.es
119
*
120
*/
121
public class SimpleLine extends AbstractTypeSymbolEditorPanel implements ActionListener {
122

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

    
129

    
130
        public SimpleLine(SymbolEditor owner) {
131
                super(owner);
132
                initialize();
133
        }
134

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

    
141
                // color chooser
142
                jccColor = new ColorChooserPanel();
143
                jccColor.setAlpha(255);
144

    
145
                aux.addComponent(PluginServices.getText(this, "color")+":",
146
                                jccColor        );
147

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

    
154
                // line style combo
155
                cmbLineStyles = new JLineStyleComboBox();
156

    
157
                aux2.add(aux);
158
                myTab.add(aux2);
159
                aux.addComponent(PluginServices.getText(this, "style")+":",
160
                                cmbLineStyles);
161

    
162

    
163
                // initialize defaults
164
                jccColor.setColor(Color.BLACK);
165
                txtWidth.setText(NumberFormat.getInstance().format(1.0));
166

    
167
                jccColor.addActionListener(this);
168
                txtWidth.addActionListener(this);
169
                tabs.add(myTab);
170
        }
171

    
172

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

    
185
        public String getName() {
186
                return PluginServices.getText(this, "simple_line");
187
        }
188

    
189
        public JPanel[] getTabs() {
190
                return (JPanel[]) tabs.toArray(new JPanel[0]);
191
        }
192

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

    
216
        public Class getSymbolClass() {
217
                return SimpleLineSymbol.class;
218
        }
219

    
220
        public void actionPerformed(ActionEvent e) {
221
                cmbLineStyles.setLineWidth((int) txtWidth.getValue().floatValue());
222
                fireSymbolChangedEvent();
223
        }
224

    
225
        public EditorTool getEditorTool() {
226
                return null;
227
        }
228
}