Example usage for java.awt GraphicsEnvironment getAllFonts

List of usage examples for java.awt GraphicsEnvironment getAllFonts

Introduction

In this page you can find the example usage for java.awt GraphicsEnvironment getAllFonts.

Prototype

public abstract Font[] getAllFonts();

Source Link

Document

Returns an array containing a one-point size instance of all fonts available in this GraphicsEnvironment .

Usage

From source file:org.apache.fop.render.java2d.InstalledFontCollection.java

/**
 * {@inheritDoc}/*www. j a v  a2  s .co  m*/
 */
public int setup(int start, FontInfo fontInfo) {
    int num = start;
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

    java.awt.Font[] fonts = env.getAllFonts();
    for (int i = 0; i < fonts.length; i++) {
        java.awt.Font f = fonts[i];
        if (HARDCODED_FONT_NAMES.contains(f.getName())) {
            continue; //skip
        }

        if (log.isTraceEnabled()) {
            log.trace("AWT Font: " + f.getFontName() + ", family: " + f.getFamily() + ", PS: " + f.getPSName()
                    + ", Name: " + f.getName() + ", Angle: " + f.getItalicAngle() + ", Style: " + f.getStyle());
        }

        String searchName = FontUtil.stripWhiteSpace(f.getName()).toLowerCase();
        String guessedStyle = FontUtil.guessStyle(searchName);
        int guessedWeight = FontUtil.guessWeight(searchName);

        num++;
        String fontKey = "F" + num;
        int style = convertToAWTFontStyle(guessedStyle, guessedWeight);
        addFontMetricsMapper(fontInfo, f.getName(), fontKey, java2DFontMetrics, style);

        //Register appropriate font triplets matching the font. Two different strategies:
        //Example: "Arial Bold", normal, normal
        addFontTriplet(fontInfo, f.getName(), Font.STYLE_NORMAL, Font.WEIGHT_NORMAL, fontKey);
        if (!f.getName().equals(f.getFamily())) {
            //Example: "Arial", bold, normal
            addFontTriplet(fontInfo, f.getFamily(), guessedStyle, guessedWeight, fontKey);
        }
    }
    return num;
}

From source file:com.alkacon.opencms.formgenerator.CmsCaptchaEngine.java

/**
 * Filters the fonts available on the system. <p>
 * //from  w  ww  .j a  va2 s .  c o  m
 * Only fonts, which start with one of the provided prefix are returned. 
 * These prefix list ensures, that font do not contain unreadable characters.
 * 
 * @param prefixList the list of prefix to filter the system fonts
 * 
 * @return an array of standard fonts
 */
private Font[] getFilteredFonts(List<String> prefixList) {

    LOG.debug(Messages.get().getBundle().key(Messages.DEBUG_CAPTCHA_FONT_FILTERING_START_0));
    List<Font> filteredFontsList = new LinkedList<Font>();

    // Get all system fonts
    GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] systemFonts = e.getAllFonts();

    for (Font f : systemFonts) {
        for (String prefix : prefixList) {
            if (f.getFontName().toLowerCase().startsWith(prefix.toLowerCase())) {
                filteredFontsList.add(f);
                LOG.debug(Messages.get().getBundle().key(Messages.DEBUG_CAPTCHA_ADD_FONT_1, f.getFontName()));
            }
        }
    }
    Font[] filteredFonts = new Font[filteredFontsList.size()];
    int i = 0;
    for (Font f : filteredFontsList) {
        filteredFonts[i] = f;
        i++;
    }
    LOG.debug(Messages.get().getBundle().key(Messages.DEBUG_CAPTCHA_FONT_FILTERING_FINISH_1,
            Integer.valueOf(filteredFonts.length)));
    return filteredFonts;
}

From source file:com.floreantpos.config.ui.TerminalConfigurationView.java

