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.Map;
024:
025: /**
026: * A base class for tree renderers that provides some common properties.
027: */
028: public abstract class TreeRenderer {
029:
030: // constructors /////////////////////////////////////////////////////////////
031:
032: // constants ////////////////////////////////////////////////////////////////
033:
034: /**
035: * The icon to be used for a node whose icon hint cannot be found in the
036: * renderer's icon images.
037: */
038: public static final String DEFAULT_ICON = "com.methodhead.tree.DEFAULT_ICON";
039:
040: /**
041: * The icon to be used as a spacer in cells where no icon should appear; this
042: * icon should be the same size as other icons, but should match the
043: * background or be transparent.
044: */
045: public static final String SPACER_ICON = "com.methodhead.tree.SPACER_ICON";
046:
047: // classes //////////////////////////////////////////////////////////////////
048:
049: // methods //////////////////////////////////////////////////////////////////
050:
051: /**
052: * Returns the HTML for the tree.
053: */
054: public abstract String renderTree(FoldingTreeNode root)
055: throws TreeException;
056:
057: // properties ///////////////////////////////////////////////////////////////
058:
059: /**
060: * Returns URL of the image to display for the handle (the icon clicked to
061: * open or close a node) of a opened node. If no image has been specified,
062: * the renderer should use a reasonable text character in it's place.
063: */
064: public String getOpenedHandleImage() {
065: return openedHandleImage_;
066: }
067:
068: public void setOpenedHandleImage(String openedHandleImage) {
069: openedHandleImage_ = openedHandleImage;
070: }
071:
072: /**
073: * Returns URL of the image to display for the handle (the icon clicked to
074: * open or close a node) of a closed node. If no image has been specified,
075: * the renderer should use a reasonable text character in it's place.
076: */
077: public String getClosedHandleImage() {
078: return closedHandleImage_;
079: }
080:
081: public void setClosedHandleImage(String closedHandleImage) {
082: closedHandleImage_ = closedHandleImage;
083: }
084:
085: /**
086: * Returns a map of image URLs for the icons displayed next to each node. A
087: * node's iconHint is looked up in the map. If no image URL is found, {@link
088: * #DEFAULT_ICON DEFAULT_ICON} is looked up; if that image URL is not found,
089: * a blank space should be rendered. If no map is specified at all, no icons
090: * should be at all.
091: */
092: public Map getIconImages() {
093: return iconImages_;
094: }
095:
096: public void setIconImages(Map iconImages) {
097: iconImages_ = iconImages;
098: }
099:
100: /**
101: * Returns whether the root node is hidden when the tree is rendered.
102: */
103: public boolean isRootHidden() {
104: return rootHidden_;
105: }
106:
107: public void setRootHidden(boolean rootHidden) {
108: rootHidden_ = rootHidden;
109: }
110:
111: // attributes ///////////////////////////////////////////////////////////////
112:
113: private String openedHandleImage_ = null;
114: private String closedHandleImage_ = null;
115: private Map iconImages_ = null;
116: private boolean rootHidden_ = false;
117: }
|