diff --git a/UML.dia b/UML.dia index 6f33a4c400cee424817c34093c0c7f55ad92a964..c30ba857e61c2a94a2541f847d2e4ae08143bfa3 100644 Binary files a/UML.dia and b/UML.dia differ diff --git a/src/tec/letsgoing/ardublock/simulator/Simulator.java b/src/tec/letsgoing/ardublock/simulator/Simulator.java index 9a75e78f2d740bd5703175035cf275bc56b92550..1dd934441e66cfc35adaff17a5885f1287a76e8b 100644 --- a/src/tec/letsgoing/ardublock/simulator/Simulator.java +++ b/src/tec/letsgoing/ardublock/simulator/Simulator.java @@ -40,14 +40,17 @@ import tec.letsgoing.ardublock.simulator.view.GUI; * */ public class Simulator implements Runnable, ActionListener{ + + private static final int X_SCALE = 800; + private static final int Y_SCALE = 800; + private static Simulator instance; private Arduino arduino; private GUI gui; private Thread guiThread; private Thread simuThread; private Vector<SimCodeFunction> functionsCode = new Vector<SimCodeFunction>(); - private final int xscale = 800; - private final int yscale = 800; + /** * Privater Konstruktor der Klasse Simulator<br> * Die Klasse ist als Singelton geschrieben, daher sollte diese Konstruktor nie @@ -67,7 +70,7 @@ public class Simulator implements Runnable, ActionListener{ } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } - createSubClasses(xscale, yscale); + createSubClasses(X_SCALE, Y_SCALE, null); } @@ -95,8 +98,8 @@ public class Simulator implements Runnable, ActionListener{ * * @return true */ - private boolean createSubClasses(int _xscale, int _yscale) { - gui = new GUI(this, _xscale, _yscale); + private boolean createSubClasses(int _xscale, int _yscale, Point _windowLocation) { + gui = new GUI(this, _xscale, _yscale, _windowLocation); arduino = new Arduino(gui); gui.connectPins(arduino); @@ -179,9 +182,8 @@ public class Simulator implements Runnable, ActionListener{ Point locationWindow = gui.getLocation(); -// int widthWindow = ((int)((gui.getWidth() * 1.0975) - 13.307)); -// int heightWindow = ((int)((gui.getHeight() * 1.2709) - 174.77)); + //Bei unterschiedlicher //Die bisherige Größe des Fenster wird abgespeichert int widthWindow = gui.getWidth(); int heightWindow = gui.getHeight(); @@ -191,9 +193,9 @@ public class Simulator implements Runnable, ActionListener{ //Die neue Objekte werden mit den gespeicherten Werten erzeugt - createSubClasses(widthWindow, heightWindow); + createSubClasses(widthWindow, heightWindow, locationWindow); //die GUI wird an die gespeicherte Position verschoben - gui.setLocation(locationWindow); + for (SimCodeFunction function : functionsCode) { diff --git a/src/tec/letsgoing/ardublock/simulator/view/GUI.java b/src/tec/letsgoing/ardublock/simulator/view/GUI.java index d721bda333f9ca8097a57abcde3e978b45ebfa1c..5e98f8fbdd90c77550417e074b1b4989e9602539 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/GUI.java +++ b/src/tec/letsgoing/ardublock/simulator/view/GUI.java @@ -49,13 +49,23 @@ import tec.letsgoing.ardublock.simulator.view.modules.RGB; * */ public class GUI extends JFrame implements Runnable, ActionListener { + private static final int SCALING_OFFSET = 100; //wird für die Skalierung des Arduinos benötigt + private static final int UPDATE_GAP = 10; //Legt fest wie groß eine Fenstergrößenänderung sein muss um eine Fensteraktualisierungen durchzuführen private static final long serialVersionUID = 1L; - private static final int MAXIMUM_MESSAGES = 100; // Anzahl der Seriellen Nachrichten - private Vector<String> serialprint = new Vector<String>(); - private Modul[] modules = new Modul[4]; - private volatile boolean stopFlag = false; - private JTextArea serialLog = new JTextArea(); - private JPanel botControlPanel, topControlPanel, controlPanel, panel, topPanel; + private static final int MAXIMUM_MESSAGES = 100; // Anzahl der Seriellen Nachrichten + private static final int WINDOW_SIZE_MIN_X = 200; + private static final int WINDOW_SIZE_MIN_Y = 200; + + private Vector<String> serialprint = new Vector<String>(); + private Modul[] modules = new Modul[4]; + private volatile boolean stopFlag = false; + private JTextArea serialLog = new JTextArea(); + private JPanel botControlPanel; + private JPanel topControlPanel; + private JPanel controlPanel; + private JPanel panel; + private JPanel topPanel; + private JPanel modulPanel; private JButton goButton; private JButton stopButton; private JButton reloadButton; @@ -63,13 +73,11 @@ public class GUI extends JFrame implements Runnable, ActionListener { private JButton clearButton; private JCheckBox checkBox; private JScrollPane scrollPane; + private Container mainPane; private int xscale; private int yscale; - private JPanel modulPanel; - private Container mainPane; - private int windowHeight, windowWidth; - private final int scalingOffset = 100; //wird für die Skalierung des Arduinos benötigt - private final int updateGap = 10; //Legt fest wie groß eine Fenstergrößenänderung sein muss um eine Fensteraktualisierungen durchzuführen + private int windowHeight; + private int windowWidth; /** @@ -77,18 +85,18 @@ public class GUI extends JFrame implements Runnable, ActionListener { * * @param simu Instanz des Simulators */ - public GUI(Simulator simu, int _xscale, int _yscale) { + public GUI(Simulator simu, int _xscale, int _yscale, Point _windowLocation) { super("ArduBlock Simulator"); //Das Fenster wird gemäß des kleineren Seitenverhältnisses erstellt - if(_xscale <= _yscale - scalingOffset) { + if(_xscale <= _yscale - SCALING_OFFSET) { xscale = _xscale; yscale = _xscale; } else { - xscale = _yscale - scalingOffset; - yscale = _yscale - scalingOffset; + xscale = _yscale - SCALING_OFFSET; + yscale = _yscale - SCALING_OFFSET; } @@ -97,7 +105,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { // Konstruktor der Module modules[0] = new RGB(new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM31_RGB_LED.png"))), xscale, yscale); + .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM31_RGB_LED.png"))), xscale, yscale); modules[1] = new Button( new ImageIcon(getToolkit() .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM26_Taster.png"))), @@ -146,12 +154,15 @@ public class GUI extends JFrame implements Runnable, ActionListener { //mainPane.add(createControlPanel(simu), BorderLayout.EAST); mainPane.add(createSerialLog(), BorderLayout.PAGE_END); - //Die Fenstergröße wird mit der dem Konstruktor übergebenen Größe festgelegt - super.setSize(_xscale, _yscale); + if(_windowLocation != null) { + setLocation(_windowLocation); + } + //Die Fenstergröße wird mit der dem Konstruktor übergebenen Größe festgelegt + setSize(_xscale, _yscale); //Eine Minimum Fenstergröße wird festgelegt - super.setMinimumSize(new Dimension(200, 200)); + setMinimumSize(new Dimension(WINDOW_SIZE_MIN_X, WINDOW_SIZE_MIN_Y)); // this.setLocation(-1300, 0); //Möglichkeit die Renderingposition festzulegen - super.setVisible(true); + setVisible(true); //Eine Aktualisierung der GUI gemäß den übergebenen Seitenverhältnissen wird aufgerufen. updateGUI(xscale, yscale); @@ -161,12 +172,10 @@ public class GUI extends JFrame implements Runnable, ActionListener { @Override public void componentResized(ComponentEvent e) { - - //Das Fenster soll erst dann upgedatet werden wenn eine Größenänderung größer 5 stattgefunden hat //um zu verhindern dass die update Funktion durch ein zu häufiges Aufrufen das Programm aufhängt. - if((Math.abs(windowHeight - getHeight()) > updateGap) || (Math.abs(windowWidth - getWidth()) > updateGap)) { + if((Math.abs(windowHeight - getHeight()) > UPDATE_GAP) || (Math.abs(windowWidth - getWidth()) > UPDATE_GAP)) { //Die aktuelle Fenstergröße wird abgespeichert windowHeight = getHeight(); @@ -174,13 +183,13 @@ public class GUI extends JFrame implements Runnable, ActionListener { //GUI wird nur gleichmäßig skaliert mit den Größen des kleineren Seitenverhätlnisses - if(windowWidth <= windowHeight - scalingOffset) { + if(windowWidth <= windowHeight - SCALING_OFFSET) { xscale = windowWidth; yscale = windowWidth; } else { - xscale = windowHeight - scalingOffset; - yscale = windowHeight - scalingOffset; + xscale = windowHeight - SCALING_OFFSET; + yscale = windowHeight - SCALING_OFFSET; } //GUI wird upgedatet diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java index ecd583550519f66df927e4ffe8cbc138d04be217..8547bff1044b6d8d9a131672c08163327029f49b 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java @@ -29,9 +29,13 @@ import tec.letsgoing.ardublock.simulator.view.GUI; 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 int led13 = 0; + private JLabel labelPower; + private JLabel chiplabel; + private JLabel label13; + private JLabel labelButton; + private ImageIcon chipIcon; + private ImageIcon chipIcon_temp; private JButton button; diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java index 6f88c152801c1effb50e63c4ce35d64f9e66be41..1d4306211ffee27b534b8e8d5b91c4c882962bea 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java @@ -27,22 +27,33 @@ import tec.letsgoing.ardublock.simulator.arduino.Pin; * */ public class Button extends Modul implements ActionListener, MouseListener { - private int[] lastState = { 0, 0, 0 }; - private ImageIcon iconOff, iconOn, chipIcon, chipIcon_temp, iconOff_temp, iconOn_temp; + private int[] lastState = { 0, 0, 0 }; + private ImageIcon iconOff; + private ImageIcon iconOn; + private ImageIcon chipIcon; + private ImageIcon chipIcon_temp; + private ImageIcon iconOff_temp; + private ImageIcon iconOn_temp; //private JToggleButton but1, but2, but3; - private JLabel chiplabel, label1, label2, label3; - private LockButton but1, but2, but3; + private JLabel chiplabel; + private JLabel label1; + private JLabel label2; + private JLabel label3; + private LockButton but1; + private LockButton but2; + private LockButton but3; + private class LockButton extends JButton { private static final long serialVersionUID = 1L; - private boolean clicked = false; - private boolean locked = false; + private boolean clicked = false; + private boolean locked = false; private int pin; - private int value = 0; - private static final String BTN_TOOLTIP = "Linksklick -> Taster | Rechtsklick -> Schalter"; + private int value = 0; + private static final String BTN_TOOLTIP = "Linksklick -> Taster | Rechtsklick -> Schalter"; LockButton(int _pin){//ImageIcon _iconOn, ImageIcon _iconOff){ pin = _pin; diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Modul.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Modul.java index 18c9b59cf843e7362a9db11752afecc2adb681bf..beaf002439730e8d4beb0a0dfe1c7a91cad8a0ef 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Modul.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Modul.java @@ -20,12 +20,13 @@ import tec.letsgoing.ardublock.simulator.arduino.Pin; * */ public abstract class Modul implements Observer { - private boolean active = true; + private boolean active = true; private Point position; - protected Vector<Pin> pins = new Vector<Pin>(); + protected Vector<Pin> pins = new Vector<Pin>(); protected JLayeredPane layerpane = new JLayeredPane(); - protected Vector<Point> pinPos = new Vector<Point>(); - protected int xscale, yscale; + protected Vector<Point> pinPos = new Vector<Point>(); + protected int xscale; + protected int yscale; public void setState(boolean State) { active = State; diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java index 496c10f9299249bdcffb4ed656f46b0db4e27a4e..72af13c64aea4ca54e297a3b26ed050fe991feef 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java @@ -30,10 +30,14 @@ import tec.letsgoing.ardublock.simulator.view.GUI; * */ public class Poti extends Modul implements ChangeListener, MouseWheelListener { - int value = 0; + int value = 0; private JSlider slider; - private JLabel chiplabel, sliderlabel1, sliderlabel2, sliderlabel3; - private ImageIcon chipIcon, chipIcon_temp; + private JLabel chiplabel; + private JLabel sliderlabel1; + private JLabel sliderlabel2; + private JLabel sliderlabel3; + private ImageIcon chipIcon; + private ImageIcon chipIcon_temp; private JPanel sliderPanel; private Hashtable<Integer, JLabel> labelTable; diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java index 9627774663e0ff21e1b5ffb4d4661ad373abee95..dbd6b049b053ddab544942077699bb438eb3d23a 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java @@ -25,12 +25,17 @@ import tec.letsgoing.ardublock.simulator.view.GUI; * */ public class RGB extends Modul { - private int redValue = 0; - private int greenValue = 0; - private int blueValue = 0; - private int transparancy, tredValue, tgreenValue, tblueValue; - private JLabel chiplabel, ledlabel; - private ImageIcon chipIcon, chipIcon_temp; + private int redValue = 0; + private int greenValue = 0; + private int blueValue = 0; + private int transparancy; + private int tredValue; + private int tgreenValue; + private int tblueValue; + private JLabel chiplabel; + private JLabel ledlabel; + private ImageIcon chipIcon; + private ImageIcon chipIcon_temp; public RGB(ImageIcon _icon, int _xscale, int _yscale) {