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

The following examples show how to use java.awt.Font#getAttributes() . 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: TextLayout.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
Example 2
Source File: TextLayout.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
Example 3
Source File: TextLayout.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a {@code TextLayout} from a {@code String}
 * and a {@link Font}.  All the text is styled using the specified
 * {@code Font}.
 * <p>
 * The {@code String} must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a {@code Font} used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       {@code TextLayout} and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
Example 4
Source File: TextLayout.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
Example 5
Source File: TextLayout.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
Example 6
Source File: TextLayout.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
Example 7
Source File: GradleCliCompletionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) {
    Map<TextAttribute, Object> attributes = new HashMap<>(defaultFont.getAttributes());
    if (!flag.isSupported()) {
        attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    }
    Font font = new Font(attributes);
    CompletionUtilities.renderHtml(null, getValue(), null, g, font, defaultColor, width, height, selected);
}
 
Example 8
Source File: TextLayout.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a <code>TextLayout</code> from a <code>String</code>
 * and a {@link Font}.  All the text is styled using the specified
 * <code>Font</code>.
 * <p>
 * The <code>String</code> must specify a single paragraph of text,
 * because an entire paragraph is required for the bidirectional
 * algorithm.
 * @param string the text to display
 * @param font a <code>Font</code> used to style the text
 * @param frc contains information about a graphics device which is needed
 *       to measure the text correctly.
 *       Text measurements can vary slightly depending on the
 *       device resolution, and attributes such as antialiasing.  This
 *       parameter does not specify a translation between the
 *       <code>TextLayout</code> and user space.
 */
public TextLayout(String string, Font font, FontRenderContext frc) {

    if (font == null) {
        throw new IllegalArgumentException("Null font passed to TextLayout constructor.");
    }

    if (string == null) {
        throw new IllegalArgumentException("Null string passed to TextLayout constructor.");
    }

    if (string.length() == 0) {
        throw new IllegalArgumentException("Zero length string passed to TextLayout constructor.");
    }

    Map<? extends Attribute, ?> attributes = null;
    if (font.hasLayoutAttributes()) {
        attributes = font.getAttributes();
    }

    char[] text = string.toCharArray();
    if (sameBaselineUpTo(font, text, 0, text.length) == text.length) {
        fastInit(text, font, attributes, frc);
    } else {
        AttributedString as = attributes == null
            ? new AttributedString(string)
            : new AttributedString(string, attributes);
        as.addAttribute(TextAttribute.FONT, font);
        standardInit(as.getIterator(), text, frc);
    }
}
 
Example 9
Source File: MetaData.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    Font font = (Font) oldInstance;

    int count = 0;
    String family = null;
    int style = Font.PLAIN;
    int size = 12;

    Map<TextAttribute, ?> basic = font.getAttributes();
    Map<TextAttribute, Object> clone = new HashMap<>(basic.size());
    for (TextAttribute key : basic.keySet()) {
        Object value = basic.get(key);
        if (value != null) {
            clone.put(key, value);
        }
        if (key == TextAttribute.FAMILY) {
            if (value instanceof String) {
                count++;
                family = (String) value;
            }
        }
        else if (key == TextAttribute.WEIGHT) {
            if (TextAttribute.WEIGHT_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.WEIGHT_BOLD.equals(value)) {
                count++;
                style |= Font.BOLD;
            }
        }
        else if (key == TextAttribute.POSTURE) {
            if (TextAttribute.POSTURE_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.POSTURE_OBLIQUE.equals(value)) {
                count++;
                style |= Font.ITALIC;
            }
        } else if (key == TextAttribute.SIZE) {
            if (value instanceof Number) {
                Number number = (Number) value;
                size = number.intValue();
                if (size == number.floatValue()) {
                    count++;
                }
            }
        }
    }
    Class<?> type = font.getClass();
    if (count == clone.size()) {
        return new Expression(font, type, "new", new Object[]{family, style, size});
    }
    if (type == Font.class) {
        return new Expression(font, type, "getFont", new Object[]{clone});
    }
    return new Expression(font, type, "new", new Object[]{Font.getFont(clone)});
}
 
Example 10
Source File: LabelNav.java    From brModelo with GNU General Public License v3.0 4 votes vote down vote up
public void LikeLink() {
    Font font = getFont();
    Map attributes = font.getAttributes();
    attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    setFont(font.deriveFont(attributes));
}
 
