-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathPaneMenu.java
More file actions
130 lines (110 loc) · 3.62 KB
/
PaneMenu.java
File metadata and controls
130 lines (110 loc) · 3.62 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package nodebox.client;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.EventListenerList;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
public class PaneMenu extends JComponent implements MouseListener {
private static Image paneMenuLeft, paneMenuBackground, paneMenuRight;
static {
try {
paneMenuLeft = ImageIO.read(new File("res/pane-menu-left.png"));
paneMenuBackground = ImageIO.read(new File("res/pane-menu-background.png"));
paneMenuRight = ImageIO.read(new File("res/pane-menu-right.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* The list of event listeners for this component.
*/
protected EventListenerList listenerList = new EventListenerList();
public PaneMenu() {
Dimension d = new Dimension(103, 21);
setMinimumSize(d);
setMaximumSize(d);
setPreferredSize(d);
setEnabled(true);
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (enabled) {
addMouseListener(this);
} else {
removeMouseListener(this);
}
repaint();
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
// Full width minus left side and right side
int contentWidth = getWidth() - 9 - 21;
if (isEnabled()) {
g.drawImage(paneMenuLeft, 0, 0, null);
g.drawImage(paneMenuBackground, 9, 0, contentWidth, 21, null);
g.drawImage(paneMenuRight, 9 + contentWidth, 0, null);
}
g2.setFont(Theme.SMALL_BOLD_FONT);
g2.setColor(Theme.TEXT_NORMAL_COLOR);
int textPosition = isEnabled() ? 9 : 5;
SwingUtils.drawShadowText(g2, getMenuName(), textPosition, 14);
}
public String getMenuName() {
return "";
}
public void mouseClicked(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
/**
* Adds a ChangeListener to the slider.
*
* @param l the ChangeListener to add
* @see #fireActionEvent
* @see #removeActionListener
*/
public void addActionListener(ActionListener l) {
listenerList.add(ActionListener.class, l);
}
/**
* Removes a ChangeListener from the slider.
*
* @param l the ChangeListener to remove
* @see #fireActionEvent
* @see #addActionListener
*/
public void removeActionListener(ActionListener l) {
listenerList.remove(ActionListener.class, l);
}
/**
* Send a ChangeEvent, whose source is this Slider, to
* each listener. This method method is called each time
* a ChangeEvent is received from the model.
*
* @param menuKey The menu item key that was selected.
* @see #addActionListener
* @see javax.swing.event.EventListenerList
*/
protected void fireActionEvent(String menuKey) {
ActionEvent actionEvent = new ActionEvent(this, 0, menuKey);
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ActionListener.class) {
((ActionListener) listeners[i + 1]).actionPerformed(actionEvent);
}
}
}
}