svn-gvsig-desktop / branches / simbologia / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SimpleLine.java @ 10437
History | View | Annotate | Download (7.69 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 10437 2007-02-21 07:35:14Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.6 2007-02-21 07:35:14 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1.2.5 2007/02/12 15:14:41 jaume
|
50 |
* refactored interval legend and added graduated symbol legend
|
51 |
*
|
52 |
* Revision 1.1.2.4 2007/02/09 11:05:16 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.1.2.3 2007/02/09 11:00:02 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.1.2.2 2007/02/08 15:43:05 jaume
|
59 |
* some bug fixes in the editor and removed unnecessary imports
|
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.BorderLayout; |
70 |
import java.awt.Color; |
71 |
import java.awt.Component; |
72 |
import java.awt.Dimension; |
73 |
import java.awt.FlowLayout; |
74 |
import java.awt.Graphics2D; |
75 |
import java.awt.Rectangle; |
76 |
import java.awt.event.ActionEvent; |
77 |
import java.awt.event.ActionListener; |
78 |
import java.awt.geom.AffineTransform; |
79 |
import java.text.NumberFormat; |
80 |
import java.util.ArrayList; |
81 |
|
82 |
import javax.swing.DefaultListCellRenderer; |
83 |
import javax.swing.JList; |
84 |
import javax.swing.JPanel; |
85 |
|
86 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
87 |
|
88 |
import com.iver.andami.PluginServices; |
89 |
import com.iver.andami.messages.NotificationManager; |
90 |
import com.iver.cit.gvsig.fmap.core.IStyle; |
91 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
92 |
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle; |
93 |
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle; |
94 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
95 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
96 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
97 |
import com.iver.utiles.swing.JComboBox; |
98 |
|
99 |
import de.ios.framework.swing.JDecimalField; |
100 |
|
101 |
public class SimpleLine extends AbstractTypeSymbolEditorPanel implements ActionListener { |
102 |
private static final int PREDEFINED_STYLE_COUNT = 6; |
103 |
private static final int LINE_WIDTH = 10; |
104 |
private static final int DOT_WIDTH = 2; |
105 |
|
106 |
private ColorChooserPanel jccColor;
|
107 |
private JDecimalField txtWidth;
|
108 |
// TODO faltar?a el style
|
109 |
private ArrayList tabs = new ArrayList(); |
110 |
private JComboBox cmbLineStyles; |
111 |
private int endCap; |
112 |
private int lineJoin; |
113 |
private float miterlimit; |
114 |
private float[][] dash = new float[PREDEFINED_STYLE_COUNT][]; |
115 |
|
116 |
{ |
117 |
BasicStroke dummy = new BasicStroke(); |
118 |
endCap = dummy.getEndCap(); |
119 |
lineJoin = dummy.getLineJoin(); |
120 |
miterlimit = dummy.getMiterLimit(); |
121 |
} |
122 |
|
123 |
public SimpleLine(SymbolEditor owner) {
|
124 |
super(owner);
|
125 |
initialize(); |
126 |
} |
127 |
|
128 |
private void initialize() { |
129 |
JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
130 |
myTab.setName(PluginServices.getText(this, "simple_fill")); |
131 |
JPanel aux2 = new JPanel(new BorderLayout(5,5)); |
132 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
133 |
|
134 |
// color chooser
|
135 |
jccColor = new ColorChooserPanel();
|
136 |
jccColor.setAlpha(255);
|
137 |
|
138 |
aux.addComponent(PluginServices.getText(this, "color")+":", |
139 |
jccColor ); |
140 |
|
141 |
// line width
|
142 |
txtWidth = new JDecimalField(25); |
143 |
aux.addComponent(PluginServices.getText(this, "width")+":", |
144 |
txtWidth ); |
145 |
aux.setPreferredSize(new Dimension(300, 300)); |
146 |
|
147 |
// line style combo
|
148 |
cmbLineStyles = new JComboBox(); |
149 |
cmbLineStyles.setRenderer(new DefaultListCellRenderer() { |
150 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
151 |
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
152 |
if (value == null) |
153 |
return c;
|
154 |
final SimpleLineStyle style = (SimpleLineStyle) value;
|
155 |
SymbolPreviewer sp = new SymbolPreviewer();
|
156 |
|
157 |
SimpleLineSymbol sym = new SimpleLineSymbol() {
|
158 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
159 |
style.drawInsideRectangle(g, r); |
160 |
} |
161 |
}; |
162 |
sp.setPreferredSize(c.getPreferredSize()); |
163 |
sp.setSymbol(sym); |
164 |
return sp;
|
165 |
}; |
166 |
}); |
167 |
aux2.add(aux); |
168 |
myTab.add(aux2); |
169 |
aux.addComponent(PluginServices.getText(this, "style")+":", |
170 |
cmbLineStyles); |
171 |
|
172 |
|
173 |
// initialize defaults
|
174 |
jccColor.setColor(Color.BLACK);
|
175 |
txtWidth.setText(NumberFormat.getInstance().format(1.0)); |
176 |
refreshCmbStyles(); |
177 |
|
178 |
jccColor.addActionListener(this);
|
179 |
txtWidth.addActionListener(this);
|
180 |
tabs.add(myTab); |
181 |
} |
182 |
|
183 |
private void refreshCmbStyles() { |
184 |
float width = txtWidth.getValue().floatValue();
|
185 |
|
186 |
dash[0] = new BasicStroke().getDashArray(); // line (no dash) |
187 |
|
188 |
dash[1] = new float[] { LINE_WIDTH }; // lines |
189 |
|
190 |
|
191 |
dash[2] = new float[] { DOT_WIDTH }; // dots |
192 |
|
193 |
|
194 |
dash[3] = new float[] { LINE_WIDTH, |
195 |
DOT_WIDTH }; // line + dot
|
196 |
|
197 |
dash[4] = new float[] { LINE_WIDTH, |
198 |
DOT_WIDTH, |
199 |
DOT_WIDTH}; // line + dot + dot
|
200 |
dash[5] = new float[] { LINE_WIDTH, |
201 |
LINE_WIDTH, |
202 |
DOT_WIDTH, |
203 |
DOT_WIDTH}; // line + line + dot + dot
|
204 |
|
205 |
ILineStyle[] styles = new ILineStyle[PREDEFINED_STYLE_COUNT]; |
206 |
for (int i = 0; i < styles.length; i++) { |
207 |
styles[i] = new SimpleLineStyle(width, endCap, lineJoin, miterlimit, dash[i], width*5); |
208 |
} |
209 |
|
210 |
cmbLineStyles.removeAll(); |
211 |
for (int i = 0; i < styles.length; i++) { |
212 |
cmbLineStyles.addItem(styles[i]); |
213 |
} |
214 |
|
215 |
}; |
216 |
|
217 |
public ISymbol getLayer() {
|
218 |
SimpleLineSymbol s = new SimpleLineSymbol();
|
219 |
s.setColor(jccColor.getColor()); |
220 |
s.setIsShapeVisible(true);
|
221 |
// clone the selected style in the combo box
|
222 |
ILineStyle sty = (ILineStyle) SymbologyFactory.createStyleFromXML( |
223 |
((IStyle) cmbLineStyles.getSelectedItem()).getXMLEntity(), null);
|
224 |
sty.setLineWidth(txtWidth.getValue().floatValue()); |
225 |
s.setLineStyle(sty); |
226 |
return s;
|
227 |
} |
228 |
|
229 |
public String getName() { |
230 |
return PluginServices.getText(this, "simple_line"); |
231 |
} |
232 |
|
233 |
public JPanel[] getTabs() { |
234 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
235 |
} |
236 |
|
237 |
public void refreshControls(ISymbol layer) { |
238 |
SimpleLineSymbol sym; |
239 |
try {
|
240 |
if (layer == null) { |
241 |
// initialize defaults
|
242 |
System.err.println("SimpleLine.java:: should be unreachable code"); |
243 |
jccColor.setColor(Color.BLACK);
|
244 |
txtWidth.setText(NumberFormat.getInstance().format(1.0)); |
245 |
} else {
|
246 |
sym = (SimpleLineSymbol) layer; |
247 |
jccColor.setColor(sym.getColor()); |
248 |
txtWidth.setText(String.valueOf(
|
249 |
sym.getLineStyle().getLineWidth())); |
250 |
} |
251 |
} catch (IndexOutOfBoundsException ioEx) { |
252 |
NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
253 |
} catch (ClassCastException ccEx) { |
254 |
NotificationManager.addWarning("Illegal casting from " +
|
255 |
layer.getClassName() + " to " + getSymbolClass().
|
256 |
getName() + ".", ccEx);
|
257 |
} |
258 |
} |
259 |
|
260 |
public Class getSymbolClass() { |
261 |
return SimpleLineSymbol.class;
|
262 |
} |
263 |
|
264 |
public void actionPerformed(ActionEvent e) { |
265 |
refreshCmbStyles(); |
266 |
fireSymbolChangedEvent(); |
267 |
} |
268 |
} |