From fb3267ba7a0c48214d7fd24e3d152bedcdfd09fa Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 10:32:36 +0400 Subject: [PATCH 01/10] create zoom panel --- .../com/github/creme332/view/ZoomPanel.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/main/java/com/github/creme332/view/ZoomPanel.java diff --git a/src/main/java/com/github/creme332/view/ZoomPanel.java b/src/main/java/com/github/creme332/view/ZoomPanel.java new file mode 100644 index 00000000..f609a9b3 --- /dev/null +++ b/src/main/java/com/github/creme332/view/ZoomPanel.java @@ -0,0 +1,87 @@ +package com.github.creme332.view; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + +import javax.swing.JButton; +import javax.swing.JPanel; + +import org.kordamp.ikonli.Ikon; +import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; +import org.kordamp.ikonli.swing.FontIcon; + +public class ZoomPanel extends JPanel { + + private JButton homeButton = new CircularButton(); + private JButton zoomInButton = new CircularButton(); + private JButton zoomOutButton = new CircularButton(); + + public ZoomPanel() { + setOpaque(false); + this.setLayout(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + + // create buttons for zoom panel + homeButton = createZoomPanelButton(BootstrapIcons.HOUSE); + zoomInButton = createZoomPanelButton(BootstrapIcons.ZOOM_IN); + zoomOutButton = createZoomPanelButton(BootstrapIcons.ZOOM_OUT); + + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.insets = new Insets(20, 0, 0, 0); + gbc.gridx = 0; + gbc.gridy = 0; + gbc.gridwidth = 1; + + this.add(homeButton, gbc); + + gbc.gridx = 0; + gbc.gridy = 1; + this.add(zoomInButton, gbc); + + gbc.gridx = 0; + gbc.gridy = 2; + this.add(zoomOutButton, gbc); + + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + // get current dimensions + int width = getWidth(); + int height = getHeight(); + + System.out.format("Zoom panel dimensions = %d x %d %n", width, height); + } + }); + } + + public JButton createZoomPanelButton(Ikon ikon) { + final int ICON_SIZE = 30; + final int BUTTON_SIZE = 60; + final Color gray = new Color(116, 116, 116); + + JButton btn = new CircularButton(); + btn.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); + + FontIcon icon = FontIcon.of(ikon, ICON_SIZE); + icon.setIconColor(gray); + btn.setIcon(icon); + return btn; + } + + public JButton getHomeButton() { + return homeButton; + } + + public JButton getZoomInButton() { + return zoomInButton; + } + + public JButton getZoomOutButton() { + return zoomOutButton; + } +} From bcfcbd2367970ffc4f7bcbd66276db396b311f64 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 10:45:44 +0400 Subject: [PATCH 02/10] add help button in menubar --- .../creme332/controller/MenuBarController.java | 3 +++ src/main/java/com/github/creme332/view/MenuBar.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/creme332/controller/MenuBarController.java b/src/main/java/com/github/creme332/controller/MenuBarController.java index ab503678..4fdc5471 100644 --- a/src/main/java/com/github/creme332/controller/MenuBarController.java +++ b/src/main/java/com/github/creme332/controller/MenuBarController.java @@ -15,6 +15,7 @@ import com.github.creme332.model.MenuModel; import com.github.creme332.model.CanvasModel; import com.github.creme332.model.Mode; +import com.github.creme332.model.Screen; import com.github.creme332.view.MenuBar; public class MenuBarController implements PropertyChangeListener { @@ -91,6 +92,8 @@ public void mousePressed(MouseEvent e) { } }); + menubar.getHelpButton().addActionListener(e -> app.switchScreen(Screen.TUTORIAL_SCREEN)); + menubar.getToggleAxesButton().addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { diff --git a/src/main/java/com/github/creme332/view/MenuBar.java b/src/main/java/com/github/creme332/view/MenuBar.java index 5c421e2e..41f3bc22 100644 --- a/src/main/java/com/github/creme332/view/MenuBar.java +++ b/src/main/java/com/github/creme332/view/MenuBar.java @@ -22,9 +22,10 @@ public class MenuBar extends JMenuBar { private JButton sidebarButton; private JButton guidelinesButton; // Button to toggle guidelines private JButton toggleAxesButton; // Button to toggle axes visibility + private JButton helpButton; public MenuBar(MenuModel[] menus) throws InvalidIconSizeException, InvalidPathException { - + // add menus to menubar for (MenuModel menuModel : menus) { JMenu menu = new JMenu(); @@ -65,6 +66,12 @@ public MenuBar(MenuModel[] menus) throws InvalidIconSizeException, InvalidPathEx toggleAxesButton.setBorderPainted(false); leftPanel.add(toggleAxesButton); + // help button + helpButton = new JButton(); + helpButton.setIcon(FontIcon.of(BootstrapIcons.QUESTION_CIRCLE, 37)); + helpButton.setBorderPainted(false); + leftPanel.add(helpButton); + // sidebar menu button sidebarButton = new JButton(); sidebarButton.setIcon(FontIcon.of(BootstrapIcons.LIST, 40)); @@ -85,4 +92,8 @@ public JButton getGuidelinesButton() { public JButton getToggleAxesButton() { return toggleAxesButton; } + + public JButton getHelpButton() { + return helpButton; + } } From 170248451d7a68c92c428f89141d475d459c7b53 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:23:52 +0400 Subject: [PATCH 03/10] remove toolbar, zoompanel, toast --- .../java/com/github/creme332/view/Canvas.java | 110 +----------------- 1 file changed, 4 insertions(+), 106 deletions(-) diff --git a/src/main/java/com/github/creme332/view/Canvas.java b/src/main/java/com/github/creme332/view/Canvas.java index 137d2a43..5fbce646 100644 --- a/src/main/java/com/github/creme332/view/Canvas.java +++ b/src/main/java/com/github/creme332/view/Canvas.java @@ -1,116 +1,30 @@ package com.github.creme332.view; -import javax.swing.JButton; import javax.swing.JPanel; -import org.kordamp.ikonli.Ikon; -import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; -import org.kordamp.ikonli.swing.FontIcon; - import com.github.creme332.model.CanvasModel; import com.github.creme332.model.ShapeWrapper; import java.awt.BasicStroke; import java.awt.Color; -import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.Shape; import java.awt.geom.Ellipse2D; import java.awt.geom.Point2D; +/** + * Drawing board for coordinate system. + */ public class Canvas extends JPanel { - private JButton homeButton = new CircularButton(); - private JButton zoomInButton = new CircularButton(); - private JButton zoomOutButton = new CircularButton(); - private Toolbar toolbar; private transient CanvasModel model; - private Toast toast = new Toast(); - - /** - * Place zoom panel in bottom right corner of canvas. - */ - public void positionZoomPanel() { - final int MARGIN_RIGHT = 20; - final int MARGIN_BOTTOM = 200; - - final int canvasWidth = getWidth(); - final int canvasHeight = getHeight(); - - Dimension buttonSize = homeButton.getPreferredSize(); - int x = canvasWidth - buttonSize.width - MARGIN_RIGHT; - int y = canvasHeight - buttonSize.height - MARGIN_BOTTOM; - - homeButton.setBounds(x, y, buttonSize.width, buttonSize.height); - zoomInButton.setBounds(x, y + 60, buttonSize.width, buttonSize.height); - zoomOutButton.setBounds(x, y + 120, buttonSize.width, buttonSize.height); - } - - public void positionToast() { - // position toast - Dimension toastSize = toast.getPreferredSize(); - - Rectangle r = new Rectangle(); - r.x = 30; - r.y = (int) (this.getHeight() - toastSize.getHeight() - 30); - - r.width = (int) toastSize.getWidth(); - r.height = (int) toastSize.getHeight(); - - toast.setBounds(r); - } - - /** - * Place toolbar at middle top of canvas - */ - public void positionToolbar() { - final int MARGIN_TOP = 25; // distance between toolbar and canvas top - final int canvasWidth = getWidth(); - - // position toolbar such that center of toolbar coincides with center of canvas - Dimension toolbarSize = toolbar.getPreferredSize(); - Rectangle r = new Rectangle(); - r.x = canvasWidth / 2 - (int) (toolbarSize.getWidth() / 2); - r.y = MARGIN_TOP; - - r.width = (int) toolbarSize.getWidth(); - r.height = (int) toolbarSize.getHeight(); - - toolbar.setBounds(r); - } - - public JButton createZoomPanelButton(Ikon ikon) { - final int ICON_SIZE = 25; - final Color gray = new Color(116, 116, 116); - - JButton btn = new CircularButton(); - btn.setPreferredSize(new Dimension(50, 50)); - FontIcon icon = FontIcon.of(ikon, ICON_SIZE); - icon.setIconColor(gray); - btn.setIcon(icon); - return btn; - } - public Canvas(CanvasModel model, Toolbar toolbar) { + public Canvas(CanvasModel model) { setLayout(null); // Use no layout manager - this.model = model; - this.toolbar = toolbar; - add(toolbar); - add(toast); - - // create buttons for zoom panel - homeButton = createZoomPanelButton(BootstrapIcons.HOUSE); - zoomInButton = createZoomPanelButton(BootstrapIcons.ZOOM_IN); - zoomOutButton = createZoomPanelButton(BootstrapIcons.ZOOM_OUT); - - add(homeButton); - add(zoomInButton); - add(zoomOutButton); } public void setAntialiasing(Graphics2D g2) { @@ -239,10 +153,6 @@ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; setAntialiasing(g2); - positionZoomPanel(); - positionToolbar(); - positionToast(); - if (model.isGuidelinesEnabled()) { drawGuidelines(g2); } @@ -285,16 +195,4 @@ private Shape createPointAsShape(Point2D mySpaceCoord) { radius, radius); } - - public JButton getHomeButton() { - return homeButton; - } - - public JButton getZoomInButton() { - return zoomInButton; - } - - public JButton getZoomOutButton() { - return zoomOutButton; - } } From 0be72e376f6571dda2e305330b23f4bb034440c0 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:24:31 +0400 Subject: [PATCH 04/10] create a canvas console --- .../github/creme332/view/CanvasConsole.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/com/github/creme332/view/CanvasConsole.java diff --git a/src/main/java/com/github/creme332/view/CanvasConsole.java b/src/main/java/com/github/creme332/view/CanvasConsole.java new file mode 100644 index 00000000..69ccd707 --- /dev/null +++ b/src/main/java/com/github/creme332/view/CanvasConsole.java @@ -0,0 +1,59 @@ +package com.github.creme332.view; + +import java.awt.BorderLayout; + +import javax.swing.JPanel; + +import com.github.creme332.utils.exception.InvalidIconSizeException; +import com.github.creme332.utils.exception.InvalidPathException; + +/** + * A panel that contains control buttons for Canvas. It should be placed on top + * of the canvas and should have the same dimensions as Canvas. + */ +public class CanvasConsole extends JPanel { + private Toolbar toolbar; + private Toast toast = new Toast(); + private ZoomPanel zoomPanel = new ZoomPanel(); + + public CanvasConsole() { + setOpaque(false); // make panel transparent + setLayout(new BorderLayout()); + + try { + toolbar = new Toolbar(); + } catch (InvalidIconSizeException | InvalidPathException e) { + e.printStackTrace(); + System.exit(0); + } + + JPanel topPanel = new JPanel(); + topPanel.setOpaque(false); + topPanel.add(toolbar); + add(topPanel, BorderLayout.NORTH); + + JPanel southPanel = new JPanel(new BorderLayout()); + southPanel.setOpaque(false); + + southPanel.add(toast, BorderLayout.WEST); + add(southPanel, BorderLayout.SOUTH); + + JPanel eastPanel = new JPanel(new BorderLayout()); + eastPanel.setOpaque(false); + + eastPanel.add(zoomPanel, BorderLayout.SOUTH); + add(eastPanel, BorderLayout.EAST); + } + + public Toolbar getToolbar() { + return toolbar; + } + + public Toast getToast() { + return toast; + } + + public ZoomPanel getZoomPanel() { + return zoomPanel; + } +} From d3ee48c103fd2d1aa2f9b2bf380f09c04709917f Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:36:32 +0400 Subject: [PATCH 05/10] add padding to toast --- src/main/java/com/github/creme332/view/CanvasConsole.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/github/creme332/view/CanvasConsole.java b/src/main/java/com/github/creme332/view/CanvasConsole.java index 69ccd707..35497e82 100644 --- a/src/main/java/com/github/creme332/view/CanvasConsole.java +++ b/src/main/java/com/github/creme332/view/CanvasConsole.java @@ -1,8 +1,10 @@ package com.github.creme332.view; import java.awt.BorderLayout; +import java.awt.Insets; import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; import com.github.creme332.utils.exception.InvalidIconSizeException; import com.github.creme332.utils.exception.InvalidPathException; @@ -33,6 +35,7 @@ public CanvasConsole() { add(topPanel, BorderLayout.NORTH); JPanel southPanel = new JPanel(new BorderLayout()); + southPanel.setBorder(new EmptyBorder(new Insets(0, 20, 10, 0))); southPanel.setOpaque(false); southPanel.add(toast, BorderLayout.WEST); From 5084663829730c16dc36b02f8b327063a1879da3 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:37:03 +0400 Subject: [PATCH 06/10] refactor --- .../java/com/github/creme332/view/ZoomPanel.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/main/java/com/github/creme332/view/ZoomPanel.java b/src/main/java/com/github/creme332/view/ZoomPanel.java index f609a9b3..8a0daa67 100644 --- a/src/main/java/com/github/creme332/view/ZoomPanel.java +++ b/src/main/java/com/github/creme332/view/ZoomPanel.java @@ -5,8 +5,6 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; import javax.swing.JButton; import javax.swing.JPanel; @@ -46,20 +44,9 @@ public ZoomPanel() { gbc.gridx = 0; gbc.gridy = 2; this.add(zoomOutButton, gbc); - - addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - // get current dimensions - int width = getWidth(); - int height = getHeight(); - - System.out.format("Zoom panel dimensions = %d x %d %n", width, height); - } - }); } - public JButton createZoomPanelButton(Ikon ikon) { + private JButton createZoomPanelButton(Ikon ikon) { final int ICON_SIZE = 30; final int BUTTON_SIZE = 60; final Color gray = new Color(116, 116, 116); From 0f481aaa5a8b65d0fdb554713480facb8d5d48b4 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:37:31 +0400 Subject: [PATCH 07/10] create a zoom panel controller for handling zoom logic --- .../creme332/controller/CanvasController.java | 14 -------------- .../controller/ZoomPanelController.java | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/github/creme332/controller/ZoomPanelController.java diff --git a/src/main/java/com/github/creme332/controller/CanvasController.java b/src/main/java/com/github/creme332/controller/CanvasController.java index 01058562..53b68748 100644 --- a/src/main/java/com/github/creme332/controller/CanvasController.java +++ b/src/main/java/com/github/creme332/controller/CanvasController.java @@ -84,11 +84,6 @@ public void mouseWheelMoved(MouseWheelEvent e) { handleCanvasZoom(e); } }); - - // Add action listeners for the zoom panel buttons - canvas.getHomeButton().addActionListener(e -> resetCanvasView()); - canvas.getZoomInButton().addActionListener(e -> model.updateCanvasZoom(true)); - canvas.getZoomOutButton().addActionListener(e -> model.updateCanvasZoom(false)); } private void handleCanvasZoom(MouseWheelEvent e) { @@ -171,15 +166,6 @@ private void handleMousePressed(MouseEvent e) { canvas.repaint(); } - private void resetCanvasView() { - // show origin at center of canvas - model.setXZero(canvas.getWidth() / 2); - model.setYZero(canvas.getHeight() / 2); - - model.resetZoom(); - canvas.repaint(); - } - @Override public void propertyChange(PropertyChangeEvent e) { final String propertyName = e.getPropertyName(); diff --git a/src/main/java/com/github/creme332/controller/ZoomPanelController.java b/src/main/java/com/github/creme332/controller/ZoomPanelController.java new file mode 100644 index 00000000..ebe5ec2b --- /dev/null +++ b/src/main/java/com/github/creme332/controller/ZoomPanelController.java @@ -0,0 +1,19 @@ +package com.github.creme332.controller; + +import com.github.creme332.model.CanvasModel; +import com.github.creme332.view.ZoomPanel; + +public class ZoomPanelController { + CanvasModel model; + ZoomPanel view; + + public ZoomPanelController(CanvasModel model, ZoomPanel view) { + this.model = model; + this.view = view; + + // Add action listeners for the zoom panel buttons + view.getHomeButton().addActionListener(e -> model.resetZoom()); + view.getZoomInButton().addActionListener(e -> model.updateCanvasZoom(true)); + view.getZoomOutButton().addActionListener(e -> model.updateCanvasZoom(false)); + } +} \ No newline at end of file From 42f4c9aa6c39b5eb0f4062a301e463c8ccaad833 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:56:45 +0400 Subject: [PATCH 08/10] instantiate CanvasConsole and ZoomPanelController --- .../com/github/creme332/controller/Controller.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/creme332/controller/Controller.java b/src/main/java/com/github/creme332/controller/Controller.java index 28b27242..4f433d39 100644 --- a/src/main/java/com/github/creme332/controller/Controller.java +++ b/src/main/java/com/github/creme332/controller/Controller.java @@ -14,7 +14,6 @@ public class Controller { private Frame frame; // frame of app private MenuBar menuBar; private Canvas canvas; - private Toolbar toolbar; private FrameController frameController; @@ -23,16 +22,18 @@ public Controller() { menuBar = new MenuBar(app.getMenuModels()); new MenuBarController(app, menuBar); - toolbar = new Toolbar(); - new ToolBarController(toolbar); + CanvasConsole canvasConsole = new CanvasConsole(); - canvas = new Canvas(app.getCanvasModel(), toolbar); + new ToolBarController(canvasConsole.getToolbar()); + new ZoomPanelController(app.getCanvasModel(), canvasConsole.getZoomPanel()); + + canvas = new Canvas(app.getCanvasModel()); new CanvasController(app, canvas); TutorialCenter tutorialCenter = new TutorialCenter(); - new TutorialController(tutorialCenter); + new TutorialController(app, tutorialCenter); - frame = new Frame(canvas, menuBar, tutorialCenter); + frame = new Frame(canvas, canvasConsole, menuBar, tutorialCenter); frameController = new FrameController(app, frame); new SideMenuController(app, frame.getSideMenuPanel()); @@ -44,7 +45,6 @@ public Controller() { e.printStackTrace(); System.exit(1); } - frameController.playStartAnimation(); } From 35b37b767a5d44313c0e0f2156e67b8c79456cb7 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:57:56 +0400 Subject: [PATCH 09/10] introduce a layered canvas --- .../creme332/controller/FrameController.java | 65 ++++++++++++++----- .../java/com/github/creme332/view/Frame.java | 36 +++++++--- 2 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/github/creme332/controller/FrameController.java b/src/main/java/com/github/creme332/controller/FrameController.java index 0c19a4bf..3258af87 100644 --- a/src/main/java/com/github/creme332/controller/FrameController.java +++ b/src/main/java/com/github/creme332/controller/FrameController.java @@ -10,6 +10,8 @@ import java.util.Timer; import java.util.TimerTask; +import javax.swing.JLayeredPane; + import com.github.creme332.model.AppState; import com.github.creme332.model.MenuModel; import com.github.creme332.model.Screen; @@ -19,49 +21,77 @@ public class FrameController implements PropertyChangeListener { private Frame frame; private AppState app; - public FrameController(AppState app, Frame frame) { + public FrameController(AppState model, Frame frame) { this.frame = frame; - this.app = app; + this.app = model; - app.addPropertyChangeListener(this); + model.addPropertyChangeListener(this); frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { - // get current frame dimensions - int width = frame.getWidth(); - int height = frame.getHeight(); - - // get menubar dimensions - int menuWidth = frame.getMyMenuBar().getWidth(); - int menuHeight = frame.getMyMenuBar().getHeight(); + resizeEverything(); - int sideWidth = Math.min(400, width / 3); - frame.getMainPanel().setPreferredSize(new Dimension(menuWidth, height - menuHeight)); - frame.setPreferredSize(new Dimension(sideWidth, height - menuHeight)); } }); frame.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - MenuModel[] menuModels = app.getMenuModels(); + MenuModel[] menuModels = model.getMenuModels(); // if Esc is pressed, select mode in first menu if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { - app.setMode(menuModels[0].getActiveItem().getMode()); + model.setMode(menuModels[0].getActiveItem().getMode()); return; } // if key number k is pressed, select mode in k-th menu where k = 1, 2, ... for (int i = 0; i < menuModels.length; i++) { if (e.getKeyCode() == (KeyEvent.VK_1 + i)) - app.setMode(menuModels[i].getActiveItem().getMode()); + model.setMode(menuModels[i].getActiveItem().getMode()); } } }); } + private void resizeEverything() { + int frameWidth = frame.getWidth(); + int frameHeight = frame.getHeight(); + System.out.format("Frame dimensions = %d x %d %n", frameWidth, frameHeight); + + int menuBarHeight = frame.getMyMenuBar().getHeight(); + System.out.format("Menubar dimensions = %d x %d %n", frameWidth, menuBarHeight); + + int sideBarWidth = app.getSideBarVisibility() ? Math.max(800, frameWidth / 3) : 0; + System.out.format("Sidebar dimensions = %d x %d %n", sideBarWidth, frameHeight - menuBarHeight); + + // update sidebar dimensions + // frame.getSideMenuPanel().setPreferredSize(new Dimension(sideBarWidth, + // frameHeight - menuBarHeight)); + + // update main panel dimensions + frame.getMainPanel().setPreferredSize(new Dimension(frameWidth, frameHeight - menuBarHeight)); + + // update pane dimensions + JLayeredPane pane = frame.getPane(); + pane.setPreferredSize(new Dimension(frameWidth, frameHeight - menuBarHeight)); + System.out.format("Pane dimensions = %d x %d %n", pane.getWidth(), + pane.getHeight()); + + // update size of canvas control + pane.getComponent(0).setBounds(0, 0, frameWidth - 80, + frameHeight - menuBarHeight - 100); + + // temporarily hide the canvas control. without this, the canvas console does + // not render its new size when frame is maximized. + pane.getComponent(0).setVisible(false); + pane.getComponent(0).setVisible(true); + + // update canvas size + pane.getComponent(1).setBounds(0, 0, frameWidth, frameHeight - menuBarHeight); + } + public void playStartAnimation() { Timer timer = new Timer(); TimerTask showNextScreen; @@ -81,6 +111,7 @@ public void run() { if (app.getCurrentScreen().equals(Screen.TUTORIAL_SCREEN)) { frame.showScreen(Screen.TUTORIAL_SCREEN); } + resizeEverything(); timer.cancel(); timer.purge(); @@ -98,6 +129,8 @@ public void propertyChange(PropertyChangeEvent e) { if (Screen.TUTORIAL_SCREEN.equals(e.getNewValue())) frame.showScreen(Screen.TUTORIAL_SCREEN); + + resizeEverything(); } } diff --git a/src/main/java/com/github/creme332/view/Frame.java b/src/main/java/com/github/creme332/view/Frame.java index a2ff82a0..5e430a2f 100644 --- a/src/main/java/com/github/creme332/view/Frame.java +++ b/src/main/java/com/github/creme332/view/Frame.java @@ -4,6 +4,7 @@ import java.awt.CardLayout; import javax.swing.JFrame; +import javax.swing.JLayeredPane; import javax.swing.JPanel; import static com.github.creme332.utils.IconLoader.loadIcon; @@ -48,7 +49,12 @@ public class Frame extends JFrame { */ MenuBar menubar = null; - public Frame(Canvas canvas, MenuBar menubar, TutorialCenter tutorialCenter) throws InvalidPathException { + CanvasConsole canvasConsole; + + JLayeredPane layeredPane; + + public Frame(Canvas canvas, CanvasConsole console, MenuBar menubar, TutorialCenter tutorialCenter) + throws InvalidPathException { // set frame title this.setTitle("polydraw"); @@ -73,19 +79,25 @@ public Frame(Canvas canvas, MenuBar menubar, TutorialCenter tutorialCenter) thro this.menubar = menubar; setJMenuBar(menubar); + this.canvasConsole = console; + + // setup layered pane + layeredPane = new JLayeredPane(); + layeredPane.add(canvas, Integer.valueOf(1)); + layeredPane.add(console, Integer.valueOf(2)); + // layeredPane.add(sideMenu, Integer.valueOf(3)); + + canvas.setBounds(0, 0, 600, 600); + console.setBounds(0, 0, 600, 600); + // add layeredPane to mainScreen + mainScreen.add(layeredPane, BorderLayout.CENTER); + // setup screen container screenContainer.add(splashScreen, Screen.SPLASH_SCREEN.toString()); screenContainer.add(mainScreen, Screen.MAIN_SCREEN.toString()); screenContainer.add(tutorialCenter, Screen.TUTORIAL_SCREEN.toString()); - this.add(screenContainer); - // add canvas to mainScreen - mainScreen.add(canvas, BorderLayout.CENTER); - - // add side menu to main screen - mainScreen.add(sideMenu, BorderLayout.EAST); - // display frame this.setVisible(true); } @@ -118,10 +130,18 @@ public void showScreen(Screen screen) { } } + public JLayeredPane getPane() { + return layeredPane; + } + public SideMenuPanel getSideMenuPanel() { return sideMenu; } + public CanvasConsole getCanvasConsole() { + return canvasConsole; + } + public MenuBar getMyMenuBar() { return menubar; } From 25802a63d12c964ce69638169af1e94f1b53eec3 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:31:36 +0400 Subject: [PATCH 10/10] remove model temporarily from TutorialController --- src/main/java/com/github/creme332/controller/Controller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/creme332/controller/Controller.java b/src/main/java/com/github/creme332/controller/Controller.java index 4f433d39..a2484a0f 100644 --- a/src/main/java/com/github/creme332/controller/Controller.java +++ b/src/main/java/com/github/creme332/controller/Controller.java @@ -31,7 +31,7 @@ public Controller() { new CanvasController(app, canvas); TutorialCenter tutorialCenter = new TutorialCenter(); - new TutorialController(app, tutorialCenter); + new TutorialController(tutorialCenter); frame = new Frame(canvas, canvasConsole, menuBar, tutorialCenter); frameController = new FrameController(app, frame);