summaryrefslogtreecommitdiffstats
path: root/src/cppcheckplus/menu/MyMenu.java
blob: 73cf5ab1727207b66a2cf0c95bf1d3a48ce28372 (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
60
61
62
63
64
65
package cppcheckplus.menu;

import cppcheckplus.control.MyContorlUtil;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.BorderFactory;
import javax.swing.JMenu;
import javax.swing.border.Border;


public class MyMenu extends JMenu {
    private Color backgroundColor;
    private Color foregroundColor;
    private int borderThickness;
    private Border border;
    private int preferredHeight;

    public MyMenu() {
        backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND;
        foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR;
        borderThickness = 1;
        border =
            BorderFactory.createLineBorder(backgroundColor, borderThickness);
        preferredHeight = 25;
        init();
    }

    public MyMenu(String text) {
        super(text);
        backgroundColor = MyContorlUtil.MENUITEM_BACKGROUND;
        foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR;
        borderThickness = 1;
        border =
            BorderFactory.createLineBorder(backgroundColor, borderThickness);
        preferredHeight = 25;
        init();
    }

    private void init() {
        setForeground(foregroundColor);
        setFont(MyContorlUtil.FONT_14_BOLD);
        setOpaque(true);
        setBackground(backgroundColor);
        setBorder(border);
    }

    @Override
    protected void paintComponent(Graphics g) {
        if (isSelected()) {
            Graphics2D g2d = (Graphics2D) g;
            g2d.setColor(MyContorlUtil.MENUITEM_SELECTED_BACKGROUND);
            g2d.fillRect(0, 0, getWidth(), getHeight());
            super.paintComponent(g);
        } else {
            super.paintComponent(g);
        }
    }

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