Search in sources :

Example 26 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project beast2 by CompEvol.

the class Utils method loadUIManager.

public static void loadUIManager() {
    if (isMac()) {
        System.setProperty("apple.awt.graphics.UseQuartz", "true");
        System.setProperty("apple.awt.antialiasing", "true");
        System.setProperty("apple.awt.rendering", "VALUE_RENDER_QUALITY");
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("apple.awt.draggableWindowBackground", "true");
        System.setProperty("apple.awt.showGrowBox", "true");
        LookAndFeel laf = UIManager.getLookAndFeel();
        try {
            try {
                // We need to do this using dynamic class loading to avoid other platforms
                // having to link to this class. If the Quaqua library is not on the classpath
                // it simply won't be used.
                Class<?> qm = Class.forName("ch.randelshofer.quaqua.QuaquaManager");
                Method method = qm.getMethod("setExcludedUIs", Set.class);
                Set<String> excludes = new HashSet<>();
                excludes.add("Button");
                excludes.add("ToolBar");
                method.invoke(null, excludes);
            } catch (Throwable e) {
            }
            // set the Quaqua Look and Feel in the UIManager
            UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
            UIManager.put("SystemFont", new Font("Lucida Grande", Font.PLAIN, 13));
            UIManager.put("SmallSystemFont", new Font("Lucida Grande", Font.PLAIN, 11));
        } catch (Exception e) {
            Log.warning.println(e.getMessage());
            try {
                UIManager.setLookAndFeel(laf);
            } catch (UnsupportedLookAndFeelException e1) {
                e1.printStackTrace();
            }
        }
    } else {
        try {
            // Set System L&F
            // this is supposed to look OK on high res screens
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            Log.warning.println(e.getMessage());
        }
    }
    // change font size, if specified in beauti.properties file
    String fontsize = getBeautiProperty("fontsize");
    if (fontsize != null) {
        try {
            setFontSize(Integer.parseInt(fontsize));
        } catch (NumberFormatException e) {
        // ignore if fontsize is improperly formatted.
        }
    }
// APART FROM THE ABOVE CODE FOR OLD MAC OS X, WE SHOULD LEAVE THE UIManager to the defaults, rather than mess it up
// DEFAULT is almost always the most appropriate thing to use!
// try {
// 
// if (!lafLoaded) {
// if (System.getProperty("beast.laf") != null && !System.getProperty("beast.laf").equals("")) {
// UIManager.setLookAndFeel(System.getProperty("beast.laf"));
// } else if (isMac()) {
// UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
// } else { // If Windows or Linux
// try {
// UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
// } catch (Exception e) {
// UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
// }
// }
// }
// } catch (Exception e) {
// }
}
Also used : Method(java.lang.reflect.Method) LookAndFeel(javax.swing.LookAndFeel) Font(java.awt.Font) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) IOException(java.io.IOException) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) HashSet(java.util.HashSet)

Example 27 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project mafscaling by vimsh.

the class MafScaling method main.

/**
 * Launch the application.
 * @throws UnsupportedLookAndFeelException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ClassNotFoundException
 */
public static void main(String[] args) throws Exception {
    if (UIManager.getLookAndFeel().getName().equals("Nimbus")) {
        UIManager.put("Table.gridColor", new Color(214, 217, 223));
        UIManager.put("Table.disabled", false);
        UIManager.put("Table.showGrid", true);
        UIManager.put("Table.intercellSpacing", new Dimension(1, 1));
        UIManager.put("TitledBorder.font", new Font(Font.SANS_SERIF, Font.PLAIN, 12));
        UIManager.put("Table.selectionBackground", new Color(115, 164, 209));
        UIManager.put("Table.selectionForeground", Color.WHITE);
        UIManager.put("Table.focusCellBackground", new Color(115, 164, 209));
        UIManager.put("Table.focusCellForeground", Color.WHITE);
    }
    EventQueue.invokeLater(new Runnable() {

        public void run() {
            try {
                MafScaling window = new MafScaling();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
                logger.error(e);
            }
        }
    });
}
Also used : Color(java.awt.Color) Dimension(java.awt.Dimension) Font(java.awt.Font) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException)

Example 28 with UnsupportedLookAndFeelException

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

the class NUISkinEditorScreen method initialise.

