summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Jung2011-05-30 09:12:50 (EDT)
committer Henrik Rentz-Reichert2011-05-30 09:12:50 (EDT)
commitc16a6eb26609bae54427c7169b77d20585ec0528 (patch)
tree92036b096183bfd198b7607b586ec827029a302d
parentaa39e80c5ac6ccc9aa24a4b8f528fa0b751fd88c (diff)
downloadorg.eclipse.etrice-c16a6eb26609bae54427c7169b77d20585ec0528.zip
org.eclipse.etrice-c16a6eb26609bae54427c7169b77d20585ec0528.tar.gz
org.eclipse.etrice-c16a6eb26609bae54427c7169b77d20585ec0528.tar.bz2
[tutorials] added extra Java files needed for tutorials
The files have been contributed by Thomas Jung with bug 345825, https://bugs.eclipse.org/bugs/attachment.cgi?id=196884.
-rw-r--r--examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/PedestrianLightWndNoTcp.java135
-rw-r--r--examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/TrafficLight2.java89
-rw-r--r--examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/TrafficLight3.java97
-rw-r--r--examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/WindowClosingAdapter.java50
4 files changed, 371 insertions, 0 deletions
diff --git a/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/PedestrianLightWndNoTcp.java b/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/PedestrianLightWndNoTcp.java
new file mode 100644
index 0000000..78e1c1a
--- /dev/null
+++ b/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/PedestrianLightWndNoTcp.java
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2011 tieto deutschland gmbh (http://www.tieto.com)
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Thomas Jung
+ *******************************************************************************/
+
+package org.eclipse.etrice.tutorials.PedLightGUI;
+
+//This is used for PedLightController tutorial and must be disabled for Blinky
+//import PedLightsController.PedControlProtocol.*;
+
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+/**
+ * A little simple Trafficlight GUI for the etrice tutorials
+ *
+ * @author Thomas Jung
+ *
+ */
+@SuppressWarnings("serial")
+public class PedestrianLightWndNoTcp extends Frame
+implements ActionListener {
+ private TrafficLight3 carLights;
+ private TrafficLight2 pedLights;
+ Button requestButton;
+ TextField statusLine;
+
+ //This is used for PedLightController tutorial and must be disabled for Blinky
+ //private PedControlProtocolConjPort port=null;
+
+ // Constructors
+ public PedestrianLightWndNoTcp(){
+ super("PedastrianLightsGUI");
+ setupWindow();
+ statusLine.setText(" direct connection");
+ }
+
+ public PedestrianLightWndNoTcp(String wnd, String but){
+ super(wnd);
+ setupWindow();
+ statusLine.setText(but);
+ }
+
+ private void setupWindow(){
+ GridBagLayout layout = new GridBagLayout();
+ GridBagConstraints gbc;
+ carLights = new TrafficLight3(TrafficLight3.OFF);
+ pedLights = new TrafficLight2(TrafficLight2.OFF);
+ statusLine = new TextField();
+ requestButton = new Button("REQUEST");
+ requestButton.setEnabled(false);
+ addWindowListener(new WindowClosingAdapter(true));
+
+ setLayout(layout);
+
+ gbc=makeGbc(0,1,1,1);
+ layout.setConstraints(carLights,gbc);
+ add(carLights);
+
+ gbc=makeGbc(1,1,1,1);
+ layout.setConstraints(pedLights,gbc);
+ add(pedLights);
+
+ statusLine.setText("");
+ statusLine.setEditable(false);
+ statusLine.setFocusable(false);
+ gbc = makeGbc(0,0,2,1);
+ gbc.fill = GridBagConstraints.BOTH;
+ layout.setConstraints(statusLine,gbc);
+ add(statusLine);
+
+ gbc = makeGbc(0,2,2,1);
+ gbc.fill = GridBagConstraints.BOTH;
+ layout.setConstraints(requestButton,gbc);
+ add(requestButton);
+
+ pack();
+ setVisible(true);
+
+ requestButton.addActionListener(this);
+ requestButton.setEnabled(true);
+
+ carLights.setState(TrafficLight3.RED);
+ pedLights.setState(TrafficLight2.RED);
+ }
+
+ public TrafficLight3 getCarLights(){
+ return carLights;
+ }
+
+ public TrafficLight2 getPedLights(){
+ return pedLights;
+ }
+
+ private GridBagConstraints makeGbc(int x, int y, int width, int height){
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridx = x;
+ gbc.gridy = y;
+ gbc.gridwidth = width;
+ gbc.gridheight = height;
+ gbc.weightx = 1;
+ gbc.weighty = 1;
+ gbc.anchor = GridBagConstraints.CENTER;
+ gbc.insets = new Insets(1,1,1,1);
+ return gbc;
+ }
+
+ public void actionPerformed(ActionEvent arg0) {
+ // TODO Auto-generated method stub
+ String s = arg0.getActionCommand();
+
+ if (s.equals("REQUEST")) {
+ System.out.println("Taste gedrückt");
+ // This is used for PedLightController tutorial and must be disabled for Blinky
+ // if (port != null) port.start();
+ }
+ }
+ public void closeWindow(){
+ this.setVisible(false);
+ this.dispose();
+ // System.exit(0);
+ }
+
+// This is used for PedLightController tutorial and must be disabled for Blinky
+// public void setPort(PedControlProtocolConjPort p){
+// port=p;
+// }
+} \ No newline at end of file
diff --git a/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/TrafficLight2.java b/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/TrafficLight2.java
new file mode 100644
index 0000000..1cc55ff
--- /dev/null
+++ b/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/TrafficLight2.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2011 tieto deutschland gmbh (http://www.tieto.com)
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Thomas Jung
+ *******************************************************************************/
+package org.eclipse.etrice.tutorials.PedLightGUI;
+
+import java.awt.*;
+
+/**
+ * A little simple Trafficlight GUI for the etrice tutorials
+ *
+ * @author Thomas Jung
+ *
+ */
+@SuppressWarnings("serial")
+public class TrafficLight2 extends Canvas {
+ // Traffic light has 3 states
+ // 0 = red
+ // 1 = green
+ // 2 = off
+ public static final int RED=0;
+ public static final int GREEN=1;
+ public static final int OFF=2;
+
+ private int state;
+
+ public TrafficLight2(int state){
+ this.state = state;
+ }
+ public TrafficLight2(){
+ this.state = 0;
+ }
+
+ private int singleLightSize = 20;
+ private int xPosition = 5;
+ private int gap = 5;
+
+ public void paint(Graphics g){
+ Color lightRed = new Color(255,0,0);
+ Color darkRed = new Color (127,0,0);
+ Color lightGreen = new Color (0,255,0);
+ Color darkGreen = new Color (0,127,0);
+
+ Color colors [][] = {
+ {lightRed,darkGreen},
+ {darkRed,lightGreen},
+ {darkRed,darkGreen}
+ };
+
+ // set Background
+ g.setColor(Color.lightGray);
+ g.fillRect(0,0,getSize().width,getSize().height);
+ // draw boarder
+ g.setColor(Color.BLACK);
+ g.drawRect(0,0,getSize().width-1,getSize().height-1);
+
+ for (int i = 0; i<2; i++) {
+ g.setColor(colors[state][i]);
+ g.fillOval(xPosition,i*singleLightSize+gap,singleLightSize,singleLightSize);
+ g.setColor(Color.black);
+ g.drawOval(xPosition,i*singleLightSize+gap,singleLightSize-1,singleLightSize-1);
+ }
+ }
+
+ public Dimension getPreferredSize(){
+ return new Dimension(singleLightSize + 2 * gap, singleLightSize * 2 + 2 * gap);
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(singleLightSize + 2 * gap, singleLightSize * 2 + 2 * gap);
+ }
+
+ public void setState(int state)
+ {
+ // avoid array error
+ if (state < 3){
+ this.state = state;
+ repaint();
+ }
+ }
+
+}
diff --git a/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/TrafficLight3.java b/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/TrafficLight3.java
new file mode 100644
index 0000000..a646bdf
--- /dev/null
+++ b/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/TrafficLight3.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2011 tieto deutschland gmbh (http://www.tieto.com)
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Thomas Jung
+ *******************************************************************************/
+
+package org.eclipse.etrice.tutorials.PedLightGUI;
+
+import java.awt.*;
+
+/**
+ * A little simple Trafficlight GUI for the etrice tutorials
+ *
+ * @author Thomas Jung
+ *
+ */
+@SuppressWarnings("serial")
+public class TrafficLight3 extends Canvas {
+ // Traffic light has 5 states
+ // 0 = red
+ // 1 = yellowRed
+ // 2 = green
+ // 3 = yellow
+ // 4 = OFF
+ public static final int RED=0;
+ public static final int YELLOW_RED=1;
+ public static final int GREEN=2;
+ public static final int YELLOW=3;
+ public static final int OFF=4;
+
+ private int state;
+
+ public TrafficLight3(int state){
+ this.state = state;
+ }
+ public TrafficLight3(){
+ this.state = 0;
+ }
+
+ private int singleLightSize = 20;
+ private int xPosition = 5;
+ private int gap = 5;
+
+ public void paint(Graphics g){
+ Color lightRed = new Color(255,0,0);
+ Color darkRed = new Color (127,0,0);
+ Color lightGreen = new Color (0,255,0);
+ Color darkGreen = new Color (0,127,0);
+ Color lightYellow = new Color (255,255,0);
+ Color darkYellow = new Color (127,127,0);
+
+ Color colors [][] = {
+ {lightRed,darkYellow,darkGreen},
+ {lightRed,lightYellow,darkGreen},
+ {darkRed,darkYellow,lightGreen},
+ {darkRed,lightYellow,darkGreen},
+ {darkRed,darkYellow,darkGreen}
+ };
+
+
+ // set Background
+ g.setColor(Color.lightGray);
+ g.fillRect(0,0,getSize().width,getSize().height);
+ // draw boarder
+ g.setColor(Color.BLACK);
+ g.drawRect(0,0,getSize().width-1,getSize().height-1);
+
+ for (int i = 0; i<3; i++) {
+ g.setColor(colors[state][i]);
+ g.fillOval(xPosition,i*singleLightSize+gap,singleLightSize,singleLightSize);
+ g.setColor(Color.black);
+ g.drawOval(xPosition,i*singleLightSize+gap,singleLightSize-1,singleLightSize-1);
+ }
+ }
+
+ public Dimension getPreferredSize(){
+ return new Dimension(singleLightSize + 2 * gap, singleLightSize * 3 + 2 * gap);
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(singleLightSize + 2 * gap, singleLightSize * 3 + 2 * gap);
+ }
+
+ public void setState(int state)
+ {
+ if (state < 5){
+ this.state = state;
+ repaint();
+ }
+ }
+}
diff --git a/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/WindowClosingAdapter.java b/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/WindowClosingAdapter.java
new file mode 100644
index 0000000..93005f3
--- /dev/null
+++ b/examples/org.eclipse.etrice.tutorials/src/org/eclipse/etrice/tutorials/PedLightGUI/WindowClosingAdapter.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2011 tieto deutschland gmbh (http://www.tieto.com)
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Thomas Jung
+ *******************************************************************************/
+package org.eclipse.etrice.tutorials.PedLightGUI;
+
+import org.eclipse.etrice.tutorials.PedLightGUI.*;
+
+/* WindowClosingAdapter.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+/**
+ * A little simple Trafficlight GUI for the etrice tutorials
+ *
+ * @author Thomas Jung
+ *
+**/
+@SuppressWarnings("unused")
+public class WindowClosingAdapter
+extends WindowAdapter
+{
+ private boolean exitSystem;
+
+ public WindowClosingAdapter(boolean exitSystem)
+ {
+ this.exitSystem = exitSystem;
+ }
+
+ public WindowClosingAdapter()
+ {
+ this(false);
+ }
+
+ public void windowClosing(WindowEvent event)
+ {
+ event.getWindow().setVisible(false);
+ event.getWindow().dispose();
+ if (exitSystem) {
+ System.exit(0);
+ }
+ }
+}