[RavenclawDev 266] [28] Agents/JavaTTY: cleaned up the code more

svetlana@edam.speech.cs.cmu.edu svetlana at edam.speech.cs.cmu.edu
Tue May 1 23:21:58 EDT 2007


An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/ravenclaw-developers/attachments/20070501/7a56f6d1/attachment.html
-------------- next part --------------
Modified: Agents/JavaTTY/nbproject/.cvsignore
===================================================================
--- Agents/JavaTTY/nbproject/.cvsignore	2007-04-25 19:54:23 UTC (rev 27)
+++ Agents/JavaTTY/nbproject/.cvsignore	2007-05-02 03:21:57 UTC (rev 28)
@@ -1,2 +1,3 @@
 vssver.scc
+.svn
 private

Modified: Agents/JavaTTY/nbproject/private/private.properties
===================================================================
--- Agents/JavaTTY/nbproject/private/private.properties	2007-04-25 19:54:23 UTC (rev 27)
+++ Agents/JavaTTY/nbproject/private/private.properties	2007-05-02 03:21:57 UTC (rev 28)
@@ -1,3 +1,5 @@
+application.args=-port 11002
+file.reference.CalendarJavaUtils.jar=C:\\calendar-from28\\RavenCalendar\\Libraries\\CalendarJavaUtils\\dist\\CalendarJavaUtils.jar
 javac.debug=true
 javadoc.preview=true
 user.properties.file=C:\\Documents and Settings\\sveta\\.netbeans\\5.5\\build.properties

Modified: Agents/JavaTTY/nbproject/project.properties
===================================================================
--- Agents/JavaTTY/nbproject/project.properties	2007-04-25 19:54:23 UTC (rev 27)
+++ Agents/JavaTTY/nbproject/project.properties	2007-05-02 03:21:57 UTC (rev 28)
@@ -17,6 +17,7 @@
 dist.javadoc.dir=${dist.dir}/javadoc
 file.reference.bsh-core-2.0b4.jar=bsh-core-2.0b4.jar
 file.reference.bsh-util-2.0b4.jar=bsh-util-2.0b4.jar
+file.reference.CalendarJavaUtils.jar=../../../../../../../../calendar-from28/RavenCalendar/Libraries/CalendarJavaUtils/dist/CalendarJavaUtils.jar
 file.reference.galaxy.jar=galaxy.jar
 file.reference.jiu.jar=jiu.jar
 file.reference.PenDecoder-src=src
@@ -25,7 +26,8 @@
     ${file.reference.jiu.jar}:\
     ${file.reference.bsh-util-2.0b4.jar}:\
     ${file.reference.galaxy.jar}:\
-    ${file.reference.bsh-core-2.0b4.jar}
+    ${file.reference.bsh-core-2.0b4.jar}:\
+    ${file.reference.CalendarJavaUtils.jar}
 # Space-separated list of extra javac options
 javac.compilerargs=-Xlint
 javac.deprecation=false

Modified: Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/DecoderInterpreter.java
===================================================================
--- Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/DecoderInterpreter.java	2007-04-25 19:54:23 UTC (rev 27)
+++ Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/DecoderInterpreter.java	2007-05-02 03:21:57 UTC (rev 28)
@@ -20,15 +20,17 @@
   
   protected JConsole jconsole;
   protected JConsole jconsoleWrite;
+  protected JConsole jconsoleCanSay;
   protected Reader reader;
   protected PrintStream outStream;
   protected PrintStream errStream;
   protected DrawingPad pad;
   
   /** Creates a new instance of DecoderInterpreter */
