1 /* 2 * Copyright (c) 2016, 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 23 * questions. 24 */ 25 package javax.swing.plaf.basic; 26 27 import java.awt.FontMetrics; 28 import java.awt.Graphics; 29 import javax.swing.JComponent; 30 import javax.swing.plaf.TextUIDrawing; 31 import javax.swing.plaf.UIResource; 32 import sun.swing.SwingUtilities2; 33 34 /** 35 * TextUIDrawing implementation for BasicTextUIDrawing 36 * 37 * @since 9 38 */ 39 public class BasicTextUIDrawing implements TextUIDrawing, UIResource { 40 41 /** 42 * Draws the given string at the specified location using text properties 43 * and anti-aliasing hints from the provided component. 44 * Nothing is drawn for the null string. 45 * 46 * @since 9 47 */ 48 @Override 49 public void drawString(JComponent c, Graphics g, String string, 50 int x, int y) { 51 SwingUtilities2.drawString(c, g, string, x, y); 52 } 53 54 /** 55 * Draws the given string at the specified location underlining 56 * the specified character. The provided component is used to query text 57 * properties and anti-aliasing hints. 58 * <p> 59 * The underline will be positioned at the base glyph which represents 60 * the valid char indicated by the index. If the char index is not valid 61 * or is not the index of a valid unicode code point then no underline 62 * is drawn. 63 * 64 * @since 9 65 */ 66 @Override 67 public void drawStringUnderlineCharAt(JComponent c, Graphics g, 68 String string, int underlinedIndex, 69 int x, int y) { 70 SwingUtilities2.drawStringUnderlineCharAt(c, g, string, underlinedIndex, 71 x, y); 72 } 73 74 /** 75 * Clips the passed in string to the space provided. 76 * The provided component is used to query text properties and anti-aliasing hints. 77 * The unchanged string is returned if the space provided is greater than 78 * the string width. 79 * 80 * @since 9 81 */ 82 @Override 83 public String getClippedString(JComponent c, FontMetrics fm, String string, 84 int availTextWidth) { 85 return SwingUtilities2.clipStringIfNecessary(c, fm, string, availTextWidth); 86 } 87 88 /** 89 * Returns the total advance width of the passed in string using text 90 * properties and anti-aliasing hints from the provided component. 91 * The advance is the distance from the leftmost point to the rightmost point 92 * on the string's baseline. 93 * If the passed string is {@code null}, returns zero. 94 * 95 * @since 9 96 */ 97 @Override 98 public int getStringWidth(JComponent c, FontMetrics fm, String string) { 99 return SwingUtilities2.stringWidth(c, fm, string); 100 } 101 }