diff options
Diffstat (limited to 'embedding/java/src/org/uscxml/tests/ioprocessor/console')
-rw-r--r-- | embedding/java/src/org/uscxml/tests/ioprocessor/console/ConsoleFrame.java | 74 | ||||
-rw-r--r-- | embedding/java/src/org/uscxml/tests/ioprocessor/console/ConsoleIOProc.java | 84 |
2 files changed, 0 insertions, 158 deletions
diff --git a/embedding/java/src/org/uscxml/tests/ioprocessor/console/ConsoleFrame.java b/embedding/java/src/org/uscxml/tests/ioprocessor/console/ConsoleFrame.java deleted file mode 100644 index a88cce4..0000000 --- a/embedding/java/src/org/uscxml/tests/ioprocessor/console/ConsoleFrame.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.uscxml.tests.ioprocessor.console; - -import java.awt.Frame; -import java.util.HashMap; -import java.util.Map; - -import javax.swing.JLabel; -import javax.swing.JPanel; - -import org.uscxml.Factory; -import org.uscxml.Interpreter; -import org.uscxml.InterpreterException; - -public class ConsoleFrame extends Frame { - - private static final long serialVersionUID = 3682378173372160680L; - private ConsoleIOProc ioProc; - - public ConsoleFrame() throws InterpreterException { - super("Input Frame"); - JPanel p = new JPanel(); - JLabel label = new JLabel("Key Listener!"); - p.add(label); - add(p); - setSize(200, 100); - - final Interpreter interpreter = Interpreter.fromXML( - "<scxml datamodel=\"ecmascript\">" - + " <script src=\"http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js\" />" - + " <script>var charSeq = \"\";</script>" - + " <state id=\"idle\">" - + " <transition event=\"error\" target=\"quit\" />" - + " <transition event=\"key.released\" cond=\"_event.data.keyChar == 10\">" - + " <send type=\"console\">" - + " <param name=\"foo\" expr=\"charSeq\" />" - + " </send>" - + " <script>" - + " charSeq = \"\"; // reset string" - + " </script>" - + " </transition>" - + " <transition event=\"*\">" - + " <log label=\"event\" expr=\"dump(_event.data)\" />" - + " <script>charSeq += String.fromCharCode(_event.data.keyChar);</script>" - + " </transition>" - + " </state>" - + " <final id=\"quit\" />" - + "</scxml>"); - - ioProc = new ConsoleIOProc(this); - interpreter.addIOProcessor(ioProc); - - Thread intrerpreterThread = new Thread(new Runnable() { - @Override - public void run() { - try { - interpreter.interpret(); - } catch (InterpreterException e) { - e.printStackTrace(); - } - } - }); - intrerpreterThread.start(); - - setVisible(true); - } - - public static void main(String[] args) throws InterpreterException { - System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); - ConsoleFrame frame = new ConsoleFrame(); - - } - -} - diff --git a/embedding/java/src/org/uscxml/tests/ioprocessor/console/ConsoleIOProc.java b/embedding/java/src/org/uscxml/tests/ioprocessor/console/ConsoleIOProc.java deleted file mode 100644 index a95f6cb..0000000 --- a/embedding/java/src/org/uscxml/tests/ioprocessor/console/ConsoleIOProc.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.uscxml.tests.ioprocessor.console; - -import java.awt.Frame; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; - -import org.uscxml.Data; -import org.uscxml.Event; -import org.uscxml.IOProcessor; -import org.uscxml.SendRequest; -import org.uscxml.StringList; - -public class ConsoleIOProc extends IOProcessor implements KeyListener { - - public ConsoleIOProc(Frame frame) { - super(); - frame.addKeyListener(this); - } - - /** IOProcessor */ - @Override - public StringList getNames() { - StringList ss = new StringList(); - ss.add("console"); - return ss; - } - - /** IOProcessor */ - @Override - public Data getDataModelVariables() { - // return anything for _ioprocessor['console'] - Data data = Data.fromJSON("{ foo: \"bar\", test: [1,2,3,4,5,6] }"); - return data; - } - - /** IOProcessor */ - @Override - public void send(SendRequest req) { - // interpreter wants to send something, just print on console - System.out.println(req); - } - - /** KeyListener */ - @Override - public void keyPressed(KeyEvent e) { - Event evt = new Event("key.pressed"); - evt.setData(keyEventToData(e)); - returnEvent(evt, true); - } - - /** KeyListener */ - @Override - public void keyReleased(KeyEvent e) { - Event evt = new Event("key.released"); - evt.setData(keyEventToData(e)); - returnEvent(evt, true); - } - - /** KeyListener */ - @Override - public void keyTyped(KeyEvent e) { - Event evt = new Event("key.typed"); - evt.setData(keyEventToData(e)); - returnEvent(evt, true); - } - - static Data keyEventToData(KeyEvent e) { - Data data = new Data(); - data.put("id", new Data(e.getID())); - data.put("keyChar", new Data(e.getKeyChar())); - data.put("keyLocation", new Data(e.getKeyLocation())); - data.put("modifiers", new Data(e.getModifiers())); - data.put("modifiersEx", new Data(e.getModifiersEx())); - data.put("when", new Data(e.getWhen())); - data.put("actionKey", new Data(e.isActionKey())); - data.put("altDown", new Data(e.isAltDown())); - data.put("altGraphDown", new Data(e.isAltGraphDown())); - data.put("ctrlDown", new Data(e.isControlDown())); - data.put("metaDown", new Data(e.isMetaDown())); - data.put("shiftDown", new Data(e.isShiftDown())); - - return data; - } -}
\ No newline at end of file |