From 73de0d06e3c24808a18a8e248f1019dbfbb33753 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Fri, 24 Jun 2022 14:53:38 -0400 Subject: [PATCH 1/4] Progress made Just storing the changes I've made so far --- src/main/java/edu/rpi/legup/ui/HomePanel.java | 26 +++++++++++++++---- src/main/java/edu/rpi/legup/ui/LegupUI.java | 6 ++--- .../edu/rpi/legup/ui/ProofEditorPanel.java | 6 +++-- .../edu/rpi/legup/ui/PuzzleEditorPanel.java | 5 +++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/java/edu/rpi/legup/ui/HomePanel.java b/src/main/java/edu/rpi/legup/ui/HomePanel.java index 51ca01116..09dd24bd1 100644 --- a/src/main/java/edu/rpi/legup/ui/HomePanel.java +++ b/src/main/java/edu/rpi/legup/ui/HomePanel.java @@ -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; @@ -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(); } @@ -111,9 +113,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); @@ -125,6 +128,19 @@ 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() + { + this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); + + //JPanel welcomeText = new JPanel(); + //for (JLabel label : this.text) + // welcomeText.add(label); JPanel buttons = new JPanel(); buttons.add(this.buttons[0]); @@ -137,9 +153,9 @@ private void render() batchGraderButton.add(this.buttons[3]); batchGraderButton.setAlignmentX(Component.LEFT_ALIGNMENT); - this.add(welcome); - this.add(version); - this.add(credits); + // this.add(welcomeText); + for (JLabel label : this.text) + this.add(label); this.add(buttons); this.add(batchGraderButton); } diff --git a/src/main/java/edu/rpi/legup/ui/LegupUI.java b/src/main/java/edu/rpi/legup/ui/LegupUI.java index ed994fc72..8142319e4 100644 --- a/src/main/java/edu/rpi/legup/ui/LegupUI.java +++ b/src/main/java/edu/rpi/legup/ui/LegupUI.java @@ -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(); diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index 48080d7d1..e18e8482e 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -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()); } @@ -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); diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index f5ae071df..d40529f9e 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -37,10 +37,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()); } From 8dd16e1b69e4762e90f1225dfe9f299fdadf995d Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Fri, 1 Jul 2022 14:40:28 -0400 Subject: [PATCH 2/4] Fixed whitespace problem --- src/main/java/edu/rpi/legup/ui/HomePanel.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/rpi/legup/ui/HomePanel.java b/src/main/java/edu/rpi/legup/ui/HomePanel.java index 09dd24bd1..db2df5024 100644 --- a/src/main/java/edu/rpi/legup/ui/HomePanel.java +++ b/src/main/java/edu/rpi/legup/ui/HomePanel.java @@ -48,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) @@ -136,26 +135,30 @@ private void initText() 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 welcomeText = new JPanel(); - //for (JLabel label : this.text) - // welcomeText.add(label); 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(welcomeText); - for (JLabel label : this.text) - this.add(label); + for (int i = 0; i < this.text.length; i++) + this.add(this.text[i]); this.add(buttons); this.add(batchGraderButton); } From 45d89bf5080a607075ddfc4c9158aff463254992 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Fri, 1 Jul 2022 14:41:44 -0400 Subject: [PATCH 3/4] Added some padding to home screen --- src/main/java/edu/rpi/legup/ui/HomePanel.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/rpi/legup/ui/HomePanel.java b/src/main/java/edu/rpi/legup/ui/HomePanel.java index db2df5024..73fcdb9b4 100644 --- a/src/main/java/edu/rpi/legup/ui/HomePanel.java +++ b/src/main/java/edu/rpi/legup/ui/HomePanel.java @@ -156,11 +156,12 @@ the home screen. However, this line does not seem to be present in other makeVis batchGraderButton.add(this.buttons[3]); batchGraderButton.setAlignmentX(Component.LEFT_ALIGNMENT); - // this.add(welcomeText); + 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() { From 143c5029fee885833ab6c411dc0ca0b7d16eca62 Mon Sep 17 00:00:00 2001 From: charlestian23 Date: Fri, 1 Jul 2022 14:46:48 -0400 Subject: [PATCH 4/4] Added exit button to Puzzle Editor --- src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java index d40529f9e..c0739a082 100644 --- a/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/PuzzleEditorPanel.java @@ -82,6 +82,7 @@ public void setMenuBar() { menus = new JMenu[3]; // create menus + // FILE menus[0] = new JMenu("File"); // file>new @@ -91,9 +92,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");