Example usage for java.awt Font getFamily

List of usage examples for java.awt Font getFamily

Introduction

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

Prototype

public String getFamily() 

Source Link

Document

Returns the family name of this Font .

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.//ww w . ja  v  a  2 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: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$

        }/*from  www . j  a  v a  2s . c o  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:org.tinymediamanager.ui.movies.settings.MovieScraperSettingsPanel.java

/**
 * Instantiates a new movie scraper settings panel.
 *//*from  w w  w .j ava  2  s  . c o m*/
public MovieScraperSettingsPanel() {
    // data init
    MediaScraper defaultMediaScraper = MovieList.getInstance().getDefaultMediaScraper();
    int selectedIndex = 0;
    int counter = 0;
    for (MediaScraper scraper : MovieList.getInstance().getAvailableMediaScrapers()) {
        MovieScraper movieScraper = new MovieScraper(scraper);
        if (scraper.equals(defaultMediaScraper)) {
            movieScraper.defaultScraper = true;
            selectedIndex = counter;
        }
        scrapers.add(movieScraper);
        counter++;
    }
    // UI init
    setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
            FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    RowSpec.decode("default:grow"), }));
    JPanel panelMovieScrapers = new JPanel();
    panelMovieScrapers.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            BUNDLE.getString("scraper.metadata"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); // $NON-NLS-1$
    add(panelMovieScrapers, "2, 2, 3, 1, fill, fill");
    panelMovieScrapers.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC,
            FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("50dlu:grow"),
            FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("200dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("150dlu:grow"),
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, }));

    scrollPaneScraper = new JScrollPane();
    panelMovieScrapers.add(scrollPaneScraper, "2, 2, 3, 1, fill, fill");

    tableScraper = new JTable() {
        private static final long serialVersionUID = -144223066269069772L;

        @Override
        public java.awt.Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
            java.awt.Component comp = super.prepareRenderer(renderer, row, col);
            String value = getModel().getValueAt(row, 2).toString();
            if (!Globals.isDonator() && value.startsWith("Kodi")) { // FIXME: use scraper.isEnabled() somehow?
                comp.setBackground(Color.lightGray);
                comp.setEnabled(false);
            } else {
                comp.setBackground(Color.white);
                comp.setEnabled(true);
            }
            return comp;
        }
    };
    tableScraper.setRowHeight(29);
    scrollPaneScraper.setViewportView(tableScraper);

    scrollPane = new JScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(null);
    panelMovieScrapers.add(scrollPane, "6, 1, 1, 7, fill, fill");

    panelScraperDetails = new ScrollablePanel();
    scrollPane.setViewportView(panelScraperDetails);
    panelScraperDetails
            .setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"), }, new RowSpec[] {
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));
    {
        // add a CSS rule to force body tags to use the default label font
        // instead of the value in javax.swing.text.html.default.csss
        Font font = UIManager.getFont("Label.font");
        String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize()
                + "pt; }";

        tpScraperDescription = new JTextPane();
        tpScraperDescription.setOpaque(false);
        tpScraperDescription.setEditorKit(new HTMLEditorKit());
        ((HTMLDocument) tpScraperDescription.getDocument()).getStyleSheet().addRule(bodyRule);
        panelScraperDetails.add(tpScraperDescription, "1, 1, default, top");
    }

    panelScraperOptions = new JPanel();
    panelScraperOptions.setLayout(new FlowLayout(FlowLayout.LEFT));
    panelScraperDetails.add(panelScraperOptions, "1, 3, fill, top");

    JSeparator separator = new JSeparator();
    panelMovieScrapers.add(separator, "2, 4, 3, 1");

    JLabel lblScraperLanguage = new JLabel(BUNDLE.getString("Settings.preferredLanguage")); //$NON-NLS-1$
    panelMovieScrapers.add(lblScraperLanguage, "2, 5, right, default");

    cbScraperLanguage = new JComboBox(MediaLanguages.values());
    panelMovieScrapers.add(cbScraperLanguage, "4, 5");

    JLabel lblCountry = new JLabel(BUNDLE.getString("Settings.certificationCountry")); //$NON-NLS-1$
    panelMovieScrapers.add(lblCountry, "2, 7, right, default");

    cbCertificationCountry = new JComboBox(CountryCode.values());
    panelMovieScrapers.add(cbCertificationCountry, "4, 7, fill, default");
    panelMovieScrapers.add(new JSeparator(), "2, 8, 5, 1");

    chckbxScraperFallback = new JCheckBox(BUNDLE.getString("Settings.scraperfallback")); //$NON-NLS-1$
    panelMovieScrapers.add(chckbxScraperFallback, "2, 9, 5, 1");

    panelScraperMetadataContainer = new JPanel();
    panelScraperMetadataContainer.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            BUNDLE.getString("scraper.metadata.defaults"), TitledBorder.LEADING, TitledBorder.TOP, null, //$NON-NLS-1$
            new Color(51, 51, 51)));
    add(panelScraperMetadataContainer, "2, 4, fill, fill");
    panelScraperMetadataContainer.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("10dlu"),
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), },
            new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                    FormFactory.DEFAULT_ROWSPEC, FormFactory.NARROW_LINE_GAP_ROWSPEC,
                    FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, }));

    panelScraperMetadata = new MovieScraperMetadataPanel(
            Settings.getInstance().getMovieScraperMetadataConfig());
    panelScraperMetadataContainer.add(panelScraperMetadata, "1, 1, 4, 1, fill, default");

    chckbxAutomaticallyScrapeImages = new JCheckBox(BUNDLE.getString("Settings.default.autoscrape")); //$NON-NLS-1$
    panelScraperMetadataContainer.add(chckbxAutomaticallyScrapeImages, "2, 3, 3, 1");

    chckbxImageLanguage = new JCheckBox(BUNDLE.getString("Settings.default.autoscrape.language"));//$NON-NLS-1$
    panelScraperMetadataContainer.add(chckbxImageLanguage, "4, 5");

    panelAutomaticScraper = new JPanel();
    panelAutomaticScraper.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.automaticscraper"), //$NON-NLS-1$
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    add(panelAutomaticScraper, "4, 4, fill, fill");
    panelAutomaticScraper.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("default:grow"), },
            new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, }));

    JLabel lblScraperTreshold = new JLabel(BUNDLE.getString("Settings.scraperTreshold")); //$NON-NLS-1$
    panelAutomaticScraper.add(lblScraperTreshold, "1, 2, default, top");

    sliderThreshold = new JSlider();
    sliderThreshold.setMinorTickSpacing(5);
    sliderThreshold.setMajorTickSpacing(10);
    sliderThreshold.setPaintTicks(true);
    sliderThreshold.setPaintLabels(true);
    sliderThreshold.setValue((int) (settings.getScraperThreshold() * 100));

    Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<>();
    labelTable.put(100, new JLabel("1.0"));
    labelTable.put(75, new JLabel("0.75"));
    labelTable.put(50, new JLabel("0.50"));
    labelTable.put(25, new JLabel("0.25"));
    labelTable.put(0, new JLabel("0.0"));
    sliderThreshold.setLabelTable(labelTable);
    sliderThreshold.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent arg0) {
            settings.setScraperThreshold(sliderThreshold.getValue() / 100.0);
        }
    });
    panelAutomaticScraper.add(sliderThreshold, "3, 2");

    lblScraperThresholdHint = new JTextPane();
    panelAutomaticScraper.add(lblScraperThresholdHint, "1, 6, 3, 1");
    lblScraperThresholdHint.setOpaque(false);
    TmmFontHelper.changeFont(lblScraperThresholdHint, 0.833);
    lblScraperThresholdHint.setText(BUNDLE.getString("Settings.scraperTreshold.hint")); //$NON-NLS-1$

    initDataBindings();

    // adjust table columns
    // Checkbox and Logo shall have minimal width
    TableColumnResizer.setMaxWidthForColumn(tableScraper, 0, 2);
    TableColumnResizer.setMaxWidthForColumn(tableScraper, 1, 2);
    TableColumnResizer.adjustColumnPreferredWidths(tableScraper, 5);

    // implement listener to simulate button group
    tableScraper.getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent arg0) {
            // click on the checkbox
            if (arg0.getColumn() == 0) {
                int row = arg0.getFirstRow();
                MovieScraper changedScraper = scrapers.get(row);
                // if flag default scraper was changed, change all other flags
                if (changedScraper.getDefaultScraper()) {
                    settings.setMovieScraper(changedScraper.getScraperId());
                    for (MovieScraper scraper : scrapers) {
                        if (scraper != changedScraper) {
                            scraper.setDefaultScraper(Boolean.FALSE);
                        }
                    }
                }
            }
        }
    });

    // implement selection listener to load settings
    tableScraper.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            int index = tableScraper.convertRowIndexToModel(tableScraper.getSelectedRow());
            if (index > -1) {
                panelScraperOptions.removeAll();
                if (scrapers.get(index).getMediaProvider().getProviderInfo().getConfig().hasConfig()) {
                    panelScraperOptions
                            .add(new MediaScraperConfigurationPanel(scrapers.get(index).getMediaProvider()));
                }
                panelScraperOptions.revalidate();
            }
        }
    });

    // select default movie scraper
    if (counter > 0) {
        tableScraper.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex);
    }
}

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  .  java  2s  .c  o  m
    italic.setSelected(font.isItalic());
}

