Example usage for java.awt Font getFont

List of usage examples for java.awt Font getFont

Introduction

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

Prototype

public static Font getFont(String nm) 

Source Link

Document

Returns a Font object from the system properties list.

Usage

From source file:Main.java

public static FontMetrics getFontMetrics(Component component) {
    Font font = component.getFont();
    if (font == null) {
        font = Font.getFont(Font.DIALOG);
    }//from w  w w  .j av a2 s .c om
    return component.getFontMetrics(font);
}

From source file:com.ethercamp.harmony.desktop.HarmonyDesktop.java

private void showErrorWindow(String title, String body) {
    try {//from  w  w w .j a va  2 s. c om
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        //            System.setProperty("apple.awt.UIElement", "false");

        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

        JTextArea textArea = new JTextArea(body);
        JScrollPane scrollPane = new JScrollPane(textArea);
        textArea.setLineWrap(true);
        textArea.setFont(Font.getFont(Font.MONOSPACED));
        textArea.setEditable(false);
        textArea.setWrapStyleWord(true);
        scrollPane.setPreferredSize(new Dimension(500, 500));

        JTextPane titleLabel = new JTextPane();
        titleLabel.setContentType("text/html"); // let the text pane know this is what you want
        titleLabel.setText("<html>" + "<b>" + title + "</b>" + "</html>"); // showing off
        titleLabel.setEditable(false);
        titleLabel.setBackground(null);
        titleLabel.setBorder(null);

        panel.add(titleLabel);
        panel.add(scrollPane);

        final JFrame frame = new JFrame();
        frame.setAlwaysOnTop(true);
        moveCenter(frame);
        frame.setVisible(true);

        JOptionPane.showMessageDialog(frame, panel, "Oops. Ethereum Harmony stopped with error.",
                JOptionPane.CLOSED_OPTION);
        System.exit(1);
    } catch (Exception e) {
        log.error("Problem showing error window", e);
    }
}

From source file:net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.java

protected Font loadFont(Map<Attribute, Object> textAttributes) {
    // check bundled fonts
    FontUtil fontUtil = FontUtil.getInstance(context.getJasperReportsContext());
    Font font = fontUtil.getAwtFontFromBundles(fontKey.fontAttribute, fontKey.style, fontKey.size,
            fontKey.locale, false);/*from w  w  w.jav  a2  s .c om*/
    if (font == null) {
        // checking AWT font
        fontUtil.checkAwtFont(fontKey.fontAttribute.getFamily(), context.isIgnoreMissingFont());
        // creating AWT font
        // FIXME using the current text attributes might be slightly dangerous as we are sharing font metrics
        font = Font.getFont(textAttributes);
    }
    return font;
}

From source file:net.sf.jabref.gui.groups.GroupSelector.java

private void setEditMode(boolean editMode) {
    Globals.prefs.putBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE, editModeIndicator);
    editModeIndicator = editMode;// ww w . j  ava 2 s  .c o m

    if (editMode) {
        groupsTree.setBorder(
                BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.RED),
                        "Edit mode", TitledBorder.RIGHT, TitledBorder.TOP, Font.getFont("Default"), Color.RED));
        this.setTitle("<html><font color='red'>Groups Edit mode</font></html>");
    } else {
        groupsTree.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 0));
        this.setTitle(Localization.lang("Groups"));
    }
    groupsTree.revalidate();
    groupsTree.repaint();
}

From source file:com.raddle.tools.MergeMain.java

private void setCellRenderer(JList list) {
    list.setCellRenderer(new DefaultListCellRenderer() {

        private static final long serialVersionUID = 1L;

        @Override/*  ww  w.  j  a v  a 2 s  .c  om*/
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                PropertyLine line = (PropertyLine) value;
                boolean isInSelected = false;
                for (int selectedIndex : list.getSelectedIndices()) {
                    if (index == selectedIndex) {
                        isInSelected = true;
                    }
                }
                if (!isInSelected) {
                    if (CompareResult.extra == line.getCompareResult()) {
                        c.setBackground(new Color(0xFFC48E));
                    } else if (CompareResult.different == line.getCompareResult()) {
                        c.setBackground(new Color(0xBBBBFF));
                    }
                }
                if (line.getState() != null) {
                    if (LineState.added == line.getState()) {
                        c.setForeground(new Color(0xCC0033));
                    } else if (LineState.updated == line.getState()) {
                        c.setForeground(new Color(0x0066CC));
                    } else if (LineState.deleted == line.getState()) {
                        if (line.getOriginalValue() == null) {
                            c.setForeground(new Color(0xAAAAAA));
                        } else {
                            c.setForeground(new Color(0x666666));
                        }
                        Map<Attribute, Object> map = new HashMap<Attribute, Object>();
                        map.put(TextAttribute.FONT, c.getFont());
                        map.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
                        c.setFont(Font.getFont(map));
                    }
                }
            }
            return c;
        }

    });
}

From source file:org.n52.ifgicopter.spf.output.FileWriterPlugin.java

