From f01a03cc14187d08ff258818af9f7bb548f41076 Mon Sep 17 00:00:00 2001 From: Leon Dieter <Leon Dieter@DESKTOP-L4JC8N4> Date: Wed, 17 Feb 2021 14:30:54 +0100 Subject: [PATCH] updating resized modules in progress / nullpointer exception error left --- .../ardublock/simulator/Simulator.java | 25 ++-- .../ardublock/simulator/view/GUI.java | 108 +++++++++--------- .../simulator/view/modules/Button.java | 39 +++++-- 3 files changed, 90 insertions(+), 82 deletions(-) diff --git a/src/tec/letsgoing/ardublock/simulator/Simulator.java b/src/tec/letsgoing/ardublock/simulator/Simulator.java index ad98c3b..98adcd2 100644 --- a/src/tec/letsgoing/ardublock/simulator/Simulator.java +++ b/src/tec/letsgoing/ardublock/simulator/Simulator.java @@ -187,34 +187,25 @@ public class Simulator implements Runnable, ActionListener{ public boolean reloadGUI(GUI currentGUI) { - if (simuThread instanceof Thread) { - stopSimu(); - try { - simuThread.join(); - } catch (InterruptedException e) { - // e.printStackTrace(); - arduino.errorAbort("Thread Überwachung gestört - Bitte Programm neustarten"); - return false; - } - } - gui.stopThread(); + + //gui.stopThread(); this.gui = currentGUI; - arduino = new Arduino(gui); - gui.connectPins(arduino); + arduino = new Arduino(currentGUI); + currentGUI.connectPins(arduino); - guiThread = new Thread(gui); - guiThread.start(); + //guiThread = new Thread(gui); + //guiThread.start(); for (SimCodeFunction function : functionsCode) { arduino.addFunction(function); } - startSimu(); + return true; } @@ -232,7 +223,7 @@ public class Simulator implements Runnable, ActionListener{ } } startSimu(); - //System.out.println("reset"); + return true; } diff --git a/src/tec/letsgoing/ardublock/simulator/view/GUI.java b/src/tec/letsgoing/ardublock/simulator/view/GUI.java index 74fba93..af3735c 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/GUI.java +++ b/src/tec/letsgoing/ardublock/simulator/view/GUI.java @@ -65,7 +65,56 @@ public class GUI extends JFrame implements Runnable, ActionListener { */ public GUI(Simulator simu) { super("ArduBlock Simulator"); - createGUI(simu); + // Konstruktor der Module + modules[0] = new RGB(new ImageIcon(getToolkit() + .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM31_RGB_LED.png")))); + modules[1] = new Button( + new ImageIcon(getToolkit() + .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM26_Taster.png"))), + new ImageIcon(getToolkit() + .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Taster_Off.png"))), + new ImageIcon(getToolkit() + .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Taster_On.png")))); + modules[2] = new Poti(new ImageIcon(getToolkit() + .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM24_Potentiometer.png")))); + modules[3] = new ArduinoUno( + new ImageIcon(getToolkit() + .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/ArduinoUno.png"))), + simu); + + //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Vermutlich nicht + // gew�nscht. + this.setResizable(true); //TODO Muss in true ge�ndert werden wenn skalierbar + + + mainPane = this.getContentPane(); + + // Panel welches alle Module sowie die Verdrahtung enth�lt. + modulPanel = new JPanel(new BorderLayout()) { + private static final long serialVersionUID = 1L; + + @Override + public void paint(Graphics g) { + super.paint(g); + drawConnections(g); // Zeichne Verdrahtung + } + + }; + // Füge Module hinzu + modulPanel.add(modules[0].getPane(), BorderLayout.WEST); + modulPanel.add(modules[1].getPane(), BorderLayout.CENTER); + modulPanel.add(modules[2].getPane(), BorderLayout.EAST); + modulPanel.add(modules[3].getPane(), BorderLayout.PAGE_END); + + mainPane.add(modulPanel, BorderLayout.CENTER); + //Panel der Buttons auf der rechten Seite wird ausgeblendet + //mainPane.add(createControlPanel(simu), BorderLayout.LINE_END); + mainPane.add(createSerialLog(), BorderLayout.PAGE_END); + this.setSize(xscale, yscale); + //this.pack(); + // this.setLocation(-1300, 0); //M�glichkeit die Renderingposition festzulegen + this.setVisible(true); + this.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent e) { @@ -82,7 +131,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { } - updating(simu); + //updating(simu); System.out.println("xScale: " + xscale + "\tyScale: " + yscale); @@ -112,12 +161,12 @@ public class GUI extends JFrame implements Runnable, ActionListener { } - public void updating(Simulator simu) { + public void updateGUI(Simulator simu) { + - mainPane.removeAll(); createGUI(simu); - //simu.reloadGUI(this); + @@ -126,55 +175,6 @@ public class GUI extends JFrame implements Runnable, ActionListener { public void createGUI(Simulator simu) { - // Konstruktor der Module - modules[0] = new RGB(new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM31_RGB_LED.png")))); - modules[1] = new Button( - new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM26_Taster.png"))), - new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Taster_Off.png"))), - new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Taster_On.png")))); - modules[2] = new Poti(new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM24_Potentiometer.png")))); - modules[3] = new ArduinoUno( - new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/ArduinoUno.png"))), - simu); - - //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Vermutlich nicht - // gew�nscht. - this.setResizable(true); //TODO Muss in true ge�ndert werden wenn skalierbar - - - mainPane = this.getContentPane(); - - // Panel welches alle Module sowie die Verdrahtung enth�lt. - modulPanel = new JPanel(new BorderLayout()) { - private static final long serialVersionUID = 1L; - - @Override - public void paint(Graphics g) { - super.paint(g); - drawConnections(g); // Zeichne Verdrahtung - } - - }; - // Füge Module hinzu - modulPanel.add(modules[0].getPane(), BorderLayout.WEST); - modulPanel.add(modules[1].getPane(), BorderLayout.CENTER); - modulPanel.add(modules[2].getPane(), BorderLayout.EAST); - modulPanel.add(modules[3].getPane(), BorderLayout.PAGE_END); - - mainPane.add(modulPanel, BorderLayout.CENTER); - //Panel der Buttons auf der rechten Seite wird ausgeblendet - //mainPane.add(createControlPanel(simu), BorderLayout.LINE_END); - mainPane.add(createSerialLog(), BorderLayout.PAGE_END); - this.setSize(xscale, yscale); - //this.pack(); - // this.setLocation(-1300, 0); //M�glichkeit die Renderingposition festzulegen - this.setVisible(true); } diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java index 501945d..7f77fc1 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java @@ -26,47 +26,61 @@ import tec.letsgoing.ardublock.simulator.view.GUI; */ public class Button extends Modul implements ActionListener { private int[] lastState = { 0, 0, 0 }; - private ImageIcon iconOff, iconOn; + private ImageIcon iconOff, iconOn, chipIcon; + private JToggleButton but1, but2, but3; + private JLabel chiplabel, label1, label2, label3; private int xscale = GUI.getxscale(); private int yscale = GUI.getyscale(); public Button(ImageIcon _icon, ImageIcon _icon1, ImageIcon _icon2) { + chipIcon = _icon; iconOff = _icon1; iconOn = _icon2; - layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale)))); - JLabel chiplabel = new JLabel(); - ImageIcon chipIcon = _icon; + chiplabel = new JLabel(); + but1 = new JToggleButton(); + but2 = new JToggleButton(); + but3 = new JToggleButton(); + label1 = new JLabel(); + label2 = new JLabel(); + label3 = new JLabel(); + updateButton(); + calculatePinPos(); + } + + public void updateButton(){ + + layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale)))); chipIcon = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.3037*xscale)), ((int)(0.304*yscale)), Image.SCALE_SMOOTH)); chiplabel.setIcon(chipIcon); chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale))); layerpane.add(chiplabel, 0); - JToggleButton but1 = new JToggleButton(); + but1.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); but1.setIcon(iconOff); but1.setActionCommand("0"); but1.addActionListener(this); - JLabel label1 = new JLabel(); + label1.add(but1); label1.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); label1.setLocation(((int)(0.02996*xscale)), ((int)(0.06618*yscale))); - JToggleButton but2 = new JToggleButton(); + but2.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); but2.setIcon(iconOff); but2.setActionCommand("1"); but2.addActionListener(this); - JLabel label2 = new JLabel(); + label2.add(but2); label2.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); label2.setLocation(((int)(0.1147*xscale)), ((int)(0.03619*yscale))); - JToggleButton but3 = new JToggleButton(); + but3.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); but3.setIcon(iconOff); but3.setActionCommand("2"); but3.addActionListener(this); - JLabel label3 = new JLabel(); + label3.add(but3); label3.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); label3.setLocation(((int)(0.200*xscale)), ((int)(0.06618*yscale))); @@ -74,7 +88,6 @@ public class Button extends Modul implements ActionListener { layerpane.add(label1, 0); layerpane.add(label2, 0); layerpane.add(label3, 0); - calculatePinPos(); } public void updateModul(Pin pin) { @@ -119,8 +132,12 @@ public class Button extends Modul implements ActionListener { int value = 0; if (bool) value = 1023; + lastState[pin] = value; pins.get(pin).setValue(value); + + System.out.println("called"); + } private void calculatePinPos() { -- GitLab