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:net.mariottini.swing.JFontChooser.java

/**
 * Sets the currently selected font. The dialog will try to change the listboxes selections
 * according to the font set.//from  w w w. j a  va2  s  . c o  m
 * 
 * @param font
 *          the font to select.
 */
public void setSelectedFont(Font font) {
    fontList.setSelectedValue(font.getFamily(), true);
    styleList.setSelectedIndex(font.getStyle());
    int size = font.getSize();
    int index = Arrays.binarySearch(SIZES, new Integer(size));
    if (index >= 0) {
        sizeList.setSelectedIndex(index);
        sizeList.ensureIndexIsVisible(index);
    } else {
        sizeText.setText(String.valueOf(size));
    }
}

From source file:org.openmicroscopy.shoola.env.data.util.StatusLabel.java

/** Initializes the components.*/
private void initialize() {
    step = 0;//from w w w .j  a  v  a 2  s  . c o  m
    sizeUpload = 0;
    fileSize = "";
    seriesCount = 0;
    readerType = "";
    markedAsCancel = false;
    cancellable = true;
    totalUploadedSize = 0;
    generalLabel = new JLabel(DEFAULT_TEXT);
    Font f = generalLabel.getFont();
    Font derived = f.deriveFont(f.getStyle(), f.getSize() - 2);
    uploadBar = new JProgressBar(0, MAX);
    uploadBar.setFont(derived);
    uploadBar.setStringPainted(true);
    Dimension d = uploadBar.getPreferredSize();
    uploadBar.setPreferredSize(new Dimension(WIDTH, d.height));
    processingBar = new JProgressBar(0, STEPS.size());
    processingBar.setStringPainted(true);
    processingBar.setString(DEFAULT_TEXT);
    processingBar.setFont(derived);
    uploadBar.setVisible(false);
    processingBar.setVisible(false);
}

From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java

@SuppressWarnings("unchecked") //$NON-NLS-1$
public void savePrefs() {
    if (form.getValidator() == null || form.getValidator().hasChanged()) {
        super.savePrefs(); // gets data from the UI

        Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) disciplineCBX.getComboBox().getSelectedItem();
        if (item != null) {
            AppPreferences.getRemote().put(getDisciplineImageName(), item.first); //$NON-NLS-1$

            IconManager.aliasImages(item.first, // Source
                    "collectionobject"); // Dest //$NON-NLS-1$
            IconManager.aliasImages(item.first, // Source
                    "CollectionObject"); // Dest //$NON-NLS-1$

        }//w w w. j av a 2  s .co m

        int inx = bnrIconSizeCBX.getComboBox().getSelectedIndex();
        if (inx > -1) {
            AppPreferences.getLocalPrefs().putInt(BNR_ICON_SIZE, pixelSizes[inx]);
        }

        AppPreferences local = AppPreferences.getLocalPrefs();

        if (!(UIHelper.isMacOS_10_5_X())) {
            String key = "ui.formatting.controlSizes"; //$NON-NLS-1$
            if (clearFontSettings) {
                local.remove(key + ".FN");
                local.remove(key + ".SZ");

                UIRegistry.setBaseFont(UIRegistry.getDefaultFont());
                BaseTask.setToolbarBtnFont(UIRegistry.getBaseFont()); // For ToolbarButtons
                RolloverCommand.setDefaultFont(UIRegistry.getBaseFont());

            } else {
                Font baseFont = UIRegistry.getBaseFont();
                if (!baseFont.getFamily().equals(fontNames.getSelectedItem())
                        || baseFont.getSize() != fontSizes.getSelectedIndex() + BASE_FONT_SIZE) {
                    Font newBaseFont = UIRegistry
                            .adjustPerDefaultFont(new Font((String) fontNames.getSelectedItem(), Font.PLAIN,
                                    fontSizes.getSelectedIndex() + BASE_FONT_SIZE));
                    UIRegistry.setBaseFont(newBaseFont);
                    BaseTask.setToolbarBtnFont(newBaseFont); // For ToolbarButtons
                    RolloverCommand.setDefaultFont(newBaseFont);

                    local.put(key + ".FN", (String) fontNames.getSelectedItem());
                    local.putInt(key + ".SZ", fontSizes.getSelectedIndex() + BASE_FONT_SIZE);
                }
            }

        } else {
            String key = "ui.formatting.controlSizes"; //$NON-NLS-1$
            UIHelper.setControlSize(controlSizesHash.get(controlSizes.getSelectedItem()));
            local.put(key, controlSizesHash.get(controlSizes.getSelectedItem()).toString());
        }

        String fType = formTypeHash.get(formTypesCBX.getComboBox().getSelectedItem()).toString();
        local.put("ui.formatting.formtype", fType);
    }
}

