From 02d16e8555e716ff2ffb9926be0427b7c99e4830 Mon Sep 17 00:00:00 2001
From: Leon Dieter <Leon Dieter@DESKTOP-L4JC8N4>
Date: Wed, 17 Feb 2021 17:08:07 +0100
Subject: [PATCH] drawconnections call is missing / nullpointer exception error
 left

---
 .../ardublock/simulator/Simulator.java        |  23 ---
 .../ardublock/simulator/view/GUI.java         |  19 ++-
 .../simulator/view/modules/ArduinoUno.java    | 138 ++++++++++--------
 .../simulator/view/modules/Button.java        |  13 +-
 .../simulator/view/modules/Modul.java         |   2 +
 .../simulator/view/modules/Poti.java          |  55 ++++---
 .../ardublock/simulator/view/modules/RGB.java |  97 +++++++-----
 7 files changed, 190 insertions(+), 157 deletions(-)

diff --git a/src/tec/letsgoing/ardublock/simulator/Simulator.java b/src/tec/letsgoing/ardublock/simulator/Simulator.java
index 98adcd2..a34761b 100644
--- a/src/tec/letsgoing/ardublock/simulator/Simulator.java
+++ b/src/tec/letsgoing/ardublock/simulator/Simulator.java
@@ -185,29 +185,6 @@ public class Simulator implements Runnable, ActionListener{
 	}
 	
 	
