java.awt.Font#getName ( )源码实例Demo

下面列出了java.awt.Font#getName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jpexs-decompiler   文件: FontHelper.java
public static String fontToString(Font font) {
    int style = font.getStyle();
    String styleString;
    switch (style) {
        case 1:
            styleString = "Bold";
            break;
        case 2:
            styleString = "Italic";
            break;
        case 3:
            styleString = "BoldItalic";
            break;
        default:
            styleString = "Plain";
            break;
    }

    return font.getName() + "-" + styleString + "-" + font.getSize();
}
 
源代码2 项目: netbeans   文件: HintArea.java
@Override
public void setText(String value) {
    if (value == null) {
        return;
    }

    Font font = getFont();
    Color textColor = getForeground();
    value = value.replaceAll("\\n\\r|\\r\\n|\\n|\\r", "<br>"); // NOI18N
    value = value.replace("<code>", "<code style=\"font-size: " + font.getSize() + "pt;\">"); // NOI18N

    String colorText = "rgb(" + textColor.getRed() + "," + textColor.getGreen() + "," + textColor.getBlue() + ")"; // NOI18N
    String newText = "<html><body style=\"color: " + colorText + "; font-size: " + font.getSize()  // NOI18N
            + "pt; font-family: " + font.getName() + ";\">" + value + "</body></html>"; // NOI18N

    setDocument(getEditorKit().createDefaultDocument()); // Workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5042872
    super.setText(newText);
}
 
源代码3 项目: osp   文件: TextLine.java
/**
 * Instantiate the class
 * @param f Font to use.
 * @param c Color to use
 * @param j Justification
 */
public TextLine(Font f, Color c, int j) {
  font = f;
  color = c;
  justification = j;
  if(font==null) {
    return;
  }
  fontname = f.getName();
  fontstyle = f.getStyle();
  fontsize = f.getSize();
}
 
源代码4 项目: netbeans   文件: ComponentLine.java
private Font createFont(Font attrFont, Font defaultFont) {
    if ( !Config.getDefault().isUseFont()) {
        return defaultFont;
    }
    String name = defaultFont.getName();
    int size = defaultFont.getSize();
    int style = attrFont.getStyle();
    return new Font(name, style, size);
}
 
源代码5 项目: netbeans   文件: ComponentLine.java
private String getString(Font font) {
    String style = ""; // NOI18N

    if (font.isBold()) {
        style += "bold"; // NOI18N
    }
    if (font.isItalic()) {
        style += " italic"; // NOI18N
    }
    else {
        style += " plain"; // NOI18N
    }
    return "[" + font.getName() + ", " + style + ", " + font.getSize() + "]"; // NOI18N
}
 
源代码6 项目: orbit-image-analysis   文件: BasicFontChooserUI.java
private void updateSelectedFont() {
  Font currentFont = chooser.getSelectedFont();
  String fontFamily =
    currentFont == null ? "SansSerif" : currentFont.getName();
  int fontSize = currentFont == null ? 11 : currentFont.getSize();

  if (fontList.getSelectedIndex() >= 0) {
    fontFamily = (String)fontList.getSelectedValue();
  }

  if (fontSizeField.getText().trim().length() > 0) {
    try {
      fontSize = Integer.parseInt(fontSizeField.getText().trim());
    } catch (Exception e) {
      // ignore the NumberFormatException
    }
  }

  Map attributes = new HashMap();
  attributes.put(TextAttribute.SIZE, new Float(fontSize));
  attributes.put(TextAttribute.FAMILY, fontFamily);
  if (boldCheck.isSelected()) {
    attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
  }
  if (italicCheck.isSelected()) {
    attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
  }

  Font font = Font.getFont(attributes);
  if (!font.equals(currentFont)) {
    chooser.setSelectedFont(font);
    previewPanel.setFont(font);
  }
}
 
源代码7 项目: astor   文件: FontChooserPanel.java
/**
 * Initializes the contents of the dialog from the given font
 * object.
 *
 * @param font the font from which to read the properties.
 */
public void setSelectedFont( Font font) {
    if (font == null) {
        throw new NullPointerException();
    }
    this.bold.setSelected(font.isBold());
    this.italic.setSelected(font.isItalic());

    String fontName = font.getName();
    ListModel model = this.fontlist.getModel();
    this.fontlist.clearSelection();
    for (int i = 0; i < model.getSize(); i++) {
        if (fontName.equals(model.getElementAt(i))) {
            this.fontlist.setSelectedIndex(i);
            break;
        }
    }

    String fontSize = String.valueOf(font.getSize());
    model = this.sizelist.getModel();
    this.sizelist.clearSelection();
    for (int i = 0; i < model.getSize(); i++) {
        if (fontSize.equals(model.getElementAt(i))) {
            this.sizelist.setSelectedIndex(i);
            break;
        }
    }
}
 