From source file:au.org.ala.delta.editor.ui.image.ImageSettingsDialog.java

private void updateFromFont(Font font, JComboBox name, JComboBox size, JCheckBox bold, JCheckBox italic) {
    name.getModel().setSelectedItem(font.getFamily());
    size.getModel().setSelectedItem(font.getSize());
    bold.setSelected(font.isBold());/*from w w w . j  av a2  s . co m*/
    italic.setSelected(font.isItalic());
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public void showVersionDialog() {
    GithubReleaseData data = GithubRepoUtils.getLatestRelease(GITHUB_REPO);
    String content = "";
    if (data != null && !VERSION.equals(data.getTagName())) {
        content = MessageBundle.get("dialogs.version.new", data.getTagName()) + "<br>" + "<a href=\""
                + data.getHtmlUrl() + "\">" + MessageBundle.get("dialogs.version.link") + "</a>";
    } else {//from  w  ww  .  j  a va2 s .co m
        content = MessageBundle.get("dialogs.version.uptodate");
    }
    Font font = getFont();
    JEditorPane pane = new JEditorPane("text/html",
            "<html><body style=\"font-family:" + font.getFamily() + ";font-size:" + font.getSize()
                    + "pt;text-align:center;width:200px;\">" + content + "</body></html>");
    pane.addHyperlinkListener(e -> {
        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
            try {
                Desktop.getDesktop().browse(e.getURL().toURI());
            } catch (Exception e1) {
                //
            }
        }
    });
    pane.setBackground(getBackground());
    pane.setEditable(false);
    showMessage(MessageBundle.get("dialogs.version.title"), pane);
}

From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java

/**
 * Returns the component displaying the description of the script.
 *
 * @return See above./*from www.  j  a va2 s  . c o m*/
 */
private JComponent buildDescriptionPane() {
    String description = script.getDescription();
    if (StringUtils.isBlank(description))
        return null;
    OMEWikiComponent area = new OMEWikiComponent(false);
    area.setEnabled(false);
    area.setText(description);
    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    JLabel label = UIUtilities.setTextFont(script.getName());
    Font f = label.getFont();
    label.setFont(f.deriveFont(f.getStyle(), f.getSize() + 2));
    content.add(UIUtilities.buildComponentPanel(label));
    content.add(Box.createVerticalStrut(5));
    JPanel p = UIUtilities.buildComponentPanel(area);
    p.setBackground(BG_COLOR);
    area.setBackground(BG_COLOR);
    content.add(p);
    return content;
}

From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java

/**
 * Builds the component displaying the parameters.
 *
 * @return See above.//from  w w w  .  j av  a 2  s  . co m
 */
private JPanel buildBody() {
    JPanel p = new JPanel();
    p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    double[] columns = { TableLayout.PREFERRED, 5, TableLayout.FILL };
    TableLayout layout = new TableLayout();
    layout.setColumn(columns);
    p.setLayout(layout);
    int row = 0;
    JComponent area = buildDescriptionPane();
    JComponent authorsPane = buildScriptDetails();
    if (area != null) {
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(area, "0," + row + ", 2, " + row);
        row++;
    }

    if (authorsPane != null) {
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(authorsPane, "0," + row + ", 2, " + row);
        row++;
    }
    layout.insertRow(row, 5);

    row++;
    Entry<String, ScriptComponent> entry;
    Iterator<Entry<String, ScriptComponent>> i = components.entrySet().iterator();
    ScriptComponent comp;
    int required = 0;
    while (i.hasNext()) {
        entry = i.next();
        comp = entry.getValue();
        layout.insertRow(row, TableLayout.PREFERRED);
        comp.buildUI();
        if (comp.isRequired())
            required++;
        p.add(comp, "0," + row + ", 2, " + row);
        row++;
        layout.insertRow(row, 2);
        row++;
    }
    if (required > 0) {
        JLabel label = new JLabel(TEXT_END);
        Font font = label.getFont();
        label.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2));
        label.setForeground(UIUtilities.REQUIRED_FIELDS_COLOR);
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(UIUtilities.buildComponentPanel(label), "0," + row + ",2, " + row);
    }

    JPanel controls = new JPanel();
    controls.setLayout(new BorderLayout(0, 0));
    controls.add(new JScrollPane(p), BorderLayout.CENTER);
    controls.add(buildControlPanel(), BorderLayout.SOUTH);
    return controls;
}

