Search in sources :

Example 21 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project jdk8u_jdk by JetBrains.

the class ColorCustomizationTest method main.

public static void main(String[] args) throws Exception {
    nimbus = new NimbusLookAndFeel();
    try {
        UIManager.setLookAndFeel(nimbus);
    } catch (UnsupportedLookAndFeelException e) {
        throw new Error("Unable to set Nimbus LAF");
    }
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            new ColorCustomizationTest().test();
        }
    });
}
Also used : UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel)

Example 22 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project jabref by JabRef.

the class JabRefGUI method setLookAndFeel.

private void setLookAndFeel() {
    try {
        String lookFeel;
        String systemLookFeel = UIManager.getSystemLookAndFeelClassName();
        if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
            // See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
            if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
                // Metal L&F
                lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
                LOGGER.warn("There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution.");
            } else {
                lookFeel = systemLookFeel;
            }
        } else {
            lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
        }
        // FIXME: Open JDK problem
        if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel) && !System.getProperty("java.runtime.name").contains("OpenJDK")) {
            // try to avoid ending up with the ugly Metal L&F
            Plastic3DLookAndFeel lnf = new Plastic3DLookAndFeel();
            MetalLookAndFeel.setCurrentTheme(new SkyBluer());
            com.jgoodies.looks.Options.setPopupDropShadowEnabled(true);
            UIManager.setLookAndFeel(lnf);
        } else {
            try {
                UIManager.setLookAndFeel(lookFeel);
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
                // specified look and feel does not exist on the classpath, so use system l&f
                UIManager.setLookAndFeel(systemLookFeel);
                // also set system l&f as default
                Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel);
                // notify the user
                JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), Localization.lang("Unable to find the requested look and feel and thus the default one is used."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
                LOGGER.warn("Unable to find requested look and feel", e);
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Look and feel could not be set", e);
    }
    // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms
    boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS);
    if (overrideDefaultFonts) {
        int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE);
        UIDefaults defaults = UIManager.getDefaults();
        Enumeration<Object> keys = defaults.keys();
        for (Object key : Collections.list(keys)) {
            if ((key instanceof String) && ((String) key).endsWith(".font")) {
                FontUIResource font = (FontUIResource) UIManager.get(key);
                font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
                defaults.put(key, font);
            }
        }
    }
}
Also used : UIDefaults(javax.swing.UIDefaults) FontUIResource(javax.swing.plaf.FontUIResource) Plastic3DLookAndFeel(com.jgoodies.looks.plastic.Plastic3DLookAndFeel) DatabaseNotSupportedException(org.jabref.shared.exception.DatabaseNotSupportedException) SQLException(java.sql.SQLException) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) NotASharedDatabaseException(org.jabref.shared.exception.NotASharedDatabaseException) InvalidDBMSConnectionPropertiesException(org.jabref.shared.exception.InvalidDBMSConnectionPropertiesException) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) SkyBluer(com.jgoodies.looks.plastic.theme.SkyBluer)

Example 23 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project Terasology by MovingBlocks.

the class NUIEditorScreen method initialise.

