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

correctly resizing windows in progress..

parent 122c3d58
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,8 @@ import java.awt.Dimension; ...@@ -11,6 +11,8 @@ import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Point; import java.awt.Point;
import java.awt.Stroke; import java.awt.Stroke;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
...@@ -53,6 +55,14 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -53,6 +55,14 @@ 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 JPanel botControlPanel, topControlPanel, controlPanel, panel, topPanel;
private JButton goButton;
private JButton stopButton;
private JButton reloadButton;
private JButton measButton;
private JButton clearButton;
private JCheckBox checkBox;
private JScrollPane scrollPane;
private static int xscale= 968; private static int xscale= 968;
private static int yscale= 968; private static int yscale= 968;
private JPanel modulPanel; private JPanel modulPanel;
...@@ -86,17 +96,22 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -86,17 +96,22 @@ public class GUI extends JFrame implements Runnable, ActionListener {
// gew�nscht. // gew�nscht.
this.setResizable(true); //TODO Muss in true ge�ndert werden wenn skalierbar this.setResizable(true); //TODO Muss in true ge�ndert werden wenn skalierbar
createControlPanel(simu);
mainPane = this.getContentPane(); mainPane = this.getContentPane();
topPanel = new JPanel(new GridBagLayout());
// Panel welches alle Module sowie die Verdrahtung enth�lt. // Panel welches alle Module sowie die Verdrahtung enth�lt.
modulPanel = new JPanel(new BorderLayout()) { modulPanel = new JPanel(new BorderLayout()) {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
public void paint(Graphics g) { public void paint(Graphics g) {
super.paint(g); super.paint(g);
drawConnections(g); // Zeichne Verdrahtung drawConnections(g); // Zeichne Verdrahtung
} }
}; };
...@@ -105,10 +120,10 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -105,10 +120,10 @@ public class GUI extends JFrame implements Runnable, ActionListener {
modulPanel.add(modules[1].getPane(), BorderLayout.CENTER); modulPanel.add(modules[1].getPane(), BorderLayout.CENTER);
modulPanel.add(modules[2].getPane(), BorderLayout.EAST); modulPanel.add(modules[2].getPane(), BorderLayout.EAST);
modulPanel.add(modules[3].getPane(), BorderLayout.PAGE_END); modulPanel.add(modules[3].getPane(), BorderLayout.PAGE_END);
topPanel.add(modulPanel);
mainPane.add(modulPanel, BorderLayout.CENTER); mainPane.add(topPanel, BorderLayout.CENTER);
//Panel der Buttons auf der rechten Seite wird ausgeblendet //Panel der Buttons auf der rechten Seite wird ausgeblendet
//mainPane.add(createControlPanel(simu), BorderLayout.LINE_END); //mainPane.add(createControlPanel(simu), BorderLayout.EAST);
mainPane.add(createSerialLog(), BorderLayout.PAGE_END); mainPane.add(createSerialLog(), BorderLayout.PAGE_END);
//this.setSize(xscale, yscale); //this.setSize(xscale, yscale);
this.pack(); this.pack();
...@@ -118,19 +133,40 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -118,19 +133,40 @@ public class GUI extends JFrame implements Runnable, ActionListener {
this.addComponentListener(new ComponentListener() { this.addComponentListener(new ComponentListener() {
@Override @Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
if(!(xscale == getWidth() && yscale == getHeight())) {
System.out.println("topPanel Hhe und Weite: " + topPanel.getHeight() + "\t" + topPanel.getWidth());
System.out.println("modulPanel Hhe und Weite: " + modulPanel.getHeight() + "\t" + modulPanel.getWidth());
System.out.println("Fenster Hhe und Weite: " + getHeight() + "\t" + getWidth());
if((getWidth() - topPanel.getWidth() < 100) || (topPanel.getHeight() - modulPanel.getHeight() < 100)) {
xscale = getWidth(); xscale = getWidth();
yscale = getHeight(); yscale = getWidth();
updateGUI(xscale, yscale);
System.out.println("xScale: " + xscale + "\tyScale: " + yscale);
xscale = getHeight();
yscale = getHeight();
} }
else {
xscale = getWidth();
yscale = getHeight();
}
if(xscale % 4 == 0 || yscale % 10 == 0) {
updateGUI(xscale, yscale);
}
//System.out.println("xScale: " + xscale + "\tyScale: " + yscale);
} }
@Override @Override
...@@ -177,13 +213,18 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -177,13 +213,18 @@ public class GUI extends JFrame implements Runnable, ActionListener {
* @return JPanel mit allen Knöpfen * @return JPanel mit allen Knöpfen
*/ */
private JPanel createControlPanel(Simulator simu) { private JPanel createControlPanel(Simulator simu) {
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
JButton goButton = new JButton();
JButton stopButton = new JButton(); controlPanel = new JPanel(new BorderLayout());
JButton reloadButton = new JButton(); topControlPanel = new JPanel(new GridLayout(2,1));
JButton measButton = new JButton(); botControlPanel = new JPanel(new GridLayout(2,1));
goButton = new JButton();
stopButton = new JButton();
reloadButton = new JButton();
measButton = new JButton();
goButton.setIcon(new ImageIcon( goButton.setIcon(new ImageIcon(
getToolkit().getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Play.png")))); getToolkit().getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/Play.png"))));
...@@ -204,23 +245,34 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -204,23 +245,34 @@ public class GUI extends JFrame implements Runnable, ActionListener {
reloadButton.setActionCommand("reload"); reloadButton.setActionCommand("reload");
measButton.setActionCommand("meas"); measButton.setActionCommand("meas");
controlPanel.add(goButton);
controlPanel.add(stopButton); topControlPanel.add(goButton);
controlPanel.add(Box.createRigidArea(new Dimension(0, 450))); topControlPanel.add(stopButton);
controlPanel.add(reloadButton); //controlPanel.add(Box.createRigidArea(new Dimension(0, ((int)(0.3*yscale)))));
controlPanel.add(measButton); botControlPanel.add(reloadButton);
botControlPanel.add(measButton);
controlPanel.add(topControlPanel, BorderLayout.NORTH);
controlPanel.add(botControlPanel, BorderLayout.SOUTH);
return controlPanel; return controlPanel;
} }
/** /**
* Erzeuge den Bereich mit dem SerialLog * Erzeuge den Bereich mit dem SerialLog
* *
* @return JPanel des SerialLogs * @return JPanel des SerialLogs
*/ */
private JPanel createSerialLog() { private JPanel createSerialLog() {
JPanel panel = new JPanel(new BorderLayout()); panel = new JPanel(new BorderLayout());
JScrollPane scrollPane = new JScrollPane(serialLog); scrollPane = new JScrollPane(serialLog);
serialLog.setRows(8); // Anzahl der Angezeigten Reihen serialLog.setRows(4); // Anzahl der Angezeigten Reihen
serialLog.setAutoscrolls(true); serialLog.setAutoscrolls(true);
serialLog.setForeground(Color.black); serialLog.setForeground(Color.black);
serialLog.setBackground(Color.white); serialLog.setBackground(Color.white);
...@@ -228,12 +280,12 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -228,12 +280,12 @@ public class GUI extends JFrame implements Runnable, ActionListener {
DefaultCaret caret = (DefaultCaret) serialLog.getCaret(); DefaultCaret caret = (DefaultCaret) serialLog.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
JButton clearButton = new JButton("Clear Serial Output"); clearButton = new JButton("Clear Serial Output");
clearButton.setActionCommand("clearSerial"); clearButton.setActionCommand("clearSerial");
clearButton.addActionListener(this); clearButton.addActionListener(this);
panel.add(clearButton, BorderLayout.CENTER); panel.add(clearButton, BorderLayout.CENTER);
JCheckBox checkBox = new JCheckBox("Autoscroll"); checkBox = new JCheckBox("Autoscroll");
checkBox.setActionCommand("autoscroll"); checkBox.setActionCommand("autoscroll");
checkBox.addActionListener(this); checkBox.addActionListener(this);
checkBox.setSelected(true); checkBox.setSelected(true);
...@@ -251,6 +303,11 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -251,6 +303,11 @@ public class GUI extends JFrame implements Runnable, ActionListener {
* @param g Graphics Instanz des Panels * @param g Graphics Instanz des Panels
*/ */
private void drawConnections(Graphics g) { private void drawConnections(Graphics g) {
// Zeichne die Stromversorgung // Zeichne die Stromversorgung
for (int i = -1; i < 2; i++) { for (int i = -1; i < 2; i++) {
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
...@@ -298,6 +355,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -298,6 +355,7 @@ public class GUI extends JFrame implements Runnable, ActionListener {
counter++; counter++;
} }
} }
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment