summaryrefslogtreecommitdiffstats
path: root/src/cppcheckplus/menu/MyRootMenu.java
blob: b5d442de1e5514cfd378e9a592e78be0ff16e2d8 (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


package cppcheckplus.menu;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.TexturePaint;

import javax.swing.BorderFactory;
import javax.swing.JMenu;
import javax.swing.border.Border;

import cppcheckplus.control.MyContorlUtil;


public class MyRootMenu extends JMenu
{
	private Color foregroundColor;
	private String selectedBackgroundImageURL;
	private TexturePaint paint;
	private Border border;
	
	public MyRootMenu()
	{
		foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR;
		paint = MyContorlUtil.createTexturePaint("control/images/menubar_background_selected.png");
		border = BorderFactory.createEmptyBorder(0, 5, 0, 4);
		init();
		
	}

	public MyRootMenu(String text)
	{
		super(text);
		foregroundColor = MyContorlUtil.DEFAULT_TEXT_COLOR;
		paint = MyContorlUtil.createTexturePaint("control/images/menubar_background_selected.png");
		border = BorderFactory.createEmptyBorder(0, 5, 0, 4);
		init();
	}

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

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