Example usage for java.awt Font deriveFont

List of usage examples for java.awt Font deriveFont

Introduction

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

Prototype

public Font deriveFont(Map<? extends Attribute, ?> attributes) 

Source Link

Document

Creates a new Font object by replicating the current Font object and applying a new set of font attributes to it.

Usage

From source file:org.pgptool.gui.ui.tools.UiUtils.java

public static void setLookAndFeel() {
    // NOTE: We doing it this way to prevent dead=locks that is sometimes
    // happens if do it in main thread
    Edt.invokeOnEdtAndWait(new Runnable() {
        @Override//from w  w w  .  j  a  v  a2s.c  o  m
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                fixCheckBoxMenuItemForeground();
                fixFontSize();
            } catch (Throwable t) {
                log.error("Failed to set L&F", t);
            }
        }

        /**
         * In some cases (depends on OS theme) check menu item foreground is same as
         * bacground - thus it;'s invisible when cheked
         */
        private void fixCheckBoxMenuItemForeground() {
            UIDefaults defaults = UIManager.getDefaults();
            Color selectionForeground = defaults.getColor("CheckBoxMenuItem.selectionForeground");
            Color foreground = defaults.getColor("CheckBoxMenuItem.foreground");
            Color background = defaults.getColor("CheckBoxMenuItem.background");
            if (colorsDiffPercentage(selectionForeground, background) < 10) {
                // TODO: That doesn't actually affect defaults. Need to find out how to fix it
                defaults.put("CheckBoxMenuItem.selectionForeground", foreground);
            }
        }

        private int colorsDiffPercentage(Color c1, Color c2) {
            int diffRed = Math.abs(c1.getRed() - c2.getRed());
            int diffGreen = Math.abs(c1.getGreen() - c2.getGreen());
            int diffBlue = Math.abs(c1.getBlue() - c2.getBlue());

            float pctDiffRed = (float) diffRed / 255;
            float pctDiffGreen = (float) diffGreen / 255;
            float pctDiffBlue = (float) diffBlue / 255;

            return (int) ((pctDiffRed + pctDiffGreen + pctDiffBlue) / 3 * 100);
        }

        private void fixFontSize() {
            if (isJreHandlesScaling()) {
                log.info("JRE handles font scaling, won't change it");
                return;
            }
            log.info("JRE doesnt't seem to support font scaling");

            Toolkit toolkit = Toolkit.getDefaultToolkit();
            int dpi = toolkit.getScreenResolution();
            if (dpi == 96) {
                if (log.isDebugEnabled()) {
                    Font font = UIManager.getDefaults().getFont("TextField.font");
                    String current = font != null ? Integer.toString(font.getSize()) : "unknown";
                    log.debug(
                            "Screen dpi seem to be 96. Not going to change font size. Btw current size seem to be "
                                    + current);
                }
                return;
            }
            int targetFontSize = 12 * dpi / 96;
            log.debug("Screen dpi = " + dpi + ", decided to change font size to " + targetFontSize);
            setDefaultSize(targetFontSize);
        }

        private boolean isJreHandlesScaling() {
            try {
                JreVersion noNeedToScaleForVer = JreVersion.parseString("9");
                String jreVersionStr = System.getProperty("java.version");
                if (jreVersionStr != null) {
                    JreVersion curVersion = JreVersion.parseString(jreVersionStr);
                    if (noNeedToScaleForVer.compareTo(curVersion) <= 0) {
                        return true;
                    }
                }

                return false;
            } catch (Throwable t) {
                log.warn("Failed to see oif JRE can handle font scaling. Will assume it does. JRE version: "
                        + System.getProperty("java.version"), t);
                return true;
            }
        }

        public void setDefaultSize(int size) {
            Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet();
            Object[] keys = keySet.toArray(new Object[keySet.size()]);
            for (Object key : keys) {
                if (key != null && key.toString().toLowerCase().contains("font")) {
                    Font font = UIManager.getDefaults().getFont(key);
                    if (font != null) {
                        Font changedFont = font.deriveFont((float) size);
                        UIManager.put(key, changedFont);
                        Font doubleCheck = UIManager.getDefaults().getFont(key);
                        log.debug("Font size changed for " + key + ". From " + font.getSize() + " to "
                                + doubleCheck.getSize());
                    }
                }
            }
        }
    });
    log.info("L&F set");
}

