001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032: package de.latlon.deejump.plugin.style;
033:
034: import java.awt.Component;
035: import java.awt.Dimension;
036: import java.awt.GridBagLayout;
037: import java.util.ArrayList;
038: import java.util.Arrays;
039: import java.util.Collection;
040: import java.util.Iterator;
041:
042: import javax.swing.ImageIcon;
043: import javax.swing.JComponent;
044: import javax.swing.JLabel;
045: import javax.swing.JPanel;
046: import javax.swing.JTabbedPane;
047:
048: import com.vividsolutions.jts.util.Assert;
049: import com.vividsolutions.jump.I18N;
050: import com.vividsolutions.jump.feature.Feature;
051: import com.vividsolutions.jump.workbench.WorkbenchContext;
052: import com.vividsolutions.jump.workbench.model.Layer;
053: import com.vividsolutions.jump.workbench.model.UndoableCommand;
054: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
055: import com.vividsolutions.jump.workbench.plugin.EnableCheck;
056: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
057: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
058: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
059: import com.vividsolutions.jump.workbench.ui.GUIUtil;
060: import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
061: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
062: import com.vividsolutions.jump.workbench.ui.renderer.style.ColorThemingStylePanel;
063: import com.vividsolutions.jump.workbench.ui.style.DecorationStylePanel;
064: import com.vividsolutions.jump.workbench.ui.style.LabelStylePanel;
065: import com.vividsolutions.jump.workbench.ui.style.ScaleStylePanel;
066: import com.vividsolutions.jump.workbench.ui.style.StylePanel;
067:
068: public class DeeChangeStylesPlugIn extends AbstractPlugIn {
069: private final static String LAST_TAB_KEY = DeeChangeStylesPlugIn.class
070: .getName()
071: + " - LAST TAB";
072:
073: public String getName() {
074: return I18N.get("ui.style.ChangeStylesPlugIn.change-styles");
075: }
076:
077: public DeeChangeStylesPlugIn() {
078: }
079:
080: public boolean execute(PlugInContext context) throws Exception {
081: final Layer layer = context.getSelectedLayer(0);
082: MultiInputDialog dialog = new MultiInputDialog(context
083: .getWorkbenchFrame(), I18N
084: .get("ui.style.ChangeStylesPlugIn.change-styles"), true);
085: dialog.setInset(0);
086: dialog.setSideBarImage(IconLoader.icon("Symbology.gif"));
087: dialog
088: .setSideBarDescription(I18N
089: .get("ui.style.ChangeStylesPlugIn.you-can-use-this-dialog-to-change-the-colour-line-width"));
090:
091: final ArrayList stylePanels = new ArrayList();
092: DeeRenderingStylePanel renderingStylePanel = new DeeRenderingStylePanel(
093: context.getWorkbenchContext().getWorkbench()
094: .getBlackboard(), layer);
095:
096: stylePanels.add(renderingStylePanel);
097: stylePanels.add(new ScaleStylePanel(layer, context
098: .getLayerViewPanel()));
099:
100: //Only set preferred size for DecorationStylePanel or ColorThemingStylePanel;
101: //otherwise they will grow to the height of the screen. But don't set
102: //the preferred size of LabelStylePanel to (400, 300) -- in fact, it needs
103: //a bit more height -- any less, and its text boxes will shrink to
104: //zero-width. I've found that if you don't give text boxes enough height,
105: //they simply shrink to zero-width. [Jon Aquino]
106: DecorationStylePanel decorationStylePanel = new DecorationStylePanel(
107: layer, context.getWorkbenchFrame()
108: .getChoosableStyleClasses());
109: decorationStylePanel.setPreferredSize(new Dimension(400, 300));
110: if (layer.getFeatureCollectionWrapper().getFeatureSchema()
111: .getAttributeCount() > 1) {
112: Iterator iter = layer.getFeatureCollectionWrapper()
113: .getUltimateWrappee().getFeatures().iterator();
114: String type = "";
115: if (iter.hasNext()) {
116: Feature f = (Feature) iter.next();
117: type = f.getGeometry().getGeometryType();
118:
119: }
120:
121: if ("MultiPoint".equals(type) || "Point".equals(type)) {
122: //-- [sstein 18.oct 2006] test de-activation and using original
123: // DeeColorThemingStylePanel deeColorThemingStylePanel = new DeeColorThemingStylePanel(layer,
124: // context.getWorkbenchContext());
125: ColorThemingStylePanel colorThemingStylePanel = new ColorThemingStylePanel(
126: layer, context.getWorkbenchContext());
127: // deeColorThemingStylePanel.setPreferredSize(new Dimension(400, 300));
128: colorThemingStylePanel.setPreferredSize(new Dimension(
129: 400, 300));
130: // stylePanels.add(deeColorThemingStylePanel);
131: stylePanels.add(colorThemingStylePanel);
132: GUIUtil.sync(renderingStylePanel
133: .getTransparencySlider(),
134: // deeColorThemingStylePanel.getTransparencySlider());
135: colorThemingStylePanel.getTransparencySlider());
136: GUIUtil
137: .sync(renderingStylePanel
138: .getSynchronizeCheckBox(),
139: // deeColorThemingStylePanel.getSynchronizeCheckBox());
140: colorThemingStylePanel
141: .getSynchronizeCheckBox());
142:
143: } else {
144: ColorThemingStylePanel colorThemingStylePanel = new ColorThemingStylePanel(
145: layer, context.getWorkbenchContext());
146: colorThemingStylePanel.setPreferredSize(new Dimension(
147: 400, 300));
148: stylePanels.add(colorThemingStylePanel);
149: GUIUtil.sync(renderingStylePanel
150: .getTransparencySlider(),
151: colorThemingStylePanel.getTransparencySlider());
152: GUIUtil
153: .sync(renderingStylePanel
154: .getSynchronizeCheckBox(),
155: colorThemingStylePanel
156: .getSynchronizeCheckBox());
157:
158: }
159:
160: } else {
161: stylePanels.add(new DummyColorThemingStylePanel());
162: }
163:
164: stylePanels
165: .add(new LabelStylePanel(layer, context
166: .getLayerViewPanel(), dialog, context
167: .getErrorHandler()));
168: stylePanels.add(decorationStylePanel);
169:
170: JTabbedPane tabbedPane = new JTabbedPane();
171:
172: for (Iterator i = stylePanels.iterator(); i.hasNext();) {
173: final StylePanel stylePanel = (StylePanel) i.next();
174: tabbedPane.add((Component) stylePanel, stylePanel
175: .getTitle());
176: dialog.addEnableChecks(stylePanel.getTitle(), Arrays
177: .asList(new EnableCheck[] { new EnableCheck() {
178: public String check(JComponent component) {
179: return stylePanel.validateInput();
180: }
181: } }));
182: }
183:
184: dialog.addRow(tabbedPane);
185: tabbedPane.setSelectedComponent(find(stylePanels,
186: (String) context.getWorkbenchContext().getWorkbench()
187: .getBlackboard().get(
188: LAST_TAB_KEY,
189: ((StylePanel) stylePanels.iterator()
190: .next()).getTitle())));
191: dialog.setVisible(true);
192: context
193: .getWorkbenchContext()
194: .getWorkbench()
195: .getBlackboard()
196: .put(
197: LAST_TAB_KEY,
198: ((StylePanel) tabbedPane.getSelectedComponent())
199: .getTitle());
200:
201: if (dialog.wasOKPressed()) {
202: final Collection oldStyles = layer.cloneStyles();
203: layer.getLayerManager().deferFiringEvents(new Runnable() {
204: public void run() {
205: for (Iterator i = stylePanels.iterator(); i
206: .hasNext();) {
207: StylePanel stylePanel = (StylePanel) i.next();
208: stylePanel.updateStyles();
209: }
210:
211: }
212: });
213:
214: final Collection newStyles = layer.cloneStyles();
215: execute(new UndoableCommand(getName()) {
216: public void execute() {
217: layer.setStyles(newStyles);
218: }
219:
220: public void unexecute() {
221: layer.setStyles(oldStyles);
222: }
223: }, context);
224: return true;
225: }
226:
227: return false;
228: }
229:
230: private Component find(Collection stylePanels, String title) {
231: for (Iterator i = stylePanels.iterator(); i.hasNext();) {
232: StylePanel stylePanel = (StylePanel) i.next();
233:
234: if (stylePanel.getTitle().equals(title)) {
235: return (Component) stylePanel;
236: }
237: }
238:
239: Assert.shouldNeverReachHere();
240:
241: return null;
242: }
243:
244: public ImageIcon getIcon() {
245: return IconLoader.icon("Palette.gif");
246: }
247:
248: public MultiEnableCheck createEnableCheck(
249: final WorkbenchContext workbenchContext) {
250: EnableCheckFactory checkFactory = new EnableCheckFactory(
251: workbenchContext);
252:
253: return new MultiEnableCheck()
254: .add(
255: checkFactory
256: .createWindowWithLayerNamePanelMustBeActiveCheck())
257: // ScaledStylePanel assumes that the active window has a LayerViewPanel. [Jon Aquino 2005-08-09]
258: .add(
259: checkFactory
260: .createWindowWithLayerViewPanelMustBeActiveCheck())
261: .add(
262: checkFactory
263: .createExactlyNLayersMustBeSelectedCheck(1));
264: }
265:
266: private class DummyColorThemingStylePanel extends JPanel implements
267: StylePanel {
268: public DummyColorThemingStylePanel() {
269: //GridBagLayout so it gets centered. [Jon Aquino]
270: super (new GridBagLayout());
271: add(new JLabel(
272: I18N
273: .get("ui.style.ChangeStylesPlugIn.this-layer-has-no-attributes")));
274: }
275:
276: public String getTitle() {
277: //return DeeColorThemingStylePanel.TITLE;
278: return ColorThemingStylePanel.TITLE;
279: }
280:
281: public void updateStyles() {
282: }
283:
284: public String validateInput() {
285: return null;
286: }
287: }
288: }
|