Example usage for java.awt Font getSize

List of usage examples for java.awt Font getSize

Introduction

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

Prototype

public int getSize() 

Source Link

Document

Returns the point size of this Font , rounded to an integer.

Usage

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:LocationSensitiveDemo.java

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

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;//from ww  w .  j  ava2s .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:Main.java

public static String displayPropertiesToCSS(Font font, Color fg) {
    StringBuffer rule = new StringBuffer("body {");
    if (font != null) {
        rule.append(" font-family: ");
        rule.append(font.getFamily());//from  w  w  w.j a v  a2  s.  c o m
        rule.append(" ; ");
        rule.append(" font-size: ");
        rule.append(font.getSize());
        rule.append("pt ;");
        if (font.isBold()) {
            rule.append(" font-weight: 700 ; ");
        }
        if (font.isItalic()) {
            rule.append(" font-style: italic ; ");
        }
    }
    if (fg != null) {
        rule.append(" color: #");
        if (fg.getRed() < 16) {
            rule.append('0');
        }
        rule.append(Integer.toHexString(fg.getRed()));
        if (fg.getGreen() < 16) {
            rule.append('0');
        }
        rule.append(Integer.toHexString(fg.getGreen()));
        if (fg.getBlue() < 16) {
            rule.append('0');
        }
        rule.append(Integer.toHexString(fg.getBlue()));
        rule.append(" ; ");
    }
    rule.append(" }");
    return rule.toString();
}

From source file:net.sf.texprinter.utils.UIUtils.java

/**
 * Set the label font to the editor. When the content type
 * is set to 'text/html', the plain visualization is very ugly, so this
 * method will set the default JLabel font to a JEditorPane.
 *
 * @param editor The editor. The CSS stylesheet will be added to it.
 * @param justify A flag representing full justification. If true, the
 * text will be fully justified.//from w ww.jav  a  2s.co  m
 */
public static void setDefaultFontToEditorPane(JEditorPane editor, boolean justify) {

    // get the system font
    Font font = UIManager.getFont("Label.font");

    // set the body rule
    String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize()
            + "pt; margin-left: 0px; margin-top: 0px; " + (justify ? "text-align: justify;" : "") + " }";

    // set the list rule
    String listRule = "ol { margin-left: 20px; list-style-type: square; }";

    // add the body rule
    ((HTMLDocument) editor.getDocument()).getStyleSheet().addRule(bodyRule);

    // add the list rule
    ((HTMLDocument) editor.getDocument()).getStyleSheet().addRule(listRule);
}

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));
            }/*from  w  ww  .  j av 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);
            }
        }
    }
}

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());
    }//from   ww w. j  a v  a 2  s.c  o  m
}

From source file:org.notebook.gui.widget.LookAndFeelSelector.java

private static void fixFontBug() {
    int sizeOffset = 0;
    Enumeration keys = UIManager.getLookAndFeelDefaults().keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof Font) {
            Font oldFont = (Font) value;
            // logger.info(oldFont.getName());
            Font newFont = new Font("Dialog", oldFont.getStyle(), oldFont.getSize() + sizeOffset);
            UIManager.put(key, newFont);
        }/*from   www.j  av a2  s .  c om*/
    }
}

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  w w  .  j a v  a 2  s  . c  o  m*/

    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:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java

public static void enableCapability(final JTextPane desc, Project project, String value, boolean editable,
        boolean navigation) {
    value = removeSmallFont(value);/*from   w  w  w  .j ava  2s  . c  om*/
    HTMLEditorKit kit = new HTMLLetterWrappingEditorKit();
    desc.setEditorKit(kit);
    desc.setDocument(kit.createDefaultDocument());
    if (!editable && navigation) {
        value = NavigationDecorator.explodeHtml(project, value);
    }
    desc.setText(value);
    if (!editable) {
        desc.setCaret(new NonAdjustingCaret());
    }
    desc.addCaretListener(new BodyLimitCaretListener(desc));
    if (editable) {
        String element = checkElements(desc.getDocument().getDefaultRootElement());
        if (element != null) {
            desc.setToolTipText("Found unsupported element '" + element + "', editing is disabled.");
            editable = false;
        }
    }
    desc.setEditable(editable);

    if (editable && SpellCheckerManager.isAvailable()
            && ApplicationManager.getApplication().getComponent(AliConfiguration.class).spellChecker) {
        desc.getDocument().addDocumentListener(new SpellCheckDocumentListener(project, desc));
    }

    Font font = UIManager.getFont("Label.font");
    String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize()
            + "pt; }";
    ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(bodyRule);

    // AGM uses plain "p" to create lines, we need to avoid excessive spacing this by default creates
    String paragraphRule = "p { margin-top: 0px; }";
    ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(paragraphRule);

    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // following is needed to make copy work in the IDE
            try {
                StringSelection selection = new StringSelection(desc.getText(desc.getSelectionStart(),
                        desc.getSelectionEnd() - desc.getSelectionStart()));
                CopyPasteManager.getInstance().setContents(selection);
            } catch (Exception ex) {
                // no clipboard, so what
            }
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_COPY)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // avoid pasting non-supported HTML markup by always converting to plain text
            Transferable contents = CopyPasteManager.getInstance().getContents();
            try {
                desc.getActionMap().get(DefaultEditorKit.cutAction).actionPerformed(null);
                desc.getDocument().insertString(desc.getSelectionStart(),
                        (String) contents.getTransferData(DataFlavor.stringFlavor), null);
            } catch (Exception ex) {
                // no clipboard, so what
            }
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_PASTE)), desc);
    installNavigationShortCuts(desc);

}