1 7 8 package com.sun.java.swing.plaf.motif; 9 10 import java.awt.*; 11 import java.awt.event.*; 12 13 import javax.swing.*; 14 import javax.swing.border.*; 15 import javax.swing.plaf.*; 16 import javax.swing.plaf.basic.*; 17 18 19 32 public class MotifToggleButtonUI extends BasicToggleButtonUI 33 { 34 private final static MotifToggleButtonUI motifToggleButtonUI = new MotifToggleButtonUI(); 35 36 protected Color selectColor; 37 38 private boolean defaults_initialized = false; 39 40 public static ComponentUI createUI(JComponent b) { 44 return motifToggleButtonUI; 45 } 46 47 public void installDefaults(AbstractButton b) { 51 super.installDefaults(b); 52 if(!defaults_initialized) { 53 selectColor = UIManager.getColor(getPropertyPrefix() + "select"); 54 defaults_initialized = true; 55 } 56 LookAndFeel.installProperty(b, "opaque", Boolean.FALSE); 57 } 58 59 protected void uninstallDefaults(AbstractButton b) { 60 super.uninstallDefaults(b); 61 defaults_initialized = false; 62 } 63 64 68 protected Color getSelectColor() { 69 return selectColor; 70 } 71 72 protected void paintButtonPressed(Graphics g, AbstractButton b) { 76 if (b.isContentAreaFilled()) { 77 Color oldColor = g.getColor(); 78 Dimension size = b.getSize(); 79 Insets insets = b.getInsets(); 80 Insets margin = b.getMargin(); 81 82 if(b.getBackground() instanceof UIResource) { 83 g.setColor(getSelectColor()); 84 } 85 g.fillRect(insets.left - margin.left, 86 insets.top - margin.top, 87 size.width - (insets.left-margin.left) - (insets.right - margin.right), 88 size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom)); 89 g.setColor(oldColor); 90 } 91 } 92 93 public Insets getInsets(JComponent c) { 94 Border border = c.getBorder(); 95 Insets i = border != null? border.getBorderInsets(c) : new Insets(0,0,0,0); 96 return i; 97 } 98 99 } 100 101 102 | Popular Tags |