List of usage examples for java.awt Font getSize
public int getSize()
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 om if (font.isItalic()) { fs += "ITALIC"; } } fs += "-" + font.getSize(); return (fs); }
From source file:com.github.fritaly.dualcommander.Utils.java
public static Font getBoldFont(Font font) { Validate.notNull(font, "The given font is null"); return new Font(font.getName(), font.getStyle() | Font.BOLD, font.getSize()); }
From source file:Main.java
public static String getNiceFontName(Font font) { if (font == null) return ""; StringBuilder buf = new StringBuilder(); buf.append(font.getName());//from ww w . j av a 2s . c o m buf.append(", "); switch (font.getStyle()) { case Font.BOLD: buf.append("bold"); break; case Font.ITALIC: buf.append("italic"); break; case Font.PLAIN: buf.append("plain"); break; } buf.append(", "); buf.append(font.getSize()); return buf.toString(); }
From source file:org.pgptool.gui.ui.tools.UiUtils.java
public static void setLookAndFeel() { // NOTE: We doing it this way to prevent dead=locks that is sometimes // happens if do it in main thread Edt.invokeOnEdtAndWait(new Runnable() { @Override//w ww .ja va2s. c o m public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); fixCheckBoxMenuItemForeground(); fixFontSize(); } catch (Throwable t) { log.error("Failed to set L&F", t); } } /** * In some cases (depends on OS theme) check menu item foreground is same as * bacground - thus it;'s invisible when cheked */ private void fixCheckBoxMenuItemForeground() { UIDefaults defaults = UIManager.getDefaults(); Color selectionForeground = defaults.getColor("CheckBoxMenuItem.selectionForeground"); Color foreground = defaults.getColor("CheckBoxMenuItem.foreground"); Color background = defaults.getColor("CheckBoxMenuItem.background"); if (colorsDiffPercentage(selectionForeground, background) < 10) { // TODO: That doesn't actually affect defaults. Need to find out how to fix it defaults.put("CheckBoxMenuItem.selectionForeground", foreground); } } private int colorsDiffPercentage(Color c1, Color c2) { int diffRed = Math.abs(c1.getRed() - c2.getRed()); int diffGreen = Math.abs(c1.getGreen() - c2.getGreen()); int diffBlue = Math.abs(c1.getBlue() - c2.getBlue()); float pctDiffRed = (float) diffRed / 255; float pctDiffGreen = (float) diffGreen / 255; float pctDiffBlue = (float) diffBlue / 255; return (int) ((pctDiffRed + pctDiffGreen + pctDiffBlue) / 3 * 100); } private void fixFontSize() { if (isJreHandlesScaling()) { log.info("JRE handles font scaling, won't change it"); return; } log.info("JRE doesnt't seem to support font scaling"); Toolkit toolkit = Toolkit.getDefaultToolkit(); int dpi = toolkit.getScreenResolution(); if (dpi == 96) { if (log.isDebugEnabled()) { Font font = UIManager.getDefaults().getFont("TextField.font"); String current = font != null ? Integer.toString(font.getSize()) : "unknown"; log.debug( "Screen dpi seem to be 96. Not going to change font size. Btw current size seem to be " + current); } return; } int targetFontSize = 12 * dpi / 96; log.debug("Screen dpi = " + dpi + ", decided to change font size to " + targetFontSize); setDefaultSize(targetFontSize); } private boolean isJreHandlesScaling() { try { JreVersion noNeedToScaleForVer = JreVersion.parseString("9"); String jreVersionStr = System.getProperty("java.version"); if (jreVersionStr != null) { JreVersion curVersion = JreVersion.parseString(jreVersionStr); if (noNeedToScaleForVer.compareTo(curVersion) <= 0) { return true; } } return false; } catch (Throwable t) { log.warn("Failed to see oif JRE can handle font scaling. Will assume it does. JRE version: " + System.getProperty("java.version"), t); return true; } } public void setDefaultSize(int size) { Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet(); Object[] keys = keySet.toArray(new Object[keySet.size()]); for (Object key : keys) { if (key != null && key.toString().toLowerCase().contains("font")) { Font font = UIManager.getDefaults().getFont(key); if (font != null) { Font changedFont = font.deriveFont((float) size); UIManager.put(key, changedFont); Font doubleCheck = UIManager.getDefaults().getFont(key); log.debug("Font size changed for " + key + ". From " + font.getSize() + " to " + doubleCheck.getSize()); } } } } }); log.info("L&F set"); }
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.kalypso.commons.java.util.StringUtilities.java
/** * Converts a font to a string. Format is defined in {@link StringUtilities#stringToFont(String)} * //from w ww. j a v a 2s . c om * @param f * @throws IllegalArgumentException * if f is null */ public static String fontToString(final Font f) { if (f == null) throw new IllegalArgumentException( Messages.getString("org.kalypso.commons.java.util.StringUtilities.5")); //$NON-NLS-1$ final StringBuffer buf = new StringBuffer(); buf.append(f.getName()).append(";").append(f.getStyle()).append(";").append(f.getSize()); //$NON-NLS-1$ //$NON-NLS-2$ return buf.toString(); }
From source file:org.gtdfree.ApplicationHelper.java
public static void changeDefaultFontSize(float size, String key) { Font f = UIManager.getDefaults().getFont(key + ".font"); //$NON-NLS-1$ if (f != null) { UIManager.getDefaults().put(key + ".font", new FontUIResource(f.deriveFont(f.getSize() + size))); //$NON-NLS-1$ }/*from w w w . jav a 2 s . c o m*/ }
From source file:com.rapidminer.gui.viewer.metadata.model.AbstractAttributeStatisticsModel.java
/** * Changes the font of {@link JFreeChart}s to Sans Serif. This method uses a * {@link StandardChartTheme} to do so, so any changes to the look of the chart must be done * after calling this method./* w w w . jav a 2 s . c o m*/ * * @param chart * the chart to change fonts for */ protected static void setDefaultChartFonts(JFreeChart chart) { final ChartTheme chartTheme = StandardChartTheme.createJFreeTheme(); if (StandardChartTheme.class.isAssignableFrom(chartTheme.getClass())) { StandardChartTheme standardTheme = (StandardChartTheme) chartTheme; // The default font used by JFreeChart cannot render japanese etc symbols final Font oldExtraLargeFont = standardTheme.getExtraLargeFont(); final Font oldLargeFont = standardTheme.getLargeFont(); final Font oldRegularFont = standardTheme.getRegularFont(); final Font oldSmallFont = standardTheme.getSmallFont(); final Font extraLargeFont = new Font(Font.SANS_SERIF, oldExtraLargeFont.getStyle(), oldExtraLargeFont.getSize()); final Font largeFont = new Font(Font.SANS_SERIF, oldLargeFont.getStyle(), oldLargeFont.getSize()); final Font regularFont = new Font(Font.SANS_SERIF, oldRegularFont.getStyle(), oldRegularFont.getSize()); final Font smallFont = new Font(Font.SANS_SERIF, oldSmallFont.getStyle(), oldSmallFont.getSize()); standardTheme.setExtraLargeFont(extraLargeFont); standardTheme.setLargeFont(largeFont); standardTheme.setRegularFont(regularFont); standardTheme.setSmallFont(smallFont); standardTheme.apply(chart); } }
From source file:processing.app.Theme.java
static public Font scale(Font font) { float size = scale(font.getSize()); // size must be float to call the correct Font.deriveFont(float) // method that is different from Font.deriveFont(int)! Font scaled = font.deriveFont(size); return scaled; }
From source file:org.yccheok.jstock.charting.Utils.java
/** * Applying chart theme based on given JFreeChart. * * @param chart the JFreeChart/*ww w . j av a2s.c o m*/ */ public static void applyChartThemeEx(JFreeChart chart) { final StandardChartTheme chartTheme; final JStockOptions.ChartTheme theme = JStock.instance().getJStockOptions().getChartTheme(); if (theme == JStockOptions.ChartTheme.Light) { applyChartTheme(chart); return; } else { assert (theme == JStockOptions.ChartTheme.Dark); chartTheme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createDarknessTheme(); } // The default font used by JFreeChart unable to render Chinese properly. // We need to provide font which is able to support Chinese rendering. final Locale defaultLocale = Locale.getDefault(); if (org.yccheok.jstock.gui.Utils.isSimplifiedChinese(defaultLocale) || org.yccheok.jstock.gui.Utils.isTraditionalChinese(defaultLocale)) { final Font oldExtraLargeFont = chartTheme.getExtraLargeFont(); final Font oldLargeFont = chartTheme.getLargeFont(); final Font oldRegularFont = chartTheme.getRegularFont(); final Font oldSmallFont = chartTheme.getSmallFont(); final Font extraLargeFont = new Font("Sans-serif", oldExtraLargeFont.getStyle(), oldExtraLargeFont.getSize()); final Font largeFont = new Font("Sans-serif", oldLargeFont.getStyle(), oldLargeFont.getSize()); final Font regularFont = new Font("Sans-serif", oldRegularFont.getStyle(), oldRegularFont.getSize()); final Font smallFont = new Font("Sans-serif", oldSmallFont.getStyle(), oldSmallFont.getSize()); chartTheme.setExtraLargeFont(extraLargeFont); chartTheme.setLargeFont(largeFont); chartTheme.setRegularFont(regularFont); chartTheme.setSmallFont(smallFont); } // Apply and return early. chartTheme.apply(chart); }