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