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:playground.thibautd.analysis.joinabletripsidentifier.DataPloter.java

private void formatChart(final JFreeChart chart) {
    TextTitle title = chart.getTitle();/*  w ww  .  ja v  a  2 s.  co m*/
    Font font = title.getFont();
    title.setFont(font.deriveFont(TITLE_FONT_SIZE));
    chart.getPlot().setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f));
}

From source file:net.sf.jabref.gui.mergeentries.MergeEntries.java

private JLabel boldFontLabel(String text) {
    JLabel label = new JLabel(text);
    Font font = label.getFont();
    label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
    return label;
}

From source file:iqq.app.core.service.impl.SkinServiceImpl.java

/**
 * /*from  ww w  .j ava2  s. c  o m*/
 */
private void loadDefaultFont() {
    Font globalFont = null;
    try {
        String fontName = XmlUtils.getNodeText(getDefaultConfig(), "font/name");
        String fontSource = XmlUtils.getNodeText(getDefaultConfig(), "font/source");
        String fontFile = XmlUtils.getNodeText(getDefaultConfig(), "font/file");
        int fontSize = Integer.parseInt(XmlUtils.getNodeText(getSkinConfig(), "font/size"));
        if (fontSource.equals("file")) {
            Font font = loadFontFromFile(new File(DEFAULT_SKIN_DIR + fontFile));
            if (font != null) {
                globalFont = font.deriveFont((float) fontSize);
                setDefaultFont(globalFont);
            }
        } else if (fontSource.equals("system")) {
            globalFont = new Font(fontName, Font.PLAIN, fontSize);
            setDefaultFont(globalFont);
        } else {
            LOG.warn("unknown font source :" + fontSource);
        }
    } catch (DocumentException e) {
        LOG.warn("?", e);
    }
}

From source file:savant.export.ExportPlugin.java

private void setupGUI(JPanel panel) {

    panel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    //create padding
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 0;/*from  w  w  w.  j a  v a  2s .c om*/
    gbc.weighty = 0;
    gbc.gridx = 0;
    gbc.gridy = 0;
    JPanel fill1 = new JPanel();
    fill1.setPreferredSize(new Dimension(10, 10));
    panel.add(fill1, gbc);

    //create path chooser
    JLabel htmlLabel = new JLabel(
            "<html>Choose folder to save files.<br>An html index file will be created here.</html>");
    gbc.gridwidth = 2;
    gbc.gridx = 1;
    gbc.gridy = 1;
    panel.add(htmlLabel, gbc);
    pf = new PathField(JFileChooser.OPEN_DIALOG, false, true);
    gbc.gridx = 1;
    gbc.gridy = 2;
    panel.add(pf, gbc);

    //create runExport button
    JButton runButton = new JButton("Run");
    runButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            exportThread = new Thread("Export Plugin") {
                @Override
                public void run() {
                    try {
                        runTool();
                    } catch (InterruptedException ex) {
                        //TODO: deal with exception?
                        LOG.error("Export interrupted.", ex);
                    }
                }
            };
            exportThread.start();

            //create progress dialog
            Object[] options = { "Cancel" };
            progressPanel = new JOptionPane("     Running Export: 1");
            progressPanel.setOptions(options);
            progressDialog = progressPanel.createDialog("Export in progress");
            progressDialog.setVisible(true);
            if (progressPanel.getValue().equals("Cancel")) {
                exportCancelled = true;
            }

        }
    });
    gbc.weightx = 0;
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gbc.gridx = 1;
    gbc.gridy = 3;
    panel.add(runButton, gbc);

    //create output label
    outputLabel = new JLabel();
    Font f = outputLabel.getFont();
    outputLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
    gbc.gridx = 2;
    gbc.gridy = 3;
    panel.add(outputLabel, gbc);

    //create padding
    JPanel fill2 = new JPanel();
    fill2.setPreferredSize(new Dimension(10, 10));
    gbc.weightx = 1.0;
    gbc.gridwidth = 1;
    gbc.gridx = 2;
    gbc.gridy = 3;
    panel.add(fill2, gbc);

    JPanel fill3 = new JPanel();
    fill3.setPreferredSize(new Dimension(10, 10));
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.gridwidth = 2;
    gbc.gridx = 0;
    gbc.gridy = 4;
    panel.add(fill3, gbc);
}

From source file:org.piraso.ui.base.PreferencePanel.java