源代码8 项目: netbeans   文件: HTMLLabel.java
public void setText(String value) {
    txt = value;
    
    Font font = getFont();
    Color fgColor = getForeground();
    Color bgColor = getBackground();
    
    value = value.replaceAll("\\n\\r|\\r\\n|\\n|\\r", "<br>"); //NOI18N
    value = value.replace("<code>", "<code style=\"font-size: " + font.getSize() + "pt;\">"); //NOI18N
    
    String fgText = "rgb(" + fgColor.getRed() + "," + fgColor.getGreen() + "," + fgColor.getBlue() + ")"; //NOI18N
    String bgText = isOpaque() ? "rgb(" + bgColor.getRed() + "," + bgColor.getGreen() + "," + bgColor.getBlue() + ")" : null; //NOI18N
    
    String alignText = null;
    switch (halign) {
        case SwingConstants.CENTER:
            alignText = "center"; //NOI18N
            break;
        case SwingConstants.RIGHT:
        case SwingConstants.TRAILING:
            alignText = "right"; //NOI18N
            break;
    }
    
    String bodyFlags = "text=\"" + fgText + "\""; //NOI18N
    if (bgText != null) bodyFlags += " bgcolor=\"" + bgText + "\""; //NOI18N
    if (alignText != null) bodyFlags += " align=\"" + alignText + "\""; //NOI18N
    
    super.setText("<html><body " + bodyFlags + " style=\"font-size: " + font.getSize() //NOI18N
                  + "pt; font-family: " + font.getName() + ";\">" + value + "</body></html>"); //NOI18N
}
 
/**
 * Checks to see if the object is an instance of <code>java.awt.Font</code>, 
 * and in case it is, it replaces it with the one looked up for in the font extensions.
 */
@Override
protected Object resolveObject(Object obj) throws IOException
{
	Font font = (obj instanceof Font) ? (Font)obj : null;
	
	if (font != null)
	{
		// We use the font.getName() method here because the name field in the java.awt.Font class is the only font name related information that gets serialized,
		// along with the size and style. The font.getFontName() and font.getFamily() both return runtime calculated values, which are not accurate in case of AWT fonts
		// created at runtime through font extensions (both seem to return 'Dialog').
		// For AWT fonts created from font extensions using the Font.createFont(int, InputStream), the name field is set to the same value as the font.getFontName(),
		// which is the recommended method to get the name of an AWT font.
		String fontName = font.getName();
		// We load an instance of an AWT font, even if the specified font name is not available (ignoreMissingFont=true),
		// because only third-party visualization packages such as JFreeChart (chart themes) store serialized java.awt.Font objects,
		// and they are responsible for the drawing as well.
		// Here we rely on the utility method ability to find a font by face name, not only family name. This is because font.getName() above returns an AWT font name,
		// not a font family name.
		Font newFont = FontUtil.getInstance(jasperReportsContext).getAwtFontFromBundles(fontName, font.getStyle(), font.getSize2D(), null, true);
		
		if (newFont != null)
		{
			return newFont.deriveFont(font.getAttributes());
		}
	}
	
	return obj;
}
 
源代码10 项目: netbeans   文件: Coloring.java
/** Modify the given font according to the font-mode */
private Font modifyFont(Font f) {
    return new Font(
               ((fontMode & FONT_MODE_APPLY_NAME) != 0) ? font.getName() : f.getName(),
               ((fontMode & FONT_MODE_APPLY_STYLE) != 0) ? font.getStyle() : f.getStyle(),
               ((fontMode & FONT_MODE_APPLY_SIZE) != 0) ? font.getSize() : f.getSize()
           );
}
 
源代码11 项目: tn5250j   文件: BasicTerminalUI.java
private void initFontMap(Font f)
{
  if (f == null)
  {
    this.widthMap = null;
    this.heightMap = null;
    return;
  }

  this.widthMap  = new int[MAX_POINT*2];
  this.heightMap = new int[MAX_POINT*2];

  this.fontName  = f.getName();
  this.fontStyle = f.getStyle();

  for (int i = 4, j = 0, tw = 0, th = 0; i < MAX_POINT; i++)
  {
    //Font        workFont = f.deriveFont((float)i);
    Font        workFont = new Font(this.fontName, this.fontStyle, i);
    FontMetrics metrics  = terminal.getFontMetrics(workFont);

    int         w        = metrics.charWidth('W');
    int         h        = metrics.getHeight();
    //int         h        = metrics.getAscent() + metrics.getDescent();

    this.widthMap[j] = w;
    this.widthMap[j+1] = i;
    this.heightMap[j] = h;
    this.heightMap[j+1] = i;

    if ( (tw == w) && (th == h) )
      break;

    tw = w;
    th = h;
    j += 2;
  }
}
 
