Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'othersrc/otdt-examples/OTSample-Stopwatch-src')
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/.classpath7
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/.project18
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/.settings/org.eclipse.jdt.core.prefs64
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/img/watch.jpgbin0 -> 48699 bytes
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/AnalogClock.java123
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/Main.java59
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/StopWatch.java127
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/WatchUI.java135
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/WatchUIAnalog.java117
-rw-r--r--othersrc/otdt-examples/OTSample-Stopwatch-src/stopwatch-zip.jardesc10
10 files changed, 660 insertions, 0 deletions
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/.classpath b/othersrc/otdt-examples/OTSample-Stopwatch-src/.classpath
new file mode 100644
index 000000000..bcc3bc2b8
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="OTRE"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/.project b/othersrc/otdt-examples/OTSample-Stopwatch-src/.project
new file mode 100644
index 000000000..7ce28463d
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/.project
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>OTSample-Stopwatch-src</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.objectteams.otdt.builder.OTJBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.objectteams.otdt.OTJavaNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/.settings/org.eclipse.jdt.core.prefs b/othersrc/otdt-examples/OTSample-Stopwatch-src/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..87e37e0d9
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,64 @@
+#Sat Jul 18 21:53:34 CEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/img/watch.jpg b/othersrc/otdt-examples/OTSample-Stopwatch-src/img/watch.jpg
new file mode 100644
index 000000000..2e293fe07
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/img/watch.jpg
Binary files differ
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/AnalogClock.java b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/AnalogClock.java
new file mode 100644
index 000000000..579ffc859
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/AnalogClock.java
@@ -0,0 +1,123 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2010 Technical University Berlin, Germany.
+ *
+ * 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
+ * $Id: AnalogClock.java 23501 2010-02-08 18:27:55Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.example.stopwatch;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.swing.JPanel;
+
+public class AnalogClock extends JPanel {
+ private int seconds = 0;
+
+ private static final int spacing = 10;
+ private static final float threePi = (float)(3.0 * Math.PI);
+ // Angles for the trigonometric functions are measured in radians.
+ // The following in the number of radians per sec or min.
+ private static final float radPerSecMin = (float)(Math.PI / 30.0);
+
+ private int size; // height and width of clock face
+ private int centerX; // x coord of middle of clock
+ private int centerY; // y coord of middle of clock
+ private BufferedImage clockImage;
+
+ //==================================================== Clock constructor
+ public AnalogClock() {
+ this.setBackground(Color.white);
+ this.setForeground(Color.black);
+ }//end constructor
+
+ //=============================================================== update
+ // Replace the default update so that the plain background
+ // doesn't get drawn.
+ public void update(int value) {
+ seconds = value;
+ this.repaint();
+ }//end update
+
+ //======================================================= paintComponent
+
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g); // paint background, borders
+ Graphics2D g2 = (Graphics2D)g;
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ int w = getWidth();
+ int h = getHeight();
+ size = ((w < h) ? w : h) - 2 * spacing;
+ centerX = size / 2 + spacing;
+ centerY = size / 2 + spacing + 35;
+
+ // Create the clock face background image if this is the first time
+ if (clockImage == null
+ || clockImage.getWidth() != w
+ || clockImage.getHeight() != h) {
+
+ try {
+ clockImage = ImageIO.read(new File("img/watch.jpg"));
+ } catch (IOException e) {
+ // File not found :-/
+ }
+ // now get a graphics context from this image
+ Graphics2D gc = clockImage.createGraphics();
+ gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ }
+
+ // Draw the clock face from the precomputed image
+ g2.drawImage(clockImage, null, 0, 0);
+
+ // Draw the clock hands
+ drawClockHand(g);
+ }//end paintComponent
+
+ //======================================================= drawClockHand
+ private void drawClockHand(Graphics g) {
+ int secondRadius = size / 2 - 55;
+
+ // second hand
+ float fseconds = seconds;
+ float secondAngle = threePi - (radPerSecMin * fseconds);
+ drawRadius(g, centerX, centerY, secondAngle, 0, secondRadius);
+
+ }//end drawClockHands
+
+ // =========================================================== drawRadius
+ private void drawRadius(Graphics g, int x, int y, double angle,
+ int minRadius, int maxRadius) {
+ float sine = (float)Math.sin(angle);
+ float cosine = (float)Math.cos(angle);
+
+ int dxmin = (int)(minRadius * sine);
+ int dymin = (int)(minRadius * cosine);
+
+ int dxmax = (int)(maxRadius * sine);
+ int dymax = (int)(maxRadius * cosine);
+ Graphics2D g2d = (Graphics2D)g;
+ g2d.setStroke(new BasicStroke(4));
+ g2d.drawLine(x + dxmin, y + dymin, x + dxmax, y + dymax);
+ }//end drawRadius
+
+}
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/Main.java b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/Main.java
new file mode 100644
index 000000000..9b65979b5
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/Main.java
@@ -0,0 +1,59 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute and Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: Main.java 23501 2010-02-08 18:27:55Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.example.stopwatch;
+
+/**
+ * Object Teams features demonstrated by this example:
+ * ---------------------------------------------------
+ *
+ * Callin and callout method binding: Callin bindings are used to inform the GUI
+ * about changes in the base class. The callout method bindings allow us to
+ * propagate commands from the GUI to the base class.
+ *
+ * Role class binding: The role WatchDisplay is bound to the base class StopWatch.
+ *
+ *
+ * Domain description:
+ * -------------------
+ *
+ * This is a simple example for an implementation of the Model-View-Controller
+ * pattern. A StopWatch with the basic functions start, stop, and clear is
+ * created and passed to two WatchDisplays. Any changes in the model (StopWatch)
+ * are made visible in both views (WatchDisplay).
+ *
+ * Launching the application:
+ * --------------------------
+ * Just run this main class as a Java Application, e.g., like this:
+ * - Choose "Run", "Run..." in the Eclipse menu bar
+ * - Select "Java Application"
+ * - Create a new run configuration by clicking "New"
+ * - Click "Run"
+ * (to check enablement of OT/J you may visit the JRE tab of the corres-
+ * ponding launch configuration and ensure that "Enable OTRE" is checked).
+ */
+public class Main {
+
+ public static void main(String[] args) {
+ StopWatch w = new StopWatch();
+ new WatchUIAnalog(w);
+ new WatchUI(w);
+ }
+} \ No newline at end of file
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/StopWatch.java b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/StopWatch.java
new file mode 100644
index 000000000..e3b0ff029
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/StopWatch.java
@@ -0,0 +1,127 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute and Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: StopWatch.java 23501 2010-02-08 18:27:55Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.example.stopwatch;
+
+/**
+ * This class acts as base class for this example. It is bound to the
+ * WatchDisplay role of the WatchUI team. StopWatch implemets a simple watch as
+ * a thread. The watch can be controlled via three methods: start(), stop() and
+ * clear(). getValue() returns the current time value. Note, that the StopWatch
+ * is not aware of the GUI.
+ */
+public class StopWatch implements Runnable {
+
+ /**
+ * Current time value
+ */
+ private int time = 0;
+
+ /**
+ * Flag that indicates if the watch is running
+ */
+ private boolean running;
+
+ /**
+ * Flag that indicates if there is a stop request
+ */
+ private boolean stopRequest;
+
+ /**
+ * Increases the time value.
+ */
+ private synchronized void advance() {
+ time++;
+ }
+
+ /**
+ * Starts the watch thread.
+ */
+ public synchronized void start() {
+ if (!running) {
+ setRunning(true);
+ setStopped(false);
+ (new Thread(this)).start();
+ }
+ }
+
+ /**
+ * Stops the watch thread.
+ *
+ */
+ public synchronized void stop() {
+ setStopped(true);
+ }
+
+ /**
+ * Resets the time value.
+ */
+ public synchronized void reset() {
+ time = 0;
+ }
+
+ /**
+ * Returns the current time value.
+ */
+ public synchronized int getValue() {
+ return time;
+ }
+
+ /**
+ * Sets the running flag value.
+ */
+ private synchronized void setRunning(boolean value) {
+ running = value;
+ }
+
+ /**
+ * Returns the stop flag value
+ */
+ private synchronized boolean isStopped() {
+ return stopRequest;
+ }
+
+ /**
+ * Sets the stop flag value
+ */
+ private synchronized void setStopped(boolean value) {
+ stopRequest = value;
+ }
+
+ /**
+ * This method contains the main loop that is executed while the watch is
+ * running.
+ */
+ public void run() {
+ while (true) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ setRunning(false);
+ return;
+ }
+ if (isStopped()) {
+ setRunning(false);
+ return;
+ }
+ advance();
+ }
+ }
+} \ No newline at end of file
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/WatchUI.java b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/WatchUI.java
new file mode 100644
index 000000000..b788f21dd
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/WatchUI.java
@@ -0,0 +1,135 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute and Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: WatchUI.java 23501 2010-02-08 18:27:55Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.example.stopwatch;
+
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+
+/**
+ * This team implements the UI for a StopWatch and contains the role class
+ * WatchDisplay.
+ */
+public team class WatchUI {
+ static int ypos = 150;
+
+ /**
+ * Role class WatchDisplay is played by the base class StopWatch. The role
+ * class WatchDisplay is bound to the base class StopWatch with the keyowrd
+ * 'playedBy'.
+ */
+ protected class WatchDisplay extends JFrame playedBy StopWatch
+ {
+ private JTextField display;
+ private JButton startButton;
+ private JButton stopButton;
+ private JButton clearButton;
+
+ /**
+ * This constructor is used for automatic role creation. E.g. via
+ * declared lifting. Role class constructor takes an object of the type
+ * of the declared base class. Setup the window, create a textfield for
+ * time display and three buttons "start", "stop", and "clear".
+ */
+ public WatchDisplay(StopWatch w) {
+ setTitle("Digital Stop Watch");
+ setSize(new Dimension(300, 100));
+ setLocation(410, ypos+=110);
+ Container pane = getContentPane();
+ pane.setLayout(new GridLayout(2,3));
+
+ pane.add(new JLabel(""));
+ display = new JTextField("0", 8);
+ display.setHorizontalAlignment(JTextField.RIGHT);
+ pane.add(display);
+ pane.add(new JLabel(""));
+
+ startButton = new JButton("start");
+ startButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ start();
+ }});
+ pane.add(startButton);
+
+ stopButton = new JButton("stop");
+ stopButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ stop();
+ }});
+ pane.add(stopButton);
+
+ clearButton = new JButton("clear");
+ clearButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ clear();
+ }});
+ pane.add(clearButton);
+ setVisible(true);
+ }
+
+ /**
+ * Shows the new time value on the watch display.
+ */
+ void update() {
+ String val = getStringValue();
+ display.setText(val);
+ }
+
+ // Abstract methods for mapping to the concrete base methods:
+ abstract void start();
+ abstract void stop();
+ abstract void clear();
+ abstract String getStringValue();
+
+ // callout method bindings: any call of the abstract WatchDisplay
+ // method will be forwarded to the concrete StopWatch method
+ start -> start;
+ stop -> stop;
+ clear -> reset;
+ String getStringValue() -> int getValue()
+ with {
+ // result is a predefined name.
+ result <- Integer.toString(result)
+ }
+
+ /* -------------------------------------------------------------- */
+
+ // Callin method bindings: WatchDisplay (role object) is updated
+ // after the StopWatch (base object) advanced or was reset.
+ void update() <- after void advance();
+ void update() <- after void reset();
+ }
+
+ /**
+ * The team constructor uses declared lifting. A WatchDisplay role is
+ * created for the given StopWatch object.
+ */
+ public WatchUI (StopWatch as WatchDisplay w) {
+ activate(ALL_THREADS); // Without this, the callin bindings have no effect.
+ }
+}
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/WatchUIAnalog.java b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/WatchUIAnalog.java
new file mode 100644
index 000000000..814e1c846
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/src/org/eclipse/objectteams/example/stopwatch/WatchUIAnalog.java
@@ -0,0 +1,117 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ *
+ * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute and Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ *
+ * 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
+ * $Id: WatchUIAnalog.java 23501 2010-02-08 18:27:55Z stephan $
+ *
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ *
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.example.stopwatch;
+
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+/**
+ * This team implements the UI for a StopWatch and contains the role class
+ * WatchDisplay.
+ */
+public team class WatchUIAnalog {
+ public class WatchDisplay extends JFrame playedBy StopWatch {
+
+ AnalogClock clockFace;
+ private JButton startButton;
+ private JButton stopButton;
+ private JButton clearButton;
+
+ //========================================================== constructor
+ public WatchDisplay(StopWatch sw) {
+ Container content = this.getContentPane();
+ content.setLayout(new BorderLayout());
+ clockFace = new AnalogClock();
+ this.setLocation(90, 110);
+ this.setResizable(false);
+
+ content.add(clockFace, BorderLayout.CENTER);
+ JPanel buttons = new JPanel();
+ buttons.setLayout(new FlowLayout());
+
+ startButton = new JButton("start");
+ startButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ start();
+ }});
+ buttons.add(startButton);
+
+ stopButton = new JButton("stop");
+ stopButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ stop();
+ }});
+ buttons.add(stopButton);
+
+ clearButton = new JButton("clear");
+ clearButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ clear();
+ }});
+ buttons.add(clearButton);
+
+ content.add(buttons, BorderLayout.SOUTH);
+
+ this.setTitle("Analog Stop Watch");
+ this.setSize(new Dimension(298, 440));
+
+ setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ setVisible(true);
+ }//end constructor
+
+ void update() {
+ clockFace.update(getValue());
+ }
+// Abstract methods for mapping to the concrete base methods:
+ abstract void stop();
+ abstract void clear();
+ abstract int getValue();
+
+ // callout method bindings: any call of the abstract WatchDisplay
+ // method will be forwarded to the concrete StopWatch method
+ void start() -> void start();
+ stop -> stop;
+ clear -> reset;
+ getValue -> getValue;
+
+// Callin method bindings: WatchDisplay (role object) is updated
+ // after the StopWatch (base object) advanced or was reset.
+ void update() <- after void advance();
+ void update() <- after void reset();
+ }//end class ClockAnalogBuf
+
+
+ /**
+ * The team constructor uses declared lifting. A WatchDisplay role is
+ * created for the given StopWatch object.
+ */
+ public WatchUIAnalog (StopWatch as WatchDisplay w) {
+ activate(ALL_THREADS); // Without this, the callin bindings have no effect.
+ }
+}
diff --git a/othersrc/otdt-examples/OTSample-Stopwatch-src/stopwatch-zip.jardesc b/othersrc/otdt-examples/OTSample-Stopwatch-src/stopwatch-zip.jardesc
new file mode 100644
index 000000000..1e6e12545
--- /dev/null
+++ b/othersrc/otdt-examples/OTSample-Stopwatch-src/stopwatch-zip.jardesc
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<jardesc>
+ <jar path="org.eclipse.objectteams.otdt.samples/samples/stopwatch.zip"/>
+ <options buildIfNeeded="true" compress="true" descriptionLocation="/OTSample-Stopwatch-src/stopwatch-zip.jardesc" exportErrors="false" exportWarnings="true" includeDirectoryEntries="false" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="true"/>
+ <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
+ <selectedProjects/>
+ <selectedElements exportClassFiles="false" exportJavaFiles="true" exportOutputFolder="false">
+ <javaElement handleIdentifier="=OTSample-Stopwatch-src"/>
+ </selectedElements>
+</jardesc>

Back to the top