List of usage examples for java.awt Font getName
public String getName()
From source file:de.aidger.view.utils.Charts.java
/** * Creates a xy area chart./*from www.j a v a2 s. com*/ * * @param title * the diagram title * @param dataset * the dataset. * @param width * the width of the chart as image * @param height * the height of the chart as image * @return the xy area chart as image */ public static ImageIcon createXYAreaChart(String title, XYDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createXYAreaChart(title, "", "", dataset, PlotOrientation.VERTICAL, false, false, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); XYPlot plot = chart.getXYPlot(); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setNoDataMessage(_("No data to display.")); ValueAxis domainAxis = new DateAxis(); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setTickLabelFont(UIManager.getFont("RootPane.font")); ValueAxis rangeAxis = new NumberAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setDomainAxis(domainAxis); plot.setRangeAxis(rangeAxis); plot.setForegroundAlpha(0.5f); return new ImageIcon(chart.createBufferedImage(width, height)); }
From source file:de.aidger.view.utils.Charts.java
/** * Creates a 3D pie chart.//from w w w . j a v a 2s. com * * @param title * the diagram title * @param dataset * the dataset. * @param width * the width of the chart as image * @param height * the height of the chart as image * * @return the 3D pie chart as image */ public static ImageIcon createPieChart3D(String title, PieDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getLegend().setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); chart.getLegend().setBorder(0, 0, 0, 0); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setForegroundAlpha(0.9f); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage(_("No data to display.")); plot.setLabelGenerator(null); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setDarkerSides(true); return new ImageIcon(chart.createBufferedImage(width, height)); }
From source file:org.apache.pdfbox.pdmodel.font.FontManager.java
/** * Try to determine if the font has a BOLD-type. * * @param name The font./*w ww .ja v a2 s . co m*/ * * @return font has BOLD-type or not */ private static boolean isBold(java.awt.Font font) { String name = font.getName().toLowerCase(); if (name.indexOf("bold") > -1) { return true; } String psname = font.getPSName().toLowerCase(); if (psname.indexOf("bold") > -1) { return true; } return false; }
From source file:org.apache.pdfbox.pdmodel.font.FontManager.java
/** * Try to determine if the font has an ITALIC-type. * * @param name The font./*from ww w.jav a2 s . c o m*/ * * @return font has ITALIC-type or not */ private static boolean isItalic(java.awt.Font font) { String name = font.getName().toLowerCase(); // oblique is the same as italic if (name.indexOf("italic") > -1 || name.indexOf("oblique") > -1) { return true; } String psname = font.getPSName().toLowerCase(); if (psname.indexOf("italic") > -1 || psname.indexOf("oblique") > -1) { return true; } return false; }
From source file:cz.muni.fi.nbs.utils.Helpers.java
private static void exportToPNG(Map<String, Collection<Result>> results) { for (Entry<String, Collection<Result>> entry : results.entrySet()) { double number = 0; String key = entry.getKey(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Iterator<Result> resultsIterator = results.get(key).iterator(); while (resultsIterator.hasNext()) { Result r = resultsIterator.next(); dataset.addValue(r.getScore(), r.getLabel(), ""); number += 0.8;//w ww . ja va 2s . c om } double width = number > 1 ? number * 200 : 300; String unit = entry.getValue().iterator().next().getScoreUnit(); String[] splitKey = key.split("_"); JFreeChart chart = ChartFactory.createBarChart3D(splitKey[0], null, unit, dataset); int len = splitKey.length / 2; for (int i = 0; i < len; i++) { String subtitle = splitKey[i * 2 + 1] + ":" + splitKey[i * 2 + 2]; TextTitle title = new TextTitle(subtitle); Font oldFont = title.getFont(); int fontSize = (int) Math.round(oldFont.getSize() * 1.2); int fontStyle = oldFont.getStyle(); String fontName = oldFont.getName(); title.setFont(new Font(fontName, fontStyle, fontSize)); chart.addSubtitle(title); } try { ChartUtilities.saveChartAsPNG(new File(resultsDir + "/charts/" + key + "Chart.png"), chart, (int) Math.round(width), 800); } catch (IOException ex) { Logger.getLogger(Helpers.class.getName()).log(Level.SEVERE, "Could not export chart to PNG file for " + key, ex); } } }
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
/** * Sets all used fonts for displaying to the specified font df * <br>Use with care! //from ww w .j a v a2 s . c o m */ public static void setUIFont(final Font df) { setUIFontSize(df.getSize()); final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys(); while (keys.hasMoreElements()) { final Object key = keys.nextElement(); final Object value = UIManager.get(key); if (value instanceof Font) { final Font ifont = (Font) value; final Font ofont = new FontUIResource(df.getName(), ifont.getStyle(), df.getSize()); UIManager.put(key, ofont); } } }
From source file:PolyGlot.IOHandler.java
/** * compares testfont to loaded file. returns file if it represents the font * * @param path full path of file to test * @param testFont font to test against// ww w. j a v a2 s . co m * @return file if path leads to passed font, null otherwise */ private static File loadFont(String path, Font testFont) { File fontFile = new File(path); File ret = null; // unrecgnized types won't be loaded if (path.toLowerCase().endsWith(".ttf") || path.toLowerCase().endsWith(".otf") || path.toLowerCase().endsWith(".ttc") || path.toLowerCase().endsWith(".ttc") || path.toLowerCase().endsWith(".dfont")) { try { Font f = Font.createFont(Font.TRUETYPE_FONT, fontFile); // if names match, set ret to return file if (f.getName().equals(testFont.getName()) || f.getName().equals(testFont.getName() + " Regular")) { ret = fontFile; } } catch (FontFormatException e) { // null detected and message bubbled to user elsewhere ret = null; } catch (IOException e) { // null detected and message bubbled to user elsewhere ret = null; } } return ret; }
From source file:me.oriley.crate.CrateGenerator.java
@Nullable private static String getFontName(@NonNull String filePath) { try {//w w w. j a va 2 s. c om FileInputStream inputStream = new FileInputStream(filePath); Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream); inputStream.close(); return font.getName(); } catch (FontFormatException | IOException e) { e.printStackTrace(); return null; } }
From source file:com.diversityarrays.kdxplore.KDXplore.java
static public void setUIfontSize(float multiplier) { UIDefaults defaults = UIManager.getDefaults(); for (Enumeration<?> e = defaults.keys(); e.hasMoreElements();) { Object key = e.nextElement(); Object value = defaults.get(key); if (value instanceof Font) { Font font = (Font) value; int newSize = Math.round(font.getSize() * multiplier); if (value instanceof FontUIResource) { defaults.put(key, new FontUIResource(font.getName(), font.getStyle(), newSize)); } else { defaults.put(key, new Font(font.getName(), font.getStyle(), newSize)); }//w w w. j a v a 2 s. c o m } else if (value instanceof Integer) { if ("Tree.rowHeight".equals(key)) { //$NON-NLS-1$ // System.out.println(key+": "+value); Integer rh = (Integer) value; rh = (int) (rh * multiplier * 1.4); defaults.put(key, rh); } } } }