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:
033: package com.vividsolutions.jump.workbench.ui.plugin.wms;
034:
035: import java.awt.Dimension;
036: import java.util.Iterator;
037:
038: import javax.swing.JLabel;
039:
040: import com.vividsolutions.jump.I18N;
041: import com.vividsolutions.jump.workbench.WorkbenchContext;
042: import com.vividsolutions.jump.workbench.model.Layerable;
043: import com.vividsolutions.jump.workbench.model.WMSLayer;
044: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
045: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
046: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
047: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
048: import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
049: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
050: import com.vividsolutions.wms.MapLayer;
051: import com.vividsolutions.wms.WMService;
052:
053: public class EditWMSQueryPlugIn extends AbstractPlugIn {
054: public MultiEnableCheck createEnableCheck(
055: final WorkbenchContext workbenchContext) {
056: EnableCheckFactory checkFactory = new EnableCheckFactory(
057: workbenchContext);
058:
059: return new MultiEnableCheck()
060: .add(
061: checkFactory
062: .createWindowWithLayerNamePanelMustBeActiveCheck())
063: .add(
064: checkFactory
065: .createExactlyNLayerablesMustBeSelectedCheck(
066: 1, Layerable.class));
067: }
068:
069: public boolean execute(PlugInContext context) throws Exception {
070: WMSLayer layer = (WMSLayer) context.getLayerNamePanel()
071: .selectedNodes(WMSLayer.class).iterator().next();
072: MultiInputDialog dialog = new MultiInputDialog(
073: context.getWorkbenchFrame(),
074: I18N
075: .get("ui.plugin.wms.EditWMSQueryPlugIn.edit-wms-query"),
076: true);
077: dialog.setInset(0);
078: dialog.setSideBarImage(IconLoader.icon("EditWMSLayer.jpg"));
079: dialog
080: .setSideBarDescription(I18N
081: .get("ui.plugin.wms.EditWMSQueryPlugIn.this-dialog-enables-you-to-change-the-layers-being-retrieved-from-a-web-map-server"));
082:
083: EditWMSQueryPanel panel = new EditWMSQueryPanel(layer
084: .getService(), layer.getLayerNames(), layer.getSRS(),
085: layer.getAlpha());
086: panel.setPreferredSize(new Dimension(600, 450));
087:
088: //The field name "Chosen Layers" will appear on validation error messages
089: //e.g. if the user doesn't pick any layers. [Jon Aquino]
090: dialog.addRow(I18N
091: .get("ui.plugin.wms.EditWMSQueryPlugIn.chosen-layers"),
092: new JLabel(""), panel, panel.getEnableChecks(), null);
093: dialog.setVisible(true);
094:
095: if (dialog.wasOKPressed()) {
096: layer.removeAllLayerNames();
097:
098: for (Iterator i = panel.getChosenMapLayers().iterator(); i
099: .hasNext();) {
100: MapLayer mapLayer = (MapLayer) i.next();
101: layer.addLayerName(mapLayer.getName());
102: }
103:
104: layer.setSRS(panel.getSRS());
105: layer.setAlpha(panel.getAlpha());
106: layer.fireAppearanceChanged();
107:
108: return true;
109: }
110:
111: return false;
112: }
113: }
|