From b50731277ef354f812e3b842f6b1dfd78e3cc5c7 Mon Sep 17 00:00:00 2001 From: Leon Dieter <Leon Dieter@DESKTOP-L4JC8N4> Date: Sat, 20 Mar 2021 11:53:02 +0100 Subject: [PATCH] window size remains constant when restarting simulator --- .../ardublock/simulator/Simulator.java | 26 +++---- .../ardublock/simulator/view/GUI.java | 72 +++++++++---------- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/tec/letsgoing/ardublock/simulator/Simulator.java b/src/tec/letsgoing/ardublock/simulator/Simulator.java index 2f9d849..000f2e0 100644 --- a/src/tec/letsgoing/ardublock/simulator/Simulator.java +++ b/src/tec/letsgoing/ardublock/simulator/Simulator.java @@ -46,7 +46,8 @@ public class Simulator implements Runnable, ActionListener{ private Thread guiThread; private Thread simuThread; private Vector<SimCodeFunction> functionsCode = new Vector<SimCodeFunction>(); - + private final int xscale = 700; + private final int yscale = 700; /** * Privater Konstruktor der Klasse Simulator<br> * Die Klasse ist als Singelton geschrieben, daher sollte diese Konstruktor nie @@ -66,7 +67,8 @@ public class Simulator implements Runnable, ActionListener{ } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } - createSubClasses(); + createSubClasses(xscale, yscale); + } /** @@ -81,6 +83,7 @@ public class Simulator implements Runnable, ActionListener{ instance = new Simulator(); } else { instance.reload(); + } return instance; } @@ -92,8 +95,8 @@ public class Simulator implements Runnable, ActionListener{ * * @return true */ - private boolean createSubClasses() { - gui = new GUI(this); + private boolean createSubClasses(int _xscale, int _yscale) { + gui = new GUI(this, _xscale, _yscale); arduino = new Arduino(gui); gui.connectPins(arduino); @@ -173,20 +176,19 @@ public class Simulator implements Runnable, ActionListener{ } } Point locationWindow = gui.getLocation(); - int WidthWindow = gui.getxscale(); - int HeightWindow = gui.getyscale(); + int WidthWindow = ((int)((gui.getWidth() * 1.0975) - 13.307)); + int HeightWindow = ((int)((gui.getHeight() * 1.2709) - 174.77)); +// int WidthWindow = gui.getWidth(); +// int HeightWindow = gui.getHeight(); + System.out.println(WidthWindow + " " + HeightWindow); gui.stopThread(); gui.dispose(); - createSubClasses(); + createSubClasses(WidthWindow, HeightWindow); gui.setLocation(locationWindow); - gui.setxscale(WidthWindow); - gui.setyscale(HeightWindow); - - System.out.println(WidthWindow + " " + HeightWindow); - //gui.updateGUI(WidthWindow, HeightWindow); + for (SimCodeFunction function : functionsCode) { arduino.addFunction(function); diff --git a/src/tec/letsgoing/ardublock/simulator/view/GUI.java b/src/tec/letsgoing/ardublock/simulator/view/GUI.java index 34c011d..a4e7031 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/GUI.java +++ b/src/tec/letsgoing/ardublock/simulator/view/GUI.java @@ -63,19 +63,25 @@ public class GUI extends JFrame implements Runnable, ActionListener { private JButton clearButton; private JCheckBox checkBox; private JScrollPane scrollPane; - private int xscale = 800; - private int yscale = 968; + private int xscale; + private int yscale; private JPanel modulPanel; private Container mainPane; - private int WindowHeight = 968, WindowWidth = 968, topPanelHeight, topPanelWidth; + private int WindowHeight, WindowWidth; + /** * Konstruktor der Klasse GUI * * @param simu Instanz des Simulators */ - public GUI(Simulator simu) { + public GUI(Simulator simu, int _xscale, int _yscale) { super("ArduBlock Simulator"); + + xscale = _xscale; + yscale = _yscale; + WindowWidth = _xscale; + WindowHeight = _yscale; // Konstruktor der Module modules[0] = new RGB(new ImageIcon(getToolkit() @@ -140,31 +146,31 @@ public class GUI extends JFrame implements Runnable, ActionListener { - //Das Fenster soll erst dann upgedatet werden wenn eine Größenänderung größer 30 stattgefunden hat - //um zu verhindern dass die update Funktion durch ein zu häufiges Aufrufen das Programm aufhängt. - if((Math.abs(WindowHeight - getHeight()) > 5) || (Math.abs(WindowWidth - getWidth()) > 5)) { - - WindowHeight = getHeight(); - WindowWidth = getWidth(); - // topPanelWidth = topPanel.getWidth(); - // topPanelHeight = topPanel.getHeight(); - - //GUI wird nur gleichmäßig skaliert mit den Größen des kleineren Seitenverhätlnisses - if(WindowWidth <= (WindowHeight - 80)) { - xscale = WindowWidth; - yscale = WindowWidth; - } - else { - xscale = WindowHeight - 80; - yscale = WindowHeight - 80; - } - - //GUI wird upgedatet - updateGUI(xscale, yscale); + //Das Fenster soll erst dann upgedatet werden wenn eine Größenänderung größer 30 stattgefunden hat + //um zu verhindern dass die update Funktion durch ein zu häufiges Aufrufen das Programm aufhängt. + if((Math.abs(WindowHeight - getHeight()) > 5) || (Math.abs(WindowWidth - getWidth()) > 5)) { + + WindowHeight = getHeight(); + WindowWidth = getWidth(); + // topPanelWidth = topPanel.getWidth(); + // topPanelHeight = topPanel.getHeight(); + //GUI wird nur gleichmäßig skaliert mit den Größen des kleineren Seitenverhätlnisses + if(WindowWidth <= (WindowHeight - 80)) { + xscale = WindowWidth; + yscale = WindowWidth; + } + else { + xscale = WindowHeight - 80; + yscale = WindowHeight - 80; + } - } - + //GUI wird upgedatet + updateGUI(xscale, yscale); + + + } + } @@ -199,21 +205,14 @@ public class GUI extends JFrame implements Runnable, ActionListener { */ public void updateGUI(int _xscale, int _yscale) { - System.out.println("update: " + xscale + " " + _yscale); + + for(int i = 0; i < 4; i++) { modules[i].updateGUI(_xscale, _yscale); } -// modules[0].updateGUI(_xscale, _yscale); -// modules[1].updateGUI(_xscale, _yscale); -// modules[2].updateGUI(_xscale, _yscale); -// modules[3].updateGUI(_xscale, _yscale); - - - - super.setVisible(true); @@ -221,6 +220,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { updateSerialLog(getHeight()-topPanel.getHeight()); + } -- GitLab