Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. package rene.gui;
  2.  
  3. import java.awt.TextField;
  4. import java.awt.event.FocusEvent;
  5. import java.awt.event.FocusListener;
  6.  
  7. /**
  8. A TextField with a modifyable background and font. This is used in
  9. DoActionListener interfaces.
  10. */
  11.  
  12. public class TextFieldAction extends TextField
  13.         implements FocusListener
  14. {       protected ActionTranslator T;
  15.         String S;
  16.         public TextFieldAction (DoActionListener t, String name, String s)
  17.         {       super(s);
  18.                 S=s;
  19.                 if (Global.NormalFont!=null) setFont(Global.NormalFont);
  20.                 if (Global.Background!=null) setBackground(Global.Background);
  21.                 T=new ActionTranslator(t,name);
  22.                 addActionListener(T);
  23.                 addFocusListener(this);
  24.         }
  25.         public TextFieldAction (DoActionListener t, String name)
  26.         {       if (Global.NormalFont!=null) setFont(Global.NormalFont);
  27.                 if (Global.Background!=null) setBackground(Global.Background);
  28.                 T=new ActionTranslator(t,name);
  29.                 addActionListener(T);
  30.                 addFocusListener(this);
  31.         }
  32.         public TextFieldAction (DoActionListener t, String name, int n)
  33.         {       super(n);
  34.                 if (Global.NormalFont!=null) setFont(Global.NormalFont);
  35.                 if (Global.Background!=null) setBackground(Global.Background);
  36.                 T=new ActionTranslator(t,name);
  37.                 addActionListener(T);
  38.                 addFocusListener(this);
  39.         }
  40.         public TextFieldAction (DoActionListener t, String name, String s, int n)
  41.         {       super(s,n);
  42.                 S=s;
  43.                 if (Global.NormalFont!=null) setFont(Global.NormalFont);
  44.                 if (Global.Background!=null) setBackground(Global.Background);
  45.                 T=new ActionTranslator(t,name);
  46.                 addActionListener(T);
  47.                 addFocusListener(this);
  48.         }
  49.         public void triggerAction ()
  50.         {       T.trigger();
  51.         }
  52.         public void focusGained (FocusEvent e)
  53.         {       setSelectionStart(0);
  54.         }
  55.         public void focusLost (FocusEvent e)
  56.         {       setSelectionStart(0);
  57.                 setSelectionEnd(0);
  58.         }
  59.         public void setText (String s)
  60.         {       super.setText(s);
  61.                 S=s;
  62.         }
  63.         public String getOldText ()
  64.         {       return S;
  65.         }
  66.         public boolean isChanged ()
  67.         {       return !S.equals(getText());
  68.         }
  69. }
  70.