0N/A/*
2362N/A * Copyright (c) 1998, 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/Apackage javax.swing.text.html;
0N/A
0N/Aimport java.io.Serializable;
0N/Aimport javax.swing.text.*;
0N/A
0N/A/**
0N/A * Value for the ListModel used to represent
0N/A * <option> elements. This is the object
0N/A * installed as items of the DefaultComboBoxModel
0N/A * used to represent the <select> element.
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 * @author Timothy Prinzing
0N/A */
0N/Apublic class Option implements Serializable {
0N/A
0N/A /**
0N/A * Creates a new Option object.
0N/A *
0N/A * @param attr the attributes associated with the
0N/A * option element. The attributes are copied to
0N/A * ensure they won't change.
0N/A */
0N/A public Option(AttributeSet attr) {
0N/A this.attr = attr.copyAttributes();
0N/A selected = (attr.getAttribute(HTML.Attribute.SELECTED) != null);
0N/A }
0N/A
0N/A /**
0N/A * Sets the label to be used for the option.
0N/A */
0N/A public void setLabel(String label) {
0N/A this.label = label;
0N/A }
0N/A
0N/A /**
0N/A * Fetch the label associated with the option.
0N/A */
0N/A public String getLabel() {
0N/A return label;
0N/A }
0N/A
0N/A /**
0N/A * Fetch the attributes associated with this option.
0N/A */
0N/A public AttributeSet getAttributes() {
0N/A return attr;
0N/A }
0N/A
0N/A /**
0N/A * String representation is the label.
0N/A */
0N/A public String toString() {
0N/A return label;
0N/A }
0N/A
0N/A /**
0N/A * Sets the selected state.
0N/A */
0N/A protected void setSelection(boolean state) {
0N/A selected = state;
0N/A }
0N/A
0N/A /**
0N/A * Fetches the selection state associated with this option.
0N/A */
0N/A public boolean isSelected() {
0N/A return selected;
0N/A }
0N/A
0N/A /**
0N/A * Convenience method to return the string associated
0N/A * with the <code>value</code> attribute. If the
0N/A * value has not been specified, the label will be
0N/A * returned.
0N/A */
0N/A public String getValue() {
0N/A String value = (String) attr.getAttribute(HTML.Attribute.VALUE);
0N/A if (value == null) {
0N/A value = label;
0N/A }
0N/A return value;
0N/A }
0N/A
0N/A private boolean selected;
0N/A private String label;
0N/A private AttributeSet attr;
0N/A}