List of usage examples for java.awt Font getFamily
public String getFamily()
From source file:Main.java
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = ge.getAllFonts(); for (Font font : fonts) { String fontName = font.getName(); String familyName = font.getFamily(); System.out.println("Font: " + fontName + "; family: " + familyName); }//from www.ja v a 2s.c om }
From source file:Main.java
public static void main(String[] args) { String HTMLTEXT = "<html><head><style>.foot{color:red} .head{color:black}</style></head>" + "<span style='font-family:consolas'>java2s.com</span><br/>" + "<span style='font-family:tahoma'>java2s.com</span>"; JTextPane textPane1 = new JTextPane(); textPane1.setContentType("text/html"); textPane1.setFont(new Font("courier new", Font.PLAIN, 32)); textPane1.setDocument(new HTMLDocument() { @Override//w ww. ja va 2 s . co m public Font getFont(AttributeSet attr) { StyleContext styles = (StyleContext) getAttributeContext(); Font f = styles.getFont(attr); String ff = f.getFamily(); System.out.println(ff); return textPane1.getFont(); } }); textPane1.setText(HTMLTEXT); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(textPane1)); f.setSize(320, 240); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:NwFontChooserS.java
static public String fontString(Font font) { String fs = font.getFamily(); if (!font.isPlain()) { fs += "-"; if (font.isBold()) { fs += "BOLD"; }//w w w . j a v a2 s . c o m if (font.isItalic()) { fs += "ITALIC"; } } fs += "-" + font.getSize(); return (fs); }
From source file:Main.java
public static String displayPropertiesToCSS(Font font, Color fg) { StringBuffer rule = new StringBuffer("body {"); if (font != null) { rule.append(" font-family: "); rule.append(font.getFamily()); rule.append(" ; "); rule.append(" font-size: "); rule.append(font.getSize());/*ww w.java2s. c om*/ rule.append("pt ;"); if (font.isBold()) { rule.append(" font-weight: 700 ; "); } if (font.isItalic()) { rule.append(" font-style: italic ; "); } } if (fg != null) { rule.append(" color: #"); if (fg.getRed() < 16) { rule.append('0'); } rule.append(Integer.toHexString(fg.getRed())); if (fg.getGreen() < 16) { rule.append('0'); } rule.append(Integer.toHexString(fg.getGreen())); if (fg.getBlue() < 16) { rule.append('0'); } rule.append(Integer.toHexString(fg.getBlue())); rule.append(" ; "); } rule.append(" }"); return rule.toString(); }
From source file:net.sf.texprinter.utils.UIUtils.java
/** * Set the label font to the editor. When the content type * is set to 'text/html', the plain visualization is very ugly, so this * method will set the default JLabel font to a JEditorPane. * * @param editor The editor. The CSS stylesheet will be added to it. * @param justify A flag representing full justification. If true, the * text will be fully justified./*from w w w. jav a2s . c om*/ */ public static void setDefaultFontToEditorPane(JEditorPane editor, boolean justify) { // get the system font Font font = UIManager.getFont("Label.font"); // set the body rule String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; margin-left: 0px; margin-top: 0px; " + (justify ? "text-align: justify;" : "") + " }"; // set the list rule String listRule = "ol { margin-left: 20px; list-style-type: square; }"; // add the body rule ((HTMLDocument) editor.getDocument()).getStyleSheet().addRule(bodyRule); // add the list rule ((HTMLDocument) editor.getDocument()).getStyleSheet().addRule(listRule); }
From source file:org.apache.pdfbox.pdmodel.font.FontManager.java
/** * Load all available fonts from the environment. *//*from w w w. j a va 2s.c om*/ private static void loadFonts() { for (Font font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()) { String family = normalizeFontname(font.getFamily()); String psname = normalizeFontname(font.getPSName()); if (isBoldItalic(font)) { envFonts.put(family + "bolditalic", font); } else if (isBold(font)) { envFonts.put(family + "bold", font); } else if (isItalic(font)) { envFonts.put(family + "italic", font); } else { envFonts.put(family, font); } if (!family.equals(psname)) { envFonts.put(normalizeFontname(font.getPSName()), font); } } }
From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java
public static void enableCapability(final JTextPane desc, Project project, String value, boolean editable, boolean navigation) { value = removeSmallFont(value);/*from w ww . j ava 2 s .c om*/ HTMLEditorKit kit = new HTMLLetterWrappingEditorKit(); desc.setEditorKit(kit); desc.setDocument(kit.createDefaultDocument()); if (!editable && navigation) { value = NavigationDecorator.explodeHtml(project, value); } desc.setText(value); if (!editable) { desc.setCaret(new NonAdjustingCaret()); } desc.addCaretListener(new BodyLimitCaretListener(desc)); if (editable) { String element = checkElements(desc.getDocument().getDefaultRootElement()); if (element != null) { desc.setToolTipText("Found unsupported element '" + element + "', editing is disabled."); editable = false; } } desc.setEditable(editable); if (editable && SpellCheckerManager.isAvailable() && ApplicationManager.getApplication().getComponent(AliConfiguration.class).spellChecker) { desc.getDocument().addDocumentListener(new SpellCheckDocumentListener(project, desc)); } Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(bodyRule); // AGM uses plain "p" to create lines, we need to avoid excessive spacing this by default creates String paragraphRule = "p { margin-top: 0px; }"; ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(paragraphRule); Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); new AnAction() { public void actionPerformed(AnActionEvent e) { // following is needed to make copy work in the IDE try { StringSelection selection = new StringSelection(desc.getText(desc.getSelectionStart(), desc.getSelectionEnd() - desc.getSelectionStart())); CopyPasteManager.getInstance().setContents(selection); } catch (Exception ex) { // no clipboard, so what } } }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_COPY)), desc); new AnAction() { public void actionPerformed(AnActionEvent e) { // avoid pasting non-supported HTML markup by always converting to plain text Transferable contents = CopyPasteManager.getInstance().getContents(); try { desc.getActionMap().get(DefaultEditorKit.cutAction).actionPerformed(null); desc.getDocument().insertString(desc.getSelectionStart(), (String) contents.getTransferData(DataFlavor.stringFlavor), null); } catch (Exception ex) { // no clipboard, so what } } }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_PASTE)), desc); installNavigationShortCuts(desc); }
From source file:pt.webdetails.cgg.scripts.BaseScope.java
private static Font decodeFont(String fontFamily, int fontStyle, int isize) { String fontStyleText = ""; switch (fontStyle) { case Font.BOLD: fontStyleText = "BOLD "; break;/* w w w. j a va 2 s .c o m*/ case Font.ITALIC: fontStyleText = "ITALIC "; break; case (Font.ITALIC | Font.BOLD): fontStyleText = "BOLDITALIC "; break; } String capFontFamily = fontFamily.substring(0, 1).toUpperCase() + fontFamily.substring(1, fontFamily.length()); Font ffont = Font.decode(capFontFamily + " " + fontStyleText + isize); if (ffont.getFamily().equals(Font.DIALOG) && !fontFamily.equals("dialog")) { // defaulted, try family GVTFontFamily awtFamily = FontFamilyResolver.resolve(fontFamily); if (awtFamily == null) { awtFamily = FontFamilyResolver.defaultFont; } ffont = new Font(awtFamily.getFamilyName(), fontStyle, isize); } return ffont; }
From source file:fxts.stations.util.UserPreferences.java
public static String getStringValue(Font aValue) { return clipFontFamily(aValue.getFamily()) + "," + aValue.getStyle() + "," + aValue.getSize(); }
From source file:org.spoutcraft.launcher.skin.ConsoleFrame.java
/** * Get a supported monospace font./*from w w w. j a v a 2s . co m*/ * * @return font */ public static Font getMonospaceFont() { for (String fontName : monospaceFontNames) { Font font = Font.decode(fontName + "-11"); if (!font.getFamily().equalsIgnoreCase("Dialog")) return font; } return new Font("Monospace", Font.PLAIN, 11); }