KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > toolbar > ExtendableToolBar


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.gui.toolbar;
17
18 import java.awt.FlowLayout JavaDoc;
19
20 import javax.swing.JButton JavaDoc;
21 import javax.swing.JSeparator JavaDoc;
22 import javax.swing.JToolBar JavaDoc;
23
24 import org.columba.core.gui.action.AbstractColumbaAction;
25
26 /**
27  * Extendable toolbar.
28  *
29  * @author fdietz
30  */

31
32 public class ExtendableToolBar extends JToolBar JavaDoc {
33
34     int insertPosition = 0;
35
36     public ExtendableToolBar() {
37         super();
38
39         setRollover(true);
40         // setFloatable(true);
41
}
42
43     public void add(AbstractColumbaAction action) {
44         JButton JavaDoc button = ToolBarButtonFactory.createButton(action);
45
46         add(button, insertPosition);
47
48         insertPosition++;
49     }
50
51     public void insert(AbstractColumbaAction action, int position) {
52         JButton JavaDoc button = ToolBarButtonFactory.createButton(action);
53
54         add(button, position);
55
56         if (position >= insertPosition)
57             insertPosition++;
58     }
59
60     /**
61      * @see javax.swing.JToolBar#addSeparator()
62      */

63     public void addSeparator() {
64         JToolBar.Separator JavaDoc s = new JToolBar.Separator JavaDoc(null);
65         if (getOrientation() == VERTICAL) {
66             s.setOrientation(JSeparator.HORIZONTAL);
67         } else {
68             s.setOrientation(JSeparator.VERTICAL);
69         }
70
71         add(s, insertPosition);
72
73         insertPosition++;
74     }
75
76     /**
77      * @see javax.swing.JToolBar#updateUI()
78      */

79     public void updateUI() {
80         super.updateUI();
81         setRollover(true);
82     }
83
84 }
Popular Tags