From source file:org.eclipse.wb.tests.designer.swing.model.property.FontPropertyEditorTest.java

/**
 * Test for {@link DerivedFontInfo}.//from   ww w  .j  a v a  2 s.c o m
 */
public void test_FontInfo_Derived() throws Exception {
    Font baseFont = new Font("Arial", Font.BOLD, 12);
    String baseFontSource = "button.getFont()";
    String baseFontClipboardSource = "%this%.getFont()";
    // no changes
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null,
                null, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("<no changes>, Arial 12 Bold", fontInfo.getText());
        assertNull(fontInfo.getSource());
        assertNull(fontInfo.getClipboardSource());
    }
    // new family
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, "Tahoma",
                null, null, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Tahoma", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("*Tahoma, Tahoma 12 Bold", fontInfo.getText());
        assertEquals("new java.awt.Font(\"Tahoma\", button.getFont().getStyle(), button.getFont().getSize())",
                fontInfo.getSource());
        assertEquals("new java.awt.Font(\"Tahoma\", %this%.getFont().getStyle(), %this%.getFont().getSize())",
                fontInfo.getClipboardSource());
    }
    // new family +5
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, "Tahoma",
                null, null, new Integer(5), null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Tahoma", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(17, font.getSize());
        }
        assertEquals("*Tahoma +5, Tahoma 17 Bold", fontInfo.getText());
        assertEquals(
                "new java.awt.Font(\"Tahoma\", button.getFont().getStyle(), button.getFont().getSize() + 5)",
                fontInfo.getSource());
        assertEquals(
                "new java.awt.Font(\"Tahoma\", %this%.getFont().getStyle(), %this%.getFont().getSize() + 5)",
                fontInfo.getClipboardSource());
    }
    // new family =20
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, "Tahoma",
                null, null, null, new Integer(20));
        {
            Font font = fontInfo.getFont();
            assertEquals("Tahoma", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(20, font.getSize());
        }
        assertEquals("*Tahoma 20, Tahoma 20 Bold", fontInfo.getText());
        assertEquals("new java.awt.Font(\"Tahoma\", button.getFont().getStyle(), 20)", fontInfo.getSource());
    }
    // +Bold
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null,
                Boolean.TRUE, null, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("+Bold, Arial 12 Bold", fontInfo.getText());
        assertEquals("button.getFont().deriveFont(button.getFont().getStyle() | java.awt.Font.BOLD)",
                fontInfo.getSource());
    }
    // -Bold
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null,
                Boolean.FALSE, null, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.PLAIN, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("-Bold, Arial 12", fontInfo.getText());
        assertEquals("button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.BOLD)",
                fontInfo.getSource());
    }
    // +Italic
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null,
                Boolean.TRUE, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD | Font.ITALIC, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("+Italic, Arial 12 Bold Italic", fontInfo.getText());
        assertEquals("button.getFont().deriveFont(button.getFont().getStyle() | java.awt.Font.ITALIC)",
                fontInfo.getSource());
    }
    // -Italic
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null,
                Boolean.FALSE, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("-Italic, Arial 12 Bold", fontInfo.getText());
        assertEquals("button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.ITALIC)",
                fontInfo.getSource());
    }
    // +Bold +Italic
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null,
                Boolean.TRUE, Boolean.TRUE, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD | Font.ITALIC, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("+Bold +Italic, Arial 12 Bold Italic", fontInfo.getText());
        assertEquals(
                "button.getFont().deriveFont(button.getFont().getStyle() | java.awt.Font.BOLD | java.awt.Font.ITALIC)",
                fontInfo.getSource());
    }
    // -Bold +Italic
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null,
                Boolean.FALSE, Boolean.TRUE, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.ITALIC, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("-Bold +Italic, Arial 12 Italic", fontInfo.getText());
        assertEquals(
                "button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.BOLD | java.awt.Font.ITALIC)",
                fontInfo.getSource());
    }
    // +Bold -Italic
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null,
                Boolean.TRUE, Boolean.FALSE, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("+Bold -Italic, Arial 12 Bold", fontInfo.getText());
        assertEquals(
                "button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.ITALIC | java.awt.Font.BOLD)",
                fontInfo.getSource());
    }
    // -Bold -Italic
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null,
                Boolean.FALSE, Boolean.FALSE, null, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.PLAIN, font.getStyle());
            assertEquals(12, font.getSize());
        }
        assertEquals("-Bold -Italic, Arial 12", fontInfo.getText());
        assertEquals(
                "button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.BOLD & ~java.awt.Font.ITALIC)",
                fontInfo.getSource());
    }
    // +5
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null,
                null, +5, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(12 + 5, font.getSize());
        }
        assertEquals("+5, Arial 17 Bold", fontInfo.getText());
        assertEquals("button.getFont().deriveFont(button.getFont().getSize() + 5f)", fontInfo.getSource());
    }
    // -5
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null,
                null, -5, null);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(12 - 5, font.getSize());
        }
        assertEquals("-5, Arial 7 Bold", fontInfo.getText());
        assertEquals("button.getFont().deriveFont(button.getFont().getSize() - 5f)", fontInfo.getSource());
    }
    // =20
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null,
                null, null, 20);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(20, font.getSize());
        }
        assertEquals("20, Arial 20 Bold", fontInfo.getText());
        assertEquals("button.getFont().deriveFont(20f)", fontInfo.getSource());
    }
    // -Bold =20
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null,
                Boolean.FALSE, null, null, 20);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.PLAIN, font.getStyle());
            assertEquals(20, font.getSize());
        }
        assertEquals("20 -Bold, Arial 20", fontInfo.getText());
        assertEquals("button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.BOLD, 20f)",
                fontInfo.getSource());
    }
    // -Italic =20
    {
        FontInfo fontInfo = new DerivedFontInfo(baseFont, baseFontSource, baseFontClipboardSource, null, null,
                Boolean.FALSE, null, 20);
        {
            Font font = fontInfo.getFont();
            assertEquals("Arial", font.getFamily());
            assertEquals(Font.BOLD, font.getStyle());
            assertEquals(20, font.getSize());
        }
        assertEquals("20 -Italic, Arial 20 Bold", fontInfo.getText());
        assertEquals("button.getFont().deriveFont(button.getFont().getStyle() & ~java.awt.Font.ITALIC, 20f)",
                fontInfo.getSource());
    }
}

From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java

private void fontSizeIncreaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontSizeIncreaseButtonActionPerformed
    MyTreeNodeRenderer renderer = (MyTreeNodeRenderer) projectTree.getCellRenderer();
    Font oldFont = renderer.getFont();
    Font font = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize() + 1);
    renderer.setFont(font);/*from   w  w  w  .  j  a  v  a  2 s  .  c o  m*/
    projectTree.updateUI();
    NbPreferences.forModule(this.getClass()).putInt("font", font.getSize());
}

From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java

private void fontSizeDecreaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontSizeDecreaseButtonActionPerformed
    MyTreeNodeRenderer renderer = (MyTreeNodeRenderer) projectTree.getCellRenderer();
    Font oldFont = renderer.getFont();
    Font font = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize() - 1);
    renderer.setFont(font);/*from ww w  .java 2 s  .  co  m*/
    projectTree.updateUI();
    NbPreferences.forModule(this.getClass()).putInt("font", font.getSize());
}