源代码12 项目: pentaho-reporting   文件: FontValueConverter.java
/**
 * Converts an object to an attribute value.
 *
 * @param o
 *          the object.
 * @return the attribute value.
 * @throws BeanException
 *           if there was an error during the conversion.
 */
public String toAttributeValue( final Object o ) throws BeanException {
  if ( o == null ) {
    throw new NullPointerException();
  }
  if ( o instanceof Font == false ) {
    throw new BeanException( "Failed to convert object of type " + o.getClass() + ": Not a Font." );
  }
  final Font font = (Font) o;
  final int fontSize = font.getSize();
  final String fontName = font.getName();
  final int fontStyle = font.getStyle();

  return fontName + '-' + styleToString( fontStyle ) + '-' + fontSize;
}
 
protected Object configureValue(Object value) {
    if (value instanceof Font) {
        Font font = (Font)value;
        if ("MS Sans Serif".equals(font.getName())) {
            int size = font.getSize();
            // 4950968: Workaround to mimic the way Windows maps the default
            // font size of 6 pts to the smallest available bitmap font size.
            // This happens mostly on Win 98/Me & NT.
            int dpi;
            try {
                dpi = Toolkit.getDefaultToolkit().getScreenResolution();
            } catch (HeadlessException ex) {
                dpi = 96;
            }
            if (Math.round(size * 72F / dpi) < 8) {
                size = Math.round(8 * dpi / 72F);
            }
            Font msFont = new FontUIResource("Microsoft Sans Serif",
                                  font.getStyle(), size);
            if (msFont.getName() != null &&
                msFont.getName().equals(msFont.getFamily())) {
                font = msFont;
            } else if (size != font.getSize()) {
                font = new FontUIResource("MS Sans Serif",
                                          font.getStyle(), size);
            }
        }

        if (FontUtilities.fontSupportsDefaultEncoding(font)) {
            if (!(font instanceof UIResource)) {
                font = new FontUIResource(font);
            }
        }
        else {
            font = FontUtilities.getCompositeFontUIResource(font);
        }
        return font;

    }
    return super.configureValue(value);
}
 
源代码14 项目: lams   文件: StaticFontMetrics.java
/**
 * Retrieves the fake font details for a given font.
 *
 * @param font
 *            the font to lookup.
 * @return the fake font.
 */
public static synchronized FontDetails getFontDetails(Font font) {
	// If we haven't already identified out font metrics file,
	// figure out which one to use and load it
	if (fontMetricsProps == null) {
	    try {
	        fontMetricsProps = loadMetrics();
	    } catch (IOException e) {
	        throw new RuntimeException("Could not load font metrics", e);
	    }
	}

	// Grab the base name of the font they've asked about
	String fontName = font.getName();

	// Some fonts support plain/bold/italic/bolditalic variants
	// Others have different font instances for bold etc
	// (eg font.dialog.plain.* vs font.Californian FB Bold.*)
	String fontStyle = "";
	if (font.isPlain()) {
		fontStyle += "plain";
	}
	if (font.isBold()) {
		fontStyle += "bold";
	}
	if (font.isItalic()) {
		fontStyle += "italic";
	}

	// Do we have a definition for this font with just the name?
	// If not, check with the font style added
	String fontHeight = FontDetails.buildFontHeightProperty(fontName);
	String styleHeight = FontDetails.buildFontHeightProperty(fontName + "." + fontStyle);
	
	if (fontMetricsProps.get(fontHeight) == null
		&& fontMetricsProps.get(styleHeight) != null) {
		// Need to add on the style to the font name
		fontName += "." + fontStyle;
	}

	// Get the details on this font
	FontDetails fontDetails = fontDetailsMap.get(fontName);
	if (fontDetails == null) {
		fontDetails = FontDetails.create(fontName, fontMetricsProps);
		fontDetailsMap.put(fontName, fontDetails);
	}
       return fontDetails;
}
 
