/* 
 * Message.java
 *
 * by Kwan Hoi Ching Eddie
 * 
 * last revised: 06/06/1996
 *
 */

import java.awt.*;
import java.applet.*;
import java.lang.*;
import java.util.*;

/* message box in the display. */
public class Message extends Applet {

  /* set the background and foreground color. */
  Color bg_color = new Color(180, 180, 180);
  Color fg_color1 = new Color(0, 0, 200);
  Color fg_color2 = Color.black;
  Font font1, font2;
  int width, height;

  DisplayPanel display;
  String dString, eString, vString;
  Cell currCell;
  int cellNum;
  int dim, type;
  int row, column;

  // constructor
  public Message(DisplayPanel d, int r, int c) {

    width = 440;
    height = 50;

    display = d;

    currCell = display.getCurrCell();
    cellNum = display.getCellNum();
    dim = display.getDim();
    type = currCell.getType();
    row = r;
    column = c;

    dString = "";
    eString = "";
    vString = "";

    font1 = new Font("TimesRoman", Font.ITALIC, 14);
    font2 = new Font("Courier", Font.PLAIN, 12);
  }

  /* paint the message box on the display. */
  public void paint(Graphics g, int x, int y) {

    int x0 = x - width;
    int y0 = y - height;

    String t = "";

    int dOff = 20;
    int eOff = 20;
    int vOff = 250;

    g.setColor(bg_color);
    g.fill3DRect(x0, y0, width, height, true);

    g.setColor(fg_color1);
    g.setFont(font1);
    g.drawString("Declaration: ", x0+dOff, y0+18);
    g.drawString("Element: ", x0+eOff, y0+38);
    g.drawString("Content: ", x0+vOff, y0+38);

    g.setColor(fg_color2);
    g.setFont(font2);
    // for Declaration
    switch (type) {
      case ArrayVisual.INT:
        t = "int";
        break;
      case ArrayVisual.CHAR:
        t = "char";
        break;
      case ArrayVisual.FLOAT:
        t = "float";
        break;
      case ArrayVisual.DOUBLE:
        t = "double";
        break;
      default:
        break;
    }
    if (dim == 1) {
      dString = t + " " + display.getName() + "[" + Integer.toString(cellNum) + "];";
      eString = display.getName() + "[" + Integer.toString(row) + "]";
    } else if (dim == 2) {
      dString = t + " " + display.getName() + "[" + Integer.toString(display.getSize(2)) + "]" +
            "[" + Integer.toString(display.getSize(1)) + "];";
      eString = display.getName() + "[" + Integer.toString(column) + "][" + Integer.toString(row) + "]";
    }

    vString = currCell.getValue();

    g.drawString(dString, x0+dOff+80, y0+18);
    g.drawString(eString, x0+eOff+60, y0+38);
    g.drawString(vString, x0+vOff+60, y0+38);
  }


}

