Skip to content

Commit

Permalink
Merge pull request #175 from Bram-Hub/puzzle-editor-exit-button
Browse files Browse the repository at this point in the history
Puzzle editor exit button
  • Loading branch information
mattsweet417 authored Jul 1, 2022
2 parents f385d60 + 143c502 commit 17b659e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
34 changes: 27 additions & 7 deletions src/main/java/edu/rpi/legup/ui/HomePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class HomePanel extends LegupPanel {
private LegupUI legupUI;
private JFrame frame;
private JButton[] buttons;
private JLabel[] text;
private JMenuBar menuBar;

private final int buttonSize = 100;
Expand All @@ -15,6 +16,7 @@ public HomePanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) {
this.legupUI = legupUI;
this.frame = frame;
setLayout(new GridLayout(1, 2));
initText();
initButtons();
}

Expand Down Expand Up @@ -46,8 +48,7 @@ public JMenuBar getMenuBar()
public void makeVisible()
{
render();
this.frame.setVisible(true);
this.frame.setJMenuBar(this.getMenuBar());
frame.setJMenuBar(this.getMenuBar());
}

private static ImageIcon resizeButtonIcon(ImageIcon icon, int width, int height)
Expand Down Expand Up @@ -111,9 +112,10 @@ private void initButtons() {
this.buttons[3].setVerticalTextPosition(AbstractButton.BOTTOM);
}

private void render()
private void initText()
{
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
this.text = new JLabel[3];

JLabel welcome = new JLabel("Welcome to Legup");
welcome.setFont(new Font("Roboto", Font.BOLD, 23));
welcome.setAlignmentX(Component.CENTER_ALIGNMENT);
Expand All @@ -125,23 +127,41 @@ private void render()
JLabel credits = new JLabel("A project by Dr. Bram van Heuveln");
credits.setFont(new Font("Roboto", Font.PLAIN, 12));
credits.setAlignmentX(Component.CENTER_ALIGNMENT);

this.text[0] = welcome;
this.text[1] = version;
this.text[2] = credits;
}

private void render()
{
/* Removing this line will cause random whitespace to be added every time you return to
the home screen. However, this line does not seem to be present in other makeVisible()
methods. We should look into this in the future.
*/
this.removeAll();

this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

JPanel buttons = new JPanel();
buttons.add(Box.createRigidArea(new Dimension(5, 0)));
buttons.add(this.buttons[0]);
buttons.add(Box.createRigidArea(new Dimension(5, 0)));
buttons.add(this.buttons[1]);
buttons.add(Box.createRigidArea(new Dimension(5, 0)));
buttons.add(this.buttons[2]);
buttons.add(Box.createRigidArea(new Dimension(5, 0)));

JPanel batchGraderButton = new JPanel();
batchGraderButton.add(this.buttons[3]);
batchGraderButton.setAlignmentX(Component.LEFT_ALIGNMENT);

this.add(welcome);
this.add(version);
this.add(credits);
this.add(Box.createRigidArea(new Dimension(0, 5)));
for (int i = 0; i < this.text.length; i++)
this.add(this.text[i]);
this.add(buttons);
this.add(batchGraderButton);
this.add(Box.createRigidArea(new Dimension(0, 5)));
}

private void openNewPuzzleDialog() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/edu/rpi/legup/ui/LegupUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ private void initPanels() {
panels = new LegupPanel[3];

panels[0] = new HomePanel(this.fileDialog, this, this);
panels[1] = new ProofEditorPanel(this.fileDialog, this);
panels[2] = new PuzzleEditorPanel(this.fileDialog, this);
panels[1] = new ProofEditorPanel(this.fileDialog, this, this);
panels[2] = new PuzzleEditorPanel(this.fileDialog, this, this);

}

protected void displayPanel(int option) {
if (option > panels.length) {
if (option > panels.length || option < 0) {
throw new InvalidParameterException("Invalid option");
}
this.window.removeAll();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ public class ProofEditorPanel extends LegupPanel implements IHistoryListener {
private BoardView boardView;
private JFileChooser folderBrowser;
private JMenuItem undo, redo;
private LegupUI legupUI;

final static int[] TOOLBAR_SEPARATOR_BEFORE = {2, 4, 8};

public ProofEditorPanel(FileDialog fileDialog, JFrame frame) {
public ProofEditorPanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) {
this.fileDialog = fileDialog;
this.frame = frame;
this.legupUI = legupUI;
setLayout(new BorderLayout());
}

Expand Down Expand Up @@ -187,7 +189,7 @@ public JMenuBar getMenuBar() {
file.addSeparator();

file.add(exit);
exit.addActionListener((ActionEvent) -> System.exit(0));
exit.addActionListener((ActionEvent) -> this.legupUI.displayPanel(0));
if(os.equals("mac")) exit.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
else exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.CTRL_DOWN_MASK));
mBar.add(edit);
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ public class PuzzleEditorPanel extends LegupPanel implements IHistoryListener {
private JMenuItem undo, redo;
private ElementFrame elementFrame;
private JPanel treePanel;
private LegupUI legupUI;
final static int[] TOOLBAR_SEPARATOR_BEFORE = {2, 4, 8};
public PuzzleEditorPanel(FileDialog fileDialog, JFrame frame) {

public PuzzleEditorPanel(FileDialog fileDialog, JFrame frame, LegupUI legupUI) {
this.fileDialog = fileDialog;
this.frame = frame;
this.legupUI = legupUI;
setLayout(new BorderLayout());
}

Expand Down Expand Up @@ -84,6 +87,7 @@ public void setMenuBar() {
menus = new JMenu[3];

// create menus

// FILE
menus[0] = new JMenu("File");
// file>new
Expand All @@ -93,9 +97,15 @@ public void setMenuBar() {
else newPuzzle.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_DOWN_MASK));
// file>save
JMenuItem savePuzzle = new JMenuItem("Save");

JMenuItem exit = new JMenuItem("Exit");
exit.addActionListener((ActionEvent) -> this.legupUI.displayPanel(0));
if (os.equals("mac"))
exit.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
else
exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.CTRL_DOWN_MASK));
menus[0].add(newPuzzle);
menus[0].add(savePuzzle);
menus[0].add(exit);

// EDIT
menus[1] = new JMenu("Edit");
Expand Down

0 comments on commit 17b659e

Please sign in to comment.