From source file:org.docx4j.fonts.fop.fonts.FontInfo.java

/**
 * Returns a suitable internal font given an AWT Font instance.
 *
 * @param awtFont the AWT font/* w w  w  . j a v  a  2 s.  c om*/
 * @return a best matching internal Font
 */
public Font getFontInstanceForAWTFont(java.awt.Font awtFont) {
    String awtFontName = awtFont.getName();
    String awtFontFamily = awtFont.getFamily();
    String awtFontStyle = awtFont.isItalic() ? Font.STYLE_ITALIC : Font.STYLE_NORMAL;
    int awtFontWeight = awtFont.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL;

    FontTriplet matchedTriplet = null;
    List/*<FontTriplet>*/ triplets = getTripletsForName(awtFontName);
    if (!triplets.isEmpty()) {
        Iterator it = triplets.iterator();
        while (it.hasNext()) {
            FontTriplet triplet = (FontTriplet) it.next();
            boolean styleMatched = triplet.getStyle().equals(awtFontStyle);
            boolean weightMatched = triplet.getWeight() == awtFontWeight;
            if (styleMatched && weightMatched) {
                matchedTriplet = triplet;
                break;
            }
        }
    }

    // not matched on font name so do a lookup using family
    if (matchedTriplet == null) {
        if (awtFontFamily.equals("sanserif")) {
            awtFontFamily = "sans-serif";
        }
        matchedTriplet = fontLookup(awtFontFamily, awtFontStyle, awtFontWeight);
    }
    int fontSize = Math.round(awtFont.getSize2D() * 1000);
    return getFontInstance(matchedTriplet, fontSize);
}

