001: /*
002: * This file is part of the Tucana Echo2 Library.
003: * Copyright (C) 2006.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package tucana.echo2.app.widgetdash;
031:
032: import nextapp.echo2.app.Component;
033:
034: /**
035: * This is a wrapping {@link Component} that makes its child a widget "Grab Point".
036: * Essentially, any Component wrapped by this can be used to drag a widget around
037: * the screen. For instance, a title bar in a WidgetContainer might be wrapped
038: * in a WidgetGrabPoint.
039: * @author Jeremy Volkman
040: *
041: */
042: public class WidgetGrabPoint extends Component {
043:
044: /**
045: *
046: */
047: private static final long serialVersionUID = 1L;
048:
049: /**
050: * The default mouse cursor
051: */
052: public static final String DEFAULT_CURSOR = "move";
053:
054: /**
055: * Mouse cursor property key
056: */
057: public static final String PROPERTY_CURSOR = "cursor";
058:
059: private WidgetContainer widgetContainer;
060:
061: /**
062: * Creates a WidgetGrabPoint making the given
063: * Component grabbable
064: * @param grabbable The Component.
065: * @param widgetContainer The WidgetContainer that will be dragged by this point
066: */
067: public WidgetGrabPoint(Component grabbable,
068: WidgetContainer widgetContainer) {
069: this .add(grabbable);
070: this .widgetContainer = widgetContainer;
071: setCursor(DEFAULT_CURSOR);
072: }
073:
074: /**
075: * Checks that no more than one Component is a
076: * child of this DragSource.
077: */
078: @Override
079: public void add(Component c, int n) {
080: if (getComponentCount() == 1) {
081: throw new IllegalStateException(
082: "Cannot add more than one Component directly to a GrabPoint.");
083: }
084: super .add(c, n);
085: }
086:
087: /**
088: * Returns the Component that is to be dragged.
089: * @return The draggable Component.
090: */
091: public Component getGrabbable() {
092: return getComponents().length > 0 ? getComponents()[0] : null;
093: }
094:
095: /**
096: * Return the container that this grab point should move.
097: * @return The WidgetContainer to be moved
098: */
099: public WidgetContainer getWidgetContainer() {
100: return widgetContainer;
101: }
102:
103: /**
104: * Set the mouse cursor icon to be displayed over this GrabPoint.
105: * @param cursor The new icon string
106: */
107: public void setCursor(String cursor) {
108: setProperty(PROPERTY_CURSOR, cursor);
109: }
110:
111: /**
112: * Get the mouse cursor to be displayed over this GrabPoint.
113: * @return The mouse cursor string
114: */
115: public String getCursor() {
116: return (String) getProperty(PROPERTY_CURSOR);
117: }
118: }
|