KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > swing > Toolbar


1 package org.antlr.works.swing;
2
3 import javax.swing.*;
4 import java.awt.*;
5
6 /**
7  * @author Copyright (c) 2007 by BEA Systems, Inc. All Rights Reserved.
8  */

9 public class Toolbar extends Box {
10
11     private boolean horizontal;
12
13     public static Toolbar createHorizontalToolbar() {
14         return new Toolbar(BoxLayout.X_AXIS);
15     }
16
17     public static Toolbar createVerticalToolbar() {
18         return new Toolbar(BoxLayout.Y_AXIS);
19     }
20
21     public Toolbar(int axis) {
22         super(axis);
23         horizontal = axis == BoxLayout.X_AXIS;
24         setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
25     }
26
27     public Component addElement(Component c) {
28         if(getComponentCount() > 0) {
29             if(horizontal) {
30                 add(Box.createHorizontalStrut(getOffset()));
31             } else {
32                 add(Box.createVerticalStrut(getOffset()));
33             }
34         }
35         return add(c);
36     }
37
38     public void addGroupSeparator() {
39         if(horizontal) {
40             add(Box.createHorizontalStrut(getGroupOffset()));
41         } else {
42             add(Box.createVerticalStrut(getGroupOffset()));
43         }
44     }
45
46     private int getOffset() {
47         return 2;
48     }
49
50     private int getGroupOffset() {
51         return 12;
52     }
53 }
54
Popular Tags