package graphbrowser;

import java.awt.event.*;
import java.applet.*;
import java.awt.*;

import graph.*;


public class GraphPropertyDialog extends Dialog implements ActionListener {


  Label     label1,label2,label3,label22,label33,label4,label44;
  TextField text1,text2,text3,text22;
  GraphWindow     source;
  Choice    mime;
  Button    okButton,cancelButton;
  String    value1,value2;
  boolean   pmode;
  Graph     graph;
  public static String graphc="Graph";
  public static String htmlc="HTML Content";
  public static String textc="PLAIN TEXT Content";

  public GraphPropertyDialog(Frame parent,Graph agraph,boolean editable) {
      super(parent,"Graph Property",true); // model dialog
      source=(GraphWindow) parent;
      pmode=editable;
      this.graph=agraph;
      reset();
  }

/*  private String translate(MIME_Type mt) {
    if ( node.getContent() ==null) return("NULL CONTENT");
    if (mt.getType()==mt.GRAPH) return graphc;
    else if (mt.getType()==mt.TEXT)
        if (mt.getSubtype()==mt.HTML) return htmlc;
            else if (mt.getSubtype()==mt.PLAIN) return textc;
    return graphc;
  }
*/
  public void reset() {

      value1=new String("");
      //value2=new String("");
      label1=new Label("     Graph Label");
      text1=new TextField(graph.getLabel());

      text2=new TextField(10);
      //text3=new TextField(10);

      /*mime=new Choice();
      mime.addItem(graphc);
      mime.addItem(htmlc);
      mime.addItem(textc); */
      //mime.addItem();

      okButton=new Button("OK");
      //cancelButton=new Button("Cancel");

      setLayout(new BorderLayout() );

      Panel p1=new Panel();
      p1.setLayout(new GridLayout(2,2,0,0) );
      p1.add(label1);
      p1.add(text1);

      if (!pmode) text1.setEditable(false);
      /*label33=new Label(node.getUID().toString());
      label3=new Label("Node OID:");
      p1.add(label3);
      p1.add(label33);

      p1.add(label2);
      //p1.add(mime);
      p1.add(label22);

      String cstr;

      if (node.getContent() ==null) cstr="NULL";
        else cstr=node.getContent().toString();
      label44=new Label(cstr);
      label4=new Label("NodeContent OID:");
      p1.add(label4);
      p1.add(label44);
      */

      label2=new Label("     Graph OID:");
      if (graph==null) System.out.println("graph is null");
      if (graph.getUID() ==null) System.out.println("graph oid is null");

      //label22=new Label( graph.getUID().toString() );
      text22=new MyTextField(graph.getUID().toString(), graph.getUID().toString().length()+1);
      text22.setEditable(false);
      text22.setBackground(Color.white);
      p1.add(label2);
      p1.add(text22);

      /*if (pmode) { mime.select(translate(mt)); mime.setEnabled(false); }
        else { mime.select(graphc);
                mt=new MIME_Type(); } */

      //p1.add(label3);
      //p1.add(text3);

      //text2.setEchoChar('*'); // for password use
      //text3.setEchoChar('*'); // for password use

      Panel p2=new Panel();
      p2.setLayout(new FlowLayout(FlowLayout.CENTER));
      p2.add(okButton);
      //p2.add(cancelButton);

      // add event listeners
      okButton.addActionListener(this);
      //cancelButton.addActionListener(this);
      //mime.addItemListener(this);
      //text2.addActionListener(this);

      this.setEnabled(true);
      if (pmode) text1.setEnabled(true);  // enable editing of text1

      this.add(p1,"North");
      this.add(p2,"South");
      this.pack();
      this.setLocation(source.getLocation().x+10,source.getLocation().y+10);
      //this.show();
  }

  public void setLabel(String value) {
    text1.setText(value);
    //text2.setText("");
    //text3.setText("");
  }

  public void actionPerformed(ActionEvent e) {

    //public boolean action(Event event, Object object) {
     Object esource=e.getSource();
    //Object esource=event.target;

    if ( (esource == okButton) ) {
        // error checking and setting the value
        value1=text1.getText();
        graph.setLabel(value1);

        if ( value1.equals("") )return;// true;
        this.setVisible(false);
        return;// true;
    }

  }

  /*public void itemStateChanged(ItemEvent e) {
    String selected=(String) e.getItem();
    if (selected ==null) return;
    if (selected.equals(graphc))
        { mt.setType(MIME_Type.GRAPH);
          mt.setSubtype(MIME_Type.NET);}
     else if (selected.equals(htmlc))
        { mt.setType(MIME_Type.TEXT);
          mt.setSubtype(MIME_Type.HTML);}
     else if (selected.equals(textc))
        { mt.setType(MIME_Type.TEXT);
          mt.setSubtype(MIME_Type.PLAIN);}
  }*/
  // callback for external data-fetching use

  public String getLabel() {
    return value1;
  }

  /*public MIME_Type getType() {
    return mt;
  }*/

}
