001 /* JSeparator.java -- 002 Copyright (C) 2002, 2004 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 package javax.swing; 039 040 import java.beans.PropertyChangeEvent; 041 042 import javax.accessibility.Accessible; 043 import javax.accessibility.AccessibleContext; 044 import javax.accessibility.AccessibleRole; 045 import javax.swing.plaf.SeparatorUI; 046 047 /** 048 * The JSeparator. It is mostly used to divide/space out 049 * components. 050 */ 051 public 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 }