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 structure is used to track the use of HTML attributes within a tree item.
023: */
024: public class TreeHtmlAttributeInfo implements java.io.Serializable {
025: public static final int HTML_LOCATION_DIV = 0;
026: public static final int HTML_LOCATION_ICON = 1;
027: public static final int HTML_LOCATION_SELECTION_LINK = 2;
028: public static final int HTML_LOCATION_CNT = 3;
029:
030: private static final int APPLY_TO_DESCENDENTS = 0x01;
031: private static final int ON_ICON = 0x02;
032: private static final int ON_SELECTION_LINK = 0x04;
033: private static final int ON_DIV = 0x08;
034:
035: private String _attribute;
036: private String _value;
037: private int state;
038: private TreeElement _parent;
039:
040: /**
041: * Default constructor for creating a TreeHtmlAttributeInfo.
042: */
043: public TreeHtmlAttributeInfo() {
044: }
045:
046: /**
047: * Construct a new TreeHtmlAttributeInfo with the specified parameters.
048: * @param attribute the name of the attribute.
049: * @param value sets HTML attribute value.
050: */
051: public TreeHtmlAttributeInfo(String attribute, String value) {
052: setAttribute(attribute);
053: setValue(value);
054: }
055:
056: /**
057: * Return the name of the attribute.
058: * @return the attribute name
059: */
060: public String getAttribute() {
061: return _attribute;
062: }
063:
064: /**
065: * Set the name of the attribute.
066: * @param attribute the name of the attribute.
067: */
068: public void setAttribute(String attribute) {
069: _attribute = attribute;
070: }
071:
072: /**
073: * Return the value of the attribute.
074: * @return the String value of the attribute.
075: */
076: public String getValue() {
077: return _value;
078: }
079:
080: /**
081: * Set the HTML attribute value.
082: * @param value the value of the HTML attribute.
083: */
084: public void setValue(String value) {
085: _value = value;
086: }
087:
088: /**
089: * Return the parent node of the HtmlAttributeInfo item.
090: * This is the node the HtmlAttributeInfo item is associated with.
091: * @return the TreeElement parent.
092: */
093: public TreeElement getParent() {
094: return _parent;
095: }
096:
097: /**
098: * Set the parent of the HtmlAttributeInfo item.
099: * This sets the node the HtmlAttributeInfo item will be associated with.
100: * @param parent the TreeElement parent.
101: */
102: public void setParent(TreeElement parent) {
103: _parent = parent;
104: }
105:
106: /**
107: * Gets whether the attribute is applied to descendants of the node.
108: * @return whether the attribute is applied to descendants of the node.
109: */
110: public boolean isApplyToDescendents() {
111: return ((state & APPLY_TO_DESCENDENTS) != 0);
112: }
113:
114: /**
115: * Sets whether the attribute is applied to descendant nodes of the parent node.
116: * @param applyToDescendents
117: */
118: public void setApplyToDescendents(boolean applyToDescendents) {
119: if (applyToDescendents)
120: state = state | APPLY_TO_DESCENDENTS;
121: else
122: state = state & (-1 ^ APPLY_TO_DESCENDENTS);
123:
124: }
125:
126: /**
127: * Gets whether the HTML attribute is on the <div> tag of the node.
128: * @return whether the attribute is on the <div> tag of the node.
129: */
130: public boolean isOnDiv() {
131: return ((state & ON_DIV) != 0);
132: }
133:
134: /**
135: * Sets whether the HTML attribute is on the node item's <div> tag.
136: * @param onDiv whether the attribute is on the <div> tag of the node.
137: */
138: public void setOnDiv(boolean onDiv) {
139: if (onDiv)
140: state = state | ON_DIV;
141: else
142: state = state & (-1 ^ ON_DIV);
143:
144: }
145:
146: /**
147: * Gets whether the HTML attribute is on the <img> tag for the icon of the node.
148: * @return whether the attribute is on the <img> tag of the node.
149: */
150: public boolean isOnIcon() {
151: return ((state & ON_ICON) != 0);
152: }
153:
154: /**
155: * Sets whether the HTML attribute is on the node item's <img> tag for the icon.
156: * @param onIcon whether the attribute is on the <img> tag of the node.
157: */
158: public void setOnIcon(boolean onIcon) {
159: if (onIcon)
160: state = state | ON_ICON;
161: else
162: state = state & (-1 ^ ON_ICON);
163:
164: }
165:
166: /**
167: * Gets whether the HTML attribute is on the selection link of the node.
168: * @return whether the attribute is on the selection link of the node.
169: */
170: public boolean isOnSelectionLink() {
171: return ((state & ON_SELECTION_LINK) != 0);
172: }
173:
174: /**
175: * Sets whether the HTML attribute is on the node item's selection.
176: * @param onSelectionLink whether the attribute is on the selection link of the node.
177: */
178: public void setOnSelectionLink(boolean onSelectionLink) {
179: if (onSelectionLink)
180: state = state | ON_SELECTION_LINK;
181: else
182: state = state & (-1 ^ ON_SELECTION_LINK);
183: }
184: }
|