@Override
public void init() throws Exception {
    String time = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH_mm_ss").print(System.currentTimeMillis());
    this.file = new File("csv-logger-" + time + ".csv");
    boolean b = this.file.createNewFile();
    if (!b)//  ww  w .  ja  v  a 2s  .  c o m
        this.log.warn("File already exists!");

    this.firstRun = true;

    synchronized (this) {
        this.fos = new FileOutputStream(this.file);
    }

    this.gui = new ModuleGUI();
    this.panel = new JPanel(new BorderLayout());
    this.gui.setGui(this.panel);

    this.scrollLock = new JCheckBox("Scroll lock");
    this.scrollLock.setSelected(true);

    this.console = new JTextPane() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean getScrollableTracksViewportWidth() {
            return false;
        }
    };
    this.consoleDoc = this.console.getStyledDocument();

    this.console.setFont(Font.getFont(Font.MONOSPACED));
    this.console.setEditable(false);
    this.console.setBackground(Color.WHITE);

    JScrollPane jsp = new JScrollPane(this.console);

    jsp.setBackground(Color.white);

    this.panel.add(jsp);
    this.panel.add(this.scrollLock, BorderLayout.NORTH);
    this.panel.add(new JLabel("Writing to file '" + this.file.getAbsolutePath() + "'."), BorderLayout.SOUTH);
}

From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java

/**
 * //from w ww .j  a  v a2s .co  m
 * @return
 */
private JPanel makeGUI() {
    if (this.panel == null) {
        this.panel = new JPanel(new BorderLayout());
        JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
        JButton selectFileButton = new JButton(SELECT_GPX_FILE_TEXT);
        selectFileButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                selectGpxFileAction();
            }
        });
        controlPanel.add(selectFileButton);

        this.outputFileLabel = new JLabel();
        controlPanel.add(this.outputFileLabel);

        JButton saveFileButton = new JButton(SAVE_CURRENT_FILE_TEXT);
        saveFileButton.setToolTipText("Does also save manual changes undless model changes were made.");
        saveFileButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveCurrentFile();
            }
        });
        controlPanel.add(saveFileButton);

        // JCheckBox scrollLockCheckBox = new JCheckBox("scroll lock");
        // scrollLockCheckBox.setSelected(true);
        // scrollLockCheckBox.addActionListener(new ActionListener() {
        // @Override
        // public void actionPerformed(final ActionEvent e) {
        // EventQueue.invokeLater(new Runnable() {
        //
        // @Override
        // public void run() {
        // JCheckBox source = (JCheckBox) e.getSource();
        // // GpxOutputPlugin.this.textPane.setAutoscrolls(source.isSelected());
        // }
        // });
        // }
        // });
        // controlPanel.add(scrollLockCheckBox);

        this.panel.add(controlPanel, BorderLayout.NORTH);

        JPanel valuesPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT));
        DefaultListModel listModel = new DefaultListModel();
        listModel.addElement(NO_DATA_LIST_ELEMENT);
        this.valuesToSaveList = new JList(listModel);
        this.valuesToSaveList.setVisibleRowCount(2);
        this.valuesToSaveList
                .setToolTipText("Select (multiple) values to include in the GPX file [Multiple using <Ctrl>].");
        this.valuesToSaveList.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(final ListSelectionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        JList list = (JList) e.getSource();
                        // DefaultListModel listModel = (DefaultListModel) list.getModel();
                        Object[] selectedValues = list.getSelectedValues();
                        log.debug("New selection in value list:" + Arrays.toString(selectedValues));

                        GpxOutputPlugin.this.valuesToSave.clear();

                        for (Object o : selectedValues) {
                            if (o instanceof String) {
                                String s = (String) o;
                                if (!GpxOutputPlugin.this.valuesToSave.contains(s))
                                    GpxOutputPlugin.this.valuesToSave.add(s);
                            }
                        }
                    }
                });
            }
        });
        this.valuesToSaveList.setSize(200, 22);
        this.valuesToSaveList.setAlignmentY(Component.CENTER_ALIGNMENT);
        valuesPanel.add(new JLabel("Saved attributes:"));
        valuesPanel.add(this.valuesToSaveList);
        valuesPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
        this.panel.add(valuesPanel, BorderLayout.EAST);

        this.textPane = new XmlTextPane();
        this.textPane.setEditable(true);
        this.textPane.setFont(Font.getFont(Font.MONOSPACED));

        JScrollPane scrollPane = new JScrollPane(this.textPane);
        this.panel.add(scrollPane, BorderLayout.CENTER);
        JButton refreshTextFieldButton = new JButton("Update");
        refreshTextFieldButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        updateGUI();
                    }
                });
            }
        });
        this.panel.add(refreshTextFieldButton, BorderLayout.SOUTH);

        updateGUI();
    }

    return this.panel;
}

From source file:org.reactome.server.tools.diagram.exporter.raster.itext.awt.DefaultFontMapper.java

/**
 * Returns an AWT Font which can be used to represent the given BaseFont
 *
 * @param font the font to be converted//ww w.j  a va2s  . c om
 * @param size the desired point size of the resulting font
 *
 * @return a Font which has similar properties to the provided BaseFont
 */

public Font pdfToAwt(PdfFont font, int size) {
    final String fontName = font.getFontProgram().getFontNames().getFontName();
    //noinspection MagicConstant
    return Font.getFont(fontName).deriveFont(extractAwtStyle(font), size);
}