Java Code Examples for java.awt.Font#getFamily()
The following examples show how to use
java.awt.Font#getFamily() .
These examples are extracted from open source projects.
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 Project: gcs File: MarkdownDocument.java License: Mozilla Public License 2.0 | 6 votes |
private Style[] createHeaderStyles(Font font) { String family = font.getFamily(); int size = font.getSize(); int[] sizes = {size * 2, size * 3 / 2, size * 5 / 4, size, size * 7 / 8}; int count = sizes.length; Style[] styles = new Style[count]; for (int i = 0; i < count; i++) { Style h = addStyle("h" + (i + 1), null); h.addAttribute(StyleConstants.FontFamily, family); h.addAttribute(StyleConstants.FontSize, Integer.valueOf(sizes[i])); h.addAttribute(StyleConstants.Bold, Boolean.TRUE); h.addAttribute(StyleConstants.SpaceBelow, Float.valueOf(sizes[i] / 2.0f)); styles[i] = h; } return styles; }
Example 2
Source Project: openjdk-jdk9 File: AppleFontNameTest.java License: GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String os = System.getProperty("os.name"); if (!(os.startsWith("Mac"))) { return; } File fontFile = new File(file); if (!fontFile.exists()) { return; } Font[] fonts = Font.createFonts(new File(file)); System.out.println("createFont from file returned " + fonts); if (fonts == null || fonts.length == 0) { throw new RuntimeException("No fonts"); } for (Font f : fonts) { System.out.println(f); if (!f.getFamily().equals("Menlo")) throw new RuntimeException("Expected Menlo, got " + f.getFamily()); } }
Example 3
Source Project: DominionSim File: DomGameFrame.java License: MIT License | 6 votes |
private JPanel getLogPanel() { JPanel theLogPanel = new JPanel(); theLogPanel.setLayout(new BorderLayout()); myLogPane = new JTextPane(); myLogPane.setPreferredSize(new Dimension(400,300)); editorKit = new HTMLEditorKit(); gameLog = (HTMLDocument) editorKit.createDefaultDocument();; myLogPane.setEditorKit(editorKit); myLogPane.setDocument(gameLog); myLogScroll = new JScrollPane(myLogPane); myLogScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); // theScrollPane.setPreferredSize(new Dimension(400,400)); theLogPanel.add(myLogScroll,BorderLayout.CENTER); Font font = new Font("Times New Roman", Font.PLAIN, 14); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument)myLogPane.getDocument()).getStyleSheet().addRule(bodyRule);// myLogPane.revalidate(); return theLogPanel; }
Example 4
Source Project: netbeans File: MissingClientPanel.java License: Apache License 2.0 | 6 votes |
/** Creates new form MissingClientPanel */ public MissingClientPanel() { initComponents(); if(Utilities.isWindows()) { tipLabel.setText(org.openide.util.NbBundle.getMessage(MissingClientPanel.class, "MissingSvnClientPanel.jLabel1.windows.text")); // NOI18N } else { tipLabel.setText(org.openide.util.NbBundle.getMessage(MissingClientPanel.class, "MissingSvnClientPanel.jLabel1.unix.text")); // NOI18N } String text = org.openide.util.NbBundle.getMessage(MissingClientPanel.class, "MissingClientPanel.textPane.text"); // NOI18N textPane.setText(text); Document doc = textPane.getDocument(); if (doc instanceof HTMLDocument) { // Issue 185505 HTMLDocument htmlDoc = (HTMLDocument)doc; Font font = UIManager.getFont("Label.font"); // NOI18N String bodyRule = "body { font-family: " + font.getFamily() + "; " // NOI18N + "color: " + SvnUtils.getColorString(textPane.getForeground()) + "; " //NOI18N + "font-size: " + font.getSize() + "pt; }"; // NOI18N htmlDoc.getStyleSheet().addRule(bodyRule); } textPane.setOpaque(false); textPane.setBackground(new Color(0,0,0,0)); // windows and nimbus workaround see issue 145826 }
Example 5
Source Project: gate-core File: JTextPaneTableCellRenderer.java License: GNU Lesser General Public License v3.0 | 6 votes |
public JTextPaneTableCellRenderer() { textPane.setContentType("text/html"); textPane.setEditable(false); textPane.setOpaque(true); textPane.setBorder(null); textPane.setForeground(UIManager.getColor("Table.selectionForeground")); textPane.setBackground(UIManager.getColor("Table.selectionBackground")); Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; " + (font.isBold() ? "font-weight: bold;" : "") + "}"; ((HTMLDocument)textPane.getDocument()).getStyleSheet().addRule(bodyRule); textPane.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) MainFrame.getInstance().showHelpFrame(e.getURL().toString(), "CREOLE Plugin Manager"); } }); }
Example 6
Source Project: jclic File: FontCheck.java License: GNU General Public License v2.0 | 5 votes |
public static String getValidFontFamilyName(Object family) { Font f = systemFonts.get(family instanceof String ? ((String) family).toLowerCase() : family); if (f != null) { return f.getFamily(); } return checkFontFamilyName(family) ? (String) family : DEFAULT_FONT_NAME; }
Example 7
Source Project: dragonwell8_jdk File: DebugFonts.java License: GNU General Public License v2.0 | 5 votes |
public static void main(String [] args) { System.setProperty("sun.java2d.debugfonts", "true"); Font font = new Font("dialog", Font.PLAIN, 14); System.out.println(font); String s1 = font.getFamily(); String s2 = font.getFontName(); }
Example 8
Source Project: jdk8u60 File: DebugFonts.java License: GNU General Public License v2.0 | 5 votes |
public static void main(String [] args) { System.setProperty("sun.java2d.debugfonts", "true"); Font font = new Font("dialog", Font.PLAIN, 14); System.out.println(font); String s1 = font.getFamily(); String s2 = font.getFontName(); }
Example 9
Source Project: openjdk-jdk8u File: DebugFonts.java License: GNU General Public License v2.0 | 5 votes |
public static void main(String [] args) { System.setProperty("sun.java2d.debugfonts", "true"); Font font = new Font("dialog", Font.PLAIN, 14); System.out.println(font); String s1 = font.getFamily(); String s2 = font.getFontName(); }
Example 10
Source Project: i18n-editor File: Dialogs.java License: MIT License | 5 votes |
public static void showHtmlDialog(Component parent, String title, String body) { Font font = parent.getFont(); JHtmlPane pane = new JHtmlPane(parent, "<html><body style=\"font-family:" + font.getFamily() + ";text-align:center;\">" + body + "</body></html>"); pane.setBorder(BorderFactory.createEmptyBorder(15,15,15,15)); showComponentDialog(parent, title, pane); }
Example 11
Source Project: ontopia File: TypesConfigFrame.java License: Apache License 2.0 | 5 votes |
/** * Build a new font object from the GUI and assign it */ protected void buildAndSetFont() { if (typeList.getSelectedValue() == null) return; // We need @ignoreSelection since we cannot set the current // font without signalling the font changes callbacks if (ignoreSelection) return; String name = (String) fontList.getSelectedValue(); String sizeString = (String) sizeList.getSelectedValue(); boolean isBold = bold.isSelected(); boolean isItalic = italic.isSelected(); if (name == null || sizeString == null) { Font fallbackFont = controller.getTypeFont(selectedType); if (name == null && sizeString == null && !isBold) isBold = fallbackFont.isBold(); if (name == null && sizeString == null && !isItalic) isItalic = fallbackFont.isItalic(); if (name == null) { name = fallbackFont.getFamily(); fontList.setSelectedValue(name, true); } if (sizeString == null) { sizeString = Integer.toString(fallbackFont.getSize()); sizeList.setSelectedValue(sizeString, true); } } int style = Font.PLAIN; if (isBold) style = style | Font.BOLD; if (isItalic) style = style | Font.ITALIC; controller.setTypeFont(selectedType, new Font(name, style, Integer .parseInt(sizeString))); }
Example 12
Source Project: jdk8u_jdk File: FontGlyphCompare.java License: GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { String osName = System.getProperty("os.name"); System.out.println("OS is " + osName); osName = osName.toLowerCase(); if (!osName.startsWith("windows")) { return; } Font msMincho = new Font("MS Mincho", Font.PLAIN, 16); String family = msMincho.getFamily(java.util.Locale.ENGLISH); if (!family.equalsIgnoreCase("MS Mincho")) { System.out.println("Japanese fonts not installed"); return; } String s = "|"; BufferedImage bi1 = getFontImage(new Font("MS Mincho", Font.PLAIN, 16), s); int h1 = bi1.getHeight(); int w1 = bi1.getWidth(); BufferedImage bi2 = getFontImage(new Font("MS Mincho", Font.ITALIC, 16), s); int h2 = bi2.getHeight(); int w2 = bi2.getWidth(); if ((h1 == h2) && (w1 == w2)) { int cnt = 0; for(int yy = 0; yy < h1; yy++) { for(int xx = 0; xx < w1; xx++) { if (bi1.getRGB(xx, yy) != bi2.getRGB(xx, yy)) { cnt++; } } } if (cnt == 0) { throw new Exception("Test failed"); } } }
Example 13
Source Project: netbeans File: NotifyHtmlPanel.java License: Apache License 2.0 | 5 votes |
/** * Creates new form SwitchToCliPanel */ public NotifyHtmlPanel () { initComponents(); Document doc = msgPanel.getDocument(); if (doc instanceof HTMLDocument) { // Issue 185505 HTMLDocument htmlDoc = (HTMLDocument)doc; Font font = UIManager.getFont("Label.font"); // NOI18N String bodyRule = "body { font-family: " + font.getFamily() + "; " // NOI18N + "color: " + SvnUtils.getColorString(msgPanel.getForeground()) + "; " //NOI18N + "font-size: " + font.getSize() + "pt; }"; // NOI18N htmlDoc.getStyleSheet().addRule(bodyRule); } msgPanel.setOpaque(false); msgPanel.setBackground(new Color(0,0,0,0)); // windows and nimbus workaround see issue 145826 }
Example 14
Source Project: netbeans File: TermOptions.java License: Apache License 2.0 | 5 votes |
public void setFontSize(int fontSize) { this.fontSize = fontSize; // recalculate font as well. font = new Font(font.getFamily(), font.getStyle(), this.fontSize); markDirty(); }
Example 15
Source Project: rapidminer-studio File: InjectedParameterPlaceholderLabel.java License: GNU Affero General Public License v3.0 | 5 votes |
public InjectedParameterPlaceholderLabel(ConnectionParameterModel param) { super(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); JLabel icon = new JLabel("", INJECTED_ICON, JLabel.LEFT); add(icon, gbc); Font font = icon.getFont(); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); editorPane.setOpaque(false); editorPane.setBorder(null); editorPane.setEditable(false); editorPane.addHyperlinkListener(event -> { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getURL() != null) { RMUrlHandler.openInBrowser(event.getURL()); } }); gbc.insets.left = icon.getIconTextGap(); gbc.weightx = 1; gbc.fill = GridBagConstraints.HORIZONTAL; add(editorPane, gbc); valueProviderChanged = (i, o, n) -> updateText(param); valueProviderParameterChanged = c -> { while (c.next()) { for (ValueProviderParameterModel valueProviderParameterModel : c.getAddedSubList()) { valueProviderParameterModel.valueProperty().removeListener(valueProviderChanged); valueProviderParameterModel.valueProperty().addListener(valueProviderChanged); } } updateText(param); }; param.injectorNameProperty().addListener((i, o, n) -> registerListener(param)); registerListener(param); }
Example 16
Source Project: jpexs-decompiler File: TagInfoPanel.java License: GNU General Public License v3.0 | 4 votes |
private void buildHtmlContent() { String categoryName = "general"; String result = "<html><body><table cellspacing='0' cellpadding='0'>"; Boolean flipFlop = false; List<TagInfo.TagInfoItem> items = tagInfo.getInfos().get(categoryName); result += "<tr bgcolor='#FDFDFD'>"; result += "<td width='50%' style='text-align:center;'>"; result += mainPanel.translate("tagInfo.header.name"); result += "</td>"; result += "<td width='50%' style='text-align:center;'>"; result += mainPanel.translate("tagInfo.header.value"); result += "</td>"; result += "</tr>"; for (TagInfo.TagInfoItem item : items) { Boolean convertToCharacterList; flipFlop = !flipFlop; result += "<tr bgcolor='" + (flipFlop ? "#FDFDFD" : "#F4F4F4") + "'>"; String name = item.getName(); String key = "tagInfo." + name; convertToCharacterList = name.equals("dependentCharacters") || name.equals("neededCharacters"); try { name = mainPanel.translate(key); } catch (MissingResourceException mes) { if (Configuration._debugMode.get()) { Logger.getLogger(TagInfoPanel.class.getName()).log(Level.WARNING, "Resource not found: {0}", key); } } result += "<td>" + name + "</td>"; Object value = item.getValue(); if (value instanceof Boolean) { boolean boolValue = (boolean) value; value = boolValue ? AppStrings.translate("yes") : AppStrings.translate("no"); } else if (convertToCharacterList) { String strValue = (String) value; String[] strIds = strValue.split(", "); List<Integer> sortedIds = new ArrayList<>(); strValue = ""; for (String strId : strIds) { sortedIds.add(Integer.parseInt(strId)); } Collections.sort(sortedIds); for (int id : sortedIds) { strValue += "<a href='jump://" + id + "'>" + id + "</a>, "; } value = strValue.substring(0, strValue.length() - 2); } result += "<td>" + value + "</td>"; result += "</tr>"; } result += "</table></body></html>"; editorPane.setText(result); Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + ";" + " font-size: " + font.getSize() + "pt;" + "}" + " table {" + " width:100%;" + " color:#053E6A;" + " padding:1px;" + "}" + "td { border: 1px solid #e4e4e4; }" + "html { border: 1px solid #789AC4; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); editorPane.setOpaque(false); editorPane.setBorder(null); editorPane.setEditable(false); }
Example 17
Source Project: Logisim File: Attributes.java License: GNU General Public License v3.0 | 4 votes |
@Override public String toStandardString(Font f) { return f.getFamily() + " " + FontUtil.toStyleStandardString(f.getStyle()) + " " + f.getSize(); }
Example 18
Source Project: dss File: PdfBoxFontMapper.java License: GNU Lesser General Public License v2.1 | 4 votes |
public static PDType1Font getPDFont(Font javaFont) { switch (javaFont.getFamily()) { case Font.SERIF: if (javaFont.isPlain()) { return PDType1Font.TIMES_ROMAN; } else if (javaFont.isBold()) { if (javaFont.isItalic()) { return PDType1Font.TIMES_BOLD_ITALIC; } else { return PDType1Font.TIMES_BOLD; } } else { return PDType1Font.TIMES_ITALIC; } case Font.SANS_SERIF: if (javaFont.isPlain()) { return PDType1Font.HELVETICA; } else if (javaFont.isBold()) { if (javaFont.isItalic()) { return PDType1Font.HELVETICA_BOLD_OBLIQUE; } else { return PDType1Font.HELVETICA_BOLD; } } else { return PDType1Font.HELVETICA_OBLIQUE; } case Font.MONOSPACED: if (javaFont.isPlain()) { return PDType1Font.COURIER; } else if (javaFont.isBold()) { if (javaFont.isItalic()) { return PDType1Font.COURIER_BOLD_OBLIQUE; } else { return PDType1Font.COURIER_BOLD; } } else { return PDType1Font.COURIER_OBLIQUE; } case Font.DIALOG: case Font.DIALOG_INPUT: return PDType1Font.SYMBOL; default: throw new DSSException("The font is not supported! Please use DSSFileFont implementation for custom fonts."); } }
Example 19
Source Project: jdk8u60 File: SunFontManager.java License: GNU General Public License v2.0 | 4 votes |
public boolean registerFont(Font font) { /* This method should not be called with "null". * It is the caller's responsibility to ensure that. */ if (font == null) { return false; } /* Initialise these objects only once we start to use this API */ synchronized (regFamilyKey) { if (createdByFamilyName == null) { createdByFamilyName = new Hashtable<String,FontFamily>(); createdByFullName = new Hashtable<String,Font2D>(); } } if (! FontAccess.getFontAccess().isCreatedFont(font)) { return false; } /* We want to ensure that this font cannot override existing * installed fonts. Check these conditions : * - family name is not that of an installed font * - full name is not that of an installed font * - family name is not the same as the full name of an installed font * - full name is not the same as the family name of an installed font * The last two of these may initially look odd but the reason is * that (unfortunately) Font constructors do not distinuguish these. * An extreme example of such a problem would be a font which has * family name "Dialog.Plain" and full name of "Dialog". * The one arguably overly stringent restriction here is that if an * application wants to supply a new member of an existing family * It will get rejected. But since the JRE can perform synthetic * styling in many cases its not necessary. * We don't apply the same logic to registered fonts. If apps want * to do this lets assume they have a reason. It won't cause problems * except for themselves. */ HashSet<String> names = getInstalledNames(); Locale l = getSystemStartupLocale(); String familyName = font.getFamily(l).toLowerCase(); String fullName = font.getFontName(l).toLowerCase(); if (names.contains(familyName) || names.contains(fullName)) { return false; } /* Checks passed, now register the font */ Hashtable<String,FontFamily> familyTable; Hashtable<String,Font2D> fullNameTable; if (!maybeMultiAppContext()) { familyTable = createdByFamilyName; fullNameTable = createdByFullName; fontsAreRegistered = true; } else { AppContext appContext = AppContext.getAppContext(); familyTable = (Hashtable<String,FontFamily>)appContext.get(regFamilyKey); fullNameTable = (Hashtable<String,Font2D>)appContext.get(regFullNameKey); if (familyTable == null) { familyTable = new Hashtable<String,FontFamily>(); fullNameTable = new Hashtable<String,Font2D>(); appContext.put(regFamilyKey, familyTable); appContext.put(regFullNameKey, fullNameTable); } fontsAreRegisteredPerAppContext = true; } /* Create the FontFamily and add font to the tables */ Font2D font2D = FontUtilities.getFont2D(font); int style = font2D.getStyle(); FontFamily family = familyTable.get(familyName); if (family == null) { family = new FontFamily(font.getFamily(l)); familyTable.put(familyName, family); } /* Remove name cache entries if not using app contexts. * To accommodate a case where code may have registered first a plain * family member and then used it and is now registering a bold family * member, we need to remove all members of the family, so that the * new style can get picked up rather than continuing to synthesise. */ if (fontsAreRegistered) { removeFromCache(family.getFont(Font.PLAIN)); removeFromCache(family.getFont(Font.BOLD)); removeFromCache(family.getFont(Font.ITALIC)); removeFromCache(family.getFont(Font.BOLD|Font.ITALIC)); removeFromCache(fullNameTable.get(fullName)); } family.setFont(font2D, style); fullNameTable.put(fullName, font2D); return true; }
Example 20
Source Project: openjdk-jdk8u File: SunFontManager.java License: GNU General Public License v2.0 | 4 votes |
public boolean registerFont(Font font) { /* This method should not be called with "null". * It is the caller's responsibility to ensure that. */ if (font == null) { return false; } /* Initialise these objects only once we start to use this API */ synchronized (regFamilyKey) { if (createdByFamilyName == null) { createdByFamilyName = new Hashtable<String,FontFamily>(); createdByFullName = new Hashtable<String,Font2D>(); } } if (! FontAccess.getFontAccess().isCreatedFont(font)) { return false; } /* We want to ensure that this font cannot override existing * installed fonts. Check these conditions : * - family name is not that of an installed font * - full name is not that of an installed font * - family name is not the same as the full name of an installed font * - full name is not the same as the family name of an installed font * The last two of these may initially look odd but the reason is * that (unfortunately) Font constructors do not distinuguish these. * An extreme example of such a problem would be a font which has * family name "Dialog.Plain" and full name of "Dialog". * The one arguably overly stringent restriction here is that if an * application wants to supply a new member of an existing family * It will get rejected. But since the JRE can perform synthetic * styling in many cases its not necessary. * We don't apply the same logic to registered fonts. If apps want * to do this lets assume they have a reason. It won't cause problems * except for themselves. */ HashSet<String> names = getInstalledNames(); Locale l = getSystemStartupLocale(); String familyName = font.getFamily(l).toLowerCase(); String fullName = font.getFontName(l).toLowerCase(); if (names.contains(familyName) || names.contains(fullName)) { return false; } /* Checks passed, now register the font */ Hashtable<String,FontFamily> familyTable; Hashtable<String,Font2D> fullNameTable; if (!maybeMultiAppContext()) { familyTable = createdByFamilyName; fullNameTable = createdByFullName; fontsAreRegistered = true; } else { AppContext appContext = AppContext.getAppContext(); familyTable = (Hashtable<String,FontFamily>)appContext.get(regFamilyKey); fullNameTable = (Hashtable<String,Font2D>)appContext.get(regFullNameKey); if (familyTable == null) { familyTable = new Hashtable<String,FontFamily>(); fullNameTable = new Hashtable<String,Font2D>(); appContext.put(regFamilyKey, familyTable); appContext.put(regFullNameKey, fullNameTable); } fontsAreRegisteredPerAppContext = true; } /* Create the FontFamily and add font to the tables */ Font2D font2D = FontUtilities.getFont2D(font); int style = font2D.getStyle(); FontFamily family = familyTable.get(familyName); if (family == null) { family = new FontFamily(font.getFamily(l)); familyTable.put(familyName, family); } /* Remove name cache entries if not using app contexts. * To accommodate a case where code may have registered first a plain * family member and then used it and is now registering a bold family * member, we need to remove all members of the family, so that the * new style can get picked up rather than continuing to synthesise. */ if (fontsAreRegistered) { removeFromCache(family.getFont(Font.PLAIN)); removeFromCache(family.getFont(Font.BOLD)); removeFromCache(family.getFont(Font.ITALIC)); removeFromCache(family.getFont(Font.BOLD|Font.ITALIC)); removeFromCache(fullNameTable.get(fullName)); } family.setFont(font2D, style); fullNameTable.put(fullName, font2D); return true; }