From source file:spectrogram.Spectrogram.java

private void drawRotatedText(int tx, int ty, double theta, String text) {

    AffineTransform fontAT = new AffineTransform();
    fontAT.setToIdentity();// ww  w .  jav a2 s.c o  m

    fontAT.rotate(Math.toRadians(theta));

    Font curFont = grph.getFont();
    Font rotFont = curFont.deriveFont(fontAT);

    grph.setFont(rotFont);
    grph.drawString(text, tx, ty);

    grph.setFont(curFont);
}

From source file:net.sf.jasperreports.engine.fonts.FontUtil.java

/**
 * Returns a java.awt.Font instance by converting a JRFont instance.
 * Mostly used in combination with third-party visualization packages such as JFreeChart (for chart themes).
 * Unless the font parameter is null, this method always returns a non-null AWT font, regardless whether it was
 * found in the font extensions or not. This is because we do need a font to draw with and there is no point
 * in raising a font missing exception here, as it is not JasperReports who does the drawing. 
 */// w  w w  .  j  a v a2 s . c om
public Font getAwtFont(JRFont font, Locale locale) {
    if (font == null) {
        return null;
    }

    // ignoring missing font as explained in the Javadoc
    Font awtFont = getAwtFontFromBundles(font.getFontName(),
            ((font.isBold() ? Font.BOLD : Font.PLAIN) | (font.isItalic() ? Font.ITALIC : Font.PLAIN)),
            font.getFontsize(), locale, true);

    if (awtFont == null) {
        awtFont = new Font(getAttributesWithoutAwtFont(new HashMap<Attribute, Object>(), font));
    } else {
        // add underline and strikethrough attributes since these are set at
        // style/font level
        Map<Attribute, Object> attributes = new HashMap<Attribute, Object>();
        if (font.isUnderline()) {
            attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        }
        if (font.isStrikeThrough()) {
            attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
        }

        if (!attributes.isEmpty()) {
            awtFont = awtFont.deriveFont(attributes);
        }
    }

    return awtFont;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Displays the specified string into a {@link JLabel} and sets 
 * the font to <code>bold</code>.
 * /*w  w w .  ja v a  2s . co  m*/
 * @param s       The string to display.
 * @param fontStyle The style of the font.
 * @return See above.
 */
public static JLabel setTextFont(String s, int fontStyle) {
    if (s == null)
        s = "";
    JLabel label = new JLabel(s);
    Font font = label.getFont();
    Font newFont = font.deriveFont(fontStyle);
    label.setFont(newFont);
    return label;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Initializes a <code>JXTaskPane</code>.
 * /* w  w  w .j a  v a  2  s. c  o m*/
 * @param title The title of the component.
 * @param background The background color.
 * @return See above.
 */
public static JXTaskPane createTaskPane(String title, Color background) {
    JXTaskPane taskPane = new JXTaskPane();
    if (isLinuxOS())
        taskPane.setAnimated(false);

    Container c = taskPane.getContentPane();
    if (background != null) {
        c.setBackground(background);
        taskPane.setBackground(background);
    }
    if (c instanceof JComponent)
        ((JComponent) c).setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    taskPane.setTitle(title);
    taskPane.setCollapsed(true);
    Font font = taskPane.getFont();
    taskPane.setFont(font.deriveFont(font.getSize2D() - 2));
    return taskPane;
}

From source file:edu.ku.brc.specify.ui.treetables.TreeDefinitionEditor.java

/**
 * @param treeDef//from www  .  jav  a2s .  co m
 */
protected void initTreeDefEditorComponent(final D treeDef) {
    Set<I> defItems = treeDef.getTreeDefItems();
    tableModel = new TreeDefEditorTableModel<T, D, I>(defItems);
    defItemsTable = new JTable(tableModel);
    defItemsTable.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false));

    defItemsTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                SwingUtilities.invokeLater(new Runnable() {

                    /* (non-Javadoc)
                     * @see java.lang.Runnable#run()
                     */
                    @Override
                    public void run() {
                        editTreeDefItem(defItemsTable.getSelectedRow());
                    }

                });
            }
        }
    });
    defItemsTable.setRowHeight(24);

    // Center the boolean Columns
    BiColorTableCellRenderer centeredRenderer = new BiColorTableCellRenderer();

    TableColumn tc = defItemsTable.getColumnModel().getColumn(2);
    tc.setCellRenderer(centeredRenderer);
    tc = defItemsTable.getColumnModel().getColumn(3);
    tc.setCellRenderer(centeredRenderer);

    if (isEditMode) {
        defItemsTable.setRowSelectionAllowed(true);
        defItemsTable.setColumnSelectionAllowed(false);
        defItemsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    } else {
        defItemsTable.setRowSelectionAllowed(false);
    }

    UIHelper.makeTableHeadersCentered(defItemsTable, false);

    defNameLabel.setText(treeDef.getName());
    Font f = defNameLabel.getFont();
    Font boldF = f.deriveFont(Font.BOLD);
    defNameLabel.setFont(boldF);

    // put everything in the main panel
    this.add(UIHelper.createScrollPane(defItemsTable), BorderLayout.CENTER);
    this.add(titlePanel, BorderLayout.NORTH);

    // Only add selection listener if the botton panel is there for editing
    if (edaPanel != null) {
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,10px", "p")); //$NON-NLS-1$ //$NON-NLS-2$
        pb.add(edaPanel, new CellConstraints().xy(2, 1));
        add(pb.getPanel(), BorderLayout.SOUTH);
        addSelectionListener();
    }

    repaint();
}