private void initPreferenceComponentsVerticalChildLayout() {
    CellConstraints c = new CellConstraints();

    int size = CollectionUtils.size(provider.getPreferences());

    int l = 0, r = 2;
    chkPreferences = new JCheckBox[size];
    preferenceKeys = new PreferenceProperty[size];

    JLabel lblHeader = new JLabel(provider.getName());
    Font of = lblHeader.getFont();
    lblHeader.setFont(of.deriveFont(Font.BOLD));

    pnlPreferences.add(lblHeader, c.xyw(2, r, 5));
    r += 2;//  www .j a  v a  2  s.c o m

    Iterator<? extends PreferenceProperty> itrp = provider.getPreferences().iterator();
    for (int j = 0; j < provider.getPreferences().size(); j++, l++) {
        PreferenceProperty prop = itrp.next();

        preferenceKeys[l] = prop;
        chkPreferences[l] = new JCheckBox();
        chkPreferences[l].setText(provider.getMessage(prop.getName()));
        chkPreferences[l].setSelected(prop.isDefaultValue());
        chkPreferences[l].addActionListener(new CheckBoxClickHandler(l));

        if (prop.isParent()) {
            chkPreferences[l].setFont(chkPreferences[l].getFont().deriveFont(Font.BOLD));
        }

        if (prop.isChild()) {
            pnlPreferences.add(chkPreferences[l], c.xy(6, r));
        } else {
            pnlPreferences.add(chkPreferences[l], c.xyw(4, r, 3));
        }

        r += 2;
    }
}

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

protected Font getFontSizeToFit(Graphics2D g, Font baseFont, String text, int width) {
    FontMetrics m = g.getFontMetrics(baseFont);
    int currentWidth = m.stringWidth(text);
    Font result = baseFont;

    int maxIter = 100;
    while (currentWidth > width && maxIter-- > 0) {
        result = result.deriveFont(result.getSize2D() * 0.95f);
        m = g.getFontMetrics(result);/*from  ww w  .  j  av a 2 s.c o  m*/
        currentWidth = m.stringWidth(text);
    }

    return result;
}

From source file:org.piraso.ui.base.PreferencePanel.java

private void initPreferenceComponentsHorizontalChildLayout() {
    handlers = new ArrayList<ParentChildHandler>();
    CellConstraints c = new CellConstraints();

    int size = CollectionUtils.size(provider.getPreferences());

    int l = 0, r = 2;
    chkPreferences = new JCheckBox[size];
    preferenceKeys = new PreferenceProperty[size];

    JLabel lblHeader = new JLabel(provider.getName());
    Font of = lblHeader.getFont();
    lblHeader.setFont(of.deriveFont(Font.BOLD));

    pnlPreferences.add(lblHeader, c.xyw(2, r, 5));
    r += 2;/*from  w  w w.j  ava 2 s .  c  o m*/

    JButton parentToggle = null;
    JPanel childrenPanel = null;
    ParentChildHandler parentChildHandler = null;

    Iterator<? extends PreferenceProperty> itrp = provider.getPreferences().iterator();
    for (int j = 0; j < provider.getPreferences().size(); j++, l++) {
        PreferenceProperty prop = itrp.next();

        preferenceKeys[l] = prop;
        chkPreferences[l] = new JCheckBox();
        chkPreferences[l].setText(provider.getMessage(prop.getName()));
        chkPreferences[l].setSelected(prop.isDefaultValue());

        if (prop.isChild()) {
            if (childrenPanel == null) {
                childrenPanel = new JPanel();
                childrenPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1));
                childrenPanel.setOpaque(false);
                childrenPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 1));
                childrenPanel.setVisible(false);

                if (parentChildHandler != null) {
                    parentChildHandler.setChildrenPanel(childrenPanel);
                }

                pnlPreferences.add(childrenPanel, c.xy(6, r));

                r += 2;
            }

            if (parentChildHandler != null) {
                parentChildHandler.addPreference(chkPreferences[l]);
            }

            childrenPanel.add(chkPreferences[l]);
            parentToggle = null;
        } else {
            if (parentToggle != null) {
                parentChildHandler.hide();
            }

            JPanel parentPanel = new JPanel();
            parentPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1));
            parentPanel.setOpaque(false);

            parentToggle = new JButton(expandImage);

            JLabel previewLabel = new JLabel();
            previewLabel.setForeground(new Color(0, 128, 0));
            previewLabel.setFont(previewLabel.getFont().deriveFont(Font.ITALIC));

            parentChildHandler = new ParentChildHandler(parentToggle, previewLabel);
            parentChildHandler.addPreference(chkPreferences[l]);
            handlers.add(parentChildHandler);

            parentToggle.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));

            parentPanel.add(parentToggle);
            parentPanel.add(chkPreferences[l]);
            parentPanel.add(previewLabel);

            pnlPreferences.add(parentPanel, c.xyw(4, r, 3));

            childrenPanel = null;
            r += 2;
        }

        chkPreferences[l].addActionListener(new CheckBoxClickHandler(l, parentChildHandler));
    }
}

From source file:Gui.HistoryAdminGUINew.java

