Example usage for java.awt Font getName

List of usage examples for java.awt Font getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the logical name of this Font .

Usage

From source file:processing.app.EditorTab.java

public void applyPreferences() {
    textarea.setCodeFoldingEnabled(PreferencesData.getBoolean("editor.code_folding"));
    scrollPane.setFoldIndicatorEnabled(PreferencesData.getBoolean("editor.code_folding"));
    scrollPane.setLineNumbersEnabled(PreferencesData.getBoolean("editor.linenumbers"));

    // apply the setting for 'use external editor', but only if it changed
    if (external != PreferencesData.getBoolean("editor.external")) {
        external = !external;//from   w  ww  .j  av  a 2 s  .  c  o m
        if (external) {
            // disable line highlight and turn off the caret when disabling
            textarea.setBackground(Theme.getColor("editor.external.bgcolor"));
            textarea.setHighlightCurrentLine(false);
            textarea.setEditable(false);
            // Detach from the code, since we are no longer the authoritative source
            // for file contents.
            file.setStorage(null);
            // Reload, in case the file contents already changed.
            reload();
        } else {
            textarea.setBackground(Theme.getColor("editor.bgcolor"));
            textarea.setHighlightCurrentLine(Theme.getBoolean("editor.linehighlight"));
            textarea.setEditable(true);
            file.setStorage(this);
            // Reload once just before disabling external mode, to ensure we have
            // the latest contents.
            reload();
        }
    }
    // apply changes to the font size for the editor
    Font editorFont = scale(PreferencesData.getFont("editor.font"));

    // check whether a theme-defined editor font is available
    Font themeFont = Theme.getFont("editor.font");
    if (themeFont != null) {
        // Apply theme font if the editor font has *not* been changed by the user,
        // This allows themes to specify an editor font which will only be applied
        // if the user hasn't already changed their editor font via preferences.txt
        String defaultFontName = StringUtils.defaultIfEmpty(PreferencesData.getDefault("editor.font"), "")
                .split(",")[0];
        if (defaultFontName.equals(editorFont.getName())) {
            editorFont = new Font(themeFont.getName(), themeFont.getStyle(), editorFont.getSize());
        }
    }

    textarea.setFont(editorFont);
    scrollPane.getGutter().setLineNumberFont(editorFont);
}

From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java

/**
 * Write a blank thumbnail image so user doesn't see the broken icon.
 *//*from   www .j  a  va 2s.  com*/
private void writePlaceholderThumbnailImage(OutputStream os, int placeholderSize) throws IOException {
    // Make the image a bit bigger to account for the empty space around the generated image.
    // If we can find a way to remove this empty space, we don't need to make the chart bigger.
    BufferedImage buffer = new BufferedImage(placeholderSize + 16, placeholderSize + 9,
            BufferedImage.TYPE_INT_RGB);
    Graphics g = buffer.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, placeholderSize + 16, placeholderSize + 9);
    g.setColor(Color.gray);
    g.drawLine(8, placeholderSize + 5, placeholderSize + 8, placeholderSize + 5); // x-axis
    g.drawLine(8, 5, 8, placeholderSize + 5); // y-axis
    g.setColor(Color.black);
    Font font = g.getFont();
    g.setFont(new Font(font.getName(), font.getStyle(), 8));
    g.drawString("N/A", 9, placeholderSize);
    ImageIO.write(buffer, "png", os);
}

From source file:userinterface.graph.Graph.java

/**
 * Allows graphs to be saved to the PRISM 'gra' file format.
 * //w  w  w . j  av  a2 s  .  c  o  m
 * @param file
 *            The file to save the graph to.
 * @throws GraphException
 *             If the file cannot be written.
 */
