< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToggleButtonUI.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 102         // layout the text and icon
 103         String text = SwingUtilities.layoutCompoundLabel(
 104             c, fm, b.getText(), b.getIcon(),
 105             b.getVerticalAlignment(), b.getHorizontalAlignment(),
 106             b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
 107             viewRect, iconRect, textRect,
 108             b.getText() == null ? 0 : b.getIconTextGap());
 109 
 110         g.setColor(b.getBackground());
 111 
 112         if (model.isArmed() && model.isPressed() || model.isSelected()) {
 113             paintButtonPressed(g,b);
 114         }
 115 
 116         // Paint the Icon
 117         if(b.getIcon() != null) {
 118             paintIcon(g, b, iconRect);
 119         }
 120 
 121         // Draw the Text
 122         if(text != null && !text.equals("")) {
 123             View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 124             if (v != null) {
 125                v.paint(g, textRect);
 126             } else {
 127                paintText(g, b, textRect, text);
 128             }
 129         }
 130 
 131         // draw the dashed focus line.
 132         if (b.isFocusPainted() && b.hasFocus()) {
 133             paintFocus(g, b, viewRect, textRect, iconRect);
 134         }
 135     }
 136 
 137     /**
 138      * Paints an icon in the specified location.
 139      *
 140      * @param g an instance of {@code Graphics}
 141      * @param b an instance of {@code Button}
 142      * @param iconRect bounds of an icon


   1 /*
   2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 102         // layout the text and icon
 103         String text = SwingUtilities.layoutCompoundLabel(
 104             c, fm, b.getText(), b.getIcon(),
 105             b.getVerticalAlignment(), b.getHorizontalAlignment(),
 106             b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
 107             viewRect, iconRect, textRect,
 108             b.getText() == null ? 0 : b.getIconTextGap());
 109 
 110         g.setColor(b.getBackground());
 111 
 112         if (model.isArmed() && model.isPressed() || model.isSelected()) {
 113             paintButtonPressed(g,b);
 114         }
 115 
 116         // Paint the Icon
 117         if(b.getIcon() != null) {
 118             paintIcon(g, b, iconRect);
 119         }
 120 
 121         // Draw the Text
 122         if(text != null && !text.isEmpty()) {
 123             View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 124             if (v != null) {
 125                v.paint(g, textRect);
 126             } else {
 127                paintText(g, b, textRect, text);
 128             }
 129         }
 130 
 131         // draw the dashed focus line.
 132         if (b.isFocusPainted() && b.hasFocus()) {
 133             paintFocus(g, b, viewRect, textRect, iconRect);
 134         }
 135     }
 136 
 137     /**
 138      * Paints an icon in the specified location.
 139      *
 140      * @param g an instance of {@code Graphics}
 141      * @param b an instance of {@code Button}
 142      * @param iconRect bounds of an icon


< prev index next >