< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2018, 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


 170             size.height - (insets.top + insets.bottom));
 171         View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 172         if (v != null) {
 173             v.paint(g, paintTextR);
 174         } else {
 175             g.setFont(font);
 176             SwingUtilities2.drawString(c, g, tipText, paintTextR.x,
 177                                   paintTextR.y + metrics.getAscent());
 178         }
 179     }
 180 
 181     public Dimension getPreferredSize(JComponent c) {
 182         Font font = c.getFont();
 183         FontMetrics fm = c.getFontMetrics(font);
 184         Insets insets = c.getInsets();
 185 
 186         Dimension prefSize = new Dimension(insets.left+insets.right,
 187                                            insets.top+insets.bottom);
 188         String text = ((JToolTip)c).getTipText();
 189 
 190         if ((text == null) || text.equals("")) {
 191             text = "";
 192         }
 193         else {
 194             View v = (c != null) ? (View) c.getClientProperty("html") : null;
 195             if (v != null) {
 196                 prefSize.width += (int) v.getPreferredSpan(View.X_AXIS) + 6;
 197                 prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS);
 198             } else {
 199                 prefSize.width += SwingUtilities2.stringWidth(c,fm,text) + 6;
 200                 prefSize.height += fm.getHeight();
 201             }
 202         }
 203         return prefSize;
 204     }
 205 
 206     public Dimension getMinimumSize(JComponent c) {
 207         Dimension d = getPreferredSize(c);
 208         View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 209         if (v != null) {
 210             d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);


   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


 170             size.height - (insets.top + insets.bottom));
 171         View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 172         if (v != null) {
 173             v.paint(g, paintTextR);
 174         } else {
 175             g.setFont(font);
 176             SwingUtilities2.drawString(c, g, tipText, paintTextR.x,
 177                                   paintTextR.y + metrics.getAscent());
 178         }
 179     }
 180 
 181     public Dimension getPreferredSize(JComponent c) {
 182         Font font = c.getFont();
 183         FontMetrics fm = c.getFontMetrics(font);
 184         Insets insets = c.getInsets();
 185 
 186         Dimension prefSize = new Dimension(insets.left+insets.right,
 187                                            insets.top+insets.bottom);
 188         String text = ((JToolTip)c).getTipText();
 189 
 190         if (text == null) {
 191             text = "";
 192         }
 193         else {
 194             View v = (c != null) ? (View) c.getClientProperty("html") : null;
 195             if (v != null) {
 196                 prefSize.width += (int) v.getPreferredSpan(View.X_AXIS) + 6;
 197                 prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS);
 198             } else {
 199                 prefSize.width += SwingUtilities2.stringWidth(c,fm,text) + 6;
 200                 prefSize.height += fm.getHeight();
 201             }
 202         }
 203         return prefSize;
 204     }
 205 
 206     public Dimension getMinimumSize(JComponent c) {
 207         Dimension d = getPreferredSize(c);
 208         View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 209         if (v != null) {
 210             d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);


< prev index next >