Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / JCheckBoxMenuItem.java
blob815244259be531cda858b550cc48a43d893be9a9
1 /* JCheckBoxMenuItem.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. */
39 package javax.swing;
41 import javax.accessibility.Accessible;
42 import javax.accessibility.AccessibleContext;
43 import javax.accessibility.AccessibleRole;
45 /**
46 * A menu item that displays a checkbox. Its behaviour is very similar
47 * to {@link JCheckBox}. Just like the <code>JCheckBox</code>, user can check
48 * and uncheck this menu item by clicking on it. Also
49 * {@link AbstractButton#setSelected} and {@link #setState} can be use used
50 * for the same purpose.
51 * <code>JCheckBoxMenuItem</code> uses
52 * <code>ToggleButtonModel</code> to keep track of its selection.
54 * @author original author unknown
56 public class JCheckBoxMenuItem extends JMenuItem implements SwingConstants,
57 Accessible
59 private static final long serialVersionUID = -6676402307973384715L;
61 /** name for the UI delegate for this menuItem. */
62 private static final String uiClassID = "CheckBoxMenuItemUI";
64 /** Indicates whether this menu item is checked. */
65 private boolean state;
67 /**
68 * This array contains text of this menu item if this menu item is in
69 * checked state and null it is not.
71 private Object[] selectedObjects = new Object[1];
73 /**
74 * Creates a new JCheckBoxMenuItem object.
76 public JCheckBoxMenuItem()
78 this(null, null);
81 /**
82 * Creates a new JCheckBoxMenuItem with given icon
84 * @param icon Icon for this menu item
86 public JCheckBoxMenuItem(Icon icon)
88 this(null, icon);
91 /**
92 * Creates a new JCheckBoxMenuItem with given label
94 * @param text Label for this menu item
96 public JCheckBoxMenuItem(String text)
98 this(text, null);
102 * Creates a new JCheckBoxMenuItem using given action
104 * @param action Action for this menu item.
106 public JCheckBoxMenuItem(Action action)
108 this();
109 setAction(action);
113 * Creates a new JCheckBoxMenuItem object with given label and icon
115 * @param text Label for this menu item
116 * @param icon Icon for this menu item
118 public JCheckBoxMenuItem(String text, Icon icon)
120 this(text, icon, false);
124 * Creates a new JCheckBoxMenuItem object using specified label and
125 * marked as checked if given 'state' is true.
127 * @param text Label for this menu item
128 * @param state <code>true</code> if this item should be in checked state and
129 * <code>false</code> otherwise
131 public JCheckBoxMenuItem(String text, boolean state)
133 this(text, null, state);
137 * Creates a new JCheckBoxMenuItem object with given label, icon,
138 * and marked as checked if given 'state' is true.
140 * @param text Label for this menu item
141 * @param icon icon for this menu item
142 * @param state <code>true</code> if this item should be in checked state and
143 * false otherwise
145 public JCheckBoxMenuItem(String text, Icon icon, boolean state)
147 super(text, icon);
148 setModel(new JToggleButton.ToggleButtonModel());
149 this.state = state;
150 this.setVisible(true);
154 * This method returns a name to identify which look and feel class will be
155 * the UI delegate for the menuItem.
157 * @return The Look and Feel classID. "JCheckBoxMenuItemUI"
159 public String getUIClassID()
161 return uiClassID;
165 * Returns checked state for this check box menu item.
167 * @return Returns true if this menu item is in checked state
168 * and false otherwise.
170 public boolean getState()
172 return state;
176 * Sets state for this check box menu item. If
177 * given 'state' is true, then mark menu item as checked,
178 * and uncheck this menu item otherwise.
180 * @param state new state for this menu item
182 public synchronized void setState(boolean state)
184 this.state = state;
188 * This method returns array containing label of this
189 * menu item if it is selected and null otherwise.
191 * @return Array containing label of this
192 * menu item if this menu item is selected or null otherwise.
194 public Object[] getSelectedObjects()
196 if (state == true)
197 selectedObjects[0] = this.getText();
198 else
199 selectedObjects[0] = null;
201 return selectedObjects;
205 * This method overrides JComponent.requestFocus with an empty
206 * implementation, since JCheckBoxMenuItems should not
207 * receve focus in general.
209 public void requestFocus()
211 // Should do nothing here
215 * A string that describes this JCheckBoxMenuItem. Normally only used
216 * for debugging.
218 * @return A string describing this JCheckBoxMenuItem
220 protected String paramString()
222 return "JCheckBoxMenuItem";
225 public AccessibleContext getAccessibleContext()
227 if (accessibleContext == null)
228 accessibleContext = new AccessibleJCheckBoxMenuItem();
230 return accessibleContext;
234 * Accessibility support for <code>JCheckBoxMenuItem</code>.
236 protected class AccessibleJCheckBoxMenuItem extends AccessibleJMenuItem
238 private static final long serialVersionUID = 1079958073579370777L;
241 * Creates a new AccessibleJCheckBoxMenuItem object.
243 protected AccessibleJCheckBoxMenuItem()
245 // Nothing to do here.
248 public AccessibleRole getAccessibleRole()
250 return AccessibleRole.CHECK_BOX;