01: // WebOnSwing - Web Application Framework
02: //Copyright (C) 2003 Fernando Damian Petrola
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.1 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 Free Software
16: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17:
18: package net.ar.webonswing.swing.components;
19:
20: import java.util.*;
21:
22: import javax.swing.tree.*;
23:
24: public class CheckNode extends DefaultMutableTreeNode {
25: public final static int SINGLE_SELECTION = 0;
26: public final static int DIG_IN_SELECTION = 4;
27: protected int selectionMode;
28: protected boolean isSelected;
29:
30: public CheckNode() {
31: this (null);
32: }
33:
34: public CheckNode(Object anUserObject) {
35: this (anUserObject, true, false);
36: }
37:
38: public CheckNode(Object anUserObject, boolean anAllowsChildren,
39: boolean selected) {
40: super (anUserObject, anAllowsChildren);
41: this .isSelected = selected;
42: setSelectionMode(SINGLE_SELECTION);
43: }
44:
45: public void setSelectionMode(int mode) {
46: selectionMode = mode;
47: }
48:
49: public int getSelectionMode() {
50: return selectionMode;
51: }
52:
53: public void setSelected(boolean selected)
54: {
55: this .isSelected= selected;
56:
57: if ((selectionMode == DIG_IN_SELECTION) && (children != null))
58: {
59: Enumeration enum= children.elements();
60: while (enum.hasMoreElements())
61: {
62: Object theNode= enum.nextElement();
63:
64: if (theNode instanceof CheckNode)
65: {
66: CheckNode theCheckNode= (CheckNode) theNode;
67: theCheckNode.setSelected(selected);
68: }
69: }
70: }
71: }
72:
73: public boolean isSelected() {
74: return isSelected;
75: }
76: }
|