List of usage examples for javax.swing UIManager setLookAndFeel
@SuppressWarnings("deprecation") public static void setLookAndFeel(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
From source file:DragDropTreeExample.java
public static void main(String[] args) { try {/*w w w. j a v a2 s. c o m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } final JFrame f = new JFrame("FileTree Drop Target Example"); try { final FileTree tree = new FileTree("D:\\"); // Add a drop target to the FileTree FileTreeDropTarget target = new FileTreeDropTarget(tree); tree.setEditable(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); JPanel panel = new JPanel(); final JCheckBox editable = new JCheckBox("Editable"); editable.setSelected(true); panel.add(editable); editable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { tree.setEditable(editable.isSelected()); } }); final JCheckBox enabled = new JCheckBox("Enabled"); enabled.setSelected(true); panel.add(enabled); enabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { tree.setEnabled(enabled.isSelected()); } }); f.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER); f.getContentPane().add(panel, BorderLayout.SOUTH); f.setSize(500, 400); f.setVisible(true); } catch (Exception e) { System.out.println("Failed to build GUI: " + e); } }
From source file:org.pegadi.client.ApplicationLauncher.java
protected void setTheme(String theme) { //TODO: fix nullpointerexception log.debug("theme: {}", theme); String lfTheme;//from w w w . j a va 2 s . com if (theme.equalsIgnoreCase("system")) { lfTheme = UIManager.getSystemLookAndFeelClassName(); } else if (theme.equalsIgnoreCase("swing")) { lfTheme = UIManager.getCrossPlatformLookAndFeelClassName(); lfTheme = UIManager.getSystemLookAndFeelClassName(); } else if (theme.equalsIgnoreCase("gtk")) { lfTheme = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"; //DEBUG lfTheme = UIManager.getSystemLookAndFeelClassName(); } else { log.error("Invalid L&F theme"); throw new IllegalArgumentException("'" + theme + "' is not a supported L&F"); } if (!lfTheme.equals(UIManager.getLookAndFeel().getName())) { try { UIManager.setLookAndFeel(lfTheme); } catch (Exception e) { log.warn("Unable to set selected L&F, swapping to a default L&F"); UIManager.LookAndFeelInfo[] installedLF = UIManager.getInstalledLookAndFeels(); try { UIManager.setLookAndFeel(installedLF[0].getClassName()); } catch (Exception e2) { log.error("Unable to load any L&F, exiting", e2); System.exit(-1); } } try { log.debug("attempting to update componenttreeui"); SwingUtilities.updateComponentTreeUI(this.getContentPane()); } catch (Exception swe) { log.error("Unable to update component tree", swe); } } pack(); //Might be the cause of occasional NullpointEx due to system //not being able to locate LookAndFeel }
From source file:JXTransformer.java
private void setLaf(String laf) { try {/*from w w w . j a v a 2 s.c o m*/ UIManager.setLookAndFeel(laf); SwingUtilities.updateComponentTreeUI(this); } catch (Exception e) { e.printStackTrace(); } for (JXTransformer t : transformers) { t.revalidate(); t.repaint(); } }
From source file:de.cenote.jasperstarter.Report.java
public static void setLookAndFeel() { try {/*from w w w .j a va 2 s.com*/ // Set System L&F UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:EditorPaneExample20.java
public static void main(String[] args) { try {/*from w w w. j a va 2 s. co m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new HTMLInsertFrame("Custom HTML Insertion", new JEditorPane()); f.setVisible(true); }
From source file:com.gele.tools.wow.wdbearmanager.WDBearManager.java
public void init(String[] args) { // copy ARGs/* ww w .j ava2 s .com*/ this.parseCommandLine(args); // Usefull for debugging this.myLogger.debug("java.version: " + System.getProperty("java.version")); this.myLogger.debug("java.vendor: " + System.getProperty("java.vendor")); this.myLogger.debug("java.vendor.url: " + System.getProperty("java.vendor.url")); this.myLogger.debug("os.name: " + System.getProperty("os.name")); this.myLogger.debug("os.arch: " + System.getProperty("os.arch")); this.myLogger.debug("os.version: " + System.getProperty("os.version")); if (this.paramDBconfig.length() != 0) { this.WDB_DB_CONFIG_FILE = this.paramDBconfig; } WDBearManager_API myAPI = new WDBearManager_API(this.WDB_DB_CONFIG_FILE); // Create all tables // -> Needed for the updata script <- // -> Otherwise it may crash with an empty database try { myAPI.getCountOfTable("creaturecache"); myAPI.getCountOfTable("gameobjectcache"); myAPI.getCountOfTable("itemcache"); myAPI.getCountOfTable("itemnamecache"); myAPI.getCountOfTable("itemtextchaxhe"); myAPI.getCountOfTable("npccache"); myAPI.getCountOfTable("pagetextcache"); myAPI.getCountOfTable("questcache"); } catch (Exception ex) { // ignore ex.printStackTrace(); System.exit(0); } // Check, if database must be re-newed DBUpdater myDBU = new DBUpdater(); myDBU.checkForUpdate(myAPI); WDBearManager_I myWoWWDBearManager_API = myAPI; // // print out some statistics // if (this.useGUI == false) { boolean paramSpec = false; // ASSERT DTO_Interface myDTO = null; if (this.paramWdbfile.length() != 0) { paramSpec = true; // Open WDB try { this.items = myWoWWDBearManager_API.readWDBfile(this.paramWdbfile); } catch (Exception ex) { this.myLogger.error("Error reading the WDB file"); return; } // first dto -> to identify the data Iterator itWDBS = this.items.iterator(); if (itWDBS.hasNext()) { myDTO = (DTO_Interface) itWDBS.next(); } } // Create CSV? if (this.paramCSVFolder.length() != 0) { if (myDTO == null) { // NO WDB specified -> exit this.myLogger.error("Error: You did not specify -" + this.PARAM_WDBFILE + "\n"); usage(this.options); return; } File csvFile = new File(this.paramCSVFolder, myDTO.getTableName() + ".csv"); if (this.useVerbose) { this.myLogger.info("Creating CSV file: " + csvFile.getAbsolutePath()); } try { WriteCSV.writeCSV(new File(this.paramCSVFolder), this.items); this.myLogger.info("CSV file written: " + csvFile.getAbsolutePath()); } catch (Exception ex) { ex.printStackTrace(); this.myLogger.error("Error writing the CSV file"); return; } } // Create TXT? if (this.paramTXTFolder.length() != 0) { if (myDTO == null) { // NO WDB specified -> exit this.myLogger.error("Error: You did not specify -" + this.PARAM_WDBFILE + "\n"); usage(this.options); return; } if (this.useVerbose) { String table = myDTO.getTableName(); File txtFile = new File(this.paramTXTFolder, table + ".txt"); this.myLogger.info("Creating TXT file: " + txtFile.getAbsolutePath()); } try { WriteTXT.writeTXT(new File(this.paramTXTFolder), this.items); } catch (Exception ex) { //ex.printStackTrace(); this.myLogger.error("Error writing the TXT file: " + ex.getMessage()); return; } } // Store inside SQL database? if (this.writeSQL == true) { paramSpec = true; if (myDTO == null) { // NO WDB specified -> exit this.myLogger.error("Error: You did not specify -" + this.PARAM_WDBFILE + "\n"); usage(this.options); return; } if (this.useVerbose) { this.myLogger.info("Storing data inside SQL database"); } SQLManager myWriteSQL = null; try { myWriteSQL = new SQLManager(this.WDB_DB_CONFIG_FILE); ObjectsWritten myOWr = myWriteSQL.insertOrUpdateToSQLDB(this.items, this.doUpdate); this.myLogger.info("Operation successfull"); if (this.useVerbose) { this.myLogger.info("DB statistics"); this.myLogger.info("INSERT: " + myOWr.getNumInsert()); this.myLogger.info("UPDATE: " + myOWr.getNumUpdate()); this.myLogger.info("Error INSERT: " + myOWr.getNumErrorInsert()); this.myLogger.info("Error UPDATE: " + myOWr.getNumErrorUpdate()); if (this.doUpdate == false) { this.myLogger.info("Objects skipped: " + myOWr.getNumSkipped()); System.out.println("If you want to overwrite/update objects, use 'update' param"); } this.myLogger.info(WDBearManager.VERSION_INFO); } } catch (Exception ex) { ex.printStackTrace(); this.myLogger.error("Error importing to database"); this.myLogger.error(ex.getMessage()); return; } } // writeSQL // Patch *.SCP with contents of database if (this.paramSCPname.length() != 0) { if (this.paramPatchSCP.length() == 0) { this.myLogger.error("Error: You did not specify -" + WDBearManager.PATCH_SCP + "\n"); usage(this.options); return; } paramSpec = true; this.myLogger.info("Patch scp file with the contents of the database"); try { SCPWritten mySCPW = myWoWWDBearManager_API.patchSCP(this.paramSCPname, this.paramPatchSCP, this.patchUTF8, this.paramLocale); if (this.useVerbose) { this.myLogger.info("Merge statistics"); System.out.println("Entries in database: " + mySCPW.getNumInDB()); this.myLogger.info("Merged with SCP: " + mySCPW.getNumPatched()); this.myLogger.info("Patched IDs: " + mySCPW.getPatchedIDs()); } this.myLogger.info("Patched file: " + this.paramSCPname + "_patch"); } catch (WDBMgr_IOException ex) { this.myLogger.error("The destination SCP file could not be created"); this.myLogger.error(ex.getMessage()); return; } catch (WDBMgr_NoDataAvailableException ex) { this.myLogger.info("Merging impossible"); this.myLogger.info("There are no entries inside the database"); } catch (Exception ex) { this.myLogger.error("Error while merging quests.scp with database"); this.myLogger.error(ex.getMessage()); return; } } // PatchSCP // Call jython script? if (this.paramScript.length() != 0) { paramSpec = true; this.myLogger.info("Calling Jython script"); this.myLogger.info("---"); PythonInterpreter interp = new PythonInterpreter(); interp.set("wdbmgrapi", myWoWWDBearManager_API); // set parameters Set setKeys = this.paramJython.keySet(); Iterator itKeys = setKeys.iterator(); String jyParam = ""; while (itKeys.hasNext()) { jyParam = (String) itKeys.next(); interp.set(jyParam, (String) this.paramJython.get(jyParam)); } interp.execfile(this.paramScript); this.myLogger.info("---"); System.out.println("Jython script executed, " + WDBearManager.VERSION_INFO); return; } // paramScript if (paramSpec == false) { usage(this.options); return; } // Exit return; } // Command Line Version // // GUI // PlasticLookAndFeel.setMyCurrentTheme(new DesertBlue()); try { UIManager.put("ClassLoader", LookUtils.class.getClassLoader()); UIManager.setLookAndFeel(new Plastic3DLookAndFeel()); } catch (Exception e) { } // try { // com.incors.plaf.kunststoff.KunststoffLookAndFeel kunststoffLnF = new com.incors.plaf.kunststoff.KunststoffLookAndFeel(); // KunststoffLookAndFeel // .setCurrentTheme(new com.incors.plaf.kunststoff.KunststoffTheme()); // UIManager.setLookAndFeel(kunststoffLnF); // } catch (javax.swing.UnsupportedLookAndFeelException ex) { // // handle exception or not, whatever you prefer // } // this line needs to be implemented in order to make JWS work properly UIManager.getLookAndFeelDefaults().put("ClassLoader", getClass().getClassLoader()); this.setTitle(WDBearManager.VERSION_INFO); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.getContentPane().setLayout(new BorderLayout()); // construct GUI to display the stuff // Menu // Where the GUI is created: JMenuBar menuBar; JMenu menu; //, submenu; JMenuItem menuItem; //JRadioButtonMenuItem rbMenuItem; //JCheckBoxMenuItem cbMenuItem; // Create the menu bar. menuBar = new JMenuBar(); // Build the first menu. menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("Process WDB files"); menuBar.add(menu); // Exit menuItem = new JMenuItem(MENU_EXIT, KeyEvent.VK_T); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Exit program"); menuItem.addActionListener(this); menu.add(menuItem); // Build the first menu. menu = new JMenu("About"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("Whassup?"); menuBar.add(menu); // Help menuItem = new JMenuItem(MENU_HELP, KeyEvent.VK_H); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Help me..."); menuItem.addActionListener(this); menu.add(menuItem); // JavaDocs menuItem = new JMenuItem(MENU_JDOCS, KeyEvent.VK_J); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Show API docs..."); menuItem.addActionListener(this); menu.add(menuItem); // separator menu.addSeparator(); // CheckForUpdate menuItem = new JMenuItem(MENU_CHECKUPDATE, KeyEvent.VK_U); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Check for update..."); menuItem.addActionListener(this); menu.add(menuItem); // separator menu.addSeparator(); // ABOUT menuItem = new JMenuItem(MENU_ABOUT, KeyEvent.VK_T); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Ueber..."); menuItem.addActionListener(this); menu.add(menuItem); this.setJMenuBar(menuBar); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new GridLayout(0, 1)); JTabbedPane tabbedPane = new JTabbedPane(); ImageIcon wowIcon = createImageIcon("images/fromdisk.gif"); JComponent panel1 = new WDB_Panel(myWoWWDBearManager_API); tabbedPane.addTab("WDB-Module", wowIcon, panel1, "Handle WDB files"); tabbedPane.setMnemonicAt(0, KeyEvent.VK_1); ImageIcon panelIcon = createImageIcon("images/hsql.gif"); JComponent panel2 = null; try { panel2 = new SQL_Panel(myWoWWDBearManager_API); } catch (Throwable ex) { System.err.println("Error while instantiating SQL Panel: "); System.err.println(ex.getMessage()); ex.printStackTrace(); System.exit(0); } tabbedPane.addTab("DB-Module", panelIcon, panel2, "Handle database"); tabbedPane.setMnemonicAt(1, KeyEvent.VK_2); panelIcon = createImageIcon("images/pythonpoweredsmall.gif"); JComponent panel3 = new Python_Panel(myWoWWDBearManager_API); tabbedPane.addTab("Scripts", panelIcon, panel3, "Scripting"); tabbedPane.setMnemonicAt(2, KeyEvent.VK_3); // maybe user PLUGIN availabe // -> check for folders below "plugins" File filUserPanels = new File("plugins"); // 1) find user plugins (scan for directories) // 2) scan for <name>.properties, where <name> is the name of the directory // 3) load the properties file and get the plugin running String[] strUserPlugins = filUserPanels.list(new FilenameFilter() { public boolean accept(File dir, String name) { return (new File(dir, name).isDirectory()); } }); if (strUserPlugins != null) { ArrayList urlJars = new ArrayList(); //URL[] urlJars = new URL[strUserPlugins.length]; String strCurrJar = ""; String strPlugins[] = new String[strUserPlugins.length]; try { for (int i = 0; i < strUserPlugins.length; i++) { File baseFile = new File("plugins", strUserPlugins[i]); File filProperties = new File(baseFile, strUserPlugins[i] + ".properties"); if (filProperties.exists()) { // set plugin folder and .properties name strPlugins[i] = strUserPlugins[i]; this.myLogger.info("Found 'plugin' : " + baseFile.getAbsolutePath()); this.myLogger.info(" Trying to load .jar file"); // Scan for JAR files and include them //System.out.println(baseFile.getAbsolutePath()); String[] strJars = baseFile.list(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".jar"); } }); for (int j = 0; j < strJars.length; j++) { File filJAR = new File(baseFile, strJars[j]); strCurrJar = filJAR.getAbsolutePath(); this.myLogger.info("Loading external 'plugin' JAR: " + strCurrJar); URL jarfile = new URL("jar", "", "file:" + strCurrJar + "!/"); urlJars.add(jarfile); } } else { // print warning - a directory inside plugins, but there is no plugin this.myLogger.warn("Found directory inside plugins folder, but no .properties file"); this.myLogger.warn(" Name of directory: " + strUserPlugins[i]); this.myLogger.warn(" Please review the directory!"); } } // for... all user plugins } catch (Exception ex) { this.myLogger.error("Plugin: Error loading " + strCurrJar); this.myLogger.error("Please check your 'plugin' folder"); } URLClassLoader cl = null; try { // File file = new File("plugins", strUserJars[i]); // this.myLogger.info("Lade externes JAR: " + file.getAbsolutePath()); // URL jarfile = new URL("jar", "", "file:" + file.getAbsolutePath() + "!/"); URL[] loadURLs = new URL[urlJars.toArray().length]; for (int j = 0; j < urlJars.toArray().length; j++) { loadURLs[j] = (URL) urlJars.get(j); } cl = URLClassLoader.newInstance(loadURLs); Thread.currentThread().setContextClassLoader(cl); // String lcStr = "Test"; // Class loadedClass = cl.loadClass(lcStr); // this.myLogger.info("Smooth..."); } catch (Exception ex) { ex.printStackTrace(); } // 2) load properties and instantiate the plugin // String[] strPlugins = filUserPanels.list(new FilenameFilter() { // public boolean accept(File dir, String name) { // return (name.endsWith("_plugin.properties")); // } // }); String strPluginName = ""; String strPluginClass = ""; String strPluginImage = ""; WDBearPlugin pluginPanel = null; for (int i = 0; i < strPlugins.length; i++) { //this.myLogger.info(strPlugins[i]); Properties prpPlugin = null; try { prpPlugin = ReadPropertiesFile.readProperties( new File("plugins", strPlugins[i] + "/" + strPlugins[i]).getAbsolutePath() + ".properties"); } catch (Exception ex) { this.myLogger.error("Error with plugin: " + strPlugins[i]); this.myLogger.error("Could not load properties file"); continue; } if ((strPluginClass = prpPlugin.getProperty(this.PLUGIN_CLASS)) == null) { this.myLogger.error("Error with plugin: " + strPlugins[i]); this.myLogger.error("Property '" + this.PLUGIN_CLASS + "' not found"); continue; } if ((strPluginName = prpPlugin.getProperty(this.PLUGIN_NAME)) == null) { this.myLogger.error("Error with plugin: " + strPlugins[i]); this.myLogger.error("Property '" + this.PLUGIN_NAME + "' not found"); continue; } if ((strPluginImage = prpPlugin.getProperty(this.PLUGIN_IMAGE)) == null) { this.myLogger.error("Error with plugin: " + strPlugins[i]); this.myLogger.error("Property '" + this.PLUGIN_IMAGE + "' not found"); continue; } File filPlgImg = new File("plugins", strPlugins[i] + "/" + strPluginImage); panelIcon = createImageIcon(filPlgImg.getAbsolutePath()); if (panelIcon == null) { this.myLogger.error("Error with plugin: " + strPlugins[i]); this.myLogger.error("Could not read image '" + strPluginImage + "'"); continue; } try { pluginPanel = (WDBearPlugin) (cl.loadClass(strPluginClass).newInstance()); pluginPanel.runPlugin(myAPI); } catch (Exception ex) { this.myLogger.error("Error with plugin: " + strPlugins[i]); this.myLogger.error("Could not instantiate '" + strPluginClass + "'"); ex.printStackTrace(); continue; } tabbedPane.addTab(strPluginName, panelIcon, pluginPanel, strPluginName); } // Plugins } // plugins folder found mainPanel.add(tabbedPane); this.getContentPane().add(mainPanel, BorderLayout.CENTER); this.setSize(1024, 768); //this.pack(); this.show(); }
From source file:de.huxhorn.lilith.Lilith.java
public static void startUI(final String appTitle) { final Logger logger = LoggerFactory.getLogger(Lilith.class); UIManager.installLookAndFeel("JGoodies Windows", "com.jgoodies.looks.windows.WindowsLookAndFeel"); UIManager.installLookAndFeel("JGoodies Plastic", "com.jgoodies.looks.plastic.PlasticLookAndFeel"); UIManager.installLookAndFeel("JGoodies Plastic 3D", "com.jgoodies.looks.plastic.Plastic3DLookAndFeel"); UIManager.installLookAndFeel("JGoodies Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); // Substance requires 1.6 UIManager.installLookAndFeel("Substance Dark - Twilight", "org.pushingpixels.substance.api.skin.SubstanceTwilightLookAndFeel"); UIManager.installLookAndFeel("Substance Light - Business", "org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel"); //UIManager.installLookAndFeel("Napkin", "net.sourceforge.napkinlaf.NapkinLookAndFeel"); // look & feels must be installed before creation of ApplicationPreferences. ApplicationPreferences applicationPreferences = new ApplicationPreferences(); // init look & feel String lookAndFeelName = applicationPreferences.getLookAndFeel(); String systemLookAndFeelClassName = UIManager.getSystemLookAndFeelClassName(); String lookAndFeelClassName = systemLookAndFeelClassName; if (lookAndFeelName != null) { for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if (lookAndFeelName.equals(info.getName())) { lookAndFeelClassName = info.getClassName(); break; }/*from w w w .j a va 2s. c o m*/ } } try { UIManager.setLookAndFeel(lookAndFeelClassName); } catch (Throwable e) { if (logger.isWarnEnabled()) logger.warn("Failed to set look&feel to '{}'.", lookAndFeelClassName, e); if (!lookAndFeelClassName.equals(systemLookAndFeelClassName)) { try { UIManager.setLookAndFeel(systemLookAndFeelClassName); lookAndFeelClassName = systemLookAndFeelClassName; } catch (Throwable e2) { if (logger.isWarnEnabled()) logger.warn("Failed to set look&feel to '{}'.", systemLookAndFeelClassName, e); lookAndFeelClassName = null; } } } boolean screenMenuBar = false; if (systemLookAndFeelClassName.equals(lookAndFeelClassName)) { // This instance of application is only used to query some info. The real one is in MainFrame. Application application = new DefaultApplication(); if (application.isMac()) { // Use Apple Aqua L&F screen menu bar if available; set property before any frames created try { System.setProperty(APPLE_SCREEN_MENU_BAR_SYSTEM_PROPERTY, "true"); screenMenuBar = true; } catch (Throwable e) { try { screenMenuBar = Boolean .parseBoolean(System.getProperty(APPLE_SCREEN_MENU_BAR_SYSTEM_PROPERTY, "false")); } catch (Throwable e2) { // ignore } } } } applicationPreferences.setUsingScreenMenuBar(screenMenuBar); boolean splashScreenDisabled = applicationPreferences.isSplashScreenDisabled(); try { SplashScreen splashScreen = null; if (!splashScreenDisabled) { CreateSplashRunnable createRunnable = new CreateSplashRunnable(appTitle); EventQueue.invokeAndWait(createRunnable); splashScreen = createRunnable.getSplashScreen(); Thread.sleep(500); // so the splash gets the chance to get displayed :( updateSplashStatus(splashScreen, "Initialized application preferences..."); } File startupApplicationPath = applicationPreferences.getStartupApplicationPath(); if (startupApplicationPath.mkdirs()) { if (logger.isDebugEnabled()) logger.debug("Created '{}'.", startupApplicationPath.getAbsolutePath()); } // System.err redirection { File errorLog = new File(startupApplicationPath, "errors.log"); boolean freshFile = false; if (!errorLog.isFile()) { freshFile = true; } try { FileOutputStream fos = new FileOutputStream(errorLog, true); PrintStream ps = new PrintStream(fos, true, StandardCharsets.UTF_8.name()); if (!freshFile) { ps.println("----------------------------------------"); } String currentDateTime = DateTimeFormatters.DATETIME_IN_SYSTEM_ZONE_SPACE.format(Instant.now()); ps.println("Started " + APP_NAME + " V" + APP_VERSION + " at " + currentDateTime); System.setErr(ps); if (logger.isInfoEnabled()) logger.info("Writing System.err to '{}'.", errorLog.getAbsolutePath()); } catch (FileNotFoundException | UnsupportedEncodingException e) { e.printStackTrace(); } } File prevPathFile = new File(startupApplicationPath, ApplicationPreferences.PREVIOUS_APPLICATION_PATH_FILENAME); if (prevPathFile.isFile()) { updateSplashStatus(splashScreen, "Moving application path content..."); moveApplicationPathContent(prevPathFile, startupApplicationPath); } if (!applicationPreferences.isLicensed()) { hideSplashScreen(splashScreen); LicenseAgreementDialog licenseDialog = new LicenseAgreementDialog(); licenseDialog.setAlwaysOnTop(true); licenseDialog.setAutoRequestFocus(true); Windows.showWindow(licenseDialog, null, true); if (licenseDialog.isLicenseAgreed()) { applicationPreferences.setLicensed(true); } else { if (logger.isWarnEnabled()) logger.warn("Didn't accept license! Exiting..."); System.exit(-1); } } updateSplashStatus(splashScreen, "Creating main window..."); CreateMainFrameRunnable createMain = new CreateMainFrameRunnable(applicationPreferences, splashScreen, appTitle); EventQueue.invokeAndWait(createMain); final MainFrame frame = createMain.getMainFrame(); if (logger.isDebugEnabled()) logger.debug("After show..."); updateSplashStatus(splashScreen, "Initializing application..."); EventQueue.invokeAndWait(frame::startUp); hideSplashScreen(splashScreen); mainFrame = frame; } catch (InterruptedException ex) { if (logger.isInfoEnabled()) logger.info("Interrupted...", ex); IOUtilities.interruptIfNecessary(ex); } catch (InvocationTargetException ex) { if (logger.isWarnEnabled()) logger.warn("InvocationTargetException...", ex); if (logger.isWarnEnabled()) logger.warn("Target-Exception: ", ex.getTargetException()); } }
From source file:net.sf.jabref.JabRef.java
private void setLookAndFeel() { try {/*from w w w.ja v a 2 s . c o m*/ String lookFeel; String systemLnF = UIManager.getSystemLookAndFeelClassName(); if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) { // Use system Look & Feel by default lookFeel = systemLnF; } else { lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL); } // At all cost, avoid ending up with the Metal look and feel: if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(lookFeel)) { Plastic3DLookAndFeel lnf = new Plastic3DLookAndFeel(); Plastic3DLookAndFeel.setCurrentTheme(new SkyBluer()); com.jgoodies.looks.Options.setPopupDropShadowEnabled(true); UIManager.setLookAndFeel(lnf); } else { try { UIManager.setLookAndFeel(lookFeel); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { // specified look and feel does not exist on the classpath, so use system l&f UIManager.setLookAndFeel(systemLnF); // also set system l&f as default Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLnF); // notify the user JOptionPane.showMessageDialog(JabRef.jrf, Localization.lang( "Unable to find the requested Look & Feel and thus the default one is used."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE); } } } catch (Exception e) { LOGGER.warn("Look and feel could not be set", e); } // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS); if (overrideDefaultFonts) { int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE); UIDefaults defaults = UIManager.getDefaults(); Enumeration<Object> keys = defaults.keys(); Double zoomLevel = null; for (Object key : Collections.list(keys)) { if ((key instanceof String) && ((String) key).endsWith(".font")) { FontUIResource font = (FontUIResource) UIManager.get(key); if (zoomLevel == null) { // zoomLevel not yet set, calculate it based on the first found font zoomLevel = (double) fontSize / (double) font.getSize(); } font = new FontUIResource(font.getName(), font.getStyle(), fontSize); defaults.put(key, font); } } if (zoomLevel != null) { GUIGlobals.zoomLevel = zoomLevel; } } }
From source file:edu.stanford.muse.launcher.Main.java
/** we need a system tray icon for management. * http://docs.oracle.com/javase/6/docs/api/java/awt/SystemTray.html */ public static void setupSystemTrayIcon() { // Set the app name in the menu bar for mac. // c.f. http://stackoverflow.com/questions/8918826/java-os-x-lion-set-application-name-doesnt-work System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Muse"); try {// ww w . j a v a 2s . com UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { throw new RuntimeException(e); } TrayIcon trayIcon = null; if (SystemTray.isSupported()) { System.out.println("Adding Muse to the system tray"); SystemTray tray = SystemTray.getSystemTray(); URL u = Main.class.getClassLoader().getResource("muse-icon.png"); // note: this better be 16x16, Windows doesn't resize! Mac os does. System.out.println("muse icon resource is " + u); Image image = Toolkit.getDefaultToolkit().getImage(u); System.out.println("Image = " + image); // create menu items and their listeners ActionListener openMuseControlsListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { launchBrowser(BASE_URL + "/info"); } catch (Exception e1) { e1.printStackTrace(); } } }; ActionListener QuitMuseListener = new ActionListener() { public void actionPerformed(ActionEvent e) { out.println("*** Received quit from system tray. Stopping the Jetty embedded web server."); try { server.stop(); } catch (Exception ex) { throw new RuntimeException(ex); } System.exit(0); // we need to explicitly system.exit because we now use Swing (due to system tray, etc). } }; // create a popup menu PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem("Open Muse window"); defaultItem.addActionListener(openMuseControlsListener); popup.add(defaultItem); MenuItem quitItem = new MenuItem("Quit Muse"); quitItem.addActionListener(QuitMuseListener); popup.add(quitItem); /// ... add other items // construct a TrayIcon String message = "Muse menu"; // on windows - the tray menu is a little non-intuitive, needs a right click (plain click seems unused) if (System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0) message = "Right click for Muse menu"; trayIcon = new TrayIcon(image, message, popup); System.out.println("tray Icon = " + trayIcon); // set the TrayIcon properties // trayIcon.addActionListener(openMuseControlsListener); try { tray.add(trayIcon); } catch (AWTException e) { System.err.println(e); } // ... } else { // disable tray option in your application or // perform other actions // ... } System.out.println("Done!"); // ... // some time later // the application state has changed - update the image if (trayIcon != null) { // trayIcon.setImage(updatedImage); } // ... }
From source file:Classes.MainForm.java
public void exitLabelMouseClicked(MouseEvent e) {//hid main form and display try icon if (!SystemTray.isSupported()) { System.exit(0);/*from w w w . j av a 2 s . c o m*/ } else { if (this.mainFrame.isVisible()) { this.mainFrame.dispose(); } if (MainForm.trayIcon == null) { try { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { } initTray(); } catch (IOException e1) { System.exit(0); } } } }