summaryrefslogtreecommitdiffstats
path: root/src/cppcheckplus/toolbar/MyToolBar.java
blob: 26f14d2428a8cb0ac4ee5f6adc39f7ef113d4b8f (plain) (blame)
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
package cppcheckplus.toolbar;

import cppcheckplus.control.MyContorlUtil;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.TexturePaint;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JPanel;


public class MyToolBar extends JPanel {
    private String backgroundImageURL;
    private int preferredHeight;
    private TexturePaint paint;
    private int buttonGap;

    public MyToolBar() {
        preferredHeight =
            MyContorlUtil.getImageIcon("control/images/toolbar_background.png")
                .getIconHeight();
        paint = MyContorlUtil.createTexturePaint(
            "control/images/toolbar_background.png");
        buttonGap = 2;
        init();
    }

    private void init() {
        setLayout(new FlowLayout(3, buttonGap, 0));
        setBorder(BorderFactory.createEmptyBorder(2, 5, 0, 5));
    }

    public void addButton(Icon icon, String tooltip, String actionCommand,
                          boolean rover) {
        MyToolBarButton barButton;
        if (rover) {
            barButton = new MyToolBarRoverButton();
        } else {
            barButton = new MyToolBarButton();
        }
        barButton.setIcon(icon);
        barButton.setToolTipText(tooltip);
        barButton.setActionCommand(actionCommand);
        add(barButton);
    }

    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.setPaint(paint);
        g2d.fillRect(0, 0, getWidth(), getHeight());
    }

    public Dimension getPreferredSize() {
        return new Dimension(super.getPreferredSize().width, preferredHeight);
    }
}