Java Code Examples for java.awt.Font#equals()

The following examples show how to use java.awt.Font#equals() . 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
Source File: XComponentPeer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setFont(Font f) {
    if (f == null) {
        f = XWindow.getDefaultFont();
    }
    synchronized (getStateLock()) {
        if (f.equals(font)) {
            return;
        }
        font = f;
    }
    // as it stands currently we don't need to do layout since
    // layout is done in the Component upon setFont.
    //layout();
    repaint();
}
 
Example 2
Source File: PropertyPanel.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
private Font getUniqueFont() {
    Font font = null;
    int n = reportGridCells.size();
    for (int i = 0; i < n; i++) {
        BandElement element = reportGridCells.get(i).getValue();
        if (i == 0) {
            font = element.getFont();
            continue;
        }
        if (!font.equals(element.getFont())) {
            return null;
        }
    }
    
    return font;
}
 
Example 3
Source File: XComponentPeer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setFont(Font f) {
    if (f == null) {
        f = XWindow.getDefaultFont();
    }
    synchronized (getStateLock()) {
        if (f.equals(font)) {
            return;
        }
        font = f;
    }
    // as it stands currently we don't need to do layout since
    // layout is done in the Component upon setFont.
    //layout();
    repaint();
}
 
Example 4
Source File: XComponentPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setFont(Font f) {
    if (f == null) {
        f = XWindow.getDefaultFont();
    }
    synchronized (getStateLock()) {
        if (f.equals(font)) {
            return;
        }
        font = f;
    }
    // as it stands currently we don't need to do layout since
    // layout is done in the Component upon setFont.
    //layout();
    repaint();
}
 
Example 5
Source File: XComponentPeer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setFont(Font f) {
    if (f == null) {
        f = XWindow.getDefaultFont();
    }
    synchronized (getStateLock()) {
        if (f.equals(font)) {
            return;
        }
        font = f;
    }
    // as it stands currently we don't need to do layout since
    // layout is done in the Component upon setFont.
    //layout();
    repaint();
}
 
Example 6
Source File: XComponentPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setFont(Font f) {
    if (f == null) {
        f = XWindow.getDefaultFont();
    }
    synchronized (getStateLock()) {
        if (f.equals(font)) {
            return;
        }
        font = f;
    }
    // as it stands currently we don't need to do layout since
    // layout is done in the Component upon setFont.
    //layout();
    repaint();
}
 
Example 7
Source File: XComponentPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setFont(Font f) {
    if (f == null) {
        f = XWindow.getDefaultFont();
    }
    synchronized (getStateLock()) {
        if (f.equals(font)) {
            return;
        }
        font = f;
    }
    // as it stands currently we don't need to do layout since
    // layout is done in the Component upon setFont.
    //layout();
    repaint();
}
 
Example 8
Source File: bug6421058.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testDefaultFont(final JFrame frame) {
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSpinner spinner = new JSpinner();
    frame.add(spinner);
    frame.setSize(300, 100);
    frame.setVisible(true);

    final DefaultEditor editor = (DefaultEditor) spinner.getEditor();
    final Font editorFont = editor.getTextField().getFont();

    /*
     * Validate that the font of the text field is changed to the
     * font of JSpinner if the font of text field was not set by the
     * user.
     */

    if (!(editorFont instanceof UIResource)) {
        throw new RuntimeException("Font must be UIResource");
    }
    if (!editorFont.equals(spinner.getFont())) {
        throw new RuntimeException("Wrong FONT");
    }
}
 
Example 9
Source File: right_QuickNotepad_1.14.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
private void propertiesChanged() {
	String propertyFilename = jEdit
			.getProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath");
	if (!MiscUtilities.objectsEqual(defaultFilename, propertyFilename)) {
		saveFile();
		toolPanel.propertiesChanged();
		defaultFilename = propertyFilename;
		filename = defaultFilename;
		readFile();
	}
	Font newFont = QuickNotepadOptionPane.makeFont();
	if (!newFont.equals(textArea.getFont())) {
		textArea.setFont(newFont);
	}
}
 
