Example usage for javax.swing LookAndFeel getClass

List of usage examples for javax.swing LookAndFeel getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:es.darkhogg.hazelnutt.Hazelnutt.java

/**
 * Runs the application//from  w  w  w  . j a  v a 2  s.c  o  m
 * 
 * @param args
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    // Print some version information
    LOGGER.log(Level.OFF, "----------------");
    LOGGER.info("Hazelnutt " + VERSION);

    LOGGER.trace("Selecting Look&Feel...");

    // Select the L&F from configuration or the default if not present
    String slaf = CONFIG.getString("Hazelnutt.gui.lookAndFeel");
    if (slaf == null) {
        LOGGER.info("Configuration entry for L&F missing, creating default");
        slaf = UIManager.getSystemLookAndFeelClassName();
    }

    // Set it or print an error
    try {
        UIManager.setLookAndFeel(slaf);
    } catch (Exception e) {
        LOGGER.warn("Error while selecting the L&F \"" + slaf + "\", leaving default");
    }

    // Update the configuration with the currently selected L&F
    LookAndFeel laf = UIManager.getLookAndFeel();
    LOGGER.debug("L&F selected: " + laf.getName() + " (" + laf.getClass().getName() + ")");
    CONFIG.setProperty("Hazelnutt.gui.lookAndFeel", laf.getClass().getName());

    // Load the frame
    LOGGER.trace("Launching main frame...");
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            SwingUtilities.updateComponentTreeUI(FRAME);
            FRAME.setVisible(true);
        }
    });
}

From source file:Main.java

/**
 * Swing menus are looking pretty bad on Linux when the GTK LaF is used (See
 * bug #6925412). It will most likely never be fixed anytime soon so this
 * method provides a workaround for it. It uses reflection to change the GTK
 * style objects of Swing so popup menu borders have a minimum thickness of
 * 1 and menu separators have a minimum vertical thickness of 1.
 *//*from  w ww.  j  ava  2 s  .c om*/
