001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.tree;
022:
023: import java.util.Enumeration;
024:
025: import javax.swing.tree.DefaultMutableTreeNode;
026:
027: /**
028: * A folding tree node.
029: */
030: public class FoldingTreeNode extends DefaultMutableTreeNode {
031:
032: // constructors /////////////////////////////////////////////////////////////
033:
034: // constants ////////////////////////////////////////////////////////////////
035:
036: // classes //////////////////////////////////////////////////////////////////
037:
038: // methods //////////////////////////////////////////////////////////////////
039:
040: /**
041: * Returns the node with <tt>hashCode</tt>.
042: */
043: public FoldingTreeNode findNode(
044: int hashCode ) {
045:
046: Enumeration enum = depthFirstEnumeration();
047: while ( enum.hasMoreElements() ) {
048: FoldingTreeNode node = ( FoldingTreeNode )enum.nextElement();
049: if ( node.hashCode() == hashCode )
050: return node;
051: }
052:
053: return null;
054: }
055:
056: /**
057: * Opened the node with <tt>hashCode</tt>.
058: */
059: public void openNode(int hashCode) {
060:
061: FoldingTreeNode node = findNode(hashCode);
062:
063: if (node != null)
064: node.setOpened(true);
065: }
066:
067: /**
068: * Closes the node with <tt>hashCode</tt>.
069: */
070: public void closeNode(int hashCode) {
071:
072: FoldingTreeNode node = findNode(hashCode);
073:
074: if (node != null)
075: node.setOpened(false);
076: }
077:
078: // properties ///////////////////////////////////////////////////////////////
079:
080: public String getLabel() {
081: return label_;
082: }
083:
084: public void setLabel(String label) {
085: label_ = label;
086: }
087:
088: public String getUrl() {
089: return url_;
090: }
091:
092: public void setUrl(String url) {
093: url_ = url;
094: }
095:
096: public String getIconHint() {
097: return iconHint_;
098: }
099:
100: public void setIconHint(String iconHint) {
101: iconHint_ = iconHint;
102: }
103:
104: public boolean getOpened() {
105: return opened_;
106: }
107:
108: public void setOpened(boolean opened) {
109: opened_ = opened;
110: }
111:
112: // attributes ///////////////////////////////////////////////////////////////
113:
114: private String label_ = "";
115: private String url_ = null;
116: private String iconHint_ = null;
117: private boolean opened_ = false;
118: }
|