Merge from mainline.
[official-gcc.git] / libjava / classpath / javax / swing / JSeparator.java
blobc87783b73eb1cc8d2ff434ef20eb04c772710dba
1 /* JSeparator.java --
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
38 package javax.swing;
40 import java.beans.PropertyChangeEvent;
42 import javax.accessibility.Accessible;
43 import javax.accessibility.AccessibleContext;
44 import javax.accessibility.AccessibleRole;
45 import javax.swing.plaf.SeparatorUI;
47 /**
48 * The JSeparator. It is mostly used to divide/space out
49 * components.
51 public class JSeparator extends JComponent implements SwingConstants,
52 Accessible
54 /**
55 * Provides the accessibility features for the <code>JSeparator</code>
56 * component.
58 protected class AccessibleJSeparator extends AccessibleJComponent
60 private static final long serialVersionUID = 916332890553201095L;
62 /**
63 * Creates a new <code>AccessibleJSeparator</code> instance.
65 protected AccessibleJSeparator()
67 // Nothing to do here.
70 /**
71 * Returns the accessible role for the <code>JSeparator</code> component.
73 * @return {@link AccessibleRole#SEPARATOR}.
75 public AccessibleRole getAccessibleRole()
77 return AccessibleRole.SEPARATOR;
81 private static final long serialVersionUID = 125301223445282357L;
83 /** The orientation of the JSeparator. */
84 private transient int orientation = HORIZONTAL;
86 /**
87 * Creates a new horizontal <code>JSeparator</code> object.
89 public JSeparator()
91 this(HORIZONTAL);
94 /**
95 * Creates a new <code>JSeparator</code> object with the given orientation.
97 * @param orientation the orientation (either {@link #HORIZONTAL} or
98 * {@link #VERTICAL}).
100 * @throws IllegalArgumentException if <code>orientation</code> is not
101 * one of the specified values.
103 public JSeparator(int orientation)
105 if (orientation != HORIZONTAL && orientation != VERTICAL)
106 throw new IllegalArgumentException(orientation
107 + " is not a valid orientation.");
108 this.orientation = orientation;
109 updateUI();
113 * Returns the UI delegate being used with the <code>JSeparator</code>.
115 * @return The JSeparator's UI delegate.
117 public SeparatorUI getUI()
119 return (SeparatorUI) ui;
123 * Sets the separator's UI delegate.
125 * @param ui the UI delegate.
127 public void setUI(SeparatorUI ui)
129 super.setUI(ui);
133 * Sets this separator's UI delegate to the default (obtained from the
134 * {@link UIManager}) for the current look and feel.
136 public void updateUI()
138 setUI((SeparatorUI) UIManager.getUI(this));
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>.
146 * @return <code>"SeparatorUI"</code>.
148 public String getUIClassID()
150 return "SeparatorUI";
154 * Returns the orientation of the <code>JSeparator</code>.
156 * @return The orientation (one of {@link #HORIZONTAL} and {@link #VERTICAL}).
158 * @see #setOrientation(int)
160 public int getOrientation()
162 return orientation;
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.
170 * @param orientation the orientation (either {@link #HORIZONTAL} or
171 * {@link #VERTICAL}).
173 * @throws IllegalArgumentException if <code>orientation</code> is not
174 * one of the specified values.
176 * @see #getOrientation()
178 public void setOrientation(int orientation)
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);
189 * Returns an implementation-dependent string describing the attributes of
190 * this <code>JSeparator</code>.
192 * @return A string describing the attributes of this <code>JSeparator</code>
193 * (never <code>null</code>).
195 protected String paramString()
197 String superParamStr = super.paramString();
198 if (orientation == HORIZONTAL)
199 return superParamStr + ",orientation=HORIZONTAL";
200 else
201 return superParamStr + ",orientation=VERTICAL";
205 * Returns the object that provides accessibility features for this
206 * <code>JSeparator</code> component.
208 * @return The accessible context (an instance of
209 * {@link AccessibleJSeparator}).
211 public AccessibleContext getAccessibleContext()
213 if (accessibleContext == null)
214 accessibleContext = new AccessibleJSeparator();
216 return accessibleContext;