public void save(File file) throws PrismException {
    try {
        JFreeChart chart = getChart();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.newDocument();

        Element chartFormat = doc.createElement("chartFormat");

        chartFormat.setAttribute("versionString", prism.Prism.getVersion());
        chartFormat.setAttribute("graphTitle", getTitle());

        Font titleFont = getTitleFont().f;
        chartFormat.setAttribute("titleFontName", titleFont.getName());
        chartFormat.setAttribute("titleFontSize", "" + titleFont.getSize());
        chartFormat.setAttribute("titleFontStyle", "" + titleFont.getStyle());

        Color titleFontColor = (Color) getTitleFont().c;
        chartFormat.setAttribute("titleFontColourR", "" + titleFontColor.getRed());
        chartFormat.setAttribute("titleFontColourG", "" + titleFontColor.getGreen());
        chartFormat.setAttribute("titleFontColourB", "" + titleFontColor.getBlue());

        chartFormat.setAttribute("legendVisible", isLegendVisible() ? "true" : "false");

        Font legendFont = getLegendFont().f;
        chartFormat.setAttribute("legendFontName", "" + legendFont.getName());
        chartFormat.setAttribute("legendFontSize", "" + legendFont.getSize());
        chartFormat.setAttribute("legendFontStyle", "" + legendFont.getStyle());

        Color legendFontColor = getLegendFont().c;

        chartFormat.setAttribute("legendFontColourR", "" + legendFontColor.getRed());
        chartFormat.setAttribute("legendFontColourG", "" + legendFontColor.getGreen());
        chartFormat.setAttribute("legendFontColourB", "" + legendFontColor.getBlue());

        switch (getLegendPosition()) {
        case LEFT:
            chartFormat.setAttribute("legendPosition", "left");
            break;
        case BOTTOM:
            chartFormat.setAttribute("legendPosition", "bottom");
            break;
        case TOP:
            chartFormat.setAttribute("legendPosition", "top");
            break;
        default:
            chartFormat.setAttribute("legendPosition", "right");
        }

        Element layout = doc.createElement("layout");
        chartFormat.appendChild(layout);

        Element xAxis = doc.createElement("axis");
        getXAxisSettings().save(xAxis);
        chartFormat.appendChild(xAxis);

        Element yAxis = doc.createElement("axis");
        getYAxisSettings().save(yAxis);
        chartFormat.appendChild(yAxis);

        synchronized (getSeriesLock()) {
            /* Make sure we preserve ordering. */
            for (int i = 0; i < seriesList.getSize(); i++) {
                SeriesKey key = seriesList.getKeyAt(i);

                Element series = doc.createElement("graph");
                SeriesSettings seriesSettings = getGraphSeries(key);
                seriesSettings.save(series);

                XYSeries seriesData = getXYSeries(key);

                for (int j = 0; j < seriesData.getItemCount(); j++) {
                    Element point = doc.createElement("point");

                    point.setAttribute("x", "" + seriesData.getX(j));
                    point.setAttribute("y", "" + seriesData.getY(j));

                    series.appendChild(point);
                }

                chartFormat.appendChild(series);
            }
        }

        doc.appendChild(chartFormat);

        // File writing 
        Transformer t = TransformerFactory.newInstance().newTransformer();
        t.setOutputProperty("doctype-system", "chartformat.dtd");
        t.setOutputProperty("indent", "yes");
        t.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(file)));
    } catch (IOException e) {
        throw new PrismException(e.getMessage());
    } catch (DOMException e) {
        throw new PrismException("Problem saving graph: DOM Exception: " + e);
    } catch (ParserConfigurationException e) {
        throw new PrismException("Problem saving graph: Parser Exception: " + e);
    } catch (TransformerConfigurationException e) {
        throw new PrismException("Problem saving graph: Error in creating XML: " + e);
    } catch (TransformerException e) {
        throw new PrismException("Problem saving graph: Transformer Exception: " + e);
    } catch (SettingException e) {
        throw new PrismException(e.getMessage());
    }
}

From source file:org.apache.pdfbox.pdmodel.font.PDSimpleFont.java

/**
 * {@inheritDoc}//from  w w w .  j av a 2  s.  com
 */
