root / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / Mask.java @ 34294
History | View | Annotate | Download (6.85 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 |
package org.gvsig.app.gui.styling; |
42 |
|
43 |
import java.awt.FlowLayout; |
44 |
import java.awt.GridLayout; |
45 |
import java.awt.event.ActionListener; |
46 |
|
47 |
import javax.swing.BorderFactory; |
48 |
import javax.swing.ButtonGroup; |
49 |
import javax.swing.JLabel; |
50 |
import javax.swing.JPanel; |
51 |
import javax.swing.JRadioButton; |
52 |
|
53 |
import org.gvsig.andami.PluginServices; |
54 |
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector; |
55 |
import org.gvsig.fmap.geom.Geometry; |
56 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
57 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
58 |
import org.gvsig.gui.beans.swing.JButton; |
59 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
60 |
import org.gvsig.i18n.Messages; |
61 |
import org.gvsig.symbology.SymbologyLocator; |
62 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
63 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask; |
64 |
|
65 |
|
66 |
/**
|
67 |
* Implements a tab to modify attributes of a mask as style,size and
|
68 |
* symbol (to represent a point in the map)which can be applied to
|
69 |
* symbols like simple text, simple marker,picture marker and character marker.<p>
|
70 |
* <p>
|
71 |
* This tab is used several times in different places in our applicattion .For
|
72 |
* this reason, in order to avoid the repetition of code, this class has been
|
73 |
* created (instead of treat it like a simple tab). With this solution, the user
|
74 |
* only has to refer it to use it (and do not need to create a tab and fill it again
|
75 |
* and so on).
|
76 |
*
|
77 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
78 |
*/
|
79 |
public class Mask extends JPanel { |
80 |
/**
|
81 |
*
|
82 |
*/
|
83 |
private static final long serialVersionUID = 101766990165772454L; |
84 |
private JButton btnHaloSymbol; |
85 |
private JRadioButton rdBtnHalo; |
86 |
private JRadioButton rdBtnNone; |
87 |
private JIncrementalNumberField txtHaloSize;
|
88 |
private IFillSymbol fill;
|
89 |
private AbstractTypeSymbolEditor owner;
|
90 |
private ActionListener action = new ActionListener() { |
91 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
92 |
owner.fireSymbolChangedEvent(); |
93 |
}; |
94 |
}; |
95 |
/**
|
96 |
* Constructor method that initializes the parameters to create a tab to modify
|
97 |
* attributes of a mask for points such as style,size and symbol (to represent a point
|
98 |
* in the map).
|
99 |
* @param owner
|
100 |
*/
|
101 |
public Mask(AbstractTypeSymbolEditor owner) {
|
102 |
super();
|
103 |
setName(Messages.getText("mask"));
|
104 |
|
105 |
this.owner = owner;
|
106 |
|
107 |
GridBagLayoutPanel aux = new GridBagLayoutPanel();
|
108 |
aux.setBorder(BorderFactory.createTitledBorder(Messages.getText("style"))); |
109 |
JPanel stylePanel = new JPanel(new GridLayout(2, 1)); |
110 |
stylePanel.add(getRdNone()); |
111 |
stylePanel.add(getRdHalo()); |
112 |
aux.addComponent(stylePanel); |
113 |
ButtonGroup group = new ButtonGroup(); |
114 |
group.add(getRdNone()); |
115 |
group.add(getRdHalo()); |
116 |
|
117 |
JPanel aux2 = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
118 |
aux2.add(new JLabel(Messages.getText("size")+":")); |
119 |
aux2.add(getTxtHaloSize()); |
120 |
aux2.add(getBtnHaloSymbol()); |
121 |
|
122 |
getRdNone().addActionListener(action); |
123 |
getRdHalo().addActionListener(action); |
124 |
getTxtHaloSize().addActionListener(action); |
125 |
|
126 |
add(aux); |
127 |
add(aux2); |
128 |
} |
129 |
/**
|
130 |
* Obbtains the size for the text halo.This size is taken from a
|
131 |
* JIncrementalNumberField. If this component does not exist,
|
132 |
* a new JIncrementalNumberField is created to specify it.
|
133 |
* @return
|
134 |
*/
|
135 |
private JIncrementalNumberField getTxtHaloSize() {
|
136 |
if (txtHaloSize == null) { |
137 |
txtHaloSize = new JIncrementalNumberField(String.valueOf(0), 5, 0, Double.MAX_VALUE, 1); |
138 |
} |
139 |
|
140 |
return txtHaloSize;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Creates the button that allows the user to select the symbol that will substitute
|
145 |
* a point in the map.
|
146 |
* @return
|
147 |
*/
|
148 |
private JButton getBtnHaloSymbol() { |
149 |
if (btnHaloSymbol == null) { |
150 |
btnHaloSymbol = new JButton(Messages.getText("symbol")); |
151 |
btnHaloSymbol.addActionListener(new ActionListener() { |
152 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
153 |
ISymbolSelector symSel = SymbolSelector.createSymbolSelector( |
154 |
fill, Geometry.TYPES.SURFACE); |
155 |
PluginServices.getMDIManager().addCentredWindow(symSel); |
156 |
fill = (IFillSymbol) symSel.getSelectedObject(); |
157 |
}; |
158 |
}); |
159 |
} |
160 |
|
161 |
return btnHaloSymbol;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* Determines if the halo style is selected.If the Radio button
|
166 |
* that determines this information does not exist, a new radio button
|
167 |
* is created for this purpose.
|
168 |
* @return
|
169 |
*/
|
170 |
private JRadioButton getRdHalo() { |
171 |
if (rdBtnHalo == null) { |
172 |
rdBtnHalo = new JRadioButton(Messages.getText("halo")); |
173 |
} |
174 |
|
175 |
return rdBtnHalo;
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* Determines if there will be no defined style for a point (without halo).
|
180 |
* If the Radio button that determines this information does not exist,
|
181 |
* a new radio button is created for this purpose.
|
182 |
* @return
|
183 |
*/
|
184 |
private JRadioButton getRdNone() { |
185 |
if (rdBtnNone == null) { |
186 |
rdBtnNone = new JRadioButton(Messages.getText("none")); |
187 |
rdBtnNone.setSelected(true);
|
188 |
} |
189 |
|
190 |
return rdBtnNone;
|
191 |
} |
192 |
/**
|
193 |
* Sets the graphical component that shows the properties of the model.
|
194 |
* @param mask
|
195 |
*/
|
196 |
public void setModel(IMask mask) { |
197 |
if (mask != null) { |
198 |
getTxtHaloSize().setDouble(mask.getSize()); |
199 |
fill = mask.getFillSymbol(); |
200 |
} |
201 |
getRdHalo().setSelected(mask != null);
|
202 |
} |
203 |
/**
|
204 |
* Returns an IMask or null depending on the option
|
205 |
* that the user had decided (if he wants a mask or not)in the tab "mask" inside
|
206 |
* the panel to edit the properities of a symbol (SymbolEditor).
|
207 |
* If the user
|
208 |
* wants it, a new IMask is created.
|
209 |
* @return
|
210 |
*/
|
211 |
public IMask getMask() {
|
212 |
if (!getRdHalo().isSelected()) return null; |
213 |
|
214 |
IMask mask = SymbologyLocator.getSymbologyManager().createMask(); |
215 |
if (fill == null) { |
216 |
fill = |
217 |
(IFillSymbol) MapContextLocator.getSymbolManager() |
218 |
.createSymbol(IFillSymbol.SYMBOL_NAME); |
219 |
} |
220 |
mask.setFillSymbol(fill); |
221 |
mask.setSize(getTxtHaloSize().getDouble()); |
222 |
return mask;
|
223 |
} |
224 |
|
225 |
} |