源代码15 项目: TencentKona-8   文件: WindowsLookAndFeel.java
protected Object configureValue(Object value) {
    if (value instanceof Font) {
        Font font = (Font)value;
        if ("MS Sans Serif".equals(font.getName())) {
            int size = font.getSize();
            // 4950968: Workaround to mimic the way Windows maps the default
            // font size of 6 pts to the smallest available bitmap font size.
            // This happens mostly on Win 98/Me & NT.
            int dpi;
            try {
                dpi = Toolkit.getDefaultToolkit().getScreenResolution();
            } catch (HeadlessException ex) {
                dpi = 96;
            }
            if (Math.round(size * 72F / dpi) < 8) {
                size = Math.round(8 * dpi / 72F);
            }
            Font msFont = new FontUIResource("Microsoft Sans Serif",
                                  font.getStyle(), size);
            if (msFont.getName() != null &&
                msFont.getName().equals(msFont.getFamily())) {
                font = msFont;
            } else if (size != font.getSize()) {
                font = new FontUIResource("MS Sans Serif",
                                          font.getStyle(), size);
            }
        }

        if (FontUtilities.fontSupportsDefaultEncoding(font)) {
            if (!(font instanceof UIResource)) {
                font = new FontUIResource(font);
            }
        }
        else {
            font = FontUtilities.getCompositeFontUIResource(font);
        }
        return font;

    }
    return super.configureValue(value);
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: WindowsLookAndFeel.java
protected Object configureValue(Object value) {
    if (value instanceof Font) {
        Font font = (Font)value;
        if ("MS Sans Serif".equals(font.getName())) {
            int size = font.getSize();
            // 4950968: Workaround to mimic the way Windows maps the default
            // font size of 6 pts to the smallest available bitmap font size.
            // This happens mostly on Win 98/Me & NT.
            int dpi;
            try {
                dpi = Toolkit.getDefaultToolkit().getScreenResolution();
            } catch (HeadlessException ex) {
                dpi = 96;
            }
            if (Math.round(size * 72F / dpi) < 8) {
                size = Math.round(8 * dpi / 72F);
            }
            Font msFont = new FontUIResource("Microsoft Sans Serif",
                                  font.getStyle(), size);
            if (msFont.getName() != null &&
                msFont.getName().equals(msFont.getFamily())) {
                font = msFont;
            } else if (size != font.getSize()) {
                font = new FontUIResource("MS Sans Serif",
                                          font.getStyle(), size);
            }
        }

        if (FontUtilities.fontSupportsDefaultEncoding(font)) {
            if (!(font instanceof UIResource)) {
                font = new FontUIResource(font);
            }
        }
        else {
            font = FontUtilities.getCompositeFontUIResource(font);
        }
        return font;

    }
    return super.configureValue(value);
}
 
源代码17 项目: Course_Generator   文件: MapObjectImpl.java
public static Font getDefaultFont() {
	Font f = UIManager.getDefaults().getFont("TextField.font");
	return new Font(f.getName(), Font.BOLD, f.getSize());
}
 
源代码18 项目: openjdk-jdk8u   文件: WindowsLookAndFeel.java
protected Object configureValue(Object value) {
    if (value instanceof Font) {
        Font font = (Font)value;
        if ("MS Sans Serif".equals(font.getName())) {
            int size = font.getSize();
            // 4950968: Workaround to mimic the way Windows maps the default
            // font size of 6 pts to the smallest available bitmap font size.
            // This happens mostly on Win 98/Me & NT.
            int dpi;
            try {
                dpi = Toolkit.getDefaultToolkit().getScreenResolution();
            } catch (HeadlessException ex) {
                dpi = 96;
            }
            if (Math.round(size * 72F / dpi) < 8) {
                size = Math.round(8 * dpi / 72F);
            }
            Font msFont = new FontUIResource("Microsoft Sans Serif",
                                  font.getStyle(), size);
            if (msFont.getName() != null &&
                msFont.getName().equals(msFont.getFamily())) {
                font = msFont;
            } else if (size != font.getSize()) {
                font = new FontUIResource("MS Sans Serif",
                                          font.getStyle(), size);
            }
        }

        if (FontUtilities.fontSupportsDefaultEncoding(font)) {
            if (!(font instanceof UIResource)) {
                font = new FontUIResource(font);
            }
        }
        else {
            font = FontUtilities.getCompositeFontUIResource(font);
        }
        return font;

    }
    return super.configureValue(value);
}
 
源代码19 项目: MtgDesktopCompanion   文件: JTagsPanel.java
public void setFontSize(int s) {
	componentFont = new Font(componentFont.getName(), componentFont.getStyle(), s);
}
 
源代码20 项目: brModelo   文件: Elementar.java
public static Font CloneFont(Font origem) {
    return new Font(origem.getName(), origem.getStyle(), origem.getSize());
}