svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / JComboBoxSimpleMarkeStyles.java @ 46158
History | View | Annotate | Download (4.78 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.gui.styling; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Component; |
28 |
import java.awt.Dimension; |
29 |
|
30 |
import javax.swing.JComboBox; |
31 |
import javax.swing.JList; |
32 |
import javax.swing.ListCellRenderer; |
33 |
import javax.swing.UIManager; |
34 |
|
35 |
import org.gvsig.symbology.SymbologyLocator; |
36 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
37 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol; |
38 |
|
39 |
|
40 |
/**
|
41 |
* JComboBox used by the user to select the different styles of simple marker symbols.
|
42 |
* The available options are: circle style,square style,cross style, diamond style,x style
|
43 |
* and triangle style.
|
44 |
*
|
45 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
46 |
*/
|
47 |
public class JComboBoxSimpleMarkeStyles extends JComboBox{ |
48 |
/**
|
49 |
*
|
50 |
*/
|
51 |
private static final long serialVersionUID = 3018193423738880772L; |
52 |
private Color symColor = Color.BLACK; |
53 |
private Color outlineColor = Color.BLACK; |
54 |
private boolean outlined = false; |
55 |
static MyItem[] pointTypes = new MyItem[] { |
56 |
new MyItem(IMarkerSymbol.CIRCLE_STYLE),
|
57 |
new MyItem(IMarkerSymbol.SQUARE_STYLE),
|
58 |
new MyItem(IMarkerSymbol.CROSS_STYLE),
|
59 |
new MyItem(IMarkerSymbol.DIAMOND_STYLE),
|
60 |
new MyItem(IMarkerSymbol.X_STYLE),
|
61 |
new MyItem(IMarkerSymbol.TRIANGLE_STYLE),
|
62 |
new MyItem(IMarkerSymbol.STAR_STYLE),
|
63 |
new MyItem(IMarkerSymbol.VERTICAL_LINE_STYLE),
|
64 |
new MyItem(IMarkerSymbol.HORIZONTAL_LINE_STYLE),
|
65 |
}; |
66 |
|
67 |
/**
|
68 |
* Constructor method
|
69 |
*
|
70 |
*/
|
71 |
|
72 |
public JComboBoxSimpleMarkeStyles() {
|
73 |
super();
|
74 |
removeAllItems(); |
75 |
for (int i = 0; i < pointTypes.length; i++) { |
76 |
addItem(pointTypes[i]); |
77 |
} |
78 |
|
79 |
setEditable(false);
|
80 |
setRenderer(new ListCellRenderer() { |
81 |
|
82 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
83 |
SymbolPreviewer preview = new SymbolPreviewer(true) ; |
84 |
ISimpleMarkerSymbol mySymbol = SymbologyLocator.getSymbologyManager().createSimpleMarkerSymbol(); |
85 |
mySymbol.setColor(symColor); |
86 |
mySymbol.setOutlined(outlined); |
87 |
mySymbol.setOutlineColor(outlineColor); |
88 |
if (value instanceof MyItem) { |
89 |
mySymbol.setStyle(((MyItem) value).style); |
90 |
} else {
|
91 |
mySymbol.setStyle(((Integer) value).intValue());
|
92 |
} |
93 |
|
94 |
mySymbol.setUnit(-1); // pixel |
95 |
mySymbol.setSize(10);
|
96 |
preview.setForeground(UIManager.getColor(isSelected
|
97 |
? "ComboBox.selectionForeground"
|
98 |
: "ComboBox.foreground"));
|
99 |
preview.setBackground(UIManager.getColor(isSelected
|
100 |
? "ComboBox.selectionBackground"
|
101 |
: "ComboBox.background"));
|
102 |
preview.setSymbol(mySymbol); |
103 |
preview.setSize(preview.getWidth(), 20);
|
104 |
preview.setPreferredSize(new Dimension(preview.getWidth(), 20)); |
105 |
return preview;
|
106 |
} |
107 |
}); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Establishes the color of the simple marker symbol.
|
112 |
* @param c,Color
|
113 |
*/
|
114 |
public void setSymbolColor(Color c) { |
115 |
this.symColor = c;
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* Sets the color for the outline of the simple marker symbol
|
120 |
* @param c,Color
|
121 |
*/
|
122 |
public void setOutlineColor(Color c) { |
123 |
outlined = c!=null;
|
124 |
outlineColor = c; |
125 |
} |
126 |
|
127 |
public Object getSelectedItem() { |
128 |
return new Integer(((MyItem) super.getSelectedItem()).style); |
129 |
} |
130 |
|
131 |
public void setSelectedItem(Object item) { |
132 |
if (item instanceof Integer) { |
133 |
int myItem = ((Integer) item).intValue(); |
134 |
for (int i = 0; i < pointTypes.length; i++) { |
135 |
if (myItem == pointTypes[i].style)
|
136 |
setSelectedIndex(i); |
137 |
} |
138 |
} |
139 |
super.setSelectedItem(item);
|
140 |
} |
141 |
} |
142 |
/**
|
143 |
* Used to store the different options that the JComboBoxsimplemarkerStyles shows to
|
144 |
* the user.
|
145 |
*
|
146 |
*/
|
147 |
class MyItem { |
148 |
int style;
|
149 |
|
150 |
/**
|
151 |
* Constructor method
|
152 |
* @param style
|
153 |
*/
|
154 |
MyItem(int style) {
|
155 |
this.style = style;
|
156 |
} |
157 |
|
158 |
public boolean equals(Object obj) { |
159 |
if (obj instanceof Integer) { |
160 |
Integer integer = (Integer) obj; |
161 |
return integer.intValue()==style;
|
162 |
} |
163 |
|
164 |
if (obj instanceof MyItem) { |
165 |
return ((MyItem) obj).style == style;
|
166 |
|
167 |
} |
168 |
return super.equals(obj); |
169 |
} |
170 |
} |