public void drawString(String string, int[] codePoints, Graphics g, float fontSize, AffineTransform at, float x,
        float y) throws IOException {
    Font awtFont = getawtFont();
    FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true);
    GlyphVector glyphs = null;
    boolean useCodepoints = codePoints != null && isType0Font();
    PDFont descendantFont = useCodepoints ? ((PDType0Font) this).getDescendantFont() : null;
    // symbolic fonts may trigger the same fontmanager.so/dll error as described below
    if (useCodepoints && !descendantFont.getFontDescriptor().isSymbolic()) {
        PDCIDFontType2Font cid2Font = null;
        if (descendantFont instanceof PDCIDFontType2Font) {
            cid2Font = (PDCIDFontType2Font) descendantFont;
        }
        if ((cid2Font != null && cid2Font.hasCIDToGIDMap()) || isFontSubstituted) {
            // we still have to use the string if a CIDToGIDMap is used 
            glyphs = awtFont.createGlyphVector(frc, string);
        } else {
            glyphs = awtFont.createGlyphVector(frc, codePoints);
        }
    } else {
        // mdavis - fix fontmanager.so/dll on sun.font.FileFont.getGlyphImage
        // for font with bad cmaps?
        // Type1 fonts are not affected as they don't have cmaps
        if (!isType1Font() && awtFont.canDisplayUpTo(string) != -1) {
            LOG.warn("Changing font on <" + string + "> from <" + awtFont.getName() + "> to the default font");
            awtFont = Font.decode(null).deriveFont(1f);
        }
        glyphs = awtFont.createGlyphVector(frc, string);
    }
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    writeFont(g2d, at, x, y, glyphs);
}

From source file:lcmc.common.ui.ResourceGraph.java

/** Returns layout of the text that will be drawn on the vertex. */
private TextLayout getVertexTextLayout(final Graphics2D g2d, final String text, final double fontSizeFactor) {
    final TextLayout ctl = textLayoutCache.get(fontSizeFactor + ":" + text);
    if (ctl != null) {
        return ctl;
    }/*from w  ww.  j a  v  a2 s .  co m*/
    final Font font = mainData.getMainFrame().getFont();
    final FontRenderContext context = g2d.getFontRenderContext();
    final TextLayout tl = new TextLayout(text,
            new Font(font.getName(), font.getStyle(), (int) (font.getSize() * fontSizeFactor)), context);
    textLayoutCache.put(fontSizeFactor + ":" + text, tl);
    return tl;
}

From source file:lcmc.gui.ResourceGraph.java

/** Returns layout of the text that will be drawn on the vertex. */
private TextLayout getVertexTextLayout(final Graphics2D g2d, final String text, final double fontSizeFactor) {
    final TextLayout ctl = textLayoutCache.get(fontSizeFactor + ':' + text);
    if (ctl != null) {
        return ctl;
    }//  ww w  . j  a va 2  s .  c  o m
    final Font font = Tools.getGUIData().getMainFrame().getFont();
    final FontRenderContext context = g2d.getFontRenderContext();
    TextLayout tl = new TextLayout(text,
            new Font(font.getName(), font.getStyle(), (int) (font.getSize() * fontSizeFactor)), context);
    textLayoutCache.put(fontSizeFactor + ':' + text, tl);
    return tl;
}

From source file:ro.nextreports.engine.exporter.ResultExporter.java

private void buildCellFont(Map<String, Object> format, Font font) {
    format.put(StyleFormatConstants.FONT_FAMILY_KEY, font.getFamily());
    format.put(StyleFormatConstants.FONT_NAME_KEY, font.getName());
    format.put(StyleFormatConstants.FONT_SIZE, new Float(font.getSize()));
    if (Font.PLAIN == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_NORMAL);
    }/* w w w .j  a  va2  s .  com*/
    if (Font.BOLD == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_BOLD);
    }
    if (Font.ITALIC == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_ITALIC);
    }
    if ((Font.BOLD | Font.ITALIC) == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_BOLDITALIC);
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

