home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIPHEFT062001.ISO / browser / nc32lyc / comm.z / java40.jar / sun / awt / motif / MChoicePeer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-15  |  2.6 KB  |  98 lines

  1. package sun.awt.motif;
  2.  
  3. import java.awt.Choice;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Graphics;
  10. import java.awt.event.ItemEvent;
  11. import java.awt.peer.ChoicePeer;
  12.  
  13. class MChoicePeer extends MComponentPeer implements ChoicePeer {
  14.    native void create(MComponentPeer var1);
  15.  
  16.    native void pReshape(int var1, int var2, int var3, int var4);
  17.  
  18.    public native void select(int var1);
  19.  
  20.    void initialize() {
  21.       Choice var1 = (Choice)super.target;
  22.       int var2 = var1.countItems();
  23.  
  24.       for(int var3 = 0; var3 < var2; ++var3) {
  25.          this.add(var1.getItem(var3), var3);
  26.       }
  27.  
  28.       if (var2 > 0) {
  29.          this.select(var1.getSelectedIndex());
  30.       }
  31.  
  32.       super.initialize();
  33.    }
  34.  
  35.    public MChoicePeer(Choice var1) {
  36.       super(var1);
  37.    }
  38.  
  39.    public boolean isFocusTraversable() {
  40.       return true;
  41.    }
  42.  
  43.    public Dimension getMinimumSize() {
  44.       FontMetrics var1 = ((MComponentPeer)this).getFontMetrics(super.target.getFont());
  45.       Choice var2 = (Choice)super.target;
  46.       int var3 = 0;
  47.  
  48.       for(int var4 = var2.countItems(); var4-- > 0; var3 = Math.max(var1.stringWidth(var2.getItem(var4)), var3)) {
  49.       }
  50.  
  51.       return new Dimension(32 + var3, Math.max(var1.getHeight() + 8, 15) + 5);
  52.    }
  53.  
  54.    public native void setFont(Font var1);
  55.  
  56.    public void add(String var1, int var2) {
  57.       this.addItem(var1, var2);
  58.    }
  59.  
  60.    public native void remove(int var1);
  61.  
  62.    public void removeAll() {
  63.    }
  64.  
  65.    public native void addItem(String var1, int var2);
  66.  
  67.    public native void setBackground(Color var1);
  68.  
  69.    public native void setForeground(Color var1);
  70.  
  71.    void action(int var1) {
  72.       Choice var2 = (Choice)super.target;
  73.       var2.select(var1);
  74.       ((MComponentPeer)this).postEvent(new ItemEvent(var2, 701, var2.getItem(var1), 1));
  75.    }
  76.  
  77.    public void print(Graphics var1) {
  78.       Choice var2 = (Choice)super.target;
  79.       Dimension var3 = ((Component)var2).size();
  80.       Color var4 = ((Component)var2).getBackground();
  81.       Color var5 = ((Component)var2).getForeground();
  82.       var1.setColor(var4);
  83.       var1.fillRect(2, 2, var3.width - 1, var3.height - 1);
  84.       ((MComponentPeer)this).draw3DRect(var1, var4, 1, 1, var3.width - 2, var3.height - 2, true);
  85.       ((MComponentPeer)this).draw3DRect(var1, var4, var3.width - 18, var3.height / 2 - 3, 10, 6, true);
  86.       var1.setColor(var5);
  87.       var1.setFont(((Component)var2).getFont());
  88.       FontMetrics var6 = var1.getFontMetrics();
  89.       String var7 = var2.getSelectedItem();
  90.       var1.drawString(var7, 5, (var3.height + var6.getMaxAscent() - var6.getMaxDescent()) / 2);
  91.       super.target.print(var1);
  92.    }
  93.  
  94.    public Dimension minimumSize() {
  95.       return this.getMinimumSize();
  96.    }
  97. }
  98.