// Insert Unicode In Hex.java
// Cyno's Editor Plug-In

// Cynosure.X International
// 11-6-1997

// Copyright (C) 1997 by Chieh Cheng.
// All Rights Reserved.

package plug_ins;

import cynosurex.awt.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class InsertUnicodeInHex extends Frame
  implements ActionListener, WindowListener
{
  // This variable specifies the string to be displayed
  // by Cyno's Editor.
  // This variable is required for all plug-ins.

  public final static String description = "Insert Unicode In Hex . . .";

  private TextField t = new TextField (50);
  private ShareData shared;

  // This constructor is the constructor
  // to be executed by Cyno's Editor.
  // This constructor is required for all plug-ins.

  public InsertUnicodeInHex (ShareData shared)
  {
    super (description);
    this.shared = shared;
    setLayout (new BorderLayout ());
    setBackground (SystemColor.text);
    add ("Center", t);

    t.addActionListener (this);
    addWindowListener (this);

    pack ();

    Point p = shared.getTextArea ().getLocationOnScreen ();
    p.x -= 200;
    p.y -= 150;

    Location l = new Location (p, getSize ());

    setLocation (l);
    setVisible (true);
  }

  public void actionPerformed (ActionEvent event)
  {
    EnhancedTextArea eta = shared.getTextArea ();
    StringBuffer buffer = new StringBuffer ();
    StringTokenizer tokens = new StringTokenizer (t.getText ());

    while (tokens.hasMoreTokens ())
    {
      char ch = (char) Integer.parseInt (tokens.nextToken (), 16);

      buffer.append (ch);
    }

    eta.insert (buffer.toString (), eta.getSelectionStart ());

    t.setText ("");
  }

  public void windowActivated (WindowEvent event)
  {
  }
  public void windowClosed (WindowEvent event)
  {
  }
  public void windowClosing (WindowEvent event)
  {
    setVisible (false);
    dispose ();
  }
  public void windowDeactivated (WindowEvent event)
  {
  }
  public void windowDeiconified (WindowEvent event)
  {
  }
  public void windowIconified (WindowEvent event)
  {
  }
  public void windowOpened (WindowEvent event)
  {
  }
}
