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 com.vividsolutions.jump.workbench.ui;
033:
034: import java.awt.BorderLayout;
035: import javax.swing.JInternalFrame;
036: import javax.swing.JPanel;
037: import javax.swing.JTabbedPane;
038: import javax.swing.event.InternalFrameAdapter;
039: import javax.swing.event.InternalFrameEvent;
040: import com.vividsolutions.jts.util.Assert;
041: import com.vividsolutions.jump.I18N;
042: import com.vividsolutions.jump.workbench.WorkbenchContext;
043: import com.vividsolutions.jump.workbench.model.LayerManager;
044: import com.vividsolutions.jump.workbench.model.LayerManagerProxy;
045: import com.vividsolutions.jump.workbench.model.Task;
046: import com.vividsolutions.jump.workbench.ui.cursortool.editing.EditingPlugIn;
047: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
048:
049: /**
050: * Provides proxied (non-spatial) views of a Layer.
051: */
052: public class InfoFrame extends JInternalFrame implements
053: LayerManagerProxy, SelectionManagerProxy, LayerNamePanelProxy,
054: TaskFrameProxy, LayerViewPanelProxy {
055: public LayerManager getLayerManager() {
056: return layerManager;
057: }
058:
059: public TaskFrame getTaskFrame() {
060: return attributeTab.getTaskFrame();
061: }
062:
063: private LayerManager layerManager;
064: private BorderLayout borderLayout1 = new BorderLayout();
065: private AttributeTab attributeTab;
066: private InfoModel model = new InfoModel();
067: private GeometryInfoTab geometryInfoTab;
068: private JTabbedPane tabbedPane = new JTabbedPane();
069: private WorkbenchFrame workbenchFrame;
070:
071: public InfoFrame(WorkbenchContext workbenchContext,
072: LayerManagerProxy layerManagerProxy,
073: final TaskFrame taskFrame) {
074: geometryInfoTab = new GeometryInfoTab(model, workbenchContext);
075: //Keep my own copy of LayerManager, because it will be nulled in TaskFrame
076: //when TaskFrame closes (it may in fact already be closed, which is why
077: //a LayerManagerProxy must be passed in too). But I have to
078: //remember to null it when I close. [Jon Aquino]
079: Assert.isTrue(layerManagerProxy.getLayerManager() != null);
080: layerManager = layerManagerProxy.getLayerManager();
081: // I cannot see any reason to add this listener [mmichaud 2007-06-03]
082: // See also WorkbenchFrame
083: /*addInternalFrameListener(new InternalFrameAdapter() {
084: public void internalFrameClosed(InternalFrameEvent e) {
085: layerManager = new LayerManager();
086: }
087: });*/
088: attributeTab = new AttributeTab(model, workbenchContext,
089: taskFrame, this , false);
090: addInternalFrameListener(new InternalFrameAdapter() {
091: public void internalFrameOpened(InternalFrameEvent e) {
092: attributeTab.getToolBar().updateEnabledState();
093: }
094: });
095: workbenchFrame = workbenchContext.getWorkbench().getFrame();
096: this .setResizable(true);
097: this .setClosable(true);
098: this .setMaximizable(true);
099: this .setIconifiable(true);
100: //This size is chosen so that when the user hits the Info tool, the window
101: //fits between the lower edge of the TaskFrame and the lower edge of the
102: //WorkbenchFrame. See the call to #setSize in WorkbenchFrame. [Jon Aquino]
103: //Make sure there's a little space for a custom FeatureTextWriter
104: //[Jon Aquino 12/31/2003]
105: this .setSize(550, 185);
106: try {
107: jbInit();
108: } catch (Exception e) {
109: e.printStackTrace();
110: }
111: tabbedPane.addTab("", IconLoader.icon("Table.gif"),
112: attributeTab, "Table View");
113: tabbedPane.addTab("", IconLoader.icon("Paper.gif"),
114: geometryInfoTab, "HTML View");
115: updateTitle(taskFrame.getTask().getName());
116: taskFrame.getTask().add(new Task.NameListener() {
117: public void taskNameChanged(String name) {
118: updateTitle(taskFrame.getTask().getName());
119: }
120: });
121: addInternalFrameListener(new InternalFrameAdapter() {
122: public void internalFrameClosed(InternalFrameEvent e) {
123: //Assume that there are no other views on the model
124: model.dispose();
125: }
126: });
127: }
128:
129: public JPanel getAttributeTab() {
130: return attributeTab;
131: }
132:
133: public JPanel getGeometryTab() {
134: return geometryInfoTab;
135: }
136:
137: public void setSelectedTab(JPanel tab) {
138: tabbedPane.setSelectedComponent(tab);
139: }
140:
141: public static String title(String taskName) {
142: return I18N.get("ui.InfoFrame.feature-info") + ": " + taskName;
143: }
144:
145: private void updateTitle(String taskName) {
146: setTitle(title(taskName));
147: }
148:
149: public InfoModel getModel() {
150: return model;
151: }
152:
153: private void jbInit() throws Exception {
154: setDefaultCloseOperation(DISPOSE_ON_CLOSE);
155: // With the DefaultInternalFrameCloser of WorkbenchFrame,
156: // I think this code is no more necessary [mmichaud 2007-06-03]
157: /*addInternalFrameListener(new InternalFrameAdapter() {
158: public void internalFrameClosing(InternalFrameEvent e) {
159: //Regardless of the defaultCloseOperation, this InfoFrame should be
160: //removed from the WorkbenchFrame when the user hits X so it won't
161: //appear on the Window list. [Jon Aquino]
162: try {
163: workbenchFrame.removeInternalFrame(InfoFrame.this);
164: } catch (Exception x) {
165: workbenchFrame.handleThrowable(x);
166: }
167: }
168: });*/
169: this .setTitle(I18N.get("ui.InfoFrame.feature-info"));
170: this .getContentPane().setLayout(borderLayout1);
171: tabbedPane.setTabPlacement(JTabbedPane.LEFT);
172: this .getContentPane().add(tabbedPane, BorderLayout.CENTER);
173: }
174:
175: public void surface() {
176: JInternalFrame activeFrame = workbenchFrame
177: .getActiveInternalFrame();
178: if (!workbenchFrame.hasInternalFrame(this )) {
179: workbenchFrame.addInternalFrame(this , false, true);
180: }
181: if (activeFrame != null) {
182: workbenchFrame.activateFrame(activeFrame);
183: }
184: moveToFront();
185: //Move this frame to the front, but don't activate it if the TaskFrame is
186: //active. Otherwise the user would need to re-activate the TaskFrame before
187: //making another Info gesture. [Jon Aquino]
188: }
189:
190: public SelectionManager getSelectionManager() {
191: return attributeTab.getPanel().getSelectionManager();
192: }
193:
194: public LayerNamePanel getLayerNamePanel() {
195: return attributeTab;
196: }
197:
198: public LayerViewPanel getLayerViewPanel() {
199: return getTaskFrame().getLayerViewPanel();
200: }
201: }
|