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