home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / plaf / basic / BasicRadioButtonUI.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  5.3 KB  |  173 lines

  1. package javax.swing.plaf.basic;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Insets;
  10. import java.awt.Rectangle;
  11. import javax.swing.AbstractButton;
  12. import javax.swing.ButtonModel;
  13. import javax.swing.Icon;
  14. import javax.swing.JComponent;
  15. import javax.swing.SwingUtilities;
  16. import javax.swing.UIManager;
  17. import javax.swing.plaf.ComponentUI;
  18. import javax.swing.text.View;
  19.  
  20. public class BasicRadioButtonUI extends BasicToggleButtonUI {
  21.    private static final BasicRadioButtonUI radioButtonUI = new BasicRadioButtonUI();
  22.    protected Icon icon;
  23.    private boolean defaults_initialized = false;
  24.    private static final String propertyPrefix = "RadioButton.";
  25.    private static Dimension size = new Dimension();
  26.    private static Rectangle viewRect = new Rectangle();
  27.    private static Rectangle iconRect = new Rectangle();
  28.    private static Rectangle textRect = new Rectangle();
  29.    private static Rectangle prefViewRect = new Rectangle();
  30.    private static Rectangle prefIconRect = new Rectangle();
  31.    private static Rectangle prefTextRect = new Rectangle();
  32.    private static Insets prefInsets = new Insets(0, 0, 0, 0);
  33.  
  34.    public static ComponentUI createUI(JComponent var0) {
  35.       return radioButtonUI;
  36.    }
  37.  
  38.    protected String getPropertyPrefix() {
  39.       return "RadioButton.";
  40.    }
  41.  
  42.    protected void installDefaults(AbstractButton var1) {
  43.       super.installDefaults(var1);
  44.       if (!this.defaults_initialized) {
  45.          this.icon = UIManager.getIcon(this.getPropertyPrefix() + "icon");
  46.          this.defaults_initialized = true;
  47.       }
  48.  
  49.    }
  50.  
  51.    protected void uninstallDefaults(AbstractButton var1) {
  52.       super.uninstallDefaults(var1);
  53.       this.defaults_initialized = false;
  54.    }
  55.  
  56.    public Icon getDefaultIcon() {
  57.       return this.icon;
  58.    }
  59.  
  60.    public synchronized void paint(Graphics var1, JComponent var2) {
  61.       AbstractButton var3 = (AbstractButton)var2;
  62.       ButtonModel var4 = var3.getModel();
  63.       Font var5 = ((Component)var2).getFont();
  64.       var1.setFont(var5);
  65.       FontMetrics var6 = var1.getFontMetrics();
  66.       size = ((JComponent)var3).getSize(size);
  67.       viewRect.x = viewRect.y = 0;
  68.       viewRect.width = size.width;
  69.       viewRect.height = size.height;
  70.       iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
  71.       textRect.x = textRect.y = textRect.width = textRect.height = 0;
  72.       Icon var7 = var3.getIcon();
  73.       Object var8 = null;
  74.       Object var9 = null;
  75.       String var10 = SwingUtilities.layoutCompoundLabel(var2, var6, var3.getText(), var7 != null ? var7 : this.getDefaultIcon(), var3.getVerticalAlignment(), var3.getHorizontalAlignment(), var3.getVerticalTextPosition(), var3.getHorizontalTextPosition(), viewRect, iconRect, textRect, ((BasicButtonUI)this).getDefaultTextIconGap(var3));
  76.       if (var2.isOpaque()) {
  77.          var1.setColor(((Component)var3).getBackground());
  78.          var1.fillRect(0, 0, size.width, size.height);
  79.       }
  80.  
  81.       if (var7 != null) {
  82.          if (!var4.isEnabled()) {
  83.             if (var4.isSelected()) {
  84.                var7 = var3.getDisabledSelectedIcon();
  85.             } else {
  86.                var7 = var3.getDisabledIcon();
  87.             }
  88.          } else if (var4.isPressed() && var4.isArmed()) {
  89.             var7 = var3.getPressedIcon();
  90.             if (var7 == null) {
  91.                var7 = var3.getSelectedIcon();
  92.             }
  93.          } else if (var4.isSelected()) {
  94.             if (var3.isRolloverEnabled() && var4.isRollover()) {
  95.                var7 = var3.getRolloverSelectedIcon();
  96.                if (var7 == null) {
  97.                   var7 = var3.getSelectedIcon();
  98.                }
  99.             } else {
  100.                var7 = var3.getSelectedIcon();
  101.             }
  102.          } else if (var3.isRolloverEnabled() && var4.isRollover()) {
  103.             var7 = var3.getRolloverIcon();
  104.          }
  105.  
  106.          if (var7 == null) {
  107.             var7 = var3.getIcon();
  108.          }
  109.  
  110.          var7.paintIcon(var2, var1, iconRect.x, iconRect.y);
  111.       } else {
  112.          this.getDefaultIcon().paintIcon(var2, var1, iconRect.x, iconRect.y);
  113.       }
  114.  
  115.       if (var10 != null) {
  116.          View var11 = (View)var2.getClientProperty("html");
  117.          if (var11 != null) {
  118.             var11.paint(var1, textRect);
  119.          } else {
  120.             if (var4.isEnabled()) {
  121.                var1.setColor(((Component)var3).getForeground());
  122.                BasicGraphicsUtils.drawString(var1, var10, var4.getMnemonic(), textRect.x, textRect.y + var6.getAscent());
  123.             } else {
  124.                var1.setColor(((Component)var3).getBackground().brighter());
  125.                BasicGraphicsUtils.drawString(var1, var10, var4.getMnemonic(), textRect.x + 1, textRect.y + var6.getAscent() + 1);
  126.                var1.setColor(((Component)var3).getBackground().darker());
  127.                BasicGraphicsUtils.drawString(var1, var10, var4.getMnemonic(), textRect.x, textRect.y + var6.getAscent());
  128.             }
  129.  
  130.             if (((JComponent)var3).hasFocus() && var3.isFocusPainted() && textRect.width > 0 && textRect.height > 0) {
  131.                this.paintFocus(var1, textRect, size);
  132.             }
  133.          }
  134.       }
  135.  
  136.    }
  137.  
  138.    protected void paintFocus(Graphics var1, Rectangle var2, Dimension var3) {
  139.    }
  140.  
  141.    public Dimension getPreferredSize(JComponent var1) {
  142.       if (((Container)var1).getComponentCount() > 0) {
  143.          return null;
  144.       } else {
  145.          AbstractButton var2 = (AbstractButton)var1;
  146.          String var3 = var2.getText();
  147.          Icon var4 = var2.getIcon();
  148.          if (var4 == null) {
  149.             var4 = this.getDefaultIcon();
  150.          }
  151.  
  152.          Font var5 = ((Component)var2).getFont();
  153.          FontMetrics var6 = ((Component)var2).getToolkit().getFontMetrics(var5);
  154.          prefViewRect.x = prefViewRect.y = 0;
  155.          prefViewRect.width = 32767;
  156.          prefViewRect.height = 32767;
  157.          prefIconRect.x = prefIconRect.y = prefIconRect.width = prefIconRect.height = 0;
  158.          prefTextRect.x = prefTextRect.y = prefTextRect.width = prefTextRect.height = 0;
  159.          SwingUtilities.layoutCompoundLabel(var1, var6, var3, var4, var2.getVerticalAlignment(), var2.getHorizontalAlignment(), var2.getVerticalTextPosition(), var2.getHorizontalTextPosition(), prefViewRect, prefIconRect, prefTextRect, var3 == null ? 0 : ((BasicButtonUI)this).getDefaultTextIconGap(var2));
  160.          int var7 = Math.min(prefIconRect.x, prefTextRect.x);
  161.          int var8 = Math.max(prefIconRect.x + prefIconRect.width, prefTextRect.x + prefTextRect.width);
  162.          int var9 = Math.min(prefIconRect.y, prefTextRect.y);
  163.          int var10 = Math.max(prefIconRect.y + prefIconRect.height, prefTextRect.y + prefTextRect.height);
  164.          int var11 = var8 - var7;
  165.          int var12 = var10 - var9;
  166.          prefInsets = ((JComponent)var2).getInsets(prefInsets);
  167.          var11 += prefInsets.left + prefInsets.right;
  168.          var12 += prefInsets.top + prefInsets.bottom;
  169.          return new Dimension(var11, var12);
  170.       }
  171.    }
  172. }
  173.