File: ToolBar.java

package info (click to toggle)
libtoolbar-java 1.3-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 240 kB
  • ctags: 413
  • sloc: java: 2,284; xml: 64; makefile: 10
file content (73 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * ToolBar.java
 *
 * Created on 29 September 2002, 21:01
 */

package org.tigris.toolbar;

import java.awt.Insets;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JToolBar;
import org.tigris.toolbar.toolbutton.ModalButton;

/**
 * A toolbar class which assumes rollover effects and automatically gives tooltip
 * to any buttons created by adding an action.
 *
 * @author  Bob Tarling
 */
public class ToolBar extends JToolBar {
    
    String javaVersion;

    /** Creates a new instance of an un-named horizontal ToolBar
     */
    public ToolBar() {
        this("");
    }
    
    /** Creates a new instance of a horizontal ToolBar with the given name
     * @param name the title to display while floating
     */
    public ToolBar(String name) {
        this(name, HORIZONTAL);
    }
    
    /** Creates a new instance of ToolBar with the given name and orientation
     * @param name the title to display while floating
     * @param orientation HORIZONTAL or VERTICAL
     */
    public ToolBar(String name, int orientation) {
        super(name, orientation);
        javaVersion = System.getProperties().getProperty("java.specification.version");
        this.setMargin(new Insets(0,0,0,0));
    }
    
    /** Creates a new instance of an un-named ToolBar with the given orientation
     * @param orientation HORIZONTAL or VERTICAL
     */
    public ToolBar(int orientation) {
        this("", orientation);
    }

    /**
     * Add a new button to the toolbar with properties based on
     * the given action and triggering the given action.
     * @param action the action from which to create the button
     * @return the resulting <code>JButton</code> class
     */
    public JButton add(Action action) {
        JButton button = new ModalButton(action);
        add(button);
        if (!ToolBarManager.alwaysUseStandardRollover()) {
            button.setBorderPainted(false);
        }
        if (javaVersion.equals("1.3")) {
            // This is needed specifically for JDK1.3 on Windows & Motif
            button.setMargin(new Insets(0,0,0,0));
        }
        return button;
    }
}