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:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

/**
 * Creates a title item (i.e. bold font etc.) with the given string. Simply gets the default
 * font from the plotConfig and sets it style to bold.
 * /*from  ww w.  j  a  va 2  s  .co m*/
 * @return The created legend item.
 */
private LegendItem createTitleLegendItem(String titleString, PlotConfiguration plotConfiguration) {
    LegendItem titleItem = new LegendItem(titleString, "", "", "", false, new Rectangle(), false, Color.WHITE,
            false, Color.WHITE, new BasicStroke(), false, new Rectangle(), new BasicStroke(), Color.WHITE);
    Font titleFont = titleItem.getLabelFont();

    if (titleFont == null) {
        titleFont = plotConfiguration.getLegendConfiguration().getLegendFont();
    }
    titleItem.setLabelFont(titleFont.deriveFont(Font.BOLD));
    return titleItem;
}

From source file:net.sf.jasperreports.engine.fonts.FontUtil.java

protected Font getAwtFont(FontInfo fontInfo, int style, float size, boolean ignoreMissingFont) {
    @SuppressWarnings("unused")
    int faceStyle = Font.PLAIN;
    FontFamily family = fontInfo.getFontFamily();
    FontFace face = fontInfo.getFontFace();
    if (face == null) {
        if (((style & Font.BOLD) > 0) && ((style & Font.ITALIC) > 0)) {
            face = family.getBoldItalicFace();
            faceStyle = Font.BOLD | Font.ITALIC;
        }/*from   www . j  av a 2s.co m*/

        if ((face == null || face.getFont() == null) && ((style & Font.BOLD) > 0)) {
            face = family.getBoldFace();
            faceStyle = Font.BOLD;
        }

        if ((face == null || face.getFont() == null) && ((style & Font.ITALIC) > 0)) {
            face = family.getItalicFace();
            faceStyle = Font.ITALIC;
        }

        if (face == null || face.getFont() == null) {
            face = family.getNormalFace();
            faceStyle = Font.PLAIN;
        }

        //         if (face == null)
        //         {
        //            throw new JRRuntimeException("Font family '" + family.getName() + "' does not have the normal font face.");
        //         }
    } else {
        faceStyle = fontInfo.getStyle();
    }

    Font awtFont;
    if (face == null || face.getFont() == null) {
        // None of the family's font faces was found to match, neither by name, nor by style and the font family does not even specify a normal face font.
        // In such case, we take the family name and consider it as JVM available font name.
        checkAwtFont(family.getName(), ignoreMissingFont);

        awtFont = new Font(family.getName(), style, (int) size);
        awtFont = awtFont.deriveFont(size);
    } else {
        awtFont = face.getFont();
        if (awtFont == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_NULL_FONT,
                    new Object[] { face.getName(), family.getName() });
        }

        //deriving with style and size in one call, because deriving with size and then style loses the float size
        awtFont = awtFont.deriveFont(style, size);// & ~faceStyle);
    }
    return awtFont;
}

From source file:jatoo.app.App.java

private PopupMenu getTrayIconPopup() {

    MenuItem openItem = new MenuItem(getText("popup.open") + " " + getTitle());
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            show();/*from  ww w  .j av a  2s.  c om*/
        }
    });

    MenuItem hideItem = new MenuItem(getText("popup.hide") + " " + getTitle());
    hideItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            hide();
        }
    });

    CheckboxMenuItem hideWhenMinimizedItem = new CheckboxMenuItem(getText("popup.hide_when_minimized"),
            isHideWhenMinimized());
    hideWhenMinimizedItem.addItemListener(new ItemListener() {
        public void itemStateChanged(final ItemEvent e) {
            setHideWhenMinimized(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    MenuItem sendToBackItem = new MenuItem(getText("popup.send_to_back"));
    sendToBackItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            sendToBack();
        }
    });

    MenuItem closeItem = new MenuItem(getText("popup.close"));
    closeItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            System.exit(0);
        }
    });

    //
    //

    Font font = new JMenuItem().getFont();

    if (font != null) {
        openItem.setFont(font.deriveFont(Font.BOLD));
        hideItem.setFont(font);
        hideWhenMinimizedItem.setFont(font);
        sendToBackItem.setFont(font);
        closeItem.setFont(font);
    }

    //
    // the popup

    PopupMenu popup = new PopupMenu(getTitle());

    popup.add(openItem);
    popup.add(hideItem);
    popup.addSeparator();
    popup.add(hideWhenMinimizedItem);
    popup.addSeparator();
    popup.add(sendToBackItem);
    popup.addSeparator();
    popup.add(closeItem);

    return popup;
}

