001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.api.visual.model;
042:
043: /**
044: * This class holds a state of a object or a widget. The object state is a set of those following flags:
045: * selected, highlighted (also called secondary selection), object-hovered, widget-hovered, widget-aimed.
046: * <p>
047: * Initial (normal) value of object state is used for Widget.state and in ObjectScene class.
048: *
049: * @author David Kaspar
050: */
051: // TODO - rename to VisualState?
052: public class ObjectState {
053:
054: private static final ObjectState NORMAL = new ObjectState(false,
055: false, false, false, false, false, false);
056:
057: private boolean objectSelected;
058: private boolean objectHighlighted;
059: private boolean objectHovered;
060: private boolean objectFocused;
061:
062: private boolean widgetHovered;
063: private boolean widgetFocused;
064: private boolean widgetAimed;
065:
066: private ObjectState(boolean objectSelected,
067: boolean objectHighlighted, boolean objectHovered,
068: boolean objectFocused, boolean widgetHovered,
069: boolean widgetFocused, boolean widgetAimed) {
070: this .objectSelected = objectSelected;
071: this .objectHighlighted = objectHighlighted;
072: this .objectHovered = objectHovered;
073: this .objectFocused = objectFocused;
074: this .widgetHovered = widgetHovered;
075: this .widgetFocused = widgetFocused;
076: this .widgetAimed = widgetAimed;
077: }
078:
079: /**
080: * Returns a value of selected-flag.
081: * @return true, if selected
082: */
083: public boolean isSelected() {
084: return objectSelected;
085: }
086:
087: /**
088: * Creates a state derived from this one where the selected flag will be set according to the parameter.
089: * @param selected the new selected-flag of the new state.
090: * @return the new state
091: */
092: public ObjectState deriveSelected(boolean selected) {
093: return new ObjectState(selected, objectHighlighted,
094: objectHovered, objectFocused, widgetHovered,
095: widgetFocused, widgetAimed);
096: }
097:
098: /**
099: * Returns a value of highlighted-flag.
100: * @return true, if highlighted
101: */
102: public boolean isHighlighted() {
103: return objectHighlighted;
104: }
105:
106: /**
107: * Creates a state derived from this one where the highlighted flag will be set according to the parameter.
108: * @param highlighted the new highlighted-flag of the new state.
109: * @return the new state
110: */
111: public ObjectState deriveHighlighted(boolean highlighted) {
112: return new ObjectState(objectSelected, highlighted,
113: objectHovered, objectFocused, widgetHovered,
114: widgetFocused, widgetAimed);
115: }
116:
117: /**
118: * Returns a value of hovered-flag.
119: * @return true, if object-hovered or widget-hovered flag is set
120: */
121: public boolean isHovered() {
122: return objectHovered || widgetHovered;
123: }
124:
125: /**
126: * Returns a value of object-hovered-flag.
127: * @return true, if object-hovered
128: */
129: public boolean isObjectHovered() {
130: return objectHovered;
131: }
132:
133: /**
134: * Creates a state derived from this one where the object-hovered flag will be set according to the parameter.
135: * @param hovered the new object-hovered-flag of the new state.
136: * @return the new state
137: */
138: public ObjectState deriveObjectHovered(boolean hovered) {
139: return new ObjectState(objectSelected, objectHighlighted,
140: hovered, objectFocused, widgetHovered, widgetFocused,
141: widgetAimed);
142: }
143:
144: /**
145: * Returns a value of widget-hovered-flag.
146: * @return true, if widget-hovered
147: */
148: public boolean isWidgetHovered() {
149: return widgetHovered;
150: }
151:
152: /**
153: * Creates a state derived from this one where the widget-hovered flag will be set according to the parameter.
154: * @param hovered the new widget-hovered-flag of the new state.
155: * @return the new state
156: */
157: public ObjectState deriveWidgetHovered(boolean hovered) {
158: return new ObjectState(objectSelected, objectHighlighted,
159: objectHovered, objectFocused, hovered, widgetFocused,
160: widgetAimed);
161: }
162:
163: /**
164: * Returns a value of focused-flag.
165: * @return true, if object-focused or widget-focused flag is set
166: */
167: public boolean isFocused() {
168: return objectFocused || widgetFocused;
169: }
170:
171: /**
172: * Returns a value of object-focused flag.
173: * @return true, if object-focused
174: */
175: public boolean isObjectFocused() {
176: return objectFocused;
177: }
178:
179: /**
180: * Creates a state derived from this one where the object-focused flag will be set according to the parameter.
181: * @param focused the new object-focused-flag of the new state.
182: * @return the new state
183: */
184: public ObjectState deriveObjectFocused(boolean focused) {
185: return new ObjectState(objectSelected, objectHighlighted,
186: objectHovered, focused, widgetHovered, widgetFocused,
187: widgetAimed);
188: }
189:
190: /**
191: * Returns a value of widget-focused-flag.
192: * @return true, if widget-focused
193: */
194: public boolean isWidgetFocused() {
195: return widgetFocused;
196: }
197:
198: /**
199: * Creates a state derived from this one where the widget-focused flag will be set according to the parameter.
200: * @param focused the new widget-focused-flag of the new state.
201: * @return the new state
202: */
203: public ObjectState deriveWidgetFocused(boolean focused) {
204: return new ObjectState(objectSelected, objectHighlighted,
205: objectHovered, objectFocused, widgetHovered, focused,
206: widgetAimed);
207: }
208:
209: /**
210: * Returns a value of widget-aimed-flag.
211: * @return true, if widget-aimed
212: */
213: public boolean isWidgetAimed() {
214: return widgetAimed;
215: }
216:
217: /**
218: * Creates a state derived from this one where the aimed flag will be set according to the parameter.
219: * @param aimed the new aimed-flag of the new state.
220: * @return the new state
221: */
222: public ObjectState deriveWidgetAimed(boolean aimed) {
223: return new ObjectState(objectSelected, objectHighlighted,
224: objectHovered, objectFocused, widgetHovered,
225: widgetFocused, aimed);
226: }
227:
228: /**
229: * Creates a normal (initial/default) state. No flags is set in the state.
230: * @return the normal state
231: */
232: public static ObjectState createNormal() {
233: return NORMAL;
234: }
235:
236: }
|