001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags.tree;
020:
021: /**
022: * This is a set of tree properties that are used to render the tree markup.
023: */
024: public class InheritableState implements java.io.Serializable {
025: /**
026: * The default directory name for icon images.
027: */
028: public static final String DEFAULT_IMAGES = "resources/beehive/version1/images";
029:
030: /**
031: * The names of tree state images that we need.
032: */
033: private static final String IMAGE_NODE_EXPAND_LAST = "lastNodeExpanded.gif";
034: private static final String IMAGE_NODE_EXPAND = "nodeExpanded.gif";
035: private static final String IMAGE_NODE_COLLAPSE_LAST = "lastNodeCollapsed.gif";
036: private static final String IMAGE_NODE_COLLAPSE = "nodeCollapsed.gif";
037: private static final String IMAGE_LINE_JOIN_LAST = "lastLineJoin.gif";
038: private static final String IMAGE_LINE_JOIN = "lineJoin.gif";
039: private static final String IMAGE_LINE_VERTICAL = "verticalLine.gif";
040: private static final String IMAGE_SPACER = "spacer.gif";
041: private static final String DEFAULT_ICON = "folder.gif";
042:
043: // These are accessed by the Tree tag
044: static final String IMAGE_ROOT_EXPANDED = "rootExpanded.gif";
045: static final String IMAGE_ROOT_COLLAPSED = "rootCollapsed.gif";
046:
047: // The private state of the state
048: private String _lastNodeExpandedImage = null;
049: private String _nodeExpandedImage = null;
050: private String _lastNodeCollapsedImage = null;
051: private String _nodeCollapsedImage = null;
052: private String _lastLineJoinImage = null;
053: private String _lineJoinImage = null;
054: private String _verticalLineImage = null;
055: private String _imageSpacer = null;
056: private String _defaultIcon = null;
057: private String _selectionAction = null;
058: private String _expansionAction = null;
059: private String _selectTarget = null;
060: private String _imageRoot = null;
061: private String _iconRoot = null;
062:
063: // A parent state object which we chain to if the state isn't set on this object.
064: private InheritableState _parent;
065:
066: public void setParent(InheritableState parent) {
067: _parent = parent;
068: }
069:
070: public InheritableState getParent() {
071: return _parent;
072: }
073:
074: public String getLastNodeExpandedImage() {
075: if (_lastNodeExpandedImage != null)
076: return _lastNodeExpandedImage;
077: if (_parent != null)
078: return _parent.getLastNodeExpandedImage();
079: return null;
080: }
081:
082: public void setLastNodeExpandedImage(String lastNodeExpandedImage) {
083: _lastNodeExpandedImage = lastNodeExpandedImage;
084: }
085:
086: public String getNodeExpandedImage() {
087: if (_nodeExpandedImage != null)
088: return _nodeExpandedImage;
089: if (_parent != null)
090: return _parent.getNodeExpandedImage();
091: return null;
092: }
093:
094: public void setNodeExpandedImage(String nodeExpandedImage) {
095: _nodeExpandedImage = nodeExpandedImage;
096: }
097:
098: public String getLastNodeCollapsedImage() {
099: if (_lastNodeCollapsedImage != null)
100: return _lastNodeCollapsedImage;
101: if (_parent != null)
102: return _parent.getLastNodeCollapsedImage();
103: return null;
104: }
105:
106: public void setLastNodeCollapsedImage(String lastNodeCollapsedImage) {
107: _lastNodeCollapsedImage = lastNodeCollapsedImage;
108: }
109:
110: public String getNodeCollapsedImage() {
111: if (_nodeCollapsedImage != null)
112: return _nodeCollapsedImage;
113: if (_parent != null)
114: return _parent.getNodeCollapsedImage();
115: return null;
116: }
117:
118: public void setNodeCollapsedImage(String nodeCollapsedImage) {
119: _nodeCollapsedImage = nodeCollapsedImage;
120: }
121:
122: public String getLastLineJoinImage() {
123: if (_lastLineJoinImage != null)
124: return _lastLineJoinImage;
125: if (_parent != null)
126: return _parent.getLastLineJoinImage();
127: return null;
128: }
129:
130: public void setLastLineJoinImage(String imageLineLast) {
131: _lastLineJoinImage = imageLineLast;
132: }
133:
134: public String getLineJoinImage() {
135: if (_lineJoinImage != null)
136: return _lineJoinImage;
137: if (_parent != null)
138: return _parent.getLineJoinImage();
139: return null;
140: }
141:
142: public void setLineJoinImage(String imageLineMiddle) {
143: _lineJoinImage = imageLineMiddle;
144: }
145:
146: public String getVerticalLineImage() {
147: if (_verticalLineImage != null)
148: return _verticalLineImage;
149: if (_parent != null)
150: return _parent.getVerticalLineImage();
151: return null;
152: }
153:
154: public void setVerticalLineImage(String imageLineVertical) {
155: _verticalLineImage = imageLineVertical;
156: }
157:
158: public String getImageSpacer() {
159: if (_imageSpacer != null)
160: return _imageSpacer;
161: if (_parent != null)
162: return _parent.getImageSpacer();
163: return null;
164: }
165:
166: public void setImageSpacer(String imageSpacer) {
167: _imageSpacer = imageSpacer;
168: }
169:
170: public String getItemIcon() {
171: if (_defaultIcon != null)
172: return _defaultIcon;
173: if (_parent != null)
174: return _parent.getItemIcon();
175: return null;
176: }
177:
178: public void setItemIcon(String itemIcon) {
179: _defaultIcon = itemIcon;
180: }
181:
182: public String getSelectionAction() {
183: if (_selectionAction != null)
184: return _selectionAction;
185: if (_parent != null)
186: return _parent.getSelectionAction();
187: return null;
188: }
189:
190: public void setSelectionAction(String action) {
191: _selectionAction = action;
192: }
193:
194: public String getExpansionAction() {
195: if (_expansionAction != null)
196: return _expansionAction;
197: if (_parent != null)
198: return _parent.getExpansionAction();
199: return null;
200: }
201:
202: public void setExpansionAction(String action) {
203: _expansionAction = action;
204: }
205:
206: public String getSelectionTarget() {
207: if (_selectTarget != null)
208: return _selectTarget;
209: if (_parent != null)
210: return _parent.getSelectionTarget();
211: return null;
212: }
213:
214: public void setSelectionTarget(String target) {
215: _selectTarget = target;
216: }
217:
218: /**
219: * Return the default location of all images. It is used as the location
220: * for the tree structure images.
221: * @return String
222: */
223: public String getImageRoot() {
224: if (_imageRoot != null)
225: return _imageRoot;
226: if (_parent != null)
227: return _parent.getImageRoot();
228: return null;
229: }
230:
231: /**
232: * Sets the default location of all the images.
233: * @param imageRoot
234: */
235: public void setImageRoot(String imageRoot) {
236: _imageRoot = imageRoot;
237: }
238:
239: /**
240: * This will return the location of the icon images. When the location
241: * is explicitly set, this works exactly the same as all other inheritable
242: * properties. When this is not set, it will return the <code>getImageRoot</code>
243: * location.
244: * @return a String value of the icon root.
245: */
246: public String getIconRoot() {
247: String ret = getRealIconRoot();
248: return (ret != null) ? ret : getImageRoot();
249: }
250:
251: /**
252: * This method will walk the inheritable state looking for an icon root.
253: * It returns null if not found.
254: * @return the icon root or null.
255: */
256: private String getRealIconRoot() {
257: if (_iconRoot != null)
258: return _iconRoot;
259: if (_parent != null)
260: return _parent.getRealIconRoot();
261: return null;
262: }
263:
264: /**
265: * This will set the location of the icon images.
266: * @param iconRoot the location of the icon images.
267: */
268: public void setIconRoot(String iconRoot) {
269: _iconRoot = iconRoot;
270: }
271:
272: /**
273: * This method initalizes the state of the properties to their default values used by the
274: * tree tag to create the tree markup.
275: */
276: public void initalizeTreeState() {
277: _lastNodeExpandedImage = IMAGE_NODE_EXPAND_LAST;
278: _nodeExpandedImage = IMAGE_NODE_EXPAND;
279: _lastNodeCollapsedImage = IMAGE_NODE_COLLAPSE_LAST;
280: _nodeCollapsedImage = IMAGE_NODE_COLLAPSE;
281: _lastLineJoinImage = IMAGE_LINE_JOIN_LAST;
282: _lineJoinImage = IMAGE_LINE_JOIN;
283: _verticalLineImage = IMAGE_LINE_VERTICAL;
284: _imageSpacer = IMAGE_SPACER;
285: _defaultIcon = DEFAULT_ICON;
286: _imageRoot = null;
287:
288: _selectionAction = null;
289: _expansionAction = null;
290: }
291: }
|