From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java

/**
 * Updates the charts./*w  w w .  j  a v  a  2  s. c om*/
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateCharts() {
    for (int i = 0; i < listOfChartPanels.size(); i++) {
        JPanel panel = listOfChartPanels.get(i);
        panel.removeAll();
        final ChartPanel chartPanel = new ChartPanel(getModel().getChartOrNull(i)) {

            private static final long serialVersionUID = -6953213567063104487L;

            @Override
            public Dimension getPreferredSize() {
                return DIMENSION_CHART_PANEL_ENLARGED;
            }
        };
        chartPanel.setPopupMenu(null);
        chartPanel.setBackground(COLOR_TRANSPARENT);
        chartPanel.setOpaque(false);
        chartPanel.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
        panel.add(chartPanel, BorderLayout.CENTER);

        JPanel openChartPanel = new JPanel(new GridBagLayout());
        openChartPanel.setOpaque(false);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;

        JButton openChartButton = new JButton(OPEN_CHART_ACTION);
        openChartButton.setOpaque(false);
        openChartButton.setContentAreaFilled(false);
        openChartButton.setBorderPainted(false);
        openChartButton.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
        openChartButton.setHorizontalAlignment(SwingConstants.LEFT);
        openChartButton.setHorizontalTextPosition(SwingConstants.LEFT);
        openChartButton.setIcon(null);
        Font font = openChartButton.getFont();
        Map attributes = font.getAttributes();
        attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        openChartButton.setFont(font.deriveFont(attributes).deriveFont(10.0f));

        openChartPanel.add(openChartButton, gbc);

        panel.add(openChartPanel, BorderLayout.SOUTH);
        panel.revalidate();
        panel.repaint();
    }
}

From source file:pl.otros.vfs.browser.VfsBrowser.java

License:asdf

