1 /* |
1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
20 * |
20 * |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
|
26 package javax.swing; |
25 package javax.swing; |
27 |
26 |
28 import java.awt.Color; |
|
29 import java.awt.Component; |
27 import java.awt.Component; |
30 import java.awt.ComponentOrientation; |
|
31 import java.awt.Container; |
28 import java.awt.Container; |
32 import java.awt.Dimension; |
29 import java.awt.Dimension; |
33 import java.awt.Graphics; |
30 import java.awt.Graphics; |
34 import java.awt.Insets; |
31 import java.awt.Insets; |
35 import java.awt.LayoutManager; |
32 import java.awt.LayoutManager; |
36 import java.awt.LayoutManager2; |
33 import java.awt.LayoutManager2; |
37 import java.awt.event.*; |
34 import java.beans.JavaBean; |
38 import java.beans.*; |
35 import java.beans.BeanProperty; |
39 |
36 import java.beans.PropertyChangeEvent; |
40 import javax.swing.border.Border; |
37 import java.beans.PropertyChangeListener; |
|
38 |
41 import javax.swing.plaf.*; |
39 import javax.swing.plaf.*; |
42 import javax.accessibility.*; |
40 import javax.accessibility.*; |
43 |
41 |
44 import java.io.Serializable; |
42 import java.io.Serializable; |
45 import java.io.ObjectOutputStream; |
43 import java.io.ObjectOutputStream; |
46 import java.io.ObjectInputStream; |
|
47 import java.io.IOException; |
44 import java.io.IOException; |
48 import java.util.Hashtable; |
|
49 |
|
50 |
45 |
51 /** |
46 /** |
52 * <code>JToolBar</code> provides a component that is useful for |
47 * <code>JToolBar</code> provides a component that is useful for |
53 * displaying commonly used <code>Action</code>s or controls. |
48 * displaying commonly used <code>Action</code>s or controls. |
54 * For examples and information on using tool bars see |
49 * For examples and information on using tool bars see |
76 * the same version of Swing. As of 1.4, support for long term storage |
71 * the same version of Swing. As of 1.4, support for long term storage |
77 * of all JavaBeans™ |
72 * of all JavaBeans™ |
78 * has been added to the <code>java.beans</code> package. |
73 * has been added to the <code>java.beans</code> package. |
79 * Please see {@link java.beans.XMLEncoder}. |
74 * Please see {@link java.beans.XMLEncoder}. |
80 * |
75 * |
81 * @beaninfo |
|
82 * attribute: isContainer true |
|
83 * description: A component which displays commonly used controls or Actions. |
|
84 * |
|
85 * @author Georges Saab |
76 * @author Georges Saab |
86 * @author Jeff Shapiro |
77 * @author Jeff Shapiro |
87 * @see Action |
78 * @see Action |
88 * @since 1.2 |
79 * @since 1.2 |
89 */ |
80 */ |
|
81 @JavaBean(defaultProperty = "UI", description = "A component which displays commonly used controls or Actions.") |
|
82 @SwingContainer |
90 @SuppressWarnings("serial") // Same-version serialization only |
83 @SuppressWarnings("serial") // Same-version serialization only |
91 public class JToolBar extends JComponent implements SwingConstants, Accessible |
84 public class JToolBar extends JComponent implements SwingConstants, Accessible |
92 { |
85 { |
93 /** |
86 /** |
94 * @see #getUIClassID |
87 * @see #getUIClassID |
173 /** |
166 /** |
174 * Sets the L&F object that renders this component. |
167 * Sets the L&F object that renders this component. |
175 * |
168 * |
176 * @param ui the <code>ToolBarUI</code> L&F object |
169 * @param ui the <code>ToolBarUI</code> L&F object |
177 * @see UIDefaults#getUI |
170 * @see UIDefaults#getUI |
178 * @beaninfo |
171 */ |
179 * bound: true |
172 @BeanProperty(hidden = true, visualUpdate = true, description |
180 * hidden: true |
173 = "The UI object that implements the Component's LookAndFeel.") |
181 * attribute: visualUpdate true |
|
182 * description: The UI object that implements the Component's LookAndFeel. |
|
183 */ |
|
184 public void setUI(ToolBarUI ui) { |
174 public void setUI(ToolBarUI ui) { |
185 super.setUI(ui); |
175 super.setUI(ui); |
186 } |
176 } |
187 |
177 |
188 /** |
178 /** |
264 * effectively be ignored). |
255 * effectively be ignored). |
265 * |
256 * |
266 * @param m an <code>Insets</code> object that defines the space |
257 * @param m an <code>Insets</code> object that defines the space |
267 * between the border and the buttons |
258 * between the border and the buttons |
268 * @see Insets |
259 * @see Insets |
269 * @beaninfo |
|
270 * description: The margin between the tool bar's border and contents |
|
271 * bound: true |
|
272 * expert: true |
|
273 */ |
260 */ |
|
261 @BeanProperty(expert = true, description |
|
262 = "The margin between the tool bar's border and contents") |
274 public void setMargin(Insets m) |
263 public void setMargin(Insets m) |
275 { |
264 { |
276 Insets old = margin; |
265 Insets old = margin; |
277 margin = m; |
266 margin = m; |
278 firePropertyChange("margin", old, m); |
267 firePropertyChange("margin", old, m); |
315 * Some look and feels might not implement painted borders; |
304 * Some look and feels might not implement painted borders; |
316 * they will ignore this property. |
305 * they will ignore this property. |
317 * |
306 * |
318 * @param b if true, the border is painted |
307 * @param b if true, the border is painted |
319 * @see #isBorderPainted |
308 * @see #isBorderPainted |
320 * @beaninfo |
|
321 * description: Does the tool bar paint its borders? |
|
322 * bound: true |
|
323 * expert: true |
|
324 */ |
309 */ |
|
310 @BeanProperty(expert = true, description |
|
311 = "Does the tool bar paint its borders?") |
325 public void setBorderPainted(boolean b) |
312 public void setBorderPainted(boolean b) |
326 { |
313 { |
327 if ( paintBorder != b ) |
314 if ( paintBorder != b ) |
328 { |
315 { |
329 boolean old = paintBorder; |
316 boolean old = paintBorder; |
374 * they will ignore this property. |
361 * they will ignore this property. |
375 * |
362 * |
376 * @param b if <code>true</code>, the tool bar can be moved; |
363 * @param b if <code>true</code>, the tool bar can be moved; |
377 * <code>false</code> otherwise |
364 * <code>false</code> otherwise |
378 * @see #isFloatable |
365 * @see #isFloatable |
379 * @beaninfo |
|
380 * description: Can the tool bar be made to float by the user? |
|
381 * bound: true |
|
382 * preferred: true |
|
383 */ |
366 */ |
|
367 @BeanProperty(preferred = true, description |
|
368 = "Can the tool bar be made to float by the user?") |
384 public void setFloatable( boolean b ) |
369 public void setFloatable( boolean b ) |
385 { |
370 { |
386 if ( floatable != b ) |
371 if ( floatable != b ) |
387 { |
372 { |
388 boolean old = floatable; |
373 boolean old = floatable; |
416 * @param o the new orientation -- either <code>HORIZONTAL</code> or |
401 * @param o the new orientation -- either <code>HORIZONTAL</code> or |
417 * <code>VERTICAL</code> |
402 * <code>VERTICAL</code> |
418 * @exception IllegalArgumentException if orientation is neither |
403 * @exception IllegalArgumentException if orientation is neither |
419 * <code>HORIZONTAL</code> nor <code>VERTICAL</code> |
404 * <code>HORIZONTAL</code> nor <code>VERTICAL</code> |
420 * @see #getOrientation |
405 * @see #getOrientation |
421 * @beaninfo |
406 */ |
422 * description: The current orientation of the tool bar |
407 @BeanProperty(preferred = true, enumerationValues = { |
423 * bound: true |
408 "SwingConstants.HORIZONTAL", |
424 * preferred: true |
409 "SwingConstants.VERTICAL"}, description |
425 * enum: HORIZONTAL SwingConstants.HORIZONTAL |
410 = "The current orientation of the tool bar") |
426 * VERTICAL SwingConstants.VERTICAL |
|
427 */ |
|
428 public void setOrientation( int o ) |
411 public void setOrientation( int o ) |
429 { |
412 { |
430 checkOrientation( o ); |
413 checkOrientation( o ); |
431 |
414 |
432 if ( orientation != o ) |
415 if ( orientation != o ) |
449 * The implementation of a look and feel may choose to ignore this |
432 * The implementation of a look and feel may choose to ignore this |
450 * property. |
433 * property. |
451 * |
434 * |
452 * @param rollover true for rollover toolbar buttons; otherwise false |
435 * @param rollover true for rollover toolbar buttons; otherwise false |
453 * @since 1.4 |
436 * @since 1.4 |
454 * @beaninfo |
437 */ |
455 * bound: true |
438 @BeanProperty(preferred = true, visualUpdate = true, description |
456 * preferred: true |
439 = "Will draw rollover button borders in the toolbar.") |
457 * attribute: visualUpdate true |
|
458 * description: Will draw rollover button borders in the toolbar. |
|
459 */ |
|
460 public void setRollover(boolean rollover) { |
440 public void setRollover(boolean rollover) { |
461 putClientProperty("JToolBar.isRollover", |
441 putClientProperty("JToolBar.isRollover", |
462 rollover ? Boolean.TRUE : Boolean.FALSE); |
442 rollover ? Boolean.TRUE : Boolean.FALSE); |
463 } |
443 } |
464 |
444 |
834 * A new AccessibleJToolBar instance is created if necessary. |
814 * A new AccessibleJToolBar instance is created if necessary. |
835 * |
815 * |
836 * @return an AccessibleJToolBar that serves as the |
816 * @return an AccessibleJToolBar that serves as the |
837 * AccessibleContext of this JToolBar |
817 * AccessibleContext of this JToolBar |
838 */ |
818 */ |
|
819 @BeanProperty(bound = false) |
839 public AccessibleContext getAccessibleContext() { |
820 public AccessibleContext getAccessibleContext() { |
840 if (accessibleContext == null) { |
821 if (accessibleContext == null) { |
841 accessibleContext = new AccessibleJToolBar(); |
822 accessibleContext = new AccessibleJToolBar(); |
842 } |
823 } |
843 return accessibleContext; |
824 return accessibleContext; |