-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathLegupUI.java
More file actions
217 lines (183 loc) · 7.08 KB
/
LegupUI.java
File metadata and controls
217 lines (183 loc) · 7.08 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
package edu.rpi.legup.ui;
import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatLightLaf;
import edu.rpi.legup.app.GameBoardFacade;
import edu.rpi.legup.app.LegupPreferences;
import edu.rpi.legup.ui.boardview.BoardView;
import edu.rpi.legup.ui.color.ColorPreferences;
import edu.rpi.legup.ui.lookandfeel.LegupLookAndFeel;
import edu.rpi.legup.ui.proofeditorui.treeview.TreePanel;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.security.InvalidParameterException;
import java.util.Objects;
import javax.swing.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LegupUI extends JFrame implements WindowListener {
private static final Logger LOGGER = LogManager.getLogger(LegupUI.class.getName());
// protected FileDialog fileDialog;
protected JFileChooser fileChooser;
protected JPanel window;
protected LegupPanel[] panels;
/**
* Identifies operating system
*
* @return operating system, either mac or win
*/
public static String getOS() {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("mac")) {
os = "mac";
} else {
os = "win";
}
return os;
}
/** LegupUI Constructor - creates a new LegupUI to setup the menu and toolbar */
public LegupUI() {
setTitle("LEGUP");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
LegupPreferences prefs = LegupPreferences.getInstance();
try {
final String colorFileName = prefs.getUserPref(LegupPreferences.COLOR_THEME_FILE);
if (colorFileName.endsWith(".txt")) {
UIManager.setLookAndFeel(new LegupLookAndFeel(colorFileName));
}else {
if (Boolean.valueOf(prefs.getUserPref(LegupPreferences.DARK_MODE))) {
UIManager.setLookAndFeel(new LegupLookAndFeel(ColorPreferences.DARK_COLOR_THEME_FILE_NAME));
}
else {
UIManager.setLookAndFeel(new LegupLookAndFeel(ColorPreferences.LIGHT_COLOR_THEME_FILE_NAME));
}
}
} catch (UnsupportedLookAndFeelException e) {
System.err.println("Not supported ui look and feel");
}
// fileDialog = new FileDialog(this);
fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY));
initPanels();
displayPanel(0);
setIconImage(
new ImageIcon(
Objects.requireNonNull(
ClassLoader.getSystemClassLoader()
.getResource(
"edu/rpi/legup/images/Legup/Direct"
+ " Rules.gif")))
.getImage());
if (LegupPreferences.getInstance()
.getUserPref(LegupPreferences.START_FULL_SCREEN)
.equals(Boolean.toString(true))) {
setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
}
this.addWindowListener(this);
addKeyListener(
new KeyAdapter() {
/**
* Invoked when a key has been typed. This event occurs when a key press is
* followed by a key release.
*
* @param e
*/
@Override
public void keyTyped(KeyEvent e) {
System.err.println(e.getKeyChar());
super.keyTyped(e);
}
});
setMinimumSize(getPreferredSize());
setVisible(true);
}
private void initPanels() {
window = new JPanel();
window.setLayout(new BorderLayout());
add(window);
panels = new LegupPanel[3];
panels[0] = new HomePanel(this, this);
panels[1] = new ProofEditorPanel(this.fileChooser, this, this);
panels[2] = new PuzzleEditorPanel(this.fileChooser, this, this);
}
protected void displayPanel(int option) {
if (option > panels.length || option < 0) {
throw new InvalidParameterException("Invalid option");
}
this.window.removeAll();
panels[option].makeVisible();
this.window.add(panels[option]);
pack();
setLocationRelativeTo(null);
revalidate();
repaint();
}
public ProofEditorPanel getProofEditor() {
return (ProofEditorPanel) panels[1];
}
public PuzzleEditorPanel getPuzzleEditor() {
return (PuzzleEditorPanel) panels[2];
}
public void repaintTree() {
getProofEditor().repaintTree();
}
private void directions() {
JOptionPane.showMessageDialog(
null,
"For every move you make, you must provide a rules for it (located in the Rules"
+ " panel).\n"
+ "While working on the edu.rpi.legup.puzzle, you may click on the \"Check\""
+ " button to test your proof for correctness.",
"Directions",
JOptionPane.PLAIN_MESSAGE);
}
public void showStatus(String status, boolean error) {
showStatus(status, error, 1);
}
public void errorEncountered(String error) {
JOptionPane.showMessageDialog(null, error);
}
public void showStatus(String status, boolean error, int timer) {
// TODO: implement
}
// ask to edu.rpi.legup.save current proof
public boolean noquit(String instr) {
int n = JOptionPane.showConfirmDialog(null, instr, "Confirm", JOptionPane.YES_NO_OPTION);
return n != JOptionPane.YES_OPTION;
}
@Override
public void windowOpened(WindowEvent e) {}
public void windowClosing(WindowEvent e) {
if (GameBoardFacade.getInstance().getHistory().getIndex() > -1) {
if (noquit("Exiting LEGUP?")) {
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
} else {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
} else {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
public void windowClosed(WindowEvent e) {
System.exit(0);
}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public BoardView getBoardView() {
return getProofEditor().getBoardView();
}
public BoardView getEditorBoardView() {
return getPuzzleEditor().getBoardView();
}
public DynamicView getDynamicBoardView() {
return getProofEditor().getDynamicBoardView();
}
public DynamicView getEditorDynamicBoardView() {
return getPuzzleEditor().getDynamicBoardView();
}
public TreePanel getTreePanel() {
return getProofEditor().getTreePanel();
}
}