Java Code Examples for sun.swing.PrintColorUIResource

The following examples show how to use sun.swing.PrintColorUIResource. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * The following draw functions have the same semantic as the
 * Graphics methods with the same names.
 *
 * this is used for printing
 */
public static int drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    // If text fits the screenWidth, then do not need to justify
                    if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
                                            trimmedText) > screenWidth) {
                        layout = layout.getJustifiedLayout(screenWidth);
                    }

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D)g;

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g.drawChars(data, offset, length, x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g.drawChars(data, offset, length, x, y);
    }
    return nextX;
}
 
Example 2
public static float drawString(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               int x,
                               int y) {

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator,x,y); //for the cases where advance
                                    //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}
 
Example 3
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 4
/**
 * The following draw functions have the same semantic as the
 * Graphics methods with the same names.
 *
 * this is used for printing
 */
public static int drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    // If text fits the screenWidth, then do not need to justify
                    if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
                                            trimmedText) > screenWidth) {
                        layout = layout.getJustifiedLayout(screenWidth);
                    }

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D)g;

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g.drawChars(data, offset, length, x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g.drawChars(data, offset, length, x, y);
    }
    return nextX;
}
 
Example 5
public static float drawString(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               int x,
                               int y) {

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator,x,y); //for the cases where advance
                                    //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}
 
Example 6
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 7
Source Project: jdk8u60   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * The following draw functions have the same semantic as the
 * Graphics methods with the same names.
 *
 * this is used for printing
 */
public static int drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    layout = layout.getJustifiedLayout(screenWidth);

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D)g;

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g.drawChars(data, offset, length, x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g.drawChars(data, offset, length, x, y);
    }
    return nextX;
}
 
Example 8
Source Project: jdk8u60   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static float drawString(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               int x,
                               int y) {

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator,x,y); //for the cases where advance
                                    //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}
 
Example 9
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 10
/**
 * The following draw functions have the same semantic as the
 * Graphics methods with the same names.
 *
 * this is used for printing
 */
public static int drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    // If text fits the screenWidth, then do not need to justify
                    if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
                                            trimmedText) > screenWidth) {
                        layout = layout.getJustifiedLayout(screenWidth);
                    }

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D)g;

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g.drawChars(data, offset, length, x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g.drawChars(data, offset, length, x, y);
    }
    return nextX;
}
 
Example 11
public static float drawString(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               int x,
                               int y) {

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator,x,y); //for the cases where advance
                                    //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}
 
Example 12
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 13
/**
 * The following draw functions have the same semantic as the
 * Graphics methods with the same names.
 *
 * this is used for printing
 */
public static int drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    layout = layout.getJustifiedLayout(screenWidth);

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D)g;

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g.drawChars(data, offset, length, x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g.drawChars(data, offset, length, x, y);
    }
    return nextX;
}
 
Example 14
public static float drawString(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               int x,
                               int y) {

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator,x,y); //for the cases where advance
                                    //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}
 
Example 15
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 16
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 17
Source Project: jdk8u-jdk   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * The following draw functions have the same semantic as the
 * Graphics methods with the same names.
 *
 * this is used for printing
 */
public static int drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    layout = layout.getJustifiedLayout(screenWidth);

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D)g;

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g.drawChars(data, offset, length, x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g.drawChars(data, offset, length, x, y);
    }
    return nextX;
}
 
Example 18
Source Project: jdk8u-jdk   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static float drawString(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               int x,
                               int y) {

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator,x,y); //for the cases where advance
                                    //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}
 
Example 19
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 20
Source Project: hottub   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * The following draw functions have the same semantic as the
 * Graphics methods with the same names.
 *
 * this is used for printing
 */
public static int drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    layout = layout.getJustifiedLayout(screenWidth);

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D)g;

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g.drawChars(data, offset, length, x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g.drawChars(data, offset, length, x, y);
    }
    return nextX;
}
 
Example 21
Source Project: hottub   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static float drawString(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               int x,
                               int y) {

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator,x,y); //for the cases where advance
                                    //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}
 
Example 22
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 23
/**
 * The following draw functions have the same semantic as the
 * Graphics methods with the same names.
 *
 * this is used for printing
 */
public static int drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    layout = layout.getJustifiedLayout(screenWidth);

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D)g;

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g.drawChars(data, offset, length, x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g.drawChars(data, offset, length, x, y);
    }
    return nextX;
}
 
Example 24
public static float drawString(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               int x,
                               int y) {

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator,x,y); //for the cases where advance
                                    //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}
 
Example 25
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 26
Source Project: openjdk-8   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * The following draw functions have the same semantic as the
 * Graphics methods with the same names.
 *
 * this is used for printing
 */
public static int drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             int x,
                             int y) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    int nextX = x + getFontMetrics(c, g).charsWidth(data, offset, length);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    layout = layout.getJustifiedLayout(screenWidth);

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D)g;

        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g.drawChars(data, offset, length, x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g.drawChars(data, offset, length, x, y);
    }
    return nextX;
}
 
