root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / JLineStyleComboBox.java @ 10679
History | View | Annotate | Download (2.46 KB)
1 |
package com.iver.cit.gvsig.gui.styling; |
---|---|
2 |
|
3 |
import java.awt.BasicStroke; |
4 |
import java.awt.Component; |
5 |
|
6 |
import javax.swing.DefaultListCellRenderer; |
7 |
import javax.swing.JList; |
8 |
import javax.swing.ListCellRenderer; |
9 |
|
10 |
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle; |
11 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
12 |
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle; |
13 |
import com.iver.utiles.swing.JComboBox; |
14 |
|
15 |
public class JLineStyleComboBox extends JComboBox { |
16 |
private static final int PREDEFINED_STYLE_COUNT = 6; |
17 |
private static final int LINE_WIDTH = 10; |
18 |
private static final int DOT_WIDTH = 2; |
19 |
private int endCap; |
20 |
private int lineJoin; |
21 |
private float miterlimit; |
22 |
private int width; |
23 |
|
24 |
public static float[][] dash = new float[PREDEFINED_STYLE_COUNT][]; |
25 |
{ |
26 |
dash[0] = new BasicStroke().getDashArray(); // line (no dash) |
27 |
|
28 |
dash[1] = new float[] { LINE_WIDTH }; // lines |
29 |
|
30 |
|
31 |
dash[2] = new float[] { DOT_WIDTH }; // dots |
32 |
|
33 |
|
34 |
dash[3] = new float[] { LINE_WIDTH, |
35 |
DOT_WIDTH }; // line + dot
|
36 |
|
37 |
dash[4] = new float[] { LINE_WIDTH, |
38 |
DOT_WIDTH, |
39 |
DOT_WIDTH }; // line + dot + dot
|
40 |
dash[5] = new float[] { LINE_WIDTH, |
41 |
LINE_WIDTH, |
42 |
DOT_WIDTH, |
43 |
DOT_WIDTH }; // line + line + dot + dot
|
44 |
} |
45 |
|
46 |
{ |
47 |
BasicStroke dummy = new BasicStroke(); |
48 |
endCap = dummy.getEndCap(); |
49 |
lineJoin = dummy.getLineJoin(); |
50 |
miterlimit = dummy.getMiterLimit(); |
51 |
} |
52 |
|
53 |
ILineStyle[] styles = new ILineStyle[PREDEFINED_STYLE_COUNT]; |
54 |
|
55 |
private ListCellRenderer renderer = new DefaultListCellRenderer() { |
56 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
57 |
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
58 |
if (value == null) |
59 |
return c;
|
60 |
|
61 |
final IStyle style = (IStyle) value;
|
62 |
StylePreviewer sp = new StylePreviewer();
|
63 |
sp.setPreferredSize(getSize()); |
64 |
sp.setStyle(style); |
65 |
return sp;
|
66 |
}; |
67 |
}; |
68 |
|
69 |
private void refreshStyles() { |
70 |
for (int i = 0; i < styles.length; i++) { |
71 |
styles[i] = new SimpleLineStyle(width, endCap, lineJoin, miterlimit, dash[i], width*5); |
72 |
} |
73 |
|
74 |
removeAll(); |
75 |
for (int i = 0; i < styles.length; i++) { |
76 |
addItem(styles[i]); |
77 |
} |
78 |
|
79 |
} |
80 |
public JLineStyleComboBox() {
|
81 |
super();
|
82 |
setRenderer(renderer); |
83 |
refreshStyles(); |
84 |
} |
85 |
|
86 |
public JLineStyleComboBox(Object[] elements) { |
87 |
super(elements);
|
88 |
setRenderer(renderer); |
89 |
refreshStyles(); |
90 |
} |
91 |
|
92 |
public void setLineWidth(int width) { |
93 |
this.width = width;
|
94 |
refreshStyles(); |
95 |
} |
96 |
|
97 |
|
98 |
} |