Search in sources :

Example 16 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project mudmap2 by Neop.

the class Mudmap2 method main.

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        mwin = new Mainwindow();
        mwin.setVisible(true);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
        Logger.getLogger(Mudmap2.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : Mainwindow(mudmap2.frontend.Mainwindow) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException)

Example 17 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.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 18 with UnsupportedLookAndFeelException

use of javax.swing.UnsupportedLookAndFeelException in project vcell by virtualcell.

the class VCellLookAndFeel method setVCellLookAndFeel.

public static void setVCellLookAndFeel() {
    OperatingSystemInfo osi = OperatingSystemInfo.getInstance();
    // changed to see if SystemLookAndFeel on Linux works better than the default CrossPlatformLookAndFeel (aka Metal)
    try {
        System.out.println("Operating system:  " + osi.getOsType());
        System.out.println("About to set the look and feel.  Before setting, we're using: " + UIManager.getLookAndFeel().getName());
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }
    // }
    final boolean isMac = osi.isMac();
    if (defaultFont == null) {
        defaultFont = UIManager.getFont("Label.font");
        if (isMac) {
            defaultFont = defaultFont.deriveFont(defaultFont.getSize2D() - 2);
        }
    }
    if (isMac) {
        UIManager.put("Button.font", defaultFont);
        UIManager.put("CheckBox.font", defaultFont);
        UIManager.put("CheckBoxMenuItem.font", defaultFont);
        UIManager.put("ColorChooser.font", defaultFont);
        UIManager.put("ComboBox.font", defaultFont);
        UIManager.put("DesktopIcon.font", defaultFont);
        UIManager.put("EditorPane.font", defaultFont);
        UIManager.put("FileChooser.font", defaultFont);
        UIManager.put("FormattedTextField.font", defaultFont);
        UIManager.put("Label.font", defaultFont);
        UIManager.put("List.font", defaultFont);
        UIManager.put("Menu.font", defaultFont);
        UIManager.put("MenuBar.font", defaultFont);
        UIManager.put("MenuItem.font", defaultFont);
        UIManager.put("OptionPane.font", defaultFont);
        UIManager.put("Panel.font", defaultFont);
        UIManager.put("PasswordField.font", defaultFont);
        UIManager.put("PopupMenu.font", defaultFont);
        UIManager.put("ProgressBar.font", defaultFont);
        UIManager.put("RadioButton.font", defaultFont);
        UIManager.put("RadioButtonMenuItem.font", defaultFont);
        UIManager.put("TabbedPane.font", defaultFont);
        UIManager.put("Table.font", defaultFont);
        UIManager.put("TableHeader.font", defaultFont);
        UIManager.put("TextArea.font", defaultFont);
        UIManager.put("TextField.font", defaultFont);
        UIManager.put("TextPane.font", defaultFont);
        UIManager.put("TitledBorder.font", defaultFont);
        UIManager.put("ToggleButton.font", defaultFont);
        UIManager.put("ToolBar.font", defaultFont);
        UIManager.put("ToolTip.font", defaultFont);
        UIManager.put("Tree.font", defaultFont);
        UIManager.put("Slider.font", defaultFont);
        UIManager.put("ScrollPane.font", defaultFont);
        UIManager.put("Viewport.font", defaultFont);
        UIManager.put("CheckBoxMenuItem.acceleratorFont", defaultFont);
        UIManager.put("InternalFrame.optionDialogTitleFont", defaultFont);
        UIManager.put("InternalFrame.paletteTitleFont", defaultFont);
        UIManager.put("InternalFrame.titleFont", defaultFont);
        UIManager.put("Menu.acceleratorFont", defaultFont);
        UIManager.put("MenuItem.acceleratorFont", defaultFont);
        UIManager.put("OptionPane.buttonFont", defaultFont);
        UIManager.put("OptionPane.messageFont", defaultFont);
        UIManager.put("RadioButtonMenuItem.acceleratorFont", defaultFont);
        UIManager.put("TabbedPane.useSmallLayout", Boolean.TRUE);
        // System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.getProperties().put("swing.component.sizevariant", "small");
    }
    System.out.println("After setting, we're using: " + UIManager.getLookAndFeel().getName());
}
Also used : UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) OperatingSystemInfo(cbit.vcell.resource.OperatingSystemInfo)

Example 19 with UnsupportedLookAndFeelException

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

the class bug8136998 method iterateLookAndFeels.

protected static void iterateLookAndFeels(final bug8136998 test) throws Exception {
    LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();
    for (LookAndFeelInfo info : lafInfo) {
        try {
            UIManager.setLookAndFeel(info.getClassName());
            System.out.println("Look and Feel: " + info.getClassName());
            test.runTest();
        } catch (UnsupportedLookAndFeelException e) {
            System.out.println("Skipping unsupported LaF: " + info);
        }
    }
}
Also used : LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException)

Example 20 with UnsupportedLookAndFeelException

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

the class bug8046391 method main.

public static void main(String[] args) throws Exception {
    OSType type = OSInfo.getOSType();
    if (type != OSType.WINDOWS) {
        System.out.println("This test is for Windows only... skipping!");
        return;
    }
    SwingUtilities.invokeAndWait(() -> {
        try {
            UIManager.setLookAndFeel(new WindowsLookAndFeel());
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        System.out.println("Creating JFileChooser...");
        JFileChooser fileChooser = new JFileChooser();
        System.out.println("Test passed: chooser = " + fileChooser);
    });
// Test fails if creating JFileChooser hangs
}
Also used : UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) JFileChooser(javax.swing.JFileChooser) OSType(sun.awt.OSInfo.OSType) WindowsLookAndFeel(com.sun.java.swing.plaf.windows.WindowsLookAndFeel)

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