private void initializeFontConfig() {
    GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = e.getAllFonts(); // Get the fonts
    DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) cbFonts.getModel();
    model.addElement("<select>"); //$NON-NLS-1$

    for (Font f : fonts) {
        model.addElement(f.getFontName());
    }/*from w ww . j av a  2s.c  o m*/

    String uiDefaultFont = TerminalConfig.getUiDefaultFont();
    if (StringUtils.isNotEmpty(uiDefaultFont)) {
        cbFonts.setSelectedItem(uiDefaultFont);
    }
}

From source file:edu.ku.brc.specify.config.init.PrintTableHelper.java

/**
 * @param model/*from  w w w  . j  a  v  a  2 s .  c  o  m*/
 * @return
 * @throws Exception
 */
public DynamicReport buildReport(final TableModel model, final PageSetupDlg pageSetupDlg) throws Exception {
    // Find a Sans Serif Font on the System
    String fontName = null;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (java.awt.Font font : ge.getAllFonts()) {

        String fName = font.getFamily().toLowerCase();
        if (StringUtils.contains(fName, "sansserif") || StringUtils.contains(fName, "arial")
                || StringUtils.contains(fName, "verdana")) {
            fontName = font.getFamily();
            break;
        }
    }

    if (fontName == null) {
        fontName = Font._FONT_TIMES_NEW_ROMAN;
    }

    /**
     * Creates the DynamicReportBuilder and sets the basic options for the report
     */
    FastReportBuilder drb = new FastReportBuilder();

    Style columDetail = new Style();
    //columDetail.setBorder(Border.THIN);

    Style columDetailWhite = new Style();
    //columDetailWhite.setBorder(Border.THIN);
    columDetailWhite.setBackgroundColor(Color.WHITE);
    columDetailWhite.setFont(new Font(10, fontName, false));
    columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER);
    columDetailWhite.setBlankWhenNull(true);

    Style columDetailWhiteBold = new Style();
    //columDetailWhiteBold.setBorder(Border.THIN);
    columDetailWhiteBold.setBackgroundColor(Color.WHITE);

    Style titleStyle = new Style();
    titleStyle.setFont(new Font(12, fontName, true));

    // Odd Row Style
    Style oddRowStyle = new Style();
    //oddRowStyle.setBorder(Border.NO_BORDER);
    oddRowStyle.setHorizontalAlign(HorizontalAlign.CENTER);

    Color veryLightGrey = new Color(240, 240, 240);
    oddRowStyle.setBackgroundColor(veryLightGrey);
    oddRowStyle.setTransparency(Transparency.OPAQUE);

    // Create Column Headers for the Report
    for (int i = 0; i < model.getColumnCount(); i++) {
        String colName = model.getColumnName(i);

        Class<?> dataClass = model.getColumnClass(i);
        if (dataClass == Object.class) {
            if (model.getRowCount() > 0) {
                Object data = model.getValueAt(0, i);
                if (data != null) {
                    dataClass = data.getClass();
                } else {
                    // Column in first row was null so search down the rows
                    // for a non-empty cell
                    for (int j = 1; j < model.getRowCount(); j++) {
                        data = model.getValueAt(j, i);
                        if (dataClass != null) {
                            dataClass = data.getClass();
                            break;
                        }
                    }

                    if (dataClass == null) {
                        dataClass = String.class;
                    }
                }
            }
        }

        ColumnBuilder colBldr = ColumnBuilder.getInstance().setColumnProperty(colName, dataClass.getName());
        int bracketInx = colName.indexOf('[');
        if (bracketInx > -1) {
            colName = colName.substring(0, bracketInx - 1);
        }
        colBldr.setTitle(colName);

        colBldr.setStyle(columDetailWhite);

        AbstractColumn column = colBldr.build();
        drb.addColumn(column);

        Style headerStyle = new Style();
        headerStyle.setFont(new Font(11, fontName, true));
        //headerStyle.setBorder(Border.THIN);
        headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
        headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
        headerStyle.setBackgroundColor(new Color(80, 80, 80));
        headerStyle.setTransparency(Transparency.OPAQUE);
        headerStyle.setTextColor(new Color(255, 255, 255));
        column.setHeaderStyle(headerStyle);
    }

    drb.setTitle(pageSetupDlg.getPageTitle());
    drb.setTitleStyle(titleStyle);

    drb.setLeftMargin(20);
    drb.setRightMargin(20);
    drb.setTopMargin(10);
    drb.setBottomMargin(10);

    drb.setPrintBackgroundOnOddRows(true);
    drb.setOddRowBackgroundStyle(oddRowStyle);
    drb.setColumnsPerPage(new Integer(1));
    drb.setUseFullPageWidth(true);
    drb.setColumnSpace(new Integer(5));

    // This next line causes an exception
    // Event with DynamicReport 3.0.12 and JasperReposrts 3.7.3
    //drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_CENTER);

    Page[] pageSizes = new Page[] { Page.Page_Letter_Portrait(), Page.Page_Legal_Portrait(),
            Page.Page_A4_Portrait(), Page.Page_Letter_Landscape(), Page.Page_Legal_Landscape(),
            Page.Page_A4_Landscape() };
    int pageSizeInx = pageSetupDlg.getPageSize() + (pageSetupDlg.isPortrait() ? 0 : 3);
    drb.setPageSizeAndOrientation(pageSizes[pageSizeInx]);

    DynamicReport dr = drb.build();

    return dr;
}

