1 7 8 package com.sun.java.swing.plaf.motif; 9 10 import javax.swing.*; 11 import javax.swing.border.*; 12 import javax.swing.plaf.basic.*; 13 import java.awt.*; 14 import java.awt.event.*; 15 import javax.swing.plaf.*; 16 17 30 public class MotifButtonUI extends BasicButtonUI { 31 32 private final static MotifButtonUI motifButtonUI = new MotifButtonUI(); 33 34 protected Color selectColor; 35 36 private boolean defaults_initialized = false; 37 38 public static ComponentUI createUI(JComponent c){ 42 return motifButtonUI; 43 } 44 45 protected BasicButtonListener createButtonListener(AbstractButton b){ 49 return new MotifButtonListener(b); 50 } 51 52 public void installDefaults(AbstractButton b) { 56 super.installDefaults(b); 57 if(!defaults_initialized) { 58 selectColor = UIManager.getColor(getPropertyPrefix() + "select"); 59 defaults_initialized = true; 60 } 61 LookAndFeel.installProperty(b, "opaque", Boolean.FALSE); 62 } 63 64 protected void uninstallDefaults(AbstractButton b) { 65 super.uninstallDefaults(b); 66 defaults_initialized = false; 67 } 68 69 73 protected Color getSelectColor() { 74 return selectColor; 75 } 76 77 public void paint(Graphics g, JComponent c) { 81 fillContentArea( g, (AbstractButton)c , c.getBackground() ); 82 super.paint(g,c); 83 } 84 85 protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { 87 Shape oldClip = g.getClip(); 88 Rectangle newClip = 89 AbstractBorder.getInteriorRectangle(c, c.getBorder(), 0, 0, 90 c.getWidth(), c.getHeight()); 91 92 Rectangle r = oldClip.getBounds(); 93 newClip = 94 SwingUtilities.computeIntersection(r.x, r.y, r.width, r.height, 95 newClip); 96 g.setClip(newClip); 97 super.paintIcon(g, c, iconRect); 98 g.setClip(oldClip); 99 } 100 101 protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){ 102 } 104 105 protected void paintButtonPressed(Graphics g, AbstractButton b) { 106 107 fillContentArea( g, b , selectColor ); 108 109 } 110 111 protected void fillContentArea( Graphics g, AbstractButton b, Color fillColor) { 112 113 if (b.isContentAreaFilled()) { 114 Insets margin = b.getMargin(); 115 Insets insets = b.getInsets(); 116 Dimension size = b.getSize(); 117 g.setColor(fillColor); 118 g.fillRect(insets.left - margin.left, 119 insets.top - margin.top, 120 size.width - (insets.left-margin.left) - (insets.right - margin.right), 121 size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom)); 122 } 123 } 124 } 125 126 127 | Popular Tags |