GNU Classpath (0.95) | |
Frames | No Frames |
1: /* JSeparator.java -- 2: Copyright (C) 2002, 2004 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: package javax.swing; 39: 40: import java.beans.PropertyChangeEvent; 41: 42: import javax.accessibility.Accessible; 43: import javax.accessibility.AccessibleContext; 44: import javax.accessibility.AccessibleRole; 45: import javax.swing.plaf.SeparatorUI; 46: 47: /** 48: * The JSeparator. It is mostly used to divide/space out 49: * components. 50: */ 51: public class JSeparator extends JComponent implements SwingConstants, 52: Accessible 53: { 54: /** 55: * Provides the accessibility features for the <code>JSeparator</code> 56: * component. 57: */ 58: protected class AccessibleJSeparator extends AccessibleJComponent 59: { 60: private static final long serialVersionUID = 916332890553201095L; 61: 62: /** 63: * Creates a new <code>AccessibleJSeparator</code> instance. 64: */ 65: protected AccessibleJSeparator() 66: { 67: // Nothing to do here. 68: } 69: 70: /** 71: * Returns the accessible role for the <code>JSeparator</code> component. 72: * 73: * @return {@link AccessibleRole#SEPARATOR}. 74: */ 75: public AccessibleRole getAccessibleRole() 76: { 77: return AccessibleRole.SEPARATOR; 78: } 79: } 80: 81: private static final long serialVersionUID = 125301223445282357L; 82: 83: /** The orientation of the JSeparator. */ 84: private transient int orientation = HORIZONTAL; 85: 86: /** 87: * Creates a new horizontal <code>JSeparator</code> object. 88: */ 89: public JSeparator() 90: { 91: this(HORIZONTAL); 92: } 93: 94: /** 95: * Creates a new <code>JSeparator</code> object with the given orientation. 96: * 97: * @param orientation the orientation (either {@link #HORIZONTAL} or 98: * {@link #VERTICAL}). 99: * 100: * @throws IllegalArgumentException if <code>orientation</code> is not 101: * one of the specified values. 102: */ 103: public JSeparator(int orientation) 104: { 105: if (orientation != HORIZONTAL && orientation != VERTICAL) 106: throw new IllegalArgumentException(orientation 107: + " is not a valid orientation."); 108: this.orientation = orientation; 109: updateUI(); 110: } 111: 112: /** 113: * Returns the UI delegate being used with the <code>JSeparator</code>. 114: * 115: * @return The JSeparator's UI delegate. 116: */ 117: public SeparatorUI getUI() 118: { 119: return (SeparatorUI) ui; 120: } 121: 122: /** 123: * Sets the separator's UI delegate. 124: * 125: * @param ui the UI delegate. 126: */ 127: public void setUI(SeparatorUI ui) 128: { 129: super.setUI(ui); 130: } 131: 132: /** 133: * Sets this separator's UI delegate to the default (obtained from the 134: * {@link UIManager}) for the current look and feel. 135: */ 136: public void updateUI() 137: { 138: setUI((SeparatorUI) UIManager.getUI(this)); 139: } 140: 141: /** 142: * Returns the suffix (<code>"SeparatorUI"</code> in this case) used to 143: * determine the class name for a UI delegate that can provide the look and 144: * feel for a <code>JSeparator</code>. 145: * 146: * @return <code>"SeparatorUI"</code>. 147: */ 148: public String getUIClassID() 149: { 150: return "SeparatorUI"; 151: } 152: 153: /** 154: * Returns the orientation of the <code>JSeparator</code>. 155: * 156: * @return The orientation (one of {@link #HORIZONTAL} and {@link #VERTICAL}). 157: * 158: * @see #setOrientation(int) 159: */ 160: public int getOrientation() 161: { 162: return orientation; 163: } 164: 165: /** 166: * Sets the orientation for the <code>JSeparator</code> and sends a 167: * {@link PropertyChangeEvent} (with the property name 168: * <code>orientation</code>) to all registered listeners. 169: * 170: * @param orientation the orientation (either {@link #HORIZONTAL} or 171: * {@link #VERTICAL}). 172: * 173: * @throws IllegalArgumentException if <code>orientation</code> is not 174: * one of the specified values. 175: * 176: * @see #getOrientation() 177: */ 178: public void setOrientation(int orientation) 179: { 180: if (orientation != HORIZONTAL && orientation != VERTICAL) 181: throw new IllegalArgumentException(orientation 182: + " is not a valid orientation."); 183: int old = this.orientation; 184: this.orientation = orientation; 185: firePropertyChange("orientation", old, orientation); 186: } 187: 188: /** 189: * Returns an implementation-dependent string describing the attributes of 190: * this <code>JSeparator</code>. 191: * 192: * @return A string describing the attributes of this <code>JSeparator</code> 193: * (never <code>null</code>). 194: */ 195: protected String paramString() 196: { 197: String superParamStr = super.paramString(); 198: if (orientation == HORIZONTAL) 199: return superParamStr + ",orientation=HORIZONTAL"; 200: else 201: return superParamStr + ",orientation=VERTICAL"; 202: } 203: 204: /** 205: * Returns the object that provides accessibility features for this 206: * <code>JSeparator</code> component. 207: * 208: * @return The accessible context (an instance of 209: * {@link AccessibleJSeparator}). 210: */ 211: public AccessibleContext getAccessibleContext() 212: { 213: if (accessibleContext == null) 214: accessibleContext = new AccessibleJSeparator(); 215: 216: return accessibleContext; 217: } 218: }
GNU Classpath (0.95) |