From source file:com.petersoft.advancedswing.enhancedtextarea.EnhancedTextArea.java

private void initGUI() {
    try {//  ww w. java 2 s. c o m
        BorderLayout thisLayout = new BorderLayout();
        this.setLayout(thisLayout);
        this.setPreferredSize(new java.awt.Dimension(725, 290));
        {
            jToolBar = new JToolBar();
            this.add(jToolBar, BorderLayout.NORTH);
            {
                jSaveButton = new JButton();
                jToolBar.add(jSaveButton);
                jSaveButton.setText("Save");
                jSaveButton.setIcon(new ImageIcon(getClass().getClassLoader()
                        .getResource("com/petersoft/advancedswing/enhancedtextarea/disk.png")));
                jSaveButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jSaveButtonActionPerformed(evt);
                    }
                });
            }
            {
                jLineWrapButton = new JToggleButton();
                jToolBar.add(jLineWrapButton);
                jLineWrapButton.setText("Wrap");
                jLineWrapButton.setIcon(new ImageIcon(getClass().getClassLoader()
                        .getResource("com/petersoft/advancedswing/enhancedtextarea/linewrap.png")));
                jLineWrapButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jLineWrapButtonActionPerformed(evt);
                    }
                });
            }
            {
                jFontBiggerButton = new JButton();
                jToolBar.add(jFontBiggerButton);
                jFontBiggerButton.setIcon(new ImageIcon(getClass().getClassLoader()
                        .getResource("com/petersoft/advancedswing/enhancedtextarea/font_add.png")));
                jFontBiggerButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jFontBiggerButtonActionPerformed(evt);
                    }
                });
            }
            {
                jFontSmallerButton = new JButton();
                jToolBar.add(jFontSmallerButton);
                jFontSmallerButton.setIcon(new ImageIcon(getClass().getClassLoader()
                        .getResource("com/petersoft/advancedswing/enhancedtextarea/font_delete.png")));
                jFontSmallerButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jFontSmallerButtonActionPerformed(evt);
                    }
                });
            }
            {
                jLabel1 = new JLabel();
                jToolBar.add(jLabel1);
                jLabel1.setText(" ");
            }
            {
                jSearchTextField = new JSearchTextField();
                jToolBar.add(jSearchTextField);
                jSearchTextField.setMaximumSize(new java.awt.Dimension(100, 22));
                jSearchTextField.setPreferredSize(new java.awt.Dimension(100, 22));
                jSearchTextField.setSize(new java.awt.Dimension(100, 22));
                jSearchTextField.addKeyListener(new KeyAdapter() {
                    public void keyReleased(KeyEvent evt) {
                        jSearchTextFieldKeyReleased(evt);
                    }
                });

            }
            {
                jSeparatorLabel = new JLabel();
                jToolBar.add(jSeparatorLabel);
                jSeparatorLabel.setText(" ");
            }
            {
                GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
                Font[] fonts = e.getAllFonts();
                String fontNames[] = new String[fonts.length];
                int x = 0;
                for (Font f : fonts) {
                    fontNames[x++] = f.getFontName();
                }
                ComboBoxModel jFontComboBoxModel = new DefaultComboBoxModel(fontNames);
                jFontComboBox = new JComboBox();
                jToolBar.add(jFontComboBox);
                jFontComboBox.setModel(jFontComboBoxModel);
                jFontComboBox.setMaximumSize(new java.awt.Dimension(180, 22));
                jFontComboBox.setPreferredSize(new java.awt.Dimension(180, 22));
                jFontComboBox.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        jFontComboBoxActionPerformed(evt);
                    }
                });
            }
            {
                pager = new Pager();
                jToolBar.add(pager);
                pager.setVisible(false);
            }
        }
        {
            jScrollPane1 = new JScrollPane();
            this.add(jScrollPane1, BorderLayout.CENTER);
            {
                jTextArea = new JTextArea();
                jTextArea.getDocument().addDocumentListener(this);
                lines = new JTextArea(" 1 ");
                lines.setBackground(new Color(200, 230, 245));
                lines.setEditable(false);
                jScrollPane1.setRowHeaderView(lines);

                jTextArea.getDocument().addDocumentListener(new DocumentListener() {
                    public String getText() {
                        int caretPosition = jTextArea.getDocument().getLength();
                        Element root = jTextArea.getDocument().getDefaultRootElement();

                        int base = 0;
                        if (separateByLine == false) {
                            if (str != null) {
                                base = StringUtils.countMatches(
                                        str.substring(0, (pager.getPage() - 1) * pageSize),
                                        System.getProperty("line.separator"));
                                if (base == 1) {
                                    base = 0;
                                }
                            }
                        } else {
                            base = (pager.getPage() - 1) * pageSize;
                        }
                        base += lineNoBase;
                        String text = " " + (base + 1) + " " + System.getProperty("line.separator");
                        for (int i = 2; i < root.getElementIndex(caretPosition) + 2; i++) {
                            text += " " + (base + i) + " " + System.getProperty("line.separator");
                        }
                        return text;
                    }

                    @Override
                    public void changedUpdate(DocumentEvent de) {
                        lines.setText(getText());
                    }

                    @Override
                    public void insertUpdate(DocumentEvent de) {
                        lines.setText(getText());
                    }

                    @Override
                    public void removeUpdate(DocumentEvent de) {
                        lines.setText(getText());
                    }

                });
                jScrollPane1.setViewportView(jTextArea);
            }
        }
        {
            jStatusPanel = new JPanel();
            FlowLayout jStatusPanelLayout = new FlowLayout();
            jStatusPanelLayout.setAlignment(FlowLayout.LEFT);
            jStatusPanel.setLayout(jStatusPanelLayout);
            this.add(jStatusPanel, BorderLayout.SOUTH);
            {
                jStatusLabel = new JLabel();
                jStatusPanel.add(jStatusLabel);
            }
            {
                jSearchLabel = new JLabel();
                jStatusPanel.add(jSearchLabel);
            }
        }
        this.jFontComboBox.setSelectedItem(jTextArea.getFont().getFamily() + ".plain");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ApplicationProperties.java

