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 @ 41682
History | View | Annotate | Download (8.23 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 = null;
|
121 |
try {
|
122 |
sym = (IMultiShapeSymbol) currSymbol; |
123 |
} catch(Exception ex) { |
124 |
logger.warn("Incorrect symbol type, use default.",ex);
|
125 |
} |
126 |
if (sym == null) { |
127 |
markerSelector = (SymbolSelector) SymbolSelector |
128 |
.createSymbolSelector(null, Geometry.TYPES.POINT);
|
129 |
lineSelector = (SymbolSelector) SymbolSelector |
130 |
.createSymbolSelector(null, Geometry.TYPES.CURVE);
|
131 |
fillSelector = (SymbolSelector) SymbolSelector |
132 |
.createSymbolSelector(null, Geometry.TYPES.SURFACE);
|
133 |
} else {
|
134 |
markerSelector = (SymbolSelector) SymbolSelector |
135 |
.createSymbolSelector(sym.getMarkerSymbol(), |
136 |
Geometry.TYPES.POINT); |
137 |
lineSelector = (SymbolSelector) SymbolSelector |
138 |
.createSymbolSelector(sym.getLineSymbol(), |
139 |
Geometry.TYPES.CURVE); |
140 |
fillSelector = (SymbolSelector) SymbolSelector |
141 |
.createSymbolSelector(sym.getFillSymbol(), |
142 |
Geometry.TYPES.SURFACE); |
143 |
} |
144 |
initialize(false);
|
145 |
} |
146 |
|
147 |
|
148 |
private void initialize(boolean add_close_button) { |
149 |
setLayout(new BorderLayout()); |
150 |
add(getJTabbedPane(), BorderLayout.CENTER);
|
151 |
if (add_close_button) {
|
152 |
add(getCloseButtonPanel(), BorderLayout.SOUTH);
|
153 |
} |
154 |
} |
155 |
|
156 |
private JTabbedPane getJTabbedPane() { |
157 |
if (tabbedPane == null) { |
158 |
tabbedPane = new JTabbedPane(); |
159 |
tabbedPane.addTab(Messages.getText("marker"), markerSelector);
|
160 |
tabbedPane.addTab(Messages.getText("line"), lineSelector);
|
161 |
tabbedPane.addTab(Messages.getText("fill"), fillSelector);
|
162 |
tabbedPane.setPreferredSize(getWindowInfo().getMinimumSize()); |
163 |
} |
164 |
|
165 |
return tabbedPane;
|
166 |
} |
167 |
|
168 |
|
169 |
public Object getSelectedObject() { |
170 |
|
171 |
IMultiShapeSymbol sym = SymbologyLocator.getSymbologyManager().createMultiShapeSymbol(); |
172 |
|
173 |
IMarkerSymbol ims = (IMarkerSymbol) markerSelector.getSelectedObject(); |
174 |
ILineSymbol ils = (ILineSymbol) lineSelector.getSelectedObject(); |
175 |
IFillSymbol ifs = (IFillSymbol) fillSelector.getSelectedObject(); |
176 |
|
177 |
if (ims == null || ils == null || ifs == null) { |
178 |
/*
|
179 |
* If one of the symbols is null, it's because the user
|
180 |
* has cancelled so those who have called this method must
|
181 |
* deal with null (many of them where already checking before
|
182 |
* this change)
|
183 |
*/
|
184 |
return null; |
185 |
} else {
|
186 |
sym.setMarkerSymbol(ims); |
187 |
sym.setLineSymbol(ils); |
188 |
sym.setFillSymbol(ifs); |
189 |
return sym;
|
190 |
} |
191 |
|
192 |
|
193 |
} |
194 |
|
195 |
public void setSymbol(Object symbol) { |
196 |
IMultiShapeSymbol sym = (IMultiShapeSymbol) symbol; |
197 |
markerSelector.setSymbol(sym.getMarkerSymbol()); |
198 |
lineSelector.setSymbol(sym.getLineSymbol()); |
199 |
fillSelector.setSymbol(sym.getFillSymbol()); |
200 |
} |
201 |
|
202 |
public WindowInfo getWindowInfo() {
|
203 |
if (wi == null) { |
204 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
205 |
wi.setWidth(706);
|
206 |
wi.setHeight(500);
|
207 |
wi.setTitle(Messages.getText("symbol_selector"));
|
208 |
} |
209 |
return wi;
|
210 |
} |
211 |
|
212 |
public Object getWindowProfile() { |
213 |
if( wi.isModal() ) {
|
214 |
return WindowInfo.DIALOG_PROFILE;
|
215 |
} |
216 |
return WindowInfo.EDITOR_PROFILE;
|
217 |
} |
218 |
|
219 |
private GeometryManager getGeomManager() {
|
220 |
|
221 |
if (gManager == null) { |
222 |
gManager = GeometryLocator.getGeometryManager(); |
223 |
} |
224 |
return gManager;
|
225 |
} |
226 |
|
227 |
private JButton getCloseButton() { |
228 |
if (closeButton == null) { |
229 |
String txt = Messages.getText("close"); |
230 |
closeButton = new JButton(txt); |
231 |
closeButton.addActionListener(this);
|
232 |
} |
233 |
return closeButton;
|
234 |
} |
235 |
|
236 |
private Component getCloseButtonPanel() { |
237 |
|
238 |
if (closeButtonPanel == null) { |
239 |
closeButtonPanel = new JPanel(); |
240 |
Border brd = BorderFactory.createEmptyBorder(10, 10, 10, 10); |
241 |
closeButtonPanel.setBorder(brd); |
242 |
closeButtonPanel.setLayout(new BorderLayout()); |
243 |
closeButtonPanel.add(getCloseButton(), BorderLayout.EAST);
|
244 |
} |
245 |
return closeButtonPanel;
|
246 |
} |
247 |
|
248 |
public void actionPerformed(ActionEvent e) { |
249 |
|
250 |
if (e.getSource() == this.getCloseButton()) { |
251 |
PluginServices.getMDIManager().closeWindow(this);
|
252 |
} |
253 |
|
254 |
} |
255 |
|
256 |
} |