From source file:org.eclipse.wb.internal.swing.model.property.editor.font.DerivedFontInfo.java

public DerivedFontInfo(Font baseFont, String baseFontSource, String baseFontClipboardSource, String newFamily,
        Boolean newBold, Boolean newItalic, Integer deltaSize, Integer newSize) {
    m_baseFont = baseFont;//from w w  w.  ja v  a 2s .  c  o  m
    m_baseFontSource = baseFontSource;
    m_baseFontClipboardSource = baseFontClipboardSource;
    m_newFamily = newFamily;
    m_newBold = newBold;
    m_newItalic = newItalic;
    m_deltaSize = deltaSize;
    m_newSize = newSize;
    // create derived Font
    {
        String family = newFamily != null ? newFamily : baseFont.getFamily();
        // style
        int style = baseFont.getStyle();
        if (newBold != null) {
            if (newBold.booleanValue()) {
                style |= Font.BOLD;
            } else {
                style &= ~Font.BOLD;
            }
        }
        if (newItalic != null) {
            if (newItalic.booleanValue()) {
                style |= Font.ITALIC;
            } else {
                style &= ~Font.ITALIC;
            }
        }
        // size
        int size = baseFont.getSize();
        if (deltaSize != null) {
            size += deltaSize.intValue();
        } else if (newSize != null) {
            size = newSize.intValue();
        }
        // create derived Font
        m_font = new Font(family, style, size);
    }
}

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