@Override
public void initialise() {
    // Retrieve the widgets based on their identifiers.
    UIDropdownScrollable<String> availableAssetDropdown = find(AVAILABLE_ASSETS_ID, UIDropdownScrollable.class);
    JsonEditorTreeView editor = find(EDITOR_TREE_VIEW_ID, JsonEditorTreeView.class);
    selectedScreenBox = find(SELECTED_SCREEN_ID, UIBox.class);
    super.setEditorSystem(nuiEditorSystem);
    super.setEditor(editor);
    // Populate the list of screens.
    List<String> availableAssetList = Lists.newArrayList();
    availableAssetList.add(CREATE_NEW_SCREEN);
    availableAssetList.addAll(assetManager.getAvailableAssets(UIElement.class).stream().map(Object::toString).collect(Collectors.toList()));
    Collections.sort(availableAssetList);
    if (availableAssetDropdown != null) {
        availableAssetDropdown.setOptions(availableAssetList);
        availableAssetDropdown.bindSelection(new Binding<String>() {

            @Override
            public String get() {
                return selectedAsset;
            }

            @Override
            public void set(String value) {
                // Construct a new screen tree (or de-serialize from an existing asset)
                selectedAssetPending = value;
                if (CREATE_NEW_SCREEN.equals(value)) {
                    selectedAssetPath = null;
                    resetState(NUIEditorNodeUtils.createNewScreen());
                } else {
                    selectAsset(new ResourceUrn(value));
                }
            }
        });
    }
    if (editor != null) {
        editor.subscribeTreeViewUpdate(() -> {
            getEditor().addToHistory();
            resetPreviewWidget();
            updateConfig();
            setUnsavedChangesPresent(true);
            updateAutosave();
        });
        editor.setContextMenuTreeProducer(node -> {
            NUIEditorMenuTreeBuilder nuiEditorMenuTreeBuilder = new NUIEditorMenuTreeBuilder();
            nuiEditorMenuTreeBuilder.setManager(getManager());
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_COPY, getEditor()::copyNode);
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_PASTE, getEditor()::pasteNode);
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_EDIT, this::editNode);
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_DELETE, getEditor()::deleteNode);
            nuiEditorMenuTreeBuilder.putConsumer(NUIEditorMenuTreeBuilder.OPTION_ADD_WIDGET, this::addWidget);
            nuiEditorMenuTreeBuilder.subscribeAddContextMenu(n -> {
                getEditor().fireUpdateListeners();
                // Automatically edit a node that's been added.
                if (n.getValue().getType() == JsonTreeValue.Type.KEY_VALUE_PAIR) {
                    getEditor().getModel().getNode(getEditor().getSelectedIndex()).setExpanded(true);
                    getEditor().getModel().resetNodes();
                    getEditor().setSelectedIndex(getEditor().getModel().indexOf(n));
                    editNode(n);
                }
            });
            return nuiEditorMenuTreeBuilder.createPrimaryContextMenu(node);
        });
        editor.setEditor(this::editNode, getManager());
    }
    UIButton save = find("save", UIButton.class);
    save.bindEnabled(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return CREATE_NEW_SCREEN.equals(selectedAsset) || areUnsavedChangesPresent();
        }
    });
    save.subscribe(button -> {
        // Save the current look and feel.
        LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel();
        // (Temporarily) set the look and feel to the system default.
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException ignored) {
        }
        // Configure the file chooser.
        JFileChooser fileChooser = new JFileChooser() {

            @Override
            protected JDialog createDialog(Component parent) {
                JDialog dialog = super.createDialog(parent);
                dialog.setLocationByPlatform(true);
                dialog.setAlwaysOnTop(true);
                return dialog;
            }
        };
        fileChooser.setSelectedFile(new File(CREATE_NEW_SCREEN.equals(selectedAsset) ? "untitled.ui" : selectedAsset.split(":")[1] + ".ui"));
        fileChooser.setFileFilter(new FileNameExtensionFilter("UI asset file (*.ui)", "ui"));
        if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            saveToFile(fileChooser.getSelectedFile());
            deleteAutosave();
        }
        // Reload the look and feel.
        try {
            UIManager.setLookAndFeel(currentLookAndFeel);
        } catch (UnsupportedLookAndFeelException ignored) {
        }
    });
    UIButton override = find("override", UIButton.class);
    override.bindEnabled(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return selectedAssetPath != null && areUnsavedChangesPresent();
        }
    });
    override.subscribe(button -> {
        saveToFile(selectedAssetPath);
        deleteAutosave();
    });
    // Set the handlers for the editor buttons.
    WidgetUtil.trySubscribe(this, "settings", button -> getManager().pushScreen(NUIEditorSettingsScreen.ASSET_URI, NUIEditorSettingsScreen.class));
    WidgetUtil.trySubscribe(this, "copy", button -> copyJson());
    WidgetUtil.trySubscribe(this, "paste", button -> pasteJson());
    WidgetUtil.trySubscribe(this, "undo", button -> undo());
    WidgetUtil.trySubscribe(this, "redo", button -> redo());
    WidgetUtil.trySubscribe(this, "close", button -> nuiEditorSystem.toggleEditor());
    updateConfig();
}
Also used : UIBox(org.terasology.rendering.nui.widgets.UIBox) LookAndFeel(javax.swing.LookAndFeel) UIButton(org.terasology.rendering.nui.widgets.UIButton) JsonEditorTreeView(org.terasology.rendering.nui.widgets.JsonEditorTreeView) ResourceUrn(org.terasology.assets.ResourceUrn) Component(java.awt.Component) NUIEditorMenuTreeBuilder(org.terasology.rendering.nui.editor.utils.NUIEditorMenuTreeBuilder) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) JFileChooser(javax.swing.JFileChooser) AssetDataFile(org.terasology.assets.format.AssetDataFile) File(java.io.File) JDialog(javax.swing.JDialog)

