001: /**
002: * Caption: Zaval Java Resource Editor
003: * $Revision: 0.37 $
004: * $Date: 2002/03/28 9:24:42 $
005: *
006: * @author: Victor Krapivin
007: * @version: 1.3
008: *
009: * Zaval JRC Editor is a visual editor which allows you to manipulate
010: * localization strings for all Java based software with appropriate
011: * support embedded.
012: *
013: * For more info on this product read Zaval Java Resource Editor User's Guide
014: * (It comes within this package).
015: * The latest product version is always available from the product's homepage:
016: * http://www.zaval.org/products/jrc-editor/
017: * and from the SourceForge:
018: * http://sourceforge.net/projects/zaval0002/
019: *
020: * Contacts:
021: * Support : support@zaval.org
022: * Change Requests : change-request@zaval.org
023: * Feedback : feedback@zaval.org
024: * Other : info@zaval.org
025: *
026: * Copyright (C) 2001-2002 Zaval Creative Engineering Group (http://www.zaval.org)
027: *
028: * This program is free software; you can redistribute it and/or
029: * modify it under the terms of the GNU General Public License
030: * (version 2) as published by the Free Software Foundation.
031: *
032: * This program is distributed in the hope that it will be useful,
033: * but WITHOUT ANY WARRANTY; without even the implied warranty of
034: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
035: * GNU General Public License for more details.
036: *
037: * You should have received a copy of the GNU General Public License
038: * along with this program; if not, write to the Free Software
039: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
040: *
041: */package org.zaval.awt.peer;
042:
043: import org.zaval.awt.*;
044:
045: import java.awt.*;
046: import java.util.*;
047:
048: public class TreeNode {
049: public ImageResolver imgres = null;
050:
051: public TreeNode sibling;
052: public TreeNode child;
053: public TreeNode parent;
054: public String text;
055: public String nameCollImage = null;
056: public String nameExpImage = null;
057: public Image collapsedImage = null;
058: public Image expandedImage = null;
059: public int depth = -1;
060: public boolean isExpanded = false;
061: public int numberOfChildren;
062: public int contextMenu = -1;
063: public Hashtable property = null;
064: public boolean hidden = false;
065: public String caption;
066: public Image indicator;
067:
068: //constructors
069:
070: public void setResolver(ImageResolver imgres) {
071: this .imgres = imgres;
072: }
073:
074: public TreeNode(String text) {
075: this (text, null, null);
076: }
077:
078: public TreeNode(String text, String nameCollImage,
079: String nameExpImage) {
080: property = new Hashtable();
081: this .text = text;
082: this .sibling = null;
083: this .child = null;
084: this .nameCollImage = nameCollImage;
085: this .nameExpImage = nameExpImage;
086:
087: if (nameCollImage != null && imgres != null)
088: this .collapsedImage = imgres.getImage(nameCollImage);
089:
090: if (nameExpImage != null && imgres != null)
091: this .expandedImage = imgres.getImage(nameCollImage);
092:
093: numberOfChildren = 0;
094: caption = null;
095: }
096:
097: public void setDepth(int depth) {
098: this .depth = depth;
099: }
100:
101: public int getDepth() {
102: return depth;
103: }
104:
105: public boolean isExpanded() {
106: return !hidden && isExpanded;
107: }
108:
109: public boolean isExpandable() {
110: return !hidden && (child != null);
111: }
112:
113: public void expand() {
114: if (isExpandable())
115: isExpanded = true;
116: }
117:
118: public void collapse() {
119: isExpanded = false;
120: }
121:
122: public void toggle() {
123: if (isExpanded) {
124: collapse();
125: } else if (isExpandable()) {
126: expand();
127: }
128: }
129:
130: public Image getImage() {
131: return ((isExpanded && (expandedImage != null)) ? expandedImage
132: : collapsedImage);
133: }
134:
135: public Image getExpandedImage() {
136: loadImages();
137: return (expandedImage != null) ? expandedImage : collapsedImage;
138: }
139:
140: public Image getCollapsedImage() {
141: loadImages();
142: return collapsedImage;
143: }
144:
145: public String getNameImage() {
146: if (getImage() != null)
147: return ((isExpanded && (expandedImage != null)) ? nameExpImage
148: : nameCollImage);
149: return null;
150: }
151:
152: private void loadImages() {
153: if (imgres == null)
154: return;
155: if (nameCollImage != null && collapsedImage == null)
156: collapsedImage = imgres.getImage(nameCollImage);
157: if (nameExpImage != null && expandedImage == null)
158: expandedImage = imgres.getImage(nameExpImage);
159: }
160:
161: public void setExpandedImage(String image) {
162: this .nameCollImage = image;
163: if (image != null && imgres != null)
164: this .collapsedImage = imgres.getImage(nameCollImage);
165: }
166:
167: public void setCollapsedImage(String image) {
168: this .nameExpImage = image;
169: if (image != null && imgres != null)
170: this .expandedImage = imgres.getImage(nameExpImage);
171: }
172:
173: public String getText() {
174: return text;
175: }
176:
177: public void setText(String s) {
178: text = s;
179: }
180:
181: public void setContextMenu(int index) {
182: contextMenu = index;
183: }
184:
185: public int getContextMenu() {
186: return contextMenu;
187: }
188:
189: public Object getProperty(String name) {
190: return property.get(name);
191: }
192:
193: public String getStringProperty(String name) {
194: return (String) getProperty(name);
195: }
196:
197: public int getIntProperty(String name) {
198: return Integer.parseInt((String) getProperty(name));
199: }
200:
201: public void setProperty(String name, Object value) {
202: property.put(name, value);
203: }
204:
205: public void setStringProperty(String name, String value) {
206: setProperty(name, value);
207: }
208:
209: public void setIntProperty(String name, int value) {
210: setProperty(name, "" + value);
211: }
212:
213: public int getNumberOfChildren() {
214: return numberOfChildren;
215: }
216:
217: public void setHide(boolean b) {
218: hidden = b;
219: }
220:
221: public boolean getHide() {
222: return hidden;
223: }
224:
225: public String getCaption() {
226: return caption == null ? text : caption;
227: }
228:
229: public void setCaption(String c) {
230: caption = c;
231: }
232:
233: public void setCollapsedImage(Image image) {
234: this .collapsedImage = image;
235: }
236:
237: public void setExpandedImage(Image image) {
238: this .expandedImage = image;
239: }
240:
241: public void setIndicator(String name) {
242: if (name == null || imgres == null)
243: indicator = null;
244: else
245: indicator = imgres.getImage(name);
246: }
247:
248: public Image getIndicator() {
249: return indicator;
250: }
251: }
|