The Java Console

This little Java applet was built in 1996 as a proof of concept for the user interface in the Lunar Rover project at CMU. Here we go; you can click inside the driving wheel (just dragging the mouse does not have any effect):


The code that generated this applet is below.

© Fabio Cozman[Send Mail?]


import java.awt.*;
import java.applet.*;

public class Console extends Applet {
 BorderPanel left_panel = new BorderPanel(new Panel());
  Button emergency_stop_button = new Button("Emergency Stop");
  Choice morphin_choice = new Choice();
  Choice external_arc_set = new Choice();
  Choice user_mode = new Choice();
  
  BorderPanel center_panel = new BorderPanel(new DrivingWheelPanel(30, 20));

  BorderPanel right_panel = new BorderPanel(new Panel());
  Scrollbar user_speed = new Scrollbar(Scrollbar.VERTICAL, 15, 10, 0, 100);
  BorderPanel user_speed_panel = new BorderPanel(user_speed, 5);
  Scrollbar arbiter_speed = new Scrollbar(Scrollbar.VERTICAL, 15, 10, 0, 100);
  BorderPanel arbiter_speed_panel = new BorderPanel(arbiter_speed, 5);
  Scrollbar vehicle_speed = new Scrollbar(Scrollbar.VERTICAL, 15, 10, 0, 100);
  BorderPanel vehicle_speed_panel = new BorderPanel(vehicle_speed, 5);

  BorderPanel bottom_panel = new BorderPanel(new Panel());
  Button something_button = new Button("Something");
  Button scanner_override_button = new Button("Scanner Override");

public void init() {
  Panel internal_panel;

  internal_panel =  (Panel)left_panel.component;
  internal_panel.setLayout(new GridLayout(4,1));
  internal_panel.add(emergency_stop_button);
  internal_panel.add(morphin_choice);
  morphin_choice.addItem("Morphin");
  morphin_choice.addItem("Morphin and D*");
  morphin_choice.addItem("None");
  internal_panel.add(external_arc_set);
  external_arc_set.addItem("Extended arc set");
  external_arc_set.addItem("Restricted arc set");
  external_arc_set.addItem("Full arc set");
  internal_panel.add(user_mode);
  user_mode.addItem("User is boss");
  user_mode.addItem("User is partner");

  internal_panel = (Panel)right_panel.component;
  internal_panel.setLayout(new GridLayout(1,3));
  internal_panel.add(user_speed_panel);
  internal_panel.add(arbiter_speed_panel);
  internal_panel.add(vehicle_speed_panel);

  internal_panel = (Panel)bottom_panel.component;
  internal_panel.setLayout(new FlowLayout());
  internal_panel.add(scanner_override_button);
  internal_panel.add(something_button);

  setLayout(new BorderLayout());
  add("West", left_panel);
  add("Center", center_panel);
  add("East", right_panel);
  add("South", bottom_panel);
  show();
}
}

class DrivingWheelPanel extends Panel {
  private   int       thick, x, y, size;
  private   int       begin_x, end_x, begin_y, end_y;
  private   Color     lineColor, fillColor, borderColor;
  private static final int DEFAULT_THICKNESS = 2;
  private static final int DRIVING_WHEEL_SIZE = 200;

  DrivingWheelPanel() {
    this(DEFAULT_THICKNESS, DRIVING_WHEEL_SIZE, 0, 0);
  }

  DrivingWheelPanel(int size) {
    this(DEFAULT_THICKNESS, size, 0, 0);
  }

  DrivingWheelPanel(int x, int y) {
    this(DEFAULT_THICKNESS, DRIVING_WHEEL_SIZE, x, y);
  }

  DrivingWheelPanel(int size, int x, int y) {
    this(DEFAULT_THICKNESS, size, x, y);
  }

  DrivingWheelPanel(int thick, int size, int x, int y) {
    this.thick    = thick;
    this.x = x;
    this.y = y;
    this.begin_x = x + size/2;
    this.end_x = begin_x;
    this.begin_y = y + size/2;
    this.end_y = begin_y;
    this.size = size;
    this.borderColor = Color.blue;
    this.fillColor = Color.red;
    this.lineColor = Color.orange;
  }

  public void setEnd(int x, int y) {
    end_x = x;
    end_y = y;
  }

  public void paint(Graphics g) {
    super.paint(g);
    paintFlat(g);
    g.setColor(lineColor);
    g.drawOval(x, y, size-1, size-1);
    g.drawOval(x, y, size-2, size-2);
    g.drawLine(begin_x, begin_y, end_x, end_y);
  }

  private void paintFlat(Graphics g) {
    fill(g);
    g.setColor(borderColor);
    for(int i=0; i < thick; ++i)
      g.drawRect(x+i, y+i, size-(i*2)-1, size-(i*2)-1);
  }

  public void fill(Graphics g) {
    Rectangle r = getInnerBounds();
    g.setColor(fillColor);
    g.fillRect(r.x, r.y, r.width, r.height);
  }

  public Rectangle getInnerBounds() {
    return(new Rectangle(x+thick, y+thick, size-(thick*2), size-(thick*2)));
  }

  public boolean mouseDown(Event event, int x, int y) {
    int distance = (x - begin_x)*(x - begin_x) + (y - begin_y)*(y - begin_y);
    if (distance <= ((size*size)/4)) {
      Graphics g = getGraphics();
      g.setColor(fillColor);
      g.drawLine(begin_x, begin_y, end_x, end_y);
      setEnd(x, y);
      g.setColor(lineColor);
      g.drawLine(begin_x, begin_y, end_x, end_y);
    }
    return(true);
  }
}

class BorderPanel extends Panel {
final private int BORDER_SIZE = 10;
private int border_size = 10;
Component component;
  
public BorderPanel(Component borderMe) { 
  component = borderMe;
  border_size = BORDER_SIZE;
  setLayout(new BorderLayout());
  add("Center", borderMe);
}
public BorderPanel(Component borderMe, int size) { 
  component = borderMe;
  border_size = size;
  setLayout(new BorderLayout());
  add("Center", borderMe);
}
public void paint(Graphics g) {
  Dimension mySize   = size();
  Insets    myInsets = insets();
  g.setColor(Color.green);
  g.fillRect(0, 0, mySize.width, myInsets.top);
  g.fillRect(0, 0, myInsets.left, mySize.height);
  g.fillRect(mySize.width - myInsets.right, 0, 
	     myInsets.right, mySize.height);
  g.fillRect(0, mySize.height - myInsets.bottom, 
	     mySize.width, mySize.height);
}
public Insets insets() { 
  return new Insets(border_size,border_size,border_size,border_size); 
}
}