Example usage for javax.swing LookAndFeel isSupportedLookAndFeel

List of usage examples for javax.swing LookAndFeel isSupportedLookAndFeel

Introduction

In this page you can find the example usage for javax.swing LookAndFeel isSupportedLookAndFeel.

Prototype

public abstract boolean isSupportedLookAndFeel();

Source Link

Document

Return true if the underlying platform supports and or permits this look and feel.

Usage

From source file:FileChooserDemo.java

/**
 * A utility function that layers on top of the LookAndFeel's
 * isSupportedLookAndFeel() method. Returns true if the LookAndFeel is
 * supported. Returns false if the LookAndFeel is not supported and/or if
 * there is any kind of error checking if the LookAndFeel is supported.
 * /*from w ww  .  ja v a 2  s. c o m*/
 * The L&F menu will use this method to detemine whether the various L&F
 * options should be active or inactive.
 * 
 */
protected boolean isAvailableLookAndFeel(String laf) {
    try {
        Class lnfClass = Class.forName(laf);
        LookAndFeel newLAF = (LookAndFeel) (lnfClass.newInstance());
        return newLAF.isSupportedLookAndFeel();
    } catch (Exception e) { // If ANYTHING weird happens, return false
        return false;
    }
}

From source file:FileChooserDemo.java

