svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / CharacterMarker.java @ 11055
History | View | Annotate | Download (8.35 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: CharacterMarker.java 11055 2007-04-04 16:01:14Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.4 2007-04-04 16:01:13 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.3 2007/03/30 12:54:11 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.2 2007/03/09 11:25:00 jaume
|
53 |
* Advanced symbology (start committing)
|
54 |
*
|
55 |
* Revision 1.1.2.7 2007/02/21 07:35:14 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.1.2.6 2007/02/08 15:43:05 jaume
|
59 |
* some bug fixes in the editor and removed unnecessary imports
|
60 |
*
|
61 |
* Revision 1.1.2.5 2007/02/05 14:58:28 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.1.2.3 2007/02/04 16:57:22 jaume
|
65 |
* working the map of characters
|
66 |
*
|
67 |
* Revision 1.1.2.2 2007/02/02 16:21:32 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.1 2007/01/16 11:52:11 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.3 2006/11/06 17:08:45 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.2 2006/11/06 16:06:52 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.1 2006/10/31 16:16:34 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
*
|
86 |
*/
|
87 |
package com.iver.cit.gvsig.gui.styling; |
88 |
|
89 |
import java.awt.BorderLayout; |
90 |
import java.awt.Color; |
91 |
import java.awt.Component; |
92 |
import java.awt.Dimension; |
93 |
import java.awt.Font; |
94 |
import java.awt.GraphicsEnvironment; |
95 |
import java.awt.event.ActionEvent; |
96 |
import java.awt.event.ActionListener; |
97 |
import java.util.ArrayList; |
98 |
|
99 |
import javax.swing.BoxLayout; |
100 |
import javax.swing.JComponent; |
101 |
import javax.swing.JLabel; |
102 |
import javax.swing.JList; |
103 |
import javax.swing.JPanel; |
104 |
import javax.swing.JScrollPane; |
105 |
import javax.swing.ListCellRenderer; |
106 |
import javax.swing.ListModel; |
107 |
import javax.swing.event.ListDataListener; |
108 |
import javax.swing.event.ListSelectionEvent; |
109 |
import javax.swing.event.ListSelectionListener; |
110 |
|
111 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
112 |
|
113 |
import com.iver.andami.PluginServices; |
114 |
import com.iver.andami.messages.NotificationManager; |
115 |
import com.iver.cit.gvsig.fmap.core.symbols.CharacterMarkerSymbol; |
116 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
117 |
import com.iver.utiles.swing.JComboBox; |
118 |
|
119 |
/**
|
120 |
*
|
121 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
122 |
*
|
123 |
*/
|
124 |
public class CharacterMarker extends AbstractTypeSymbolEditorPanel implements ActionListener { |
125 |
|
126 |
private ArrayList tabs = new ArrayList(); |
127 |
private JList jListSymbols; |
128 |
private JScrollPane jScrollPane; |
129 |
private JComboBox cmbFonts; |
130 |
private CharacterMarkerSymbol layer;
|
131 |
|
132 |
public CharacterMarker(SymbolEditor owner) {
|
133 |
super(owner);
|
134 |
initialize(); |
135 |
} |
136 |
|
137 |
private void initialize() { |
138 |
JPanel myTab;
|
139 |
{ |
140 |
myTab = new JPanel(); |
141 |
myTab.setName(PluginServices.getText(this, "character_marker")); |
142 |
myTab.setLayout(new BorderLayout(15,15)); |
143 |
|
144 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
145 |
aux.addComponent(PluginServices.getText(this, "font")+":", getCmbFonts()); |
146 |
|
147 |
getJListSymbols().setModel(new CharacterListModel(new Font("ESRI Conservation", Font.PLAIN, 14))); |
148 |
aux.addComponent(getJScrollPane()); |
149 |
myTab.add(aux); |
150 |
tabs.add(myTab); |
151 |
} |
152 |
|
153 |
} |
154 |
|
155 |
private JComboBox getCmbFonts() { |
156 |
if (cmbFonts == null) { |
157 |
// Font info is obtained from the current graphics environment.
|
158 |
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
159 |
|
160 |
// --- Get an array of font names (smaller than the number of fonts)
|
161 |
String[] fontNames = ge.getAvailableFontFamilyNames(); |
162 |
cmbFonts = new JComboBox(fontNames); |
163 |
cmbFonts.addActionListener(this);
|
164 |
} |
165 |
return cmbFonts;
|
166 |
} |
167 |
|
168 |
private JScrollPane getJScrollPane() { |
169 |
if (jScrollPane == null) { |
170 |
jScrollPane = new JScrollPane(); |
171 |
jScrollPane.setViewportView(getJListSymbols()); |
172 |
jScrollPane.setPreferredSize(new Dimension(300, 180)); |
173 |
} |
174 |
return jScrollPane;
|
175 |
} |
176 |
|
177 |
private JList getJListSymbols() { |
178 |
if (jListSymbols == null) { |
179 |
jListSymbols = new JList(); |
180 |
jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
181 |
jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
182 |
jListSymbols.setVisibleRowCount(-1);
|
183 |
jListSymbols.addListSelectionListener(new ListSelectionListener() { |
184 |
public void valueChanged(ListSelectionEvent e) { |
185 |
CharacterItem theChar = (CharacterItem) jListSymbols.getSelectedValue(); |
186 |
layer = new CharacterMarkerSymbol(theChar.font, theChar.glyph, Color.BLACK); |
187 |
} |
188 |
}); |
189 |
ListCellRenderer renderer = new ListCellRenderer() { |
190 |
private Color mySelectedBGColor = new Color(255,145,100,255); |
191 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
192 |
CharacterItem theChar = (CharacterItem) value; |
193 |
CharacterMarkerSymbol sym = new CharacterMarkerSymbol(theChar.font, theChar.glyph, Color.BLACK); |
194 |
JPanel pnl = new JPanel(); |
195 |
BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS); |
196 |
pnl.setLayout(layout); |
197 |
Color bgColor = (isSelected) ? mySelectedBGColor
|
198 |
: getJListSymbols().getBackground(); |
199 |
|
200 |
pnl.setBackground(bgColor); |
201 |
SymbolPreviewer sp = new SymbolPreviewer();
|
202 |
sp.setAlignmentX(Component.CENTER_ALIGNMENT);
|
203 |
int prevSize = 30; |
204 |
sp.setPreferredSize(new Dimension(prevSize, prevSize)); |
205 |
sp.setSymbol(sym); |
206 |
sp.setBackground(bgColor); |
207 |
sym.setSize(prevSize*.8);
|
208 |
pnl.add(sp); |
209 |
JLabel lbl = new JLabel(sym.getDescription()); |
210 |
lbl.setBackground(bgColor); |
211 |
lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
|
212 |
pnl.add(lbl); |
213 |
|
214 |
return pnl;
|
215 |
} |
216 |
}; |
217 |
jListSymbols.setCellRenderer(renderer); |
218 |
} |
219 |
return jListSymbols;
|
220 |
} |
221 |
|
222 |
|
223 |
public String getName() { |
224 |
return PluginServices.getText(this, "character_marker_symbol"); |
225 |
} |
226 |
|
227 |
public JPanel[] getTabs() { |
228 |
return (JPanel[]) tabs .toArray(new JPanel[0]); |
229 |
} |
230 |
|
231 |
public void refreshControls(ISymbol layer) { |
232 |
CharacterMarkerSymbol sym; |
233 |
try {
|
234 |
sym = (CharacterMarkerSymbol) layer; |
235 |
// TODO finish it
|
236 |
} catch (IndexOutOfBoundsException ioEx) { |
237 |
NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
238 |
} catch (ClassCastException ccEx) { |
239 |
NotificationManager.addWarning("Illegal casting from " +
|
240 |
layer.getClassName() + " to " + getSymbolClass().
|
241 |
getName() + ".", ccEx);
|
242 |
|
243 |
} |
244 |
|
245 |
} |
246 |
|
247 |
public Class getSymbolClass() { |
248 |
return CharacterMarkerSymbol.class;
|
249 |
} |
250 |
|
251 |
public ISymbol getLayer() {
|
252 |
if (layer == null) |
253 |
layer = new CharacterMarkerSymbol();
|
254 |
return layer;
|
255 |
} |
256 |
|
257 |
private class CharacterListModel implements ListModel { |
258 |
|
259 |
private Font font; |
260 |
private ArrayList listeners; |
261 |
|
262 |
public CharacterListModel(Font font) { |
263 |
this.font = font;
|
264 |
} |
265 |
|
266 |
public int getSize() { |
267 |
return font.getNumGlyphs();
|
268 |
} |
269 |
|
270 |
public Object getElementAt(int index) { |
271 |
return new CharacterItem(font, index); |
272 |
} |
273 |
|
274 |
public void addListDataListener(ListDataListener l) { |
275 |
if (listeners == null) |
276 |
listeners = new ArrayList(); |
277 |
listeners.add(l); |
278 |
} |
279 |
|
280 |
public void removeListDataListener(ListDataListener l) { |
281 |
if (listeners!=null) |
282 |
listeners.remove(l); |
283 |
} |
284 |
} |
285 |
|
286 |
private class CharacterItem { |
287 |
int glyph;
|
288 |
Font font;
|
289 |
public CharacterItem(Font font, int glyph) { |
290 |
this.font = font;
|
291 |
this.glyph = glyph;
|
292 |
} |
293 |
|
294 |
} |
295 |
|
296 |
public void actionPerformed(ActionEvent e) { |
297 |
JComponent c = (JComponent) e.getSource(); |
298 |
if (c.equals(getCmbFonts())) {
|
299 |
String fontName = (String) getCmbFonts().getSelectedItem(); |
300 |
getJListSymbols().setModel( |
301 |
new CharacterListModel(
|
302 |
new Font(fontName, Font.PLAIN, 10))); |
303 |
} |
304 |
} |
305 |
|
306 |
} |