private void initGui(final String initialPath) {
    this.setLayout(new BorderLayout());
    JLabel pathLabel = new JLabel(Messages.getMessage("browser.location"));
    pathLabel.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3));
    pathField = new JTextField(80);
    pathField.setFont(pathLabel.getFont().deriveFont(pathLabel.getFont().getSize() * 1.2f));
    pathField.setToolTipText(Messages.getMessage("nav.pathTooltip"));
    GuiUtils.addBlinkOnFocusGain(pathField);
    pathLabel.setLabelFor(pathField);//from ww w  . ja v a2s  .  c om
    pathLabel.setDisplayedMnemonic(Messages.getMessage("browser.location.mnemonic").charAt(0));

    InputMap inputMapPath = pathField.getInputMap(JComponent.WHEN_FOCUSED);
    inputMapPath.put(KeyStroke.getKeyStroke("ENTER"), "OPEN_PATH");
    inputMapPath.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), ACTION_FOCUS_ON_TABLE);
    pathField.getActionMap().put("OPEN_PATH", new BaseNavigateAction(this) {

        @Override
        protected void performLongOperation(CheckBeforeActionResult actionResult) {
            try {
                FileObject resolveFile = VFSUtils.resolveFileObject(pathField.getText().trim());
                if (resolveFile != null && resolveFile.getType() == FileType.FILE) {
                    loadAndSelSingleFile(resolveFile);
                    pathField.setText(resolveFile.getURL().toString());
                    actionApproveDelegate.actionPerformed(
                            // TODO:  Does actionResult provide an ID for 2nd param here,
                            // or should use a Random number?
                            new ActionEvent(actionResult, (int) new java.util.Date().getTime(),
                                    "SELECTED_FILE"));
                    return;
                }
            } catch (FileSystemException fse) {
                // Intentionally empty
            }
            goToUrl(pathField.getText().trim());
        }

        @Override
        protected boolean canGoUrl() {
            return true;
        }

        @Override
        protected boolean canExecuteDefaultAction() {
            return false;
        }

    });
    actionFocusOnTable = new

    AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tableFiles.requestFocusInWindow();
            if (tableFiles.getSelectedRow() < 0 && tableFiles.getRowCount() == 0) {
                tableFiles.getSelectionModel().setSelectionInterval(0, 0);
            }
        }
    };
    pathField.getActionMap().put(ACTION_FOCUS_ON_TABLE, actionFocusOnTable);

    BaseNavigateActionGoUp goUpAction = new BaseNavigateActionGoUp(this);
    goUpButton = new JButton(goUpAction);

    BaseNavigateActionRefresh refreshAction = new BaseNavigateActionRefresh(this);
    JButton refreshButton = new JButton(refreshAction);

    JToolBar upperPanel = new JToolBar(Messages.getMessage("nav.ToolBarName"));
    upperPanel.setRollover(true);
    upperPanel.add(pathLabel);
    upperPanel.add(pathField, "growx");
    upperPanel.add(goUpButton);
    upperPanel.add(refreshButton);

    AddCurrentLocationToFavoriteAction addCurrentLocationToFavoriteAction = new AddCurrentLocationToFavoriteAction(
            this);
    JButton addCurrentLocationToFavoriteButton = new JButton(addCurrentLocationToFavoriteAction);
    addCurrentLocationToFavoriteButton.setText("");
    upperPanel.add(addCurrentLocationToFavoriteButton);

    previewComponent = new PreviewComponent();

    vfsTableModel = new VfsTableModel();

    tableFiles = new JTable(vfsTableModel);
    tableFiles.setFillsViewportHeight(true);
    tableFiles.getColumnModel().getColumn(0).setMinWidth(140);
    tableFiles.getColumnModel().getColumn(1).setMaxWidth(80);
    tableFiles.getColumnModel().getColumn(2).setMaxWidth(80);
    tableFiles.getColumnModel().getColumn(3).setMaxWidth(180);
    tableFiles.getColumnModel().getColumn(3).setMinWidth(120);

    sorter = new TableRowSorter<VfsTableModel>(vfsTableModel);
    final FileNameWithTypeComparator fileNameWithTypeComparator = new FileNameWithTypeComparator();
    sorter.addRowSorterListener(new RowSorterListener() {
        @Override
        public void sorterChanged(RowSorterEvent e) {
            RowSorterEvent.Type type = e.getType();
            if (type.equals(RowSorterEvent.Type.SORT_ORDER_CHANGED)) {
                List<? extends RowSorter.SortKey> sortKeys = e.getSource().getSortKeys();
                for (RowSorter.SortKey sortKey : sortKeys) {
                    if (sortKey.getColumn() == VfsTableModel.COLUMN_NAME) {
                        fileNameWithTypeComparator.setSortOrder(sortKey.getSortOrder());
                    }
                }
            }
        }
    });
    sorter.setComparator(VfsTableModel.COLUMN_NAME, fileNameWithTypeComparator);

    tableFiles.setRowSorter(sorter);
    tableFiles.setShowGrid(false);
    tableFiles.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            try {
                selectionChanged();
            } catch (FileSystemException e1) {
                LOGGER.error("Error during update state", e);
            }
        }
    });
    tableFiles.setColumnSelectionAllowed(false);
    vfsTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            updateStatusText();
        }
    });

    tableFiles.setDefaultRenderer(FileSize.class, new FileSizeTableCellRenderer());
    tableFiles.setDefaultRenderer(FileNameWithType.class, new FileNameWithTypeTableCellRenderer());
    tableFiles.setDefaultRenderer(Date.class, new MixedDateTableCellRenderer());
    tableFiles.setDefaultRenderer(FileType.class, new FileTypeTableCellRenderer());

    tableFiles.getSelectionModel().addListSelectionListener(new PreviewListener(this, previewComponent));

    JPanel favoritesPanel = new JPanel(new MigLayout("wrap, fillx", "[grow]"));
    favoritesUserListModel = new MutableListModel<Favorite>();

    List<Favorite> favSystemLocations = FavoritesUtils.getSystemLocations();
    List<Favorite> favUser = FavoritesUtils.loadFromProperties(configuration);
    List<Favorite> favJVfsFileChooser = FavoritesUtils.getJvfsFileChooserBookmarks();
    for (Favorite favorite : favUser) {
        favoritesUserListModel.add(favorite);
    }
    favoritesUserListModel.addListDataListener(new ListDataListener() {
        @Override
        public void intervalAdded(ListDataEvent e) {
            saveFavorites();

        }

        @Override
        public void intervalRemoved(ListDataEvent e) {
            saveFavorites();
        }

        @Override
        public void contentsChanged(ListDataEvent e) {
            saveFavorites();
        }

        protected void saveFavorites() {
            FavoritesUtils.storeFavorites(configuration, favoritesUserListModel.getList());
        }
    });

    favoritesUserList = new JList(favoritesUserListModel);
    favoritesUserList.setTransferHandler(new MutableListDropHandler(favoritesUserList));
    new MutableListDragListener(favoritesUserList);
    favoritesUserList.setCellRenderer(new FavoriteListCellRenderer());
    favoritesUserList.addFocusListener(new SelectFirstElementFocusAdapter());

    addOpenActionToList(favoritesUserList);
    addEditActionToList(favoritesUserList, favoritesUserListModel);

    favoritesUserList.getActionMap().put(ACTION_DELETE, new AbstractAction(
            Messages.getMessage("favorites.deleteButtonText"), Icons.getInstance().getMinusButton()) {

        @Override
        public void actionPerformed(ActionEvent e) {
            Favorite favorite = favoritesUserListModel.getElementAt(favoritesUserList.getSelectedIndex());
            if (!Favorite.Type.USER.equals(favorite.getType())) {
                return;
            }
            int response = JOptionPane.showConfirmDialog(VfsBrowser.this,
                    Messages.getMessage("favorites.areYouSureToDeleteConnections"),
                    Messages.getMessage("favorites.confirm"), JOptionPane.YES_NO_OPTION);

            if (response == JOptionPane.YES_OPTION) {
                favoritesUserListModel.remove(favoritesUserList.getSelectedIndex());
            }
        }
    });
    InputMap favoritesListInputMap = favoritesUserList.getInputMap(JComponent.WHEN_FOCUSED);
    favoritesListInputMap.put(KeyStroke.getKeyStroke("DELETE"), ACTION_DELETE);

    ActionMap actionMap = tableFiles.getActionMap();
    actionMap.put(ACTION_OPEN, new BaseNavigateActionOpen(this));
    actionMap.put(ACTION_GO_UP, goUpAction);
    actionMap.put(ACTION_APPROVE, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (actionApproveButton.isEnabled()) {
                actionApproveDelegate.actionPerformed(e);
            }
        }
    });

    InputMap inputMap = tableFiles.getInputMap(JComponent.WHEN_FOCUSED);
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), ACTION_OPEN);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_MASK), ACTION_APPROVE);

    inputMap.put(KeyStroke.getKeyStroke("BACK_SPACE"), ACTION_GO_UP);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), ACTION_GO_UP);
    addPopupMenu(favoritesUserList, ACTION_OPEN, ACTION_EDIT, ACTION_DELETE);

    JList favoriteSystemList = new JList(new Vector<Object>(favSystemLocations));
    favoriteSystemList.setCellRenderer(new FavoriteListCellRenderer());
    addOpenActionToList(favoriteSystemList);
    addPopupMenu(favoriteSystemList, ACTION_OPEN);
    favoriteSystemList.addFocusListener(new SelectFirstElementFocusAdapter());

    JList favoriteJVfsList = new JList(new Vector<Object>(favJVfsFileChooser));
    addOpenActionToList(favoriteJVfsList);
    favoriteJVfsList.setCellRenderer(new FavoriteListCellRenderer());
    addPopupMenu(favoriteJVfsList, ACTION_OPEN);
    favoriteJVfsList.addFocusListener(new SelectFirstElementFocusAdapter());

    JLabel favoritesSystemLocationsLabel = getTitleListLabel(Messages.getMessage("favorites.systemLocations"),
            COMPUTER_ICON);
    favoritesSystemLocationsLabel.setLabelFor(favoriteSystemList);
    favoritesSystemLocationsLabel
            .setDisplayedMnemonic(Messages.getMessage("favorites.systemLocations.mnemonic").charAt(0));
    favoritesPanel.add(favoritesSystemLocationsLabel, "gapleft 16");
    favoritesPanel.add(favoriteSystemList, "growx");
    JLabel favoritesFavoritesLabel = getTitleListLabel(Messages.getMessage("favorites.favorites"),
            Icons.getInstance().getStar());
    favoritesFavoritesLabel.setLabelFor(favoritesUserList);
    favoritesFavoritesLabel.setDisplayedMnemonic(Messages.getMessage("favorites.favorites.mnemonic").charAt(0));
    favoritesPanel.add(favoritesFavoritesLabel, "gapleft 16");
    favoritesPanel.add(favoritesUserList, "growx");

    if (favoriteJVfsList.getModel().getSize() > 0) {
        JLabel favoritesJVfsFileChooser = getTitleListLabel(
                Messages.getMessage("favorites.JVfsFileChooserBookmarks"), null);
        favoritesJVfsFileChooser.setDisplayedMnemonic(
                Messages.getMessage("favorites.JVfsFileChooserBookmarks.mnemonic").charAt(0));
        favoritesJVfsFileChooser.setLabelFor(favoriteJVfsList);
        favoritesPanel.add(favoritesJVfsFileChooser, "gapleft 16");
        favoritesPanel.add(favoriteJVfsList, "growx");
    }

    tableFiles.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                tableFiles.getActionMap().get(ACTION_OPEN).actionPerformed(null);
            }
        }
    });
    tableFiles.addKeyListener(new QuickSearchKeyAdapter());

    cardLayout = new CardLayout();
    tablePanel = new JPanel(cardLayout);
    loadingProgressBar = new JProgressBar();
    loadingProgressBar.setStringPainted(true);
    loadingProgressBar.setString(Messages.getMessage("browser.loading"));
    loadingProgressBar.setIndeterminate(true);
    loadingIconLabel = new JLabel(Icons.getInstance().getNetworkStatusOnline());
    skipCheckingLinksButton = new JToggleButton(Messages.getMessage("browser.skipCheckingLinks"));
    skipCheckingLinksButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (taskContext != null) {
                taskContext.setStop(skipCheckingLinksButton.isSelected());
            }
        }
    });

    showHidCheckBox = new JCheckBox(Messages.getMessage("browser.showHidden.label"), showHidden);
    showHidCheckBox.setToolTipText(Messages.getMessage("browser.showHidden.tooltip"));
    showHidCheckBox.setMnemonic(Messages.getMessage("browser.showHidden.mnemonic").charAt(0));
    Font tmpFont = showHidCheckBox.getFont();
    showHidCheckBox.setFont(tmpFont.deriveFont(tmpFont.getSize() * 0.9f));
    showHidCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateUiFilters();
        }
    });

    final String defaultFilterText = Messages.getMessage("browser.nameFilter.defaultText");
    filterField = new JTextField("", 16);
    filterField.setForeground(filterField.getDisabledTextColor());
    filterField.setToolTipText(Messages.getMessage("browser.nameFilter.tooltip"));
    PromptSupport.setPrompt(defaultFilterText, filterField);
    filterField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            documentChanged();
        }

        void documentChanged() {
            if (filterField.getText().length() == 0) {
                updateUiFilters();
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            documentChanged();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            documentChanged();
        }
    });
    filterField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            updateUiFilters();
        }
    });

    AbstractAction actionClearRegexFilter = new

    AbstractAction(Messages.getMessage("browser.nameFilter.clearFilterText")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterField.setText("");
        }
    };
    filterField.getActionMap().put(ACTION_FOCUS_ON_TABLE, actionFocusOnTable);
    filterField.getActionMap().put(ACTION_CLEAR_REGEX_FILTER, actionClearRegexFilter);

    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), ACTION_FOCUS_ON_TABLE);
    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), ACTION_FOCUS_ON_TABLE);
    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),
            ACTION_FOCUS_ON_TABLE);
    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            ACTION_FOCUS_ON_TABLE);
    filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            ACTION_CLEAR_REGEX_FILTER);

    JLabel nameFilterLabel = new JLabel(Messages.getMessage("browser.nameFilter"));
    nameFilterLabel.setLabelFor(filterField);
    nameFilterLabel.setDisplayedMnemonic(Messages.getMessage("browser.nameFilter.mnemonic").charAt(0));

    sorter.setRowFilter(createFilter());
    statusLabel = new JLabel();

    actionApproveButton = new JButton();
    actionApproveButton.setFont(actionApproveButton.getFont().deriveFont(Font.BOLD));
    actionCancelButton = new JButton();

    ActionMap browserActionMap = this.getActionMap();
    browserActionMap.put(ACTION_FOCUS_ON_REGEX_FILTER, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            filterField.requestFocus();
            filterField.selectAll();
            GuiUtils.blinkComponent(filterField);
        }
    });

    browserActionMap.put(ACTION_FOCUS_ON_PATH, new SetFocusOnAction(pathField));
    browserActionMap.put(ACTION_SWITCH_SHOW_HIDDEN, new ClickOnJComponentAction(showHidCheckBox));
    browserActionMap.put(ACTION_REFRESH, refreshAction);
    browserActionMap.put(ACTION_ADD_CURRENT_LOCATION_TO_FAVORITES, addCurrentLocationToFavoriteAction);
    browserActionMap.put(ACTION_GO_UP, goUpAction);
    browserActionMap.put(ACTION_FOCUS_ON_TABLE, new SetFocusOnAction(tableFiles));

    InputMap browserInputMap = this.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    browserInputMap.put(KeyStroke.getKeyStroke("control F"), ACTION_FOCUS_ON_REGEX_FILTER);
    browserInputMap.put(KeyStroke.getKeyStroke("control L"), ACTION_FOCUS_ON_PATH);
    browserInputMap.put(KeyStroke.getKeyStroke("F4"), ACTION_FOCUS_ON_PATH);
    browserInputMap.put(KeyStroke.getKeyStroke("control H"), ACTION_SWITCH_SHOW_HIDDEN);
    browserInputMap.put(KeyStroke.getKeyStroke("control R"), ACTION_REFRESH);
    browserInputMap.put(KeyStroke.getKeyStroke("F5"), ACTION_REFRESH);
    browserInputMap.put(KeyStroke.getKeyStroke("control D"), ACTION_ADD_CURRENT_LOCATION_TO_FAVORITES);
    browserInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK), ACTION_GO_UP);
    browserInputMap.put(KeyStroke.getKeyStroke("control T"), ACTION_FOCUS_ON_TABLE);

    //DO layout
    // create the layer for the panel using our custom layerUI
    tableScrollPane = new JScrollPane(tableFiles);

    JPanel tableScrollPaneWithFilter = new JPanel(new BorderLayout());
    tableScrollPaneWithFilter.add(tableScrollPane);
    JToolBar filtersToolbar = new JToolBar("Filters");
    filtersToolbar.setFloatable(false);
    filtersToolbar.setBorderPainted(true);
    tableScrollPaneWithFilter.add(filtersToolbar, BorderLayout.SOUTH);
    filtersToolbar.add(nameFilterLabel);
    filtersToolbar.add(filterField);
    filtersToolbar.add(showHidCheckBox);
    JSplitPane tableWithPreviewPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
            tableScrollPaneWithFilter, previewComponent);
    tableWithPreviewPane.setOneTouchExpandable(true);

    JPanel loadingPanel = new JPanel(new MigLayout());
    loadingPanel.add(loadingIconLabel, "right");
    loadingPanel.add(loadingProgressBar, "left, w 420:420:500,wrap");
    loadingPanel.add(skipCheckingLinksButton, "span, right");
    tablePanel.add(loadingPanel, LOADING);
    tablePanel.add(tableWithPreviewPane, TABLE);

    JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(favoritesPanel),
            tablePanel);
    jSplitPane.setOneTouchExpandable(true);
    jSplitPane.setDividerLocation(180);

    JPanel southPanel = new JPanel(new MigLayout("", "[]push[][]", ""));
    southPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    southPanel.add(statusLabel);
    southPanel.add(actionApproveButton);
    southPanel.add(actionCancelButton);

    this.add(upperPanel, BorderLayout.NORTH);
    this.add(jSplitPane, BorderLayout.CENTER);
    this.add(southPanel, BorderLayout.SOUTH);

    try {
        selectionChanged();
    } catch (FileSystemException e) {
        LOGGER.error("Can't initialize default selection mode", e);
    }
    // Why this not done in EDT?
    // Is it assume that constructor is invoked from an  EDT?
    try {
        if (initialPath == null) {
            goToUrl(VFSUtils.getUserHome());
        } else {
            try {
                FileObject resolveFile = VFSUtils.resolveFileObject(initialPath);
                if (resolveFile != null && resolveFile.getType() == FileType.FILE) {
                    loadAndSelSingleFile(resolveFile);
                    pathField.setText(resolveFile.getURL().toString());
                    targetFileSelected = true;
                    return;
                }
            } catch (FileSystemException fse) {
                // Intentionally empty
            }
            goToUrl(initialPath);
        }
    } catch (FileSystemException e1) {
        LOGGER.error("Can't initialize default location", e1);
    }
    showTable();
}

From source file:shuffle.fwk.ShuffleController.java

@Override
public Font scaleFont(Font givenFont) {
    Font retFont = givenFont;
    Integer menuFontOverride = getPreferencesManager().getIntegerValue(KEY_FONT_SIZE_SCALING);
    if (menuFontOverride != null && menuFontOverride != 100 && menuFontOverride > 0
            && menuFontOverride < 10000) {
        float scale = menuFontOverride.floatValue() / 100.0f;
        float adjustedSize = retFont.getSize2D() * scale;
        retFont = retFont.deriveFont(adjustedSize);
    }// www  .j  a  v  a2 s. c  o  m
    return retFont;
}

From source file:org.yccheok.jstock.gui.Utils.java

/**
 * Get a new bold version of specified font, with rest of specified font
 * attributes remained the same./*from  w  w  w  .  j  ava  2 s .  c  o  m*/
 * 
 * @param font specified font
 * @return a new bold version of specified font
 */
public static Font getBoldFont(Font font) {
    return font.deriveFont(font.getStyle() | Font.BOLD);
}