001: /*
002: * @(#) Gripper.java
003: * Last modified date: 2/9/2005
004: *
005: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
006: */
007:
008: package com.jidesoft.swing;
009:
010: import com.jidesoft.plaf.GripperUI;
011: import com.jidesoft.plaf.LookAndFeelFactory;
012: import com.jidesoft.plaf.UIDefaultsLookup;
013:
014: import javax.swing.*;
015: import javax.swing.plaf.UIResource;
016: import java.awt.*;
017:
018: /**
019: * Gripper is a component that you can drag. Actually the component itself doesn't allow you to
020: * drag, it is up to the component who uses this Gripper to add mouse motion listener and do the dragging.
021: * The Gripper will paint itself so that user can tell immediately that it is something dragable.
022: */
023: public class Gripper extends JComponent implements SwingConstants,
024: Alignable, DragableHandle, UIResource {
025:
026: /**
027: * @see #getUIClassID
028: * @see #readObject
029: */
030: private static final String uiClassID = "GripperUI";
031:
032: /**
033: * Identifies a change from rollover enabled to disabled or back
034: * to enabled.
035: */
036: public static final String ROLLOVER_ENABLED_CHANGED_PROPERTY = "rolloverEnabled";
037:
038: private boolean _rolloverEnabled = false;
039:
040: private boolean _rollover;
041:
042: public static final String ROLLOVER_PROPERTY = "ROLLOVER";
043: public static final String SELECTED_PROPERTY = "SELECTED";
044:
045: private int _orientation;
046:
047: private boolean _selected;
048:
049: /**
050: * Creates a new horizontal separator.
051: */
052: public Gripper() {
053: this (HORIZONTAL);
054: }
055:
056: /**
057: * Creates a new separator with the specified horizontal or
058: * vertical orientation.
059: *
060: * @param orientation an integer specifying
061: * <code>SwingConstants.HORIZONTAL</code> or
062: * <code>SwingConstants.VERTICAL</code>
063: * @throws IllegalArgumentException if <code>orientation</code>
064: * is neither <code>SwingConstants.HORIZONTAL</code> nor
065: * <code>SwingConstants.VERTICAL</code>
066: */
067: public Gripper(int orientation) {
068: setOrientation(orientation);
069: setFocusable(false);
070: updateUI();
071: }
072:
073: /**
074: * Returns the L&F object that renders this component.
075: *
076: * @return the SeparatorUI object that renders this component
077: */
078: public GripperUI getUI() {
079: return (GripperUI) ui;
080: }
081:
082: /**
083: * Resets the UI property to a value from the current look and feel.
084: *
085: * @see javax.swing.JComponent#updateUI
086: */
087: @Override
088: public void updateUI() {
089: if (UIDefaultsLookup.get(uiClassID) == null) {
090: LookAndFeelFactory.installJideExtension();
091: }
092: setUI(UIManager.getUI(this ));
093: }
094:
095: /**
096: * Returns the name of the L&F class that renders this component.
097: *
098: * @return the string "GripperUI"
099: * @see javax.swing.JComponent#getUIClassID
100: * @see javax.swing.UIDefaults#getUI
101: */
102: @Override
103: public String getUIClassID() {
104: return uiClassID;
105: }
106:
107: /**
108: * return ture if it supports vertical orientation.
109: *
110: * @return ture if it supports vertical orientation
111: */
112: public boolean supportVerticalOrientation() {
113: return true;
114: }
115:
116: /**
117: * return ture if it supports horizontal orientation.
118: *
119: * @return ture if it supports horizontal orientation
120: */
121: public boolean supportHorizontalOrientation() {
122: return true;
123: }
124:
125: /**
126: * Changes the orientation.
127: *
128: * @param orientation the new orientation.
129: */
130: public void setOrientation(int orientation) {
131: int old = _orientation;
132: if (old != orientation) {
133: _orientation = orientation;
134: firePropertyChange(PROPERTY_ORIENTATION, old, orientation);
135: }
136: }
137:
138: /**
139: * Gets the orientation.
140: *
141: * @return orientation
142: */
143: public int getOrientation() {
144: return _orientation;
145: }
146:
147: /**
148: * Gets the cursor set in the component. If the component does
149: * not have a cursor set, the cursor of its parent is returned.
150: * If no cursor is set in the entire hierarchy,
151: * <code>Cursor.DEFAULT_CURSOR</code> is returned.
152: *
153: * @see #setCursor
154: * @since JDK1.1
155: */
156: @Override
157: public Cursor getCursor() {
158: if (isEnabled()) {
159: return Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
160: } else {
161: return super .getCursor();
162: }
163: }
164:
165: /**
166: * Gets the <code>rolloverEnabled</code> property.
167: *
168: * @return the value of the <code>rolloverEnabled</code> property
169: * @see #setRolloverEnabled
170: */
171: public boolean isRolloverEnabled() {
172: return _rolloverEnabled;
173: }
174:
175: /**
176: * Sets the <code>rolloverEnabled</code> property, which
177: * must be <code>true</code> for rollover effects to occur.
178: * The default value for the <code>rolloverEnabled</code>
179: * property is <code>false</code>.
180: * Some look and feels might not implement rollover effects;
181: * they will ignore this property.
182: *
183: * @param b if <code>true</code>, rollover effects should be painted
184: * @see #isRolloverEnabled
185: */
186: public void setRolloverEnabled(boolean b) {
187: boolean oldValue = _rolloverEnabled;
188: if (b != oldValue) {
189: _rolloverEnabled = b;
190: firePropertyChange(ROLLOVER_ENABLED_CHANGED_PROPERTY,
191: oldValue, _rolloverEnabled);
192: repaint();
193: }
194: }
195:
196: public boolean isRollover() {
197: return _rollover;
198: }
199:
200: public void setRollover(boolean rollover) {
201: boolean oldValue = _rollover;
202: if (rollover != oldValue) {
203: _rollover = rollover;
204: firePropertyChange(ROLLOVER_PROPERTY, oldValue, rollover);
205: repaint();
206: }
207: }
208:
209: public boolean isSelected() {
210: return _selected;
211: }
212:
213: public void setSelected(boolean selected) {
214: boolean oldValue = _selected;
215: if (selected != oldValue) {
216: _selected = selected;
217: firePropertyChange(SELECTED_PROPERTY, oldValue, _selected);
218: repaint();
219: }
220: }
221: }
|