List of usage examples for javax.swing UIManager getSystemLookAndFeelClassName
public static String getSystemLookAndFeelClassName()
LookAndFeel
class that implements the native system look and feel if there is one, otherwise the name of the default cross platform LookAndFeel
class. From source file:org.opendatakit.briefcase.ui.CharsetConverterDialog.java
/** * Launch the application.//from w ww . j a va2 s . co m */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { // Set System L&F UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); CharsetConverterDialog window = new CharsetConverterDialog(new JFrame()); window.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:org.opendatakit.briefcase.ui.MainBriefcaseWindow.java
/** * Launch the application.//from www.j ava 2 s .com */ public static void main(String[] args) { if (args.length == 0) { EventQueue.invokeLater(new Runnable() { public void run() { try { // Set System L&F UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); MainBriefcaseWindow window = new MainBriefcaseWindow(); window.frame.setTitle(BRIEFCASE_VERSION); ImageIcon icon = new ImageIcon( MainBriefcaseWindow.class.getClassLoader().getResource("odk_logo.png")); window.frame.setIconImage(icon.getImage()); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } else { Options options = addOptions(); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e1) { log.error("Launch Failed: " + e1.getMessage()); showHelp(options); System.exit(1); } if (cmd.hasOption(HELP)) { showHelp(options); System.exit(1); } if (cmd.hasOption(VERSION)) { showVersion(); System.exit(1); } // required for all operations if (!cmd.hasOption(FORM_ID) || !cmd.hasOption(STORAGE_DIRECTORY)) { log.error(FORM_ID + " and " + STORAGE_DIRECTORY + " are required"); showHelp(options); System.exit(1); } // pull from collect or aggregate, not both if (cmd.hasOption(ODK_DIR) && cmd.hasOption(AGGREGATE_URL)) { log.error("Can only have one of " + ODK_DIR + " or " + AGGREGATE_URL); showHelp(options); System.exit(1); } // pull from aggregate if (cmd.hasOption(AGGREGATE_URL) && (!(cmd.hasOption(ODK_USERNAME) && cmd.hasOption(ODK_PASSWORD)))) { log.error(ODK_USERNAME + " and " + ODK_PASSWORD + " required when " + AGGREGATE_URL + " is specified"); showHelp(options); System.exit(1); } // export files if (cmd.hasOption(EXPORT_DIRECTORY) && !cmd.hasOption(EXPORT_FILENAME) || !cmd.hasOption(EXPORT_DIRECTORY) && cmd.hasOption(EXPORT_FILENAME)) { log.error(EXPORT_DIRECTORY + " and " + EXPORT_FILENAME + " are both required to export"); showHelp(options); System.exit(1); } if (cmd.hasOption(EXPORT_END_DATE)) { if (!testDateFormat(cmd.getOptionValue(EXPORT_END_DATE))) { log.error("Invalid date format in " + EXPORT_END_DATE); showHelp(options); System.exit(1); } } if (cmd.hasOption(EXPORT_START_DATE)) { if (!testDateFormat(cmd.getOptionValue(EXPORT_START_DATE))) { log.error("Invalid date format in " + EXPORT_START_DATE); showHelp(options); System.exit(1); } } BriefcaseCLI bcli = new BriefcaseCLI(cmd); bcli.run(); } }
From source file:org.opendatakit.briefcase.ui.MainClearBriefcasePreferencesWindow.java
/** * Launch the application./*from www . j a va 2 s .c o m*/ */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { // Set System L&F UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); Image myImage = Toolkit.getDefaultToolkit().getImage( MainClearBriefcasePreferencesWindow.class.getClassLoader().getResource("odk_logo.png")); Object[] options = { "Purge", "Cancel" }; int outcome = JOptionPane.showOptionDialog(null, "Clear all Briefcase preferences. ", CLEAR_PREFERENCES_VERSION, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, new ImageIcon(myImage), options, options[1]); if (outcome == 0) { BriefcasePreferences.setBriefcaseDirectoryProperty(null); } } catch (Exception e) { log.error("failed to launch app", e); } } }); }
From source file:org.opendatakit.briefcase.ui.MainFormUploaderWindow.java
/** * Launch the application./* ww w. j av a 2 s . com*/ */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { // Set System L&F UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); MainFormUploaderWindow window = new MainFormUploaderWindow(); window.frame.setTitle(FORM_UPLOADER_VERSION); ImageIcon icon = new ImageIcon( MainFormUploaderWindow.class.getClassLoader().getResource("odk_logo.png")); window.frame.setIconImage(icon.getImage()); window.frame.setVisible(true); } catch (Exception e) { log.error("failed to launch app", e); } } }); }
From source file:org.openmrs.test.BaseContextSensitiveTest.java
/** * Utility method for obtaining username and password through Swing interface for tests. Any * tests extending the org.openmrs.BaseTest class may simply invoke this method by name. * Username and password are returned in a two-member String array. If the user aborts, null is * returned. <b> <em>Do not call for non-interactive tests, since this method will try to * render an interactive dialog box for authentication!</em></b> * /*from w ww . j a va 2 s . co m*/ * @param message string to display above username field * @return Two-member String array containing username and password, respectively, or * <code>null</code> if user aborts dialog */ public static synchronized String[] askForUsernameAndPassword(String message) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } if (message == null || "".equals(message)) message = "Enter username/password to authenticate to OpenMRS..."; JPanel panel = new JPanel(new GridBagLayout()); JLabel usernameLabel = new JLabel("Username"); usernameLabel.setFont(font); usernameField = new JTextField(20); usernameField.setFont(font); JLabel passwordLabel = new JLabel("Password"); passwordLabel.setFont(font); JPasswordField passwordField = new JPasswordField(20); passwordField.setFont(font); panel.add(usernameLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 0)); panel.add(usernameField, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); panel.add(passwordLabel, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 0)); panel.add(passwordField, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); frame = new JFrame(); Window window = new Window(frame); frame.setVisible(true); frame.setTitle("JUnit Test Credentials"); // We use a TimerTask to force focus on username, but still use // JOptionPane for model dialog TimerTask later = new TimerTask() { @Override public void run() { if (frame != null) { // bring the dialog's window to the front frame.toFront(); usernameField.grabFocus(); } } }; // try setting focus half a second from now new Timer().schedule(later, 500); // attention grabber for those people that aren't as observant TimerTask laterStill = new TimerTask() { @Override public void run() { if (frame != null) { frame.toFront(); // bring the dialog's window to the // front usernameField.grabFocus(); } } }; // if the user hasn't done anything in 10 seconds, tell them the window // is there new Timer().schedule(laterStill, 10000); // show the dialog box int response = JOptionPane.showConfirmDialog(window, panel, message, JOptionPane.OK_CANCEL_OPTION); // clear out the window so the timer doesn't screw up laterStill.cancel(); frame.setVisible(false); window.setVisible(false); frame = null; // response of 2 is the cancel button, response of -1 is the little red // X in the top right return (response == 2 || response == -1 ? null : new String[] { usernameField.getText(), String.valueOf(passwordField.getPassword()) }); }
From source file:org.openpnp.Main.java
public static void main(String[] args) { // http://developer.apple.com/library/mac/#documentation/Java/Conceptual/Java14Development/07-NativePlatformIntegration/NativePlatformIntegration.html#//apple_ref/doc/uid/TP40001909-212952-TPXREF134 System.setProperty("apple.laf.useScreenMenuBar", "true"); try {/*w w w. j a v a 2 s . c o m*/ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { throw new Error(e); } File configurationDirectory = new File(System.getProperty("user.home")); configurationDirectory = new File(configurationDirectory, ".openpnp"); // If the log4j.properties is not in the configuration directory, copy // the default over. File log4jConfigurationFile = new File(configurationDirectory, "log4j.properties"); if (!log4jConfigurationFile.exists()) { try { FileUtils.copyURLToFile(ClassLoader.getSystemResource("log4j.properties"), log4jConfigurationFile); } catch (Exception e) { e.printStackTrace(); } } // Use the local configuration if it exists. if (log4jConfigurationFile.exists()) { System.setProperty("log4j.configuration", log4jConfigurationFile.toURI().toString()); } // We don't create a logger until log4j has been configured or it tries // to configure itself. logger = LoggerFactory.getLogger(Main.class); logger.debug(String.format("OpenPnP %s Started.", Main.getVersion())); Configuration.initialize(configurationDirectory); final Configuration configuration = Configuration.get(); final JobProcessor jobProcessor = new JobProcessor(configuration); EventQueue.invokeLater(new Runnable() { public void run() { try { MainFrame frame = new MainFrame(configuration, jobProcessor); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:org.openscience.jchempaint.application.JChemPaint.java
@SuppressWarnings("static-access") public static void main(String[] args) { try {//ww w . j a v a 2 s.c o m String vers = System.getProperty("java.version"); String requiredJVM = "1.5.0"; Package self = Package.getPackage("org.openscience.jchempaint"); String version = GT._("Could not determine JCP version"); if (self != null) version = JCPPropertyHandler.getInstance(true).getVersion(); if (vers.compareTo(requiredJVM) < 0) { System.err.println(GT._("WARNING: JChemPaint {0} must be run with a Java VM version {1} or higher.", new String[] { version, requiredJVM })); System.err.println(GT._("Your JVM version is {0}", vers)); System.exit(1); } Options options = new Options(); options.addOption("h", "help", false, GT._("gives this help page")); options.addOption("v", "version", false, GT._("gives JChemPaints version number")); options.addOption("d", "debug", false, "switches on various debug options"); options.addOption(OptionBuilder.withArgName("property=value").hasArg().withValueSeparator() .withDescription(GT._("supported options are given below")).create("D")); CommandLine line = null; try { CommandLineParser parser = new PosixParser(); line = parser.parse(options, args); } catch (UnrecognizedOptionException exception) { System.err.println(exception.getMessage()); System.exit(-1); } catch (ParseException exception) { System.err.println("Unexpected exception: " + exception.toString()); } if (line.hasOption("v")) { System.out.println("JChemPaint v." + version + "\n"); System.exit(0); } if (line.hasOption("h")) { System.out.println("JChemPaint v." + version + "\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("JChemPaint", options); // now report on the -D options System.out.println(); System.out.println("The -D options are as follows (defaults in parathesis):"); System.out.println(" cdk.debugging [true|false] (false)"); System.out.println(" cdk.debug.stdout [true|false] (false)"); System.out.println(" user.language [ar|ca|cs|de|en|es|hu|nb|nl|pl|pt|ru|th] (en)"); System.out.println(" user.language [ar|ca|cs|de|hu|nb|nl|pl|pt_BR|ru|th] (EN)"); System.exit(0); } boolean debug = false; if (line.hasOption("d")) { debug = true; } // Set Look&Feel Properties props = JCPPropertyHandler.getInstance(true).getJCPProperties(); try { UIManager.setLookAndFeel(props.getProperty("LookAndFeelClass")); } catch (Throwable e) { String sys = UIManager.getSystemLookAndFeelClassName(); UIManager.setLookAndFeel(sys); props.setProperty("LookAndFeelClass", sys); } // Language props.setProperty("General.language", System.getProperty("user.language", "en")); // Process command line arguments String modelFilename = ""; args = line.getArgs(); if (args.length > 0) { modelFilename = args[0]; File file = new File(modelFilename); if (!file.exists()) { System.err.println(GT._("File does not exist") + ": " + modelFilename); System.exit(-1); } showInstance(file, null, null, debug); } else { showEmptyInstance(debug); } } catch (Throwable t) { System.err.println("uncaught exception: " + t); t.printStackTrace(System.err); } }
From source file:org.parosproxy.paros.Andiparos.java
/** * Initialization without dependence on any data model nor view creation. * //from w w w. j a va 2 s. c o m * @param args */ private void init(String[] args) { try { cmdLine = new CommandLine(args); } catch (Exception e) { System.out.println(CommandLine.getHelpGeneral()); System.exit(1); } Locale.setDefault(Locale.ENGLISH); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } // Andiparos: Use Nimbus if it is enforced and installed if (Constant.useNimbus) { try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (UnsupportedLookAndFeelException e) { // handle exception } catch (ClassNotFoundException e) { // handle exception } catch (InstantiationException e) { // handle exception } catch (IllegalAccessException e) { // handle exception } } }
From source file:org.parosproxy.paros.Paros.java
/** * Initialization without dependence on any data model nor view creation. * @param args//from w w w . j ava2s . c o m */ private void init(String[] args) { HttpSender.setUserAgent(Constant.USER_AGENT); try { cmdLine = new CommandLine(args); } catch (Exception e) { System.out.println(CommandLine.getHelpGeneral()); System.exit(1); } Locale.setDefault(Locale.ENGLISH); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } // System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); // System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); // System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "error"); }
From source file:org.pgptool.gui.ui.tools.UiUtils.java
public static void setLookAndFeel() { // NOTE: We doing it this way to prevent dead=locks that is sometimes // happens if do it in main thread Edt.invokeOnEdtAndWait(new Runnable() { @Override/*w ww.j a v a 2s . co m*/ public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); fixCheckBoxMenuItemForeground(); fixFontSize(); } catch (Throwable t) { log.error("Failed to set L&F", t); } } /** * In some cases (depends on OS theme) check menu item foreground is same as * bacground - thus it;'s invisible when cheked */ private void fixCheckBoxMenuItemForeground() { UIDefaults defaults = UIManager.getDefaults(); Color selectionForeground = defaults.getColor("CheckBoxMenuItem.selectionForeground"); Color foreground = defaults.getColor("CheckBoxMenuItem.foreground"); Color background = defaults.getColor("CheckBoxMenuItem.background"); if (colorsDiffPercentage(selectionForeground, background) < 10) { // TODO: That doesn't actually affect defaults. Need to find out how to fix it defaults.put("CheckBoxMenuItem.selectionForeground", foreground); } } private int colorsDiffPercentage(Color c1, Color c2) { int diffRed = Math.abs(c1.getRed() - c2.getRed()); int diffGreen = Math.abs(c1.getGreen() - c2.getGreen()); int diffBlue = Math.abs(c1.getBlue() - c2.getBlue()); float pctDiffRed = (float) diffRed / 255; float pctDiffGreen = (float) diffGreen / 255; float pctDiffBlue = (float) diffBlue / 255; return (int) ((pctDiffRed + pctDiffGreen + pctDiffBlue) / 3 * 100); } private void fixFontSize() { if (isJreHandlesScaling()) { log.info("JRE handles font scaling, won't change it"); return; } log.info("JRE doesnt't seem to support font scaling"); Toolkit toolkit = Toolkit.getDefaultToolkit(); int dpi = toolkit.getScreenResolution(); if (dpi == 96) { if (log.isDebugEnabled()) { Font font = UIManager.getDefaults().getFont("TextField.font"); String current = font != null ? Integer.toString(font.getSize()) : "unknown"; log.debug( "Screen dpi seem to be 96. Not going to change font size. Btw current size seem to be " + current); } return; } int targetFontSize = 12 * dpi / 96; log.debug("Screen dpi = " + dpi + ", decided to change font size to " + targetFontSize); setDefaultSize(targetFontSize); } private boolean isJreHandlesScaling() { try { JreVersion noNeedToScaleForVer = JreVersion.parseString("9"); String jreVersionStr = System.getProperty("java.version"); if (jreVersionStr != null) { JreVersion curVersion = JreVersion.parseString(jreVersionStr); if (noNeedToScaleForVer.compareTo(curVersion) <= 0) { return true; } } return false; } catch (Throwable t) { log.warn("Failed to see oif JRE can handle font scaling. Will assume it does. JRE version: " + System.getProperty("java.version"), t); return true; } } public void setDefaultSize(int size) { Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet(); Object[] keys = keySet.toArray(new Object[keySet.size()]); for (Object key : keys) { if (key != null && key.toString().toLowerCase().contains("font")) { Font font = UIManager.getDefaults().getFont(key); if (font != null) { Font changedFont = font.deriveFont((float) size); UIManager.put(key, changedFont); Font doubleCheck = UIManager.getDefaults().getFont(key); log.debug("Font size changed for " + key + ". From " + font.getSize() + " to " + doubleCheck.getSize()); } } } } }); log.info("L&F set"); }