Example 11
Source File: MetaData.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    Font font = (Font) oldInstance;

    int count = 0;
    String family = null;
    int style = Font.PLAIN;
    int size = 12;

    Map basic = font.getAttributes();
    Map clone = new HashMap(basic.size());
    for (Object key : basic.keySet()) {
        Object value = basic.get(key);
        if (value != null) {
            clone.put(key, value);
        }
        if (key == TextAttribute.FAMILY) {
            if (value instanceof String) {
                count++;
                family = (String) value;
            }
        }
        else if (key == TextAttribute.WEIGHT) {
            if (TextAttribute.WEIGHT_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.WEIGHT_BOLD.equals(value)) {
                count++;
                style |= Font.BOLD;
            }
        }
        else if (key == TextAttribute.POSTURE) {
            if (TextAttribute.POSTURE_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.POSTURE_OBLIQUE.equals(value)) {
                count++;
                style |= Font.ITALIC;
            }
        } else if (key == TextAttribute.SIZE) {
            if (value instanceof Number) {
                Number number = (Number) value;
                size = number.intValue();
                if (size == number.floatValue()) {
                    count++;
                }
            }
        }
    }
    Class type = font.getClass();
    if (count == clone.size()) {
        return new Expression(font, type, "new", new Object[]{family, style, size});
    }
    if (type == Font.class) {
        return new Expression(font, type, "getFont", new Object[]{clone});
    }
    return new Expression(font, type, "new", new Object[]{Font.getFont(clone)});
}
 
Example 12
Source File: TextSettingsPanel.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void setAttributeMapFromFontSettings(Font font) {
    if (font.hasLayoutAttributes()) {
        map = (Map<TextAttribute, Object>) font.getAttributes();
    }
}
 
Example 13
Source File: MetaData.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    Font font = (Font) oldInstance;

    int count = 0;
    String family = null;
    int style = Font.PLAIN;
    int size = 12;

    Map<TextAttribute, ?> basic = font.getAttributes();
    Map<TextAttribute, Object> clone = new HashMap<>(basic.size());
    for (TextAttribute key : basic.keySet()) {
        Object value = basic.get(key);
        if (value != null) {
            clone.put(key, value);
        }
        if (key == TextAttribute.FAMILY) {
            if (value instanceof String) {
                count++;
                family = (String) value;
            }
        }
        else if (key == TextAttribute.WEIGHT) {
            if (TextAttribute.WEIGHT_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.WEIGHT_BOLD.equals(value)) {
                count++;
                style |= Font.BOLD;
            }
        }
        else if (key == TextAttribute.POSTURE) {
            if (TextAttribute.POSTURE_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.POSTURE_OBLIQUE.equals(value)) {
                count++;
                style |= Font.ITALIC;
            }
        } else if (key == TextAttribute.SIZE) {
            if (value instanceof Number) {
                Number number = (Number) value;
                size = number.intValue();
                if (size == number.floatValue()) {
                    count++;
                }
            }
        }
    }
    Class<?> type = font.getClass();
    if (count == clone.size()) {
        return new Expression(font, type, "new", new Object[]{family, style, size});
    }
    if (type == Font.class) {
        return new Expression(font, type, "getFont", new Object[]{clone});
    }
    return new Expression(font, type, "new", new Object[]{Font.getFont(clone)});
}
 
Example 14
Source File: MetaData.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    Font font = (Font) oldInstance;

    int count = 0;
    String family = null;
    int style = Font.PLAIN;
    int size = 12;

    Map<TextAttribute, ?> basic = font.getAttributes();
    Map<TextAttribute, Object> clone = new HashMap<>(basic.size());
    for (TextAttribute key : basic.keySet()) {
        Object value = basic.get(key);
        if (value != null) {
            clone.put(key, value);
        }
        if (key == TextAttribute.FAMILY) {
            if (value instanceof String) {
                count++;
                family = (String) value;
            }
        }
        else if (key == TextAttribute.WEIGHT) {
            if (TextAttribute.WEIGHT_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.WEIGHT_BOLD.equals(value)) {
                count++;
                style |= Font.BOLD;
            }
        }
        else if (key == TextAttribute.POSTURE) {
            if (TextAttribute.POSTURE_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.POSTURE_OBLIQUE.equals(value)) {
                count++;
                style |= Font.ITALIC;
            }
        } else if (key == TextAttribute.SIZE) {
            if (value instanceof Number) {
                Number number = (Number) value;
                size = number.intValue();
                if (size == number.floatValue()) {
                    count++;
                }
            }
        }
    }
    Class<?> type = font.getClass();
    if (count == clone.size()) {
        return new Expression(font, type, "new", new Object[]{family, style, size});
    }
    if (type == Font.class) {
        return new Expression(font, type, "getFont", new Object[]{clone});
    }
    return new Expression(font, type, "new", new Object[]{Font.getFont(clone)});
}
 