Example 10
Source File: SyntaxUtilities.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Paints the specified line onto the graphics context. Note that this method munges the offset
 * and count values of the segment.
 * 
 * @param line
 *            The line segment
 * @param tokens
 *            The token list for the line
 * @param styles
 *            The syntax style list
 * @param expander
 *            The tab expander used to determine tab stops. May be null
 * @param gfx
 *            The graphics context
 * @param x
 *            The x co-ordinate
 * @param y
 *            The y co-ordinate
 * @return The x co-ordinate, plus the width of the painted string
 */
public static int paintSyntaxLine(Segment line, Token tokens, SyntaxStyle[] styles, TabExpander expander, Graphics gfx,
		int x, int y) {
	Font defaultFont = gfx.getFont();
	Color defaultColor = gfx.getColor();

	for (;;) {
		byte id = tokens.id;
		if (id == Token.END) {
			break;
		}

		int length = tokens.length;
		if (id == Token.NULL) {
			if (!defaultColor.equals(gfx.getColor())) {
				gfx.setColor(defaultColor);
			}
			if (!defaultFont.equals(gfx.getFont())) {
				gfx.setFont(defaultFont);
			}
		} else {
			styles[id].setGraphicsFlags(gfx, defaultFont);
		}

		line.count = length;
		x = Utilities.drawTabbedText(line, x, y, gfx, expander, 0);
		line.offset += length;

		tokens = tokens.next;
	}

	return x;
}
 
Example 11
Source File: Test7022041.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
  * Check behaviour of method TitledBorder.getTitleFont()
  */
private static void checkTitleFont() {
    TitledBorder titledBorder = new TitledBorder(new EmptyBorder(1, 1, 1, 1));
    Font defaultFont = UIManager.getLookAndFeelDefaults().getFont("TitledBorder.font");
    Font titledBorderFont = titledBorder.getTitleFont();

    // check default configuration
    if (defaultFont == null) {
        if (titledBorderFont == null) {
            return;
        }
        else {
            throw new RuntimeException("TitledBorder default font should be null");
        }
    }
    if (!defaultFont.equals(titledBorderFont)) {
        throw new RuntimeException("L&F default font " + defaultFont.toString()
                                 + " differs from TitledBorder font " + titledBorderFont.toString());
    }

    // title font is explicitly specified
    Font font = new Font("Dialog", Font.PLAIN, 10);
    titledBorder.setTitleFont(font);
    if (!font.equals(titledBorder.getTitleFont())) {
        throw new RuntimeException("TitledBorder font should be " + font.toString());
    }

    // title Font is unspecified
    titledBorder.setTitleFont(null);
    if (!defaultFont.equals(titledBorder.getTitleFont())) {
        throw new RuntimeException("L&F default font " + defaultFont.toString()
                                 + " differs from TitledBorder font " + titledBorderFont.toString());
    }
}
 
Example 12
Source File: right_QuickNotepad_1.14.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
private void propertiesChanged() {
	String propertyFilename = jEdit
			.getProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath");
	if (!MiscUtilities.objectsEqual(defaultFilename, propertyFilename)) {
		saveFile();
		toolPanel.propertiesChanged();
		defaultFilename = propertyFilename;
		filename = defaultFilename;
		readFile();
	}
	Font newFont = QuickNotepadOptionPane.makeFont();
	if (!newFont.equals(textArea.getFont())) {
		textArea.setFont(newFont);
	}
}
 
Example 13
Source File: left_QuickNotepad_1.13.java    From coming with MIT License 5 votes vote down vote up
private void propertiesChanged() {
	String propertyFilename = jEdit
			.getProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath");
	if (!MiscUtilities.objectsEqual(defaultFilename, propertyFilename)) {
		saveFile();
		toolPanel.propertiesChanged();
		defaultFilename = propertyFilename;
		filename = defaultFilename;
		readFile();
	}
	Font newFont = QuickNotepadOptionPane.makeFont();
	if (!newFont.equals(textArea.getFont())) {
		textArea.setFont(newFont);
	}
}
 
