source: trunk/gli/src/org/greenstone/gatherer/gems/GEMSNode.java@ 12306

Last change on this file since 12306 was 12114, checked in by kjdon, 18 years ago

removed Dictionary import cos its not using it

  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gems;
38
39import java.io.*;
40import java.util.*;
41import javax.swing.tree.*;
42import javax.swing.JPopupMenu;
43import java.awt.event.*;
44import org.greenstone.gatherer.Configuration;
45import org.greenstone.gatherer.DebugStream;
46import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
47import org.w3c.dom.*;
48/**
49 * @author John Thompson, Greenstone Digital Library, University of Waikato
50 * @version 2.3
51 * Modified 2/02/05 by Matthew Whyte
52 */
53public class GEMSNode
54 extends DefaultMutableTreeNode{
55 private AttributeTableModel model = null;
56 public int type = 0;
57 private String text = null;
58 static final public int COLLECTION = 0;
59 static final public int ELEMENT = 1;
60 static final public int PROFILER = 2;
61 static final public int ROOT = 3;
62 static final public int SET = 4;
63 //static final public int SUBELEMENT = 5;
64
65 public GEMSNode() {
66 this.type = ROOT;
67 }
68
69 public GEMSNode(int type, Object object, GEMSNode parent) {
70 this.userObject = object;
71 this.parent = parent;
72 this.type = type;
73 this.text = null;
74 }
75
76 public Enumeration children() {
77 if(children == null) {
78 mapChildren();
79 }
80 return children.elements();
81 }
82
83 public boolean getAllowsChildren() {
84 return true;
85 }
86
87 public TreeNode getChildAt(int index) {
88 if(children == null) {
89 mapChildren();
90 }
91 return (TreeNode) children.get(index);
92 }
93 public int getChildCount() {
94 if(children == null) {
95 mapChildren();
96 }
97 return children.size();
98 }
99 public ElementWrapper getElement() {
100 ElementWrapper result = null;
101 if(type == ELEMENT) {
102 result = (ElementWrapper) userObject;
103 }
104 return result;
105 }
106
107 public int getIndex(TreeNode node) {
108 if(children == null) {
109 mapChildren();
110 }
111 return children.indexOf(node);
112 }
113 public AttributeTableModel getModel() {
114 return model;
115 }
116 public TreeNode getParent() {
117 return parent;
118 }
119 public MetadataSet getSet() {
120 MetadataSet result = null;
121 if(type == SET) {
122 result = (MetadataSet) userObject;
123 }
124 return result;
125 }
126 public int getType() {
127 return type;
128 }
129 public boolean isLeaf() {
130 if(children == null) {
131 mapChildren();
132 }
133 return children.size() == 0;
134 }
135 public void setModel(AttributeTableModel model) {
136 this.model = model;
137 }
138
139 public String toString()
140 {
141 if(text == null)
142 {
143 if(userObject != null)
144 {
145 if(userObject instanceof ElementWrapper)
146 {
147 text = ((ElementWrapper)userObject).getName();
148 }
149 else
150 {
151 text = userObject.toString();
152 }
153 }
154 else
155 {
156 text = "error";
157 }
158 }
159 return text;
160 }
161
162 public void mapChildren()
163 {
164 children = new Vector();
165
166 // How we build children depends on the node type
167 if (type == SET)
168 {
169 // Add the elements as children
170 MetadataSet set = (MetadataSet) userObject;
171 ArrayList elements = set.getElements();
172 for (int i = 0; i < elements.size(); i++)
173 {
174 children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element) elements.get(i)), this));
175 }
176 }
177 if (type == ELEMENT) //Add subelements. As elements and subelements are identical, this process continues.
178 {
179 ArrayList subelements = this.getElement().getSubelements();
180 for(int j = 0; j < subelements.size(); j++)
181 {
182 children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element)subelements.get(j)), this));
183 }
184 }
185 }
186
187 class GemsNodeMouseAdapter
188 extends MouseAdapter {
189
190 public void mouseClicked(MouseEvent e) {
191 JPopupMenu setPopup = new JPopupMenu("asdf");
192 if (e.isPopupTrigger()) {
193 setPopup.show(e.getComponent(),
194 e.getX(), e.getY());
195 }
196 }
197
198 public void mouseEntered(MouseEvent e) {
199 }
200
201 public void mouseExited(MouseEvent e) {
202 }
203
204 public void mousePressed(MouseEvent e) {
205 JPopupMenu setPopup = new JPopupMenu("asdf");
206 if (e.isPopupTrigger()) {
207 setPopup.show(e.getComponent(),
208 e.getX(), e.getY());
209 }
210 }
211
212 public void mouseReleased(MouseEvent e) {
213 JPopupMenu setPopup = new JPopupMenu("asdf");
214 if (e.isPopupTrigger()) {
215 setPopup.show(e.getComponent(),
216 e.getX(), e.getY());
217 }
218 }
219 }
220}
Note: See TracBrowser for help on using the repository browser.