46 |
|
|
47 |
import javax.accessibility.Accessible; |
import javax.accessibility.Accessible; |
48 |
import javax.accessibility.AccessibleContext; |
import javax.accessibility.AccessibleContext; |
49 |
|
import javax.accessibility.AccessibleRole; |
50 |
|
import javax.accessibility.AccessibleSelection; |
51 |
|
import javax.accessibility.AccessibleStateSet; |
52 |
import javax.swing.plaf.MenuBarUI; |
import javax.swing.plaf.MenuBarUI; |
53 |
|
|
54 |
/** |
/** |
62 |
*/ |
*/ |
63 |
public class JMenuBar extends JComponent implements Accessible, MenuElement |
public class JMenuBar extends JComponent implements Accessible, MenuElement |
64 |
{ |
{ |
65 |
|
/** |
66 |
|
* Provides accessibility support for <code>JMenuBar</code>. |
67 |
|
* |
68 |
|
* @author Roman Kennke (kennke@aicas.com) |
69 |
|
*/ |
70 |
|
protected class AccessibleJMenuBar extends AccessibleJComponent |
71 |
|
implements AccessibleSelection |
72 |
|
{ |
73 |
|
|
74 |
|
/** |
75 |
|
* Returns the number of selected items in the menu bar. Possible values |
76 |
|
* are <code>0</code> if nothing is selected, or <code>1</code> if one |
77 |
|
* item is selected. |
78 |
|
* |
79 |
|
* @return the number of selected items in the menu bar |
80 |
|
*/ |
81 |
|
public int getAccessibleSelectionCount() |
82 |
|
{ |
83 |
|
int count = 0; |
84 |
|
if (getSelectionModel().getSelectedIndex() != -1) |
85 |
|
count = 1; |
86 |
|
return count; |
87 |
|
} |
88 |
|
|
89 |
|
/** |
90 |
|
* Returns the selected with index <code>i</code> menu, or |
91 |
|
* <code>null</code> if the specified menu is not selected. |
92 |
|
* |
93 |
|
* @param i the index of the menu to return |
94 |
|
* |
95 |
|
* @return the selected with index <code>i</code> menu, or |
96 |
|
* <code>null</code> if the specified menu is not selected |
97 |
|
*/ |
98 |
|
public Accessible getAccessibleSelection(int i) |
99 |
|
{ |
100 |
|
if (getSelectionModel().getSelectedIndex() != i) |
101 |
|
return null; |
102 |
|
return getMenu(i); |
103 |
|
} |
104 |
|
|
105 |
|
/** |
106 |
|
* Returns <code>true</code> if the specified menu is selected, |
107 |
|
* <code>false</code> otherwise. |
108 |
|
* |
109 |
|
* @param i the index of the menu to check |
110 |
|
* |
111 |
|
*@return <code>true</code> if the specified menu is selected, |
112 |
|
* <code>false</code> otherwise |
113 |
|
*/ |
114 |
|
public boolean isAccessibleChildSelected(int i) |
115 |
|
{ |
116 |
|
return getSelectionModel().getSelectedIndex() == i; |
117 |
|
} |
118 |
|
|
119 |
|
/** |
120 |
|
* Selects the menu with index <code>i</code>. If another menu is already |
121 |
|
* selected, this will be deselected. |
122 |
|
* |
123 |
|
* @param i the menu to be selected |
124 |
|
*/ |
125 |
|
public void addAccessibleSelection(int i) |
126 |
|
{ |
127 |
|
getSelectionModel().setSelectedIndex(i); |
128 |
|
} |
129 |
|
|
130 |
|
/** |
131 |
|
* Deselects the menu with index <code>i</code>. |
132 |
|
* |
133 |
|
* @param i the menu index to be deselected |
134 |
|
*/ |
135 |
|
public void removeAccessibleSelection(int i) |
136 |
|
{ |
137 |
|
if (getSelectionModel().getSelectedIndex() == i) |
138 |
|
getSelectionModel().clearSelection(); |
139 |
|
} |
140 |
|
|
141 |
|
/** |
142 |
|
* Deselects all possibly selected menus. |
143 |
|
*/ |
144 |
|
public void clearAccessibleSelection() |
145 |
|
{ |
146 |
|
getSelectionModel().clearSelection(); |
147 |
|
} |
148 |
|
|
149 |
|
/** |
150 |
|
* In menu bars it is not possible to select all items, so this method |
151 |
|
* does nothing. |
152 |
|
*/ |
153 |
|
public void selectAllAccessibleSelection() |
154 |
|
{ |
155 |
|
// In menu bars it is not possible to select all items, so this method |
156 |
|
// does nothing. |
157 |
|
} |
158 |
|
|
159 |
|
/** |
160 |
|
* Returns the accessible role of <code>JMenuBar</code>, which is |
161 |
|
* {@link AccessibleRole#MENU_BAR}. |
162 |
|
* |
163 |
|
* @return the accessible role of <code>JMenuBar</code>, which is |
164 |
|
* {@link AccessibleRole#MENU_BAR} |
165 |
|
*/ |
166 |
|
public AccessibleRole getAccessibleRole() |
167 |
|
{ |
168 |
|
return AccessibleRole.MENU_BAR; |
169 |
|
} |
170 |
|
|
171 |
|
/** |
172 |
|
* Returns the <code>AccessibleSelection</code> for this object. This |
173 |
|
* method returns <code>this</code>, since the |
174 |
|
* <code>AccessibleJMenuBar</code> manages its selection itself. |
175 |
|
* |
176 |
|
* @return the <code>AccessibleSelection</code> for this object |
177 |
|
*/ |
178 |
|
public AccessibleSelection getAccessibleSelection() |
179 |
|
{ |
180 |
|
return this; |
181 |
|
} |
182 |
|
|
183 |
|
/** |
184 |
|
* Returns the state of this <code>AccessibleJMenuBar</code>. |
185 |
|
* |
186 |
|
* @return the state of this <code>AccessibleJMenuBar</code>. |
187 |
|
*/ |
188 |
|
public AccessibleStateSet getAccessibleStateSet() |
189 |
|
{ |
190 |
|
AccessibleStateSet stateSet = super.getAccessibleStateSet(); |
191 |
|
// TODO: Figure out what state must be added to the super state set. |
192 |
|
return stateSet; |
193 |
|
} |
194 |
|
} |
195 |
|
|
196 |
private static final long serialVersionUID = -8191026883931977036L; |
private static final long serialVersionUID = -8191026883931977036L; |
197 |
|
|
198 |
/** JMenuBar's model. It keeps track of selected menu's index */ |
/** JMenuBar's model. It keeps track of selected menu's index */ |
240 |
|
|
241 |
public AccessibleContext getAccessibleContext() |
public AccessibleContext getAccessibleContext() |
242 |
{ |
{ |
243 |
return null; |
if (accessibleContext == null) |
244 |
|
accessibleContext = new AccessibleJMenuBar(); |
245 |
|
return accessibleContext; |
246 |
} |
} |
247 |
|
|
248 |
/** |
/** |
520 |
* Sets help menu for this menu bar |
* Sets help menu for this menu bar |
521 |
* |
* |
522 |
* @param menu help menu |
* @param menu help menu |
523 |
|
* |
524 |
|
* @specnote The specification states that this method is not yet implemented |
525 |
|
* and should throw an exception. |
526 |
*/ |
*/ |
527 |
public void setHelpMenu(JMenu menu) |
public void setHelpMenu(JMenu menu) |
528 |
{ |
{ |
529 |
|
// We throw an Error here, just as Sun's JDK does. |
530 |
|
throw new Error("setHelpMenu() not yet implemented."); |
531 |
} |
} |
532 |
|
|
533 |
/** |
/** |