01: /* SwingML
02: * Copyright (C) 2002 SwingML Team
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: *
19: * Authors:
20: * Ezequiel Cuellar <ecuellar@crosslogic.com>
21: * Alessandro Dibella <alessandro.dibella@fuurou.org>
22: */
23:
24: package org.swingml.component;
25:
26: import java.awt.datatransfer.DataFlavor;
27: import java.awt.datatransfer.Transferable;
28:
29: import javax.swing.tree.DefaultMutableTreeNode;
30:
31: import org.swingml.model.JTreeModel;
32: import org.swingml.model.NodeModel;
33:
34: public class TreeNodeComponent extends DefaultMutableTreeNode implements
35: Transferable {
36: private boolean isLeaf = false;
37: private String name = null;
38: private DataFlavor[] dataFlavors = null;
39: public static DataFlavor dataFlavor = new DataFlavor(
40: DataFlavor.javaJVMLocalObjectMimeType
41: + "; class=org.swingml.component.TreeNodeComponent",
42: "TreeNodeComponent");
43:
44: public TreeNodeComponent(JTreeModel aModel) {
45: Object theChild = null;
46: TreeNodeComponent theNode = null;
47:
48: this .setName(aModel.getName());
49: this .setUserObject(aModel);
50: for (int i = 0; i < aModel.getChildren().size(); i++) {
51: theChild = aModel.getChildren().get(i);
52: if (theChild instanceof JTreeModel) {
53: theNode = new TreeNodeComponent((JTreeModel) theChild);
54: }
55: if (theChild instanceof NodeModel) {
56: theNode = new TreeNodeComponent((NodeModel) theChild);
57: }
58: super .add(theNode);
59: }
60: }
61:
62: public TreeNodeComponent(NodeModel aModel) {
63: this .isLeaf = true;
64: this .setUserObject(aModel);
65: }
66:
67: public void setName(String aName) {
68: this .name = aName;
69: }
70:
71: public String getName() {
72: return this .name;
73: }
74:
75: public boolean isLeaf() {
76: return this .isLeaf;
77: }
78:
79: public Object getTransferData(DataFlavor aFlavor) {
80: return this ;
81: }
82:
83: public DataFlavor[] getTransferDataFlavors() {
84: this .dataFlavors = new DataFlavor[1];
85: this .dataFlavors[0] = dataFlavor;
86: return dataFlavors;
87: }
88:
89: public boolean isDataFlavorSupported(DataFlavor aFlavor) {
90: boolean theDataFlavorSupported = false;
91: if (aFlavor.equals(this .dataFlavors)) {
92: theDataFlavorSupported = true;
93: }
94: return theDataFlavorSupported;
95: }
96: }
|