List of usage examples for javax.swing UIManager getLookAndFeel
public static LookAndFeel getLookAndFeel()
null
. From source file:org.eclipse.wb.internal.swing.preferences.laf.LafPreferencePage.java
/** * Creates {@link EmbeddedSwingComposite} with some Swing components to show it using different * LAFs./*from www. j a v a 2 s . c o m*/ */ private void createPreviewArea(Group previewGroup) { try { LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel(); EmbeddedSwingComposite awtComposite = new EmbeddedSwingComposite(previewGroup, SWT.NONE) { @Override protected JComponent createSwingComponent() { // create the JRootPane JRootPane rootPane = new JRootPane(); { JMenuBar menuBar = new JMenuBar(); rootPane.setJMenuBar(menuBar); { JMenu mnFile = new JMenu(Messages.LafPreferencePage_previewFile); menuBar.add(mnFile); { JMenuItem mntmNew = new JMenuItem(Messages.LafPreferencePage_previewNew); mnFile.add(mntmNew); } { JMenuItem mntmExit = new JMenuItem(Messages.LafPreferencePage_previewExit); mnFile.add(mntmExit); } } { JMenu mnView = new JMenu(Messages.LafPreferencePage_previewView); menuBar.add(mnView); { JMenuItem mntmCommon = new JMenuItem(Messages.LafPreferencePage_previewCommon); mnView.add(mntmCommon); } } } GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0, 0, 0 }; gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 1.0E-4 }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0E-4 }; rootPane.getContentPane().setLayout(gridBagLayout); { JLabel lblLabel = new JLabel(Messages.LafPreferencePage_previewLabel); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 5); gbc.gridx = 0; gbc.gridy = 0; rootPane.getContentPane().add(lblLabel, gbc); } { JButton btnPushButton = new JButton(Messages.LafPreferencePage_previewButton); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 0); gbc.gridx = 1; gbc.gridy = 0; rootPane.getContentPane().add(btnPushButton, gbc); } { JComboBox comboBox = new JComboBox(); comboBox.setModel(new DefaultComboBoxModel(new String[] { Messages.LafPreferencePage_previewCombo, "ComboBox Item 1", "ComboBox Item 2" })); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 5); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = 1; rootPane.getContentPane().add(comboBox, gbc); } { JRadioButton rdbtnRadioButton = new JRadioButton(Messages.LafPreferencePage_previewRadio); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 5, 0); gbc.gridx = 1; gbc.gridy = 1; rootPane.getContentPane().add(rdbtnRadioButton, gbc); } { JCheckBox chckbxCheckbox = new JCheckBox(Messages.LafPreferencePage_previewCheck); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 0, 5); gbc.gridx = 0; gbc.gridy = 2; rootPane.getContentPane().add(chckbxCheckbox, gbc); } { JTextField textField = new JTextField(); textField.setText(Messages.LafPreferencePage_previewTextField); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 1; gbc.gridy = 2; rootPane.getContentPane().add(textField, gbc); } return rootPane; } }; awtComposite.populate(); // restore current laf UIManager.put("ClassLoader", currentLookAndFeel.getClass().getClassLoader()); UIManager.setLookAndFeel(currentLookAndFeel); } catch (Throwable e) { DesignerPlugin.log(e); } }
From source file:org.executequery.components.FileChooserDialog.java
protected JDialog createDialog(Component parent) throws HeadlessException { Frame frame = parent instanceof Frame ? (Frame) parent : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); String title = getUI().getDialogTitle(this); JDialog dialog = new JDialog(frame, title, true); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(this, BorderLayout.CENTER); setPreferredSize(new Dimension(700, getPreferredSize().height)); // add any custom panel if (customPanel != null) { contentPane.add(customPanel, BorderLayout.SOUTH); }/* w w w . ja v a 2s. c o m*/ if (JDialog.isDefaultLookAndFeelDecorated()) { boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations(); if (supportsWindowDecorations) { dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG); } } setFileView(new DefaultFileView()); dialog.pack(); dialog.setLocation(GUIUtilities.getLocationForDialog(dialog.getSize())); return dialog; }
From source file:org.f2o.absurdum.puck.gui.PuckFrame.java
/** * Sets the L&F to:// w w w.ja va 2 s .co m * The default cross-platform look and feel if the passed string is (case-insensitive) "Default", * The system look and feel if the passed string is (case-insensitive) "System", * The first look and feel found containing (case-insensitive) the string in its name (e.g. "Nimbus"), if any. * If the L&F specified is the current L&F, nothing will be done. * @param lookAndFeel */ public void setLookAndFeel(String lookAndFeel) { boolean changed = false; try { if ("default".equals(lookAndFeel.toLowerCase()) && !UIManager.getLookAndFeel().getClass().getName() .equals(UIManager.getCrossPlatformLookAndFeelClassName())) { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); changed = true; } else if ("system".equals(lookAndFeel.toLowerCase()) && !UIManager.getLookAndFeel().getClass() .getName().equals(UIManager.getSystemLookAndFeelClassName())) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); changed = true; } else { LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels(); for (int i = 0; i < lfs.length; i++) { if (lfs[i].getName().toLowerCase().contains(lookAndFeel.toLowerCase()) && !UIManager .getLookAndFeel().getName().toLowerCase().contains(lookAndFeel.toLowerCase())) { UIManager.setLookAndFeel(lfs[i].getClassName()); changed = true; break; } } } } catch (Exception e) //class not found, instantiation exception, etc. (shouldn't happen) { e.printStackTrace(); } if (changed) { SwingUtilities.updateComponentTreeUI(this); PuckConfiguration.getInstance().setProperty("look", lookAndFeel); } }
From source file:org.gcaldaemon.gui.ConfigEditor.java
private ConfigEditor(MainConfig config, ProgressMonitor monitor) throws Exception { this.config = config; try {/* w w w. j a v a 2s . c om*/ // Init swing System.setProperty("sun.awt.noerasebackground", "false"); //$NON-NLS-1$ //$NON-NLS-2$ System.setProperty("swing.aatext", "true"); //$NON-NLS-1$ //$NON-NLS-2$ System.setProperty("swing.boldMetal", "false"); //$NON-NLS-1$ //$NON-NLS-2$ Locale locale = Locale.getDefault(); String code = null; try { code = config.getConfigProperty(Configurator.EDITOR_LANGUAGE, null); if (code != null) { locale = new Locale(code); } } catch (Exception invalidLocale) { log.warn(invalidLocale); } if (!Messages.setUserLocale(locale)) { locale = Locale.ENGLISH; Messages.setUserLocale(locale); code = null; } if (code == null) { config.setConfigProperty(Configurator.EDITOR_LANGUAGE, locale.getLanguage().toLowerCase()); } try { boolean lookAndFeelChanged = false; String oldLaf = UIManager.getLookAndFeel().getClass().getName(); String newLaf = config.getConfigProperty(Configurator.EDITOR_LOOK_AND_FEEL, UIManager.getCrossPlatformLookAndFeelClassName()); lookAndFeelChanged = !oldLaf.equals(newLaf); if (lookAndFeelChanged) { UIManager.setLookAndFeel(newLaf); } if (config.getConfigProperty(Configurator.EDITOR_LOOK_AND_FEEL, null) == null) { config.setConfigProperty(Configurator.EDITOR_LOOK_AND_FEEL, newLaf); } if (lookAndFeelChanged) { new ConfigEditor(config, monitor); dispose(); return; } } catch (Exception invalidLaf) { log.warn(invalidLaf); } // Window settings setTitle(Messages.getString("config.editor") + " - " + config.getConfigPath()); //$NON-NLS-1$ //$NON-NLS-2$ setIconImage(TOOLKIT.getImage(ConfigEditor.class.getResource("/org/gcaldaemon/gui/icons/icon.gif"))); //$NON-NLS-1$ setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); Container root = getContentPane(); root.setLayout(new BorderLayout()); root.add(folder, BorderLayout.CENTER); folder.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); folder.setTabPlacement(JTabbedPane.LEFT); folder.addChangeListener(this); status.setBorder(new BevelBorder(BevelBorder.LOWERED)); root.add(status, BorderLayout.SOUTH); // Create menu items fileMenu = new JMenu(Messages.getString("file")); //$NON-NLS-1$ saveMenu = new JMenuItem(Messages.getString("save"), getIcon("save")); //$NON-NLS-1$ //$NON-NLS-2$ exitMenu = new JMenuItem(Messages.getString("exit"), getIcon("exit")); //$NON-NLS-1$ //$NON-NLS-2$ viewMenu = new JMenu(Messages.getString("view")); //$NON-NLS-1$ langMenu = new JMenu(Messages.getString("language")); //$NON-NLS-1$ lafMenu = new JMenu(Messages.getString("look.and.feel")); //$NON-NLS-1$ transMenu = new JMenuItem(Messages.getString("translate")); //$NON-NLS-1$ logMenu = new JMenuItem(Messages.getString("log.viewer")); //$NON-NLS-1$ helpMenu = new JMenu(Messages.getString("help")); //$NON-NLS-1$ aboutMenu = new JMenuItem(Messages.getString("about")); //$NON-NLS-1$ // Build menu setJMenuBar(menuBar); menuBar.add(fileMenu); fileMenu.add(saveMenu); fileMenu.addSeparator(); fileMenu.add(exitMenu); menuBar.add(viewMenu); viewMenu.add(logMenu); viewMenu.addSeparator(); viewMenu.add(langMenu); viewMenu.add(lafMenu); langMenu.add(transMenu); menuBar.add(helpMenu); helpMenu.add(aboutMenu); // Build language menu Locale[] locales = Messages.getAvailableLocales(); String[] names = new String[locales.length]; String temp; int i; for (i = 0; i < locales.length; i++) { names[i] = locales[i].getDisplayLanguage(Locale.ENGLISH); if (names[i] == null || names[i].length() == 0) { names[i] = locales[i].getLanguage().toLowerCase(); } temp = locales[i].getDisplayLanguage(locale); if (temp != null && temp.length() > 0 && !temp.equals(names[i])) { names[i] = names[i] + " [" + temp + ']'; } } Arrays.sort(names, String.CASE_INSENSITIVE_ORDER); if (locales.length != 0) { langMenu.addSeparator(); } for (i = 0; i < locales.length; i++) { JMenuItem item = new JMenuItem(names[i]); item.setName('!' + names[i]); langMenu.add(item); item.addActionListener(this); } // Build look and feel menu LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels(); LookAndFeelInfo info; for (i = 0; i < infos.length; i++) { info = infos[i]; JMenuItem item = new JMenuItem(info.getName()); item.addActionListener(this); item.setName('#' + info.getClassName()); lafMenu.add(item); } // Action listeners addWindowListener(this); folder.addChangeListener(this); exitMenu.addActionListener(this); saveMenu.addActionListener(this); transMenu.addActionListener(this); logMenu.addActionListener(this); aboutMenu.addActionListener(this); // Add pages addPage("common.settings", new CommonPage(config, this)); //$NON-NLS-1$ addPage("http.settings", new HttpPage(config, this)); //$NON-NLS-1$ addPage("file.settings", new FilePage(config, this)); //$NON-NLS-1$ addPage("feed.settings", new FeedPage(config, this)); //$NON-NLS-1$ addPage("ldap.settings", new LdapPage(config, this)); //$NON-NLS-1$ addPage("notifier.settings", new NotifierPage(config, this)); //$NON-NLS-1$ addPage("sendmail.settings", new SendmailPage(config, this)); //$NON-NLS-1$ addPage("mailterm.settings", new MailtermPage(config, this)); //$NON-NLS-1$ // Set tab colors Iterator editors = disabledServices.iterator(); while (editors.hasNext()) { setServiceEnabled((BooleanEditor) editors.next(), false); } disabledServices = null; // Show GUI setResizable(true); Dimension size = TOOLKIT.getScreenSize(); int w = size.width - 50; int h = size.height - 70; w = Math.min(w, 1000); h = Math.min(h, 700); setSize(w, h); setLocation((size.width - w) / 2, (size.height - h) / 2); validate(); if (monitor != null) { monitor.dispose(); } setVisible(true); toFront(); } catch (Exception error) { if (monitor != null) { monitor.dispose(); } error(Messages.getString("error"), "Unable to start configurator: " + error, error); } }
From source file:org.gtdfree.ApplicationHelper.java
public static final boolean isGTKLaF() { if (gtklaf == null) { try {/*from w w w .j av a2s. c om*/ gtklaf = Class.forName("com.sun.java.swing.plaf.gtk.GTKLookAndFeel") //$NON-NLS-1$ .isAssignableFrom(UIManager.getLookAndFeel().getClass()); } catch (Exception e) { gtklaf = Boolean.FALSE; } } return gtklaf; }
From source file:org.gtdfree.ApplicationHelper.java
public static int getDefaultFieldHeigth() { if (defaultFieldHeigth <= 0) { JTextField jtf = new JTextField(); jtf.setText("1234567890"); //$NON-NLS-1$ defaultFieldHeigth = jtf.getPreferredSize().height; if (UIManager.getLookAndFeel() != null && UIManager.getLookAndFeel().getClass().getName() .equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel")) { //$NON-NLS-1$ defaultFieldHeigth -= 4;//from w w w . j a v a 2 s.c o m } if (defaultFieldHeigth < 21) { defaultFieldHeigth = 21; } } return defaultFieldHeigth; }
From source file:org.gtdfree.GTDFree.java
/** * @param args//www . j a va2 s. co m */ @SuppressWarnings("static-access") public static void main(final String[] args) { //ApplicationHelper.changeDefaultFontSize(6, "TextField"); //ApplicationHelper.changeDefaultFontSize(6, "TextArea"); //ApplicationHelper.changeDefaultFontSize(6, "Table"); //ApplicationHelper.changeDefaultFontSize(6, "Tree"); //ApplicationHelper.changeDefaultFontStyle(Font.BOLD, "Tree"); final Logger logger = Logger.getLogger(GTDFree.class); logger.setLevel(Level.ALL); BasicConfigurator.configure(); Options op = new Options(); op.addOption("data", true, Messages.getString("GTDFree.Options.data")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("eodb", true, Messages.getString("GTDFree.Options.eodb")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("exml", true, Messages.getString("GTDFree.Options.exml")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("h", "help", false, Messages.getString("GTDFree.Options.help")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ op.addOption("log", true, Messages.getString("GTDFree.Options.log")); //$NON-NLS-1$ //$NON-NLS-2$ Options op2 = new Options(); op2.addOption(OptionBuilder.hasArg().isRequired(false) .withDescription(new MessageFormat(Messages.getString("GTDFree.Options.lang")) //$NON-NLS-1$ .format(new Object[] { "'en'", "'de', 'en'" })) //$NON-NLS-1$ //$NON-NLS-2$ .withArgName("de|en") //$NON-NLS-1$ .withLongOpt("Duser.language") //$NON-NLS-1$ .withValueSeparator('=').create()); op2.addOption(OptionBuilder.hasArg().isRequired(false) .withDescription(new MessageFormat(Messages.getString("GTDFree.Options.laf")).format(new Object[] { //$NON-NLS-1$ "'com.jgoodies.looks.plastic.Plastic3DLookAndFeel', 'com.jgoodies.looks.plastic.PlasticLookAndFeel', 'com.jgoodies.looks.plastic.PlasticXPLookAndFeel', 'com.jgoodies.looks.windows.WindowsLookAndFeel' (only on MS Windows), 'com.sun.java.swing.plaf.gtk.GTKLookAndFeel' (only on Linux with GTK), 'com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel', 'javax.swing.plaf.metal.MetalLookAndFeel'" })) //$NON-NLS-1$ .withLongOpt("Dswing.crossplatformlaf") //$NON-NLS-1$ .withValueSeparator('=').create()); CommandLineParser clp = new GnuParser(); CommandLine cl = null; try { cl = clp.parse(op, args); } catch (ParseException e1) { logger.error("Parse error.", e1); //$NON-NLS-1$ } System.out.print("GTD-Free"); //$NON-NLS-1$ String ver = ""; //$NON-NLS-1$ try { System.out.println(" version " + (ver = ApplicationHelper.getVersion())); //$NON-NLS-1$ } catch (Exception e) { System.out.println(); // ignore } if (true) { // || cl.hasOption("help") || cl.hasOption("h")) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("java [Java options] -jar gtd-free.jar [gtd-free options]" //$NON-NLS-1$ , "[gtd-free options] - " + Messages.getString("GTDFree.Options.appop") //$NON-NLS-1$ //$NON-NLS-2$ , op, "[Java options] - " + new MessageFormat(Messages.getString("GTDFree.Options.javaop")) //$NON-NLS-1$//$NON-NLS-2$ .format(new Object[] { "'-jar'" }) //$NON-NLS-1$ , false); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); hf.setLongOptPrefix("-"); //$NON-NLS-1$ hf.setWidth(88); hf.printOptions(pw, hf.getWidth(), op2, hf.getLeftPadding(), hf.getDescPadding()); String s = sw.getBuffer().toString(); s = s.replaceAll("\\A {3}", ""); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll("\n {3}", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll(" <", "=<"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.print(s); } String val = cl.getOptionValue("data"); //$NON-NLS-1$ if (val != null) { System.setProperty(ApplicationHelper.DATA_PROPERTY, val); System.setProperty(ApplicationHelper.TITLE_PROPERTY, "1"); //$NON-NLS-1$ } else { System.setProperty(ApplicationHelper.TITLE_PROPERTY, "0"); //$NON-NLS-1$ } val = cl.getOptionValue("log"); //$NON-NLS-1$ if (val != null) { Level l = Level.toLevel(val, Level.ALL); logger.setLevel(l); } if (!ApplicationHelper.tryLock(null)) { System.out.println("Instance of GTD-Free already running, pushing it to be visible..."); //$NON-NLS-1$ remotePushVisible(); System.out.println("Instance of GTD-Free already running, exiting."); //$NON-NLS-1$ System.exit(0); } if (!"OFF".equalsIgnoreCase(val)) { //$NON-NLS-1$ RollingFileAppender f = null; try { f = new RollingFileAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), ApplicationHelper.getLogFileName(), true); f.setMaxBackupIndex(3); BasicConfigurator.configure(f); f.rollOver(); } catch (IOException e2) { logger.error("Logging error.", e2); //$NON-NLS-1$ } } logger.info("GTD-Free " + ver + " started."); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("Args: " + Arrays.toString(args)); //$NON-NLS-1$ logger.info("Using data in: " + ApplicationHelper.getDataFolder()); //$NON-NLS-1$ if (cl.getOptionValue("exml") != null || cl.getOptionValue("eodb") != null) { //$NON-NLS-1$ //$NON-NLS-2$ GTDFreeEngine engine = null; try { engine = new GTDFreeEngine(); } catch (Exception e1) { logger.fatal("Fatal error, exiting.", e1); //$NON-NLS-1$ } val = cl.getOptionValue("exml"); //$NON-NLS-1$ if (val != null) { File f1 = new File(val); if (f1.isDirectory()) { f1 = new File(f1, "gtd-free-" + ApplicationHelper.formatLongISO(new Date()) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ } try { f1.getParentFile().mkdirs(); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } try { engine.getGTDModel().exportXML(f1); logger.info("Data successfully exported as XML to " + f1.toString()); //$NON-NLS-1$ } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } } val = cl.getOptionValue("eodb"); //$NON-NLS-1$ if (val != null) { File f1 = new File(val); if (f1.isDirectory()) { f1 = new File(f1, "gtd-free-" + ApplicationHelper.formatLongISO(new Date()) + ".odb-xml"); //$NON-NLS-1$ //$NON-NLS-2$ } try { f1.getParentFile().mkdirs(); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } try { GTDData data = engine.getGTDModel().getDataRepository(); if (data instanceof GTDDataODB) { try { ((GTDDataODB) data).exportODB(f1); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } logger.info("Data successfully exported as ODB to " + f1.toString()); //$NON-NLS-1$ } else { logger.info("Data is not stored in ODB database, nothing is exported."); //$NON-NLS-1$ } } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } } try { engine.close(true, false); } catch (Exception e) { logger.error("Internal error.", e); //$NON-NLS-1$ } return; } logger.debug("Using OS '" + System.getProperty("os.name") + "', '" + System.getProperty("os.version") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + "', '" + System.getProperty("os.arch") + "'."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ logger.debug("Using Java '" + System.getProperty("java.runtime.name") + "' version '" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + System.getProperty("java.runtime.version") + "'."); //$NON-NLS-1$ //$NON-NLS-2$ Locale[] supported = { Locale.ENGLISH, Locale.GERMAN }; String def = Locale.getDefault().getLanguage(); boolean toSet = true; for (Locale locale : supported) { toSet &= !locale.getLanguage().equals(def); } if (toSet) { logger.debug("System locale '" + def + "' not supported, setting to '" + Locale.ENGLISH.getLanguage() //$NON-NLS-1$//$NON-NLS-2$ + "'."); //$NON-NLS-1$ try { Locale.setDefault(Locale.ENGLISH); } catch (Exception e) { logger.warn("Setting default locale failed.", e); //$NON-NLS-1$ } } else { logger.debug("Using locale '" + Locale.getDefault().toString() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ } try { //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.Plastic3DLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.PlasticLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "javax.swing.plaf.metal.MetalLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); if (System.getProperty("swing.crossplatformlaf") == null) { //$NON-NLS-1$ String osName = System.getProperty("os.name"); //$NON-NLS-1$ if (osName != null && osName.toLowerCase().indexOf("windows") != -1) { //$NON-NLS-1$ UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel"); //$NON-NLS-1$ } else { try { // we prefer to use native L&F, many systems support GTK, even if Java thinks it is not supported UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); //$NON-NLS-1$ } catch (Throwable e) { logger.debug("GTK L&F not supported.", e); //$NON-NLS-1$ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } } } catch (Throwable e) { logger.warn("Setting L&F failed.", e); //$NON-NLS-1$ } logger.debug("Using L&F '" + UIManager.getLookAndFeel().getName() + "' by " //$NON-NLS-1$//$NON-NLS-2$ + UIManager.getLookAndFeel().getClass().getName()); try { final GTDFree application = new GTDFree(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { application.getJFrame(); application.restore(); //application.getJFrame().setVisible(true); application.pushVisible(); ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { if (SystemTray.isSupported() && application.getEngine().getGlobalProperties() .getBoolean(GlobalProperties.SHOW_TRAY_ICON, false)) { try { SystemTray.getSystemTray().add(application.getTrayIcon()); } catch (AWTException e) { logger.error("Failed to activate system tray icon.", e); //$NON-NLS-1$ } } } }); ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { application.exportRemote(); } }); if (application.getEngine().getGlobalProperties() .getBoolean(GlobalProperties.CHECK_FOR_UPDATE_AT_START, true)) { ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { application.checkForUpdates(false); } }); } } catch (Throwable t) { t.printStackTrace(); logger.fatal("Failed to start application, exiting.", t); //$NON-NLS-1$ if (application != null) { application.close(true); } System.exit(0); } } }); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { application.close(true); } catch (Exception e) { logger.warn("Failed to stop application.", e); //$NON-NLS-1$ } logger.info("Closed."); //$NON-NLS-1$ ApplicationHelper.releaseLock(); LogManager.shutdown(); } }); } catch (Throwable t) { logger.fatal("Initialization failed, exiting.", t); //$NON-NLS-1$ t.printStackTrace(); System.exit(0); } }
From source file:org.intermine.install.swing.ProjectEditor.java
/** * Change the look and feel of the application. * * @param laf The new Look and Feel information. * * @return <code>true</code> if the look and feel changed ok, <code>false</code> * if not.//from w ww . j a v a 2s . c om * * @see <a href="http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/plaf.html#dynamic"> * The Swing Tutorial</a> */ public boolean changeLookAndFeel(LookAndFeelInfo laf) { assert SwingUtilities.isEventDispatchThread() : "Can only change L&F from event thread"; if (laf.getName().equals(UIManager.getLookAndFeel().getName())) { return true; } boolean changeOk = false; try { UIManager.setLookAndFeel(laf.getClassName()); SwingUtilities.updateComponentTreeUI(this); SwingUtilities.updateComponentTreeUI(modelViewerFrame); for (Window w : getOwnedWindows()) { SwingUtilities.updateComponentTreeUI(w); } changeOk = true; } catch (Exception e) { logger.error("Failed to change look and feel: " + e.getMessage()); logger.debug("", e); int choice = JOptionPane.showConfirmDialog(this, Messages.getMessage("preferences.lookandfeel.changefailed.message", e.getMessage()), Messages.getMessage("preferences.lookandfeel.changefailed.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); changeOk = choice == JOptionPane.OK_OPTION; } return changeOk; }
From source file:org.jets3t.gui.skins.SkinsFactory.java
/** * @param itemName/*from w w w.j ava2 s. com*/ * the name of this specific item in the GUI, which may be used to determine how the skinned * item should look or behave. * * @return * a <code>SkinnedLookAndFeel</code> class implementation for the current skin, or the default * system LookAndFeel if no skin-specific implementation is available. */ public LookAndFeel createSkinnedMetalTheme(String itemName) { Object instance = instantiateClass(buildSkinnedClassName("SkinnedLookAndFeel"), itemName); if (instance != null) { return (LookAndFeel) instance; } else { return UIManager.getLookAndFeel(); } }
From source file:org.languagetool.gui.Main.java
private void addLookAndFeelMenuItem(JMenu lafMenu, UIManager.LookAndFeelInfo laf, ButtonGroup buttonGroup) { JRadioButtonMenuItem lfItem = new JRadioButtonMenuItem(new SelectLFAction(laf)); lafMenu.add(lfItem);// w w w . j a v a 2 s. c o m buttonGroup.add(lfItem); if (laf.getClassName().equals(UIManager.getLookAndFeel().getClass().getName())) { buttonGroup.setSelected(lfItem.getModel(), true); } }