-  public DecoderInterpreter(JConsole jconsole, JConsole jconsoleWrite, DrawingPad pad) {
+  public DecoderInterpreter(JConsole jconsole, JConsole jconsoleWrite, JConsole jconsoleCanSay, DrawingPad pad) {
     this.jconsole = jconsole;
     this.jconsoleWrite = jconsoleWrite;
+    this.jconsoleCanSay = jconsoleCanSay;
     this.pad = pad;
     reader = jconsoleWrite.getIn();
     outStream = jconsole.getOut();
@@ -65,6 +67,12 @@
     jconsole.println();
   }
   
+  public void print_cansay(String bot, String text) {
+    
+    jconsoleCanSay.print(bot + ": " + text, java.awt.Color.BLACK);
+    jconsoleCanSay.println();
+  }  
+  
   public void print_human(String source, String confidence, String utterance) {
     jconsole.print("U(" + source + ":" + confidence + "): " + utterance, java.awt.Color.GREEN);
     jconsole.println();

Modified: Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/DrawingPad.java
===================================================================
--- Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/DrawingPad.java	2007-04-25 19:54:23 UTC (rev 27)
+++ Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/DrawingPad.java	2007-05-02 03:21:57 UTC (rev 28)
@@ -23,9 +23,14 @@
   
   JConsole consolePrint = new JConsole();
   JConsole consoleWrite = new JConsole();
+  JConsole consoleCanSay = new JConsole();
 
   protected static int width = 1200; 
   protected static int height = 800; 
+  
+  protected static int screenHeight = 0;
+  protected static int screenWidth = 0;
+  
   //
   
   protected JComponent toolbar;
@@ -34,7 +39,10 @@
   
   public DrawingPad(String title) {
     super(title);
-    
+
+    getScreenSize();
+    setResizable(true);
+ 
     // calling factory method 
     getContentPane().setLayout(new BorderLayout()); 
     menuBar = createMenuBar(); 
@@ -42,6 +50,7 @@
     
     startSessionButton = new JButton("Start Session");
     startSessionButton.addActionListener(new ButtonPressed());
+    startSessionButton.setPreferredSize(new Dimension(screenWidth, (int)((0.1)*screenHeight)));
     getContentPane().add(startSessionButton, BorderLayout.CENTER); 
     
     addWindowListener(new WindowAdapter() {
@@ -51,31 +60,59 @@
 	  }
 	}
       }); 
+      
     
     JPanel lowerContainer = new JPanel(new BorderLayout());
     //lowerContainer.setPreferredSize(new Dimension(1024, 260));
+
+    //add console to lowerContainer
+    consoleCanSay.setPreferredSize(new Dimension(screenWidth, (int)((0.1)*screenHeight)));
+    consoleCanSay.getViewport().getView().setBackground(Color.gray);
+    consoleCanSay.getViewport().getView().setForeground(Color.black);
+    consoleCanSay.setFont(new Font("Arial", Font.BOLD, 14));
+    consoleCanSay.setVerticalScrollBarPolicy(consoleCanSay.VERTICAL_SCROLLBAR_NEVER);
+    lowerContainer.add(consoleCanSay, BorderLayout.SOUTH);   
     
+    
     //add console to topContainer
-    consolePrint.setPreferredSize(new Dimension(1000, 300));
+    consolePrint.setPreferredSize(new Dimension(screenWidth, (int)((0.35)*screenHeight)));
     consolePrint.getViewport().getView().setBackground(Color.white);
     consolePrint.getViewport().getView().setForeground(Color.black);
     consolePrint.setFont(new Font("Arial", Font.BOLD, 14));
     lowerContainer.add(consolePrint, BorderLayout.NORTH);
+
     
+    
     //add console to lowerContainer
-    consoleWrite.setPreferredSize(new Dimension(1000, 350));
+    consoleWrite.setPreferredSize(new Dimension(screenWidth, (int)((0.35)*screenHeight)));
     consoleWrite.getViewport().getView().setBackground(Color.white);
     consoleWrite.getViewport().getView().setForeground(Color.black);
     consoleWrite.setFont(new Font("Arial", Font.BOLD, 14));
-    lowerContainer.add(consoleWrite, BorderLayout.SOUTH);
+    lowerContainer.add(consoleWrite, BorderLayout.CENTER);
+ 
     
-    interpreter = new DecoderInterpreter(consolePrint, consoleWrite, this);
+    
+    interpreter = new DecoderInterpreter(consolePrint, consoleWrite, consoleCanSay, this);
     interpreter.start();
     
     //add lowerContainer to this
     getContentPane().add(lowerContainer, BorderLayout.SOUTH);
   }
   
