0N/A/*
2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing;
0N/A
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.accessibility.*;
0N/A
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.IOException;
0N/A
0N/A
0N/A/**
0N/A * <code>JSeparator</code> provides a general purpose component for
0N/A * implementing divider lines - most commonly used as a divider
0N/A * between menu items that breaks them up into logical groupings.
0N/A * Instead of using <code>JSeparator</code> directly,
0N/A * you can use the <code>JMenu</code> or <code>JPopupMenu</code>
0N/A * <code>addSeparator</code> method to create and add a separator.
0N/A * <code>JSeparator</code>s may also be used elsewhere in a GUI
0N/A * wherever a visual divider is useful.
0N/A *
0N/A * <p>
0N/A *
0N/A * For more information and examples see
0N/A * <a
0N/A href="http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html">How to Use Menus</a>,
0N/A * a section in <em>The Java Tutorial.</em>
0N/A * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @beaninfo
0N/A * attribute: isContainer false
0N/A * description: A divider between menu items.
0N/A *
0N/A * @author Georges Saab
0N/A * @author Jeff Shapiro
0N/A */
0N/Apublic class JSeparator extends JComponent implements SwingConstants, Accessible
0N/A{
0N/A /**
0N/A * @see #getUIClassID
0N/A * @see #readObject
0N/A */
0N/A private static final String uiClassID = "SeparatorUI";
0N/A
0N/A private int orientation = HORIZONTAL;
0N/A
0N/A /** Creates a new horizontal separator. */
0N/A public JSeparator()
0N/A {
0N/A this( HORIZONTAL );
0N/A }
0N/A
0N/A /**
0N/A * Creates a new separator with the specified horizontal or
0N/A * vertical orientation.
0N/A *
0N/A * @param orientation an integer specifying
0N/A * <code>SwingConstants.HORIZONTAL</code> or
0N/A * <code>SwingConstants.VERTICAL</code>
0N/A * @exception IllegalArgumentException if <code>orientation</code>
0N/A * is neither <code>SwingConstants.HORIZONTAL</code> nor
0N/A * <code>SwingConstants.VERTICAL</code>
0N/A */
0N/A public JSeparator( int orientation )
0N/A {
0N/A checkOrientation( orientation );
0N/A this.orientation = orientation;
0N/A setFocusable(false);
0N/A updateUI();
0N/A }
0N/A
0N/A /**
0N/A * Returns the L&F object that renders this component.
0N/A *
0N/A * @return the SeparatorUI object that renders this component
0N/A */
0N/A public SeparatorUI getUI() {
0N/A return (SeparatorUI)ui;
0N/A }
0N/A
0N/A /**
0N/A * Sets the L&F object that renders this component.
0N/A *
0N/A * @param ui the SeparatorUI L&F object
0N/A * @see UIDefaults#getUI
0N/A * @beaninfo
0N/A * bound: true
0N/A * hidden: true
0N/A * attribute: visualUpdate true
0N/A * description: The UI object that implements the Component's LookAndFeel.
0N/A */
0N/A public void setUI(SeparatorUI ui) {
0N/A super.setUI(ui);
0N/A }
0N/A
0N/A /**
0N/A * Resets the UI property to a value from the current look and feel.
0N/A *
0N/A * @see JComponent#updateUI
0N/A */
0N/A public void updateUI() {
0N/A setUI((SeparatorUI)UIManager.getUI(this));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the name of the L&F class that renders this component.
0N/A *
0N/A * @return the string "SeparatorUI"
0N/A * @see JComponent#getUIClassID
0N/A * @see UIDefaults#getUI
0N/A */
0N/A public String getUIClassID() {
0N/A return uiClassID;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * See <code>readObject</code> and <code>writeObject</code> in
0N/A * <code>JComponent</code> for more
0N/A * information about serialization in Swing.
0N/A */
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
0N/A s.defaultWriteObject();
0N/A if (getUIClassID().equals(uiClassID)) {
0N/A byte count = JComponent.getWriteObjCounter(this);
0N/A JComponent.setWriteObjCounter(this, --count);
0N/A if (count == 0 && ui != null) {
0N/A ui.installUI(this);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the orientation of this separator.
0N/A *
0N/A * @return The value of the orientation property, one of the
0N/A * following constants defined in <code>SwingConstants</code>:
0N/A * <code>VERTICAL</code>, or
0N/A * <code>HORIZONTAL</code>.
0N/A *
0N/A * @see SwingConstants
0N/A * @see #setOrientation
0N/A */
0N/A public int getOrientation() {
0N/A return this.orientation;
0N/A }
0N/A
0N/A /**
0N/A * Sets the orientation of the separator.
0N/A * The default value of this property is HORIZONTAL.
0N/A * @param orientation either <code>SwingConstants.HORIZONTAL</code>
0N/A * or <code>SwingConstants.VERTICAL</code>
0N/A * @exception IllegalArgumentException if <code>orientation</code>
0N/A * is neither <code>SwingConstants.HORIZONTAL</code>
0N/A * nor <code>SwingConstants.VERTICAL</code>
0N/A *
0N/A * @see SwingConstants
0N/A * @see #getOrientation
0N/A * @beaninfo
0N/A * bound: true
0N/A * preferred: true
0N/A * enum: HORIZONTAL SwingConstants.HORIZONTAL
0N/A * VERTICAL SwingConstants.VERTICAL
0N/A * attribute: visualUpdate true
0N/A * description: The orientation of the separator.
0N/A */
0N/A public void setOrientation( int orientation ) {
0N/A if (this.orientation == orientation) {
0N/A return;
0N/A }
0N/A int oldValue = this.orientation;
0N/A checkOrientation( orientation );
0N/A this.orientation = orientation;
0N/A firePropertyChange("orientation", oldValue, orientation);
0N/A revalidate();
0N/A repaint();
0N/A }
0N/A
0N/A private void checkOrientation( int orientation )
0N/A {
0N/A switch ( orientation )
0N/A {
0N/A case VERTICAL:
0N/A case HORIZONTAL:
0N/A break;
0N/A default:
0N/A throw new IllegalArgumentException( "orientation must be one of: VERTICAL, HORIZONTAL" );
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string representation of this <code>JSeparator</code>.
0N/A * This method
0N/A * is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A *
0N/A * @return a string representation of this <code>JSeparator</code>
0N/A */
0N/A protected String paramString() {
0N/A String orientationString = (orientation == HORIZONTAL ?
0N/A "HORIZONTAL" : "VERTICAL");
0N/A
0N/A return super.paramString() +
0N/A ",orientation=" + orientationString;
0N/A }
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A /**
0N/A * Gets the AccessibleContext associated with this JSeparator.
0N/A * For separators, the AccessibleContext takes the form of an
0N/A * AccessibleJSeparator.
0N/A * A new AccessibleJSeparator instance is created if necessary.
0N/A *
0N/A * @return an AccessibleJSeparator that serves as the
0N/A * AccessibleContext of this JSeparator
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleJSeparator();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>JSeparator</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to separator user-interface elements.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A protected class AccessibleJSeparator extends AccessibleJComponent {
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.SEPARATOR;
0N/A }
0N/A }
0N/A}