-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileMenu.java
More file actions
84 lines (76 loc) · 2.97 KB
/
Copy pathFileMenu.java
File metadata and controls
84 lines (76 loc) · 2.97 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
//henry bogardus
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
import java.awt.Toolkit;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FileMenu extends JMenu
{
PaintMainWindow mMainWindow;
public FileMenu(PaintMainWindow mainWindow)
{
super("File");
mMainWindow = mainWindow;
JMenu fileMenu = new JMenu("File");
JMenuItem newMenuItem = new JMenuItem("New");
add(newMenuItem);
newMenuItem.setMnemonic(KeyEvent.VK_N);
newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
class NewMenuOptionListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
newWindow();
}
}
newMenuItem.addActionListener(new NewMenuOptionListener());
JMenuItem openMenuItem = new JMenuItem("Open");
add(openMenuItem);
openMenuItem.setMnemonic(KeyEvent.VK_O);
openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
class OpenMenuOptionListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
mMainWindow.getShapeManager().loadFromFile();
}
}
openMenuItem.addActionListener(new OpenMenuOptionListener());
addSeparator();
JMenuItem saveMenuItem = new JMenuItem("Save");
add(saveMenuItem);
saveMenuItem.setMnemonic(KeyEvent.VK_S);
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
class SaveMenuOptionListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
mMainWindow.getShapeManager().saveToFile();
}
}
saveMenuItem.addActionListener(new SaveMenuOptionListener());
}
public void newWindow()
{
Object[] options = {"OK", "Back To Paint", "Save"};
int option = JOptionPane.showOptionDialog(null, "Are you sure you want to open\na new window without saving?",
"New Window Options", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
if (option == 0)
{
PaintMainWindow mainWindow = new PaintMainWindow();
mainWindow.go();
}
else if (option == 2)
{
mMainWindow.getShapeManager().saveToFile();
PaintMainWindow mainWindow = new PaintMainWindow();
mainWindow.go();
}
}
}