Example 24 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project jgnash by ccavanaugh.

the class ThemeManager method setLookAndFeel.

private static void setLookAndFeel(final String lookAndFeel) {
    Preferences pref = Preferences.userNodeForPackage(ThemeManager.class);
    String theme = pref.get(THEME, DEFAULT_THEME);
    try {
        Class<?> lafClass = Class.forName(lookAndFeel);
        Object lafInstance = lafClass.newInstance();
        if (lafInstance instanceof SubstanceSkin) {
            UIManager.put(SubstanceLookAndFeel.SHOW_EXTRA_WIDGETS, Boolean.TRUE);
            if (isSubstanceAnimationsEnabled()) {
                AnimationConfigurationManager.getInstance().setTimelineDuration(animationDuration);
            } else {
                AnimationConfigurationManager.getInstance().setTimelineDuration(0);
            }
            SubstanceLookAndFeel.setSkin(lookAndFeel);
        } else if (lafInstance instanceof NimbusLookAndFeel) {
            UIManager.setLookAndFeel((LookAndFeel) lafInstance);
            NimbusUtils.changeFontSize(getNimbusFontSize());
        } else if (lafInstance instanceof MetalLookAndFeel) {
            UIManager.setLookAndFeel((LookAndFeel) lafInstance);
            setTheme(theme);
        } else if (lafInstance instanceof LookAndFeel) {
            UIManager.setLookAndFeel((LookAndFeel) lafInstance);
        }
    } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
        Logger.getLogger(ThemeManager.class.getName()).log(Level.WARNING, null, e);
    }
}
Also used : LookAndFeel(javax.swing.LookAndFeel) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) SubstanceLookAndFeel(org.pushingpixels.substance.api.SubstanceLookAndFeel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel) SubstanceSkin(org.pushingpixels.substance.api.SubstanceSkin) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) Preferences(java.util.prefs.Preferences)

Example 25 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project sirix by sirixdb.

the class GUI method createAndShowGUI.

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event dispatch thread.
 */
private static void createAndShowGUI() {
    ExceptionReporting.registerExceptionReporter();
    // Added to handle possible JDK 1.6 bug (thanks to Makoto Yui and the BaseX
    // guys).
    UIManager.getInstalledLookAndFeels();
    // Refresh views when windows are resized (thanks to the BaseX guys).
    Toolkit.getDefaultToolkit().setDynamicLayout(true);
    if (mUseSystemLookAndFeel) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
            LOGWRAPPER.error(e.getMessage(), e);
        }
    } else {
        try {
            for (final LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (final Exception e) {
            // feel.
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException exc) {
                LOGWRAPPER.error(exc.getMessage(), exc);
            }
        }
    }
    // Create GUI.
    new GUI(new GUIProp());
}
Also used : UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) SirixException(org.sirix.exception.SirixException)

Aggregations

UnsupportedLookAndFeelException (javax.swing.UnsupportedLookAndFeelException)32 LookAndFeel (javax.swing.LookAndFeel)8 File (java.io.File)6 LookAndFeelInfo (javax.swing.UIManager.LookAndFeelInfo)6 Component (java.awt.Component)5 JFileChooser (javax.swing.JFileChooser)5 JFrame (javax.swing.JFrame)5 JDialog (javax.swing.JDialog)4 JPanel (javax.swing.JPanel)4 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)4 JLabel (javax.swing.JLabel)3 BorderLayout (java.awt.BorderLayout)2 Color (java.awt.Color)2 Dimension (java.awt.Dimension)2 FlowLayout (java.awt.FlowLayout)2 Font (java.awt.Font)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Preferences (java.util.prefs.Preferences)2 DefaultListModel (javax.swing.DefaultListModel)2