Example 14
Source File: left_QuickNotepad_1.13.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
private void propertiesChanged() {
	String propertyFilename = jEdit
			.getProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath");
	if (!MiscUtilities.objectsEqual(defaultFilename, propertyFilename)) {
		saveFile();
		toolPanel.propertiesChanged();
		defaultFilename = propertyFilename;
		filename = defaultFilename;
		readFile();
	}
	Font newFont = QuickNotepadOptionPane.makeFont();
	if (!newFont.equals(textArea.getFont())) {
		textArea.setFont(newFont);
	}
}
 
Example 15
Source File: Coloring.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Derive a new coloring by changing the font and font-mode and leaving
* the rest of the coloring unchanged.
*/
public static Coloring changeFont(Coloring c, Font newFont, int newFontMode) {
    if ((newFont == null && c.font == null)
            || (newFont != null && newFont.equals(c.font)
                && c.fontMode == newFontMode)
       ) {
        return c;
    }

    return new Coloring(newFont, c.foreColor, c.backColor);
}
 
Example 16
Source File: PSPathGraphics.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    if (str.length() == 0) {
        return;
    }

    /* If the Font has layout attributes we need to delegate to TextLayout.
     * TextLayout renders text as GlyphVectors. We try to print those
     * using printer fonts - ie using Postscript text operators so
     * we may be reinvoked. In that case the "!printingGlyphVector" test
     * prevents us recursing and instead sends us into the body of the
     * method where we can safely ignore layout attributes as those
     * are already handled by TextLayout.
     */
    if (font.hasLayoutAttributes() && !printingGlyphVector) {
        TextLayout layout = new TextLayout(str, font, frc);
        layout.draw(this, x, y);
        return;
    }

    Font oldFont = getFont();
    if (!oldFont.equals(font)) {
        setFont(font);
    } else {
        oldFont = null;
    }

    boolean drawnWithPS = false;

    float translateX = 0f, translateY = 0f;
    boolean fontisTransformed = getFont().isTransformed();

    if (fontisTransformed) {
        AffineTransform fontTx = getFont().getTransform();
        int transformType = fontTx.getType();
        /* TYPE_TRANSLATION is a flag bit but we can do "==" here
         * because we want to detect when its just that bit set and
         *
         */
        if (transformType == AffineTransform.TYPE_TRANSLATION) {
            translateX = (float)(fontTx.getTranslateX());
            translateY = (float)(fontTx.getTranslateY());
            if (Math.abs(translateX) < 0.00001) translateX = 0f;
            if (Math.abs(translateY) < 0.00001) translateY = 0f;
            fontisTransformed = false;
        }
    }

    boolean directToPS = !fontisTransformed;

    if (!PSPrinterJob.shapeTextProp && directToPS) {

        PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
        if (psPrinterJob.setFont(getFont())) {

            /* Set the text color.
             * We should not be in this shape printing path
             * if the application is drawing with non-solid
             * colors. We should be in the raster path. Because
             * we are here in the shape path, the cast of the
             * paint to a Color should be fine.
             */
            try {
                psPrinterJob.setColor((Color)getPaint());
            } catch (ClassCastException e) {
                if (oldFont != null) {
                    setFont(oldFont);
                }
                throw new IllegalArgumentException(
                                            "Expected a Color instance");
            }

            psPrinterJob.setTransform(getTransform());
            psPrinterJob.setClip(getClip());

            drawnWithPS = psPrinterJob.textOut(this, str,
                                               x+translateX, y+translateY,
                                               font, frc, w);
        }
    }

    /* The text could not be converted directly to PS text
     * calls so decompose the text into a shape.
     */
    if (drawnWithPS == false) {
        if (oldFont != null) {
            setFont(oldFont);
            oldFont = null;
        }
        super.drawString(str, x, y, font, frc, w);
    }

    if (oldFont != null) {
        setFont(oldFont);
    }
}
 