+  
+  protected void getScreenSize()
+  {
+    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+    GraphicsDevice[] gs = ge.getScreenDevices();
+    
+    // Get size of each screen
+    //for (int i=0; i<gs.length; i++) {
+        DisplayMode dm = gs[0].getDisplayMode();
+        screenWidth = dm.getWidth();
+        screenHeight = dm.getHeight();
+    //}      
+  }
+  
   //Creat teh Drop Down Menu
   protected JMenuBar createMenuBar() {
     JMenuBar menuBar = new JMenuBar();
@@ -126,7 +163,7 @@
     public void actionPerformed(ActionEvent e) {
       int result = JOptionPane.showConfirmDialog(null,
 						 "Do you want to exit?", 
-						 "Exit Treasure Hunt GUI?",
+						 "Exit Calendar GUI?",
 						 JOptionPane.YES_NO_OPTION);
       if (result == JOptionPane.YES_OPTION) {
 	System.exit(0); 
@@ -200,13 +237,13 @@
     }
   }
   
-  public void saySelectBot(String name) {
+/*  public void saySelectBot(String name) {
     ListIterator<JavaTTYServer> i = servers.listIterator();
     while(i.hasNext()) {
       i.next().saySelectBot(name);
     }
   }
-  
+  */
   /*public void selectBot(String name) {
     drawingCanvas.selectBot(name);
   }*/

Modified: Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/JavaTTYServer.java
===================================================================
--- Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/JavaTTYServer.java	2007-04-25 19:54:23 UTC (rev 27)
+++ Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/JavaTTYServer.java	2007-05-02 03:21:57 UTC (rev 28)
@@ -7,6 +7,8 @@
 
 package edu.cmu.ravenclaw.javatty;
 
+import edu.sunysb.CalendarJavaUtils.*;
+
 import com.sun.image.codec.jpeg.JPEGCodec;
 import com.sun.image.codec.jpeg.JPEGImageDecoder;
 import java.io.*;
@@ -32,7 +34,7 @@
     }
     frame.addServer(this);
   }
-  
+  /*
   public void serverOpReinitialize(GFrame f) {
     String botName = (String)f.getProperty(":user_id");
   }
@@ -87,7 +89,7 @@
       GVector y = f.getList(":y");
       return (GFrame) null;
   }
-  
+  */
   public GFrame serverOpSpeak(GFrame f) { 
     String utt = (String)f.getProperty(":tty-phrase");//(":speaktext");
     if(utt==null)
@@ -112,6 +114,7 @@
       String id = "CALENDAR";//(String)f.getProperty(":robot_name");
       //frame.getInterpreter().print_bot(id.replaceFirst("-.*", ""), rendering);
       frame.getInterpreter().print_bot(id, rendering);
+
     }
     return (GFrame) null;
   }
@@ -137,7 +140,7 @@
     }
     return (GFrame) null;
   }
