001/* JSeparator.java -- 002 Copyright (C) 2002, 2004 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038package javax.swing; 039 040import java.beans.PropertyChangeEvent; 041 042import javax.accessibility.Accessible; 043import javax.accessibility.AccessibleContext; 044import javax.accessibility.AccessibleRole; 045import javax.swing.plaf.SeparatorUI; 046 047/** 048 * The JSeparator. It is mostly used to divide/space out 049 * components. 050 */ 051public class JSeparator extends JComponent implements SwingConstants, 052 Accessible 053{ 054 /** 055 * Provides the accessibility features for the <code>JSeparator</code> 056 * component. 057 */ 058 protected class AccessibleJSeparator extends AccessibleJComponent 059 { 060 private static final long serialVersionUID = 916332890553201095L; 061 062 /** 063 * Creates a new <code>AccessibleJSeparator</code> instance. 064 */ 065 protected AccessibleJSeparator() 066 { 067 // Nothing to do here. 068 } 069 070 /** 071 * Returns the accessible role for the <code>JSeparator</code> component. 072 * 073 * @return {@link AccessibleRole#SEPARATOR}. 074 */ 075 public AccessibleRole getAccessibleRole() 076 { 077 return AccessibleRole.SEPARATOR; 078 } 079 } 080 081 private static final long serialVersionUID = 125301223445282357L; 082 083 /** The orientation of the JSeparator. */ 084 private transient int orientation = HORIZONTAL; 085 086 /** 087 * Creates a new horizontal <code>JSeparator</code> object. 088 */ 089 public JSeparator() 090 { 091 this(HORIZONTAL); 092 } 093 094 /** 095 * Creates a new <code>JSeparator</code> object with the given orientation. 096 * 097 * @param orientation the orientation (either {@link #HORIZONTAL} or 098 * {@link #VERTICAL}). 099 * 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}