Example 15
Source File: MetaData.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    Font font = (Font) oldInstance;

    int count = 0;
    String family = null;
    int style = Font.PLAIN;
    int size = 12;

    Map<TextAttribute, ?> basic = font.getAttributes();
    Map<TextAttribute, Object> clone = new HashMap<>(basic.size());
    for (TextAttribute key : basic.keySet()) {
        Object value = basic.get(key);
        if (value != null) {
            clone.put(key, value);
        }
        if (key == TextAttribute.FAMILY) {
            if (value instanceof String) {
                count++;
                family = (String) value;
            }
        }
        else if (key == TextAttribute.WEIGHT) {
            if (TextAttribute.WEIGHT_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.WEIGHT_BOLD.equals(value)) {
                count++;
                style |= Font.BOLD;
            }
        }
        else if (key == TextAttribute.POSTURE) {
            if (TextAttribute.POSTURE_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.POSTURE_OBLIQUE.equals(value)) {
                count++;
                style |= Font.ITALIC;
            }
        } else if (key == TextAttribute.SIZE) {
            if (value instanceof Number) {
                Number number = (Number) value;
                size = number.intValue();
                if (size == number.floatValue()) {
                    count++;
                }
            }
        }
    }
    Class<?> type = font.getClass();
    if (count == clone.size()) {
        return new Expression(font, type, "new", new Object[]{family, style, size});
    }
    if (type == Font.class) {
        return new Expression(font, type, "getFont", new Object[]{clone});
    }
    return new Expression(font, type, "new", new Object[]{Font.getFont(clone)});
}
 
Example 16
Source File: SwingTextMetrics.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Allows reuse of the multi-line text element for computing bounds of
 * changed font/text content
 * 
 * @param fd
 */
public final void reuse( Label la, double forceWrappingSize )
{

	final Font f = (Font) xs.createFont( la.getCaption( ).getFont( ) );
	fm = g2d.getFontMetrics( f );
	final FontRenderContext frc = g2d.getFontRenderContext( );

	cachedwidth = Double.NaN;

	String s = la.getCaption( ).getValue( );
	if ( s == null )
	{
		s = IConstants.NULL_STRING;
	}
	else
	{
		// trim leading and trailing spaces.
		s = s.trim( );
	}

	if ( s.length( ) == 0 ) // TextLayout DOESN'T LIKE EMPTY STRINGS
	{
		s = IConstants.ONE_SPACE;
	}
	String[] sa = splitOnBreaks( s, forceWrappingSize, f );
	if ( sa == null )
	{
		iLineCount = 1;
		oText = s;
		tla = new TextLayout[1];
		fsa = new String[1];
		tla[0] = new TextLayout( s, f.getAttributes( ), frc );
		fsa[0] = s;
	}
	else
	{
		iLineCount = sa.length;
		oText = sa;
		tla = new TextLayout[iLineCount];
		fsa = new String[iLineCount];
		for ( int i = 0; i < iLineCount; i++ )
		{
			tla[i] = new TextLayout( sa[i], f.getAttributes( ), frc );
			fsa[i] = sa[i];
		}
	}
	ins = la.getInsets( ).scaledInstance( pointsToPixels( ) );

	if ( forceWrappingSize > 0 )
	{
		// update label with new broken content.
		StringBuffer sb = new StringBuffer( );
		for ( int i = 0; i < fsa.length; i++ )
		{
			sb.append( fsa[i] ).append( "\n" ); //$NON-NLS-1$
		}

		if ( sb.length( ) > 0 )
		{
			sb.deleteCharAt( sb.length( ) - 1 );
		}

		la.getCaption( ).setValue( sb.toString( ) );
	}
}
 
Example 17
Source File: MetaData.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    Font font = (Font) oldInstance;

    int count = 0;
    String family = null;
    int style = Font.PLAIN;
    int size = 12;

    Map<TextAttribute, ?> basic = font.getAttributes();
    Map<TextAttribute, Object> clone = new HashMap<>(basic.size());
    for (TextAttribute key : basic.keySet()) {
        Object value = basic.get(key);
        if (value != null) {
            clone.put(key, value);
        }
        if (key == TextAttribute.FAMILY) {
            if (value instanceof String) {
                count++;
                family = (String) value;
            }
        }
        else if (key == TextAttribute.WEIGHT) {
            if (TextAttribute.WEIGHT_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.WEIGHT_BOLD.equals(value)) {
                count++;
                style |= Font.BOLD;
            }
        }
        else if (key == TextAttribute.POSTURE) {
            if (TextAttribute.POSTURE_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.POSTURE_OBLIQUE.equals(value)) {
                count++;
                style |= Font.ITALIC;
            }
        } else if (key == TextAttribute.SIZE) {
            if (value instanceof Number) {
                Number number = (Number) value;
                size = number.intValue();
                if (size == number.floatValue()) {
                    count++;
                }
            }
        }
    }
    Class<?> type = font.getClass();
    if (count == clone.size()) {
        return new Expression(font, type, "new", new Object[]{family, style, size});
    }
    if (type == Font.class) {
        return new Expression(font, type, "getFont", new Object[]{clone});
    }
    return new Expression(font, type, "new", new Object[]{Font.getFont(clone)});
}
 
