package aji;

/**
 * windows用のステータスバー。
 * Linuxだと表示されない。（たしか）
 */
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.SWT;

//Windowのステータスバー生成クラス
public class StatusBar{

  private Canvas canvas;
  private String text;
  private Image image;
  private int flag;
  private GC gc;

  // コンストラクタ
  public StatusBar(Shell shell, int flag) {
    image = null;
    text = "";
    this.flag = flag;

    canvas = new Canvas(shell, SWT.NULL);
    canvas.setBounds(0,530,791,50);
    canvas.addPaintListener(new PaintListener() {
    	public void paintControl(PaintEvent e) {
    		redraw();
    	}
    });

    gc = new GC(canvas);
    gc.setBackground(shell.getBackground());
  }

  // 描画メソッド
  private void redraw() {
    gc.fillRectangle(canvas.getClientArea());
    if ( (flag & SWT.BORDER) != 0) {
      int height = canvas.getClientArea().height - 1;
      int width = canvas.getClientArea().width - 1;
      gc.setForeground(new Color(null, 127, 127, 127));
      gc.drawLine(0, 0, width, 0);
      gc.drawLine(0, 0, 0, height);
      gc.setForeground(new Color(null, 255, 255, 255));
      gc.drawLine(width, 0, width, height);
      gc.drawLine(0, height, width, height);
      gc.setForeground(new Color(null, 0, 0, 0));
    }
    if (image != null) {
      gc.drawImage(image, 0, 0, image.getBounds().width,
                   image.getBounds().height, 2, 1, 16, 16);
      gc.drawString(text, 22, 3);
    }
    else {
      gc.drawString(text, 3, 3);
    }
  }

  public void setText(String str) {
    this.text = str;
    redraw();
  }

  public void setImage(Image img) {
    this.image = img;
    redraw();
  }

  public void setLayoutData(Object obj) {
    if (obj instanceof GridData) {
      if ( ( (GridData) obj).heightHint < 18) {
        ( (GridData) obj).heightHint = 18;
      }
    }
    canvas.setLayoutData(obj);
  }
}

