jdk/src/solaris/classes/sun/awt/X11/XButtonPeer.java
changeset 10096 f9ac9a52952d
parent 5506 202f599c92aa
child 21270 8a0fc12b81a2
equal deleted inserted replaced
10095:daec42746ec0 10096:f9ac9a52952d
    31 import java.awt.event.KeyEvent;
    31 import java.awt.event.KeyEvent;
    32 import java.awt.event.ActionEvent;
    32 import java.awt.event.ActionEvent;
    33 import javax.swing.plaf.basic.*;
    33 import javax.swing.plaf.basic.*;
    34 import javax.swing.SwingUtilities;
    34 import javax.swing.SwingUtilities;
    35 import javax.swing.SwingConstants;
    35 import javax.swing.SwingConstants;
    36 
       
    37 public class XButtonPeer extends XComponentPeer implements ButtonPeer {
    36 public class XButtonPeer extends XComponentPeer implements ButtonPeer {
    38 
    37     private boolean pressed;
    39     boolean pressed;
    38     private boolean armed;
    40     boolean armed;
       
    41 
       
    42     private Insets focusInsets;
    39     private Insets focusInsets;
    43     private Insets borderInsets;
    40     private Insets borderInsets;
    44     private Insets contentAreaInsets;
    41     private Insets contentAreaInsets;
    45 
    42 
    46     private final static String propertyPrefix = "Button" + ".";
    43     private final static String propertyPrefix = "Button" + ".";
    84 
    81 
    85     public void  setLabel(java.lang.String label) {
    82     public void  setLabel(java.lang.String label) {
    86         this.label = label;
    83         this.label = label;
    87         repaint();
    84         repaint();
    88     }
    85     }
    89 
       
    90     public void paint(Graphics g) {
       
    91         paint(g,target);
       
    92     }
       
    93 
       
    94     public void setBackground(Color c) {
    86     public void setBackground(Color c) {
    95         updateMotifColors(c);
    87         updateMotifColors(c);
    96         super.setBackground(c);
    88         super.setBackground(c);
    97     }
    89     }
    98 
    90 
   131               break;
   123               break;
   132 
   124 
   133           case  MouseEvent.MOUSE_ENTERED:
   125           case  MouseEvent.MOUSE_ENTERED:
   134               if (pressed)
   126               if (pressed)
   135                   armed = true;
   127                   armed = true;
   136 //                 repaint();
   128               break;
   137 
       
   138               break;
       
   139 
       
   140           case MouseEvent.MOUSE_EXITED:
   129           case MouseEvent.MOUSE_EXITED:
   141               armed = false;
   130               armed = false;
   142 //                 repaint();
   131               break;
   143 
       
   144               break;
       
   145 
       
   146         }
   132         }
   147     }
   133     }
   148 
   134 
   149 
   135 
   150     // NOTE: This method is called by privileged threads.
   136     // NOTE: This method is called by privileged threads.
   207      * DEPRECATED
   193      * DEPRECATED
   208      */
   194      */
   209     public Dimension minimumSize() {
   195     public Dimension minimumSize() {
   210         return getMinimumSize();
   196         return getMinimumSize();
   211     }
   197     }
   212 
   198     /**
   213 
   199      * This method is called from Toolkit Thread and so it should not call any
   214     /*
   200      * client code.
   215        This method is called from Toolkit Thread and so it should not call any client code
   201      */
   216 
   202     @Override
   217     */
   203     void paintPeer(final Graphics g) {
   218     public void paint(Graphics g, Component c)
   204         if (!disposed) {
   219     {
       
   220         if (!disposed && (g != null))
       
   221         {
       
   222             Dimension size = getPeerSize();
   205             Dimension size = getPeerSize();
   223 
       
   224             g.setColor( getPeerBackground() );   /* erase the existing button remains */
   206             g.setColor( getPeerBackground() );   /* erase the existing button remains */
   225             g.fillRect(0,0, size.width , size.height);
   207             g.fillRect(0,0, size.width , size.height);
   226             paintBorder(g,borderInsets.left,
   208             paintBorder(g,borderInsets.left,
   227                         borderInsets.top,
   209                         borderInsets.top,
   228                         size.width-(borderInsets.left+borderInsets.right),
   210                         size.width-(borderInsets.left+borderInsets.right),
   237             iconRect = new Rectangle();
   219             iconRect = new Rectangle();
   238 
   220 
   239 
   221 
   240             viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right);
   222             viewRect.width = size.width - (contentAreaInsets.left+contentAreaInsets.right);
   241             viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom);
   223             viewRect.height = size.height - (contentAreaInsets.top+contentAreaInsets.bottom);
   242 
       
   243             viewRect.x = contentAreaInsets.left;
   224             viewRect.x = contentAreaInsets.left;
   244             viewRect.y = contentAreaInsets.right;
   225             viewRect.y = contentAreaInsets.top;
   245             String llabel = (label != null) ? label : "";
   226             String llabel = (label != null) ? label : "";
   246 
       
   247             // layout the text and icon
   227             // layout the text and icon
   248             String text = SwingUtilities.layoutCompoundLabel(
   228             String text = SwingUtilities.layoutCompoundLabel(
   249                                                              fm, llabel, null,
   229                                                              fm, llabel, null,
   250                                                              SwingConstants.CENTER, SwingConstants.CENTER,
   230                                                              SwingConstants.CENTER, SwingConstants.CENTER,
   251                                                              SwingConstants.CENTER, SwingConstants.CENTER,
   231                                                              SwingConstants.CENTER, SwingConstants.CENTER,
   307             BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
   287             BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
   308         }
   288         }
   309         else {
   289         else {
   310             /*** paint the text disabled ***/
   290             /*** paint the text disabled ***/
   311             g.setColor(getPeerBackground().brighter());
   291             g.setColor(getPeerBackground().brighter());
   312 
       
   313             BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
   292             BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
   314                                                          textRect.x, textRect.y + fm.getAscent());
   293                                                          textRect.x, textRect.y + fm.getAscent());
   315             g.setColor(c.getBackground().darker());
   294             g.setColor(getPeerBackground().darker());
   316             BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
   295             BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,
   317                                                          textRect.x - 1, textRect.y + fm.getAscent() - 1);
   296                                                          textRect.x - 1, textRect.y + fm.getAscent() - 1);
   318         }
   297         }
   319     }
   298     }
   320 }
   299 }