From source file:edu.ku.brc.specify.BackupAndRestoreApp.java

/**
 * /*from   ww  w  . j a  v  a2  s .  c o  m*/
 */
protected void setupDefaultFonts() {
    //if (UIHelper.isMacOS())
    {
        Font labelFont = (createLabel("")).getFont(); //$NON-NLS-1$
        log.debug("****** " + labelFont); //$NON-NLS-1$
        Font defaultFont;
        if (!UIHelper.isMacOS()) {
            defaultFont = labelFont;
        } else {
            if (labelFont.getSize() == 13) {
                defaultFont = labelFont.deriveFont((float) labelFont.getSize() - 2);
            } else {
                defaultFont = labelFont;
            }
        }
        BaseTask.setToolbarBtnFont(defaultFont); // For ToolbarButtons
        RolloverCommand.setDefaultFont(defaultFont);
    }
}

From source file:ch.zhaw.iamp.rct.ui.GrammarWindow.java

private void setEditorFontSizes(float fontSize) {
    Font currentFont = grammarTextPane.getFont();
    Font newFont = currentFont.deriveFont(fontSize);

    grammarTextPane.setFont(newFont);/*  w ww .ja  v  a2  s.  co m*/
    initialisationTextPane.setFont(newFont);
    initialisationOutputTextArea.setFont(newFont);
}

From source file:util.ui.PictureAreaIcon.java

/**
 * Constructor for programs with picture.
 *
 * @param p The program with the picture.
 * @param f The font for the description.
 * @param width The width of this area./*w w w  .  j  a  v a  2 s .c  o  m*/
 * @param showDescription If description should be shown.
 * @param grayFilter If the image should be filtered to gray if the program is expired.
 * @param zoom If the picture should be zoomed to width.
 */
public PictureAreaIcon(Program p, Font f, int width, boolean showDescription, boolean grayFilter,
        boolean zoom) {
    mProgram = p;
    mIsExpired = false;
    mIsGrayFilter = grayFilter;
    if (showDescription) {
        mDescriptionLines = Settings.propPictureDescriptionLines.getInt();
    } else {
        mDescriptionLines = 0;
    }

    byte[] picture = p.getBinaryField(ProgramFieldType.PICTURE_TYPE);

    if (picture != null) {
        ImageIcon imic = new ImageIcon(picture);

        if (width == -1) {
            width = imic.getIconWidth() + 6;
        }

        if (imic.getIconWidth() > width - 6 || (zoom && imic.getIconWidth() != width)) {
            mScaledIcon = (ImageIcon) UiUtilities.scaleIcon(imic, width - 6);
        } else {
            mScaledIcon = imic;
        }
    }

    mCopyrightText = new TextAreaIcon(p.getTextField(ProgramFieldType.PICTURE_COPYRIGHT_TYPE),
            f.deriveFont((float) (f.getSize() * 0.9)), width - 6);
    String pictureText = showDescription ? p.getTextField(ProgramFieldType.PICTURE_DESCRIPTION_TYPE) : "";
    if (StringUtils.isNotEmpty(pictureText)) {
        mDescriptionText = new TextAreaIcon(pictureText, f, width - 6);
        mDescriptionText.setMaximumLineCount(mDescriptionLines);
    } else {
        // reset show description as the string is empty
        mDescriptionLines = 0;
    }
}

From source file:org.underworldlabs.swing.plaf.base.AcceleratorToolTipUI.java

public void paint(Graphics g, JComponent c) {

    UIUtils.antialias(g);// w ww .  j a  va  2 s  .c om

    Font font = c.getFont();
    FontMetrics metrics = c.getFontMetrics(font);

    Dimension size = c.getSize();
    if (c.isOpaque()) {
        g.setColor(c.getBackground());
        g.fillRect(0, 0, size.width + 20, size.height);
    }

    JToolTip toolTip = (JToolTip) c;
    String tipText = getTipText(toolTip);

    if (!MiscUtils.isNull(tipText)) {

        Insets insets = c.getInsets();
        Rectangle paintTextR = new Rectangle(insets.left, insets.top, size.width - (insets.left + insets.right),
                size.height - (insets.top + insets.bottom));

        Color foreground = c.getForeground();
        g.setColor(foreground);
        g.setFont(font);

        g.drawString(tipText, paintTextR.x + 3, paintTextR.y + metrics.getAscent());

        String acceleratorString = getAcceleratorStringForRender(toolTip);
        if (StringUtils.isNotBlank(acceleratorString)) {

            Font acceleratorFont = font.deriveFont(font.getSize() - 1f);
            g.setFont(acceleratorFont);
            g.setColor(GUIUtils.getSlightlyBrighter(foreground, 2.0f));

            g.drawString(acceleratorString, paintTextR.x + 6 + metrics.stringWidth(tipText),
                    paintTextR.y + metrics.getAscent());
        }

    }

}

