001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI for
003: * 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 modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
015: * more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
019: * Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions Suite #1A 2328 Government Street Victoria BC V8T 5G5 Canada
024: *
025: * (250)385-6040 www.vividsolutions.com
026: */
027:
028: package com.vividsolutions.jump.workbench.ui;
029:
030: import java.awt.BorderLayout;
031: import java.awt.Dimension;
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034: import java.util.Iterator;
035:
036: import javax.swing.ButtonGroup;
037: import javax.swing.JComponent;
038: import javax.swing.JPanel;
039: import javax.swing.JToggleButton;
040: import javax.swing.JToolBar;
041:
042: import com.vividsolutions.jump.I18N;
043: import com.vividsolutions.jump.feature.Feature;
044: import com.vividsolutions.jump.workbench.WorkbenchContext;
045: import com.vividsolutions.jump.workbench.plugin.EnableCheck;
046: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
047: import com.vividsolutions.jump.workbench.ui.images.IconLoader;
048:
049: public class GeometryInfoTab extends JPanel {
050: private BorderLayout borderLayout2 = new BorderLayout();
051:
052: private JToggleButton showAttributesButton = new JToggleButton();
053:
054: private JToggleButton showGeometriesButton = new JToggleButton();
055:
056: private EnableableToolBar toolBar = new EnableableToolBar();
057:
058: private GeometryInfoPanel geometryInfoPanel;
059:
060: private EnableCheck geometriesShownEnableCheck = new EnableCheck() {
061: public String check(JComponent component) {
062: return (!showGeometriesButton.isSelected()) ? "X" : null;
063: }
064: };
065:
066: public GeometryInfoTab(InfoModel model, WorkbenchContext context) {
067: geometryInfoPanel = new GeometryInfoPanel(model);
068:
069: try {
070: jbInit();
071: } catch (Exception ex) {
072: ex.printStackTrace();
073: }
074:
075: toolBar.add(showGeometriesButton, I18N
076: .get("ui.GeometryInfoTab.geometries"), IconLoader
077: .icon("Geometry.gif"), new ActionListener() {
078: public void actionPerformed(ActionEvent e) {
079: updateText();
080: }
081: }, new MultiEnableCheck());
082: toolBar.addSpacer();
083: toolBar.add(showAttributesButton, I18N
084: .get("ui.GeometryInfoTab.attributes"), IconLoader
085: .icon("Attribute.gif"), new ActionListener() {
086: public void actionPerformed(ActionEvent e) {
087: updateText();
088: }
089: }, new MultiEnableCheck());
090: Dimension buttonSize = new Dimension(
091: (int) (showGeometriesButton.getPreferredSize().width * 1.5),
092: showGeometriesButton.getPreferredSize().height);
093: toolBar.addSpacer();
094: ButtonGroup buttonGroup = new ButtonGroup();
095: for (Iterator i = context.getFeatureTextWriterRegistry()
096: .iterator(); i.hasNext();) {
097: final AbstractFeatureTextWriter writer = (AbstractFeatureTextWriter) i
098: .next();
099: JToggleButton button = new JToggleButton(writer
100: .getShortDescription());
101: button.setFont(button.getFont().deriveFont(10f));
102: buttonGroup.add(button);
103: toolBar.add(button, writer.getDescription(), null,
104: new ActionListener() {
105: public void actionPerformed(ActionEvent e) {
106: if (showGeometriesButton.isSelected()) {
107: geometryWriter = new FeatureInfoWriterAdapter(
108: writer);
109: }
110: updateText();
111: }
112: }, geometriesShownEnableCheck);
113: button.setPreferredSize(buttonSize);
114: button.setMinimumSize(buttonSize);
115: button.setMaximumSize(buttonSize);
116: button.setSize(buttonSize);
117: }
118: showGeometriesButton.doClick();
119: ((JToggleButton) buttonGroup.getElements().nextElement())
120: .doClick();
121: }
122:
123: private void updateText() {
124: if (showAttributesButton.isSelected()) {
125: geometryInfoPanel
126: .setAttributeWriter(FeatureInfoWriter.ATTRIBUTE_WRITER);
127: } else {
128: geometryInfoPanel
129: .setAttributeWriter(FeatureInfoWriter.EMPTY_WRITER);
130: }
131:
132: if (showGeometriesButton.isSelected()) {
133: geometryInfoPanel.setGeometryWriter(geometryWriter);
134: } else {
135: geometryInfoPanel
136: .setGeometryWriter(FeatureInfoWriter.EMPTY_WRITER);
137: }
138:
139: geometryInfoPanel.updateText();
140: }
141:
142: void jbInit() throws Exception {
143: setLayout(borderLayout2);
144: toolBar.setOrientation(JToolBar.VERTICAL);
145: add(geometryInfoPanel, BorderLayout.CENTER);
146: add(toolBar, BorderLayout.WEST);
147: }
148:
149: private FeatureInfoWriter.Writer geometryWriter;
150:
151: private class FeatureInfoWriterAdapter implements
152: FeatureInfoWriter.Writer {
153: private AbstractFeatureTextWriter featureTextWriter;
154:
155: public FeatureInfoWriterAdapter(
156: AbstractFeatureTextWriter featureTextWriter) {
157: this .featureTextWriter = featureTextWriter;
158: }
159:
160: public String toHTML(Feature feature) {
161: return featureTextWriter.isWrapping() ? "<BR><CODE>"
162: + GUIUtil.escapeHTML(featureTextWriter
163: .write(feature), false, false) + "</CODE>"
164: : "<pre>"
165: + GUIUtil.escapeHTML(featureTextWriter
166: .write(feature), false, false)
167: + "</pre>";
168: }
169: }
170: }
|