svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / JLineStyleComboBox.java @ 11055
History | View | Annotate | Download (3.71 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 com.iver.cit.gvsig.gui.styling; |
43 |
|
44 |
import java.awt.BasicStroke; |
45 |
import java.awt.Component; |
46 |
|
47 |
import javax.swing.DefaultListCellRenderer; |
48 |
import javax.swing.JList; |
49 |
import javax.swing.ListCellRenderer; |
50 |
|
51 |
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle; |
52 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
53 |
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle; |
54 |
import com.iver.utiles.swing.JComboBox; |
55 |
/**
|
56 |
*
|
57 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
58 |
*
|
59 |
*/
|
60 |
public class JLineStyleComboBox extends JComboBox { |
61 |
private static final int PREDEFINED_STYLE_COUNT = 6; |
62 |
private static final int LINE_WIDTH = 10; |
63 |
private static final int DOT_WIDTH = 2; |
64 |
private int endCap; |
65 |
private int lineJoin; |
66 |
private float miterlimit; |
67 |
private int width; |
68 |
|
69 |
public static float[][] dash = new float[PREDEFINED_STYLE_COUNT][]; |
70 |
{ |
71 |
dash[0] = new BasicStroke().getDashArray(); // line (no dash) |
72 |
|
73 |
dash[1] = new float[] { LINE_WIDTH }; // lines |
74 |
|
75 |
|
76 |
dash[2] = new float[] { DOT_WIDTH }; // dots |
77 |
|
78 |
|
79 |
dash[3] = new float[] { LINE_WIDTH, |
80 |
DOT_WIDTH }; // line + dot
|
81 |
|
82 |
dash[4] = new float[] { LINE_WIDTH, |
83 |
DOT_WIDTH, |
84 |
DOT_WIDTH }; // line + dot + dot
|
85 |
dash[5] = new float[] { LINE_WIDTH, |
86 |
LINE_WIDTH, |
87 |
DOT_WIDTH, |
88 |
DOT_WIDTH }; // line + line + dot + dot
|
89 |
} |
90 |
|
91 |
{ |
92 |
BasicStroke dummy = new BasicStroke(); |
93 |
endCap = dummy.getEndCap(); |
94 |
lineJoin = dummy.getLineJoin(); |
95 |
miterlimit = dummy.getMiterLimit(); |
96 |
} |
97 |
|
98 |
ILineStyle[] styles = new ILineStyle[PREDEFINED_STYLE_COUNT]; |
99 |
|
100 |
private ListCellRenderer renderer = new DefaultListCellRenderer() { |
101 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
102 |
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
103 |
if (value == null) |
104 |
return c;
|
105 |
|
106 |
final IStyle style = (IStyle) value;
|
107 |
StylePreviewer sp = new StylePreviewer();
|
108 |
sp.setPreferredSize(getSize()); |
109 |
sp.setStyle(style); |
110 |
return sp;
|
111 |
}; |
112 |
}; |
113 |
|
114 |
private void refreshStyles() { |
115 |
for (int i = 0; i < styles.length; i++) { |
116 |
styles[i] = new SimpleLineStyle(width, endCap, lineJoin, miterlimit, dash[i], width*5); |
117 |
} |
118 |
|
119 |
removeAll(); |
120 |
for (int i = 0; i < styles.length; i++) { |
121 |
addItem(styles[i]); |
122 |
} |
123 |
|
124 |
} |
125 |
public JLineStyleComboBox() {
|
126 |
super();
|
127 |
setRenderer(renderer); |
128 |
refreshStyles(); |
129 |
} |
130 |
|
131 |
public JLineStyleComboBox(Object[] elements) { |
132 |
super(elements);
|
133 |
setRenderer(renderer); |
134 |
refreshStyles(); |
135 |
} |
136 |
|
137 |
public void setLineWidth(int width) { |
138 |
this.width = width;
|
139 |
refreshStyles(); |
140 |
} |
141 |
|
142 |
|
143 |
} |