Example usage for java.awt Font deriveFont

List of usage examples for java.awt Font deriveFont

Introduction

In this page you can find the example usage for java.awt Font deriveFont.

Prototype

public Font deriveFont(Map<? extends Attribute, ?> attributes) 

Source Link

Document

Creates a new Font object by replicating the current Font object and applying a new set of font attributes to it.

Usage

From source file:org.datacleaner.util.GraphUtils.java

private static <E> Transformer<E, Font> createFontTransformer() {
    return new Transformer<E, Font>() {
        @Override//ww w . j  av  a 2 s  .c  om
        public Font transform(E input) {
            final Font defaultFont = WidgetUtils.FONT_SMALL;
            if (input == null) {
                return defaultFont;
            }

            final String str;
            if (input instanceof HasName) {
                str = ((HasName) input).getName();
            } else if (input instanceof Object[]) {
                str = Arrays.toString((Object[]) input);
            } else {
                str = input.toString();
            }

            if (defaultFont.canDisplayUpTo(str) == -1) {
                return defaultFont;
            }
            final Font findCompatibleFont = WidgetUtils.findCompatibleFont(str, WidgetUtils.FONT_SMALL);
            return findCompatibleFont.deriveFont(WidgetUtils.FONT_SIZE_SMALL);
        }
    };
}

From source file:org.neo4j.desktop.ui.Components.java

@SuppressWarnings({ "unchecked", "rawtypes" })
static Font underlined(Font font) {
    Map attributes = font.getAttributes();
    attributes.put(UNDERLINE, UNDERLINE_ON);
    return font.deriveFont(attributes);
}

From source file:LocationSensitiveDemo.java

private static void increaseFont(String type) {
    Font font = UIManager.getFont(type);
    font = font.deriveFont(font.getSize() + 4f);
    UIManager.put(type, font);//from w  w w.  j a  v a  2s . co  m
}

From source file:net.sf.keystore_explorer.gui.CreateApplicationGui.java

private static 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 = font.deriveFont((float) size);
                UIManager.put(key, font);
            }//  w w  w  . j a va 2  s .  com
        }
    }
}

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static JFreeChart createXYChart(String title, XYDataset data, String xLabel, String yLabel,
        int pointRadius, int lineThickness, ColorTheme theme) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, data, PlotOrientation.VERTICAL,
            true, false, false);//from   w  ww.ja  v a2 s .  com

    formatColorTheme(chart, theme);

    XYPlot plot = (XYPlot) chart.getPlot();
    Shape icon = new Ellipse2D.Double(-pointRadius, -pointRadius, pointRadius * 2, pointRadius * 2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    Color[] colors = generateJetSpectrum(data.getSeriesCount());
    for (int i = 0; i < data.getSeriesCount(); i++) {
        plot.getRenderer().setSeriesStroke(i, new BasicStroke(lineThickness));
        plot.getRenderer().setSeriesShape(i, icon);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesVisible(i, true);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesFilled(i, true);
        plot.getRenderer().setSeriesPaint(i, colors[i]);
    }

    LegendTitle legend = chart.getLegend();
    Font legendFont = legend.getItemFont();
    float legendFontSize = legendFont.getSize();
    Font newLegendFont = legendFont.deriveFont(legendFontSize * 0.6f);
    legend.setItemFont(newLegendFont);

    ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis();
    Font domainAxisLabelFont = domainAxis.getLabelFont();
    float domainAxisLabelFontSize = domainAxisLabelFont.getSize();
    domainAxis.setLabelFont(domainAxisLabelFont.deriveFont(domainAxisLabelFontSize * 0.6f));

    Font domainAxisTickLabelFont = domainAxis.getTickLabelFont();
    float domainAxisTickLabelFontSize = domainAxisTickLabelFont.getSize();
    domainAxis.setTickLabelFont(domainAxisTickLabelFont.deriveFont(domainAxisTickLabelFontSize * 0.6f));

    ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis();
    Font rangeAxisLabelFont = rangeAxis.getLabelFont();
    float rangeAxisLabelFontSize = rangeAxisLabelFont.getSize();
    rangeAxis.setLabelFont(rangeAxisLabelFont.deriveFont(rangeAxisLabelFontSize * 0.6f));

    Font rangeAxisTickLabelFont = rangeAxis.getTickLabelFont();
    float rangeAxisTickLabelFontSize = rangeAxisTickLabelFont.getSize();
    rangeAxis.setTickLabelFont(rangeAxisTickLabelFont.deriveFont(rangeAxisTickLabelFontSize * 0.6f));

    return chart;
}

From source file:org.gumtree.vis.awt.PlotFactory.java

public static JFreeChart createTimeChart(ITimeSeriesSet timeSeriesSet) {
    //      TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    JFreeChart chart = ChartFactory.createTimeSeriesChart(timeSeriesSet.getTitle(), null,
            timeSeriesSet.getYTitle()/*from  w  w w  .  ja va2  s .  co m*/
                    + (timeSeriesSet.getYUnits() != null ? " (" + timeSeriesSet.getYUnits() + ")" : ""),
            timeSeriesSet, true, true, false);
    XYPlot xyplot = chart.getXYPlot();
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    //        valueaxis.setFixedAutoRange(60000D);   
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(0.0D, 200D);
    valueaxis.setAutoRange(true);
    XYItemRenderer renderer = xyplot.getRenderer();
    if (renderer instanceof XYLineAndShapeRenderer) {
        ((XYLineAndShapeRenderer) renderer).setBaseShapesVisible(false);
    }
    chartTheme.apply(chart);
    Font font = valueaxis.getLabelFont();
    valueaxis.setLabelFont(font.deriveFont(Font.PLAIN));
    return chart;
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

private static void drawMaskName(Graphics2D g2, AbstractMask mask, Rectangle2D imageArea, double fontSizeRate) {
    if (mask.getName() == null) {
        return;//from  w  ww .ja  v a  2 s.com
    }
    Point2D fontLocation = mask.getTitleLocation(imageArea);
    g2.setPaint(Color.black);
    Font currentFont = g2.getFont();
    g2.setFont(currentFont.deriveFont((float) (maskNameFont.getSize() * fontSizeRate)).deriveFont(Font.ITALIC));
    g2.drawString(mask.getName(), (int) fontLocation.getX(), (int) fontLocation.getY());
    g2.setFont(currentFont);
}

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$
    }//  w ww  . j  a  va2  s. c  o m
}

From source file:org.gtdfree.ApplicationHelper.java

public static void changeDefaultFontStyle(int style, String key) {
    Font f = UIManager.getDefaults().getFont(key + ".font"); //$NON-NLS-1$
    if (f != null) {
        UIManager.getDefaults().put(key + ".font", new FontUIResource(f.deriveFont(style))); //$NON-NLS-1$
    }/*  ww  w  . j a  va  2s. c o m*/
}

From source file:es.emergya.cliente.constants.LogicConstants.java

private static Font getFont(Integer type, String font) {
    Font f;
    try {//w w  w .  j  av a2  s.  c  om
        f = Font.createFont(Font.TRUETYPE_FONT, LogicConstants.class.getResourceAsStream(font));
    } catch (Exception e) {
        LogicConstants.LOG.error("No se pudo cargar el font bold", e);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontNames = ge.getAvailableFontFamilyNames();
        if (fontNames.length > 0) {
            f = Font.decode(fontNames[0]);
            if (type != null) {
                f = f.deriveFont(type);
            }
        } else {
            throw new NullPointerException("There is no font available: " + font);
        }
    }
    return f;
}