-  
+ /* 
   public GFrame serverOpSelectBot(GFrame f) {
     System.err.println("got select_bot: " + f.toString());
     String inframe = (String)f.getProperty(":inframe");
@@ -161,7 +164,52 @@
     rname.put("[RobotName]", name);
     sayToBot("Commands", "[HumanReportCommand]", rname);
   }
- 
+ */
+  
+ /**
+  * this is calendar application specific. Displays the utterances 
+  * that can be understood dependeing on the grammar
+  *  
+  **/ 
+  public GFrame serverOpSetGrammar(GFrame inputFrame){
+//      loggingHandler.publish(new LogRecord(Level.INFO, "Sphinx4Trans::serverOpSetGrammar  inputframe="
+//                                                                        + inputFrame));                
+
+      System.out.println("SetGrammar is received frame=" + inputFrame);
+      GFrame result = new Clause("");
+      result.setProperty("error", "true");
+            
+      return (GFrame) RavenHack.ravenHack(result);
+}  
+  
+/**
+* Gets the agenda from the inputFrame
+* Displays utterances that may be said
+*/
+public GFrame serverOpSetDialogState(GFrame inputFrame){
+                            
+    System.out.println( "Set Dialog State got called");
+            
+    //get the g
+    String dialogStateStr = ((String)inputFrame.getProperty(":dialog_state"));
+    //NOTE: there is a space after set_grammar BUT no space after can_say. 
+    //why??? that's how DM sends the frame. 
+    String grammarStr = RavenHack.findSubString(dialogStateStr, "set_grammar =");
+        
+    String canSayStr = RavenHack.findSubString(dialogStateStr, "can_say=");    
+        
+    System.err.println("serverOpSetDialogState: Grammar String=" + grammarStr );
+    System.err.println("serverOpSetDialogState: Can say String=" + canSayStr );
+    
+    //let the user know what they can say
+    if(canSayStr!=null)        
+        frame.getInterpreter().print_cansay("You can say", canSayStr);
+    
+                      
+    return null;
+}
+
+
   public void startSession() {
     GFrame f = new Clause("main");
     long time = System.currentTimeMillis()/1000;

Deleted: Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/scribble3/ScribbleCanvas.java
===================================================================
--- Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/scribble3/ScribbleCanvas.java	2007-04-25 19:54:23 UTC (rev 27)
+++ Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/scribble3/ScribbleCanvas.java	2007-05-02 03:21:57 UTC (rev 28)
@@ -1,159 +0,0 @@
-package edu.cmu.ravenclaw.javatty.scribble3;
-
-import net.sourceforge.jiu.codecs.*;
-import net.sourceforge.jiu.gui.awt.ImageCreator;
-import net.sourceforge.jiu.data.PixelImage;
-import java.awt.*;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.NoninvertibleTransformException;
-import java.util.*;
-import java.io.*;
-import java.awt.event.*;
-import java.util.EventListener;
-import javax.swing.*;
-
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBuffer;
-import java.awt.image.IndexColorModel;
-import java.awt.image.WritableRaster;
-
-
-public class ScribbleCanvas extends JComponent implements Scrollable {
-  
-  /** 
-   * The list of shapes of the drawing
-   */
-  protected java.util.List<Shape> shapes = new ArrayList<Shape>();
-  
-  protected Color curColor = Color.black;
-  
-  protected EventListener listener;
-  
-  protected boolean mouseButtonDown = false;
-  protected int x, y;
-  
-  /**
-   * The width and height of the area that the map represents (in centimeters)
-   */
-  protected float native_width, native_height;
-  
-  /**
-   * The width and height of the actual map image (in pixels)
-   */
-  protected float image_width_in_pixels, image_height_in_pixels;
-  
-  /**
-   * The width and height of the rendered map image (in pixels).
-   * The map is streched when the application window grows or during zooming, etc.
-   */
-  protected Dimension view_size;
-  
-  /**
-   * A transform from the map image to the rendered map image
-   * The map is streched when the application window grows or during zooming, etc.
-   */
-  protected AffineTransform mapScale = new AffineTransform();
-  
-  /**
-   * A transform from screen coordinates (pixels, left-handed) 
-   * to map coordinates (centimeters, right-handed)
-   */
-  protected AffineTransform screen_to_map = new AffineTransform();
-
-  /**
-   * A transform from map coordinates (centimeters, right-handed) 
-   * to screen coordinates (pixels, left-handed)
-   */
-  protected AffineTransform map_to_screen = new AffineTransform();
-  
-  
-  public ScribbleCanvas() {
-                                                     
-    String mapfile = null;
-    try {
-      Properties properties = new Properties();
-      properties.load(new FileInputStream("map.properties"));
-      mapfile = properties.getProperty("edu.cmu.ravenclaw.pendecoder.mapfile");
-      if(mapfile == null) throw new Exception("mapfile is missing");
-      String widthstr = properties.getProperty("edu.cmu.ravenclaw.pendecoder.mapwidth");
-      if(widthstr == null) throw new Exception("mapwidth is missing");
-      String heightstr = properties.getProperty("edu.cmu.ravenclaw.pendecoder.mapheight");
-      native_width = Float.parseFloat(widthstr);
-      native_height = Float.parseFloat(heightstr);
-    } catch (NumberFormatException e) {
-      System.err.println("Can't parse double:" + e.toString());
-      System.exit(1);
-    } catch (Exception e) {
-      System.err.println("Problem with properties" + e.toString());
-      System.exit(1);
-    }
-    try {
-      PNGCodec codec = new PNGCodec();
-      codec.setFile(mapfile, CodecMode.LOAD);
-      codec.process();
-      PixelImage pixelimage = codec.getImage();
-
-      setPreferredSize(new Dimension((int)image_width_in_pixels, 
-              (int)image_height_in_pixels));
-    } catch(Exception e) {
-      System.err.println("Problem reading or converting PNG: " + e.toString());
-      System.exit(1);
-    }
-    listener = makeCanvasListener();
-    addMouseListener((MouseListener) listener);
-    addMouseMotionListener((MouseMotionListener) listener);
-  }
-
- 
-  public AffineTransform getScreenToMap() {
-    return screen_to_map;
-  }
-  
-  /**
-   * factory method
-   */
-  protected EventListener makeCanvasListener() {
-    return new ScribbleCanvasListener(this);
-  }
-  
-  //Scrollable methods
-  public void setPreferredSize(Dimension d) {
-    view_size = d;
-    map_to_screen.setToScale(view_size.width/native_width,
-                             -view_size.height/native_height);
-    map_to_screen.translate(native_width/2, -native_height/2);
-
-    mapScale.setToScale(view_size.width/image_width_in_pixels,
-                        -view_size.height/image_height_in_pixels);
-    mapScale.translate(0, -image_height_in_pixels);
-  }
-  
-  public Dimension getPreferredSize() {
-    return view_size;
-  }
-  
-  public Dimension getPreferredScrollableViewportSize() {
-    //return the native size of the image
-    return getPreferredSize();
-  }
-  
-  public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
-    return 1;
-  }
-  
-  public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
-    //scroll by half of the visible image
-    if(orientation == SwingConstants.VERTICAL) return visibleRect.height/2;
-    else return visibleRect.width/2;
-  }
-  
-  public boolean getScrollableTracksViewportWidth() {
-    return false;
-  }
-  
-  public boolean getScrollableTracksViewportHeight() {
-    return false;
-  }
-  
-  private static final long serialVersionUID = -5625162305999062655L;
-}