public static void installGtkPopupBugWorkaround() {
    // Get current look-and-feel implementation class
    LookAndFeel laf = UIManager.getLookAndFeel();
    Class<?> lafClass = laf.getClass();

    // Do nothing when not using the problematic LaF
    if (!lafClass.getName().equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"))
        return;

    // We do reflection from here on. Failure is silently ignored. The
    // workaround is simply not installed when something goes wrong here
    try {
        // Access the GTK style factory
        Field field = lafClass.getDeclaredField("styleFactory");
        boolean accessible = field.isAccessible();
        field.setAccessible(true);
        Object styleFactory = field.get(laf);
        field.setAccessible(accessible);

        // Fix the horizontal and vertical thickness of popup menu style
        Object style = getGtkStyle(styleFactory, new JPopupMenu(), "POPUP_MENU");
        fixGtkThickness(style, "yThickness");
        fixGtkThickness(style, "xThickness");

        // Fix the vertical thickness of the popup menu separator style
        style = getGtkStyle(styleFactory, new JSeparator(), "POPUP_MENU_SEPARATOR");
        fixGtkThickness(style, "yThickness");
    } catch (Exception e) {
        // Silently ignored. Workaround can't be applied.
    }
}

From source file:Main.java

/**
 * With certain look and feels, namely windows with XP style, the focus of a toolbar button is already indicated (border changes) and the focus indicator should not be drawn: this fixes the visual rendering.
 * @param toolBarButton the tool bar button for which to adjust the focus state.
 *///  ww  w.j  ava  2s. co  m
public static void adjustToolbarButtonFocus(AbstractButton toolBarButton) {
    LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
    if (lookAndFeel.isNativeLookAndFeel() && System.getProperty("os.name").startsWith("Windows")
            && !Boolean.parseBoolean(System.getProperty("swing.noxp"))
            && !lookAndFeel.getClass().getName().endsWith("WindowsClassicLookAndFeel")) {
        toolBarButton.setFocusPainted(false);
    }
}

From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java

private JMenu createViewMenu() {
    JMenu viewMenu = new JMenu("View");
    viewMenu.setMnemonic('v');

    JMenu lnfMenu = new JMenu("Look and Feel");
    lnfMenu.setMnemonic('f');

    ButtonGroup lnfGroup = new ButtonGroup();
    LookAndFeelInfo lnfs[] = UIManager.getInstalledLookAndFeels();
    String lnfCurrentName = null;
    LookAndFeel lnfCurrent = UIManager.getLookAndFeel();
    if (lnfCurrent != null) {
        lnfCurrentName = lnfCurrent.getClass().getName();
    }//from   w ww  .ja  va  2  s  . c  o m
    UISwitcher switcher = new UISwitcher();
    for (int i = 0; i < lnfs.length; i++) {
        JRadioButtonMenuItem lnfItem = new JRadioButtonMenuItem(lnfs[i].getName());
        lnfItem.addActionListener(switcher);
        lnfItem.setActionCommand(lnfs[i].getClassName());
        lnfGroup.add(lnfItem);
        lnfMenu.add(lnfItem);

        if (lnfs[i].getClassName().equals(lnfCurrentName)) {
            lnfGroup.setSelected(lnfItem.getModel(), true);
        }
    }
    viewMenu.add(lnfMenu);

    return viewMenu;
}

From source file:com.sshtools.common.ui.SshToolsApplication.java

/**
 *
 *
 * @param className//from  w  ww  .  ja va2  s . co  m
        
        
 *
 * @throws Exception
 */
public static void setLookAndFeel(String className) throws Exception {
    LookAndFeel laf = null;

    if (!className.equals(DEFAULT_LAF)) {
        if (className.equals(SYSTEM_LAF)) {
            String systemLaf = UIManager.getSystemLookAndFeelClassName();
            log.debug("System Look And Feel is " + systemLaf);
            laf = (LookAndFeel) Class.forName(systemLaf).newInstance();
        } else if (className.equals(CROSS_PLATFORM_LAF)) {
            String crossPlatformLaf = UIManager.getCrossPlatformLookAndFeelClassName();
            log.debug("Cross Platform Look And Feel is " + crossPlatformLaf);
            laf = (LookAndFeel) Class.forName(crossPlatformLaf).newInstance();
        } else {
            laf = (LookAndFeel) Class.forName(className).newInstance();
        }
    }

    //  Now actually set the look and feel
    if (laf != null) {
        log.info("Setting look and feel " + laf.getName() + " (" + laf.getClass().getName() + ")");
        UIManager.setLookAndFeel(laf);
        UIManager.put("EditorPane.font", UIManager.getFont("TextArea.font"));
    }
}

From source file:de.xplib.xdbm.ui.Application.java

/**
 * Sets global user interface options.//from  ww  w .j a  v  a2s. co m
 */
private void configureUI() {

    Options.setDefaultIconSize(new Dimension(18, 18));

    // Set font options      
    UIManager.put(Options.USE_SYSTEM_FONTS_APP_KEY, settings.isUseSystemFonts());
    Options.setGlobalFontSizeHints(settings.getFontSizeHints());
    Options.setUseNarrowButtons(settings.isUseNarrowButtons());
    Options.setPopupDropShadowEnabled(settings.isPopupDropShadowEnabled().booleanValue());

    // Global options
    Options.setTabIconsEnabled(settings.isTabIconsEnabled());
    UIManager.put(Options.POPUP_DROP_SHADOW_ENABLED_KEY, settings.isPopupDropShadowEnabled());

    // Swing Settings
    LookAndFeel selectedLaf = settings.getSelectedLookAndFeel();
    if (selectedLaf instanceof PlasticLookAndFeel) {
        PlasticLookAndFeel.setMyCurrentTheme(settings.getSelectedTheme());
        PlasticLookAndFeel.setTabStyle(settings.getPlasticTabStyle());
        PlasticLookAndFeel.setHighContrastFocusColorsEnabled(settings.isPlasticHighContrastFocusEnabled());
    } else if (selectedLaf.getClass() == MetalLookAndFeel.class) {
        MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
    }

    // Work around caching in MetalRadioButtonUI
    JRadioButton radio = new JRadioButton();
    radio.getUI().uninstallUI(radio);
    JCheckBox checkBox = new JCheckBox();
    checkBox.getUI().uninstallUI(checkBox);

    try {
        UIManager.setLookAndFeel(selectedLaf);
    } catch (Exception e) {
        System.out.println("Can't change L&F: " + e);
    }
}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

public MainFrame(@Nonnull @MustNotContainNull final String... args) {
    super();//from www  .j av a 2  s . c  o m
    initComponents();

    this.stackPanel = new JPanel();
    this.stackPanel.setFocusable(false);
    this.stackPanel.setOpaque(false);
    this.stackPanel.setBorder(BorderFactory.createEmptyBorder(32, 32, 16, 32));
    this.stackPanel.setLayout(new BoxLayout(this.stackPanel, BoxLayout.Y_AXIS));

    final JPanel glassPanel = (JPanel) this.getGlassPane();
    glassPanel.setOpaque(false);

    this.setGlassPane(glassPanel);

    glassPanel.setLayout(new BorderLayout(8, 8));
    glassPanel.add(Box.createGlue(), BorderLayout.CENTER);

    final JPanel ppanel = new JPanel(new BorderLayout(0, 0));
    ppanel.setFocusable(false);
    ppanel.setOpaque(false);
    ppanel.setCursor(null);
    ppanel.add(this.stackPanel, BorderLayout.SOUTH);

    glassPanel.add(ppanel, BorderLayout.EAST);

    this.stackPanel.add(Box.createGlue());

    glassPanel.setVisible(false);

    this.setTitle("Scia Reto");

    setIconImage(UiUtils.loadImage("logo256x256.png"));

    this.stateless = args.length > 0;

    final MainFrame theInstance = this;

    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(@Nonnull final WindowEvent e) {
            if (doClosing()) {
                dispose();
            }
        }
    });

    this.tabPane = new EditorTabPane(this);

    this.explorerTree = new ExplorerTree(this);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(250);
    splitPane.setResizeWeight(0.0d);
    splitPane.setLeftComponent(this.explorerTree);
    splitPane.setRightComponent(this.tabPane);

    add(splitPane, BorderLayout.CENTER);

    this.menuOpenRecentProject.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedProjects = FileHistoryManager.getInstance().getLastOpenedProjects();
            if (lastOpenedProjects.length > 0) {
                for (final File folder : lastOpenedProjects) {
                    final JMenuItem item = new JMenuItem(folder.getName());
                    item.setToolTipText(folder.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openProject(folder, false);
                        }
                    });
                    menuOpenRecentProject.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentProject.removeAll();
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });

    this.menuOpenRecentFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedFiles = FileHistoryManager.getInstance().getLastOpenedFiles();
            if (lastOpenedFiles.length > 0) {
                for (final File file : lastOpenedFiles) {
                    final JMenuItem item = new JMenuItem(file.getName());
                    item.setToolTipText(file.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openFileAsTab(file);
                        }
                    });
                    menuOpenRecentFile.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentFile.removeAll();
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });

    if (!this.stateless) {
        restoreState();
    } else {
        boolean openedProject = false;
        for (final String filePath : args) {
            final File file = new File(filePath);
            if (file.isDirectory()) {
                openedProject = true;
                openProject(file, true);
            } else if (file.isFile()) {
                openFileAsTab(file);
            }
        }
        if (!openedProject) {
            //TODO try to hide project panel!
        }
    }

    final LookAndFeel current = UIManager.getLookAndFeel();
    final ButtonGroup lfGroup = new ButtonGroup();
    final String currentLFClassName = current.getClass().getName();
    for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(info.getName());
        lfGroup.add(menuItem);
        if (currentLFClassName.equals(info.getClassName())) {
            menuItem.setSelected(true);
        }
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@Nonnull final ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(info.getClassName());
                    SwingUtilities.updateComponentTreeUI(theInstance);
                    PreferencesManager.getInstance().getPreferences().put(Main.PROPERTY_LOOKANDFEEL,
                            info.getClassName());
                    PreferencesManager.getInstance().flush();
                } catch (Exception ex) {
                    LOGGER.error("Can't change LF", ex);
                }
            }
        });
        this.menuLookAndFeel.add(menuItem);
    }
}