Example 27
Source Project: openjdk-8   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static float drawString(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               int x,
                               int y) {

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator,x,y); //for the cases where advance
                                    //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}
 
Example 28
protected Color getAnotherObject() {
    return new PrintColorUIResource(0, Color.WHITE);
}
 
Example 29
Source Project: jdk8u_jdk   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static float drawChars(JComponent c, Graphics g,
                             char[] data,
                             int offset,
                             int length,
                             float x,
                             float y,
                             boolean useFPAPI) {
    if ( length <= 0 ) { //no need to paint empty strings
        return x;
    }
    float nextX = x + getFontCharsWidth(data, offset, length,
                                        getFontMetrics(c, g),
                                        useFPAPI);
    if (isPrinting(g)) {
        Graphics2D g2d = getGraphics2D(g);
        if (g2d != null) {
            FontRenderContext deviceFontRenderContext = g2d.
                getFontRenderContext();
            FontRenderContext frc = getFontRenderContext(c);
            if (frc != null &&
                !isFontRenderContextPrintCompatible
                (deviceFontRenderContext, frc)) {

                String text = new String(data, offset, length);
                TextLayout layout = new TextLayout(text, g2d.getFont(),
                                deviceFontRenderContext);
                String trimmedText = trimTrailingSpaces(text);
                if (!trimmedText.isEmpty()) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(trimmedText, frc).getWidth();
                    // If text fits the screenWidth, then do not need to justify
                    if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
                                            trimmedText) > screenWidth) {
                        layout = layout.getJustifiedLayout(screenWidth);
                    }

                    /* Use alternate print color if specified */
                    Color col = g2d.getColor();
                    if (col instanceof PrintColorUIResource) {
                        g2d.setColor(((PrintColorUIResource)col).getPrintColor());
                    }

                    layout.draw(g2d,x,y);

                    g2d.setColor(col);
                }

                return nextX;
            }
        }
    }

    if (!(g instanceof Graphics2D)) {
        g.drawChars(data, offset, length, (int) x, (int) y);
        return nextX;
    }

    Graphics2D g2 = (Graphics2D) g;
    // Assume we're not printing if we get here, or that we are invoked
    // via Swing text printing which is laid out for the printer.
    AATextInfo info = drawTextAntialiased(c);
    if (info != null) {
        Object oldContrast = null;
        Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
        if (info.aaHint != null && info.aaHint != oldAAValue) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, info.aaHint);
        } else {
            oldAAValue = null;
        }
        if (info.lcdContrastHint != null) {
            oldContrast = g2.getRenderingHint(KEY_TEXT_LCD_CONTRAST);
            if (info.lcdContrastHint.equals(oldContrast)) {
                oldContrast = null;
            } else {
                g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST,
                                    info.lcdContrastHint);
            }
        }

        g2.drawString(new String(data, offset, length), x, y);

        if (oldAAValue != null) {
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
        }
        if (oldContrast != null) {
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
        }
    }
    else {
        g2.drawString(new String(data, offset, length), x, y);
    }
    return nextX;
}
 
Example 30
Source Project: jdk8u_jdk   Source File: SwingUtilities2.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static float drawStringImpl(JComponent c, Graphics g,
                               AttributedCharacterIterator iterator,
                               float x, float y)
{

    float retVal;
    boolean isPrinting = isPrinting(g);
    Color col = g.getColor();

    if (isPrinting) {
        /* Use alternate print color if specified */
        if (col instanceof PrintColorUIResource) {
            g.setColor(((PrintColorUIResource)col).getPrintColor());
        }
    }

    Graphics2D g2d = getGraphics2D(g);
    if (g2d == null) {
        g.drawString(iterator, (int)x, (int)y); //for the cases where advance
                                                //matters it should not happen
        retVal = x;

    } else {
        FontRenderContext frc;
        if (isPrinting) {
            frc = getFontRenderContext(c);
            if (frc.isAntiAliased() || frc.usesFractionalMetrics()) {
                frc = new FontRenderContext(frc.getTransform(), false, false);
            }
        } else if ((frc = getFRCProperty(c)) != null) {
            /* frc = frc; ! */
        } else {
            frc = g2d.getFontRenderContext();
        }
        TextLayout layout;
        if (isPrinting) {
            FontRenderContext deviceFRC = g2d.getFontRenderContext();
            if (!isFontRenderContextPrintCompatible(frc, deviceFRC)) {
                layout = new TextLayout(iterator, deviceFRC);
                AttributedCharacterIterator trimmedIt =
                        getTrimmedTrailingSpacesIterator(iterator);
                if (trimmedIt != null) {
                    float screenWidth = new TextLayout(trimmedIt, frc).
                            getAdvance();
                    layout = layout.getJustifiedLayout(screenWidth);
                }
            } else {
                layout = new TextLayout(iterator, frc);
            }
        } else {
            layout = new TextLayout(iterator, frc);
        }
        layout.draw(g2d, x, y);
        retVal = layout.getAdvance();
    }

    if (isPrinting) {
        g.setColor(col);
    }

    return retVal;
}