当前位置: 首页>>代码示例>>Java>>正文


Java Font.getAttributes方法代码示例

本文整理汇总了Java中java.awt.Font.getAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java Font.getAttributes方法的具体用法?Java Font.getAttributes怎么用?Java Font.getAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Font的用法示例。


在下文中一共展示了Font.getAttributes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initializeFont

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Initialise the font to be used based on configuration
 * 
 * @param baseFont The AWT font to render
 * @param size The point size of the font to generated
 * @param bold True if the font should be rendered in bold typeface
 * @param italic True if the font should be rendered in bold typeface
 */
private void initializeFont(Font baseFont, int size, boolean bold, boolean italic) {
	Map attributes = baseFont.getAttributes();
	attributes.put(TextAttribute.SIZE, new Float(size));
	attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR);
	attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR);
	try {
		attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField(
			"KERNING_ON").get(null));
	} catch (Exception ignored) {
	}
	font = baseFont.deriveFont(attributes);

	FontMetrics metrics = GlyphPage.getScratchGraphics().getFontMetrics(font);
	ascent = metrics.getAscent();
	descent = metrics.getDescent();
	leading = metrics.getLeading();
	
	// Determine width of space glyph (getGlyphPixelBounds gives a width of zero).
	char[] chars = " ".toCharArray();
	GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
	spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:31,代码来源:UnicodeFont.java

示例2: initModifiedFilesInfo

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Configure the text area which presents the informations about modified files.
 */
@SuppressWarnings("unchecked")
private void initModifiedFilesInfo() {
  StringBuilder text = new StringBuilder();
  text.append("(").append(modifiedResources.size()).append(")");
  text.append(" files were modified since ");
  Date date = new Date(reportFile.lastModified());
  SimpleDateFormat dataFormat = new SimpleDateFormat(DATE_FORMAT);
  text.append(dataFormat.format(date));
  modifiedFilesLabel.setText(text.toString());
  
  text.setLength(0);
  text.append("More details...");
  moreDetailsLabel.setText(text.toString());
  moreDetailsLabel.setToolTipText("Click to see the list of files which will be archived.");
  
  Font font = moreDetailsLabel.getFont();
  Map attributes = font.getAttributes();
  attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
  moreDetailsLabel.setFont(font.deriveFont(attributes));
}
 
开发者ID:oxygenxml,项目名称:oxygen-dita-translation-package-builder,代码行数:24,代码来源:GenerateArchivePackageDialog.java

示例3: marshal

import java.awt.Font; //导入方法依赖的package包/类
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    final Font font = (Font)source;
    final Map<TextAttribute, ?> attributes = font.getAttributes();
    if (mapper != null) {
        final String classAlias = mapper.aliasForSystemAttribute("class");
        for (final Map.Entry<TextAttribute, ?> entry : attributes.entrySet()) {
            final String name = textAttributeConverter.toString(entry.getKey());
            final Object value = entry.getValue();
            final Class<?> type = value != null ? value.getClass() : Mapper.Null.class;
            ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, type);
            writer.addAttribute(classAlias, mapper.serializedClass(type));
            if (value != null) {
                context.convertAnother(value);
            }
            writer.endNode();
        }
    } else {
        writer.startNode("attributes"); // <attributes>
        context.convertAnother(attributes);
        writer.endNode(); // </attributes>
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:FontConverter.java

示例4: TextLayout

import java.awt.Font; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:48,代码来源:TextLayout.java

示例5: TextLayout

import java.awt.Font; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:TextLayout.java

示例6: updateCharts

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Updates the charts.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateCharts() {
	for (int i = 0; i < listOfChartPanels.size(); i++) {
		JPanel panel = listOfChartPanels.get(i);
		panel.removeAll();
		final ChartPanel chartPanel = new ChartPanel(getModel().getChartOrNull(i)) {

			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();
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:53,代码来源:AttributeStatisticsPanel.java

示例7: instantiate

import java.awt.Font; //导入方法依赖的package包/类
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)});
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:56,代码来源:MetaData.java

示例8: LikeLink

import java.awt.Font; //导入方法依赖的package包/类
public void LikeLink() {
    Font font = getFont();
    Map attributes = font.getAttributes();
    attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    setFont(font.deriveFont(attributes));
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:7,代码来源:LabelNav.java


注:本文中的java.awt.Font.getAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。