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