From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java

/**
 * //from  ww  w .  j a  va 2  s  .  c o m
 */
protected void showForm() {
    if (selectedForm != null) {
        if (formFrame != null) {
            formFrame.setVisible(false);
            formFrame.dispose();
        }

        formFrame = new JFrame();

        FormPanelInfo formPanelInfo = createPanel(selectedForm);
        JPanel panel = formPanelInfo.getPanel();

        JLabel label = new JLabel(formPanelInfo.getTitle(), SwingConstants.CENTER);
        Font font = label.getFont();

        label.setFont(font.deriveFont(14.0f).deriveFont(Font.BOLD));

        JPanel container = new JPanel(new BorderLayout());

        container.add(panel, BorderLayout.CENTER);
        container.add(label, BorderLayout.SOUTH);

        formFrame.setContentPane(container);

        panel.addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                //System.out.println(e.getPoint());
            }
        });

        formFrame.setVisible(true);
        formFrame.setSize(new Dimension(formPanelInfo.getMaxWidth() + 10, formPanelInfo.getMaxHeight() + 25));
    }
}

From source file:GUI.GraphicalInterface.java

/**
 * Set console (monospace) fonts in Terminal and Command Description.
 */// w w  w . j  a v a  2s .  c om
private void setFont() {
    try {
        InputStream is = GraphicalInterface.class.getResourceAsStream("/Resources/style/fonts/Inconsolata.otf");
        Font font = Font.createFont(Font.PLAIN, is);
        Font sizedFont = font.deriveFont(14f);

        terminalJTextArea.setFont(sizedFont);
        descriptionJTextArea.setFont(sizedFont);
        statusJLabel.setFont(sizedFont);
    } catch (FontFormatException ex) {
        Logger.getLogger(GraphicalInterface.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(GraphicalInterface.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:net.sf.jasperreports.engine.util.JRFontUtil.java

/**
 *
 *//*  w ww .  j  a v  a 2 s  . c  o  m*/
public static Font getAwtFontFromBundles(String name, int style, int size, Locale locale,
        boolean ignoreMissingFont) {
    Font awtFont = null;
    FontInfo fontInfo = getFontInfo(name, locale);

    if (fontInfo != null) {
        int faceStyle = Font.PLAIN;
        FontFamily family = fontInfo.getFontFamily();
        FontFace face = fontInfo.getFontFace();
        if (face == null) {
            if (((style & Font.BOLD) > 0) && ((style & Font.ITALIC) > 0)) {
                face = family.getBoldItalicFace();
                faceStyle = Font.BOLD | Font.ITALIC;
            }

            if (face == null && ((style & Font.BOLD) > 0)) {
                face = family.getBoldFace();
                faceStyle = Font.BOLD;
            }

            if (face == null && ((style & Font.ITALIC) > 0)) {
                face = family.getItalicFace();
                faceStyle = Font.ITALIC;
            }

            if (face == null) {
                face = family.getNormalFace();
                faceStyle = Font.PLAIN;
            }

            //            if (face == null)
            //            {
            //               throw new JRRuntimeException("Font family '" + family.getName() + "' does not have the normal font face.");
            //            }
        } else {
            faceStyle = fontInfo.getStyle();
        }

        if (face == null) {
            // The font family does not specify any font face, not even a normal one.
            // In such case, we take the family name and consider it as JVM available font name.
            checkAwtFont(family.getName(), ignoreMissingFont);

            awtFont = new Font(family.getName(), style, size);
        } else {
            awtFont = face.getFont();
            if (awtFont == null) {
                throw new JRRuntimeException("The '" + face.getName() + "' font face in family '"
                        + family.getName() + "' returns a null font.");
            }

            awtFont = awtFont.deriveFont((float) size);

            awtFont = awtFont.deriveFont(style & ~faceStyle);
        }
    }

    return awtFont;
}