@Override
public void drawString(final String s, final float x, float y) {
    if (s.length() == 0) {
        return;/*ww w  . ja va 2  s  .co  m*/
    }
    setFillPaint();
    setStrokePaint();

    final AffineTransform at = getTransform();
    final AffineTransform at2 = getTransform();
    at2.translate(x, y);
    at2.concatenate(font.getTransform());
    setTransform(at2);
    final AffineTransform inverse = this.normalizeMatrix();
    final AffineTransform flipper = FLIP_TRANSFORM;
    inverse.concatenate(flipper);
    final double[] mx = new double[6];
    inverse.getMatrix(mx);
    cb.beginText();

    final float fontSize = font.getSize2D();
    if (lastBaseFont == null) {
        final String fontName = font.getName();
        final boolean bold = font.isBold();
        final boolean italic = font.isItalic();

        final BaseFontFontMetrics fontMetrics = metaData.getBaseFontFontMetrics(fontName, fontSize, bold,
                italic, null, metaData.isFeatureSupported(OutputProcessorFeature.EMBED_ALL_FONTS), false);
        final FontNativeContext nativeContext = fontMetrics.getNativeContext();
        lastBaseFont = fontMetrics.getBaseFont();

        cb.setFontAndSize(lastBaseFont, fontSize);
        if (fontMetrics.isTrueTypeFont() && bold && nativeContext.isNativeBold() == false) {
            final float strokeWidth = font.getSize2D() / 30.0f; // right from iText ...
            if (strokeWidth == 1) {
                cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
            } else {
                cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
                cb.setLineWidth(strokeWidth);
            }
        } else {
            cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
        }
    } else {
        cb.setFontAndSize(lastBaseFont, fontSize);
    }

    cb.setTextMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]);
    double width = 0;
    if (fontSize > 0) {
        final float scale = 1000 / fontSize;
        final Font font = this.font.deriveFont(AffineTransform.getScaleInstance(scale, scale));
        final Rectangle2D stringBounds = font.getStringBounds(s, getFontRenderContext());
        width = stringBounds.getWidth() / scale;
    }
    if (s.length() > 1) {
        final float adv = ((float) width - lastBaseFont.getWidthPoint(s, fontSize)) / (s.length() - 1);
        cb.setCharacterSpacing(adv);
    }
    cb.showText(s);
    if (s.length() > 1) {
        cb.setCharacterSpacing(0);
    }
    cb.endText();
    setTransform(at);
    if (underline) {
        // These two are supposed to be taken from the .AFM file
        // int UnderlinePosition = -100;
        final int UnderlineThickness = 50;
        //
        final double d = PdfGraphics2D.asPoints(UnderlineThickness, (int) fontSize);
        setStroke(new BasicStroke((float) d));
        y = (float) ((y) + PdfGraphics2D.asPoints((UnderlineThickness), (int) fontSize));
        final Line2D line = new Line2D.Double(x, y, (width + x), y);
        draw(line);
    }
}

From source file:org.nuclos.client.ui.collect.Chart.java

static String fontToString(Font font) {
    String strStyle;//from w w w  .j a va2 s  .c  o  m

    if (font.isBold()) {
        strStyle = font.isItalic() ? "bolditalic" : "bold";
    } else {
        strStyle = font.isItalic() ? "italic" : "plain";
    }

    return font.getName() + "-" + strStyle + "-" + font.getSize();
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Present the user with a font selection dialog and update the widgets if
 * the user chooses a font.//  www .  j  av a  2 s  .  c o  m
 */
private void configureFont() {
    FontChooser chooser;
    Font newFont;
    Color newColor;

    chooser = new FontChooser(this);
    chooser.setFont(getFontFromProperties());
    chooser.setColor(getColorFromProperties());

    LOGGER.debug("Font before choices: " + chooser.getNewFont());

    chooser.setVisible(true);

    newFont = chooser.getNewFont();
    newColor = chooser.getNewColor();

    // Values will be null if user canceled request
    if (newFont != null && newColor != null) {
        properties.setProperty(ConfigurationProperty.FONT_NAME.key(), newFont.getName());
        properties.setProperty(ConfigurationProperty.FONT_SIZE.key(), newFont.getSize() + "");
        properties.setProperty(ConfigurationProperty.FONT_STYLE.key(), newFont.getStyle() + "");

        properties.setProperty(ConfigurationProperty.FONT_COLOR.key(), newColor.getRGB() + "");

        LOGGER.debug("Font after choices: " + newFont);
        setFont(newFont, newColor);
    }
}