/**
 * Test for {@link DerivedFontInfo}./*from   w ww . j  a  v a  2  s  .  c  om*/
 */
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.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 {/*  w  ww  .  ja  v  a 2  s  .com*/
        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:ca.sqlpower.wabit.dao.WorkspaceXMLDAO.java

/**
 * This will save a font to the print writer. The font tag must be contained within tags of 
 * the font's parent object. This allows giving a specific font name for the XML tag.
 *//*from w  w  w  .jav  a  2  s. c o m*/
private void saveFont(Font font, String fontName) {
    xml.print(out, "<" + fontName);
    printAttribute("name", font.getFamily());
    printAttribute("size", font.getSize());
    printAttribute("style", font.getStyle());
    xml.niprintln(out, "/>");
}

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

/**
 * Create the UI for the panel//w  w  w . j a  va  2 s  .  c o m
 */
protected void createUI() {
    createForm("Preferences", "Formatting"); //$NON-NLS-1$ //$NON-NLS-2$

    UIValidator.setIgnoreAllValidation(this, true);

    JLabel fontNamesLabel = form.getLabelFor("fontNames"); //$NON-NLS-1$
    ValComboBox fontNamesVCB = form.getCompById("fontNames"); //$NON-NLS-1$

    JLabel fontSizesLabel = form.getLabelFor("fontSizes"); //$NON-NLS-1$
    ValComboBox fontSizesVCB = form.getCompById("fontSizes"); //$NON-NLS-1$

    JLabel controlSizesLabel = form.getLabelFor("controlSizes"); //$NON-NLS-1$
    ValComboBox controlSizesVCB = form.getCompById("controlSizes"); //$NON-NLS-1$

    formTypesCBX = form.getCompById("formtype"); //$NON-NLS-1$

    fontNames = fontNamesVCB.getComboBox();
    fontSizes = fontSizesVCB.getComboBox();
    controlSizes = controlSizesVCB.getComboBox();

    testField = form.getCompById("fontTest"); //$NON-NLS-1$
    if (testField != null) {
        testField.setText(UIRegistry.getResourceString("FormattingPrefsPanel.THIS_TEST")); //$NON-NLS-1$
    }
    if (UIHelper.isMacOS_10_5_X()) {
        fontNamesLabel.setVisible(false);
        fontNamesVCB.setVisible(false);
        fontSizesLabel.setVisible(false);
        fontSizesVCB.setVisible(false);
        testField.setVisible(false);

        int inx = -1;
        int i = 0;
        Vector<String> controlSizeTitles = new Vector<String>();
        for (UIHelper.CONTROLSIZE cs : UIHelper.CONTROLSIZE.values()) {
            String titleStr = getResourceString(cs.toString());
            controlSizeTitles.add(titleStr);
            controlSizesHash.put(titleStr, cs);
            controlSizes.addItem(titleStr);
            if (cs == UIHelper.getControlSize()) {
                inx = i;
            }
            i++;
        }
        controlSizes.setSelectedIndex(inx);

        Font baseFont = UIRegistry.getBaseFont();
        if (baseFont != null) {
            fontNames.addItem(baseFont.getFamily());
            fontSizes.addItem(Integer.toString(baseFont.getSize()));
            fontNames.setSelectedIndex(0);
            fontSizes.setSelectedIndex(0);
        }

    } else {
        controlSizesLabel.setVisible(false);
        controlSizesVCB.setVisible(false);

        Hashtable<String, Boolean> namesUsed = new Hashtable<String, Boolean>();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        for (Font font : ge.getAllFonts()) {
            if (namesUsed.get(font.getFamily()) == null) {
                fontNames.addItem(font.getFamily());
                namesUsed.put(font.getFamily(), true); //$NON-NLS-1$
            }
        }
        for (int i = BASE_FONT_SIZE; i < 22; i++) {
            fontSizes.addItem(Integer.toString(i));
        }

        Font baseFont = UIRegistry.getBaseFont();
        if (baseFont != null) {
            fontNames.setSelectedItem(baseFont.getFamily());
            fontSizes.setSelectedItem(Integer.toString(baseFont.getSize()));

            if (testField != null) {
                ActionListener al = new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        testField.setFont(new Font((String) fontNames.getSelectedItem(), Font.PLAIN,
                                fontSizes.getSelectedIndex() + BASE_FONT_SIZE));
                        form.getUIComponent().validate();
                        clearFontSettings = false;
                    }
                };
                fontNames.addActionListener(al);
                fontSizes.addActionListener(al);
            }
        }
    }

    //-----------------------------------
    // Do DisciplineType Icons
    //-----------------------------------

    String iconName = AppPreferences.getRemote().get(getDisciplineImageName(), "CollectionObject"); //$NON-NLS-1$ //$NON-NLS-2$

    List<Pair<String, ImageIcon>> list = IconManager.getListByType("disciplines", IconManager.IconSize.Std16); //$NON-NLS-1$
    Collections.sort(list, new Comparator<Pair<String, ImageIcon>>() {
        public int compare(Pair<String, ImageIcon> o1, Pair<String, ImageIcon> o2) {
            String s1 = UIRegistry.getResourceString(o1.first);
            String s2 = UIRegistry.getResourceString(o2.first);
            return s1.compareTo(s2);
        }
    });

    disciplineCBX = (ValComboBox) form.getCompById("disciplineIconCBX"); //$NON-NLS-1$

    final JLabel dispLabel = form.getCompById("disciplineIcon"); //$NON-NLS-1$
    JComboBox comboBox = disciplineCBX.getComboBox();
    comboBox.setRenderer(new DefaultListCellRenderer() {
        @SuppressWarnings("unchecked") //$NON-NLS-1$
        public Component getListCellRendererComponent(JList listArg, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) value;
            JLabel label = (JLabel) super.getListCellRendererComponent(listArg, value, index, isSelected,
                    cellHasFocus);
            if (item != null) {
                label.setIcon(item.second);
                label.setText(UIRegistry.getResourceString(item.first));
            }
            return label;
        }
    });

    int inx = 0;
    Pair<String, ImageIcon> colObj = new Pair<String, ImageIcon>("colobj_backstop", //$NON-NLS-1$
            IconManager.getIcon("colobj_backstop", IconManager.IconSize.Std16)); //$NON-NLS-1$
    comboBox.addItem(colObj);

    int cnt = 1;
    for (Pair<String, ImageIcon> item : list) {
        if (item.first.equals(iconName)) {
            inx = cnt;
        }
        comboBox.addItem(item);
        cnt++;
    }

    comboBox.addActionListener(new ActionListener() {
        @SuppressWarnings("unchecked") //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            JComboBox cbx = (JComboBox) e.getSource();
            Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) cbx.getSelectedItem();
            if (item != null) {
                dispLabel.setIcon(IconManager.getIcon(item.first));
                form.getUIComponent().validate();
            }
        }
    });

    comboBox.setSelectedIndex(inx);

    //-----------------------------------
    // Date Field
    //-----------------------------------
    dateFieldCBX = form.getCompById("scrdateformat"); //$NON-NLS-1$
    fillDateFormat();

    //-----------------------------------
    // FormType
    //-----------------------------------
    fillFormTypes();

    //-----------------------------------
    // Do App Icon
    //-----------------------------------

    final JButton getIconBtn = form.getCompById("GetIconImage"); //$NON-NLS-1$
    final JButton clearIconBtn = form.getCompById("ClearIconImage"); //$NON-NLS-1$
    final JLabel appLabel = form.getCompById("appIcon"); //$NON-NLS-1$
    final JButton resetDefFontBtn = form.getCompById("ResetDefFontBtn"); //$NON-NLS-1$

    String imgEncoded = AppPreferences.getRemote().get(iconImagePrefName, ""); //$NON-NLS-1$
    ImageIcon innerAppImgIcon = null;
    if (StringUtils.isNotEmpty(imgEncoded)) {
        innerAppImgIcon = GraphicsUtils.uudecodeImage("", imgEncoded); //$NON-NLS-1$
        if (innerAppImgIcon != null && innerAppImgIcon.getIconWidth() != 32
                || innerAppImgIcon.getIconHeight() != 32) {
            innerAppImgIcon = null;
            clearIconBtn.setEnabled(false);
        } else {
            clearIconBtn.setEnabled(true);
        }
    }

    if (innerAppImgIcon == null) {
        innerAppImgIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$
        clearIconBtn.setEnabled(false);
    } else {
        clearIconBtn.setEnabled(true);
    }
    appLabel.setIcon(innerAppImgIcon);

    getIconBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            chooseToolbarIcon(appLabel, clearIconBtn);
        }
    });

    clearIconBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ImageIcon appIcon = IconManager.getIcon("AppIcon");
            IconEntry entry = IconManager.getIconEntryByName(INNER_APPICON_NAME);
            entry.setIcon(appIcon);
            if (entry.getIcons().get(IconManager.IconSize.Std32) != null) {
                entry.getIcons().get(IconManager.IconSize.Std32).setImageIcon(appIcon);
            }

            appLabel.setIcon(IconManager.getIcon("AppIcon")); //$NON-NLS-1$
            clearIconBtn.setEnabled(false);
            AppPreferences.getRemote().remove(iconImagePrefName);
            form.getValidator().dataChanged(null, null, null);
        }
    });

    resetDefFontBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Font sysDefFont = UIRegistry.getDefaultFont();
            ComboBoxModel model = fontNames.getModel();
            for (int i = 0; i < model.getSize(); i++) {
                //System.out.println("["+model.getElementAt(i).toString()+"]["+sysDefFont.getFamily()+"]");
                if (model.getElementAt(i).toString().equals(sysDefFont.getFamily())) {
                    fontNames.setSelectedIndex(i);
                    clearFontSettings = true;
                    break;
                }
            }

            if (clearFontSettings) {
                fontSizes.setSelectedIndex(sysDefFont.getSize() - BASE_FONT_SIZE);
                clearFontSettings = true; // needs to be redone 
            }

            form.getValidator().dataChanged(null, null, null);
        }
    });

    //-----------------------------------
    // Do Banner Icon Size
    //-----------------------------------

    String fmtStr = "%d x %d pixels";//getResourceString("BNR_ICON_SIZE");
    bnrIconSizeCBX = form.getCompById("bnrIconSizeCBX"); //$NON-NLS-1$

    int size = AppPreferences.getLocalPrefs().getInt(BNR_ICON_SIZE, 20);
    inx = 0;
    cnt = 0;
    for (int pixelSize : pixelSizes) {
        ((DefaultComboBoxModel) bnrIconSizeCBX.getModel())
                .addElement(String.format(fmtStr, pixelSize, pixelSize));
        if (pixelSize == size) {
            inx = cnt;
        }
        cnt++;
    }

    bnrIconSizeCBX.getComboBox().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            form.getUIComponent().validate();
        }
    });

    bnrIconSizeCBX.getComboBox().setSelectedIndex(inx);

    UIValidator.setIgnoreAllValidation(this, false);
    fontNamesVCB.setChanged(false);
    fontSizesVCB.setChanged(false);

    form.getValidator().validateForm();
}