Example usage for java.awt Font getStyle

List of usage examples for java.awt Font getStyle

Introduction

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

Prototype

public int getStyle() 

Source Link

Document

Returns the style of this Font .

Usage

From source file:Main.java

/**
 * Apply bold font to a Jlabel./*ww w.jav  a2s.  c om*/
 * @param label
 */
public static void bold(final JLabel label) {
    final Font font = label.getFont();
    label.setFont(font.deriveFont(font.getStyle() ^ Font.BOLD));
}

From source file:Main.java

/**
 * Sets component font name./*from w w w.jav a 2 s.c  om*/
 *
 * @param component component font name
 * @param fontName  new font name
 * @param <C>       component type
 * @return modified component
 */
public static <C extends Component> C setFontName(final C component, final String fontName) {
    if (component != null && component.getFont() != null) {
        final Font oldFont = component.getFont();
        component.setFont(new Font(fontName, oldFont.getStyle(), oldFont.getSize()));
    }
    return component;
}

From source file:Main.java

/** 
 * Sets all used fonts for displaying to the specified font df
 * <br>Use with care! /*from  ww  w .  ja  v  a2 s . c om*/
 */
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:Main.java

/** 
 * Returns a string with all fonts used by Swing's UIManager.
 *///from  w  ww .ja v  a 2s. c o  m
public static String getUIFonts() {

    final StringBuffer fonts = new StringBuffer(128);
    fonts.append("Default font: ");
    fonts.append(getUIFont().toString());
    final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys();
    String lf = System.getProperty("line.separator");
    while (keys.hasMoreElements()) {
        final Object key = keys.nextElement();
        final Object value = UIManager.get(key);
        if (value instanceof Font) {
            final Font ifont = (Font) value;
            fonts.append(lf + key.toString() + " " + ifont.getName() + " " + ifont.getStyle() + " "
                    + ifont.getSize());
        }
    }
    return fonts.toString();
}

From source file:Main.java

public static void addFontProperty(Document document, Element parent, String name, Font value) {
    addPropertyNode(document, parent, name).setAttribute(FONT_ATTR,
            value.getName() + "," + value.getStyle() + "," + value.getSize());
}

From source file:Main.java

public static String getNiceFontName(Font font) {
    if (font == null)
        return "";
    StringBuilder buf = new StringBuilder();
    buf.append(font.getName());/*  w  w  w.  j ava 2 s  .co 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:de.aidger.view.utils.Charts.java

/**
 * Creates a xy area chart./*from  ww  w. j  a  va2s  .  c o m*/
 * 
 * @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 ww .jav  a 2  s .  co  m
 * 
 * @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: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;// ww w  . j a  va 2  s .co  m
        }
        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:au.org.ala.delta.editor.EditorPreferences.java

public static void setPreferredFont(Font font) {
    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    if (prefs != null) {
        prefs.put(FONT_KEY, font.getFontName() + "-" + font.getStyle() + "-" + font.getSize());
    }/* w  w  w  . ja v  a2s .c o m*/
}