-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLMToolbar.java
More file actions
executable file
·274 lines (238 loc) · 9.03 KB
/
LMToolbar.java
File metadata and controls
executable file
·274 lines (238 loc) · 9.03 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.*;
/**
* Written by Daniel Barter, Alby Himelick, and Grace Whitmore.
* For CS204 - Software Design
* 4 June 2012
*
* Builds the toolbar which contains buttons for the different tools used to
* build an NFA. Implements ActionListener to handle button presses.
*
* "LM" objects: allow interaction between the toolbar and those parts of
* the GUI
* JButtons: buttons for each tool
* JPanels: panels for each button to cleanly draw a border around the selected
* tool
*/
public class LMToolbar
extends JToolBar
implements ActionListener
{
private LMWorkspacePanel workspacePanel;
private LMInputToolbar inputToolbar;
private LMOptionsPanel optionsPanel;
private LMMessagePanel messagePanel;
private JButton mouseButton;
private JButton stateButton;
private JButton acceptStateButton;
private JButton transitionButton;
private JButton deleteButton;
private JPanel mouseButtonPanel;
private JPanel stateButtonPanel;
private JPanel acceptStateButtonPanel;
private JPanel transitionButtonPanel;
private JPanel deleteButtonPanel;
/**
* Constructor for the toolbar. Calls JToolBar's constructor to set up a
* vertical toolbar. Sets the toolbar to be unable to float and gives it
* a bag layout. Calls buildUI() to fill the toolbar with buttons.
*/
public LMToolbar()
{
super(JToolBar.VERTICAL);
setFloatable(false);
setLayout(new GridBagLayout());
buildUI();
}
/**
* Sets the workspacePanel. Allows the toolbar to interact with this
* part of the GUI.
*
* LMWorkspacePanel workspacePanel: the workspace of the frame
*/
public void setWorkspacePanel(LMWorkspacePanel workspacePanel)
{
this.workspacePanel = workspacePanel;
}
/**
* Sets the inputToolbar. Allows the toolbar to interact with this
* part of the GUI.
*
* LMInputToolbar inputToolbar: the input toolbar of the frame
*/
public void setInputToolbar(LMInputToolbar inputToolbar)
{
this.inputToolbar = inputToolbar;
}
/**
* Sets the optionsPanel. Allows the toolbar to interact with this
* part of the GUI.
*
* LMOptionsPanel optionsPanel: the options panel of the frame
*/
public void setOptionsPanel(LMOptionsPanel optionsPanel)
{
this.optionsPanel = optionsPanel;
}
/**
* Sets the messagePanel. Allows the toolbar to interact with this
* part of the GUI.
*
* LMMessagePanel messagePanel: the message panel of the frame
*/
public void setMessagePanel(LMMessagePanel messagePanel)
{
this.messagePanel = messagePanel;
}
/**
* Gets the panel for containing the button corresponding to the given tool.
* Used to set a border for the panel to highlight the currently selected
* tool. If somehow a bad tool ID is passed, returns the mouseButtonPanel.
*
* int tool: the ID of the tool
*
* Returns the panel of the corresponding tool button.
*/
public JPanel getToolButtonPanel(int tool)
{
if (tool == LMWorkspacePanel.SELECT_TOOL)
{
return mouseButtonPanel;
}
else if (tool == LMWorkspacePanel.STATE_TOOL)
{
return stateButtonPanel;
}
else if (tool == LMWorkspacePanel.ACCEPT_STATE_TOOL)
{
return acceptStateButtonPanel;
}
else if (tool == LMWorkspacePanel.TRANSITION_TOOL_INITIAL ||
tool == LMWorkspacePanel.TRANSITION_TOOL_FINAL)
{
return transitionButtonPanel;
}
else if (tool == LMWorkspacePanel.DELETE_TOOL)
{
return deleteButtonPanel;
}
else
{
return mouseButtonPanel;
}
}
/**
* Called when a button is pressed. Chooses an action based on the button
* pressed. Also clears the various text fields and unselects any selected
* objects in the workspace. Part of the ActionListener implementation.
*
* ActionEvent e: the event generated when a button is clicked
*/
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
inputToolbar.clearAcceptanceText();
messagePanel.clearText();
optionsPanel.changeOptions("blank");
workspacePanel.unselectAll();
workspacePanel.repaint();
if (command.equals("mouse"))
{
workspacePanel.setTool(LMWorkspacePanel.SELECT_TOOL);
}
else if (command.equals("state"))
{
workspacePanel.setTool(LMWorkspacePanel.STATE_TOOL);
}
else if (command.equals("accept state"))
{
workspacePanel.setTool(LMWorkspacePanel.ACCEPT_STATE_TOOL);
}
else if (command.equals("transition"))
{
workspacePanel.setTool(LMWorkspacePanel.TRANSITION_TOOL_INITIAL);
}
else if (command.equals("delete"))
{
workspacePanel.setTool(LMWorkspacePanel.DELETE_TOOL);
}
}
/**
* Creates buttons and their panels and builds the UI.
*/
private void buildUI()
{
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridy = 0;
c.insets = new Insets(3, 3, 3, 3);
mouseButton = new JButton("Select", new ImageIcon("images/select32.png"));
mouseButton.setDisabledIcon(new ImageIcon("images/select32d.png"));
mouseButton.setVerticalTextPosition(AbstractButton.BOTTOM);
mouseButton.setHorizontalTextPosition(AbstractButton.CENTER);
mouseButton.setMnemonic(KeyEvent.VK_E);
mouseButton.setActionCommand("mouse");
mouseButton.addActionListener(this);
mouseButtonPanel = new JPanel(new GridLayout());
mouseButtonPanel.setBorder(new LineBorder(Color.GRAY, 2));
mouseButtonPanel.add(mouseButton);
add(mouseButtonPanel, c);
c.gridy++;
stateButton = new JButton("State", new ImageIcon("images/state32.png"));
stateButton.setDisabledIcon(new ImageIcon("images/state32d.png"));
stateButton.setVerticalTextPosition(AbstractButton.BOTTOM);
stateButton.setHorizontalTextPosition(AbstractButton.CENTER);
stateButton.setMnemonic(KeyEvent.VK_S);
stateButton.setActionCommand("state");
stateButton.addActionListener(this);
stateButtonPanel = new JPanel(new GridLayout());
stateButtonPanel.setBorder(new LineBorder(new Color(237, 237, 237), 2));
stateButtonPanel.add(stateButton);
add(stateButtonPanel, c);
c.gridy++;
acceptStateButton = new JButton("Accept State", new ImageIcon("images/acceptstate32.png"));
acceptStateButton.setDisabledIcon(new ImageIcon("images/state32d.png"));
acceptStateButton.setVerticalTextPosition(AbstractButton.BOTTOM);
acceptStateButton.setHorizontalTextPosition(AbstractButton.CENTER);
acceptStateButton.setMnemonic(KeyEvent.VK_A);
acceptStateButton.setActionCommand("accept state");
acceptStateButton.addActionListener(this);
acceptStateButtonPanel = new JPanel(new GridLayout());
acceptStateButtonPanel.setBorder(new LineBorder(new Color(237, 237, 237), 2));
acceptStateButtonPanel.add(acceptStateButton);
add(acceptStateButtonPanel, c);
c.gridy++;
transitionButton = new JButton("Transition", new ImageIcon("images/transition32.png"));
transitionButton.setDisabledIcon(new ImageIcon("images/transition32d.png"));
transitionButton.setVerticalTextPosition(AbstractButton.BOTTOM);
transitionButton.setHorizontalTextPosition(AbstractButton.CENTER);
transitionButton.setMnemonic(KeyEvent.VK_T);
transitionButton.setActionCommand("transition");
transitionButton.addActionListener(this);
transitionButtonPanel = new JPanel(new GridLayout());
transitionButtonPanel.setBorder(new LineBorder(new Color(237, 237, 237), 2));
transitionButtonPanel.add(transitionButton);
add(transitionButtonPanel, c);
c.gridy++;
deleteButton = new JButton("Delete", new ImageIcon("images/delete32.png"));
deleteButton.setDisabledIcon(new ImageIcon("images/delete32d.png"));
deleteButton.setVerticalTextPosition(AbstractButton.BOTTOM);
deleteButton.setHorizontalTextPosition(AbstractButton.CENTER);
deleteButton.setMnemonic(KeyEvent.VK_D);
deleteButton.setActionCommand("delete");
deleteButton.addActionListener(this);
deleteButtonPanel = new JPanel(new GridLayout());
deleteButtonPanel.setBorder(new LineBorder(new Color(237, 237, 237), 2));
deleteButtonPanel.add(deleteButton);
add(deleteButtonPanel, c);
c.gridy++;
c.weighty = 1;
JLabel blank = new JLabel();
add(blank, c);
}
}