Example 17
Source File: DrawGraphics.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override void setFont(Font font) {
    if (!font.equals(this.font)) {
        flush();
        this.font = font;
    }
}
 
Example 18
Source File: PSPathGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    if (str.length() == 0) {
        return;
    }

    /* If the Font has layout attributes we need to delegate to TextLayout.
     * TextLayout renders text as GlyphVectors. We try to print those
     * using printer fonts - ie using Postscript text operators so
     * we may be reinvoked. In that case the "!printingGlyphVector" test
     * prevents us recursing and instead sends us into the body of the
     * method where we can safely ignore layout attributes as those
     * are already handled by TextLayout.
     */
    if (font.hasLayoutAttributes() && !printingGlyphVector) {
        TextLayout layout = new TextLayout(str, font, frc);
        layout.draw(this, x, y);
        return;
    }

    Font oldFont = getFont();
    if (!oldFont.equals(font)) {
        setFont(font);
    } else {
        oldFont = null;
    }

    boolean drawnWithPS = false;

    float translateX = 0f, translateY = 0f;
    boolean fontisTransformed = getFont().isTransformed();

    if (fontisTransformed) {
        AffineTransform fontTx = getFont().getTransform();
        int transformType = fontTx.getType();
        /* TYPE_TRANSLATION is a flag bit but we can do "==" here
         * because we want to detect when its just that bit set and
         *
         */
        if (transformType == AffineTransform.TYPE_TRANSLATION) {
            translateX = (float)(fontTx.getTranslateX());
            translateY = (float)(fontTx.getTranslateY());
            if (Math.abs(translateX) < 0.00001) translateX = 0f;
            if (Math.abs(translateY) < 0.00001) translateY = 0f;
            fontisTransformed = false;
        }
    }

    boolean directToPS = !fontisTransformed;

    if (!PSPrinterJob.shapeTextProp && directToPS) {

        PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
        if (psPrinterJob.setFont(getFont())) {

            /* Set the text color.
             * We should not be in this shape printing path
             * if the application is drawing with non-solid
             * colors. We should be in the raster path. Because
             * we are here in the shape path, the cast of the
             * paint to a Color should be fine.
             */
            try {
                psPrinterJob.setColor((Color)getPaint());
            } catch (ClassCastException e) {
                if (oldFont != null) {
                    setFont(oldFont);
                }
                throw new IllegalArgumentException(
                                            "Expected a Color instance");
            }

            psPrinterJob.setTransform(getTransform());
            psPrinterJob.setClip(getClip());

            drawnWithPS = psPrinterJob.textOut(this, str,
                                               x+translateX, y+translateY,
                                               font, frc, w);
        }
    }

    /* The text could not be converted directly to PS text
     * calls so decompose the text into a shape.
     */
    if (drawnWithPS == false) {
        if (oldFont != null) {
            setFont(oldFont);
            oldFont = null;
        }
        super.drawString(str, x, y, font, frc, w);
    }

    if (oldFont != null) {
        setFont(oldFont);
    }
}
 
