/[classpath]/classpath/javax/swing/plaf/basic/BasicButtonUI.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/basic/BasicButtonUI.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by mark, Thu Jul 22 19:45:39 2004 UTC revision 1.13 by mark, Sat Sep 4 17:14:01 2004 UTC
# Line 50  import java.awt.Stroke; Line 50  import java.awt.Stroke;
50  import javax.swing.AbstractButton;  import javax.swing.AbstractButton;
51  import javax.swing.ButtonModel;  import javax.swing.ButtonModel;
52  import javax.swing.Icon;  import javax.swing.Icon;
53    import javax.swing.InputMap;
54  import javax.swing.JComponent;  import javax.swing.JComponent;
55  import javax.swing.SwingUtilities;  import javax.swing.SwingUtilities;
56  import javax.swing.UIDefaults;  import javax.swing.UIDefaults;
# Line 59  import javax.swing.plaf.ComponentUI; Line 60  import javax.swing.plaf.ComponentUI;
60    
61  public class BasicButtonUI extends ButtonUI  public class BasicButtonUI extends ButtonUI
62  {  {
63    /** A constant used to pad out elements in the button's layout and    /**
64        preferred size calculations. */     * A constant used to pad out elements in the button's layout and
65    int defaultTextIconGap = 4;     * preferred size calculations.
66       */
67    /** A constant added to the defaultTextIconGap to adjust the text    protected int defaultTextIconGap = 4;
68        within this particular button. */  
69    int defaultTextShiftOffset = 0;    /**
70       * A constant added to the defaultTextIconGap to adjust the text
71       * within this particular button.
72       */
73      protected int defaultTextShiftOffset = 0;
74    
75      private int textShiftOffset;
76    
77      private Color focusColor;
78    
79    /**    /**
80     * Factory method to create an instance of BasicButtonUI for a given     * Factory method to create an instance of BasicButtonUI for a given
# Line 85  public class BasicButtonUI extends Butto Line 94  public class BasicButtonUI extends Butto
94      return defaultTextIconGap;      return defaultTextIconGap;
95    }    }
96    
97      protected void clearTextShiftOffset()
98      {
99        textShiftOffset = 0;
100      }
101      
102      protected int getTextShiftOffset()
103      {
104        return textShiftOffset;
105      }
106    
107      protected void setTextShiftOffset()
108      {
109        textShiftOffset = defaultTextShiftOffset;
110      }
111    
112    protected void installDefaults(AbstractButton b)    protected void installDefaults(AbstractButton b)
113    {    {
114      UIDefaults defaults = UIManager.getLookAndFeelDefaults();      UIDefaults defaults = UIManager.getLookAndFeelDefaults();
115        focusColor = defaults.getColor("Button.focus");
116      b.setForeground(defaults.getColor("Button.foreground"));      b.setForeground(defaults.getColor("Button.foreground"));
117      b.setBackground(defaults.getColor("Button.background"));      b.setBackground(defaults.getColor("Button.background"));
118      b.setMargin(defaults.getInsets("Button.margin"));      b.setMargin(defaults.getInsets("Button.margin"));
119      b.setBorder(defaults.getBorder("Button.border"));      b.setBorder(defaults.getBorder("Button.border"));
120      b.setIconTextGap(defaults.getInt("Button.textIconGap"));      b.setIconTextGap(defaults.getInt("Button.textIconGap"));
121        b.setInputMap(JComponent.WHEN_FOCUSED,
122                      (InputMap) defaults.get("Button.focusInputMap"));
123      b.setOpaque(true);      b.setOpaque(true);
124    }    }
125    
# Line 133  public class BasicButtonUI extends Butto Line 160  public class BasicButtonUI extends Butto
160    
161    protected void installKeyboardActions(AbstractButton b)    protected void installKeyboardActions(AbstractButton b)
162    {    {
163        listener.installKeyboardActions(b);
164    }    }
165    
166    protected void uninstallKeyboardActions(AbstractButton b)    protected void uninstallKeyboardActions(AbstractButton b)
167    {    {
168        listener.uninstallKeyboardActions(b);
169    }    }
170    
171    /**    /**
# Line 271  public class BasicButtonUI extends Butto Line 300  public class BasicButtonUI extends Butto
300    {    {
301      if (b.hasFocus() && b.isFocusPainted())      if (b.hasFocus() && b.isFocusPainted())
302        {        {
303          Graphics2D g2 = (Graphics2D) g;          Color saved_color = g.getColor();
304          Stroke saved_stroke = g2.getStroke();          g.setColor(focusColor);
305          Color saved_color = g2.getColor();          Rectangle focusRect = ir.union(tr);
306          float dashes[] = new float[] {1.0f, 1.0f};                  g.drawRect(focusRect.x, focusRect.y,
307          BasicStroke s = new BasicStroke(1.0f,                     focusRect.width, focusRect.height);
308                                          BasicStroke.CAP_SQUARE,          g.setColor(saved_color);
                                         BasicStroke.JOIN_MITER,  
                                         10, dashes, 0.0f);  
         g2.setStroke(s);  
         g2.setColor(Color.BLACK);  
         g2.drawRect(vr.x + 2,  
                     vr.y + 2,  
                     vr.width - 4,  
                     vr.height - 4);  
         g2.setStroke(saved_stroke);  
         g2.setColor(saved_color);  
309        }        }
310    }    }
311    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26