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.plugin;
034:
035: import javax.swing.JInternalFrame;
036:
037: import com.vividsolutions.jts.geom.Envelope;
038: import com.vividsolutions.jump.feature.FeatureCollection;
039: import com.vividsolutions.jump.workbench.WorkbenchContext;
040: import com.vividsolutions.jump.workbench.driver.DriverManager;
041: import com.vividsolutions.jump.workbench.model.Layer;
042: import com.vividsolutions.jump.workbench.model.LayerManager;
043: import com.vividsolutions.jump.workbench.model.LayerManagerProxy;
044: import com.vividsolutions.jump.workbench.model.Task;
045: import com.vividsolutions.jump.workbench.ui.ErrorHandler;
046: import com.vividsolutions.jump.workbench.ui.HTMLFrame;
047: import com.vividsolutions.jump.workbench.ui.LayerNamePanel;
048: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
049: import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
050: import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;
051:
052: /**
053: * Passed to PlugIns to enable them to access the rest of the JUMP Workbench.
054: * @see PlugIn
055: */
056: public class PlugInContext implements LayerManagerProxy {
057: private Task task;
058: private LayerNamePanel layerNamePanel;
059: private LayerViewPanel layerViewPanel;
060: private WorkbenchContext workbenchContext;
061: private EnableCheckFactory checkFactory;
062: private FeatureInstaller featureInstaller;
063: private LayerManagerProxy layerManagerProxy;
064:
065: public PlugInContext(WorkbenchContext workbenchContext, Task task,
066: LayerManagerProxy layerManagerProxy,
067: LayerNamePanel layerNamePanel, LayerViewPanel layerViewPanel) {
068: this .workbenchContext = workbenchContext;
069: this .task = task;
070: this .layerManagerProxy = layerManagerProxy;
071: this .layerNamePanel = layerNamePanel;
072: this .layerViewPanel = layerViewPanel;
073: checkFactory = new EnableCheckFactory(workbenchContext);
074: featureInstaller = new FeatureInstaller(workbenchContext);
075: }
076:
077: public DriverManager getDriverManager() {
078: return workbenchContext.getDriverManager();
079: }
080:
081: public ErrorHandler getErrorHandler() {
082: return workbenchContext.getErrorHandler();
083: }
084:
085: public WorkbenchContext getWorkbenchContext() {
086: return workbenchContext;
087: }
088:
089: /**
090: *@return the ith layer clicked on the layer-list panel,
091: * or null if the user hasn't clicked an ith layer
092: */
093: public Layer getSelectedLayer(int i) {
094: Layer[] selectedLayers = getSelectedLayers();
095:
096: if (selectedLayers.length > i) {
097: return selectedLayers[i];
098: }
099:
100: return null;
101: }
102:
103: /**
104: * @return the ith selected layer, or if there is none, the ith layer
105: */
106: public Layer getCandidateLayer(int i) {
107: Layer lyr = getSelectedLayer(i);
108:
109: if (lyr != null) {
110: return lyr;
111: }
112:
113: return getLayerManager().getLayer(i);
114: }
115:
116: //<<TODO:DESIGN>> Return List instead of array [Jon Aquino]
117: public Layer[] getSelectedLayers() {
118: return getLayerNamePanel().getSelectedLayers();
119: }
120:
121: public Envelope getSelectedLayerEnvelope() {
122: return getSelectedLayer(0).getFeatureCollectionWrapper()
123: .getEnvelope();
124: }
125:
126: public Task getTask() {
127: return task;
128: }
129:
130: public LayerNamePanel getLayerNamePanel() {
131: return layerNamePanel;
132: }
133:
134: public LayerManager getLayerManager() {
135: return layerManagerProxy.getLayerManager();
136: }
137:
138: public LayerViewPanel getLayerViewPanel() {
139: return layerViewPanel;
140: }
141:
142: public WorkbenchFrame getWorkbenchFrame() {
143: return workbenchContext.getWorkbench().getFrame();
144: }
145:
146: public Layer addLayer(String categoryName, String layerName,
147: FeatureCollection featureCollection) {
148: return getLayerManager().addLayer(categoryName, layerName,
149: featureCollection);
150: }
151:
152: public HTMLFrame getOutputFrame() {
153: return workbenchContext.getWorkbench().getFrame()
154: .getOutputFrame();
155: }
156:
157: public JInternalFrame getActiveInternalFrame() {
158: return workbenchContext.getWorkbench().getFrame()
159: .getActiveInternalFrame();
160: }
161:
162: public EnableCheckFactory getCheckFactory() {
163: return checkFactory;
164: }
165:
166: public FeatureInstaller getFeatureInstaller() {
167: return featureInstaller;
168: }
169:
170: }
|