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.addremove;
034:
035: import java.awt.BorderLayout;
036: import java.awt.Color;
037: import java.awt.event.MouseListener;
038: import java.util.ArrayList;
039: import java.util.Collection;
040: import java.util.List;
041:
042: import javax.swing.JPanel;
043: import javax.swing.JTree;
044: import javax.swing.border.Border;
045: import javax.swing.border.EtchedBorder;
046: import javax.swing.event.TreeSelectionEvent;
047: import javax.swing.event.TreeSelectionListener;
048: import javax.swing.tree.TreePath;
049:
050: import com.vividsolutions.jump.workbench.ui.InputChangedFirer;
051: import com.vividsolutions.jump.workbench.ui.InputChangedListener;
052:
053: public class TreeAddRemoveList extends JPanel implements AddRemoveList {
054: private BorderLayout borderLayout1 = new BorderLayout();
055: private TreeAddRemoveListModel model = new TreeAddRemoveListModel(
056: new JTree().getModel());
057: private InputChangedFirer inputChangedFirer = new InputChangedFirer();
058: private JTree tree = new JTree();
059: private Border border1;
060:
061: public void add(MouseListener listener) {
062: tree.addMouseListener(listener);
063: }
064:
065: public TreeAddRemoveList() {
066: tree.getSelectionModel().addTreeSelectionListener(
067: new TreeSelectionListener() {
068: public void valueChanged(TreeSelectionEvent e) {
069: inputChangedFirer.fire();
070: }
071: });
072:
073: try {
074: jbInit();
075: } catch (Exception ex) {
076: ex.printStackTrace();
077: }
078: }
079:
080: public void setSelectedItems(Collection items) {
081: throw new UnsupportedOperationException();
082: }
083:
084: public void setModel(TreeAddRemoveListModel model) {
085: this .model = model;
086: tree.setModel(model.getTreeModel());
087: inputChangedFirer.fire();
088: }
089:
090: public JTree getTree() {
091: return tree;
092: }
093:
094: public void add(InputChangedListener listener) {
095: inputChangedFirer.add(listener);
096: }
097:
098: void jbInit() throws Exception {
099: border1 = new EtchedBorder(EtchedBorder.RAISED, new Color(0, 0,
100: 51), new Color(0, 0, 25));
101: this .setLayout(borderLayout1);
102: this .add(tree, BorderLayout.CENTER);
103: }
104:
105: public AddRemoveListModel getModel() {
106: return model;
107: }
108:
109: public List getSelectedItems() {
110: ArrayList selectedNodes = new ArrayList();
111: TreePath[] selectionPaths = tree.getSelectionPaths();
112:
113: if (selectionPaths == null) {
114: return selectedNodes;
115: }
116:
117: for (int i = 0; i < selectionPaths.length; i++) {
118: selectedNodes.add(selectionPaths[i].getLastPathComponent());
119: }
120:
121: return selectedNodes;
122: }
123: }
|