From 2781b8d0163edfda39b27bb728d5c692d7753d14 Mon Sep 17 00:00:00 2001 From: Leon Dieter <Leon Dieter@DESKTOP-L4JC8N4> Date: Sun, 20 Dec 2020 17:44:52 +0100 Subject: [PATCH] =?UTF-8?q?Buttons,=20Module,=20Poti=20und=20RGB=20skalier?= =?UTF-8?q?f=C3=A4hig=20gemacht.=20UPDATEfunktion=20fehlt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ardublock/simulator/Simulator.java | 12 ++- .../ardublock/simulator/view/GUI.java | 96 ++++++++++++++----- .../simulator/view/modules/ArduinoUno.java | 41 ++++---- .../simulator/view/modules/Button.java | 31 +++--- .../simulator/view/modules/Poti.java | 20 ++-- .../ardublock/simulator/view/modules/RGB.java | 20 ++-- 6 files changed, 152 insertions(+), 68 deletions(-) diff --git a/src/tec/letsgoing/ardublock/simulator/Simulator.java b/src/tec/letsgoing/ardublock/simulator/Simulator.java index b8c2da0..85e17dc 100644 --- a/src/tec/letsgoing/ardublock/simulator/Simulator.java +++ b/src/tec/letsgoing/ardublock/simulator/Simulator.java @@ -6,6 +6,8 @@ package tec.letsgoing.ardublock.simulator; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; import java.util.Vector; import javax.swing.UIManager; @@ -37,7 +39,7 @@ import tec.letsgoing.ardublock.simulator.view.GUI; * * */ -public class Simulator implements Runnable, ActionListener { +public class Simulator implements Runnable, ActionListener{ private static Simulator instance; private Arduino arduino; private GUI gui; @@ -51,6 +53,7 @@ public class Simulator implements Runnable, ActionListener { * direkt aufgerufen werden. */ private Simulator() { + try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); @@ -247,7 +250,12 @@ public class Simulator implements Runnable, ActionListener { } } + + + + + /** * Demo-Main Funktion. Nicht Teil des normalen Simulators. * @@ -304,4 +312,6 @@ public class Simulator implements Runnable, ActionListener { } + + } diff --git a/src/tec/letsgoing/ardublock/simulator/view/GUI.java b/src/tec/letsgoing/ardublock/simulator/view/GUI.java index d4b26d9..b48ae31 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/GUI.java +++ b/src/tec/letsgoing/ardublock/simulator/view/GUI.java @@ -15,6 +15,9 @@ import java.awt.Point; import java.awt.Stroke; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; import java.util.Vector; import javax.swing.Box; @@ -50,6 +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= 700; + private static int yscale= 700; /** * Konstruktor der Klasse GUI @@ -58,27 +63,58 @@ public class GUI extends JFrame implements Runnable, ActionListener { */ public GUI(Simulator simu) { super("ArduBlock Simulator"); + this.addComponentListener(new ComponentListener() { + @Override + public void componentResized(ComponentEvent e) { + System.out.println("test"); + + + xscale = getWidth(); + yscale = getHeight(); + + } + + @Override + public void componentMoved(ComponentEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void componentShown(ComponentEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void componentHidden(ComponentEvent e) { + // TODO Auto-generated method stub + + } + + }); + // Konstruktor der Module modules[0] = new RGB(new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM31_RGB_LED.png")))); + .getImage(GUI.class.getResource("img/PM31_RGB_LED.png")))); modules[1] = new Button( new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM26_Taster.png"))), + .getImage(GUI.class.getResource("img/PM26_Taster.png"))), new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Taster_Off.png"))), + .getImage(GUI.class.getResource("img/Taster_Off.png"))), new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Taster_On.png")))); + .getImage(GUI.class.getResource("img/Taster_On.png")))); modules[2] = new Poti(new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM24_Potentiometer.png")))); + .getImage(GUI.class.getResource("img/PM24_Potentiometer.png")))); modules[3] = new ArduinoUno( new ImageIcon(getToolkit() - .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/ArduinoUno.png"))), + .getImage(GUI.class.getResource("img/ArduinoUno.png"))), simu); // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Vermutlich nicht // gew�nscht. - this.setResizable(false); //TODO Muss in true ge�ndert werden wenn skalierbar + this.setResizable(true); //TODO Muss in true ge�ndert werden wenn skalierbar Container mainPane = this.getContentPane(); @@ -103,7 +139,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { mainPane.add(createControlPanel(simu), BorderLayout.LINE_END); mainPane.add(createSerialLog(), BorderLayout.PAGE_END); this.pack(); - // this.setLocation(-1300, 0); //Möglichkeit die Renderingposition festzulegen + // this.setLocation(-1300, 0); //M�glichkeit die Renderingposition festzulegen this.setVisible(true); } @@ -124,13 +160,13 @@ public class GUI extends JFrame implements Runnable, ActionListener { JButton measButton = new JButton(); goButton.setIcon(new ImageIcon( - getToolkit().getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Play.png")))); + getToolkit().getImage(GUI.class.getResource("img/Play.png")))); stopButton.setIcon(new ImageIcon( - getToolkit().getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Stop.png")))); + getToolkit().getImage(GUI.class.getResource("img/Stop.png")))); reloadButton.setIcon(new ImageIcon( - getToolkit().getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Reload.png")))); + getToolkit().getImage(GUI.class.getResource("img/Reload.png")))); measButton.setIcon(new ImageIcon( - getToolkit().getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Measure.png")))); + getToolkit().getImage(GUI.class.getResource("img/Measure.png")))); goButton.addActionListener(simu); stopButton.addActionListener(simu); @@ -192,9 +228,9 @@ public class GUI extends JFrame implements Runnable, ActionListener { // Zeichne die Stromversorgung for (int i = -1; i < 2; i++) { g.setColor(Color.BLACK); - g.fillRect(i * 294 + 261, 183, 60, 5); + g.fillRect(i * ((int)(0.30372*xscale)) + ((int)(0.2699*xscale)), ((int)(0.18924*yscale)), ((int)(0.062*xscale)), ((int)(0.00516*yscale))); g.setColor(Color.RED); - g.fillRect(i * 294 + 261, 211, 60, 5); + g.fillRect(i * ((int)(0.30372*xscale)) + ((int)(0.2699*xscale)), ((int)(0.2182*yscale)), ((int)(0.062*xscale)), ((int)(0.00516*yscale))); } // Zeichne die Signalleitungen @@ -212,24 +248,24 @@ public class GUI extends JFrame implements Runnable, ActionListener { if (counter > 5) { // Fall für die analoge Signalleitung g2.drawLine(p.x + modules[i].getPosition().x, p.y + modules[i].getPosition().y, p.x + modules[i].getPosition().x, - pinArduino.get(assignment[counter]).y + posArduino.y - 40); + pinArduino.get(assignment[counter]).y + posArduino.y - ((int)(0.0414*yscale))); g2.drawLine(p.x + modules[i].getPosition().x, - pinArduino.get(assignment[counter]).y + posArduino.y - 40, + pinArduino.get(assignment[counter]).y + posArduino.y - ((int)(0.0414*yscale)), pinArduino.get(assignment[counter]).x + posArduino.x, - pinArduino.get(assignment[counter]).y + posArduino.y - 40); + pinArduino.get(assignment[counter]).y + posArduino.y - ((int)(0.0414*yscale))); g2.drawLine(pinArduino.get(assignment[counter]).x + posArduino.x, - pinArduino.get(assignment[counter]).y + posArduino.y - 40, + pinArduino.get(assignment[counter]).y + posArduino.y - ((int)(0.0414*yscale)), pinArduino.get(assignment[counter]).x + posArduino.x, pinArduino.get(assignment[counter]).y + posArduino.y); } else { // Alle anderen Signalleitungen g2.drawLine(p.x + modules[i].getPosition().x, p.y + modules[i].getPosition().y, - p.x + modules[i].getPosition().x, p.y + modules[i].getPosition().y + 90 - (counter) * 10); + p.x + modules[i].getPosition().x, p.y + modules[i].getPosition().y + ((int)(0.09298*yscale)) - (counter) * ((int)(0.01033*yscale))); g2.drawLine(p.x + modules[i].getPosition().x, - p.y + modules[i].getPosition().y + 90 - (counter) * 10, + p.y + modules[i].getPosition().y + ((int)(0.09298*yscale)) - (counter) * ((int)(0.01033*yscale)), pinArduino.get(assignment[counter]).x + posArduino.x, - p.y + modules[i].getPosition().y + 90 - (counter) * 10); + p.y + modules[i].getPosition().y + ((int)(0.09298*yscale)) - (counter) * ((int)(0.01033*yscale))); g2.drawLine(pinArduino.get(assignment[counter]).x + posArduino.x, - p.y + modules[i].getPosition().y + 90 - (counter) * 10, + p.y + modules[i].getPosition().y + ((int)(0.09298*yscale)) - (counter) * ((int)(0.01033*yscale)), pinArduino.get(assignment[counter]).x + posArduino.x, pinArduino.get(assignment[counter]).y + posArduino.y); } @@ -291,6 +327,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { } public void actionPerformed(ActionEvent arg0) { + if (arg0.getActionCommand() == "clearSerial") { serialprint.clear(); serialLog.setText(""); @@ -305,5 +342,20 @@ public class GUI extends JFrame implements Runnable, ActionListener { } } + + public static int getxscale() { + + return xscale; + } + + public static int getyscale() { + + return yscale; + } + + + + + } diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java index 65b3873..27edc73 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java @@ -18,6 +18,7 @@ import javax.swing.JLabel; import tec.letsgoing.ardublock.simulator.Simulator; import tec.letsgoing.ardublock.simulator.arduino.Arduino; import tec.letsgoing.ardublock.simulator.arduino.Pin; +import tec.letsgoing.ardublock.simulator.view.GUI; /** * Modul für einen Arduino Uno @@ -29,18 +30,20 @@ public class ArduinoUno extends Modul { Arduino arduino; private boolean ledOn; private int led13 = 0; - + 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 = 50; - int locy = 50; + int locx = ((int)(0.0516*xscale)); + int locy = ((int)(0.0517*yscale)); - layerpane.setPreferredSize(new Dimension(587 + locx, 418 + locy)); + 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(587, 418, Image.SCALE_SMOOTH)); + chipIcon = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.606*xscale)), ((int)(0.432*yscale)), Image.SCALE_SMOOTH)); chiplabel.setIcon(chipIcon); - chiplabel.setSize(587, 418); + chiplabel.setSize(((int)(0.606*xscale)), ((int)(0.432*yscale))); chiplabel.setLocation(locx, locy); layerpane.add(chiplabel, 0); @@ -55,13 +58,13 @@ public class ArduinoUno extends Modul { if (ledOn) transparancy = 220; ga.setPaint(new Color(255, 255, 0, transparancy)); - ga.fillRect(0, 0, 20, 10); + ga.fillRect(0, 0,((int)(0.02066*xscale)), ((int)(0.01034*yscale))); } }; - labelPower.setLocation(504 + locx, 126 + locy); - labelPower.setSize(20, 20); + 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 @@ -72,18 +75,18 @@ public class ArduinoUno extends Modul { public void paintComponent(Graphics g) { Graphics2D ga = (Graphics2D) g; ga.setPaint(new Color(255, 255, 0, led13 / 4)); - ga.fillRect(0, 0, 20, 10); + ga.fillRect(0, 0, ((int)(0.02066*xscale)), ((int)(0.01034*yscale))); } }; - label13.setLocation(257 + locx, 89 + locy); - label13.setSize(20, 20); + 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(70, 70); + button.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); button.setActionCommand("reset"); button.addActionListener(simu); button.setOpaque(false); @@ -92,8 +95,8 @@ public class ArduinoUno extends Modul { JLabel labelButton = new JLabel(); labelButton.add(button); - labelButton.setSize(60, 51); - labelButton.setLocation(64 + locx, 1 + locy); + 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); calculatePinPos(locx, locy); @@ -125,11 +128,11 @@ public class ArduinoUno extends Modul { int offset = 0; for (int i = 15; i > 1; i--) { if (i < 8) - offset = -11; - pins.add(new Point(i * 20 + locx + 246 + offset, locy + 19)); + offset = -((int)(0.01136*xscale)); + pins.add(new Point(i * ((int)(0.02066*xscale)) + locx + ((int)(0.2541*xscale)) + offset, locy + ((int)(0.01965*yscale)))); } for (int i = 0; i < 6; i++) { - pins.add(new Point(i * 20 + locx + 447, locy + 397)); + pins.add(new Point(i * ((int)(0.02066*xscale)) + locx + ((int)(0.46178*xscale)), locy + ((int)(0.41054*yscale)))); } // Dieser Code malt kleine Rechtecke an die PinPositionen um sie besser zu // überprüfen. @@ -146,5 +149,7 @@ 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 a49fe3c..501945d 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java @@ -4,6 +4,7 @@ package tec.letsgoing.ardublock.simulator.view.modules; import java.awt.Dimension; +import java.awt.Image; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -15,6 +16,7 @@ import javax.swing.JToggleButton; import tec.letsgoing.ardublock.simulator.arduino.Arduino; import tec.letsgoing.ardublock.simulator.arduino.Pin; +import tec.letsgoing.ardublock.simulator.view.GUI; /** * Modul mit 3 Toogle Buttons @@ -25,46 +27,49 @@ import tec.letsgoing.ardublock.simulator.arduino.Pin; public class Button extends Modul implements ActionListener { private int[] lastState = { 0, 0, 0 }; private ImageIcon iconOff, iconOn; - + private int xscale = GUI.getxscale(); + private int yscale = GUI.getyscale(); + public Button(ImageIcon _icon, ImageIcon _icon1, ImageIcon _icon2) { iconOff = _icon1; iconOn = _icon2; - layerpane.setPreferredSize(new Dimension(294, 294)); + 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(294, 294); + chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale))); layerpane.add(chiplabel, 0); JToggleButton but1 = new JToggleButton(); - but1.setSize(70, 70); + 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(70, 70); - label1.setLocation(29, 64); + 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(70, 70); + 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(70, 70); - label2.setLocation(111, 35); + 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(70, 70); + 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(70, 70); - label3.setLocation(194, 64); + label3.setSize(((int)(0.0723*xscale)), ((int)(0.0724*yscale))); + label3.setLocation(((int)(0.200*xscale)), ((int)(0.06618*yscale))); layerpane.add(label1, 0); layerpane.add(label2, 0); @@ -121,7 +126,7 @@ public class Button extends Modul implements ActionListener { private void calculatePinPos() { Vector<Point> pins = new Vector<Point>(); for (int i = 0; i < 3; i++) { - pins.add(new Point(i * 30 + 117, 235)); + pins.add(new Point(i * ((int)(0.031*xscale)) + ((int)(0.1209*xscale)), ((int)(0.243*yscale)))); } this.setPinPos(pins); } diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java index 3b326a1..d4325e8 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java @@ -4,6 +4,7 @@ package tec.letsgoing.ardublock.simulator.view.modules; import java.awt.Dimension; +import java.awt.Image; import java.awt.Point; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; @@ -19,6 +20,7 @@ import javax.swing.event.ChangeListener; import tec.letsgoing.ardublock.simulator.arduino.Arduino; import tec.letsgoing.ardublock.simulator.arduino.Pin; +import tec.letsgoing.ardublock.simulator.view.GUI; /** * Modul mit einem Potentiometer @@ -29,13 +31,17 @@ import tec.letsgoing.ardublock.simulator.arduino.Pin; public class Poti extends Modul implements ChangeListener, MouseWheelListener { int value = 0; JSlider slider; - + private int xscale = GUI.getxscale(); + private int yscale = GUI.getyscale(); + public Poti(ImageIcon _icon) { - layerpane.setPreferredSize(new Dimension(294, 294)); + 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(294, 294); + chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale))); slider = new JSlider(JSlider.HORIZONTAL, 0, 1023, 512); slider.setMajorTickSpacing(256); @@ -50,15 +56,15 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener { slider.setLabelTable(labelTable); slider.setPaintLabels(true); - slider.setPreferredSize(new Dimension(180, 50)); + 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.add(slider); - sliderPanel.setSize(200, 50); - sliderPanel.setLocation(47, 170); + 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); @@ -102,7 +108,7 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener { private void calculatePinPos() { Vector<Point> pins = new Vector<Point>(); - pins.add(new Point(30 + 117, 235)); + pins.add(new Point(((int)(0.1519*xscale)), ((int)(0.243*yscale)))); 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 2ae27da..1d38083 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java @@ -7,6 +7,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Image; import java.awt.Point; import java.util.Vector; @@ -15,6 +16,7 @@ import javax.swing.JLabel; import tec.letsgoing.ardublock.simulator.arduino.Arduino; import tec.letsgoing.ardublock.simulator.arduino.Pin; +import tec.letsgoing.ardublock.simulator.view.GUI; /** * Modul mit einer RGB LED @@ -26,14 +28,18 @@ public class RGB extends Modul { private int redValue = 0; private int greenValue = 0; private int blueValue = 0; + 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(294, 294)); + 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(294, 294); + chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale))); layerpane.add(chiplabel, 1); // Erzeuge ein JLabel welches das Leuchten der LED darstellt. @@ -56,21 +62,21 @@ public class RGB extends Modul { // System.out.println(tredValue+" "+ tgreenValue+" "+ tblueValue+" "+ // transparancy); ga.setPaint(new Color(tredValue, tgreenValue, tblueValue, transparancy)); - ga.fillOval(0, 0, 73, 73); + ga.fillOval(0, 0, ((int)(0.07541*xscale)), ((int)(0.07549*yscale))); } }; // Setze Position des Labels - ledlabel.setLocation(107, 37); - ledlabel.setSize(200, 200); + ledlabel.setLocation(((int)(0.11*xscale)), ((int)(0.0383*yscale))); + ledlabel.setSize(((int)(0.2066*xscale)), ((int)(0.2068*yscale))); layerpane.add(ledlabel, 0); calculatePinPos(); } /** - * Funktion, welche die Pin Änderungen entgegen nimmt und verarbeitet. + * Funktion, welche die Pin �nderungen entgegen nimmt und verarbeitet. */ public void updateModul(Pin pin) { if (pin == pins.get(0)) @@ -114,7 +120,7 @@ public class RGB extends Modul { private void calculatePinPos() { Vector<Point> pins = new Vector<Point>(); for (int i = 0; i < 3; i++) { - pins.add(new Point(i * 30 + 117, 235)); + pins.add(new Point(i * ((int)(0.03099*xscale)) + ((int)(0.12087*xscale)), ((int)(0.243*yscale)))); } this.setPinPos(pins); } -- GitLab