svn-gvsig-desktop / 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 / MultiShapeSymbolSelector.java @ 39765
History | View | Annotate | Download (8.29 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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.BorderLayout; |
44 |
import java.awt.Component; |
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
|
48 |
import javax.swing.BorderFactory; |
49 |
import javax.swing.JButton; |
50 |
import javax.swing.JPanel; |
51 |
import javax.swing.JTabbedPane; |
52 |
import javax.swing.border.Border; |
53 |
|
54 |
import org.slf4j.Logger; |
55 |
import org.slf4j.LoggerFactory; |
56 |
|
57 |
import org.gvsig.andami.PluginServices; |
58 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
59 |
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector; |
60 |
import org.gvsig.fmap.geom.Geometry; |
61 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
62 |
import org.gvsig.fmap.geom.GeometryLocator; |
63 |
import org.gvsig.fmap.geom.GeometryManager; |
64 |
import org.gvsig.fmap.geom.type.GeometryType; |
65 |
import org.gvsig.i18n.Messages; |
66 |
import org.gvsig.symbology.SymbologyLocator; |
67 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.IMultiShapeSymbol; |
68 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
69 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
70 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
71 |
import org.gvsig.tools.exception.BaseException; |
72 |
|
73 |
|
74 |
public class MultiShapeSymbolSelector extends JPanel implements |
75 |
ISymbolSelector, ActionListener {
|
76 |
|
77 |
private static Logger logger = LoggerFactory.getLogger( |
78 |
MultiShapeSymbolSelector.class); |
79 |
|
80 |
private static final long serialVersionUID = 3967550608736418084L; |
81 |
private SymbolSelector markerSelector;
|
82 |
private SymbolSelector lineSelector;
|
83 |
private SymbolSelector fillSelector;
|
84 |
private WindowInfo wi;
|
85 |
private JTabbedPane tabbedPane; |
86 |
|
87 |
private GeometryManager gManager = null; |
88 |
private JButton closeButton = null; |
89 |
private JPanel closeButtonPanel = null; |
90 |
|
91 |
public static ISymbolSelector createSymbolBrowser() { |
92 |
WindowInfo winfo = new WindowInfo(WindowInfo.RESIZABLE|WindowInfo.MAXIMIZABLE|WindowInfo.ICONIFIABLE);
|
93 |
winfo.setWidth(706);
|
94 |
winfo.setHeight(500);
|
95 |
winfo.setTitle(Messages.getText("symbols_browser"));
|
96 |
MultiShapeSymbolSelector resp = null;
|
97 |
|
98 |
try {
|
99 |
/*
|
100 |
* This instantiates a symbol browser
|
101 |
* (a selector without accept/cancel panel)
|
102 |
*/
|
103 |
resp = new MultiShapeSymbolSelector();
|
104 |
resp.wi = winfo; |
105 |
} catch (BaseException e) {
|
106 |
logger.info("Unable to create symbol browser, will use selector.", e);
|
107 |
resp = new MultiShapeSymbolSelector(winfo);
|
108 |
} |
109 |
return resp;
|
110 |
} |
111 |
|
112 |
/*
|
113 |
* This instantiates a symbol browser
|
114 |
*/
|
115 |
private MultiShapeSymbolSelector() throws BaseException { |
116 |
|
117 |
GeometryType |
118 |
gt = getGeomManager().getGeometryType(Geometry.TYPES.POINT, |
119 |
SUBTYPES.GEOM2D); |
120 |
markerSelector = new SymbolSelectorBrowser(gt, true); |
121 |
gt = getGeomManager().getGeometryType(Geometry.TYPES.CURVE, |
122 |
SUBTYPES.GEOM2D); |
123 |
lineSelector = new SymbolSelectorBrowser(gt, true); |
124 |
gt = getGeomManager().getGeometryType(Geometry.TYPES.SURFACE, |
125 |
SUBTYPES.GEOM2D); |
126 |
fillSelector = new SymbolSelectorBrowser(gt, true); |
127 |
|
128 |
initialize(true);
|
129 |
} |
130 |
|
131 |
private MultiShapeSymbolSelector(WindowInfo wi) {
|
132 |
this((Object)null); |
133 |
this.wi = wi;
|
134 |
} |
135 |
|
136 |
MultiShapeSymbolSelector(Object currSymbol) {
|
137 |
IMultiShapeSymbol sym = (IMultiShapeSymbol) currSymbol; |
138 |
if (sym == null) { |
139 |
markerSelector = (SymbolSelector) SymbolSelector |
140 |
.createSymbolSelector(null, Geometry.TYPES.POINT);
|
141 |
lineSelector = (SymbolSelector) SymbolSelector |
142 |
.createSymbolSelector(null, Geometry.TYPES.CURVE);
|
143 |
fillSelector = (SymbolSelector) SymbolSelector |
144 |
.createSymbolSelector(null, Geometry.TYPES.SURFACE);
|
145 |
} else {
|
146 |
markerSelector = (SymbolSelector) SymbolSelector |
147 |
.createSymbolSelector(sym.getMarkerSymbol(), |
148 |
Geometry.TYPES.POINT); |
149 |
lineSelector = (SymbolSelector) SymbolSelector |
150 |
.createSymbolSelector(sym.getLineSymbol(), |
151 |
Geometry.TYPES.CURVE); |
152 |
fillSelector = (SymbolSelector) SymbolSelector |
153 |
.createSymbolSelector(sym.getFillSymbol(), |
154 |
Geometry.TYPES.SURFACE); |
155 |
} |
156 |
initialize(false);
|
157 |
} |
158 |
|
159 |
|
160 |
private void initialize(boolean add_close_button) { |
161 |
setLayout(new BorderLayout()); |
162 |
add(getJTabbedPane(), BorderLayout.CENTER);
|
163 |
if (add_close_button) {
|
164 |
add(getCloseButtonPanel(), BorderLayout.SOUTH);
|
165 |
} |
166 |
} |
167 |
|
168 |
private JTabbedPane getJTabbedPane() { |
169 |
if (tabbedPane == null) { |
170 |
tabbedPane = new JTabbedPane(); |
171 |
tabbedPane.addTab(Messages.getText("marker"), markerSelector);
|
172 |
tabbedPane.addTab(Messages.getText("line"), lineSelector);
|
173 |
tabbedPane.addTab(Messages.getText("fill"), fillSelector);
|
174 |
tabbedPane.setPreferredSize(getWindowInfo().getMinimumSize()); |
175 |
} |
176 |
|
177 |
return tabbedPane;
|
178 |
} |
179 |
|
180 |
|
181 |
public Object getSelectedObject() { |
182 |
|
183 |
IMultiShapeSymbol sym = SymbologyLocator.getSymbologyManager().createMultiShapeSymbol(); |
184 |
|
185 |
IMarkerSymbol ims = (IMarkerSymbol) markerSelector.getSelectedObject(); |
186 |
ILineSymbol ils = (ILineSymbol) lineSelector.getSelectedObject(); |
187 |
IFillSymbol ifs = (IFillSymbol) fillSelector.getSelectedObject(); |
188 |
|
189 |
if (ims == null || ils == null || ifs == null) { |
190 |
/*
|
191 |
* If one of the symbols is null, it's because the user
|
192 |
* has cancelled so those who have called this method must
|
193 |
* deal with null (many of them where already checking before
|
194 |
* this change)
|
195 |
*/
|
196 |
return null; |
197 |
} else {
|
198 |
sym.setMarkerSymbol(ims); |
199 |
sym.setLineSymbol(ils); |
200 |
sym.setFillSymbol(ifs); |
201 |
return sym;
|
202 |
} |
203 |
|
204 |
|
205 |
} |
206 |
|
207 |
public void setSymbol(Object symbol) { |
208 |
IMultiShapeSymbol sym = (IMultiShapeSymbol) symbol; |
209 |
markerSelector.setSymbol(sym.getMarkerSymbol()); |
210 |
lineSelector.setSymbol(sym.getLineSymbol()); |
211 |
fillSelector.setSymbol(sym.getFillSymbol()); |
212 |
} |
213 |
|
214 |
public WindowInfo getWindowInfo() {
|
215 |
if (wi == null) { |
216 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
217 |
wi.setWidth(706);
|
218 |
wi.setHeight(500);
|
219 |
wi.setTitle(Messages.getText("symbol_selector"));
|
220 |
} |
221 |
return wi;
|
222 |
} |
223 |
|
224 |
public Object getWindowProfile() { |
225 |
if( wi.isModal() ) {
|
226 |
return WindowInfo.DIALOG_PROFILE;
|
227 |
} |
228 |
return WindowInfo.EDITOR_PROFILE;
|
229 |
} |
230 |
|
231 |
private GeometryManager getGeomManager() {
|
232 |
|
233 |
if (gManager == null) { |
234 |
gManager = GeometryLocator.getGeometryManager(); |
235 |
} |
236 |
return gManager;
|
237 |
} |
238 |
|
239 |
private JButton getCloseButton() { |
240 |
if (closeButton == null) { |
241 |
String txt = Messages.getText("close"); |
242 |
closeButton = new JButton(txt); |
243 |
closeButton.addActionListener(this);
|
244 |
} |
245 |
return closeButton;
|
246 |
} |
247 |
|
248 |
private Component getCloseButtonPanel() { |
249 |
|
250 |
if (closeButtonPanel == null) { |
251 |
closeButtonPanel = new JPanel(); |
252 |
Border brd = BorderFactory.createEmptyBorder(10, 10, 10, 10); |
253 |
closeButtonPanel.setBorder(brd); |
254 |
closeButtonPanel.setLayout(new BorderLayout()); |
255 |
closeButtonPanel.add(getCloseButton(), BorderLayout.EAST);
|
256 |
} |
257 |
return closeButtonPanel;
|
258 |
} |
259 |
|
260 |
public void actionPerformed(ActionEvent e) { |
261 |
|
262 |
if (e.getSource() == this.getCloseButton()) { |
263 |
PluginServices.getMDIManager().closeWindow(this);
|
264 |
} |
265 |
|
266 |
} |
267 |
|
268 |
} |