home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / awt / win32 / MTextFieldPeer.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  2.6 KB  |  81 lines

  1. /*
  2.  * @(#)MTextFieldPeer.java    1.9 95/09/19 Sami Shaio
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.awt.win32;
  21.  
  22. import java.awt.*;
  23. import java.awt.peer.*;
  24.  
  25. public class MTextFieldPeer extends MComponentPeer implements TextFieldPeer {
  26.     native void create(MComponentPeer parent);
  27.  
  28.     void initialize() {
  29.     TextField txt = (TextField)target;
  30.  
  31.     setText(txt.getText());
  32.     if (txt.echoCharIsSet()) {
  33.         setEchoCharacter(txt.getEchoChar());
  34.     }
  35.     select(txt.getSelectionStart(), txt.getSelectionEnd());
  36.     setEditable(txt.isEditable());
  37.     super.initialize();
  38.     }
  39.  
  40.     public MTextFieldPeer(TextField target) {
  41.     super(target);
  42.     }
  43.  
  44.     public void setEditable(boolean editable) {
  45.     pSetEditable(editable);
  46.     setBackground(target.getBackground());
  47.     }
  48.     public void setBackground(Color c) {
  49.     TextField t = (TextField)target;
  50.     if (t.isEditable()) {
  51.         c = c.brighter();
  52.     }
  53.     super.setBackground(c);
  54.     }
  55.     public native void pSetEditable(boolean editable);
  56.     public native void select(int selStart, int selEnd);
  57.     public native int getSelectionStart();
  58.     public native int getSelectionEnd();
  59.     public native void setText(String l);
  60.     public native void dispose();
  61.     public native String getText();
  62.     public native void setEchoCharacter(char c);
  63.  
  64.     public Dimension minimumSize() {
  65.     FontMetrics fm = getFontMetrics(target.getFont());
  66.     return new Dimension(fm.stringWidth(((TextField)target).getText()) + 20, 
  67.                     fm.getHeight() + 8);
  68.     }
  69.     public Dimension preferredSize(int cols) {
  70.     return minimumSize(cols);
  71.     }
  72.     public Dimension minimumSize(int cols) {
  73.     FontMetrics fm = getFontMetrics(target.getFont());
  74.     return new Dimension(fm.charWidth('0') * cols + 20,fm.getHeight() + 8);
  75.     }
  76.  
  77.     public void action() {
  78.     target.postEvent(new Event(target, Event.ACTION_EVENT, ((TextField)target).getText()));
  79.     }
  80. }
  81.