home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / plaf / metal / MetalRadioButtonUI.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  4.0 KB  |  101 lines

  1. package com.sun.java.swing.plaf.metal;
  2.  
  3. import com.sun.java.swing.AbstractButton;
  4. import com.sun.java.swing.ButtonModel;
  5. import com.sun.java.swing.Icon;
  6. import com.sun.java.swing.JComponent;
  7. import com.sun.java.swing.SwingUtilities;
  8. import com.sun.java.swing.UIManager;
  9. import com.sun.java.swing.plaf.ComponentUI;
  10. import com.sun.java.swing.plaf.basic.BasicGraphicsUtils;
  11. import com.sun.java.swing.plaf.basic.BasicRadioButtonUI;
  12. import com.sun.java.swing.plaf.basic.BasicToggleButtonUI;
  13. import java.awt.Component;
  14. import java.awt.Dimension;
  15. import java.awt.Font;
  16. import java.awt.FontMetrics;
  17. import java.awt.Graphics;
  18. import java.awt.Rectangle;
  19.  
  20. public class MetalRadioButtonUI extends BasicRadioButtonUI {
  21.    private static final MetalRadioButtonUI metalRadioButtonUI = new MetalRadioButtonUI();
  22.    protected ButtonModel model;
  23.    // $FF: renamed from: f java.awt.Font
  24.    Font field_0;
  25.    // $FF: renamed from: fm java.awt.FontMetrics
  26.    FontMetrics field_1;
  27.    Rectangle viewRect;
  28.    Rectangle iconRect;
  29.    Rectangle textRect;
  30.    Icon altIcon;
  31.    Icon selectedIcon;
  32.    Icon disabledIcon;
  33.  
  34.    public static ComponentUI createUI(JComponent var0) {
  35.       return metalRadioButtonUI;
  36.    }
  37.  
  38.    public synchronized void paint(Graphics var1, JComponent var2) {
  39.       AbstractButton var3 = (AbstractButton)var2;
  40.       this.model = var3.getModel();
  41.       Dimension var4 = ((Component)var2).getSize();
  42.       this.field_0 = ((Component)var2).getFont();
  43.       var1.setFont(this.field_0);
  44.       this.field_1 = var1.getFontMetrics();
  45.       this.viewRect = new Rectangle(var4);
  46.       this.iconRect = new Rectangle();
  47.       this.textRect = new Rectangle();
  48.       this.altIcon = var3.getIcon();
  49.       this.selectedIcon = null;
  50.       this.disabledIcon = null;
  51.       String var5 = SwingUtilities.layoutCompoundLabel(this.field_1, var3.getText(), this.altIcon != null ? this.altIcon : super.icon, var3.getVerticalAlignment(), var3.getHorizontalAlignment(), var3.getVerticalTextPosition(), var3.getHorizontalTextPosition(), this.viewRect, this.iconRect, this.textRect, ((BasicToggleButtonUI)this).getDefaultTextIconGap(var3));
  52.       if (var2.isOpaque()) {
  53.          var1.setColor(((Component)var3).getBackground());
  54.          var1.fillRect(0, 0, var4.width, var4.height);
  55.       }
  56.  
  57.       if (this.altIcon != null) {
  58.          if (!this.model.isEnabled()) {
  59.             this.altIcon = var3.getDisabledIcon();
  60.          } else if (this.model.isPressed() && this.model.isArmed()) {
  61.             this.altIcon = var3.getPressedIcon();
  62.             if (this.altIcon == null) {
  63.                this.altIcon = var3.getSelectedIcon();
  64.             }
  65.          } else if (this.model.isSelected()) {
  66.             this.altIcon = var3.getSelectedIcon();
  67.          } else if (var3.isRolloverEnabled() && this.model.isRollover()) {
  68.             this.altIcon = var3.getRolloverIcon();
  69.          }
  70.  
  71.          if (this.altIcon == null) {
  72.             this.altIcon = var3.getIcon();
  73.          }
  74.  
  75.          this.altIcon.paintIcon(var2, var1, this.iconRect.x, this.iconRect.y);
  76.       } else {
  77.          super.icon.paintIcon(var2, var1, this.iconRect.x, this.iconRect.y);
  78.       }
  79.  
  80.       if (var5 != null) {
  81.          if (this.model.isEnabled()) {
  82.             var1.setColor(((Component)var3).getForeground());
  83.             BasicGraphicsUtils.drawString(var1, var5, this.model.getMnemonic(), this.textRect.x, this.textRect.y + this.field_1.getAscent());
  84.          } else {
  85.             var1.setColor(((Component)var3).getBackground().darker());
  86.             BasicGraphicsUtils.drawString(var1, var5, this.model.getMnemonic(), this.textRect.x, this.textRect.y + this.field_1.getAscent());
  87.          }
  88.  
  89.          if (((JComponent)var3).hasFocus() && var3.isFocusPainted() && this.textRect.width > 0 && this.textRect.height > 0) {
  90.             this.paintFocus(var1, this.textRect, var4);
  91.          }
  92.       }
  93.  
  94.    }
  95.  
  96.    protected void paintFocus(Graphics var1, Rectangle var2, Dimension var3) {
  97.       var1.setColor(UIManager.getColor("RadioButton.focus"));
  98.       var1.drawRect(var2.x, var2.y - 1, var2.width + 1, var2.height + 1);
  99.    }
  100. }
  101.