svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / CharacterMarker.java @ 11741
History | View | Annotate | Download (11.8 KB)
1 | 9745 | jaume | /* 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$
|
||
45 | * $Log$
|
||
46 | 11734 | jaume | * Revision 1.10 2007-05-21 10:38:27 jaume
|
47 | 11548 | jaume | * *** empty log message ***
|
48 | *
|
||
49 | 11734 | jaume | * Revision 1.9 2007/05/09 16:08:14 jaume
|
50 | * *** empty log message ***
|
||
51 | *
|
||
52 | 11548 | jaume | * Revision 1.8 2007/04/26 11:40:09 jaume
|
53 | 11734 | jaume | * added new components (JIncrementalNumberField)
|
54 | 11371 | jaume | *
|
55 | * Revision 1.7 2007/04/20 07:54:38 jaume
|
||
56 | 11271 | jaume | * *** empty log message ***
|
57 | *
|
||
58 | 11297 | jaume | * Revision 1.6 2007/04/19 14:22:20 jaume
|
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | 11271 | jaume | * Revision 1.5 2007/04/05 16:08:34 jaume
|
62 | 11073 | jaume | * Styled labeling stuff
|
63 | *
|
||
64 | * Revision 1.4 2007/04/04 16:01:13 jaume
|
||
65 | 10993 | jaume | * *** empty log message ***
|
66 | *
|
||
67 | 11055 | jaume | * Revision 1.3 2007/03/30 12:54:11 jaume
|
68 | * *** empty log message ***
|
||
69 | *
|
||
70 | 10993 | jaume | * Revision 1.2 2007/03/09 11:25:00 jaume
|
71 | 10679 | jaume | * Advanced symbology (start committing)
|
72 | *
|
||
73 | * Revision 1.1.2.7 2007/02/21 07:35:14 jaume
|
||
74 | 9745 | jaume | * *** empty log message ***
|
75 | *
|
||
76 | 10679 | jaume | * Revision 1.1.2.6 2007/02/08 15:43:05 jaume
|
77 | * some bug fixes in the editor and removed unnecessary imports
|
||
78 | *
|
||
79 | * Revision 1.1.2.5 2007/02/05 14:58:28 jaume
|
||
80 | * *** empty log message ***
|
||
81 | *
|
||
82 | * Revision 1.1.2.3 2007/02/04 16:57:22 jaume
|
||
83 | * working the map of characters
|
||
84 | *
|
||
85 | * Revision 1.1.2.2 2007/02/02 16:21:32 jaume
|
||
86 | * *** empty log message ***
|
||
87 | *
|
||
88 | * Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
||
89 | * *** empty log message ***
|
||
90 | *
|
||
91 | * Revision 1.1 2007/01/16 11:52:11 jaume
|
||
92 | * *** empty log message ***
|
||
93 | *
|
||
94 | 9745 | jaume | * Revision 1.3 2006/11/06 17:08:45 jaume
|
95 | * *** empty log message ***
|
||
96 | *
|
||
97 | * Revision 1.2 2006/11/06 16:06:52 jaume
|
||
98 | * *** empty log message ***
|
||
99 | *
|
||
100 | * Revision 1.1 2006/10/31 16:16:34 jaume
|
||
101 | * *** empty log message ***
|
||
102 | *
|
||
103 | *
|
||
104 | */
|
||
105 | package com.iver.cit.gvsig.gui.styling; |
||
106 | |||
107 | 10679 | jaume | import java.awt.BorderLayout; |
108 | import java.awt.Color; |
||
109 | import java.awt.Component; |
||
110 | import java.awt.Dimension; |
||
111 | import java.awt.Font; |
||
112 | import java.awt.GraphicsEnvironment; |
||
113 | import java.awt.event.ActionEvent; |
||
114 | import java.awt.event.ActionListener; |
||
115 | 11271 | jaume | import java.awt.geom.Point2D; |
116 | 9745 | jaume | import java.util.ArrayList; |
117 | |||
118 | 11271 | jaume | import javax.swing.BorderFactory; |
119 | 10679 | jaume | import javax.swing.BoxLayout; |
120 | import javax.swing.JComponent; |
||
121 | import javax.swing.JLabel; |
||
122 | import javax.swing.JList; |
||
123 | 9745 | jaume | import javax.swing.JPanel; |
124 | 10679 | jaume | import javax.swing.JScrollPane; |
125 | import javax.swing.ListCellRenderer; |
||
126 | import javax.swing.ListModel; |
||
127 | import javax.swing.event.ListDataListener; |
||
128 | import javax.swing.event.ListSelectionEvent; |
||
129 | import javax.swing.event.ListSelectionListener; |
||
130 | 9745 | jaume | |
131 | 10679 | jaume | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
132 | 11734 | jaume | import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
133 | 11271 | jaume | import org.gvsig.gui.beans.swing.JFontSizeComboBox; |
134 | 10679 | jaume | |
135 | 9745 | jaume | import com.iver.andami.PluginServices; |
136 | 10679 | jaume | import com.iver.andami.messages.NotificationManager; |
137 | import com.iver.cit.gvsig.fmap.core.symbols.CharacterMarkerSymbol; |
||
138 | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
||
139 | 11271 | jaume | import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
140 | 10679 | jaume | import com.iver.utiles.swing.JComboBox; |
141 | 9745 | jaume | |
142 | 11271 | jaume | |
143 | 11371 | jaume | |
144 | 11055 | jaume | /**
|
145 | *
|
||
146 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
147 | *
|
||
148 | */
|
||
149 | 10679 | jaume | public class CharacterMarker extends AbstractTypeSymbolEditorPanel implements ActionListener { |
150 | 11271 | jaume | private static final double DEGREE_TO_RADIANS = Math.PI/180D; |
151 | 9745 | jaume | private ArrayList tabs = new ArrayList(); |
152 | 10679 | jaume | private JList jListSymbols; |
153 | private JScrollPane jScrollPane; |
||
154 | private JComboBox cmbFonts; |
||
155 | 11548 | jaume | private Mask mask;
|
156 | 11271 | jaume | private JFontSizeComboBox cmbFontSize;
|
157 | 11734 | jaume | private JIncrementalNumberField numberAngle;
|
158 | 11271 | jaume | private ColorChooserPanel jcc;
|
159 | 11734 | jaume | private JIncrementalNumberField txtYOffset;
|
160 | private JIncrementalNumberField txtXOffset;
|
||
161 | 11271 | jaume | private Font font; |
162 | private int unicode; |
||
163 | 9745 | jaume | |
164 | public CharacterMarker(SymbolEditor owner) {
|
||
165 | super(owner);
|
||
166 | initialize(); |
||
167 | } |
||
168 | |||
169 | private void initialize() { |
||
170 | JPanel myTab;
|
||
171 | { |
||
172 | 11271 | jaume | // Character marker tab
|
173 | myTab = new JPanel(new BorderLayout(10, 10)); |
||
174 | 9745 | jaume | myTab.setName(PluginServices.getText(this, "character_marker")); |
175 | 10679 | jaume | myTab.setLayout(new BorderLayout(15,15)); |
176 | |||
177 | 11271 | jaume | JPanel aux = new JPanel(new BorderLayout(15, 15)); |
178 | aux.add(new JLabel(PluginServices.getText(this, "font")+":"), BorderLayout.NORTH); |
||
179 | aux.add(getCmbFonts(), BorderLayout.NORTH);
|
||
180 | |||
181 | getJListSymbols().setModel( |
||
182 | new CharacterListModel(
|
||
183 | new Font((String) getCmbFonts().getSelectedItem(), Font.PLAIN, 14))); |
||
184 | aux.add(getJScrollPane(), BorderLayout.CENTER);
|
||
185 | myTab.add(aux, BorderLayout.CENTER);
|
||
186 | |||
187 | GridBagLayoutPanel aux1 = new GridBagLayoutPanel();
|
||
188 | aux1.addComponent(PluginServices.getText(this, "size")+":", getCmbFontSize()); |
||
189 | aux1.addComponent(PluginServices.getText(this, "angle")+":", getNumberAngle()); |
||
190 | |||
191 | aux1.addComponent(PluginServices.getText(this, "color")+":", getColorChooser()); |
||
192 | |||
193 | GridBagLayoutPanel aux2 = new GridBagLayoutPanel();
|
||
194 | aux2.addComponent("X:", getTxtXOffset());
|
||
195 | aux2.addComponent("Y:", getTxtYOffset());
|
||
196 | aux2.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "offset"))); |
||
197 | aux1.addComponent(aux2); |
||
198 | |||
199 | myTab.add(aux1, BorderLayout.EAST);
|
||
200 | tabs.add(myTab); |
||
201 | } |
||
202 | |||
203 | { |
||
204 | // Mask tab
|
||
205 | 11548 | jaume | mask = new Mask(this); |
206 | 11271 | jaume | |
207 | 11548 | jaume | tabs.add(mask); |
208 | 9745 | jaume | } |
209 | |||
210 | } |
||
211 | |||
212 | 11734 | jaume | private JIncrementalNumberField getTxtYOffset() {
|
213 | 11271 | jaume | if (txtYOffset == null) { |
214 | 11734 | jaume | txtYOffset = new JIncrementalNumberField(String.valueOf(0), 7); |
215 | 11371 | jaume | |
216 | 11271 | jaume | } |
217 | |||
218 | return txtYOffset;
|
||
219 | } |
||
220 | |||
221 | 11734 | jaume | private JIncrementalNumberField getTxtXOffset() {
|
222 | 11271 | jaume | if (txtXOffset == null) { |
223 | 11734 | jaume | txtXOffset = new JIncrementalNumberField(String.valueOf(0), 7); |
224 | 11271 | jaume | } |
225 | |||
226 | return txtXOffset;
|
||
227 | } |
||
228 | |||
229 | private ColorChooserPanel getColorChooser() {
|
||
230 | if (jcc == null) { |
||
231 | jcc = new ColorChooserPanel();
|
||
232 | jcc.setAlpha(255);
|
||
233 | } |
||
234 | |||
235 | return jcc;
|
||
236 | } |
||
237 | |||
238 | private JFontSizeComboBox getCmbFontSize() {
|
||
239 | if (cmbFontSize == null) { |
||
240 | cmbFontSize = new JFontSizeComboBox();
|
||
241 | |||
242 | } |
||
243 | |||
244 | return cmbFontSize;
|
||
245 | } |
||
246 | |||
247 | 11734 | jaume | private JIncrementalNumberField getNumberAngle() {
|
248 | 11271 | jaume | if (numberAngle == null) { |
249 | 11734 | jaume | numberAngle = new JIncrementalNumberField(String.valueOf(0), 5); |
250 | 11371 | jaume | |
251 | 11271 | jaume | } |
252 | |||
253 | return numberAngle;
|
||
254 | } |
||
255 | |||
256 | |||
257 | |||
258 | 10679 | jaume | private JComboBox getCmbFonts() { |
259 | if (cmbFonts == null) { |
||
260 | 11271 | jaume | // Font info is obtained from the current graphics environment.
|
261 | 10679 | jaume | GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
262 | |||
263 | 11271 | jaume | // --- Get an array of font names (smaller than the number of fonts)
|
264 | 10679 | jaume | String[] fontNames = ge.getAvailableFontFamilyNames(); |
265 | cmbFonts = new JComboBox(fontNames); |
||
266 | cmbFonts.addActionListener(this);
|
||
267 | } |
||
268 | return cmbFonts;
|
||
269 | 9745 | jaume | } |
270 | |||
271 | 10679 | jaume | private JScrollPane getJScrollPane() { |
272 | if (jScrollPane == null) { |
||
273 | jScrollPane = new JScrollPane(); |
||
274 | jScrollPane.setViewportView(getJListSymbols()); |
||
275 | jScrollPane.setPreferredSize(new Dimension(300, 180)); |
||
276 | } |
||
277 | return jScrollPane;
|
||
278 | } |
||
279 | |||
280 | private JList getJListSymbols() { |
||
281 | if (jListSymbols == null) { |
||
282 | jListSymbols = new JList(); |
||
283 | jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
||
284 | jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
||
285 | jListSymbols.setVisibleRowCount(-1);
|
||
286 | jListSymbols.addListSelectionListener(new ListSelectionListener() { |
||
287 | 11271 | jaume | |
288 | 10679 | jaume | public void valueChanged(ListSelectionEvent e) { |
289 | CharacterItem theChar = (CharacterItem) jListSymbols.getSelectedValue(); |
||
290 | 11271 | jaume | if (theChar == null) return; |
291 | font = theChar.font; |
||
292 | unicode = theChar.glyph; |
||
293 | 10679 | jaume | } |
294 | }); |
||
295 | ListCellRenderer renderer = new ListCellRenderer() { |
||
296 | private Color mySelectedBGColor = new Color(255,145,100,255); |
||
297 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
||
298 | CharacterItem theChar = (CharacterItem) value; |
||
299 | CharacterMarkerSymbol sym = new CharacterMarkerSymbol(theChar.font, theChar.glyph, Color.BLACK); |
||
300 | JPanel pnl = new JPanel(); |
||
301 | BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS); |
||
302 | pnl.setLayout(layout); |
||
303 | Color bgColor = (isSelected) ? mySelectedBGColor
|
||
304 | : getJListSymbols().getBackground(); |
||
305 | |||
306 | pnl.setBackground(bgColor); |
||
307 | SymbolPreviewer sp = new SymbolPreviewer();
|
||
308 | sp.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||
309 | 10993 | jaume | int prevSize = 30; |
310 | sp.setPreferredSize(new Dimension(prevSize, prevSize)); |
||
311 | 10679 | jaume | sp.setSymbol(sym); |
312 | sp.setBackground(bgColor); |
||
313 | 10993 | jaume | sym.setSize(prevSize*.8);
|
314 | 10679 | jaume | pnl.add(sp); |
315 | JLabel lbl = new JLabel(sym.getDescription()); |
||
316 | lbl.setBackground(bgColor); |
||
317 | lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||
318 | pnl.add(lbl); |
||
319 | |||
320 | return pnl;
|
||
321 | } |
||
322 | }; |
||
323 | jListSymbols.setCellRenderer(renderer); |
||
324 | } |
||
325 | return jListSymbols;
|
||
326 | } |
||
327 | |||
328 | |||
329 | 9745 | jaume | public String getName() { |
330 | return PluginServices.getText(this, "character_marker_symbol"); |
||
331 | } |
||
332 | |||
333 | public JPanel[] getTabs() { |
||
334 | return (JPanel[]) tabs .toArray(new JPanel[0]); |
||
335 | } |
||
336 | |||
337 | 10679 | jaume | public void refreshControls(ISymbol layer) { |
338 | CharacterMarkerSymbol sym; |
||
339 | try {
|
||
340 | sym = (CharacterMarkerSymbol) layer; |
||
341 | 11271 | jaume | getCmbFonts().setSelectedItem(sym.getFont().getName()); |
342 | getCmbFontSize().setSelectedItem(new Integer(sym.getFont().getSize())); |
||
343 | 11371 | jaume | getTxtXOffset().setDouble( sym.getOffset().getX() ); |
344 | getTxtYOffset().setDouble( -sym.getOffset().getY() ); |
||
345 | 11271 | jaume | getJListSymbols().setSelectedIndex(sym.getUnicode()); |
346 | 11371 | jaume | getNumberAngle().setDouble( sym.getRotation()/DEGREE_TO_RADIANS ); |
347 | 11271 | jaume | getColorChooser().setColor(sym.getColor()); |
348 | 11297 | jaume | |
349 | 11271 | jaume | // TODO mask
|
350 | 10679 | jaume | } catch (IndexOutOfBoundsException ioEx) { |
351 | NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
||
352 | } catch (ClassCastException ccEx) { |
||
353 | NotificationManager.addWarning("Illegal casting from " +
|
||
354 | layer.getClassName() + " to " + getSymbolClass().
|
||
355 | getName() + ".", ccEx);
|
||
356 | 9745 | jaume | |
357 | 10679 | jaume | } |
358 | |||
359 | 9745 | jaume | } |
360 | |||
361 | public Class getSymbolClass() { |
||
362 | 10679 | jaume | return CharacterMarkerSymbol.class;
|
363 | 9745 | jaume | } |
364 | |||
365 | 10679 | jaume | public ISymbol getLayer() {
|
366 | 11271 | jaume | CharacterMarkerSymbol layer = new CharacterMarkerSymbol();
|
367 | layer.setFont(font); |
||
368 | layer.setUnicode(unicode); |
||
369 | layer.setColor(getColorChooser().getColor()); |
||
370 | layer.setSize(getCmbFontSize().getSelectedValue()); |
||
371 | layer.setOffset(new Point2D.Double( |
||
372 | 11371 | jaume | getTxtXOffset().getDouble(), |
373 | -getTxtYOffset().getDouble())); |
||
374 | layer.setRotation(getNumberAngle().getDouble()*DEGREE_TO_RADIANS); |
||
375 | 11297 | jaume | |
376 | layer.setScaleX(getUnitScaleFactor()); |
||
377 | 11548 | jaume | layer.setMask(mask.getMask()); |
378 | 10679 | jaume | return layer;
|
379 | } |
||
380 | |||
381 | private class CharacterListModel implements ListModel { |
||
382 | |||
383 | private Font font; |
||
384 | private ArrayList listeners; |
||
385 | |||
386 | public CharacterListModel(Font font) { |
||
387 | this.font = font;
|
||
388 | } |
||
389 | |||
390 | public int getSize() { |
||
391 | return font.getNumGlyphs();
|
||
392 | } |
||
393 | |||
394 | public Object getElementAt(int index) { |
||
395 | return new CharacterItem(font, index); |
||
396 | } |
||
397 | |||
398 | public void addListDataListener(ListDataListener l) { |
||
399 | if (listeners == null) |
||
400 | listeners = new ArrayList(); |
||
401 | listeners.add(l); |
||
402 | } |
||
403 | |||
404 | public void removeListDataListener(ListDataListener l) { |
||
405 | if (listeners!=null) |
||
406 | listeners.remove(l); |
||
407 | } |
||
408 | } |
||
409 | |||
410 | private class CharacterItem { |
||
411 | int glyph;
|
||
412 | Font font;
|
||
413 | public CharacterItem(Font font, int glyph) { |
||
414 | this.font = font;
|
||
415 | this.glyph = glyph;
|
||
416 | } |
||
417 | } |
||
418 | |||
419 | public void actionPerformed(ActionEvent e) { |
||
420 | JComponent c = (JComponent) e.getSource(); |
||
421 | if (c.equals(getCmbFonts())) {
|
||
422 | String fontName = (String) getCmbFonts().getSelectedItem(); |
||
423 | getJListSymbols().setModel( |
||
424 | new CharacterListModel(
|
||
425 | new Font(fontName, Font.PLAIN, 10))); |
||
426 | } |
||
427 | } |
||
428 | |||
429 | 11073 | jaume | public EditorTool getEditorTool() {
|
430 | return null; |
||
431 | } |
||
432 | 9745 | jaume | } |