Skip to content
Snippets Groups Projects
Commit 02d16e85 authored by Leon Dieter's avatar Leon Dieter
Browse files

drawconnections call is missing / nullpointer exception error left

parent f01a03cc
No related branches found
No related tags found
No related merge requests found
...@@ -185,29 +185,6 @@ public class Simulator implements Runnable, ActionListener{ ...@@ -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. * Führt einen Reset des Arduinos aus und startet diesen neu.
......
...@@ -53,8 +53,8 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -53,8 +53,8 @@ public class GUI extends JFrame implements Runnable, ActionListener {
private Modul[] modules = new Modul[4]; private Modul[] modules = new Modul[4];
private volatile boolean stopFlag = false; private volatile boolean stopFlag = false;
private JTextArea serialLog = new JTextArea(); private JTextArea serialLog = new JTextArea();
private static int xscale= 1500; private static int xscale= 968;
private static int yscale= 1000; private static int yscale= 968;
private JPanel modulPanel; private JPanel modulPanel;
private Container mainPane; private Container mainPane;
...@@ -131,7 +131,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -131,7 +131,7 @@ public class GUI extends JFrame implements Runnable, ActionListener {
} }
//updating(simu); updateGUI(xscale, yscale);
System.out.println("xScale: " + xscale + "\tyScale: " + yscale); System.out.println("xScale: " + xscale + "\tyScale: " + yscale);
...@@ -161,11 +161,14 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -161,11 +161,14 @@ 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);
...@@ -173,12 +176,8 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -173,12 +176,8 @@ public class GUI extends JFrame implements Runnable, ActionListener {
} }
public void createGUI(Simulator simu) {
}
/** /**
* Erzeugt das Controlpanel mit den Steuerungsknöpfen * Erzeugt das Controlpanel mit den Steuerungsknöpfen
* *
......
...@@ -30,25 +30,47 @@ public class ArduinoUno extends Modul { ...@@ -30,25 +30,47 @@ public class ArduinoUno extends Modul {
Arduino arduino; Arduino arduino;
private boolean ledOn; private boolean ledOn;
private int led13 = 0; 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 xscale = GUI.getxscale();
private int yscale = GUI.getyscale(); private int yscale = GUI.getyscale();
public ArduinoUno(ImageIcon _icon, Simulator simu) { public ArduinoUno(ImageIcon _icon, Simulator simu) {
chiplabel = new JLabel();
chipIcon = _icon;
button = new JButton();
button.setActionCommand("reset");
button.addActionListener(simu);
button.setOpaque(false);
button.setContentAreaFilled(false);
button.setBorderPainted(false);
labelButton = new JLabel();
labelButton.add(button);
layerpane.add(labelButton, 0);
updateGUI(xscale, yscale);
}
@Override
public void updateGUI(int xscale, int yscale) {
// Offset für den Arduino um diesen mehr mittig zu platzieren. // Offset für den Arduino um diesen mehr mittig zu platzieren.
int locx = ((int)(0.0516*xscale)); int locx = ((int)(0.0516*xscale));
int locy = ((int)(0.0517*yscale)); int locy = ((int)(0.0517*yscale));
calculatePinPos(locx, locy);
layerpane.setPreferredSize(new Dimension(((int)(0.606*xscale)) + locx, ((int)(0.432*yscale)) + locy)); layerpane.setPreferredSize(new Dimension(((int)(0.606*xscale)) + locx, ((int)(0.432*yscale)) + locy));
JLabel chiplabel = new JLabel();
ImageIcon chipIcon = _icon; chipIcon_temp = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.606*xscale)), ((int)(0.432*yscale)), Image.SCALE_SMOOTH));
chipIcon = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.606*xscale)), ((int)(0.432*yscale)), Image.SCALE_SMOOTH)); chiplabel.setIcon(chipIcon_temp);
chiplabel.setIcon(chipIcon);
chiplabel.setSize(((int)(0.606*xscale)), ((int)(0.432*yscale))); chiplabel.setSize(((int)(0.606*xscale)), ((int)(0.432*yscale)));
chiplabel.setLocation(locx, locy); chiplabel.setLocation(locx, locy);
layerpane.add(chiplabel, 0); layerpane.add(chiplabel, 0);
// Label für die PowerLED // Label für die PowerLED
JLabel labelPower = new JLabel() { labelPower = new JLabel() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
...@@ -68,7 +90,7 @@ public class ArduinoUno extends Modul { ...@@ -68,7 +90,7 @@ public class ArduinoUno extends Modul {
layerpane.add(labelPower, 0); layerpane.add(labelPower, 0);
// Label für die Pin 13 LED // Label für die Pin 13 LED
JLabel label13 = new JLabel() { label13 = new JLabel() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
...@@ -85,24 +107,19 @@ public class ArduinoUno extends Modul { ...@@ -85,24 +107,19 @@ public class ArduinoUno extends Modul {
layerpane.add(label13, 0); layerpane.add(label13, 0);
// unsichtbarer Resetbutton // unsichtbarer Resetbutton
JButton button = new JButton();
button.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); button.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale)));
button.setActionCommand("reset");
button.addActionListener(simu);
button.setOpaque(false);
button.setContentAreaFilled(false);
button.setBorderPainted(false);
JLabel labelButton = new JLabel();
labelButton.add(button);
labelButton.setSize(((int)(0.062*xscale)), ((int)(0.0527*yscale))); labelButton.setSize(((int)(0.062*xscale)), ((int)(0.0527*yscale)));
labelButton.setLocation(((int)(0.06612*xscale))+locx, ((int)(0.00103*yscale))+locy); labelButton.setLocation(((int)(0.06612*xscale))+locx, ((int)(0.00103*yscale))+locy);
layerpane.add(labelButton, 0);
calculatePinPos(locx, locy);
} }
public void updateModul(Pin pin) { public void updateModul(Pin pin) {
if (pin == pins.get(0)) if (pin == pins.get(0))
ledOn = (pin.getValue() == 1023); ledOn = (pin.getValue() == 1023);
...@@ -152,4 +169,7 @@ public class ArduinoUno extends Modul { ...@@ -152,4 +169,7 @@ public class ArduinoUno extends Modul {
} }
...@@ -26,7 +26,7 @@ import tec.letsgoing.ardublock.simulator.view.GUI; ...@@ -26,7 +26,7 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
*/ */
public class Button extends Modul implements ActionListener { public class Button extends Modul implements ActionListener {
private int[] lastState = { 0, 0, 0 }; private int[] lastState = { 0, 0, 0 };
private ImageIcon iconOff, iconOn, chipIcon; private ImageIcon iconOff, iconOn, chipIcon, chipIcon_temp;
private JToggleButton but1, but2, but3; private JToggleButton but1, but2, but3;
private JLabel chiplabel, label1, label2, label3; private JLabel chiplabel, label1, label2, label3;
private int xscale = GUI.getxscale(); private int xscale = GUI.getxscale();
...@@ -43,15 +43,18 @@ public class Button extends Modul implements ActionListener { ...@@ -43,15 +43,18 @@ public class Button extends Modul implements ActionListener {
label1 = new JLabel(); label1 = new JLabel();
label2 = new JLabel(); label2 = new JLabel();
label3 = new JLabel(); label3 = new JLabel();
updateButton(); updateGUI(xscale, yscale);
calculatePinPos(); 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)))); 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)); chipIcon_temp = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.3037*xscale)), ((int)(0.304*yscale)), Image.SCALE_SMOOTH));
chiplabel.setIcon(chipIcon); chiplabel.setIcon(chipIcon_temp);
chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale))); chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale)));
layerpane.add(chiplabel, 0); layerpane.add(chiplabel, 0);
......
...@@ -57,6 +57,8 @@ public abstract class Modul implements Observer { ...@@ -57,6 +57,8 @@ public abstract class Modul implements Observer {
public abstract void updateModul(Pin pin); public abstract void updateModul(Pin pin);
public abstract void updateGUI(int xscale, int yscale);
public void addPin(Pin _pin) { public void addPin(Pin _pin) {
pins.add(_pin); pins.add(_pin);
} }
......
...@@ -30,49 +30,60 @@ import tec.letsgoing.ardublock.simulator.view.GUI; ...@@ -30,49 +30,60 @@ import tec.letsgoing.ardublock.simulator.view.GUI;
*/ */
public class Poti extends Modul implements ChangeListener, MouseWheelListener { public class Poti extends Modul implements ChangeListener, MouseWheelListener {
int value = 0; 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 xscale = GUI.getxscale();
private int yscale = GUI.getyscale(); private int yscale = GUI.getyscale();
public Poti(ImageIcon _icon) { public Poti(ImageIcon _icon) {
layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale)))); chipIcon = _icon;
JLabel chiplabel = new JLabel(); chiplabel = new JLabel();
ImageIcon chipIcon = _icon; labelTable = new Hashtable<Integer, JLabel>();
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)));
slider = new JSlider(JSlider.HORIZONTAL, 0, 1023, 512); slider = new JSlider(JSlider.HORIZONTAL, 0, 1023, 512);
slider.setMajorTickSpacing(256); slider.setMajorTickSpacing(256);
slider.setMinorTickSpacing(64); slider.setMinorTickSpacing(64);
slider.setPaintTicks(true); slider.setPaintTicks(true);
// Erzeuge eine individuelle Slider Beschriftung // Erzeuge eine individuelle Slider Beschriftung
Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
labelTable.put(new Integer(10), new JLabel("0%")); labelTable.put(new Integer(10), new JLabel("0%"));
labelTable.put(new Integer(512), new JLabel("50%")); labelTable.put(new Integer(512), new JLabel("50%"));
labelTable.put(new Integer(1023), new JLabel("100%")); labelTable.put(new Integer(1023), new JLabel("100%"));
slider.setLabelTable(labelTable); slider.setLabelTable(labelTable);
slider.setPaintLabels(true); slider.setPaintLabels(true);
slider.setPreferredSize(new Dimension(((int)(0.186*xscale)), ((int)(0.0517*yscale))));
slider.setOpaque(false); slider.setOpaque(false);
slider.addChangeListener(this); slider.addChangeListener(this);
slider.addMouseWheelListener(this); slider.addMouseWheelListener(this);
sliderPanel = new JPanel();
JPanel sliderPanel = new JPanel();
sliderPanel.add(slider); 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); sliderPanel.setOpaque(false);
layerpane.add(chiplabel, 0); layerpane.add(chiplabel, 0);
layerpane.add(sliderPanel, 0); layerpane.add(sliderPanel, 0);
updateGUI(xscale, yscale);
calculatePinPos(); 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) { public void updateModul(Pin arg0) {
if (pins.get(0).getValue() != slider.getValue()) { if (pins.get(0).getValue() != slider.getValue()) {
pins.get(0).setValue(slider.getValue()); pins.get(0).setValue(slider.getValue());
...@@ -112,4 +123,8 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener { ...@@ -112,4 +123,8 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener {
this.setPinPos(pins); this.setPinPos(pins);
} }
} }
...@@ -28,22 +28,35 @@ public class RGB extends Modul { ...@@ -28,22 +28,35 @@ public class RGB extends Modul {
private int redValue = 0; private int redValue = 0;
private int greenValue = 0; private int greenValue = 0;
private int blueValue = 0; private int blueValue = 0;
private JLabel chiplabel, ledlabel;
private ImageIcon chipIcon, chipIcon_temp;
private int xscale = GUI.getxscale(); private int xscale = GUI.getxscale();
private int yscale = GUI.getyscale(); private int yscale = GUI.getyscale();
public RGB(ImageIcon _icon) { public RGB(ImageIcon _icon) {
chiplabel = new JLabel();
chipIcon = _icon;
updateGUI(xscale, yscale);
calculatePinPos();
}
@Override
public void updateGUI(int xscale, int yscale) {
// Erstellen der JLayerPane für das Modul // Erstellen der JLayerPane für das Modul
layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale)))); 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); 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))); chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale)));
layerpane.add(chiplabel, 1); layerpane.add(chiplabel, 1);
// Erzeuge ein JLabel welches das Leuchten der LED darstellt. // Erzeuge ein JLabel welches das Leuchten der LED darstellt.
JLabel ledlabel = new JLabel() { ledlabel = new JLabel() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
...@@ -71,7 +84,7 @@ public class RGB extends Modul { ...@@ -71,7 +84,7 @@ public class RGB extends Modul {
ledlabel.setLocation(((int)(0.11*xscale)), ((int)(0.0383*yscale))); ledlabel.setLocation(((int)(0.11*xscale)), ((int)(0.0383*yscale)));
ledlabel.setSize(((int)(0.2066*xscale)), ((int)(0.2068*yscale))); ledlabel.setSize(((int)(0.2066*xscale)), ((int)(0.2068*yscale)));
layerpane.add(ledlabel, 0); layerpane.add(ledlabel, 0);
calculatePinPos();
} }
...@@ -125,4 +138,8 @@ public class RGB extends Modul { ...@@ -125,4 +138,8 @@ public class RGB extends Modul {
this.setPinPos(pins); this.setPinPos(pins);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment