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