Example 19
Source File: PSPathGraphics.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected void drawString(String str, float x, float y,
                          Font font, FontRenderContext frc, float w) {
    if (str.length() == 0) {
        return;
    }

    /* If the Font has layout attributes we need to delegate to TextLayout.
     * TextLayout renders text as GlyphVectors. We try to print those
     * using printer fonts - ie using Postscript text operators so
     * we may be reinvoked. In that case the "!printingGlyphVector" test
     * prevents us recursing and instead sends us into the body of the
     * method where we can safely ignore layout attributes as those
     * are already handled by TextLayout.
     */
    if (font.hasLayoutAttributes() && !printingGlyphVector) {
        TextLayout layout = new TextLayout(str, font, frc);
        layout.draw(this, x, y);
        return;
    }

    Font oldFont = getFont();
    if (!oldFont.equals(font)) {
        setFont(font);
    } else {
        oldFont = null;
    }

    boolean drawnWithPS = false;

    float translateX = 0f, translateY = 0f;
    boolean fontisTransformed = getFont().isTransformed();

    if (fontisTransformed) {
        AffineTransform fontTx = getFont().getTransform();
        int transformType = fontTx.getType();
        /* TYPE_TRANSLATION is a flag bit but we can do "==" here
         * because we want to detect when its just that bit set and
         *
         */
        if (transformType == AffineTransform.TYPE_TRANSLATION) {
            translateX = (float)(fontTx.getTranslateX());
            translateY = (float)(fontTx.getTranslateY());
            if (Math.abs(translateX) < 0.00001) translateX = 0f;
            if (Math.abs(translateY) < 0.00001) translateY = 0f;
            fontisTransformed = false;
        }
    }

    boolean directToPS = !fontisTransformed;

    if (!PSPrinterJob.shapeTextProp && directToPS) {

        PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
        if (psPrinterJob.setFont(getFont())) {

            /* Set the text color.
             * We should not be in this shape printing path
             * if the application is drawing with non-solid
             * colors. We should be in the raster path. Because
             * we are here in the shape path, the cast of the
             * paint to a Color should be fine.
             */
            try {
                psPrinterJob.setColor((Color)getPaint());
            } catch (ClassCastException e) {
                if (oldFont != null) {
                    setFont(oldFont);
                }
                throw new IllegalArgumentException(
                                            "Expected a Color instance");
            }

            psPrinterJob.setTransform(getTransform());
            psPrinterJob.setClip(getClip());

            drawnWithPS = psPrinterJob.textOut(this, str,
                                               x+translateX, y+translateY,
                                               font, frc, w);
        }
    }

    /* The text could not be converted directly to PS text
     * calls so decompose the text into a shape.
     */
    if (drawnWithPS == false) {
        if (oldFont != null) {
            setFont(oldFont);
            oldFont = null;
        }
        super.drawString(str, x, y, font, frc, w);
    }

    if (oldFont != null) {
        setFont(oldFont);
    }
}
 
Example 20
Source File: WrongEditorTextFieldFont.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testDefaultFont(final JFrame frame) {
    final JSpinner spinner = new JSpinner();
    final JSpinner spinner_u = new JSpinner();
    frame.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 50));
    frame.getContentPane().add(spinner);
    frame.getContentPane().add(spinner_u);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    final DefaultEditor ed = (DefaultEditor) spinner.getEditor();
    final DefaultEditor ed_u = (DefaultEditor) spinner_u.getEditor();
    ed_u.getTextField().setFont(USERS_FONT);

    for (int i = 5; i < 40; i += 5) {
        /*
         * Validate that the font of the text field is changed to the
         * font of JSpinner if the font of text field was not set by the
         * user.
         */
        final Font tff = ed.getTextField().getFont();
        if (!(tff instanceof UIResource)) {
            throw new RuntimeException("Font must be UIResource");
        }
        if (spinner.getFont().getSize() != tff.getSize()) {
            throw new RuntimeException("Rrong size");
        }
        spinner.setFont(new Font("dialog", Font.BOLD, i));
        /*
         * Validate that the font of the text field is NOT changed to the
         * font of JSpinner if the font of text field was set by the user.
         */
        final Font tff_u = ed_u.getTextField().getFont();
        if (tff_u instanceof UIResource || !tff_u.equals(USERS_FONT)) {
            throw new RuntimeException("Font must NOT be UIResource");
        }
        if (spinner_u.getFont().getSize() == tff_u.getSize()) {
            throw new RuntimeException("Wrong size");
        }
        spinner_u.setFont(new Font("dialog", Font.BOLD, i));
    }
}