Example 18
Source File: BeltColumnStatisticsPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Updates the charts.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateCharts() {
	for (int i = 0; i < listOfChartPanels.size(); i++) {
		JPanel panel = listOfChartPanels.get(i);
		panel.removeAll();
		JFreeChart chartOrNull = getModel().getChartOrNull(i);
		if (chartOrNull != null) {
			final ChartPanel chartPanel = new ChartPanel(chartOrNull) {

				private static final long serialVersionUID = -6953213567063104487L;

				@Override
				public Dimension getPreferredSize() {
					return DIMENSION_CHART_PANEL_ENLARGED;
				}
			};
			chartPanel.setPopupMenu(null);
			chartPanel.setBackground(COLOR_TRANSPARENT);
			chartPanel.setOpaque(false);
			chartPanel.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
			panel.add(chartPanel, BorderLayout.CENTER);

			JPanel openChartPanel = new JPanel(new GridBagLayout());
			openChartPanel.setOpaque(false);

			GridBagConstraints gbc = new GridBagConstraints();
			gbc.anchor = GridBagConstraints.CENTER;
			gbc.fill = GridBagConstraints.NONE;
			gbc.weightx = 1.0;
			gbc.weighty = 1.0;

			JButton openChartButton = new JButton(OPEN_CHART_ACTION);
			openChartButton.setOpaque(false);
			openChartButton.setContentAreaFilled(false);
			openChartButton.setBorderPainted(false);
			openChartButton.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
			openChartButton.setHorizontalAlignment(SwingConstants.LEFT);
			openChartButton.setHorizontalTextPosition(SwingConstants.LEFT);
			openChartButton.setIcon(null);
			Font font = openChartButton.getFont();
			Map attributes = font.getAttributes();
			attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
			openChartButton.setFont(font.deriveFont(attributes).deriveFont(10.0f));

			openChartPanel.add(openChartButton, gbc);

			panel.add(openChartPanel, BorderLayout.SOUTH);
		}
		panel.revalidate();
		panel.repaint();
	}
}
 
Example 19
Source File: MetaData.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    Font font = (Font) oldInstance;

    int count = 0;
    String family = null;
    int style = Font.PLAIN;
    int size = 12;

    Map<TextAttribute, ?> basic = font.getAttributes();
    Map<TextAttribute, Object> clone = new HashMap<>(basic.size());
    for (TextAttribute key : basic.keySet()) {
        Object value = basic.get(key);
        if (value != null) {
            clone.put(key, value);
        }
        if (key == TextAttribute.FAMILY) {
            if (value instanceof String) {
                count++;
                family = (String) value;
            }
        }
        else if (key == TextAttribute.WEIGHT) {
            if (TextAttribute.WEIGHT_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.WEIGHT_BOLD.equals(value)) {
                count++;
                style |= Font.BOLD;
            }
        }
        else if (key == TextAttribute.POSTURE) {
            if (TextAttribute.POSTURE_REGULAR.equals(value)) {
                count++;
            } else if (TextAttribute.POSTURE_OBLIQUE.equals(value)) {
                count++;
                style |= Font.ITALIC;
            }
        } else if (key == TextAttribute.SIZE) {
            if (value instanceof Number) {
                Number number = (Number) value;
                size = number.intValue();
                if (size == number.floatValue()) {
                    count++;
                }
            }
        }
    }
    Class<?> type = font.getClass();
    if (count == clone.size()) {
        return new Expression(font, type, "new", new Object[]{family, style, size});
    }
    if (type == Font.class) {
        return new Expression(font, type, "getFont", new Object[]{clone});
    }
    return new Expression(font, type, "new", new Object[]{Font.getFont(clone)});
}
 
Example 20
Source File: PGTUtil.java    From PolyGlot with MIT License 3 votes vote down vote up
/**
 * Adds attributes to fontmapping
 *
 * @param key Key value
 * @param value value-value
 * @param font font to add value to
 * @return newly derived font
 */
@SuppressWarnings("unchecked") // No good way to do this in a type safe manner.
public static Font addFontAttribute(Object key, Object value, Font font) {
    Map attributes = font.getAttributes();
    attributes.put(key, value);
    return font.deriveFont(attributes);
}