From source file:org.eclipse.wb.internal.swing.laf.LafSupport.java

/**
 * Applies the selected LAF in Swing via UIManager.
 * /*from   w  w  w. ja v  a2 s  . c o  m*/
 * @param lafInfo
 *          the {@link LafInfo} to be applied.
 */
public static void applySelectedLAF(final LafInfo lafInfo) {
    try {
        SwingUtils.runLaterAndWait(new RunnableEx() {
            public void run() throws Exception {
                LookAndFeel lookAndFeelInstance = lafInfo.getLookAndFeelInstance();
                UIManager.put("ClassLoader", lookAndFeelInstance.getClass().getClassLoader());
                UIManager.setLookAndFeel(lookAndFeelInstance);
            }
        });
    } catch (Throwable e) {
        DesignerPlugin.log(e);
    }
}

From source file:org.eclipse.wb.internal.swing.laf.LafSupport.java

/**
 * Looks up for <code>main()</code> method and searches the installed LAF by searching
 * <code>setLookAndFeel</code> method invocation. If found, stores LAF id in passed
 * <code>javaInfo</code> 's underlying resource under <code>SWING_LAF_SELECTED</code> persistent
 * key.//from   w  ww . j  a  v  a 2 s.c  o m
 * 
 * @return {@link LafInfo} which represents installed LAF or <code>null</code> if no
 *         <code>main</code> method found of no <code>setLookAndFeel</code> method invocation
 *         found.
 */