-	public boolean reloadGUI(GUI currentGUI) {
-		
-		
-		
-		
-		//gui.stopThread();
-		
-		this.gui = currentGUI;
-		
-		arduino = new Arduino(currentGUI);
-		currentGUI.connectPins(arduino);
-
-		//guiThread = new Thread(gui);
-		//guiThread.start();
-	
-		for (SimCodeFunction function : functionsCode) {
-			arduino.addFunction(function);
-		}
-		
-		
-		
-		return true;
-	}
 
 	/**
 	 * Führt einen Reset des Arduinos aus und startet diesen neu.
diff --git a/src/tec/letsgoing/ardublock/simulator/view/GUI.java b/src/tec/letsgoing/ardublock/simulator/view/GUI.java
index af3735c..cb2516d 100644
--- a/src/tec/letsgoing/ardublock/simulator/view/GUI.java
+++ b/src/tec/letsgoing/ardublock/simulator/view/GUI.java
@@ -53,8 +53,8 @@ public class GUI extends JFrame implements Runnable, ActionListener {
 	private Modul[] modules = new Modul[4];
 	private volatile boolean stopFlag = false;
 	private JTextArea serialLog = new JTextArea();
-	private static int xscale= 1500;
-	private static int yscale= 1000;
+	private static int xscale= 968;
+	private static int yscale= 968;
 	private JPanel modulPanel;
 	private Container mainPane;
 
@@ -131,7 +131,7 @@ public class GUI extends JFrame implements Runnable, ActionListener {
 				}
 				
 				
-				//updating(simu);
+				updateGUI(xscale, yscale);
 					
 					
 					System.out.println("xScale: " + xscale +  "\tyScale: " + yscale);
@@ -161,23 +161,22 @@ public class GUI extends JFrame implements Runnable, ActionListener {
 	}
 	
 	
-	public void updateGUI(Simulator simu) {
+	public void updateGUI(int xscale, int yscale) {
 		
 		
+		modules[0].updateGUI(xscale, yscale);
+		modules[1].updateGUI(xscale, yscale);
+		modules[2].updateGUI(xscale, yscale);
+		modules[3].updateGUI(xscale, yscale);
+		
 		
-		createGUI(simu);
-	
 		
 		
 		
 	}
 	
 	
-	public void createGUI(Simulator simu) {	
 	
-		
-		
-	}
 
 	/**
 	 * Erzeugt das Controlpanel mit den Steuerungsknöpfen
diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java
index 27edc73..ab6352d 100644
--- a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java
+++ b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java
@@ -30,78 +30,95 @@ public class ArduinoUno extends Modul {
 	Arduino arduino;
 	private boolean ledOn;
 	private int led13 = 0;
+	private JLabel labelPower, chiplabel, label13, labelButton;
+	private ImageIcon chipIcon, chipIcon_temp;
+	private JButton button;
 	private int xscale = GUI.getxscale();
 	private int yscale = GUI.getyscale();
 	
 	public ArduinoUno(ImageIcon _icon, Simulator simu) {
-		// Offset für den Arduino um diesen mehr mittig zu platzieren.
-		int locx = ((int)(0.0516*xscale));
-		int locy = ((int)(0.0517*yscale));
-
-		layerpane.setPreferredSize(new Dimension(((int)(0.606*xscale)) + locx, ((int)(0.432*yscale)) + locy));
-		JLabel chiplabel = new JLabel();
-		ImageIcon chipIcon = _icon;
-		chipIcon = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.606*xscale)), ((int)(0.432*yscale)), Image.SCALE_SMOOTH));
-		chiplabel.setIcon(chipIcon);
-		chiplabel.setSize(((int)(0.606*xscale)), ((int)(0.432*yscale)));
-		chiplabel.setLocation(locx, locy);
-		layerpane.add(chiplabel, 0);
-
-		// Label für die PowerLED
-		JLabel labelPower = new JLabel() {
-			private static final long serialVersionUID = 1L;
-
-			@Override
-			public void paintComponent(Graphics g) {
-				Graphics2D ga = (Graphics2D) g;
-				int transparancy = 0;
-				if (ledOn)
-					transparancy = 220;
-				ga.setPaint(new Color(255, 255, 0, transparancy));
-				ga.fillRect(0, 0,((int)(0.02066*xscale)), ((int)(0.01034*yscale)));
-			}
-
-		};
-
-		labelPower.setLocation(((int)(0.5207*xscale))+locx, ((int)(0.13*yscale))+locy);
-		labelPower.setSize(((int)(0.02066*xscale)), ((int)(0.01034*yscale)));
-		layerpane.add(labelPower, 0);
-
-		// Label für die Pin 13 LED
-		JLabel label13 = new JLabel() {
-			private static final long serialVersionUID = 1L;
-
-			@Override
-			public void paintComponent(Graphics g) {
-				Graphics2D ga = (Graphics2D) g;
-				ga.setPaint(new Color(255, 255, 0, led13 / 4));
-				ga.fillRect(0, 0, ((int)(0.02066*xscale)), ((int)(0.01034*yscale)));
-			}
-
-		};
-
-		label13.setLocation(((int)(0.2655*xscale))+locx, ((int)(0.092*yscale))+locy);
-		label13.setSize(((int)(0.02066*xscale)), ((int)(0.01034*yscale)));
-		layerpane.add(label13, 0);
-
-		// unsichtbarer Resetbutton
-		JButton button = new JButton();
-		button.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale)));
+		chiplabel = new JLabel();
+		chipIcon = _icon;
+		button = new JButton();
 		button.setActionCommand("reset");
 		button.addActionListener(simu);
 		button.setOpaque(false);
 		button.setContentAreaFilled(false);
 		button.setBorderPainted(false);
-
-		JLabel labelButton = new JLabel();
+		
+		labelButton = new JLabel();
 		labelButton.add(button);
-		labelButton.setSize(((int)(0.062*xscale)), ((int)(0.0527*yscale)));
-		labelButton.setLocation(((int)(0.06612*xscale))+locx, ((int)(0.00103*yscale))+locy);
 		layerpane.add(labelButton, 0);
+		
+		updateGUI(xscale, yscale);
 
-		calculatePinPos(locx, locy);
-
 	}
+	
+	@Override
+	public void updateGUI(int xscale, int yscale) {
+		
+		// Offset für den Arduino um diesen mehr mittig zu platzieren.
+				int locx = ((int)(0.0516*xscale));
+				int locy = ((int)(0.0517*yscale));
+				calculatePinPos(locx, locy);
+				layerpane.setPreferredSize(new Dimension(((int)(0.606*xscale)) + locx, ((int)(0.432*yscale)) + locy));
+				
+				chipIcon_temp = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.606*xscale)), ((int)(0.432*yscale)), Image.SCALE_SMOOTH));
+				chiplabel.setIcon(chipIcon_temp);
+				chiplabel.setSize(((int)(0.606*xscale)), ((int)(0.432*yscale)));
+				chiplabel.setLocation(locx, locy);
+				layerpane.add(chiplabel, 0);
+
+				// Label für die PowerLED
+				labelPower = new JLabel() {
+					private static final long serialVersionUID = 1L;
+
+					@Override
+					public void paintComponent(Graphics g) {
+						Graphics2D ga = (Graphics2D) g;
+						int transparancy = 0;
+						if (ledOn)
+							transparancy = 220;
+						ga.setPaint(new Color(255, 255, 0, transparancy));
+						ga.fillRect(0, 0,((int)(0.02066*xscale)), ((int)(0.01034*yscale)));
+					}
+
+				};
+
+				labelPower.setLocation(((int)(0.5207*xscale))+locx, ((int)(0.13*yscale))+locy);
+				labelPower.setSize(((int)(0.02066*xscale)), ((int)(0.01034*yscale)));
+				layerpane.add(labelPower, 0);
+
+				// Label für die Pin 13 LED
+				label13 = new JLabel() {
+					private static final long serialVersionUID = 1L;
+
+					@Override
+					public void paintComponent(Graphics g) {
+						Graphics2D ga = (Graphics2D) g;
+						ga.setPaint(new Color(255, 255, 0, led13 / 4));
+						ga.fillRect(0, 0, ((int)(0.02066*xscale)), ((int)(0.01034*yscale)));
+					}
+
+				};
+
+				label13.setLocation(((int)(0.2655*xscale))+locx, ((int)(0.092*yscale))+locy);
+				label13.setSize(((int)(0.02066*xscale)), ((int)(0.01034*yscale)));
+				layerpane.add(label13, 0);
+
+				// unsichtbarer Resetbutton
+				
+				button.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale)));
+				
+
+				
+				
+				labelButton.setSize(((int)(0.062*xscale)), ((int)(0.0527*yscale)));
+				labelButton.setLocation(((int)(0.06612*xscale))+locx, ((int)(0.00103*yscale))+locy);
+				
+		
+	}
+	
 
 	public void updateModul(Pin pin) {
 		if (pin == pins.get(0))
@@ -149,6 +166,9 @@ public class ArduinoUno extends Modul {
 		 */
 		this.setPinPos(pins);
 	}