public void showStatHistory() {
    // method statGreensociety......  History 
    int tempRepair = history.statGreensocietyRepair();
    int tempBorrow = history.statGreensocietyBorrow();
    int tempReturn = history.statGreensocietyReturn();
    DefaultCategoryDataset barchartData = new DefaultCategoryDataset();

    barchartData.setValue(tempRepair, "0", "RepairHistory");
    barchartData.setValue(tempBorrow, "1", "BorrowHistory");
    barchartData.setValue(tempReturn, "2", "ReturnHistory");

    JFreeChart chart = ChartFactory.createBarChart("History Statictics", "History", "Times", barchartData,
            PlotOrientation.HORIZONTAL, false, true, false);

    //        chart.getTitle().setPaint(Color.WHITE);   //??

    //--------SET FONT--------------
    try {/*from   w ww .  j  a v  a2 s .  c  om*/
        File f = new File("leelawad.ttf");
        Font customFont = Font.createFont(Font.TRUETYPE_FONT, f);
        customFont = customFont.deriveFont(16f);
        chart.getTitle().setFont(customFont);
        System.out.println(customFont.getFontName());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (FontFormatException | IOException e) {
        e.printStackTrace();
    }
    //------------------------------
    chart.setBackgroundPaint(new Color(19, 175, 248)); //setBackground ?

    CategoryPlot barchartPlot = chart.getCategoryPlot();

    barchartPlot.setRangeGridlinePaint(Color.BLACK); //set ??

    //Customize renderer
    BarRenderer renderer = (BarRenderer) barchartPlot.getRenderer();
    java.awt.Paint paint1 = new Color(255, 0, 0);
    java.awt.Paint paint2 = new Color(0, 0, 255);
    java.awt.Paint paint3 = new Color(255, 255, 0);

    renderer.setSeriesPaint(0, paint1); //Color for RepairGraph
    renderer.setSeriesPaint(1, paint2); //Color for BorrowGraph
    renderer.setSeriesPaint(2, paint3); //Color for ReturnGraph

    ChartPanel barPanel = new ChartPanel(chart);
    jPanelShowGraph.removeAll();
    jPanelShowGraph.add(barPanel, BorderLayout.CENTER);
    jPanelShowGraph.validate();
}

From source file:savant.plugin.Tool.java

@Override
public void init(JPanel panel) {
    mainPanel = panel;/*  w  w w  . ja va2s . co  m*/
    panel.setLayout(new CardLayout());

    JPanel settingsPanel = new ToolSettingsPanel(this);
    panel.add(new JScrollPane(settingsPanel), "Settings");

    JPanel waitCard = new JPanel();
    waitCard.setLayout(new GridBagLayout());

    // Left side filler.
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(5, 100, 0, 100);
    waitCard.add(new JLabel(getDescriptor().getName()), gbc);

    progressBar = new JProgressBar();
    progressBar.setPreferredSize(new Dimension(240, progressBar.getPreferredSize().height));
    waitCard.add(progressBar, gbc);

    progressInfo = new JLabel();
    progressInfo.setAlignmentX(1.0f);
    Font f = progressInfo.getFont();
    f = f.deriveFont(f.getSize() - 2.0f);
    progressInfo.setFont(f);
    waitCard.add(progressInfo, gbc);

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (toolProc != null) {
                Process p = toolProc;
                toolProc = null;
                p.destroy();
            }
            showCard("Settings");
        }
    });
    gbc.fill = GridBagConstraints.NONE;
    waitCard.add(cancelButton, gbc);

    // Console output at the bottom.
    console = new JTextArea();
    console.setFont(f);
    console.setLineWrap(false);
    console.setEditable(false);

    JScrollPane consolePane = new JScrollPane(console);
    consolePane.setPreferredSize(new Dimension(800, 200));
    gbc.weighty = 1.0;
    gbc.insets = new Insets(30, 5, 5, 5);
    gbc.fill = GridBagConstraints.BOTH;
    waitCard.add(consolePane, gbc);

    panel.add(waitCard, "Progress");
}

From source file:net.sf.taverna.raven.plugins.ui.CheckForUpdatesDialog.java

private void initComponents() {
    // Base font for all components on the form
    Font baseFont = new JLabel("base font").getFont().deriveFont(11f);

    // Message saying that updates are available
    JPanel messagePanel = new JPanel(new BorderLayout());
    messagePanel.setBorder(//  w  ww. j av  a  2 s.  c o  m
            new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder(EtchedBorder.LOWERED)));
    JLabel message = new JLabel(
            "<html><body>Updates are available for some Taverna components. To review and <br>install them go to 'Updates and plugins' in the 'Advanced' menu.</body><html>");
    message.setFont(baseFont.deriveFont(12f));
    message.setBorder(new EmptyBorder(5, 5, 5, 5));
    message.setIcon(UpdatesAvailableIcon.updateIcon);
    messagePanel.add(message, BorderLayout.CENTER);

    // Buttons
    JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton okButton = new JButton("OK"); // we'll check for updates again in 2 weeks
    okButton.setFont(baseFont);
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            okPressed();
        }
    });

    buttonsPanel.add(okButton);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(messagePanel, BorderLayout.CENTER);
    getContentPane().add(buttonsPanel, BorderLayout.SOUTH);

    pack();
    setResizable(false);
    // Center the dialog on the screen (we do not have the parent)
    Dimension dimension = getToolkit().getScreenSize();
    Rectangle abounds = getBounds();
    setLocation((dimension.width - abounds.width) / 2, (dimension.height - abounds.height) / 2);
    setSize(getPreferredSize());
}