private static LafInfo getLAFFromMain(final JavaInfo javaInfo) {
    AstEditor editor = javaInfo.getEditor();
    MethodDeclaration mainMethod = getMainMethod(editor);
    if (mainMethod == null) {
        // no main method 
        return null;
    }
    // look up for setLookAndFeel method
    MethodInvocation setLookAndFeelMethod = getSetLookAndFeelMethod(mainMethod);
    if (setLookAndFeelMethod == null) {
        return null;
    }
    String methodSignature = AstNodeUtils.getMethodSignature(setLookAndFeelMethod);
    try {
        String className;
        // evaluate what we've got
        EvaluationContext context = new EvaluationContext(EditorState.get(editor).getEditorLoader(),
                new ExecutionFlowDescription(mainMethod));
        final Object evaluateObject = AstEvaluationEngine.evaluate(context,
                DomGenerics.arguments(setLookAndFeelMethod).get(0));
        // it can be String or LookAndFeel only
        if (SET_LOOK_AND_FEEL_LAF.equals(methodSignature)) {
            LookAndFeel laf = (LookAndFeel) evaluateObject;
            className = laf.getClass().getName();
        } else {
            className = (String) evaluateObject;
        }
        // find in known LAFs list by class name
        for (CategoryInfo categoryInfo : m_lafList) {
            LafInfo lafInfo = categoryInfo.lookupByClassName(className);
            if (lafInfo != null) {
                return lafInfo;
            }
        }
    } catch (Throwable e) {
        EditorState.get(editor)
                .addWarning(new EditorWarning(ModelMessages.LafSupport_errCanParse_setLookAndFeel, e));
    }
    return null;
}

From source file:org.eclipse.wb.internal.swing.preferences.laf.LafPreferencePage.java

/**
 * Updates the Swing preview part basing on selected LAF.
 *///w  w w . j a  v a2s . c  o  m
private void updatePreview0() {
    if (m_updatingPreview) {
        return;
    }
    m_updatingPreview = true;
    try {
        ExecutionUtils.runLog(new RunnableEx() {
            public void run() throws Exception {
                try {
                    m_previewGroup.getParent().setRedraw(false);
                    for (Control control : m_previewGroup.getChildren()) {
                        control.dispose();
                    }
                    LafInfo selectedLAF = getSelectedLAF();
                    if (selectedLAF == null) {
                        // nothing selected
                        return;
                    }
                    LookAndFeel lookAndFeel = selectedLAF.getLookAndFeelInstance();
                    m_previewGroup.getParent().layout(true);
                    UIManager.put("ClassLoader", lookAndFeel.getClass().getClassLoader());
                    UIManager.setLookAndFeel(lookAndFeel);
                    createPreviewArea(m_previewGroup);
                    m_previewGroup.getParent().layout(true);
                } finally {
                    m_previewGroup.getParent().setRedraw(true);
                }
            }
        });
    } finally {
        m_updatingPreview = false;
    }
}