CS 4773 Object Oriented Systems


The New JOTSA

The following describes the new JOTSA interface.

Before:

The applet sets up a layout with widgets and JOTSA draws into what is left of the applet's window.

Now:

The applet sets up a layout containing the JotsaDefaultCanvas and JOTSA draws into that canvas.

A simple JOTSA applet will do the following:


Additional canvases of type JotsaCanvas may be created with
Canvases, other than the defalt one should be inserted into a list of canvases to be displayed with
The default paint method is:
   public void paint(Graphics g) {
      JotsaPaintStart();
      JotsaDisplayCanvases();
      JotsaPaintEnd();
   }
This takes care of all popups and scaled windows.



A popup jotsa creates an additional canvas with a few buttons such as hide and remove.

Scaled windows will consist of a

MakeScaledWindow will make a standard window containing a scaled canvas and one of these position canvases along with sliders for position and scaling.


Events:

Events are handled by overiding JotsaHandleCanvasEvent.

You can overide eith of these:

   public boolean JotsaHandleCanvasEvent(Event e, JotsaCanvas canv);
   public boolean JotsaHandleCanvasEvent(Event e);
The first gives you the Canvas from which the event occurred.

The default

JotsaHandleCanvasEvent(Event e, JotsaCanvas canv)
just calls
  JotsaHandleCanvasEvent(e)
and returns if this returned true; Otherwise it returns false. The default
  JotsaHandleCanvasEvent(Event e)
just returns false.

If your JotsaHandleCanvasEvent handles the event it should return true, otherwise it should return super.handleEvent(e);

Actions:

Actions should be handled in a similar but this has not been implemented yet.


Here is the new version of the first test program





/*
   < Applet code = "jtest1.simple"
           width = 200 height = 200 >
   < /applet >
 */

package jtest1;
import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import jotsa.*;

public class simple extends JotsaAnimationApplet {
   Button doit;
   JotsaAnimationObject obj;
   Color C = new Color(255,0,0);
   int start_x = 20;
   int start_y = 10;
   int end_x = 120;
   int end_y = 120;
   int start_size = 20;
   int end_size = 30;
   int move_time = 5000;


   public void init() {
      super.init();
      setLayout(new BorderLayout());
      add("South",doit = new Button("Do It"));
      add("Center",JotsaDefaultCanvas);
      validate();
      JotsaInitImages();
      JotsaWriteBackgroundString("A simple JOTSA example",20,100,Color.blue);
      obj = new JotsaAnimationObject(start_x,start_y,1,1,this);
      obj.set_fill_centered_oval(start_size,start_size,C);
      obj.path_create_along_line(start_x,start_y,end_x,end_y);
      obj.set_size_linear(start_size,end_size);
   }

   public boolean action(Event e,Object arg) {
      if ("Do It".equals(arg)) {
         System.out.println("Do It Pushed");
         doit.setLabel("Move It");
         JotsaRemoveAllObjects();
         obj.deactivate();
         obj.times_set(move_time);
         JotsaInsertObject(obj);
         repaint(1);
         return true;
      }  
      if ("Move It".equals(arg)) {
         System.out.println("Move It Pushed");
         doit.setLabel("Do It");
         obj.activate_delay();
         JotsaForceRedisplay();
         return true;
      }
      return super.action(e,arg);
   }
}

Here are the new parts of the second example:
package jtest2;

import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import jotsa.*;

public class example extends JotsaAnimationApplet {
   
...

   public void init() {
       super.init(); 
       width = bounds().width;
       selected = -1;
       height = setup_layout();
       System.out.println("Height is "+height);
       JotsaInitImages();

...


   private int setup_layout() {
       setLayout(new BorderLayout());
       Panel p = new Panel();
       Panel q = new Panel();
...
       add("Center",JotsaDefaultCanvas);
       add("South",p);
       validate();
...
   }

   public boolean JotsaHandleCanvasEvent(Event e, JotsaCanvas canv) {
         int move_time;
         int level;
      if (e.id == Event.MOUSE_DOWN) {
         change_to_canvas(canv);
...