1 /* MultiComboBoxUI.java --
2 Copyright (C) 2005 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)
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
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
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
.plaf
.multi
;
40 import java
.awt
.Dimension
;
41 import java
.awt
.Graphics
;
42 import java
.util
.Iterator
;
43 import java
.util
.Vector
;
45 import javax
.accessibility
.Accessible
;
46 import javax
.swing
.JComboBox
;
47 import javax
.swing
.JComponent
;
48 import javax
.swing
.LookAndFeel
;
49 import javax
.swing
.UIManager
;
50 import javax
.swing
.plaf
.ComboBoxUI
;
51 import javax
.swing
.plaf
.ComponentUI
;
54 * A UI delegate that that coordinates multiple {@link ComboBoxUI}
55 * instances, one from the primary look and feel, and one or more from the
56 * auxiliary look and feel(s).
58 * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel)
60 public class MultiComboBoxUI
extends ComboBoxUI
63 /** A list of references to the actual component UIs. */
67 * Creates a new <code>MultiComboBoxUI</code> instance.
69 * @see #createUI(JComponent)
71 public MultiComboBoxUI()
77 * Creates a delegate object for the specified component. If any auxiliary
78 * look and feels support this component, a <code>MultiComboBoxUI</code>
79 * is returned, otherwise the UI from the default look and feel is returned.
81 * @param target the component.
83 * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent)
85 public static ComponentUI
createUI(JComponent target
)
87 MultiComboBoxUI mui
= new MultiComboBoxUI();
88 return MultiLookAndFeel
.createUIs(mui
, mui
.uis
, target
);
92 * Calls the {@link ComponentUI#installUI(JComponent)} method for all
93 * the UI delegates managed by this <code>MultiComboBoxUI</code>.
95 * @param c the component.
97 public void installUI(JComponent c
)
99 Iterator iterator
= uis
.iterator();
100 while (iterator
.hasNext())
102 ComponentUI ui
= (ComponentUI
) iterator
.next();
108 * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all
109 * the UI delegates managed by this <code>MultiComboBoxUI</code>.
111 * @param c the component.
113 public void uninstallUI(JComponent c
)
115 Iterator iterator
= uis
.iterator();
116 while (iterator
.hasNext())
118 ComponentUI ui
= (ComponentUI
) iterator
.next();
124 * Returns an array containing the UI delegates managed by this
125 * <code>MultiComboBoxUI</code>. The first item in the array is always
126 * the UI delegate from the installed default look and feel.
128 * @return An array of UI delegates.
130 public ComponentUI
[] getUIs()
132 return MultiLookAndFeel
.uisToArray(uis
);
136 * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all
137 * the UI delegates managed by this <code>MultiComboBoxUI</code>,
138 * returning the result for the UI delegate from the primary look and
141 * @param c the component.
142 * @param x the x-coordinate.
143 * @param y the y-coordinate.
145 * @return <code>true</code> if the specified (x, y) coordinate falls within
146 * the bounds of the component as rendered by the UI delegate in the
147 * primary look and feel, and <code>false</code> otherwise.
149 public boolean contains(JComponent c
, int x
, int y
)
151 boolean result
= false;
152 Iterator iterator
= uis
.iterator();
153 // first UI delegate provides the return value
154 if (iterator
.hasNext())
156 ComponentUI ui
= (ComponentUI
) iterator
.next();
157 result
= ui
.contains(c
, x
, y
);
159 // return values from auxiliary UI delegates are ignored
160 while (iterator
.hasNext())
162 ComponentUI ui
= (ComponentUI
) iterator
.next();
163 /* boolean ignored = */ ui
.contains(c
, x
, y
);
169 * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all
170 * the UI delegates managed by this <code>MultiComboBoxUI</code>.
172 * @param g the graphics device.
173 * @param c the component.
175 public void update(Graphics g
, JComponent c
)
177 Iterator iterator
= uis
.iterator();
178 while (iterator
.hasNext())
180 ComponentUI ui
= (ComponentUI
) iterator
.next();
186 * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI
187 * delegates managed by this <code>MultiComboBoxUI</code>.
189 * @param g the graphics device.
190 * @param c the component.
192 public void paint(Graphics g
, JComponent c
)
194 Iterator iterator
= uis
.iterator();
195 while (iterator
.hasNext())
197 ComponentUI ui
= (ComponentUI
) iterator
.next();
203 * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all
204 * the UI delegates managed by this <code>MultiComboBoxUI</code>,
205 * returning the preferred size for the UI delegate from the primary look and
208 * @param c the component.
210 * @return The preferred size returned by the UI delegate from the primary
213 public Dimension
getPreferredSize(JComponent c
)
215 Dimension result
= null;
216 Iterator iterator
= uis
.iterator();
217 // first UI delegate provides the return value
218 if (iterator
.hasNext())
220 ComponentUI ui
= (ComponentUI
) iterator
.next();
221 result
= ui
.getPreferredSize(c
);
223 // return values from auxiliary UI delegates are ignored
224 while (iterator
.hasNext())
226 ComponentUI ui
= (ComponentUI
) iterator
.next();
227 /* Dimension ignored = */ ui
.getPreferredSize(c
);
233 * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all
234 * the UI delegates managed by this <code>MultiComboBoxUI</code>,
235 * returning the minimum size for the UI delegate from the primary look and
238 * @param c the component.
240 * @return The minimum size returned by the UI delegate from the primary
243 public Dimension
getMinimumSize(JComponent c
)
245 Dimension result
= null;
246 Iterator iterator
= uis
.iterator();
247 // first UI delegate provides the return value
248 if (iterator
.hasNext())
250 ComponentUI ui
= (ComponentUI
) iterator
.next();
251 result
= ui
.getMinimumSize(c
);
253 // return values from auxiliary UI delegates are ignored
254 while (iterator
.hasNext())
256 ComponentUI ui
= (ComponentUI
) iterator
.next();
257 /* Dimension ignored = */ ui
.getMinimumSize(c
);
263 * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all
264 * the UI delegates managed by this <code>MultiComboBoxUI</code>,
265 * returning the maximum size for the UI delegate from the primary look and
268 * @param c the component.
270 * @return The maximum size returned by the UI delegate from the primary
273 public Dimension
getMaximumSize(JComponent c
)
275 Dimension result
= null;
276 Iterator iterator
= uis
.iterator();
277 // first UI delegate provides the return value
278 if (iterator
.hasNext())
280 ComponentUI ui
= (ComponentUI
) iterator
.next();
281 result
= ui
.getMaximumSize(c
);
283 // return values from auxiliary UI delegates are ignored
284 while (iterator
.hasNext())
286 ComponentUI ui
= (ComponentUI
) iterator
.next();
287 /* Dimension ignored = */ ui
.getMaximumSize(c
);
293 * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method
294 * for all the UI delegates managed by this <code>MultiComboBoxUI</code>,
295 * returning the count for the UI delegate from the primary look and
298 * @param c the component.
300 * @return The count returned by the UI delegate from the primary
303 public int getAccessibleChildrenCount(JComponent c
)
306 Iterator iterator
= uis
.iterator();
307 // first UI delegate provides the return value
308 if (iterator
.hasNext())
310 ComponentUI ui
= (ComponentUI
) iterator
.next();
311 result
= ui
.getAccessibleChildrenCount(c
);
313 // return values from auxiliary UI delegates are ignored
314 while (iterator
.hasNext())
316 ComponentUI ui
= (ComponentUI
) iterator
.next();
317 /* int ignored = */ ui
.getAccessibleChildrenCount(c
);
323 * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method
324 * for all the UI delegates managed by this <code>MultiComboBoxUI</code>,
325 * returning the child for the UI delegate from the primary look and
328 * @param c the component
329 * @param i the child index.
331 * @return The child returned by the UI delegate from the primary
334 public Accessible
getAccessibleChild(JComponent c
, int i
)
336 Accessible result
= null;
337 Iterator iterator
= uis
.iterator();
338 // first UI delegate provides the return value
339 if (iterator
.hasNext())
341 ComponentUI ui
= (ComponentUI
) iterator
.next();
342 result
= ui
.getAccessibleChild(c
, i
);
344 // return values from auxiliary UI delegates are ignored
345 while (iterator
.hasNext())
347 ComponentUI ui
= (ComponentUI
) iterator
.next();
348 /* Accessible ignored = */ ui
.getAccessibleChild(c
, i
);
354 * Calls the {@link ComboBoxUI#setPopupVisible(JComboBox, boolean)} method
355 * for all the UI delegates managed by this <code>MultiComboBoxUI</code>.
357 * @param c the component.
358 * @param visible the visible state.
360 public void setPopupVisible(JComboBox c
, boolean visible
) {
361 Iterator iterator
= uis
.iterator();
362 while (iterator
.hasNext())
364 ComboBoxUI ui
= (ComboBoxUI
) iterator
.next();
365 ui
.setPopupVisible(c
, visible
);
370 * Calls the {@link ComboBoxUI#isPopupVisible(JComboBox)} method for all
371 * the UI delegates managed by this <code>MultiComboBoxUI</code>,
372 * returning the result for the UI delegate from the primary look and
375 * @param c the component.
377 * @return The result for the UI delegate from the primary look and feel.
379 public boolean isPopupVisible(JComboBox c
) {
380 boolean result
= false;
381 Iterator iterator
= uis
.iterator();
382 // first UI delegate provides the return value
383 if (iterator
.hasNext())
385 ComboBoxUI ui
= (ComboBoxUI
) iterator
.next();
386 result
= ui
.isPopupVisible(c
);
388 // return values from auxiliary UI delegates are ignored
389 while (iterator
.hasNext())
391 ComboBoxUI ui
= (ComboBoxUI
) iterator
.next();
392 /* boolean ignored = */ ui
.isPopupVisible(c
);
398 * Calls the {@link ComboBoxUI#isFocusTraversable(JComboBox)} method for all
399 * the UI delegates managed by this <code>MultiComboBoxUI</code>,
400 * returning the result for the UI delegate from the primary look and
403 * @param c the component.
405 * @return <code>true</code> if the combo box is traversable according to the
406 * UI delegate in the primary look and feel, and <code>false</code>
409 public boolean isFocusTraversable(JComboBox c
) {
410 boolean result
= false;
411 Iterator iterator
= uis
.iterator();
412 // first UI delegate provides the return value
413 if (iterator
.hasNext())
415 ComboBoxUI ui
= (ComboBoxUI
) iterator
.next();
416 result
= ui
.isFocusTraversable(c
);
418 // return values from auxiliary UI delegates are ignored
419 while (iterator
.hasNext())
421 ComboBoxUI ui
= (ComboBoxUI
) iterator
.next();
422 /* boolean ignored = */ ui
.isFocusTraversable(c
);