List of usage examples for java.awt Font getFamily
public String getFamily()
From source file:processing.app.Theme.java
/** * Returns the default font for text areas. * * @return The default font.// w ww . jav a 2 s . co m */ public static final Font getDefaultFont() { // Use StyleContext to get a composite font for better Asian language // support; see Sun bug S282887. StyleContext sc = StyleContext.getDefaultStyleContext(); Font font = null; if (OSUtils.isMacOS()) { // Snow Leopard (1.6) uses Menlo as default monospaced font, // pre-Snow Leopard used Monaco. font = sc.getFont("Menlo", Font.PLAIN, 12); if (!"Menlo".equals(font.getFamily())) { font = sc.getFont("Monaco", Font.PLAIN, 12); if (!"Monaco".equals(font.getFamily())) { // Shouldn't happen font = sc.getFont("Monospaced", Font.PLAIN, 13); } } } else { // Consolas added in Vista, used by VS2010+. font = sc.getFont("Consolas", Font.PLAIN, 13); if (!"Consolas".equals(font.getFamily())) { font = sc.getFont("Monospaced", Font.PLAIN, 13); } } // System.out.println(font.getFamily() + ", " + font.getName()); return font; }
From source file:Main.java
public void paint(Graphics g) { Font f = g.getFont(); String fontName = f.getName(); String fontFamily = f.getFamily(); int fontSize = f.getSize(); int fontStyle = f.getStyle(); String msg = "Family: " + fontName; msg += ", Font: " + fontFamily; msg += ", Size: " + fontSize + ", Style: "; if ((fontStyle & Font.BOLD) == Font.BOLD) msg += "Bold "; if ((fontStyle & Font.ITALIC) == Font.ITALIC) msg += "Italic "; if ((fontStyle & Font.PLAIN) == Font.PLAIN) msg += "Plain "; g.drawString(msg, 4, 16);/* w ww.j av a 2s. c om*/ }
From source file:Main.java
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { return new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); Font font = (Font) value; String text = font.getFamily(); FontMetrics fm = g.getFontMetrics(font); g.setColor(isSelected ? list.getSelectionBackground() : list.getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(isSelected ? list.getSelectionForeground() : list.getForeground()); g.setFont(font);// w w w . j a va 2 s . c o m g.drawString(text, 0, fm.getAscent()); } public Dimension getPreferredSize() { Font font = (Font) value; String text = font.getFamily(); Graphics g = getGraphics(); FontMetrics fm = g.getFontMetrics(font); return new Dimension(fm.stringWidth(text), fm.getHeight()); } }; }
From source file:processing.app.Theme.java
public static Map<String, Object> getStyledFont(String what, Font font) { String split[] = get("editor." + what + ".style").split(","); Color color = PreferencesHelper.parseColor(split[0]); String style = split[1];/* w w w . j a v a2 s .c o m*/ boolean bold = style.contains("bold"); boolean italic = style.contains("italic"); boolean underlined = style.contains("underlined"); Font styledFont = new Font(font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize()); if (underlined) { Map<TextAttribute, Object> attr = new Hashtable<>(); attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); styledFont = styledFont.deriveFont(attr); } Map<String, Object> result = new HashMap<>(); result.put("color", color); result.put("font", styledFont); return result; }
From source file:cc.pinel.mangue.ui.ChaptersPanel.java
/** * Highlights the label./* w w w . j a v a2 s . c o m*/ * * @param label the chapter label */ private void highlightLabel(KLabel label) { Font font = label.getFont(); label.setFont(new Font(font.getFamily(), Font.BOLD, font.getSize())); label.setForeground(new Color(255, 84, 84)); }
From source file:cc.pinel.mangue.ui.ChaptersPanel.java
/** * Unhighlights the label.//from w ww. ja v a 2 s . c o m * * @param label the chapter label */ private void unhighlightLabel(KLabel label) { Font font = label.getFont(); label.setFont(new Font(font.getFamily(), Font.PLAIN, font.getSize())); label.setForeground(Color.BLACK); }
From source file:org.geoserver.wms.WMSLifecycleHandler.java
List<Font> loadFontsFromDataDirectory() { List<Font> result = new ArrayList<Font>(); try {/*from ww w .j a v a 2 s . c o m*/ Collection<File> files = FileUtils.listFiles(data.findStyleDir(), new String[] { "ttf", "TTF" }, true); for (File file : files) { try { final Font font = Font.createFont(Font.TRUETYPE_FONT, file); result.add(font); LOGGER.log(Level.INFO, "Loaded font file " + file + ", loaded font '" + font.getName() + "' in family '" + font.getFamily() + "'"); } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to load font file " + file, e); } } } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to scan style directory for fonts", e); } return result; }
From source file:org.freeplane.main.application.UserPropertiesUpdater.java
private void updateNoteStyle(final NodeStyleController nodeStyleController, MapModel defaultStyleMap) { if (ResourceController.getResourceController() .getBooleanProperty((MNoteController.RESOURCES_USE_DEFAULT_FONT_FOR_NOTES_TOO))) return;//from w w w.ja v a2 s . co m final NodeModel styleNode = MapStyleModel.getExtension(defaultStyleMap) .getStyleNode(MapStyleModel.NOTE_STYLE); if (styleNode == null) return; styleNode.removeExtension(NodeStyleModel.class); final Font defaultFont = new JLabel().getFont(); final NodeStyleModel nodeStyleModel = new NodeStyleModel(); nodeStyleModel.setFontFamilyName(defaultFont.getFamily()); nodeStyleModel.setFontSize(defaultFont.getSize()); styleNode.addExtension(nodeStyleModel); }
From source file:com.haulmont.cuba.desktop.gui.components.SwingXTableSettings.java
protected void saveFontPreferences(Element element) { if (table.getFont() != null) { Font font = table.getFont(); Map<TextAttribute, ?> attributes = font.getAttributes(); // save content font element.addAttribute("fontFamily", font.getFamily()); element.addAttribute("fontSize", Integer.toString(font.getSize())); element.addAttribute("fontStyle", Integer.toString(font.getStyle())); element.addAttribute("fontUnderline", Boolean.toString(attributes.get(TextAttribute.UNDERLINE) == TextAttribute.UNDERLINE_ON)); }/*from w w w.j ava 2s. co m*/ }
From source file:gate.gui.ControllerMetadataViewer.java
@Override public void setTarget(Object target) { if (target == null) throw new NullPointerException("received a null target"); if (!(target instanceof Controller)) throw new IllegalArgumentException("not a controller"); Controller controller = (Controller) target; if (!controller.getFeatures().containsKey("gate.app.MetadataURL")) throw new IllegalArgumentException("no gate.app.MetadataURL feature"); try {/* w w w .java 2s. c om*/ URL metadata = (URL) controller.getFeatures().get("gate.app.MetadataURL"); URL longDesc = new URL(metadata, "long-desc.html"); URL iconDesc = new URL(metadata, "icon.png"); Document document = builder.parse(metadata.openStream()); Node text = document.getDocumentElement().getElementsByTagName("pipeline-name").item(0).getFirstChild(); Font font = Gate.getUserConfig().getFont(GateConstants.TEXT_COMPONENTS_FONT); StringBuilder page = new StringBuilder(); page.append("<!DOCTYPE html>"); page.append("<html>"); page.append("<head>"); page.append("<style type='text/css'>body { font-family: ").append(font.getFamily()) .append("; font-size: ").append(font.getSize()).append("pt }</style>"); page.append("</head>"); page.append("<body>"); page.append("<h1><img style='vertical-align: middle;' src='") .append(StringEscapeUtils.escapeHtml(iconDesc.toString())).append("'/> ") .append(StringEscapeUtils.escapeHtml(text.getTextContent())).append("</h1>"); page.append(IOUtils.toString(longDesc, "UTF-8")); page.append("</body></html>"); // parse using NekoHTML HTMLConfiguration config = new HTMLConfiguration(); // Force element names to lower case to match XHTML requirements // as that is what Flying Saucer expects config.setProperty("http://cyberneko.org/html/properties/names/elems", "lower"); DOMParser htmlParser = new DOMParser(config); htmlParser.parse(new InputSource(new StringReader(page.toString()))); display.setDocument(htmlParser.getDocument(), longDesc.toString()); } catch (Exception e) { throw new IllegalArgumentException(e); } }