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: * JUMP is Copyright (C) 2003 Vivid Solutions
006: *
007: * This program implements extensions to JUMP and is
008: * Copyright (C) 2004 Integrated Systems Analysts, Inc.
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU General Public License for more details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
023: *
024: * For more information, contact:
025: *
026: * Integrated Systems Analysts, Inc.
027: * 630C Anchors St., Suite 101
028: * Fort Walton Beach, Florida
029: * USA
030: *
031: * (850)862-7321
032: * www.ashs.isa.com
033: */
034:
035: package org.openjump.core.ui.plugin.view;
036:
037: import java.awt.Component;
038: import java.awt.Graphics;
039: import java.awt.event.ContainerEvent;
040: import java.awt.event.ContainerListener;
041: import java.util.Collection;
042: import java.util.Iterator;
043:
044: import com.vividsolutions.jts.geom.Envelope;
045: import com.vividsolutions.jts.geom.Geometry;
046: import com.vividsolutions.jump.I18N;
047: import com.vividsolutions.jump.io.datasource.DataSourceQuery;
048: import com.vividsolutions.jump.workbench.model.Layer;
049: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
050: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
051: import com.vividsolutions.jump.workbench.ui.LayerNamePanelListener;
052: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
053: import com.vividsolutions.jump.workbench.ui.LayerViewPanelListener;
054: import com.vividsolutions.jump.workbench.ui.TaskFrame;
055:
056: public class ShowFullPathPlugIn extends AbstractPlugIn {
057: PlugInContext gContext;
058: final static String sErrorSeeOutputWindow = I18N
059: .get("org.openjump.core.ui.plugin.view.ShowFullPathPlugIn.Error-See-Output-Window");
060: final static String sNumberSelected = I18N
061: .get("org.openjump.core.ui.plugin.view.ShowFullPathPlugIn.NumberSelected");
062:
063: //-- added by sstein for test reasons
064: // private LayerListener myLayerListener = new LayerListener() {
065: // public void categoryChanged(CategoryEvent e) {}
066: // public void featuresChanged(FeatureEvent e) {}
067: // public void layerChanged(LayerEvent e) {
068: // if (e.getType() == LayerEventType.ADDED || e.getType() == LayerEventType.REMOVED) {
069: // Collection layerCollection = (Collection) gContext.getWorkbenchContext().getLayerNamePanel().getLayerManager().getLayers();
070: // for (Iterator i = layerCollection.iterator(); i.hasNext();)
071: // {
072: // Layer layer = (Layer) i.next();
073: // if (layer.hasReadableDataSource())
074: // {
075: // DataSourceQuery dsq = layer.getDataSourceQuery();
076: // try{
077: // String fname = dsq.getDataSource().getProperties().get("File").toString();
078: // layer.setDescription(fname);
079: // }
080: // catch(Exception e){
081: // System.out.println("seems to be a database dataset" + e);
082: // } }
083: // }
084: // }
085: // }
086: // };
087:
088: private LayerNamePanelListener layerNamePanelListener = new LayerNamePanelListener() {
089: public void layerSelectionChanged() {
090: Collection layerCollection = (Collection) gContext
091: .getWorkbenchContext().getLayerNamePanel()
092: .getLayerManager().getLayers();
093: for (Iterator i = layerCollection.iterator(); i.hasNext();) {
094: Layer layer = (Layer) i.next();
095: if (layer.hasReadableDataSource()) {
096: DataSourceQuery dsq = layer.getDataSourceQuery();
097: String fname = "";
098: Object fnameObj = dsq.getDataSource()
099: .getProperties().get("File");
100: if (fnameObj != null)
101: fname = fnameObj.toString();
102: //layer.setDescription(fname);
103:
104: Object archiveObj = layer.getBlackboard().get(
105: "ArchiveFileName");
106: //if (archiveObj != null) layer.setDescription(archiveObj.toString());
107: }
108: }
109: }
110: };
111:
112: private LayerViewPanelListener layerViewPanelListener = new LayerViewPanelListener() {
113: public void selectionChanged() {
114: LayerViewPanel panel = gContext.getWorkbenchContext()
115: .getLayerViewPanel();
116: if (panel == null) {
117: return;
118: } //[Jon Aquino 2005-08-04]
119: Collection selectedFeatures = panel.getSelectionManager()
120: .getSelectedItems();
121: int numSel = selectedFeatures.size();
122: int numPts = 0;
123: for (Iterator i = selectedFeatures.iterator(); i.hasNext();)
124: numPts += ((Geometry) i.next()).getNumPoints();
125:
126: //LDB added the following to simulate 4D Draw Coordinates Panel
127: Envelope env = envelope(panel.getSelectionManager()
128: .getSelectedItems());
129: String sx = panel.format(env.getWidth());
130: String sy = panel.format(env.getHeight());
131: //gContext.getWorkbenchFrame().setTimeMessage(sNumberSelected + " " + numSel);
132: gContext.getWorkbenchFrame().setTimeMessage(
133: sNumberSelected + " " + numSel + " [" + sx + ", "
134: + sy + "] " + numPts + " pts");
135: }
136:
137: public void cursorPositionChanged(String x, String y) {
138:
139: }
140:
141: public void painted(Graphics graphics) {
142:
143: }
144: };
145:
146: public void initialize(PlugInContext context) throws Exception {
147: gContext = context;
148: // /*** added by sstein ***********************/
149: // //
150: // // Whenever anything happens on an internal frame we want to do this.
151: // //
152: // GUIUtil.addInternalFrameListener(
153: // context.getWorkbenchFrame().getDesktopPane(),
154: // GUIUtil.toInternalFrameListener(new ActionListener() {
155: // public void actionPerformed(ActionEvent e) {
156: // installListenersOnCurrentPanel();
157: // }
158: // }));
159: /**** original *********************************/
160: context.getWorkbenchFrame().getDesktopPane()
161: .addContainerListener(new ContainerListener() {
162: public void componentAdded(ContainerEvent e) {
163: Component child = e.getChild();
164: if (child
165: .getClass()
166: .getName()
167: .equals(
168: "com.vividsolutions.jump.workbench.ui.TaskFrame")) {
169: ((TaskFrame) child)
170: .getLayerNamePanel()
171: .addListener(layerNamePanelListener);
172: ((TaskFrame) child)
173: .getLayerViewPanel()
174: .addListener(layerViewPanelListener);
175: }
176: }
177:
178: public void componentRemoved(ContainerEvent e) {
179: Component child = e.getChild();
180: if (child
181: .getClass()
182: .getName()
183: .equals(
184: "com.vividsolutions.jump.workbench.ui.TaskFrame")) {
185: ((TaskFrame) child).getLayerNamePanel()
186: .removeListener(
187: layerNamePanelListener);
188: ((TaskFrame) child).getLayerViewPanel()
189: .removeListener(
190: layerViewPanelListener);
191: }
192: }
193: });
194: }
195:
196: // //-- method by sstein adapted from Zoombar
197: // private void installListenersOnCurrentPanel(){
198: // System.out.println("try to install listener");
199: // String LAYER_PATH_LISTENERS_INSTALLED_KEY =
200: // Integer.toHexString(hashCode()) + " - LAYER PATH LISTENERS INSTALLED";
201: // if (viewBlackboard().get(LAYER_PATH_LISTENERS_INSTALLED_KEY) != null) {
202: // return;
203: // }
204: //
205: // if(gContext.getLayerViewPanel() == null){
206: // return;
207: // }
208: // //[sstein]
209: // LayerManager lm = gContext.getLayerManager();
210: // lm.addLayerListener(this.myLayerListener);
211: // System.out.println("listener installed");
212: // viewBlackboard().put(LAYER_PATH_LISTENERS_INSTALLED_KEY, new Object());
213: // }
214: //
215: // //-- method by sstein adapted from Zoombar
216: // private Blackboard viewBlackboard() {
217: // return gContext.getLayerViewPanel() != null ? gContext.getLayerViewPanel().getBlackboard() : new Blackboard();
218: // }
219: //
220: public boolean execute(PlugInContext context) throws Exception {
221: try {
222: return true;
223: } catch (Exception e) {
224: context
225: .getWorkbenchFrame()
226: .warnUser(
227: I18N
228: .get("org.openjump.core.ui.plugin.layer.AddSIDLayerPlugIn.Error-See-Output-Window"));
229: context.getWorkbenchFrame().getOutputFrame()
230: .createNewDocument();
231: context.getWorkbenchFrame().getOutputFrame().addText(
232: "ShowFullPathPlugIn Exception:" + e.toString());
233: return false;
234: }
235: }
236:
237: private Envelope envelope(Collection geometries) {
238: Envelope envelope = new Envelope();
239:
240: for (Iterator i = geometries.iterator(); i.hasNext();) {
241: Geometry geometry = (Geometry) i.next();
242: envelope.expandToInclude(geometry.getEnvelopeInternal());
243: }
244:
245: return envelope;
246: }
247:
248: }
|