public FileChooserDemo() {
    UIManager.LookAndFeelInfo[] installedLafs = UIManager.getInstalledLookAndFeels();
    for (UIManager.LookAndFeelInfo lafInfo : installedLafs) {
        try {//w ww  .j  a v  a  2  s . c  o m
            Class lnfClass = Class.forName(lafInfo.getClassName());
            LookAndFeel laf = (LookAndFeel) (lnfClass.newInstance());
            if (laf.isSupportedLookAndFeel()) {
                String name = lafInfo.getName();
                supportedLaFs.add(new SupportedLaF(name, laf));
            }
        } catch (Exception e) { // If ANYTHING weird happens, don't add it
            continue;
        }
    }

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    chooser = new JFileChooser();
    previewer = new FilePreviewer(chooser);

    // Create Custom FileView
    fileView = new ExampleFileView();
    //    fileView.putIcon("jpg", new ImageIcon(getClass().getResource("/resources/images/jpgIcon.jpg")));
    //  fileView.putIcon("gif", new ImageIcon(getClass().getResource("/resources/images/gifIcon.gif")));

    // create a radio listener to listen to option changes
    OptionListener optionListener = new OptionListener();

    // Create options
    openRadioButton = new JRadioButton("Open");
    openRadioButton.setSelected(true);
    openRadioButton.addActionListener(optionListener);

    saveRadioButton = new JRadioButton("Save");
    saveRadioButton.addActionListener(optionListener);

    customButton = new JRadioButton("Custom");
    customButton.addActionListener(optionListener);

    customField = new JTextField(8) {
        public Dimension getMaximumSize() {
            return new Dimension(getPreferredSize().width, getPreferredSize().height);
        }
    };
    customField.setText("Doit");
    customField.setAlignmentY(JComponent.TOP_ALIGNMENT);
    customField.setEnabled(false);
    customField.addActionListener(optionListener);

    ButtonGroup group1 = new ButtonGroup();
    group1.add(openRadioButton);
    group1.add(saveRadioButton);
    group1.add(customButton);

    // filter buttons
    showAllFilesFilterCheckBox = new JCheckBox("Show \"All Files\" Filter");
    showAllFilesFilterCheckBox.addActionListener(optionListener);
    showAllFilesFilterCheckBox.setSelected(true);

    showImageFilesFilterCheckBox = new JCheckBox("Show JPG and GIF Filters");
    showImageFilesFilterCheckBox.addActionListener(optionListener);
    showImageFilesFilterCheckBox.setSelected(false);

    accessoryCheckBox = new JCheckBox("Show Preview");
    accessoryCheckBox.addActionListener(optionListener);
    accessoryCheckBox.setSelected(false);

    // more options
    setHiddenCheckBox = new JCheckBox("Show Hidden Files");
    setHiddenCheckBox.addActionListener(optionListener);

    showFullDescriptionCheckBox = new JCheckBox("With File Extensions");
    showFullDescriptionCheckBox.addActionListener(optionListener);
    showFullDescriptionCheckBox.setSelected(true);
    showFullDescriptionCheckBox.setEnabled(false);

    useFileViewCheckBox = new JCheckBox("Use FileView");
    useFileViewCheckBox.addActionListener(optionListener);
    useFileViewCheckBox.setSelected(false);

    useEmbedInWizardCheckBox = new JCheckBox("Embed in Wizard");
    useEmbedInWizardCheckBox.addActionListener(optionListener);
    useEmbedInWizardCheckBox.setSelected(false);

    useControlsCheckBox = new JCheckBox("Show Control Buttons");
    useControlsCheckBox.addActionListener(optionListener);
    useControlsCheckBox.setSelected(true);

    enableDragCheckBox = new JCheckBox("Enable Dragging");
    enableDragCheckBox.addActionListener(optionListener);

    // File or Directory chooser options
    ButtonGroup group3 = new ButtonGroup();
    justFilesRadioButton = new JRadioButton("Just Select Files");
    justFilesRadioButton.setSelected(true);
    group3.add(justFilesRadioButton);
    justFilesRadioButton.addActionListener(optionListener);

    justDirectoriesRadioButton = new JRadioButton("Just Select Directories");
    group3.add(justDirectoriesRadioButton);
    justDirectoriesRadioButton.addActionListener(optionListener);

    bothFilesAndDirectoriesRadioButton = new JRadioButton("Select Files or Directories");
    group3.add(bothFilesAndDirectoriesRadioButton);
    bothFilesAndDirectoriesRadioButton.addActionListener(optionListener);

    singleSelectionRadioButton = new JRadioButton("Single Selection", true);
    singleSelectionRadioButton.addActionListener(optionListener);

    multiSelectionRadioButton = new JRadioButton("Multi Selection");
    multiSelectionRadioButton.addActionListener(optionListener);

    ButtonGroup group4 = new ButtonGroup();
    group4.add(singleSelectionRadioButton);
    group4.add(multiSelectionRadioButton);

    // Create show button
    showButton = new JButton("Show FileChooser");
    showButton.addActionListener(this);
    showButton.setMnemonic('s');

    // Create laf combo box

    lafComboBox = new JComboBox(supportedLaFs);
    lafComboBox.setEditable(false);
    lafComboBox.addActionListener(optionListener);

    // ********************************************************
    // ******************** Dialog Type ***********************
    // ********************************************************
    JPanel control1 = new InsetPanel(insets);
    control1.setBorder(BorderFactory.createTitledBorder("Dialog Type"));

    control1.setLayout(new BoxLayout(control1, BoxLayout.Y_AXIS));
    control1.add(Box.createRigidArea(vpad20));
    control1.add(openRadioButton);
    control1.add(Box.createRigidArea(vpad7));
    control1.add(saveRadioButton);
    control1.add(Box.createRigidArea(vpad7));
    control1.add(customButton);
    control1.add(Box.createRigidArea(vpad4));
    JPanel fieldWrapper = new JPanel();
    fieldWrapper.setLayout(new BoxLayout(fieldWrapper, BoxLayout.X_AXIS));
    fieldWrapper.setAlignmentX(Component.LEFT_ALIGNMENT);
    fieldWrapper.add(Box.createRigidArea(hpad10));
    fieldWrapper.add(Box.createRigidArea(hpad10));
    fieldWrapper.add(customField);
    control1.add(fieldWrapper);
    control1.add(Box.createRigidArea(vpad20));
    control1.add(Box.createGlue());

    // ********************************************************
    // ***************** Filter Controls **********************
    // ********************************************************
    JPanel control2 = new InsetPanel(insets);
    control2.setBorder(BorderFactory.createTitledBorder("Filter Controls"));
    control2.setLayout(new BoxLayout(control2, BoxLayout.Y_AXIS));
    control2.add(Box.createRigidArea(vpad20));
    control2.add(showAllFilesFilterCheckBox);
    control2.add(Box.createRigidArea(vpad7));
    control2.add(showImageFilesFilterCheckBox);
    control2.add(Box.createRigidArea(vpad4));
    JPanel checkWrapper = new JPanel();
    checkWrapper.setLayout(new BoxLayout(checkWrapper, BoxLayout.X_AXIS));
    checkWrapper.setAlignmentX(Component.LEFT_ALIGNMENT);
    checkWrapper.add(Box.createRigidArea(hpad10));
    checkWrapper.add(Box.createRigidArea(hpad10));
    checkWrapper.add(showFullDescriptionCheckBox);
    control2.add(checkWrapper);
    control2.add(Box.createRigidArea(vpad20));
    control2.add(Box.createGlue());

    // ********************************************************
    // ****************** Display Options *********************
    // ********************************************************
    JPanel control3 = new InsetPanel(insets);
    control3.setBorder(BorderFactory.createTitledBorder("Display Options"));
    control3.setLayout(new BoxLayout(control3, BoxLayout.Y_AXIS));
    control3.add(Box.createRigidArea(vpad20));
    control3.add(setHiddenCheckBox);
    control3.add(Box.createRigidArea(vpad7));
    control3.add(useFileViewCheckBox);
    control3.add(Box.createRigidArea(vpad7));
    control3.add(accessoryCheckBox);
    control3.add(Box.createRigidArea(vpad7));
    control3.add(useEmbedInWizardCheckBox);
    control3.add(Box.createRigidArea(vpad7));
    control3.add(useControlsCheckBox);
    control3.add(Box.createRigidArea(vpad7));
    control3.add(enableDragCheckBox);
    control3.add(Box.createRigidArea(vpad20));
    control3.add(Box.createGlue());

    // ********************************************************
    // ************* File & Directory Options *****************
    // ********************************************************
    JPanel control4 = new InsetPanel(insets);
    control4.setBorder(BorderFactory.createTitledBorder("File and Directory Options"));
    control4.setLayout(new BoxLayout(control4, BoxLayout.Y_AXIS));
    control4.add(Box.createRigidArea(vpad20));
    control4.add(justFilesRadioButton);
    control4.add(Box.createRigidArea(vpad7));
    control4.add(justDirectoriesRadioButton);
    control4.add(Box.createRigidArea(vpad7));
    control4.add(bothFilesAndDirectoriesRadioButton);
    control4.add(Box.createRigidArea(vpad20));
    control4.add(singleSelectionRadioButton);
    control4.add(Box.createRigidArea(vpad7));
    control4.add(multiSelectionRadioButton);
    control4.add(Box.createRigidArea(vpad20));
    control4.add(Box.createGlue());

    // ********************************************************
    // **************** Look & Feel Switch ********************
    // ********************************************************
    JPanel panel = new JPanel();
    panel.add(new JLabel("Look and Feel: "));
    panel.add(lafComboBox);
    panel.add(showButton);

    // ********************************************************
    // ****************** Wrap 'em all up *********************
    // ********************************************************
    JPanel wrapper = new JPanel();
    wrapper.setLayout(new BoxLayout(wrapper, BoxLayout.X_AXIS));

    add(Box.createRigidArea(vpad20));

    wrapper.add(Box.createRigidArea(hpad10));
    wrapper.add(Box.createRigidArea(hpad10));
    wrapper.add(control1);
    wrapper.add(Box.createRigidArea(hpad10));
    wrapper.add(control2);
    wrapper.add(Box.createRigidArea(hpad10));
    wrapper.add(control3);
    wrapper.add(Box.createRigidArea(hpad10));
    wrapper.add(control4);
    wrapper.add(Box.createRigidArea(hpad10));
    wrapper.add(Box.createRigidArea(hpad10));

    add(wrapper);
    add(Box.createRigidArea(vpad20));
    add(panel);
    add(Box.createRigidArea(vpad20));
}