@Override
public void initialise() {
    // Retrieve the widgets based on their identifiers.
    availableAssetDropdown = find(AVAILABLE_ASSETS_ID, UIDropdownScrollable.class);
    UIDropdownScrollable<ResourceUrn> availableScreenDropdown = find(AVAILABLE_SCREENS_ID, UIDropdownScrollable.class);
    JsonEditorTreeView editor = find(EDITOR_TREE_VIEW_ID, JsonEditorTreeView.class);
    selectedScreenBox = find(SELECTED_SCREEN_ID, UIBox.class);
    super.setEditorSystem(nuiSkinEditorSystem);
    super.setEditor(editor);
    // Populate the list of screens.
    List<String> availableAssetList = Lists.newArrayList();
    availableAssetList.add(CREATE_NEW_SKIN);
    availableAssetList.addAll(assetManager.getAvailableAssets(UISkinAsset.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 skin tree (or de-serialize from an existing asset)
                selectedAssetPending = value;
                if (CREATE_NEW_SKIN.equals(value)) {
                    selectedAssetPath = null;
                    resetState(NUIEditorNodeUtils.createNewSkin());
                } else {
                    selectAsset(new ResourceUrn(value));
                }
            }
        });
    }
    if (availableScreenDropdown != null) {
        List<ResourceUrn> availableScreenList = Lists.newArrayList(assetManager.getAvailableAssets(UIElement.class));
        Collections.sort(availableScreenList);
        availableScreenDropdown.setOptions(availableScreenList);
        availableScreenDropdown.bindEnabled(new ReadOnlyBinding<Boolean>() {

            @Override
            public Boolean get() {
                return selectedAsset != null;
            }
        });
        availableScreenDropdown.bindSelection(new Binding<ResourceUrn>() {

            @Override
            public ResourceUrn get() {
                return selectedScreen;
            }

            @Override
            public void set(ResourceUrn value) {
                selectedScreen = value;
                resetPreviewWidget();
            }
        });
    }
    if (editor != null) {
        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.createPrimarySkinContextMenu(node);
        });
        editor.setEditor(this::editNode, getManager());
        editor.subscribeTreeViewUpdate(() -> {
            getEditor().addToHistory();
            resetPreviewWidget();
            updateConfig();
            setUnsavedChangesPresent(true);
            updateAutosave();
        });
    }
    UIButton save = find("save", UIButton.class);
    save.bindEnabled(new ReadOnlyBinding<Boolean>() {

        @Override
        public Boolean get() {
            return CREATE_NEW_SKIN.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_SKIN.equals(selectedAsset) ? "untitled.skin" : selectedAsset.split(":")[1] + ".skin"));
        fileChooser.setFileFilter(new FileNameExtensionFilter("Skin asset file (*.skin)", "skin"));
        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 -> nuiSkinEditorSystem.toggleEditor());
    updateConfig();
}
Also used : UIElement(org.terasology.nui.asset.UIElement) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) UIBox(org.terasology.nui.widgets.UIBox) LookAndFeel(javax.swing.LookAndFeel) UIButton(org.terasology.nui.widgets.UIButton) JsonEditorTreeView(org.terasology.engine.rendering.nui.widgets.JsonEditorTreeView) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Component(java.awt.Component) NUIEditorMenuTreeBuilder(org.terasology.engine.rendering.nui.editor.utils.NUIEditorMenuTreeBuilder) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) JFileChooser(javax.swing.JFileChooser) AssetDataFile(org.terasology.gestalt.assets.format.AssetDataFile) File(java.io.File) JDialog(javax.swing.JDialog)

Example 29 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project jmeter by apache.

the class DynamicStyle method updateLaf.

/**
 * Set new look and feel for all the open windows.
 * @param className look and feel class name
 */
@API(since = "5.3", status = API.Status.EXPERIMENTAL)
public void updateLaf(String className) {
    try {
        // setLookAndFeel has two purposes here:
        // 1) Nimbus LaF caches styles (e.g. Label.font), so if we want apply new zoom scale,
        // then we need to invalidate the cache
        // 2) We need to generate "property changed lookAndFeel" UI event. Unfortunately,
        // firePropertyChanged skips the event when old and new LaFs are equal
        UIManager.setLookAndFeel(className);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException | UnsupportedLookAndFeelException e) {
        // $NON-NLS-1$
        throw new IllegalStateException("Unable to update look and feel to " + className, e);
    }
    List<Component> components = new ArrayList<>();
    for (final Window w : Window.getWindows()) {
        updateComponentTreeUI(w, components);
        components.clear();
    }
}
Also used : Window(java.awt.Window) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) Component(java.awt.Component) API(org.apiguardian.api.API)

Example 30 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project vft-capture by videofirst.

the class VfCaptureUi method setUiLookAndFeel.

/**
 * Set look and feel (needs to be done before application loads up).
 */
private void setUiLookAndFeel() {
    try {
        BasicLookAndFeel darcula = new DarculaLaf();
        UIManager.setLookAndFeel(darcula);
    } catch (UnsupportedLookAndFeelException ex) {
        throw new CaptureException("Look and feel not supported");
    }
}
Also used : DarculaLaf(com.bulenkov.darcula.DarculaLaf) CaptureException(io.videofirst.capture.exception.CaptureException) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) BasicLookAndFeel(javax.swing.plaf.basic.BasicLookAndFeel)

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