+
+	
+
 	
 	
 
diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java
index 7f77fc1..05f4c5d 100644
--- a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java
+++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java
@@ -26,7 +26,7 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
  */
 public class Button extends Modul implements ActionListener {
 	private int[] lastState = { 0, 0, 0 };
-	private ImageIcon iconOff, iconOn, chipIcon;
+	private ImageIcon iconOff, iconOn, chipIcon, chipIcon_temp;
 	private JToggleButton but1, but2, but3;
 	private JLabel chiplabel, label1, label2, label3;
 	private int xscale = GUI.getxscale();
@@ -43,15 +43,18 @@ public class Button extends Modul implements ActionListener {
 		label1 = new JLabel();
 		label2 = new JLabel();
 		label3 = new JLabel();
-		updateButton();
+		updateGUI(xscale, yscale);
 		calculatePinPos();
 	}
 	
-	public void updateButton(){
+	public void updateGUI(int _xscale, int _yscale){
+		
+		this.xscale = _xscale; 
+		this.yscale = _yscale;
 		
 		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);
+		chipIcon_temp = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.3037*xscale)), ((int)(0.304*yscale)), Image.SCALE_SMOOTH));
+		chiplabel.setIcon(chipIcon_temp);
 		chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale)));
 		layerpane.add(chiplabel, 0);
 
diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Modul.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Modul.java
index a290af8..00b8239 100644
--- a/src/tec/letsgoing/ardublock/simulator/view/modules/Modul.java
+++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Modul.java
@@ -56,6 +56,8 @@ public abstract class Modul implements Observer {
 	}
 
 	public abstract void updateModul(Pin pin);
+	
+	public abstract void updateGUI(int xscale, int yscale);
 
 	public void addPin(Pin _pin) {
 		pins.add(_pin);
diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java
index d4325e8..6e829fc 100644
--- a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java
+++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java
@@ -30,47 +30,58 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
  */
 public class Poti extends Modul implements ChangeListener, MouseWheelListener {
 	int value = 0;
-	JSlider slider;
+	private JSlider slider;
+	private JLabel chiplabel;
+	private ImageIcon chipIcon, chipIcon_temp;
+	private JPanel sliderPanel;
+	private Hashtable<Integer, JLabel> labelTable;
 	private int xscale = GUI.getxscale();
 	private int yscale = GUI.getyscale();
 	
 	public Poti(ImageIcon _icon) {
-		layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale))));
-		JLabel chiplabel = new JLabel();
-		ImageIcon chipIcon = _icon;
-		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)));
+		chipIcon = _icon;
+		chiplabel = new JLabel();
+		labelTable = new Hashtable<Integer, JLabel>();
 		slider = new JSlider(JSlider.HORIZONTAL, 0, 1023, 512);
-
 		slider.setMajorTickSpacing(256);
 		slider.setMinorTickSpacing(64);
-		slider.setPaintTicks(true);
-
-		// Erzeuge eine individuelle Slider Beschriftung
-		Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
+		slider.setPaintTicks(true);		
+		
+		// Erzeuge eine individuelle Slider Beschriftung		
 		labelTable.put(new Integer(10), new JLabel("0%"));
 		labelTable.put(new Integer(512), new JLabel("50%"));
 		labelTable.put(new Integer(1023), new JLabel("100%"));
 		slider.setLabelTable(labelTable);
-
 		slider.setPaintLabels(true);
-		slider.setPreferredSize(new Dimension(((int)(0.186*xscale)), ((int)(0.0517*yscale))));
 		slider.setOpaque(false);
 		slider.addChangeListener(this);
 		slider.addMouseWheelListener(this);
-
-		JPanel sliderPanel = new JPanel();
+		sliderPanel = new JPanel();
 		sliderPanel.add(slider);
-		sliderPanel.setSize(((int)(0.2066*xscale)), ((int)(0.0517*yscale)));
-		sliderPanel.setLocation(((int)(0.04855*xscale)), ((int)(0.175*yscale)));
 		sliderPanel.setOpaque(false);
 		layerpane.add(chiplabel, 0);
 		layerpane.add(sliderPanel, 0);
-
+		
+		
+		updateGUI(xscale, yscale);
 		calculatePinPos();
 
+	}
+	
+	@Override
+	public void updateGUI(int xscale, int yscale) {
+		
+		layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale))));				
+
+		chipIcon_temp = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.3037*xscale)), ((int)(0.304*yscale)), Image.SCALE_SMOOTH));
+		chiplabel.setIcon(chipIcon_temp);
+		chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale)));
+		
+		slider.setPreferredSize(new Dimension(((int)(0.186*xscale)), ((int)(0.0517*yscale))));
+		sliderPanel.setSize(((int)(0.2066*xscale)), ((int)(0.0517*yscale)));
+		sliderPanel.setLocation(((int)(0.04855*xscale)), ((int)(0.175*yscale)));
+
+		
 	}
 
 	public void updateModul(Pin arg0) {
@@ -112,4 +123,8 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener {
 		this.setPinPos(pins);
 	}
 
+	
+
+	
+
 }
diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java
index 1d38083..3f3d646 100644
--- a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java
+++ b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java
@@ -28,51 +28,64 @@ public class RGB extends Modul {
 	private int redValue = 0;
 	private int greenValue = 0;
 	private int blueValue = 0;
+	private JLabel chiplabel, ledlabel;
+	private ImageIcon chipIcon, chipIcon_temp;
 	private int xscale = GUI.getxscale();
 	private int yscale = GUI.getyscale();
 
 	public RGB(ImageIcon _icon) {
-		// Erstellen der JLayerPane für das Modul
-		layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale))));
-		JLabel chiplabel = new JLabel();
-		ImageIcon chipIcon = _icon;
-		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, 1);
-
-		// Erzeuge ein JLabel welches das Leuchten der LED darstellt.
-		JLabel ledlabel = new JLabel() {
-			private static final long serialVersionUID = 1L;
-
-			@Override
-			public void paintComponent(Graphics g) {
-				Graphics2D ga = (Graphics2D) g;
-				int transparancy = (int) (Math.max(redValue, Math.max(greenValue, blueValue)) * 0.9);
-				int tredValue = 0, tgreenValue = 0, tblueValue = 0;
-				if (transparancy != 0) {
-					if (redValue > 0)
-						tredValue = map(redValue);
-					if (greenValue > 0)
-						tgreenValue = map(greenValue);
-					if (blueValue > 0)
-						tblueValue = map(blueValue);
-				}
-				// System.out.println(tredValue+" "+ tgreenValue+" "+ tblueValue+" "+
-				// transparancy);
-				ga.setPaint(new Color(tredValue, tgreenValue, tblueValue, transparancy));
-				ga.fillOval(0, 0, ((int)(0.07541*xscale)), ((int)(0.07549*yscale)));
-			}
-
-		};
-
-		// Setze Position des Labels
-		ledlabel.setLocation(((int)(0.11*xscale)), ((int)(0.0383*yscale)));
-		ledlabel.setSize(((int)(0.2066*xscale)), ((int)(0.2068*yscale)));
-		layerpane.add(ledlabel, 0);
+		
+		
+		chiplabel = new JLabel();
+		chipIcon = _icon;
+		
+		updateGUI(xscale, yscale);
 		calculatePinPos();
-
+	}
+	
+	@Override
+	public void updateGUI(int xscale, int yscale) {
+	
+		
+		// Erstellen der JLayerPane für das Modul
+				layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale))));
+				
+				chipIcon_temp = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.3037*xscale)), ((int)(0.304*yscale)), Image.SCALE_SMOOTH));
+				chiplabel.setIcon(chipIcon_temp);
+				chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale)));
+				layerpane.add(chiplabel, 1);
+
+				// Erzeuge ein JLabel welches das Leuchten der LED darstellt.
+				ledlabel = new JLabel() {
+					private static final long serialVersionUID = 1L;
+
+					@Override
+					public void paintComponent(Graphics g) {
+						Graphics2D ga = (Graphics2D) g;
+						int transparancy = (int) (Math.max(redValue, Math.max(greenValue, blueValue)) * 0.9);
+						int tredValue = 0, tgreenValue = 0, tblueValue = 0;
+						if (transparancy != 0) {
+							if (redValue > 0)
+								tredValue = map(redValue);
+							if (greenValue > 0)
+								tgreenValue = map(greenValue);
+							if (blueValue > 0)
+								tblueValue = map(blueValue);
+						}
+						// System.out.println(tredValue+" "+ tgreenValue+" "+ tblueValue+" "+
+						// transparancy);
+						ga.setPaint(new Color(tredValue, tgreenValue, tblueValue, transparancy));
+						ga.fillOval(0, 0, ((int)(0.07541*xscale)), ((int)(0.07549*yscale)));
+					}
+
+				};
+
+				// Setze Position des Labels
+				ledlabel.setLocation(((int)(0.11*xscale)), ((int)(0.0383*yscale)));
+				ledlabel.setSize(((int)(0.2066*xscale)), ((int)(0.2068*yscale)));
+				layerpane.add(ledlabel, 0);
+		
+		
 	}
 
 	/**
@@ -125,4 +138,8 @@ public class RGB extends Modul {
 		this.setPinPos(pins);
 	}
 
+	
+
+	
+
 }
-- 
GitLab