From source file:phex.gui.common.LookAndFeelUtils.java

/**
 * Determines the LAF to use for Phex. The LAF is supported and available.
 * It takes three steps:/*from  ww w . ja v  a 2  s .c o m*/
 * First the given defaultClass is tried.
 * Second the Phex default LAF is tried.
 * Third the Java default is used.
 * @param defaultClass the default class to try.
 * @return the LAF class to use.
 */
public static LookAndFeel determineLAF(String defaultClass) {
    String lafClass = defaultClass;

    // first.. try the requested LAF
    LookAndFeel laf = (LookAndFeel) ClassUtils.newInstanceQuitly(ClassUtils.classForNameQuitly(lafClass));
    if (laf != null && laf.isSupportedLookAndFeel()) {
        return laf;
    }

    // second.. try the Phex default LAF
    lafClass = getDefaultLAFClassName();
    laf = (LookAndFeel) ClassUtils.newInstanceQuitly(ClassUtils.classForNameQuitly(lafClass));
    if (laf != null && laf.isSupportedLookAndFeel()) {
        return laf;
    }

    // third.. try the Swing default LAF
    lafClass = UIManager.getCrossPlatformLookAndFeelClassName();
    laf = (LookAndFeel) ClassUtils.newInstanceQuitly(ClassUtils.classForNameQuitly(lafClass));
    return laf;
}