Deleted: Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/scribble3/ScribbleCanvasListener.java
===================================================================
--- Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/scribble3/ScribbleCanvasListener.java	2007-04-25 19:54:23 UTC (rev 27)
+++ Agents/JavaTTY/src/edu/cmu/ravenclaw/javatty/scribble3/ScribbleCanvasListener.java	2007-05-02 03:21:57 UTC (rev 28)
@@ -1,46 +0,0 @@
-package edu.cmu.ravenclaw.javatty.scribble3; 
-
-import java.awt.*;
-import java.awt.event.*;
-
-public class ScribbleCanvasListener implements MouseListener, MouseMotionListener {
-
-  protected ScribbleCanvas canvas; 
-
-  public ScribbleCanvasListener(ScribbleCanvas canvas) {
-    this.canvas = canvas; 
-  }
-
-  public void mousePressed(MouseEvent e) {
-    Point p = e.getPoint();   
-    canvas.mouseButtonDown = true;
-    canvas.x = p.x; 
-    canvas.y = p.y; 
-  } 
-
-  public void mouseDragged(MouseEvent e) {
-    Point p = e.getPoint(); 
-    if (canvas.mouseButtonDown) {
-      canvas.x = p.x; 
-      canvas.y = p.y; 
-    }       
-  }
-
-  public void mouseReleased(MouseEvent e) {
-    Point p = e.getPoint();      
-    canvas.mouseButtonDown = false;       
-  }    
-  
-  public void mouseClicked(MouseEvent e) {
-    Point p = e.getPoint();
-    if(e.getClickCount() == 1) {
-  }
-  }
-  
-  public void mouseExited(MouseEvent e) {}
-
-  public void mouseEntered(MouseEvent e) {}
-
-  public void mouseMoved(MouseEvent e) {}
-  
-}


More information about the Ravenclaw-developers mailing list