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

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.AbstractButton;
  4. import com.sun.java.swing.Icon;
  5. import com.sun.java.swing.JComponent;
  6. import com.sun.java.swing.JMenuItem;
  7. import com.sun.java.swing.JRadioButtonMenuItem;
  8. import com.sun.java.swing.LookAndFeel;
  9. import com.sun.java.swing.MenuElement;
  10. import com.sun.java.swing.MenuSelectionManager;
  11. import com.sun.java.swing.UIManager;
  12. import com.sun.java.swing.plaf.ComponentUI;
  13. import com.sun.java.swing.plaf.RadioButtonMenuItemUI;
  14. import com.sun.java.swing.plaf.UIResource;
  15. import java.awt.AWTEvent;
  16. import java.awt.Color;
  17. import java.awt.Component;
  18. import java.awt.Dimension;
  19. import java.awt.Graphics;
  20. import java.awt.Insets;
  21. import java.awt.Point;
  22. import java.awt.event.MouseEvent;
  23. import java.awt.event.MouseListener;
  24. import java.awt.event.MouseMotionListener;
  25. import java.io.Serializable;
  26.  
  27. public class BasicRadioButtonMenuItemUI extends RadioButtonMenuItemUI implements Serializable {
  28.    protected static Color pressedBackground = null;
  29.    protected static Color pressedForeground = null;
  30.    protected Icon menuArrow;
  31.    protected Icon checkIcon;
  32.    protected static final int defaultTextIconGap = 4;
  33.    protected MouseListener mouseListener;
  34.    protected MouseMotionListener mouseMotionListener;
  35.    protected boolean oldBorderPainted;
  36.  
  37.    public static ComponentUI createUI(JComponent var0) {
  38.       return new BasicRadioButtonMenuItemUI();
  39.    }
  40.  
  41.    public void installUI(JComponent var1) {
  42.       JRadioButtonMenuItem var2 = (JRadioButtonMenuItem)var1;
  43.       this.initListeners(var1);
  44.       this.addListeners(var1);
  45.       var1.setOpaque(true);
  46.       LookAndFeel.installBorder(var1, "MenuItem.border");
  47.       this.oldBorderPainted = ((AbstractButton)var2).isBorderPainted();
  48.       ((AbstractButton)var2).setBorderPainted((Boolean)UIManager.get("MenuItem.borderPainted"));
  49.       LookAndFeel.installColorsAndFont(var1, "MenuItem.background", "MenuItem.foreground", "MenuItem.font");
  50.       if (pressedBackground == null || pressedBackground instanceof UIResource) {
  51.          pressedBackground = UIManager.getColor("MenuItem.pressedBackground");
  52.       }
  53.  
  54.       if (pressedForeground == null || pressedForeground instanceof UIResource) {
  55.          pressedForeground = UIManager.getColor("MenuItem.pressedForeground");
  56.       }
  57.  
  58.       if (this.menuArrow == null || this.menuArrow instanceof UIResource) {
  59.          this.menuArrow = UIManager.getIcon("MenuItem.arrowIcon");
  60.       }
  61.  
  62.       if (((AbstractButton)var2).getSelectedIcon() == null || ((AbstractButton)var2).getSelectedIcon() instanceof UIResource) {
  63.          ((AbstractButton)var2).setSelectedIcon(UIManager.getIcon("RadioButtonMenuItem.icon"));
  64.       }
  65.  
  66.    }
  67.  
  68.    public void uninstallUI(JComponent var1) {
  69.       JRadioButtonMenuItem var2 = (JRadioButtonMenuItem)var1;
  70.       this.removeListeners(var1);
  71.       LookAndFeel.uninstallBorder(var1);
  72.       ((JMenuItem)var1).setBorderPainted(this.oldBorderPainted);
  73.       if (this.menuArrow instanceof UIResource) {
  74.          this.menuArrow = null;
  75.       }
  76.  
  77.       if (this.checkIcon instanceof UIResource) {
  78.          this.checkIcon = null;
  79.       }
  80.  
  81.       if (((AbstractButton)var2).getSelectedIcon() instanceof UIResource) {
  82.          ((AbstractButton)var2).setSelectedIcon((Icon)null);
  83.       }
  84.  
  85.    }
  86.  
  87.    protected void initListeners(JComponent var1) {
  88.       this.mouseListener = this.createMouseListener(var1);
  89.       this.mouseMotionListener = this.createMouseMotionListener(var1);
  90.    }
  91.  
  92.    protected void addListeners(JComponent var1) {
  93.       ((Component)var1).addMouseListener(this.mouseListener);
  94.       ((Component)var1).addMouseMotionListener(this.mouseMotionListener);
  95.    }
  96.  
  97.    protected void removeListeners(JComponent var1) {
  98.       ((Component)var1).removeMouseListener(this.mouseListener);
  99.       ((Component)var1).removeMouseMotionListener(this.mouseMotionListener);
  100.    }
  101.  
  102.    protected MouseListener createMouseListener(JComponent var1) {
  103.       return new BasicMenuMouseListener();
  104.    }
  105.  
  106.    protected MouseMotionListener createMouseMotionListener(JComponent var1) {
  107.       return new BasicMenuMouseMotionListener();
  108.    }
  109.  
  110.    public Insets getDefaultMargin(AbstractButton var1) {
  111.       return new Insets(2, 2, 2, 2);
  112.    }
  113.  
  114.    public Dimension getMinimumSize(JComponent var1) {
  115.       return this.getPreferredSize(var1);
  116.    }
  117.  
  118.    public Dimension getPreferredSize(JComponent var1) {
  119.       return BasicGraphicsUtils.getPreferredMenuItemSize(var1, this.checkIcon, this.menuArrow, 4);
  120.    }
  121.  
  122.    public Dimension getMaximumSize(JComponent var1) {
  123.       return this.getPreferredSize(var1);
  124.    }
  125.  
  126.    public void update(Graphics var1, JComponent var2) {
  127.       this.paint(var1, var2);
  128.    }
  129.  
  130.    public void paint(Graphics var1, JComponent var2) {
  131.       BasicGraphicsUtils.paintMenuItem(var1, var2, ((JRadioButtonMenuItem)var2).getSelectedIcon(), this.menuArrow, pressedBackground, pressedForeground, 4);
  132.    }
  133.  
  134.    public void processMouseEvent(JMenuItem var1, MouseEvent var2, MenuElement[] var3, MenuSelectionManager var4) {
  135.       Point var5 = var2.getPoint();
  136.       if (var5.x >= 0 && var5.x < ((JComponent)var1).getWidth() && var5.y >= 0 && var5.y < ((JComponent)var1).getHeight()) {
  137.          if (((AWTEvent)var2).getID() == 502) {
  138.             var4.clearSelectedPath();
  139.             ((AbstractButton)var1).doClick(0);
  140.             var1.setArmed(false);
  141.          } else {
  142.             var4.setSelectedPath(var3);
  143.          }
  144.       } else {
  145.          if (((AbstractButton)var1).getModel().isArmed()) {
  146.             MenuElement[] var6 = new MenuElement[var3.length - 1];
  147.             int var7 = 0;
  148.  
  149.             for(int var8 = var3.length - 1; var7 < var8; ++var7) {
  150.                var6[var7] = var3[var7];
  151.             }
  152.  
  153.             var4.setSelectedPath(var6);
  154.          }
  155.  
  156.       }
  157.    }
  158. }
  159.