--- /dev/null 2016-04-06 23:43:03.000000000 +0400 +++ new/src/java.desktop/share/classes/javax/swing/plaf/TextUIDrawing.java 2016-04-06 23:43:02.000000000 +0400 @@ -0,0 +1,121 @@ +/* + * 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())}. + * + * @since 9 + */ +public interface TextUIDrawing { + /** + * Draws the given string at the specified location. + * 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 underline will be positioned at the base glyph which represents + * the valid char indicated by the index. If the char index is not valid + * or is not the index of a valid unicode code point then no underline + * is drawn. + * + * @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. + * + * @param c the component + * @param fm the FontMetrics used to measure the string width, must be + * obtained from the correct font and graphics. 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. + * 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 + * be obtained from the correct font and graphics. 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); +}