/[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.11 by mark, Sat Jun 26 16:07:02 2004 UTC revision 1.12 by mark, Thu Jul 22 19:45:39 2004 UTC
# Line 61  public class BasicButtonUI extends Butto Line 61  public class BasicButtonUI extends Butto
61  {  {
62    /** A constant used to pad out elements in the button's layout and    /** A constant used to pad out elements in the button's layout and
63        preferred size calculations. */        preferred size calculations. */
64    int defaultTextIconGap = 3;    int defaultTextIconGap = 4;
65    
66    /** A constant added to the defaultTextIconGap to adjust the text    /** A constant added to the defaultTextIconGap to adjust the text
67        within this particular button. */        within this particular button. */
# Line 92  public class BasicButtonUI extends Butto Line 92  public class BasicButtonUI extends Butto
92      b.setBackground(defaults.getColor("Button.background"));      b.setBackground(defaults.getColor("Button.background"));
93      b.setMargin(defaults.getInsets("Button.margin"));      b.setMargin(defaults.getInsets("Button.margin"));
94      b.setBorder(defaults.getBorder("Button.border"));      b.setBorder(defaults.getBorder("Button.border"));
95        b.setIconTextGap(defaults.getInt("Button.textIconGap"));
96      b.setOpaque(true);      b.setOpaque(true);
97    }    }
98    
# Line 100  public class BasicButtonUI extends Butto Line 101  public class BasicButtonUI extends Butto
101      b.setForeground(null);      b.setForeground(null);
102      b.setBackground(null);      b.setBackground(null);
103      b.setBorder(null);      b.setBorder(null);
104        b.setIconTextGap(defaultTextIconGap);
105      b.setMargin(null);      b.setMargin(null);
106    }    }
107    
# Line 234  public class BasicButtonUI extends Butto Line 236  public class BasicButtonUI extends Butto
236                                                       b.getVerticalTextPosition(),                                                       b.getVerticalTextPosition(),
237                                                       b.getHorizontalTextPosition(),                                                       b.getHorizontalTextPosition(),
238                                                       vr, ir, tr,                                                       vr, ir, tr,
239                                                       defaultTextIconGap                                                       b.getIconTextGap()
240                                                       + defaultTextShiftOffset);                                                       + defaultTextShiftOffset);
241            
242      if ((b.getModel().isArmed() && b.getModel().isPressed())      if ((b.getModel().isArmed() && b.getModel().isPressed())
243          || b.isSelected())          || b.isSelected())
244        paintButtonPressed(g, br, c);        paintButtonPressed(g, b);
245      else      else
246        paintButtonNormal(g, br, c);        paintButtonNormal(g, br, c);
247                    
248      paintIcon(g, c, ir);      paintIcon(g, c, ir);
249      if (text != null)      if (text != null)
250        paintText(g, c, tr, b.getText());        paintText(g, b, tr, text);
251      paintFocus(g, c, vr, tr, ir);      paintFocus(g, b, vr, tr, ir);
252    }    }
253    
254    /**    /**
# Line 256  public class BasicButtonUI extends Butto Line 258  public class BasicButtonUI extends Butto
258     * "focusPainted" property is <code>true</code>.     * "focusPainted" property is <code>true</code>.
259     *     *
260     * @param g Graphics context to paint with     * @param g Graphics context to paint with
261     * @param c Component to paint the focus of     * @param b Button to paint the focus of
262     * @param vr Visible rectangle, the area in which to paint     * @param vr Visible rectangle, the area in which to paint
263     * @param tr Text rectangle, contained in visible rectangle     * @param tr Text rectangle, contained in visible rectangle
264     * @param ir Icon rectangle, contained in visible rectangle     * @param ir Icon rectangle, contained in visible rectangle
# Line 264  public class BasicButtonUI extends Butto Line 266  public class BasicButtonUI extends Butto
266     * @see AbstractButton.isFocusPainted()     * @see AbstractButton.isFocusPainted()
267     * @see JComponent.hasFocus()     * @see JComponent.hasFocus()
268     */     */
269    protected void paintFocus(Graphics g, JComponent c, Rectangle vr,    protected void paintFocus(Graphics g, AbstractButton b, Rectangle vr,
270                              Rectangle tr, Rectangle ir)                              Rectangle tr, Rectangle ir)
271    {    {
     AbstractButton b = (AbstractButton) c;  
272      if (b.hasFocus() && b.isFocusPainted())      if (b.hasFocus() && b.isFocusPainted())
273        {        {
274          Graphics2D g2 = (Graphics2D) g;          Graphics2D g2 = (Graphics2D) g;
# Line 313  public class BasicButtonUI extends Butto Line 314  public class BasicButtonUI extends Butto
314     * pressedBackgroundColor}.     * pressedBackgroundColor}.
315     *     *
316     * @param g The graphics context to paint with     * @param g The graphics context to paint with
317     * @param area The area in which to paint     * @param b The button to paint the state of
    * @param b The component to paint the state of  
318     */     */
319    protected void paintButtonPressed(Graphics g, Rectangle area, JComponent b)    protected void paintButtonPressed(Graphics g, AbstractButton b)
320    {    {
321      if (((AbstractButton)b).isContentAreaFilled())      if (b.isContentAreaFilled())
322        {        {
323            Rectangle area = new Rectangle();
324            SwingUtilities.calculateInnerArea(b, area);
325          g.setColor(b.getBackground().darker());          g.setColor(b.getBackground().darker());
326          g.fillRect(area.x, area.y, area.width, area.height);          g.fillRect(area.x, area.y, area.width, area.height);
327        }        }
# Line 334  public class BasicButtonUI extends Butto Line 336  public class BasicButtonUI extends Butto
336     * @param area The area in which to paint     * @param area The area in which to paint
337     * @param b The component to paint the state of     * @param b The component to paint the state of
338     */     */
339    protected void paintButtonNormal(Graphics g, Rectangle area, JComponent b)    private void paintButtonNormal(Graphics g, Rectangle area, JComponent b)
340    {    {
341      if (((AbstractButton)b).isContentAreaFilled() && b.isOpaque())      if (((AbstractButton)b).isContentAreaFilled() && b.isOpaque())
342        {        {
# Line 355  public class BasicButtonUI extends Butto Line 357  public class BasicButtonUI extends Butto
357    protected void paintText(Graphics g, JComponent c, Rectangle textRect,    protected void paintText(Graphics g, JComponent c, Rectangle textRect,
358                             String text)                             String text)
359    {        {    
360      Font f = c.getFont();      paintText(g, (AbstractButton) c, textRect, text);
361      }
362    
363      /**
364       * Paints the "text" property of an {@link AbstractButton}, using the
365       * {@link textColor} color.
366       *
367       * @param g The graphics context to paint with
368       * @param b The button to paint the state of
369       * @param textRect The area in which to paint the text
370       * @param text The text to paint
371       *
372       * @since 1.4
373       */
374      protected void paintText(Graphics g, AbstractButton b, Rectangle textRect,
375                               String text)
376      {
377        Font f = b.getFont();
378      g.setFont(f);      g.setFont(f);
379      FontMetrics fm = g.getFontMetrics(f);      FontMetrics fm = g.getFontMetrics(f);
380    
381      if (c.isEnabled())      if (b.isEnabled())
382        {        {
383          g.setColor(c.getForeground());          g.setColor(b.getForeground());
384          g.drawString(text, textRect.x, textRect.y + fm.getAscent());          g.drawString(text, textRect.x, textRect.y + fm.getAscent());
385        }        }
386      else      else
387        {        {
388          g.setColor(c.getBackground().brighter());          g.setColor(b.getBackground().brighter());
389          g.drawString(text, textRect.x, textRect.y + fm.getAscent());          g.drawString(text, textRect.x, textRect.y + fm.getAscent());
390          g.setColor(c.getBackground().darker());          g.setColor(b.getBackground().darker());
391          g.drawString(text, textRect.x + 1, textRect.y + fm.getAscent() + 1);          g.drawString(text, textRect.x + 1, textRect.y + fm.getAscent() + 1);
392        }        }
393    }    }

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

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