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;
034:
035: import java.awt.BorderLayout;
036: import java.util.HashMap;
037: import java.util.Iterator;
038: import java.util.Map;
039:
040: import javax.swing.JEditorPane;
041: import javax.swing.JPanel;
042: import javax.swing.JScrollPane;
043: import javax.swing.event.TableModelEvent;
044: import javax.swing.event.TableModelListener;
045:
046: import com.vividsolutions.jump.workbench.model.Layer;
047:
048: public class GeometryInfoPanel extends JPanel implements
049: InfoModelListener {
050: //Need the scrollpane on the panel because the scrollpane has to go around
051: //the editorpane itself -- otherwise the editorpane won't wrap. [Jon Aquino]
052: private BorderLayout borderLayout1 = new BorderLayout();
053: private JEditorPane editorPane = new JEditorPane();
054: private FeatureInfoWriter writer = new FeatureInfoWriter();
055: private InfoModel model;
056: private JScrollPane scrollPane = new JScrollPane();
057: private FeatureInfoWriter.Writer geometryWriter;
058: private FeatureInfoWriter.Writer attributeWriter;
059:
060: public GeometryInfoPanel(InfoModel model) {
061: setModel(model);
062:
063: try {
064: jbInit();
065: } catch (Exception ex) {
066: ex.printStackTrace();
067: }
068: }
069:
070: void jbInit() throws Exception {
071: editorPane.setEditable(false);
072: editorPane.setText("jEditorPane1");
073: editorPane.setContentType("text/html");
074: this .setLayout(borderLayout1);
075: this .add(scrollPane, BorderLayout.CENTER);
076: scrollPane.getViewport().add(editorPane, null);
077: }
078:
079: public void setModel(InfoModel model) {
080: this .model = model;
081: model.addListener(this );
082: }
083:
084: public void layerAdded(LayerTableModel layerTableModel) {
085: updateText();
086: layerTableModel.addTableModelListener(new TableModelListener() {
087: public void tableChanged(TableModelEvent e) {
088: updateText();
089: }
090: });
091: }
092:
093: public void layerRemoved(LayerTableModel layerTableModel) {
094: updateText();
095: }
096:
097: public void updateText() {
098: editorPane.setText(writer.writeGeom(layerToFeaturesMap(),
099: geometryWriter, attributeWriter));
100: editorPane.setCaretPosition(0);
101: }
102:
103: private Map layerToFeaturesMap() {
104: HashMap layerToFeaturesMap = new HashMap();
105:
106: for (Iterator i = model.getLayers().iterator(); i.hasNext();) {
107: Layer layer = (Layer) i.next();
108: layerToFeaturesMap.put(layer, model.getTableModel(layer)
109: .getFeatures());
110: }
111:
112: return layerToFeaturesMap;
113: }
114:
115: public void setGeometryWriter(
116: FeatureInfoWriter.Writer geometryWriter) {
117: this .geometryWriter = geometryWriter;
118: }
119:
120: public void setAttributeWriter(
121: FeatureInfoWriter.Writer attributeWriter) {
122: this.attributeWriter = attributeWriter;
123: }
124: }
|