Revision 11271 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/CharacterMarker.java
CharacterMarker.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.5 2007-04-05 16:08:34 jaume |
|
46 |
* Revision 1.6 2007-04-19 14:22:20 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.5 2007/04/05 16:08:34 jaume |
|
47 | 50 |
* Styled labeling stuff |
48 | 51 |
* |
49 | 52 |
* Revision 1.4 2007/04/04 16:01:13 jaume |
... | ... | |
93 | 96 |
import java.awt.Color; |
94 | 97 |
import java.awt.Component; |
95 | 98 |
import java.awt.Dimension; |
99 |
import java.awt.FlowLayout; |
|
96 | 100 |
import java.awt.Font; |
97 | 101 |
import java.awt.GraphicsEnvironment; |
102 |
import java.awt.GridLayout; |
|
98 | 103 |
import java.awt.event.ActionEvent; |
99 | 104 |
import java.awt.event.ActionListener; |
105 |
import java.awt.geom.Point2D; |
|
106 |
import java.math.BigInteger; |
|
100 | 107 |
import java.util.ArrayList; |
101 | 108 |
|
109 |
import javax.swing.BorderFactory; |
|
102 | 110 |
import javax.swing.BoxLayout; |
111 |
import javax.swing.ButtonGroup; |
|
103 | 112 |
import javax.swing.JComponent; |
104 | 113 |
import javax.swing.JLabel; |
105 | 114 |
import javax.swing.JList; |
106 | 115 |
import javax.swing.JPanel; |
116 |
import javax.swing.JRadioButton; |
|
107 | 117 |
import javax.swing.JScrollPane; |
118 |
import javax.swing.JTextField; |
|
108 | 119 |
import javax.swing.ListCellRenderer; |
109 | 120 |
import javax.swing.ListModel; |
110 | 121 |
import javax.swing.event.ListDataListener; |
... | ... | |
112 | 123 |
import javax.swing.event.ListSelectionListener; |
113 | 124 |
|
114 | 125 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
126 |
import org.gvsig.gui.beans.swing.JButton; |
|
127 |
import org.gvsig.gui.beans.swing.JFontSizeComboBox; |
|
115 | 128 |
|
116 | 129 |
import com.iver.andami.PluginServices; |
117 | 130 |
import com.iver.andami.messages.NotificationManager; |
118 | 131 |
import com.iver.cit.gvsig.fmap.core.symbols.CharacterMarkerSymbol; |
119 | 132 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
133 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
|
120 | 134 |
import com.iver.utiles.swing.JComboBox; |
121 | 135 |
|
136 |
import de.ios.framework.swing.JNumberField; |
|
137 |
|
|
122 | 138 |
/** |
123 | 139 |
* |
124 | 140 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
125 | 141 |
* |
126 | 142 |
*/ |
127 | 143 |
public class CharacterMarker extends AbstractTypeSymbolEditorPanel implements ActionListener { |
128 |
|
|
144 |
private static final double DEGREE_TO_RADIANS = Math.PI/180D; |
|
129 | 145 |
private ArrayList tabs = new ArrayList(); |
130 | 146 |
private JList jListSymbols; |
131 | 147 |
private JScrollPane jScrollPane; |
132 | 148 |
private JComboBox cmbFonts; |
133 |
private CharacterMarkerSymbol layer; |
|
149 |
private JButton btnHaloSymbol; |
|
150 |
private JRadioButton rdBtnHalo; |
|
151 |
private JRadioButton rdBtnNone; |
|
152 |
private JTextField txtHaloSize; |
|
153 |
private JFontSizeComboBox cmbFontSize; |
|
154 |
private JNumberField numberAngle; |
|
155 |
private ColorChooserPanel jcc; |
|
156 |
private JNumberField txtYOffset; |
|
157 |
private JNumberField txtXOffset; |
|
158 |
private Font font; |
|
159 |
private int unicode; |
|
134 | 160 |
|
135 | 161 |
public CharacterMarker(SymbolEditor owner) { |
136 | 162 |
super(owner); |
... | ... | |
140 | 166 |
private void initialize() { |
141 | 167 |
JPanel myTab; |
142 | 168 |
{ |
143 |
myTab = new JPanel(); |
|
169 |
// Character marker tab |
|
170 |
myTab = new JPanel(new BorderLayout(10, 10)); |
|
144 | 171 |
myTab.setName(PluginServices.getText(this, "character_marker")); |
145 | 172 |
myTab.setLayout(new BorderLayout(15,15)); |
146 | 173 |
|
174 |
JPanel aux = new JPanel(new BorderLayout(15, 15)); |
|
175 |
aux.add(new JLabel(PluginServices.getText(this, "font")+":"), BorderLayout.NORTH); |
|
176 |
aux.add(getCmbFonts(), BorderLayout.NORTH); |
|
177 |
|
|
178 |
getJListSymbols().setModel( |
|
179 |
new CharacterListModel( |
|
180 |
new Font((String) getCmbFonts().getSelectedItem(), Font.PLAIN, 14))); |
|
181 |
aux.add(getJScrollPane(), BorderLayout.CENTER); |
|
182 |
myTab.add(aux, BorderLayout.CENTER); |
|
183 |
|
|
184 |
GridBagLayoutPanel aux1 = new GridBagLayoutPanel(); |
|
185 |
aux1.addComponent(PluginServices.getText(this, "size")+":", getCmbFontSize()); |
|
186 |
aux1.addComponent(PluginServices.getText(this, "angle")+":", getNumberAngle()); |
|
187 |
|
|
188 |
aux1.addComponent(PluginServices.getText(this, "color")+":", getColorChooser()); |
|
189 |
|
|
190 |
GridBagLayoutPanel aux2 = new GridBagLayoutPanel(); |
|
191 |
aux2.addComponent("X:", getTxtXOffset()); |
|
192 |
aux2.addComponent("Y:", getTxtYOffset()); |
|
193 |
aux2.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "offset"))); |
|
194 |
aux1.addComponent(aux2); |
|
195 |
|
|
196 |
myTab.add(aux1, BorderLayout.EAST); |
|
197 |
tabs.add(myTab); |
|
198 |
} |
|
199 |
|
|
200 |
{ |
|
201 |
// Mask tab |
|
202 |
myTab = new JPanel(); |
|
203 |
myTab.setName(PluginServices.getText(this, "mask")); |
|
204 |
|
|
147 | 205 |
GridBagLayoutPanel aux = new GridBagLayoutPanel(); |
148 |
aux.addComponent(PluginServices.getText(this, "font")+":", getCmbFonts()); |
|
206 |
aux.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "style"))); |
|
207 |
JPanel stylePanel = new JPanel(new GridLayout(2, 1)); |
|
208 |
stylePanel.add(getRdNone()); |
|
209 |
stylePanel.add(getRdHalo()); |
|
210 |
aux.addComponent(stylePanel); |
|
211 |
ButtonGroup group = new ButtonGroup(); |
|
212 |
group.add(getRdNone()); |
|
213 |
group.add(getRdHalo()); |
|
149 | 214 |
|
150 |
getJListSymbols().setModel(new CharacterListModel(new Font("ESRI Conservation", Font.PLAIN, 14))); |
|
151 |
aux.addComponent(getJScrollPane()); |
|
215 |
JPanel aux2 = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
|
216 |
aux2.add(new JLabel(PluginServices.getText(this, "size")+":")); |
|
217 |
aux2.add(getTxtHaloSize()); |
|
218 |
aux2.add(getBtnHaloSymbol()); |
|
219 |
|
|
152 | 220 |
myTab.add(aux); |
221 |
myTab.add(aux2); |
|
153 | 222 |
tabs.add(myTab); |
154 | 223 |
} |
155 | 224 |
|
156 | 225 |
} |
157 | 226 |
|
227 |
private JNumberField getTxtYOffset() { |
|
228 |
if (txtYOffset == null) { |
|
229 |
txtYOffset = new JNumberField(); |
|
230 |
txtYOffset.setValue(0); |
|
231 |
} |
|
232 |
|
|
233 |
return txtYOffset; |
|
234 |
} |
|
235 |
|
|
236 |
private JNumberField getTxtXOffset() { |
|
237 |
if (txtXOffset == null) { |
|
238 |
txtXOffset = new JNumberField(); |
|
239 |
txtXOffset.setValue(0); |
|
240 |
} |
|
241 |
|
|
242 |
return txtXOffset; |
|
243 |
} |
|
244 |
|
|
245 |
private ColorChooserPanel getColorChooser() { |
|
246 |
if (jcc == null) { |
|
247 |
jcc = new ColorChooserPanel(); |
|
248 |
jcc.setAlpha(255); |
|
249 |
} |
|
250 |
|
|
251 |
return jcc; |
|
252 |
} |
|
253 |
|
|
254 |
private JFontSizeComboBox getCmbFontSize() { |
|
255 |
if (cmbFontSize == null) { |
|
256 |
cmbFontSize = new JFontSizeComboBox(); |
|
257 |
|
|
258 |
} |
|
259 |
|
|
260 |
return cmbFontSize; |
|
261 |
} |
|
262 |
|
|
263 |
private JNumberField getNumberAngle() { |
|
264 |
if (numberAngle == null) { |
|
265 |
numberAngle = new JNumberField(5); |
|
266 |
} |
|
267 |
|
|
268 |
return numberAngle; |
|
269 |
} |
|
270 |
|
|
271 |
private JTextField getTxtHaloSize() { |
|
272 |
if (txtHaloSize == null) { |
|
273 |
txtHaloSize = new JTextField(String.valueOf(2.0), 6); |
|
274 |
} |
|
275 |
|
|
276 |
return txtHaloSize; |
|
277 |
} |
|
278 |
|
|
279 |
private JButton getBtnHaloSymbol() { |
|
280 |
if (btnHaloSymbol == null) { |
|
281 |
btnHaloSymbol = new JButton(PluginServices.getText(this, "symbol")); |
|
282 |
} |
|
283 |
|
|
284 |
return btnHaloSymbol; |
|
285 |
} |
|
286 |
|
|
287 |
private JRadioButton getRdHalo() { |
|
288 |
if (rdBtnHalo == null) { |
|
289 |
rdBtnHalo = new JRadioButton(PluginServices.getText(this, "halo")); |
|
290 |
} |
|
291 |
|
|
292 |
return rdBtnHalo; |
|
293 |
} |
|
294 |
|
|
295 |
private JRadioButton getRdNone() { |
|
296 |
if (rdBtnNone == null) { |
|
297 |
rdBtnNone = new JRadioButton(PluginServices.getText(this, "none")); |
|
298 |
rdBtnNone.setSelected(true); |
|
299 |
} |
|
300 |
|
|
301 |
return rdBtnNone; |
|
302 |
} |
|
303 |
|
|
158 | 304 |
private JComboBox getCmbFonts() { |
159 | 305 |
if (cmbFonts == null) { |
160 |
// Font info is obtained from the current graphics environment.
|
|
306 |
// Font info is obtained from the current graphics environment.
|
|
161 | 307 |
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
162 | 308 |
|
163 |
// --- Get an array of font names (smaller than the number of fonts)
|
|
309 |
// --- Get an array of font names (smaller than the number of fonts)
|
|
164 | 310 |
String[] fontNames = ge.getAvailableFontFamilyNames(); |
165 | 311 |
cmbFonts = new JComboBox(fontNames); |
166 | 312 |
cmbFonts.addActionListener(this); |
... | ... | |
184 | 330 |
jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP); |
185 | 331 |
jListSymbols.setVisibleRowCount(-1); |
186 | 332 |
jListSymbols.addListSelectionListener(new ListSelectionListener() { |
333 |
|
|
187 | 334 |
public void valueChanged(ListSelectionEvent e) { |
188 | 335 |
CharacterItem theChar = (CharacterItem) jListSymbols.getSelectedValue(); |
189 |
layer = new CharacterMarkerSymbol(theChar.font, theChar.glyph, Color.BLACK); |
|
336 |
if (theChar == null) return; |
|
337 |
font = theChar.font; |
|
338 |
unicode = theChar.glyph; |
|
190 | 339 |
} |
191 | 340 |
}); |
192 | 341 |
ListCellRenderer renderer = new ListCellRenderer() { |
... | ... | |
235 | 384 |
CharacterMarkerSymbol sym; |
236 | 385 |
try { |
237 | 386 |
sym = (CharacterMarkerSymbol) layer; |
238 |
// TODO finish it |
|
387 |
getCmbFonts().setSelectedItem(sym.getFont().getName()); |
|
388 |
getCmbFontSize().setSelectedItem(new Integer(sym.getFont().getSize())); |
|
389 |
getTxtXOffset().setText(String.valueOf(sym.getOffset().getX())); |
|
390 |
getTxtYOffset().setText(String.valueOf(-sym.getOffset().getY())); |
|
391 |
getJListSymbols().setSelectedIndex(sym.getUnicode()); |
|
392 |
getNumberAngle().setText(String.valueOf(sym.getRotation()/DEGREE_TO_RADIANS)); |
|
393 |
getColorChooser().setColor(sym.getColor()); |
|
394 |
// TODO mask |
|
239 | 395 |
} catch (IndexOutOfBoundsException ioEx) { |
240 | 396 |
NotificationManager.addWarning("Symbol layer index out of bounds", ioEx); |
241 | 397 |
} catch (ClassCastException ccEx) { |
... | ... | |
252 | 408 |
} |
253 | 409 |
|
254 | 410 |
public ISymbol getLayer() { |
255 |
if (layer == null) |
|
256 |
layer = new CharacterMarkerSymbol(); |
|
411 |
CharacterMarkerSymbol layer = new CharacterMarkerSymbol(); |
|
412 |
layer.setFont(font); |
|
413 |
layer.setUnicode(unicode); |
|
414 |
layer.setColor(getColorChooser().getColor()); |
|
415 |
layer.setSize(getCmbFontSize().getSelectedValue()); |
|
416 |
layer.setOffset(new Point2D.Double( |
|
417 |
getTxtXOffset().getValue().doubleValue(), |
|
418 |
-getTxtYOffset().getValue().doubleValue())); |
|
419 |
layer.setRotation(getNumberAngle().getValue().doubleValue()*DEGREE_TO_RADIANS); |
|
257 | 420 |
return layer; |
258 | 421 |
} |
259 | 422 |
|
Also available in: Unified diff