private void setupForm(final String settingsPath) {
    this.setTitle("System Properties");
    try {/*from   w  w w.  j av a  2s  . c  o  m*/
        theFormControl = new FormControl(this, settingsPath);
    } catch (Exception ex) {
        LOG.error("Error loading form parameters", ex);
    }
    // Set fonts
    isSystemChange = true;
    final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final Font[] fonts = env.getAllFonts();
    DefaultListModel model = new DefaultListModel();
    for (int i = 0; i < fonts.length; i++) {
        final Font font = fonts[i];
        model.add(i, font.getName());
    }
    lstFont.setModel(model);

    // Set styles
    model = new DefaultListModel();
    model.addElement("Plain");
    model.addElement("Bold");
    model.addElement("Italic");
    model.addElement("Bold Italic");
    lstStyle.setModel(model);

    // Set sizes
    model = new DefaultListModel();
    model.addElement("8");
    model.addElement("10");
    model.addElement("12");
    model.addElement("14");
    model.addElement("18");
    model.addElement("20");
    model.addElement("22");
    model.addElement("24");
    lstSize.setModel(model);
    txtFontSize.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(final DocumentEvent e) {
            updateFontSize();
        }

        public void removeUpdate(final DocumentEvent e) {
            updateFontSize();
        }

        public void insertUpdate(final DocumentEvent e) {
            updateFontSize();
        }
    });

    model = new DefaultListModel();
    for (String favourite : personalSettings.getFavourites()) {
        model.addElement(favourite);
    }
    lstFavourites.setModel(model);

    model = new DefaultListModel();
    for (PersonalSettings.FileDescriptions descriptions : personalSettings.getFilesToIgnore()) {
        model.addElement(descriptions);
    }
    lstFilesToIgnore.setModel(model);

    final DefaultComboBoxModel cmbModel = new DefaultComboBoxModel();
    for (PersonalSettings.TextPosition position : PersonalSettings.TextPosition.values()) {
        cmbModel.addElement(position);
    }
    cmbTextPosition.setModel(cmbModel);

    chkSortRunning.setSelected(personalSettings.isSortRunningAscending());
    chkSortPending.setSelected(personalSettings.isSortPendingAscending());
    chkSortFailed.setSelected(personalSettings.isSortFailedAscending());
    chkSortDeposited.setSelected(personalSettings.isSortDepositedAscending());
    chkSortComplete.setSelected(personalSettings.isSortCompleteAscending());
    txtNoOfRetries.setText(String.format("%d", personalSettings.getNoOfRetries()));

    isSystemChange = false;
}

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

