/** Sets current LAF. The method doesn't update component hierarchy. */ @Override public void setCurrentLookAndFeel(UIManager.LookAndFeelInfo lookAndFeelInfo) { if (findLaf(lookAndFeelInfo.getClassName()) == null) { LOG.error("unknown LookAndFeel : " + lookAndFeelInfo); return; } // Set L&F if (IdeaLookAndFeelInfo.CLASS_NAME.equals( lookAndFeelInfo.getClassName())) { // that is IDEA default LAF IdeaLaf laf = new IdeaLaf(); MetalLookAndFeel.setCurrentTheme(new IdeaBlueMetalTheme()); try { UIManager.setLookAndFeel(laf); } catch (Exception e) { Messages.showMessageDialog( IdeBundle.message( "error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } } else if (DarculaLookAndFeelInfo.CLASS_NAME.equals(lookAndFeelInfo.getClassName())) { DarculaLaf laf = new DarculaLaf(); try { UIManager.setLookAndFeel(laf); JBColor.setDark(true); IconLoader.setUseDarkIcons(true); } catch (Exception e) { Messages.showMessageDialog( IdeBundle.message( "error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } } else { // non default LAF try { LookAndFeel laf = ((LookAndFeel) Class.forName(lookAndFeelInfo.getClassName()).newInstance()); if (laf instanceof MetalLookAndFeel) { MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); } UIManager.setLookAndFeel(laf); } catch (Exception e) { Messages.showMessageDialog( IdeBundle.message( "error.cannot.set.look.and.feel", lookAndFeelInfo.getName(), e.getMessage()), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); return; } } myCurrentLaf = ObjectUtils.chooseNotNull(findLaf(lookAndFeelInfo.getClassName()), lookAndFeelInfo); checkLookAndFeel(lookAndFeelInfo, false); }
/** * Main method. Begins the GUI, and the rest of the program. * * @param args the command line arguments */ public static void main(String args[]) { // playSound(); try { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex); } // </editor-fold> /* Create and display the form */ EventQueue.invokeLater( new Runnable() { @Override public void run() { new mainForm().setVisible(true); } }); }
@Override public void initComponent() { if (myCurrentLaf != null) { final UIManager.LookAndFeelInfo laf = findLaf(myCurrentLaf.getClassName()); if (laf != null) { setCurrentLookAndFeel(laf); // setup default LAF or one specified by readExternal. } } updateUI(); if (SystemInfo.isXWindow) { myThemeChangeListener = new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { //noinspection SSBasedInspection SwingUtilities.invokeLater( new Runnable() { @Override public void run() { fixGtkPopupStyle(); patchOptionPaneIcons(UIManager.getLookAndFeelDefaults()); } }); } }; Toolkit.getDefaultToolkit() .addPropertyChangeListener(GNOME_THEME_PROPERTY_NAME, myThemeChangeListener); } }
public static JMenu createLookAndFeelMenu() { JMenu menu = new JMenu("LookAndFeel"); ButtonGroup lookAndFeelRadioGroup = new ButtonGroup(); for (UIManager.LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) { menu.add( createLookAndFeelItem(lafInfo.getName(), lafInfo.getClassName(), lookAndFeelRadioGroup)); } return menu; }
/** Finds LAF by its class name. will be returned. */ @Nullable private UIManager.LookAndFeelInfo findLaf(@Nullable String className) { if (className == null) { return null; } for (UIManager.LookAndFeelInfo laf : myLaFs) { if (Comparing.equal(laf.getClassName(), className)) { return laf; } } return null; }
@Override public Element getState() { Element element = new Element("state"); if (myCurrentLaf != null) { String className = myCurrentLaf.getClassName(); if (className != null) { Element child = new Element(ELEMENT_LAF); child.setAttribute(ATTRIBUTE_CLASS_NAME, className); element.addContent(child); } } return element; }
@Override public void loadState(final Element element) { String className = null; Element lafElement = element.getChild(ELEMENT_LAF); if (lafElement != null) { className = lafElement.getAttributeValue(ATTRIBUTE_CLASS_NAME); if (className != null && ourLafClassesAliases.containsKey(className)) { className = ourLafClassesAliases.get(className); } } UIManager.LookAndFeelInfo laf = findLaf(className); // If LAF is undefined (wrong class name or something else) we have set default LAF anyway. if (laf == null) { laf = getDefaultLaf(); } if (myCurrentLaf != null && !laf.getClassName().equals(myCurrentLaf.getClassName())) { setCurrentLookAndFeel(laf); updateUI(); } myCurrentLaf = laf; }
@Override public void loadState(final Element element) { String className = null; for (final Object o : element.getChildren()) { Element child = (Element) o; if (ELEMENT_LAF.equals(child.getName())) { className = child.getAttributeValue(ATTRIBUTE_CLASS_NAME); break; } } UIManager.LookAndFeelInfo laf = findLaf(className); // If LAF is undefined (wrong class name or something else) we have set default LAF anyway. if (laf == null) { laf = getDefaultLaf(); } if (myCurrentLaf != null && !laf.getClassName().equals(myCurrentLaf.getClassName())) { setCurrentLookAndFeel(laf); updateUI(); } myCurrentLaf = laf; }
@Override public void initComponent() { if (myCurrentLaf != null) { final UIManager.LookAndFeelInfo laf = findLaf(myCurrentLaf.getClassName()); if (laf != null) { boolean needUninstall = UIUtil.isUnderDarcula(); setCurrentLookAndFeel(laf); // setup default LAF or one specified by readExternal. if (WelcomeWizardUtil.getWizardLAF() != null) { if (UIUtil.isUnderDarcula()) { DarculaInstaller.install(); } else if (needUninstall) { DarculaInstaller.uninstall(); } } } } updateUI(); if (SystemInfo.isXWindow) { myThemeChangeListener = new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { //noinspection SSBasedInspection SwingUtilities.invokeLater( new Runnable() { @Override public void run() { fixGtkPopupStyle(); patchGtkDefaults(UIManager.getLookAndFeelDefaults()); } }); } }; Toolkit.getDefaultToolkit() .addPropertyChangeListener(GNOME_THEME_PROPERTY_NAME, myThemeChangeListener); } }