root / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / styling / JComboBoxLineStyles.java @ 20768
History | View | Annotate | Download (4.39 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 |
package org.gvsig.symbology.gui.styling; |
43 |
|
44 |
import java.awt.BasicStroke; |
45 |
import java.awt.Component; |
46 |
import java.awt.Dimension; |
47 |
|
48 |
import javax.swing.JList; |
49 |
import javax.swing.ListCellRenderer; |
50 |
import javax.swing.UIManager; |
51 |
|
52 |
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle; |
53 |
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle; |
54 |
import com.iver.cit.gvsig.gui.styling.StylePreviewer; |
55 |
import com.iver.utiles.swing.JComboBox; |
56 |
/**
|
57 |
* ComboBox that shows the different styles of line that can be selected by
|
58 |
* the user in order to modify a symbol composed by lines .
|
59 |
*
|
60 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
61 |
*
|
62 |
*/
|
63 |
public class JComboBoxLineStyles extends JComboBox { |
64 |
private static final int PREDEFINED_STYLE_COUNT = 6; |
65 |
private static final int LINE_WIDTH = 10; |
66 |
private static final int DOT_WIDTH = 2; |
67 |
private int endCap; |
68 |
private int lineJoin; |
69 |
private float miterlimit; |
70 |
private int width; |
71 |
|
72 |
public static float[][] dash = new float[PREDEFINED_STYLE_COUNT][]; |
73 |
{ |
74 |
|
75 |
dash[0] = new float[] { 1 }; // no dash, line |
76 |
|
77 |
dash[1] = new float[] { LINE_WIDTH }; // lines |
78 |
|
79 |
dash[2] = new float[] { DOT_WIDTH }; // dots |
80 |
|
81 |
dash[3] = new float[] { LINE_WIDTH, |
82 |
DOT_WIDTH }; // line + dot
|
83 |
|
84 |
dash[4] = new float[] { LINE_WIDTH, |
85 |
DOT_WIDTH, |
86 |
DOT_WIDTH }; // line + dot + dot
|
87 |
dash[5] = new float[] { LINE_WIDTH, |
88 |
LINE_WIDTH, |
89 |
DOT_WIDTH, |
90 |
DOT_WIDTH }; // line + line + dot + dot
|
91 |
} |
92 |
|
93 |
{ |
94 |
BasicStroke dummy = new BasicStroke(); |
95 |
endCap = dummy.getEndCap(); |
96 |
lineJoin = dummy.getLineJoin(); |
97 |
miterlimit = dummy.getMiterLimit(); |
98 |
} |
99 |
|
100 |
ILineStyle[] styles = new ILineStyle[PREDEFINED_STYLE_COUNT]; |
101 |
|
102 |
private ListCellRenderer renderer = new ListCellRenderer() { |
103 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
104 |
SimpleLineStyle style = null;
|
105 |
if (value instanceof float[]) { |
106 |
float[] d = (float[]) value; |
107 |
style = new SimpleLineStyle(width, endCap, lineJoin, miterlimit, d, 0); |
108 |
} else if (value instanceof SimpleLineStyle) { |
109 |
style = (SimpleLineStyle) value; |
110 |
} |
111 |
StylePreviewer sp = new StylePreviewer();
|
112 |
Dimension sz = new Dimension(80, 20); |
113 |
sp.setSize(50, 25); |
114 |
sp.setPreferredSize(sz); |
115 |
sp.setStyle(style); |
116 |
sp.setForeground(UIManager.getColor(isSelected
|
117 |
? "ComboBox.selectionForeground"
|
118 |
: "ComboBox.foreground"));
|
119 |
sp.setBackground(UIManager.getColor(isSelected
|
120 |
? "ComboBox.selectionBackground"
|
121 |
: "ComboBox.background"));
|
122 |
return sp;
|
123 |
}; |
124 |
}; |
125 |
private void refreshStyles() { |
126 |
for (int i = 0; i < styles.length; i++) { |
127 |
styles[i] = new SimpleLineStyle(width, endCap, lineJoin, miterlimit, dash[i], width*5); |
128 |
} |
129 |
|
130 |
removeAllItems(); |
131 |
for (int i = 0; i < styles.length; i++) { |
132 |
addItem(styles[i]); |
133 |
} |
134 |
} |
135 |
/**
|
136 |
* Constructor method
|
137 |
*
|
138 |
*/
|
139 |
public JComboBoxLineStyles() {
|
140 |
super();
|
141 |
initialize(); |
142 |
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Initializes this
|
147 |
*
|
148 |
*/
|
149 |
private void initialize() { |
150 |
removeAllItems(); |
151 |
for (int i = 0; i < dash.length; i++) { |
152 |
addItem(dash[i]); |
153 |
} |
154 |
setEditable(false);
|
155 |
setRenderer(renderer); |
156 |
refreshStyles(); |
157 |
} |
158 |
/**
|
159 |
* Sets the width of the line
|
160 |
* @param width
|
161 |
*/
|
162 |
public void setLineWidth(int width) { |
163 |
this.width = width;
|
164 |
refreshStyles(); |
165 |
} |
166 |
|
167 |
} |