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