Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/javax/swing/JToolBar.java
+++ new/src/share/classes/javax/swing/JToolBar.java
1 1 /*
2 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 package javax.swing;
27 27
28 28 import java.awt.Color;
29 29 import java.awt.Component;
30 30 import java.awt.ComponentOrientation;
31 31 import java.awt.Container;
32 32 import java.awt.Dimension;
33 33 import java.awt.Graphics;
34 34 import java.awt.Insets;
35 35 import java.awt.LayoutManager;
36 36 import java.awt.LayoutManager2;
37 37 import java.awt.event.*;
38 38 import java.beans.*;
39 39
40 40 import javax.swing.border.Border;
41 41 import javax.swing.plaf.*;
42 42 import javax.accessibility.*;
43 43
44 44 import java.io.Serializable;
↓ open down ↓ |
44 lines elided |
↑ open up ↑ |
45 45 import java.io.ObjectOutputStream;
46 46 import java.io.ObjectInputStream;
47 47 import java.io.IOException;
48 48 import java.util.Hashtable;
49 49
50 50
51 51 /**
52 52 * <code>JToolBar</code> provides a component that is useful for
53 53 * displaying commonly used <code>Action</code>s or controls.
54 54 * For examples and information on using tool bars see
55 - * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/toolbar.html">How to Use Tool Bars</a>,
55 + * <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/toolbar.html">How to Use Tool Bars</a>,
56 56 * a section in <em>The Java Tutorial</em>.
57 57 *
58 58 * <p>
59 59 * With most look and feels,
60 60 * the user can drag out a tool bar into a separate window
61 61 * (unless the <code>floatable</code> property is set to <code>false</code>).
62 62 * For drag-out to work correctly, it is recommended that you add
63 63 * <code>JToolBar</code> instances to one of the four "sides" of a
64 64 * container whose layout manager is a <code>BorderLayout</code>,
65 65 * and do not add children to any of the other four "sides".
66 66 * <p>
67 67 * <strong>Warning:</strong> Swing is not thread safe. For more
68 68 * information see <a
69 69 * href="package-summary.html#threading">Swing's Threading
70 70 * Policy</a>.
71 71 * <p>
72 72 * <strong>Warning:</strong>
73 73 * Serialized objects of this class will not be compatible with
74 74 * future Swing releases. The current serialization support is
75 75 * appropriate for short term storage or RMI between applications running
76 76 * the same version of Swing. As of 1.4, support for long term storage
77 77 * of all JavaBeans™
78 78 * has been added to the <code>java.beans</code> package.
79 79 * Please see {@link java.beans.XMLEncoder}.
80 80 *
81 81 * @beaninfo
82 82 * attribute: isContainer true
83 83 * description: A component which displays commonly used controls or Actions.
84 84 *
85 85 * @author Georges Saab
86 86 * @author Jeff Shapiro
87 87 * @see Action
88 88 */
89 89 public class JToolBar extends JComponent implements SwingConstants, Accessible
90 90 {
91 91 /**
92 92 * @see #getUIClassID
93 93 * @see #readObject
94 94 */
95 95 private static final String uiClassID = "ToolBarUI";
96 96
97 97 private boolean paintBorder = true;
98 98 private Insets margin = null;
99 99 private boolean floatable = true;
100 100 private int orientation = HORIZONTAL;
101 101
102 102 /**
103 103 * Creates a new tool bar; orientation defaults to <code>HORIZONTAL</code>.
104 104 */
105 105 public JToolBar()
106 106 {
107 107 this( HORIZONTAL );
108 108 }
109 109
110 110 /**
111 111 * Creates a new tool bar with the specified <code>orientation</code>.
112 112 * The <code>orientation</code> must be either <code>HORIZONTAL</code>
113 113 * or <code>VERTICAL</code>.
114 114 *
115 115 * @param orientation the orientation desired
116 116 */
117 117 public JToolBar( int orientation )
118 118 {
119 119 this(null, orientation);
120 120 }
121 121
122 122 /**
123 123 * Creates a new tool bar with the specified <code>name</code>. The
124 124 * name is used as the title of the undocked tool bar. The default
125 125 * orientation is <code>HORIZONTAL</code>.
126 126 *
127 127 * @param name the name of the tool bar
128 128 * @since 1.3
129 129 */
130 130 public JToolBar( String name ) {
131 131 this(name, HORIZONTAL);
132 132 }
133 133
134 134 /**
135 135 * Creates a new tool bar with a specified <code>name</code> and
136 136 * <code>orientation</code>.
137 137 * All other constructors call this constructor.
138 138 * If <code>orientation</code> is an invalid value, an exception will
139 139 * be thrown.
140 140 *
141 141 * @param name the name of the tool bar
142 142 * @param orientation the initial orientation -- it must be
143 143 * either <code>HORIZONTAL</code> or <code>VERTICAL</code>
144 144 * @exception IllegalArgumentException if orientation is neither
145 145 * <code>HORIZONTAL</code> nor <code>VERTICAL</code>
146 146 * @since 1.3
147 147 */
148 148 public JToolBar( String name , int orientation) {
149 149 setName(name);
150 150 checkOrientation( orientation );
151 151
152 152 this.orientation = orientation;
153 153 DefaultToolBarLayout layout = new DefaultToolBarLayout( orientation );
154 154 setLayout( layout );
155 155
156 156 addPropertyChangeListener( layout );
157 157
158 158 updateUI();
159 159 }
160 160
161 161 /**
162 162 * Returns the tool bar's current UI.
163 163 * @see #setUI
164 164 */
165 165 public ToolBarUI getUI() {
166 166 return (ToolBarUI)ui;
167 167 }
168 168
169 169 /**
170 170 * Sets the L&F object that renders this component.
171 171 *
172 172 * @param ui the <code>ToolBarUI</code> L&F object
173 173 * @see UIDefaults#getUI
174 174 * @beaninfo
175 175 * bound: true
176 176 * hidden: true
177 177 * attribute: visualUpdate true
178 178 * description: The UI object that implements the Component's LookAndFeel.
179 179 */
180 180 public void setUI(ToolBarUI ui) {
181 181 super.setUI(ui);
182 182 }
183 183
184 184 /**
185 185 * Notification from the <code>UIFactory</code> that the L&F has changed.
186 186 * Called to replace the UI with the latest version from the
187 187 * <code>UIFactory</code>.
188 188 *
189 189 * @see JComponent#updateUI
190 190 */
191 191 public void updateUI() {
192 192 setUI((ToolBarUI)UIManager.getUI(this));
193 193 // GTKLookAndFeel installs a different LayoutManager, and sets it
194 194 // to null after changing the look and feel, so, install the default
195 195 // if the LayoutManager is null.
196 196 if (getLayout() == null) {
197 197 setLayout(new DefaultToolBarLayout(getOrientation()));
198 198 }
199 199 invalidate();
200 200 }
201 201
202 202
203 203
204 204 /**
205 205 * Returns the name of the L&F class that renders this component.
206 206 *
207 207 * @return the string "ToolBarUI"
208 208 * @see JComponent#getUIClassID
209 209 * @see UIDefaults#getUI
210 210 */
211 211 public String getUIClassID() {
212 212 return uiClassID;
213 213 }
214 214
215 215
216 216 /**
217 217 * Returns the index of the specified component.
218 218 * (Note: Separators occupy index positions.)
219 219 *
220 220 * @param c the <code>Component</code> to find
221 221 * @return an integer indicating the component's position,
222 222 * where 0 is first
223 223 */
224 224 public int getComponentIndex(Component c) {
225 225 int ncomponents = this.getComponentCount();
226 226 Component[] component = this.getComponents();
227 227 for (int i = 0 ; i < ncomponents ; i++) {
228 228 Component comp = component[i];
229 229 if (comp == c)
230 230 return i;
231 231 }
232 232 return -1;
233 233 }
234 234
235 235 /**
236 236 * Returns the component at the specified index.
237 237 *
238 238 * @param i the component's position, where 0 is first
239 239 * @return the <code>Component</code> at that position,
240 240 * or <code>null</code> for an invalid index
241 241 *
242 242 */
243 243 public Component getComponentAtIndex(int i) {
244 244 int ncomponents = this.getComponentCount();
245 245 if ( i >= 0 && i < ncomponents) {
246 246 Component[] component = this.getComponents();
247 247 return component[i];
248 248 }
249 249 return null;
250 250 }
251 251
252 252 /**
253 253 * Sets the margin between the tool bar's border and
254 254 * its buttons. Setting to <code>null</code> causes the tool bar to
255 255 * use the default margins. The tool bar's default <code>Border</code>
256 256 * object uses this value to create the proper margin.
257 257 * However, if a non-default border is set on the tool bar,
258 258 * it is that <code>Border</code> object's responsibility to create the
259 259 * appropriate margin space (otherwise this property will
260 260 * effectively be ignored).
261 261 *
262 262 * @param m an <code>Insets</code> object that defines the space
263 263 * between the border and the buttons
264 264 * @see Insets
265 265 * @beaninfo
266 266 * description: The margin between the tool bar's border and contents
267 267 * bound: true
268 268 * expert: true
269 269 */
270 270 public void setMargin(Insets m)
271 271 {
272 272 Insets old = margin;
273 273 margin = m;
274 274 firePropertyChange("margin", old, m);
275 275 revalidate();
276 276 repaint();
277 277 }
278 278
279 279 /**
280 280 * Returns the margin between the tool bar's border and
281 281 * its buttons.
282 282 *
283 283 * @return an <code>Insets</code> object containing the margin values
284 284 * @see Insets
285 285 */
286 286 public Insets getMargin()
287 287 {
288 288 if(margin == null) {
289 289 return new Insets(0,0,0,0);
290 290 } else {
291 291 return margin;
292 292 }
293 293 }
294 294
295 295 /**
296 296 * Gets the <code>borderPainted</code> property.
297 297 *
298 298 * @return the value of the <code>borderPainted</code> property
299 299 * @see #setBorderPainted
300 300 */
301 301 public boolean isBorderPainted()
302 302 {
303 303 return paintBorder;
304 304 }
305 305
306 306
307 307 /**
308 308 * Sets the <code>borderPainted</code> property, which is
309 309 * <code>true</code> if the border should be painted.
310 310 * The default value for this property is <code>true</code>.
311 311 * Some look and feels might not implement painted borders;
312 312 * they will ignore this property.
313 313 *
314 314 * @param b if true, the border is painted
315 315 * @see #isBorderPainted
316 316 * @beaninfo
317 317 * description: Does the tool bar paint its borders?
318 318 * bound: true
319 319 * expert: true
320 320 */
321 321 public void setBorderPainted(boolean b)
322 322 {
323 323 if ( paintBorder != b )
324 324 {
325 325 boolean old = paintBorder;
326 326 paintBorder = b;
327 327 firePropertyChange("borderPainted", old, b);
328 328 revalidate();
329 329 repaint();
330 330 }
331 331 }
332 332
333 333 /**
334 334 * Paints the tool bar's border if the <code>borderPainted</code> property
335 335 * is <code>true</code>.
336 336 *
337 337 * @param g the <code>Graphics</code> context in which the painting
338 338 * is done
339 339 * @see JComponent#paint
340 340 * @see JComponent#setBorder
341 341 */
342 342 protected void paintBorder(Graphics g)
343 343 {
344 344 if (isBorderPainted())
345 345 {
346 346 super.paintBorder(g);
347 347 }
348 348 }
349 349
350 350 /**
351 351 * Gets the <code>floatable</code> property.
352 352 *
353 353 * @return the value of the <code>floatable</code> property
354 354 *
355 355 * @see #setFloatable
356 356 */
357 357 public boolean isFloatable()
358 358 {
359 359 return floatable;
360 360 }
361 361
362 362 /**
363 363 * Sets the <code>floatable</code> property,
364 364 * which must be <code>true</code> for the user to move the tool bar.
365 365 * Typically, a floatable tool bar can be
366 366 * dragged into a different position within the same container
367 367 * or out into its own window.
368 368 * The default value of this property is <code>true</code>.
369 369 * Some look and feels might not implement floatable tool bars;
370 370 * they will ignore this property.
371 371 *
372 372 * @param b if <code>true</code>, the tool bar can be moved;
373 373 * <code>false</code> otherwise
374 374 * @see #isFloatable
375 375 * @beaninfo
376 376 * description: Can the tool bar be made to float by the user?
377 377 * bound: true
378 378 * preferred: true
379 379 */
380 380 public void setFloatable( boolean b )
381 381 {
382 382 if ( floatable != b )
383 383 {
384 384 boolean old = floatable;
385 385 floatable = b;
386 386
387 387 firePropertyChange("floatable", old, b);
388 388 revalidate();
389 389 repaint();
390 390 }
391 391 }
392 392
393 393 /**
394 394 * Returns the current orientation of the tool bar. The value is either
395 395 * <code>HORIZONTAL</code> or <code>VERTICAL</code>.
396 396 *
397 397 * @return an integer representing the current orientation -- either
398 398 * <code>HORIZONTAL</code> or <code>VERTICAL</code>
399 399 * @see #setOrientation
400 400 */
401 401 public int getOrientation()
402 402 {
403 403 return this.orientation;
404 404 }
405 405
406 406 /**
407 407 * Sets the orientation of the tool bar. The orientation must have
408 408 * either the value <code>HORIZONTAL</code> or <code>VERTICAL</code>.
409 409 * If <code>orientation</code> is
410 410 * an invalid value, an exception will be thrown.
411 411 *
412 412 * @param o the new orientation -- either <code>HORIZONTAL</code> or
413 413 * <code>VERTICAL</code>
414 414 * @exception IllegalArgumentException if orientation is neither
415 415 * <code>HORIZONTAL</code> nor <code>VERTICAL</code>
416 416 * @see #getOrientation
417 417 * @beaninfo
418 418 * description: The current orientation of the tool bar
419 419 * bound: true
420 420 * preferred: true
421 421 * enum: HORIZONTAL SwingConstants.HORIZONTAL
422 422 * VERTICAL SwingConstants.VERTICAL
423 423 */
424 424 public void setOrientation( int o )
425 425 {
426 426 checkOrientation( o );
427 427
428 428 if ( orientation != o )
429 429 {
430 430 int old = orientation;
431 431 orientation = o;
432 432
433 433 firePropertyChange("orientation", old, o);
434 434 revalidate();
435 435 repaint();
436 436 }
437 437 }
438 438
439 439 /**
440 440 * Sets the rollover state of this toolbar. If the rollover state is true
441 441 * then the border of the toolbar buttons will be drawn only when the
442 442 * mouse pointer hovers over them. The default value of this property
443 443 * is false.
444 444 * <p>
445 445 * The implementation of a look and feel may choose to ignore this
446 446 * property.
447 447 *
448 448 * @param rollover true for rollover toolbar buttons; otherwise false
449 449 * @since 1.4
450 450 * @beaninfo
451 451 * bound: true
452 452 * preferred: true
453 453 * attribute: visualUpdate true
454 454 * description: Will draw rollover button borders in the toolbar.
455 455 */
456 456 public void setRollover(boolean rollover) {
457 457 putClientProperty("JToolBar.isRollover",
458 458 rollover ? Boolean.TRUE : Boolean.FALSE);
459 459 }
460 460
461 461 /**
462 462 * Returns the rollover state.
463 463 *
464 464 * @return true if rollover toolbar buttons are to be drawn; otherwise false
465 465 * @see #setRollover(boolean)
466 466 * @since 1.4
467 467 */
468 468 public boolean isRollover() {
469 469 Boolean rollover = (Boolean)getClientProperty("JToolBar.isRollover");
470 470 if (rollover != null) {
471 471 return rollover.booleanValue();
472 472 }
473 473 return false;
474 474 }
475 475
476 476 private void checkOrientation( int orientation )
477 477 {
478 478 switch ( orientation )
479 479 {
480 480 case VERTICAL:
481 481 case HORIZONTAL:
482 482 break;
483 483 default:
484 484 throw new IllegalArgumentException( "orientation must be one of: VERTICAL, HORIZONTAL" );
485 485 }
486 486 }
487 487
488 488 /**
489 489 * Appends a separator of default size to the end of the tool bar.
490 490 * The default size is determined by the current look and feel.
491 491 */
492 492 public void addSeparator()
493 493 {
494 494 addSeparator(null);
495 495 }
496 496
497 497 /**
498 498 * Appends a separator of a specified size to the end
499 499 * of the tool bar.
500 500 *
501 501 * @param size the <code>Dimension</code> of the separator
502 502 */
503 503 public void addSeparator( Dimension size )
504 504 {
505 505 JToolBar.Separator s = new JToolBar.Separator( size );
506 506 add(s);
507 507 }
508 508
509 509 /**
510 510 * Adds a new <code>JButton</code> which dispatches the action.
511 511 *
512 512 * @param a the <code>Action</code> object to add as a new menu item
513 513 * @return the new button which dispatches the action
514 514 */
515 515 public JButton add(Action a) {
516 516 JButton b = createActionComponent(a);
517 517 b.setAction(a);
518 518 add(b);
519 519 return b;
520 520 }
521 521
522 522 /**
523 523 * Factory method which creates the <code>JButton</code> for
524 524 * <code>Action</code>s added to the <code>JToolBar</code>.
525 525 * The default name is empty if a <code>null</code> action is passed.
526 526 *
527 527 * @param a the <code>Action</code> for the button to be added
528 528 * @return the newly created button
529 529 * @see Action
530 530 * @since 1.3
531 531 */
532 532 protected JButton createActionComponent(Action a) {
533 533 JButton b = new JButton() {
534 534 protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
535 535 PropertyChangeListener pcl = createActionChangeListener(this);
536 536 if (pcl==null) {
537 537 pcl = super.createActionPropertyChangeListener(a);
538 538 }
539 539 return pcl;
540 540 }
541 541 };
542 542 if (a != null && (a.getValue(Action.SMALL_ICON) != null ||
543 543 a.getValue(Action.LARGE_ICON_KEY) != null)) {
544 544 b.setHideActionText(true);
545 545 }
546 546 b.setHorizontalTextPosition(JButton.CENTER);
547 547 b.setVerticalTextPosition(JButton.BOTTOM);
548 548 return b;
549 549 }
550 550
551 551 /**
552 552 * Returns a properly configured <code>PropertyChangeListener</code>
553 553 * which updates the control as changes to the <code>Action</code> occur,
554 554 * or <code>null</code> if the default
555 555 * property change listener for the control is desired.
556 556 *
557 557 * @return <code>null</code>
558 558 */
559 559 protected PropertyChangeListener createActionChangeListener(JButton b) {
560 560 return null;
561 561 }
562 562
563 563 /**
564 564 * If a <code>JButton</code> is being added, it is initially
565 565 * set to be disabled.
566 566 *
567 567 * @param comp the component to be enhanced
568 568 * @param constraints the constraints to be enforced on the component
569 569 * @param index the index of the component
570 570 *
571 571 */
572 572 protected void addImpl(Component comp, Object constraints, int index) {
573 573 if (comp instanceof Separator) {
574 574 if (getOrientation() == VERTICAL) {
575 575 ( (Separator)comp ).setOrientation(JSeparator.HORIZONTAL);
576 576 } else {
577 577 ( (Separator)comp ).setOrientation(JSeparator.VERTICAL);
578 578 }
579 579 }
580 580 super.addImpl(comp, constraints, index);
581 581 if (comp instanceof JButton) {
582 582 ((JButton)comp).setDefaultCapable(false);
583 583 }
584 584 }
585 585
586 586
587 587 /**
588 588 * A toolbar-specific separator. An object with dimension but
589 589 * no contents used to divide buttons on a tool bar into groups.
590 590 */
591 591 static public class Separator extends JSeparator
592 592 {
593 593 private Dimension separatorSize;
594 594
595 595 /**
596 596 * Creates a new toolbar separator with the default size
597 597 * as defined by the current look and feel.
598 598 */
599 599 public Separator()
600 600 {
601 601 this( null ); // let the UI define the default size
602 602 }
603 603
604 604 /**
605 605 * Creates a new toolbar separator with the specified size.
606 606 *
607 607 * @param size the <code>Dimension</code> of the separator
608 608 */
609 609 public Separator( Dimension size )
610 610 {
611 611 super( JSeparator.HORIZONTAL );
612 612 setSeparatorSize(size);
613 613 }
614 614
615 615 /**
616 616 * Returns the name of the L&F class that renders this component.
617 617 *
618 618 * @return the string "ToolBarSeparatorUI"
619 619 * @see JComponent#getUIClassID
620 620 * @see UIDefaults#getUI
621 621 */
622 622 public String getUIClassID()
623 623 {
624 624 return "ToolBarSeparatorUI";
625 625 }
626 626
627 627 /**
628 628 * Sets the size of the separator.
629 629 *
630 630 * @param size the new <code>Dimension</code> of the separator
631 631 */
632 632 public void setSeparatorSize( Dimension size )
633 633 {
634 634 if (size != null) {
635 635 separatorSize = size;
636 636 } else {
637 637 super.updateUI();
638 638 }
639 639 this.invalidate();
640 640 }
641 641
642 642 /**
643 643 * Returns the size of the separator
644 644 *
645 645 * @return the <code>Dimension</code> object containing the separator's
646 646 * size (This is a reference, NOT a copy!)
647 647 */
648 648 public Dimension getSeparatorSize()
649 649 {
650 650 return separatorSize;
651 651 }
652 652
653 653 /**
654 654 * Returns the minimum size for the separator.
655 655 *
656 656 * @return the <code>Dimension</code> object containing the separator's
657 657 * minimum size
658 658 */
659 659 public Dimension getMinimumSize()
660 660 {
661 661 if (separatorSize != null) {
662 662 return separatorSize.getSize();
663 663 } else {
664 664 return super.getMinimumSize();
665 665 }
666 666 }
667 667
668 668 /**
669 669 * Returns the maximum size for the separator.
670 670 *
671 671 * @return the <code>Dimension</code> object containing the separator's
672 672 * maximum size
673 673 */
674 674 public Dimension getMaximumSize()
675 675 {
676 676 if (separatorSize != null) {
677 677 return separatorSize.getSize();
678 678 } else {
679 679 return super.getMaximumSize();
680 680 }
681 681 }
682 682
683 683 /**
684 684 * Returns the preferred size for the separator.
685 685 *
686 686 * @return the <code>Dimension</code> object containing the separator's
687 687 * preferred size
688 688 */
689 689 public Dimension getPreferredSize()
690 690 {
691 691 if (separatorSize != null) {
692 692 return separatorSize.getSize();
693 693 } else {
694 694 return super.getPreferredSize();
695 695 }
696 696 }
697 697 }
698 698
699 699
700 700 /**
701 701 * See <code>readObject</code> and <code>writeObject</code> in
702 702 * <code>JComponent</code> for more
703 703 * information about serialization in Swing.
704 704 */
705 705 private void writeObject(ObjectOutputStream s) throws IOException {
706 706 s.defaultWriteObject();
707 707 if (getUIClassID().equals(uiClassID)) {
708 708 byte count = JComponent.getWriteObjCounter(this);
709 709 JComponent.setWriteObjCounter(this, --count);
710 710 if (count == 0 && ui != null) {
711 711 ui.installUI(this);
712 712 }
713 713 }
714 714 }
715 715
716 716
717 717 /**
718 718 * Returns a string representation of this <code>JToolBar</code>.
719 719 * This method
720 720 * is intended to be used only for debugging purposes, and the
721 721 * content and format of the returned string may vary between
722 722 * implementations. The returned string may be empty but may not
723 723 * be <code>null</code>.
724 724 *
725 725 * @return a string representation of this <code>JToolBar</code>.
726 726 */
727 727 protected String paramString() {
728 728 String paintBorderString = (paintBorder ?
729 729 "true" : "false");
730 730 String marginString = (margin != null ?
731 731 margin.toString() : "");
732 732 String floatableString = (floatable ?
733 733 "true" : "false");
734 734 String orientationString = (orientation == HORIZONTAL ?
735 735 "HORIZONTAL" : "VERTICAL");
736 736
737 737 return super.paramString() +
738 738 ",floatable=" + floatableString +
739 739 ",margin=" + marginString +
740 740 ",orientation=" + orientationString +
741 741 ",paintBorder=" + paintBorderString;
742 742 }
743 743
744 744
745 745 private class DefaultToolBarLayout
746 746 implements LayoutManager2, Serializable, PropertyChangeListener, UIResource {
747 747
748 748 BoxLayout lm;
749 749
750 750 DefaultToolBarLayout(int orientation) {
751 751 if (orientation == JToolBar.VERTICAL) {
752 752 lm = new BoxLayout(JToolBar.this, BoxLayout.PAGE_AXIS);
753 753 } else {
754 754 lm = new BoxLayout(JToolBar.this, BoxLayout.LINE_AXIS);
755 755 }
756 756 }
757 757
758 758 public void addLayoutComponent(String name, Component comp) {
759 759 lm.addLayoutComponent(name, comp);
760 760 }
761 761
762 762 public void addLayoutComponent(Component comp, Object constraints) {
763 763 lm.addLayoutComponent(comp, constraints);
764 764 }
765 765
766 766 public void removeLayoutComponent(Component comp) {
767 767 lm.removeLayoutComponent(comp);
768 768 }
769 769
770 770 public Dimension preferredLayoutSize(Container target) {
771 771 return lm.preferredLayoutSize(target);
772 772 }
773 773
774 774 public Dimension minimumLayoutSize(Container target) {
775 775 return lm.minimumLayoutSize(target);
776 776 }
777 777
778 778 public Dimension maximumLayoutSize(Container target) {
779 779 return lm.maximumLayoutSize(target);
780 780 }
781 781
782 782 public void layoutContainer(Container target) {
783 783 lm.layoutContainer(target);
784 784 }
785 785
786 786 public float getLayoutAlignmentX(Container target) {
787 787 return lm.getLayoutAlignmentX(target);
788 788 }
789 789
790 790 public float getLayoutAlignmentY(Container target) {
791 791 return lm.getLayoutAlignmentY(target);
792 792 }
793 793
794 794 public void invalidateLayout(Container target) {
795 795 lm.invalidateLayout(target);
796 796 }
797 797
798 798 public void propertyChange(PropertyChangeEvent e) {
799 799 String name = e.getPropertyName();
800 800 if( name.equals("orientation") ) {
801 801 int o = ((Integer)e.getNewValue()).intValue();
802 802
803 803 if (o == JToolBar.VERTICAL)
804 804 lm = new BoxLayout(JToolBar.this, BoxLayout.PAGE_AXIS);
805 805 else {
806 806 lm = new BoxLayout(JToolBar.this, BoxLayout.LINE_AXIS);
807 807 }
808 808 }
809 809 }
810 810 }
811 811
812 812
813 813 public void setLayout(LayoutManager mgr) {
814 814 LayoutManager oldMgr = getLayout();
815 815 if (oldMgr instanceof PropertyChangeListener) {
816 816 removePropertyChangeListener((PropertyChangeListener)oldMgr);
817 817 }
818 818 super.setLayout(mgr);
819 819 }
820 820
821 821 /////////////////
822 822 // Accessibility support
823 823 ////////////////
824 824
825 825 /**
826 826 * Gets the AccessibleContext associated with this JToolBar.
827 827 * For tool bars, the AccessibleContext takes the form of an
828 828 * AccessibleJToolBar.
829 829 * A new AccessibleJToolBar instance is created if necessary.
830 830 *
831 831 * @return an AccessibleJToolBar that serves as the
832 832 * AccessibleContext of this JToolBar
833 833 */
834 834 public AccessibleContext getAccessibleContext() {
835 835 if (accessibleContext == null) {
836 836 accessibleContext = new AccessibleJToolBar();
837 837 }
838 838 return accessibleContext;
839 839 }
840 840
841 841 /**
842 842 * This class implements accessibility support for the
843 843 * <code>JToolBar</code> class. It provides an implementation of the
844 844 * Java Accessibility API appropriate to toolbar user-interface elements.
845 845 */
846 846 protected class AccessibleJToolBar extends AccessibleJComponent {
847 847
848 848 /**
849 849 * Get the state of this object.
850 850 *
851 851 * @return an instance of AccessibleStateSet containing the current
852 852 * state set of the object
853 853 * @see AccessibleState
854 854 */
855 855 public AccessibleStateSet getAccessibleStateSet() {
856 856 AccessibleStateSet states = super.getAccessibleStateSet();
857 857 // FIXME: [[[WDW - need to add orientation from BoxLayout]]]
858 858 // FIXME: [[[WDW - need to do SELECTABLE if SelectionModel is added]]]
859 859 return states;
860 860 }
861 861
862 862 /**
863 863 * Get the role of this object.
864 864 *
865 865 * @return an instance of AccessibleRole describing the role of the object
866 866 */
867 867 public AccessibleRole getAccessibleRole() {
868 868 return AccessibleRole.TOOL_BAR;
869 869 }
870 870 } // inner class AccessibleJToolBar
871 871 }
↓ open down ↓ |
806 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX