home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / sun / awt / windows / WChoicePeer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  2.0 KB  |  54 lines

  1. package sun.awt.windows;
  2.  
  3. import java.awt.Choice;
  4. import java.awt.Dimension;
  5. import java.awt.Event;
  6. import java.awt.FontMetrics;
  7. import java.awt.peer.ChoicePeer;
  8.  
  9. class WChoicePeer extends WComponentPeer implements ChoicePeer {
  10.    native void create(WComponentPeer var1);
  11.  
  12.    void initialize() {
  13.       Choice opt = (Choice)super.target;
  14.       int itemCount = opt.countItems();
  15.  
  16.       for(int i = 0; i < itemCount; ++i) {
  17.          this.addItem(opt.getItem(i), i);
  18.       }
  19.  
  20.       if (itemCount > 0 && opt.getSelectedIndex() >= 0) {
  21.          this.select(opt.getSelectedIndex());
  22.       }
  23.  
  24.       super.initialize();
  25.    }
  26.  
  27.    public WChoicePeer(Choice target) {
  28.       super(target);
  29.    }
  30.  
  31.    public Dimension minimumSize() {
  32.       FontMetrics fm = ((WComponentPeer)this).getFontMetrics(super.target.getFont());
  33.       Choice c = (Choice)super.target;
  34.       int w = 0;
  35.  
  36.       for(int i = c.countItems(); i-- > 0; w = Math.max(fm.stringWidth(c.getItem(i)), w)) {
  37.       }
  38.  
  39.       return new Dimension(28 + w, Math.max(fm.getHeight() + 8, 15) + 3);
  40.    }
  41.  
  42.    public native void addItem(String var1, int var2);
  43.  
  44.    public native void select(int var1);
  45.  
  46.    public native void remove(int var1);
  47.  
  48.    void handleAction(long time, int msgData, int index) {
  49.       Choice c = (Choice)super.target;
  50.       c.select(index);
  51.       super.target.postEvent(new Event(super.target, 1001, c.getItem(index)));
  52.    }
  53. }
  54.