/**
 * Create the UI for the panel//from  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();
}

From source file:edu.ku.brc.specify.tasks.ReportsBaseTask.java

/**
 * @param model//from w w  w .j a va2 s.co  m
 * @return
 * @throws Exception
 */
public DynamicReport buildReport(final TableModel model, final PageSetupDlg pageSetupDlg) throws Exception {
    // Find a Sans Serif Font on the System
    String fontName = null;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (java.awt.Font font : ge.getAllFonts()) {
        String fName = font.getFamily().toLowerCase();
        if (StringUtils.contains(fName, "sansserif") || StringUtils.contains(fName, "arial")
                || StringUtils.contains(fName, "verdana")) {
            fontName = font.getFamily();
        }
    }

    if (fontName == null) {
        fontName = Font._FONT_TIMES_NEW_ROMAN;
    }

    /**
     * Creates the DynamicReportBuilder and sets the basic options for the report
     */
    FastReportBuilder drb = new FastReportBuilder();

    Style columDetail = new Style();
    //columDetail.setBorder(Border.THIN);

    Style columDetailWhite = new Style();
    //columDetailWhite.setBorder(Border.THIN);
    columDetailWhite.setBackgroundColor(Color.WHITE);
    columDetailWhite.setFont(new Font(10, fontName, true));
    columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER);
    columDetailWhite.setBlankWhenNull(true);

    Style columDetailWhiteBold = new Style();
    //columDetailWhiteBold.setBorder(Border.THIN);
    columDetailWhiteBold.setBackgroundColor(Color.WHITE);

    Style titleStyle = new Style();
    titleStyle.setFont(new Font(14, fontName, true));

    /*Style numberStyle = new Style();
    numberStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
            
    Style amountStyle = new Style();
    amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
    amountStyle.setBackgroundColor(Color.cyan);
    amountStyle.setTransparency(Transparency.OPAQUE);*/

    //Font dataRowFont = new Font(10, Font._FONT_VERDANA, true);

    // Odd Row Style
    Style oddRowStyle = new Style();
    //oddRowStyle.setBorder(Border.NO_BORDER);
    //oddRowStyle.setFont(dataRowFont);
    oddRowStyle.setHorizontalAlign(HorizontalAlign.CENTER);

    Color veryLightGrey = new Color(240, 240, 240);
    oddRowStyle.setBackgroundColor(veryLightGrey);
    oddRowStyle.setTransparency(Transparency.OPAQUE);

    // Event Row Style
    //Style evenRowStyle = new Style();
    //evenRowStyle.setBorder(Border.NO_BORDER);
    //evenRowStyle.setFont(dataRowFont);

    // Create Column Headers for the Report
    for (int i = 0; i < model.getColumnCount(); i++) {
        String colName = model.getColumnName(i);

        Class<?> dataClass = model.getColumnClass(i);
        if (dataClass == Object.class) {
            if (model.getRowCount() > 0) {
                Object data = model.getValueAt(0, i);
                if (data != null) {
                    dataClass = data.getClass();
                } else {
                    // Column in first row was null so search down the rows
                    // for a non-empty cell
                    for (int j = 1; j < model.getRowCount(); j++) {
                        data = model.getValueAt(j, i);
                        if (dataClass != null) {
                            dataClass = data.getClass();
                            break;
                        }
                    }

                    if (dataClass == null) {
                        dataClass = String.class;
                    }
                }
            }
        }

        ColumnBuilder colBldr = ColumnBuilder.getInstance().setColumnProperty(colName, dataClass.getName());
        int bracketInx = colName.indexOf('[');
        if (bracketInx > -1) {
            colName = colName.substring(0, bracketInx - 1);
        }
        colBldr.setTitle(colName);
        //colBldr.setWidth(new Integer(100));

        colBldr.setStyle(columDetailWhite);
        //colBldr.setHeaderStyle(columDetailWhite);

        AbstractColumn column = colBldr.build();
        drb.addColumn(column);

        Style headerStyle = new Style();
        headerStyle.setFont(new Font(12, fontName, true));
        //headerStyle.setBorder(Border.THIN);
        headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
        headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
        headerStyle.setBackgroundColor(new Color(80, 80, 80));
        headerStyle.setTransparency(Transparency.OPAQUE);
        headerStyle.setTextColor(new Color(255, 255, 255));
        column.setHeaderStyle(headerStyle);
    }

    drb.setTitle(pageSetupDlg.getPageTitle());
    drb.setTitleStyle(titleStyle);
    //drb.setTitleHeight(new Integer(30));
    //drb.setSubtitleHeight(new Integer(20));
    //drb.setDetailHeight(new Integer(15));
    //drb.setDefaultStyles(null, null, null, evenRowStyle);

    drb.setLeftMargin(20);
    drb.setRightMargin(20);
    drb.setTopMargin(10);
    drb.setBottomMargin(10);

    drb.setPrintBackgroundOnOddRows(true);
    drb.setOddRowBackgroundStyle(oddRowStyle);
    drb.setColumnsPerPage(new Integer(1));
    drb.setUseFullPageWidth(true);
    drb.setColumnSpace(new Integer(5));

    // This next line causes an exception
    // Event with DynamicReport 3.0.12 and JasperReposrts 3.7.3
    //drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_FOOTER, AutoText.ALIGMENT_CENTER);

    Page[] pageSizes = new Page[] { Page.Page_Letter_Portrait(), Page.Page_Legal_Portrait(),
            Page.Page_A4_Portrait(), Page.Page_Letter_Landscape(), Page.Page_Legal_Landscape(),
            Page.Page_A4_Landscape() };
    int pageSizeInx = pageSetupDlg.getPageSize() + (pageSetupDlg.isPortrait() ? 0 : 3);
    drb.setPageSizeAndOrientation(pageSizes[pageSizeInx]);

    DynamicReport dr = drb.build();

    return dr;
}

From source file:org.pentaho.di.core.Const.java

public static String[] GetAvailableFontNames() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    String[] FontName = new String[fonts.length];
    for (int i = 0; i < fonts.length; i++) {
        FontName[i] = fonts[i].getFontName();
    }/* w ww.  j  ava  2  s. co  m*/
    return FontName;
}