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 26 package javax.swing.plaf; 27 28 import java.awt.FontMetrics; 29 import java.awt.Graphics; 30 import javax.swing.JComponent; 31 32 /** 33 * This interface is designed to be used by various component ui classes 34 * for drawing and measuring text. 35 * {@literal L&F} sets the instance of the {@code TextUIDrawing} to the 36 * look and feel defaults using {@literal "uiDrawing.text"} property. 37 * To get an instance of {@code TextUIDrawing} for the current {@literal L&F} 38 * use {@code UIManager.get("uiDrawing.text")}. 39 * To set a custom {@code TextUIDrawing} use 40 * {@code UIManager.put("uiDrawing.text", new CustomTextUIDrawing())}. 41 * 42 * @since 9 43 */ 44 public interface TextUIDrawing { 45 /** 46 * Draws the given string at the specified location. 47 * Nothing is drawn for the null string. 48 * 49 * @param c the component that will display the string, may be null 50 * @param g the graphics context, must not be null 51 * @param string the string to display, may be null 52 * @param x the x coordinate to draw the text at 53 * @param y the y coordinate to draw the text at 54 * @throws NullPointerException if the specified {@code g} is {@code null} 55 * 56 * @since 9 57 */ 58 void drawString(JComponent c, Graphics g, String string, int x, int y); 59 60 /** 61 * Draws the given string at the specified location underlining 62 * the specified character. 63 * <p> 64 * The underline will be positioned at the base glyph which represents 65 * the valid char indicated by the index. If the char index is not valid 66 * or is not the index of a valid unicode code point then no underline 67 * is drawn. 68 * 69 * @param c the component that will display the string, may be null 70 * @param g the graphics context, must not be null 71 * @param string the string to display, may be null 72 * @param underlinedIndex index of a a char value (Unicode code unit) 73 * in the string to underline 74 * @param x the x coordinate to draw the text at 75 * @param y the y coordinate to draw the text at 76 * @throws NullPointerException if the specified {@code g} is {@code null} 77 * 78 * @see #getStringWidth 79 * 80 * @since 9 81 */ 82 void drawStringUnderlineCharAt(JComponent c, Graphics g, 83 String string, int underlinedIndex, 84 int x, int y); 85 86 /** 87 * Clips the passed in string to the space provided. 88 * 89 * @param c the component 90 * @param fm the FontMetrics used to measure the string width, must be 91 * obtained from the correct font and graphics. Must not be null. 92 * @param string the string to clip, may be null 93 * @param availTextWidth the amount of space that the string can be drawn in 94 * @return the clipped string that fits in the provided space, an empty 95 * string if the given string argument is {@code null} or empty 96 * @throws NullPointerException if the specified {@code fm} is {@code null} 97 * 98 * @see #getStringWidth 99 * 100 * @since 9 101 */ 102 String getClippedString(JComponent c, FontMetrics fm, String string, 103 int availTextWidth); 104 /** 105 * Returns the total advance width of the passed in string. 106 * The advance is the distance from the leftmost point to the rightmost point 107 * on the string's baseline. 108 * If the passed string is {@code null}, returns zero. 109 * 110 * @param c the component, may be null 111 * @param fm the FontMetrics used to measure the advance string width, must 112 * be obtained from the correct font and graphics. Must not be null. 113 * @param string the string to get the advance width of, may be null 114 * @return the advance width of the specified string, zero is returned for 115 * {@code null} string 116 * @throws NullPointerException if the specified {@code fm} is {@code null} 117 * 118 * @since 9 119 */ 120 int getStringWidth(JComponent c, FontMetrics fm, String string); 121 }