--- /dev/null 2016-01-25 00:13:43.000000000 +0400 +++ new/src/java.desktop/share/classes/javax/swing/plaf/TextUIDrawing.java 2016-01-25 00:13:43.000000000 +0400 @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javax.swing.plaf; + +import java.awt.FontMetrics; +import java.awt.Graphics; +import javax.swing.JComponent; + +/** + * This interface is designed to be used by various component ui classes + * for drawing and measuring text. + * {@literal L&F} sets the instance of the {@code TextUIDrawing} to the + * look and feel defaults using {@literal "uiDrawing.text"} property. + * To get an instance of {@code TextUIDrawing} for the current {@literal L&F} + * use {@code UIManager.get("uiDrawing.text")}. + * To set a custom {@code TextUIDrawing} use + * {@code UIManager.put("uiDrawing.text", new CustomTextUIDrawing())}. + * + * @see javax.swing.plaf.ComponentUI#getTextUIDrawing + * + * @since 9 + */ +public interface TextUIDrawing { + /** + * Draws the given string at the specified location using text properties + * and anti-aliasing hints from the provided component. + * Nothing is drawn for the null string. + * + * @param c the component that will display the string, may be null + * @param g the graphics context, must not be null + * @param string the string to display, may be null + * @param x the x coordinate to draw the text at + * @param y the y coordinate to draw the text at + * @throws NullPointerException if the specified {@code g} is {@code null} + * + * @since 9 + */ + void drawString(JComponent c, Graphics g, String string, + int x, int y); + + /** + * Draws the given string at the specified location underlining + * the specified character. The provided component is used to query text + * properties and anti-aliasing hints. + *

+ * The {@code underlinedIndex} parameter points to a char value + * (Unicode code unit) in the given string. + * If the char value specified at the underlined index is in + * the high-surrogate range and the char value at the following index is in + * the low-surrogate range then the supplementary character corresponding + * to this surrogate pair is underlined. + *

+ * No character is underlined if the index is negative or greater + * than the string length {@code (index < 0 || index >= string.length())} + * or if the char value specified at the given index + * is in the low-surrogate range. + * + * @param c the component that will display the string, may be null + * @param g the graphics context, must not be null + * @param string the string to display, may be null + * @param underlinedIndex index of a a char value (Unicode code unit) + * in the string to underline + * @param x the x coordinate to draw the text at + * @param y the y coordinate to draw the text at + * @throws NullPointerException if the specified {@code g} is {@code null} + * + * @see #getStringWidth + * + * @since 9 + */ + void drawStringUnderlineCharAt(JComponent c, Graphics g, + String string, int underlinedIndex, int x, int y); + + /** + * Clips the passed in string to the space provided. + * The provided component is used to query text properties. + * The unchanged string is returned if the space provided is greater than + * the string width. + * + * @param c the component + * @param fm the FontMetrics used to measure the string width, must not be null + * @param string the string to clip, may be null + * @param availTextWidth the amount of space that the string can be drawn in + * @return the clipped string that fits in the provided space, an empty + * string if the given string argument is {@code null} or empty + * @throws NullPointerException if the specified {@code fm} is {@code null} + * + * @see #getStringWidth + * + * @since 9 + */ + String getClippedString(JComponent c, FontMetrics fm, + String string, int availTextWidth); + + /** + * Returns the total advance width of the passed in string using the given + * font metrics, and text properties from the given component. + * The advance is the distance from the leftmost point to the rightmost point + * on the string's baseline. + * If the passed string is {@code null}, returns zero. + * + * @param c the component, may be null + * @param fm the FontMetrics used to measure the advance string width, + * must not be null + * @param string the string to get the advance width of, may be null + * @return the advance width of the specified string, zero is returned for + * {@code null} string + * @throws NullPointerException if the specified {@code fm} is {@code null} + * + * @since 9 + */ + int getStringWidth(JComponent c, FontMetrics fm, String string); + +}