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 / SimpleMarker.java @ 47476
History | View | Annotate | Download (7.35 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.Dimension; |
28 |
import java.awt.FlowLayout; |
29 |
import java.awt.event.ActionEvent; |
30 |
import java.awt.event.ActionListener; |
31 |
import java.awt.event.FocusEvent; |
32 |
import java.awt.event.FocusListener; |
33 |
import java.awt.geom.Point2D; |
34 |
import java.util.ArrayList; |
35 |
import javax.swing.JCheckBox; |
36 |
import javax.swing.JPanel; |
37 |
import org.gvsig.andami.messages.NotificationManager; |
38 |
import org.gvsig.app.gui.panels.ColorChooserPanel; |
39 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
40 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
41 |
import org.gvsig.gui.beans.swing.JNumberSpinner; |
42 |
import org.gvsig.i18n.Messages; |
43 |
import org.gvsig.symbology.SymbologyLocator; |
44 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol; |
45 |
|
46 |
|
47 |
/**
|
48 |
* SimpleMarker allows the user to store and modify the main properties that
|
49 |
* define a <b>simple marker</b>.<p>
|
50 |
* <p>
|
51 |
* This functionality is carried out thanks to a tab (simple marker and mask)
|
52 |
* which are included in the panel to edit the properities of a symbol (SymbolEditor)
|
53 |
* how is explained in AbstractTypeSymbolEditor.<p>
|
54 |
* <p>
|
55 |
* This tab (Simple Marker)allows the user to change the different attributes
|
56 |
* which are color (<b>jccColor</b>),text size (<b>txtSize</b>),text offset
|
57 |
* (<b>txtXOffset</b> and <b>txtXOffset</b>), style of the marker (<b></b>)
|
58 |
* the width (<b>txtWidth</b>) and the style of the line (<b>cmbStyle</b>)
|
59 |
* and the color of the outline(<b>jccOutlineColor</b>).<p>
|
60 |
*
|
61 |
*@see Mask
|
62 |
*@see AbstractTypeSymbolEditor
|
63 |
*@author jaume dominguez faus - jaume.dominguez@iver.es
|
64 |
*/
|
65 |
public class SimpleMarker extends AbstractTypeSymbolEditor implements ActionListener, FocusListener{ |
66 |
|
67 |
private final ArrayList tabs = new ArrayList(); |
68 |
private ColorChooserPanel jccColor;
|
69 |
private JNumberSpinner txtSize;
|
70 |
private JNumberSpinner txtXOffset;
|
71 |
private JNumberSpinner txtYOffset;
|
72 |
//TODO: Comentarizado hasta que mask est? acabado
|
73 |
// private Mask mask;
|
74 |
private JComboBoxSimpleMarkeStyles cmbStyle;
|
75 |
private JCheckBox chkUseOutline; |
76 |
private ColorChooserPanel jccOutlineColor;
|
77 |
|
78 |
public SimpleMarker(SymbolEditor owner) {
|
79 |
super(owner);
|
80 |
initialize(); |
81 |
} |
82 |
/**
|
83 |
* Initializes the parameters that define a simplemarker.To do it,
|
84 |
* a tab is created inside the SymbolEditor panel with default values
|
85 |
* for the different attributes of the simple marker.Also, a mask will be
|
86 |
* added as a new tab.
|
87 |
*/
|
88 |
|
89 |
private void initialize() { |
90 |
JPanel myTab = new JPanel(new FlowLayout(FlowLayout.LEADING, 5,5)); |
91 |
myTab.setName(Messages.getText("simple_marker"));
|
92 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
93 |
|
94 |
// color chooser
|
95 |
jccColor = new ColorChooserPanel(true); |
96 |
jccColor.setAlpha(255);
|
97 |
|
98 |
aux.addComponent(Messages.getText("Color")+":", |
99 |
jccColor ); |
100 |
|
101 |
// marker width
|
102 |
txtSize = new JNumberSpinner(5.0, 25, 0.0, Double.MAX_VALUE, 1.0, 2); |
103 |
aux.addComponent(Messages.getText("size")+":", |
104 |
txtSize ); |
105 |
|
106 |
// marker xOffset
|
107 |
txtXOffset = new JNumberSpinner(0.0, 25, 0.0, Double.MAX_VALUE, 1.0, 2); |
108 |
aux.addComponent(Messages.getText("x_offset")+":", |
109 |
txtXOffset ); |
110 |
|
111 |
|
112 |
// marker width
|
113 |
txtYOffset = new JNumberSpinner(0.0, 25, 0.0, Double.MAX_VALUE, 1.0, 2); |
114 |
aux.addComponent(Messages.getText("y_offset")+":", |
115 |
txtYOffset ); |
116 |
|
117 |
// marker style
|
118 |
cmbStyle = new JComboBoxSimpleMarkeStyles();
|
119 |
aux.addComponent(Messages.getText("marker_style")+":", |
120 |
cmbStyle); |
121 |
|
122 |
// use outline
|
123 |
chkUseOutline = new JCheckBox(Messages.getText("use_outline")); |
124 |
aux.addComponent(chkUseOutline); |
125 |
|
126 |
// outline color
|
127 |
jccOutlineColor = new ColorChooserPanel(true); |
128 |
jccOutlineColor.setAlpha(255);
|
129 |
aux.addComponent(Messages.getText("outline_color"), jccOutlineColor);
|
130 |
|
131 |
aux.setPreferredSize(new Dimension(300, 300)); |
132 |
myTab.add(aux); |
133 |
|
134 |
// initialize defaults
|
135 |
jccColor.setColor(Color.BLACK);
|
136 |
cmbStyle.setSymbolColor(jccColor.getColor()); |
137 |
|
138 |
|
139 |
jccColor.addActionListener(this);
|
140 |
txtSize.addActionListener(this);
|
141 |
txtSize.addFocusListener(this);
|
142 |
txtXOffset.addActionListener(this);
|
143 |
txtXOffset.addFocusListener(this);
|
144 |
txtYOffset.addActionListener(this);
|
145 |
txtYOffset.addFocusListener(this);
|
146 |
cmbStyle.addActionListener(this);
|
147 |
chkUseOutline.addActionListener(this);
|
148 |
jccOutlineColor.addActionListener(this);
|
149 |
|
150 |
tabs.add(myTab); |
151 |
} |
152 |
|
153 |
@Override
|
154 |
public ISymbol getLayer() {
|
155 |
ISimpleMarkerSymbol layer = SymbologyLocator.getSymbologyManager().createSimpleMarkerSymbol(); |
156 |
layer.setColor(jccColor.getColor()); |
157 |
layer.setSize(txtSize.getDouble()); |
158 |
layer.setOffset(new Point2D.Double( |
159 |
txtXOffset.getDouble(), |
160 |
txtYOffset.getDouble())); |
161 |
layer.setStyle(((Integer) cmbStyle.getSelectedItem()));
|
162 |
layer.setOutlined(chkUseOutline.isSelected()); |
163 |
layer.setOutlineColor(jccOutlineColor.getColor()); |
164 |
return layer;
|
165 |
} |
166 |
|
167 |
@Override
|
168 |
public String getName() { |
169 |
return Messages.getText("simple_marker_symbol"); |
170 |
} |
171 |
|
172 |
@Override
|
173 |
public JPanel[] getTabs() { |
174 |
return (JPanel[]) tabs.toArray(new JPanel[0]); |
175 |
} |
176 |
|
177 |
@Override
|
178 |
public void refreshControls(ISymbol layer) { |
179 |
ISimpleMarkerSymbol sym; |
180 |
try {
|
181 |
if (layer == null) { |
182 |
// initialize defaults
|
183 |
System.err.println("SimpleLine.java:: should be unreachable code"); |
184 |
jccColor.setColor(Color.BLACK);
|
185 |
|
186 |
txtSize.setDouble(1.0);
|
187 |
txtXOffset.setDouble(0.0);
|
188 |
txtYOffset.setDouble(0.0);
|
189 |
} else {
|
190 |
sym = (ISimpleMarkerSymbol) layer; |
191 |
jccColor.setColor(sym.getColor()); |
192 |
|
193 |
txtSize.setDouble(sym.getSize()); |
194 |
txtXOffset.setDouble(sym.getOffset().getX()); |
195 |
txtYOffset.setDouble(sym.getOffset().getY()); |
196 |
cmbStyle.setSymbolColor(sym.getColor()); |
197 |
chkUseOutline.setSelected(sym.hasOutline()); |
198 |
cmbStyle.setOutlineColor(sym.getOutlineColor()); |
199 |
cmbStyle.setSelectedItem(sym.getStyle()); |
200 |
} |
201 |
} catch (IndexOutOfBoundsException ioEx) { |
202 |
NotificationManager.addWarning("Symbol layer index out of bounds", ioEx);
|
203 |
} catch (ClassCastException ccEx) { |
204 |
NotificationManager.addWarning("Illegal casting from " +
|
205 |
layer.getClass().getName() + " to ISimpleMarkerSymbol.", ccEx);
|
206 |
|
207 |
} |
208 |
} |
209 |
|
210 |
@Override
|
211 |
public void actionPerformed(ActionEvent e) { |
212 |
fireSymbolChangedEvent(); |
213 |
} |
214 |
|
215 |
@Override
|
216 |
public EditorTool[] getEditorTools() { |
217 |
return null; |
218 |
} |
219 |
@Override
|
220 |
public void focusGained(FocusEvent arg0) { |
221 |
// TODO Auto-generated method stub
|
222 |
|
223 |
} |
224 |
@Override
|
225 |
public void focusLost(FocusEvent arg0) { |
226 |
fireSymbolChangedEvent(); |
227 |
|
228 |
} |
229 |
@Override
|
230 |
public boolean canManageSymbol(ISymbol symbol) { |
231 |
return symbol instanceof ISimpleMarkerSymbol; |
232 |
|
233 |
} |
234 |
} |