@SuppressWarnings("LeakingThisInConstructor") public MetalThemeMenu(String name, MetalTheme[] themeArray) { super(name); themes = themeArray; ButtonGroup group = new ButtonGroup(); for (int i = 0; i < themes.length; i++) { JRadioButtonMenuItem item = new JRadioButtonMenuItem(themes[i]. getName()); group.add(item); add(item); item.setActionCommand(i + ""); item.addActionListener(this); if (i == 0) { item.setSelected(true); } } }
public static List getInstalledThemes() /* 518: */ { /* 519: 795 */ if (null == installedThemes) { /* 520: 796 */ installDefaultThemes(); /* 521: */ } /* 522: 798 */ Collections.sort(installedThemes, new Comparator() /* 523: */ { /* 524: */ public int compare(Object o1, Object o2) /* 525: */ { /* 526: 800 */ MetalTheme theme1 = (MetalTheme)o1; /* 527: 801 */ MetalTheme theme2 = (MetalTheme)o2; /* 528: 802 */ return theme1.getName().compareTo(theme2.getName()); /* 529: */ } /* 530: 805 */ }); /* 531: 806 */ return installedThemes; /* 532: */ }
public static PlasticTheme getPlasticTheme() /* 565: */ { /* 566: 887 */ if (LookUtils.IS_JAVA_5_OR_LATER) /* 567: */ { /* 568: 888 */ MetalTheme theme = getCurrentTheme0(); /* 569: 889 */ if ((theme instanceof PlasticTheme)) { /* 570: 890 */ return (PlasticTheme)theme; /* 571: */ } /* 572: */ } /* 573: 892 */ PlasticTheme uimanagerTheme = (PlasticTheme)UIManager.get(THEME_KEY); /* 574: 893 */ if (uimanagerTheme != null) { /* 575: 894 */ return uimanagerTheme; /* 576: */ } /* 577: 896 */ PlasticTheme initialTheme = createMyDefaultTheme(); /* 578: 897 */ setPlasticTheme(initialTheme); /* 579: 898 */ return initialTheme; /* 580: */ }
/** * Handle theme selection changed * @param e */ private void themeSelectionChanged(final ListSelectionEvent e) { if (m_setting) return; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { ValueNamePair laf = lookList.getSelectedValue(); ValueNamePair theme = themeList.getSelectedValue(); LookAndFeel currentLaf = UIManager.getLookAndFeel(); MetalTheme currentTheme = MetalLookAndFeel.getCurrentTheme(); AdempierePLAF.setPLAF(laf, theme, false); previewPanel.refresh(currentLaf, currentTheme); SwingUtilities.updateComponentTreeUI(previewPanel); updatePreviewComponents(); setLFSelection(); } finally { setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); this.repaint(); } }
/** * Handle look and feel selection changed * @param e */ private void lookAndFeelSelectionChanged(final ListSelectionEvent e) { if (m_setting) return; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { ValueNamePair laf = lookList.getSelectedValue(); LookAndFeel currentLaf = UIManager.getLookAndFeel(); MetalTheme currentTheme = MetalLookAndFeel.getCurrentTheme(); AdempierePLAF.setPLAF(laf, null, false); previewPanel.refresh(currentLaf, currentTheme); SwingUtilities.updateComponentTreeUI(previewPanel); updatePreviewComponents(); setLFSelection(); } finally { setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); this.repaint(); } }
@SuppressWarnings("unchecked") @Override public void actionPerformed(ActionEvent actionEvent) { try { String lookAndFeelClassName = actionEvent.getActionCommand(); Class<LookAndFeel> lookAndFeelClass = (Class<LookAndFeel>) Class.forName(lookAndFeelClassName); LookAndFeel lookAndFeel = lookAndFeelClass.newInstance(); if (lookAndFeel instanceof MetalThemeProvider) { MetalTheme theme = ((MetalThemeProvider) lookAndFeel).getMetalTheme(); MetalLookAndFeel.setCurrentTheme(theme); } UIManager.setLookAndFeel(lookAndFeel); for (Window window : JFrame.getWindows()) { SwingUtilities.updateComponentTreeUI(window); window.validate(); window.repaint(); } } catch (Exception exception) { exception.printStackTrace(); JOptionPane.showMessageDialog(null, "Can't change look and feel", "Invalid PLAF", JOptionPane.ERROR_MESSAGE); } }
/** * Lazily initializes and returns the {@code List} of installed * color themes. * * @return a list of installed color/font themes */ public static List getInstalledThemes() { if (null == installedThemes) { installDefaultThemes(); } Collections.sort(installedThemes, new Comparator() { public int compare(Object o1, Object o2) { MetalTheme theme1 = (MetalTheme) o1; MetalTheme theme2 = (MetalTheme) o2; return theme1.getName().compareTo(theme2.getName()); } }); return installedThemes; }
public MetalLayoutStyle() { isOcean = false; try { Method method = MetalLookAndFeel.class. getMethod("getCurrentTheme", (Class[])null); isOcean = ((MetalTheme)method.invoke(null, (Object[])null)). getName() == "Ocean"; } catch (NoSuchMethodException nsme) { } catch (IllegalAccessException iae) { } catch (IllegalArgumentException iae2) { } catch (InvocationTargetException ite) { } }
public void actionPerformed(ActionEvent e) { String numStr = e.getActionCommand(); MetalTheme selectedTheme = themes[Integer.parseInt(numStr)]; MetalLookAndFeel.setCurrentTheme(selectedTheme); try { UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (Exception ex) { System.out.println("Failed loading Metal"); System.out.println(ex); } }
/** * Creates a JRadioButtonMenuItem for the Themes menu. * * @param menu the menu * @param label the label * @param mnemonic the mnemonic * @param accessibleDescription the accessible description * @param theme the theme * @return the j menu item */ public JMenuItem createThemesMenuItem(JMenu menu, String label, String mnemonic, String accessibleDescription, MetalTheme theme) { JRadioButtonMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(getString(label))); themesMenuGroup.add(mi); mi.setMnemonic(getMnemonic(mnemonic)); mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription)); // mi.addActionListener(new ChangeThemeAction(this, theme)); return mi; }
/** * Refresh look and feel preview, reset to original setting after * refresh. * @param currentLaf Current Look and feel * @param currentTheme Current Theme */ void refresh(LookAndFeel currentLaf, MetalTheme currentTheme) { this.laf = currentLaf; this.theme = currentTheme; capture = true; }
/** * Invoke the correct method to set current metal based theme. * Supported look and feel are Metal, Plastic and Compiere. * @param laf Metal based look and feel * @param theme Metal based theme */ static void setCurrentMetalTheme(final MetalLookAndFeel laf, final MetalTheme theme) { if (laf instanceof AdempiereLookAndFeel && theme instanceof PlasticTheme) { AdempiereLookAndFeel.setCurrentTheme((PlasticTheme)theme); } else { MetalLookAndFeel.setCurrentTheme(theme); } }
public MetalLayoutStyle() { isOcean = false; try { Method method = MetalLookAndFeel.class.getMethod("getCurrentTheme", (Class[]) null); isOcean = ((MetalTheme) method.invoke(null, (Object[]) null)).getName() == "Ocean"; } catch (NoSuchMethodException nsme) { } catch (IllegalAccessException iae) { } catch (IllegalArgumentException iae2) { } catch (InvocationTargetException ite) { } }
/** * Creates a JRadioButtonMenuItem for the Themes menu */ private static JMenuItem createThemesMenuItem(JMenu menu, String label, char mnemonic, MetalTheme theme) { JRadioButtonMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(label)); themesMenuGroup.add(mi); mi.addActionListener(new ChangeThemeAction(theme)); mi.setMnemonic(mnemonic); return mi; }
/** * Lazily initializes and returns the PlasticTheme. * * @return the current PlasticTheme */ public static PlasticTheme getPlasticTheme() { MetalTheme theme = getCurrentTheme(); if (theme instanceof PlasticTheme) { return (PlasticTheme) theme; } PlasticTheme initialTheme = createMyDefaultTheme(); setPlasticTheme(initialTheme); return initialTheme; }
protected void buildMenus() { menuBar = new JMenuBar(); menuBar.setOpaque(true); JMenu file = buildFileMenu(); JMenu edit = buildEditMenu(); JMenu views = buildViewsMenu(); JMenu speed = buildSpeedMenu(); JMenu help = buildHelpMenu(); // load a theme from a text file MetalTheme myTheme = null; try { InputStream istream = getClass().getResourceAsStream( "/resources/MyTheme.theme"); myTheme = new PropertiesMetalTheme(istream); } catch (NullPointerException e) { System.out.println(e); } // build an array of themes MetalTheme[] themes = { new OceanTheme(), new DefaultMetalTheme(), new GreenMetalTheme(), new AquaMetalTheme(), new KhakiMetalTheme(), new DemoMetalTheme(), new ContrastMetalTheme(), new BigContrastMetalTheme(), myTheme }; // put the themes in a menu JMenu themeMenu = new MetalThemeMenu("Theme", themes); menuBar.add(file); menuBar.add(edit); menuBar.add(views); menuBar.add(themeMenu); menuBar.add(speed); menuBar.add(help); setJMenuBar(menuBar); }