Example usage for javax.swing UIManager getSystemLookAndFeelClassName

List of usage examples for javax.swing UIManager getSystemLookAndFeelClassName

Introduction

In this page you can find the example usage for javax.swing UIManager getSystemLookAndFeelClassName.

Prototype

public static String getSystemLookAndFeelClassName() 

Source Link

Document

Returns the name of the LookAndFeel class that implements the native system look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.

Usage

From source file:org.apache.pdfbox.debugger.PDFDebugger.java

/**
 * Entry point./*from w  w  w  .  j ava2  s  .  c  o  m*/
 *
 * @param args the command line arguments
 * @throws Exception If anything goes wrong.
 */
public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    if (System.getProperty("apple.laf.useScreenMenuBar") == null) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
    }

    // handle uncaught exceptions
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable throwable) {
            new ErrorDialog(throwable).setVisible(true);
        }
    });

    // open file, if any
    String filename = null;
    String password = "";
    boolean viewPages = true;

    for (int i = 0; i < args.length; i++) {
        if (args[i].equals(PASSWORD)) {
            i++;
            if (i >= args.length) {
                usage();
            }
            password = args[i];
        } else if (args[i].equals(VIEW_STRUCTURE)) {
            viewPages = false;
        } else {
            filename = args[i];
        }
    }
    filename = "/home/data/work/pdfxx_m.pdf";
    final PDFDebugger viewer = new PDFDebugger(viewPages);

    if (filename != null) {
        File file = new File(filename);
        if (file.exists()) {
            viewer.readPDFFile(filename, password);
        }
    }
    viewer.setVisible(true);
}

From source file:org.apache.tika.gui.TikaGUI.java

/**
 * Main method. Sets the Swing look and feel to the operating system
 * settings, and starts the Tika GUI with an {@link AutoDetectParser}
 * instance as the default parser.//w w w.j  a  v a 2  s  . co m
 *
 * @param args ignored
 * @throws Exception if an error occurs
 */
public static void main(String[] args) throws Exception {
    TikaConfig config = TikaConfig.getDefaultConfig();
    if (args.length > 0) {
        File configFile = new File(args[0]);
        config = new TikaConfig(configFile);
    }
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    final TikaConfig finalConfig = config;
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new TikaGUI(new DigestingParser(new AutoDetectParser(finalConfig), new CommonsDigester(MAX_MARK,
                    CommonsDigester.DigestAlgorithm.MD5, CommonsDigester.DigestAlgorithm.SHA256)))
                            .setVisible(true);
        }
    });
}

From source file:org.apache.uima.tools.docanalyzer.DBAnnotationViewerDialog.java

/** set default look and feel */
private static void setLF() {
    // Force SwingApp to come up in the System L&F
    String laf = UIManager.getSystemLookAndFeelClassName();
    try {/*from   w w w  . j  a va  2s  .  c  om*/
        UIManager.setLookAndFeel(laf);
    } catch (UnsupportedLookAndFeelException exc) {
        System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
    } catch (Exception exc) {
        System.err.println("Error loading " + laf + ": " + exc);
    }
}

From source file:org.apparatus_templi.Coordinator.java

public static void main(String argv[]) {
    Log.setLogLevel(Log.LEVEL_DEBUG);/*  www  . j  av a2  s.c o m*/
    Log.setLogToConsole(true);

    // disable dock icon in MacOS
    System.setProperty("apple.awt.UIElement", "true");

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // start the system tray icon listener. The sysTray should be save (but useless) in a
    // headless environment
    sysTray = new SysTray();

    // parse command line options
    parseCommandLineOptions(argv);

    // set debug level
    switch (prefs.getPreference(Prefs.Keys.debugLevel)) {
    case "err":
        Log.setLogLevel(Log.LEVEL_ERR);
        break;
    case "warn":
        Log.setLogLevel(Log.LEVEL_WARN);
        break;
    default:
        Log.setLogLevel(Log.LEVEL_DEBUG);
    }

    Log.d(TAG, "SERVICE STARTING");
    Log.c(TAG, "Starting");

    // open the serial connection
    openSerialConnection();

    // start the message center
    messageCenter = MessageCenter.getInstance();
    messageCenter.setSerialConnection(serialConnection);

    // block until the local Arduino is ready
    System.out.print(TAG + ":" + "Waiting for local link to be ready.");
    if (!(serialConnection instanceof DummySerialConnection)) {
        byte[] sBytes = null;
        try {
            sBytes = messageCenter.readBytesUntil((byte) 0x0A);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String sString = new String(sBytes);
        if (sString.endsWith("READY")) {
            connectionReady = true;
        }

        if (!connectionReady) {
            Coordinator.exitWithReason("could not find a local Arduino connection, exiting");
        } else {
            Log.c(TAG, "Local link ready.");
        }
    } else {
        connectionReady = true;
        Log.c(TAG, "Local dummy link ready");
    }

    // query for remote modules. Since the modules may be slow in responding
    // + we will wait for a few seconds to make sure we get a complete list
    System.out.print(TAG + ":" + "Querying modules (6s wait).");
    messageCenter.beginReadingMessages();
    // begin processing incoming messages
    new Thread(messageCenter).start();

    // if we are using the dummy serial connection then there is no point in
    // waiting
    // + 6 seconds for a response from the modules
    if (!(serialConnection instanceof DummySerialConnection)) {
        queryRemoteModules();
        for (int i = 0; i < 6; i++) {
            if (messageCenter.isMessageAvailable()) {
                routeIncomingMessage(messageCenter.getMessage());
            }

            System.out.print(".");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    System.out.println();

    if (remoteModules.size() > 0) {
        Log.c(TAG, "Found " + remoteModules.size() + " modules :" + remoteModules.toString());
    } else {
        Log.c(TAG, "Did not find any remote modules.");
    }

    // initialize and start all drivers
    startDrivers();

    // Add a shutdown hook so that the drivers can be notified when
    // + the system is going down.
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            Log.d(TAG, "system is going down. Notifying all drivers.");
            sysTray.setStatus(SysTray.Status.TERM);
            Thread.currentThread().setName("Shutdown Hook");
            // Coordinator.sendNotificationEmail("Shutdown Hook triggered");

            // cancel any pending driver restarts
            scheduledWakeUps.clear();
            for (String driverName : loadedDrivers.keySet()) {
                Log.d(TAG, "terminating driver '" + driverName + "'");
                loadedDrivers.get(driverName).terminate();
                Log.d(TAG, "notified driver '" + driverName + "'");
            }
            // give the drivers ~4s to finalize their termination
            long wakeTime = System.currentTimeMillis() + 4 * 1000;
            while (System.currentTimeMillis() < wakeTime) {
                // do a non-blocking sleep so that incoming message can still be routed
            }
            // System.exit(0);
        }
    });

    // start the web interface
    try {
        startWebServer(null);
    } catch (UnknownHostException e1) {
        // if we cant start the web server then the service should shut down
        Log.t(TAG, "can not start web server: " + e1.getMessage());
        Coordinator.exitWithReason("unable to start web server");
    }

    // the service should be up and running, send a notification email
    String serverUp = "Service has started normally.";
    String newLocation = webServer.getProtocol() + webServer.getServerLocation() + ":" + webServer.getPort()
            + "/index.html";
    StringBuilder newAddress = new StringBuilder();
    newAddress.append(
            "Web server restarted, available at: <a href='" + newLocation + "'>" + newLocation + "</a>");
    sendNotificationEmail(new String[] { serverUp, newAddress.toString() });

    // enter main loop
    while (true) {
        // TODO keep track of the last time a message was sent to/received
        // from each remote module
        // + if the time period is too great, then re-query the remote
        // modules, possibly removing
        // + them from the known list if no response is detected

        // Check for incoming messages, only process the first byte before
        // breaking off
        // + to a more appropriate method
        if (messageCenter.isMessageAvailable()) {
            routeIncomingMessage(messageCenter.getMessage());
        }

        // Check for scheduled driver wake ups.
        for (Driver d : scheduledWakeUps.keySet()) {
            Long wakeTime = scheduledWakeUps.get(d);
            Long curTime = System.currentTimeMillis();
            if (wakeTime <= curTime && wakeTime != 0) {
                try {
                    wakeDriver(d.getName());
                } catch (Exception e) {
                    Log.e(TAG, "error restarting driver '" + d.getName() + "'");
                    scheduledWakeUps.remove(d);
                }
            }
        }

        Thread.yield();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:org.cc86.MMC.client.Main.java

public static void main(String[] args) {
    //args=new String[]{"--demo"};
    CommandLineParser parser = new DefaultParser();
    Options options = new Options();
    options.addOption("d", "demo", false, "Demo UI modus fr die H+E in Schuttgart");
    options.addOption("x", "devmode", false, "Allows the Demo mode to be closed");
    options.addOption(/*from  w  ww. j  av a2 s.c  om*/
            OptionBuilder.withLongOpt("ip").withDescription("ip").hasArg().withArgName("ADDR").create("i"));
    try {
        String srvr = "0.0.0.0";
        TimeoutManager m = null;
        CommandLine cl = parser.parse(options, args);
        setupLogging(true);
        if (cl.hasOption("i")) {
            srvr = cl.getOptionValue("i");
        } else {
            serverDiscoveryHack(args);
            return;
            //Main.setupLogging(cl.hasOption("verbose"));

            //m = new TimeoutManager(2, ()->Messagers.SingleLineMsg("Serversuche fehlgeschlagen", "OK"));
            //m.start();
            //srvr =serverDiscovery();//;//"10.110.12.183";//
            //srvr="192.168.10.41";
        }
        l.info(srvr);
        if (srvr.equals("0.0.0.0")) {
            l.error("NO SERVER FOUND");
            System.exit(0);

        }
        c = new TCPConnection(srvr, 0xCC86);
        try {
            c.connect();
        } catch (IOException ex) {
            //System.out.println(ex.m);
            l.trace("Ell-Emm-AhhX2");
            l.error("FAILED TO CONNECT");
            System.exit(0);
        }
        piIP = srvr;
        disp.connect(c);
        Runtime.getRuntime().addShutdownHook(new Thread(disp::quit));
        if (m != null) {
            m.disarm();
        }

        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
        * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
                    .getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TestsUI.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TestsUI.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TestsUI.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TestsUI.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | UnsupportedLookAndFeelException e) {
            l.error("Fehler beim Setzen des LookAndFeels");
        }
        devmode = cl.hasOption("devmode");
        if (cl.hasOption("demo")) {
            java.awt.EventQueue.invokeLater(() -> {
                //ui = new TestsUI();
                //ui.setVisible(true);
                DemoUI.bootUI();
            });
        }

        else {
            java.awt.EventQueue.invokeLater(() -> {
                //ui = new TestsUI();
                //ui.setVisible(true);
                Menu.bootUI();
            });
        }
    } catch (ParseException ex) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("client", options);
        // ex.printStackTrace();
    }

}

From source file:org.colombbus.tangara.Main.java

/**
 * Creates the GUI and shows it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*from w w  w .j av a  2  s .  c o  m*/
private static void createAndShowGUI() {
    Class<?> typeClass = Program.class;
    try {
        try {
            String lang = Configuration.instance().getLanguage();
            String className = "org.colombbus.tangara." + lang + ".Program_" + lang;
            typeClass = Class.forName(className);
        } catch (ClassNotFoundException e) {
            // If the class in this language doesn't exist, we load the
            // English version of Program.
            typeClass = Class.forName("org.colombbus.tangara.en.Program_en");
        }
        Program.INSTANCE = (Program) typeClass.newInstance();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        exit();
    }

    // Forces the program initialization for error and output stream
    // initalization
    Program.init();
    LOG.info("Application starting..."); //$NON-NLS-1$
    // Try to set the System Look&Feel
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        LOG.error("Unable to load native look and feel"); //$NON-NLS-1$
    }
    Configuration conf = Configuration.instance();
    // binds the system program
    Program programme = Program.instance();
    programme.setHistoryDepth(conf.getHistoryDepth());
    programme.setCurrentDirectory(conf.getUserHome());

    // bean permits to translate to Program the commands in the chosen
    // language.
    String beanName = Messages.getString("Main.bean.program");
    try {
        // We declare the bean for Program.
        Configuration.instance().getManager().declareBean(beanName, programme, typeClass);
    } catch (BSFException e) {
        LOG.error(e.getMessage(), e);
        exit();
    }

    Class<?> tools = Program.instance().getTranslatedClassForName("Tools");
    try {
        Tools a = (Tools) tools.newInstance();
        String toolsName = Messages.getString("Main.bean.tools");
        Configuration.instance().getManager().declareBean(toolsName, a, tools);
    } catch (Exception e) {
        LOG.error("Error while casting tools " + e);
    }

    // -------------------------------------------------------------------------------------------

    // In normal execution of Tangara, we use an EditorFrame
    // In jar file mode we use a ProgramFrame
    // programMode is false for normal mode
    if (!programMode) {
        // Creates the frame
        frame = new EditorFrame(conf, helpEngine);
        programme.setFrame(frame);
        // binds the game area and sets in which language will be the
        // GraphicsPane
        GraphicsPane graphicsPane = frame.getGraphicsPane();
        graphicsPane.declareBeanForTheScreen();

        // sets the shell for Program
        programme.setBSFEngine(conf.getEngine());

        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                // allows to divide the main panel and makes the GUI ready
                frame.afterInit();
            }
        });
        checkForUpdate();

    } else { // .jar file mode
        frame = new FileOpenFrame();
        programme.setFrame(frame);

        // bind the game area
        GraphicsPane graphicsPane = frame.getGraphicsPane();
        graphicsPane.declareBeanForTheScreen();

        // sets the shell for Program and sets in which language will be the
        // GraphicsPane
        programme.setBSFEngine(conf.getEngine());

        executeProgram();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                // allows to divide the main panel and makes the GUI ready
                frame.afterInit();
            }
        });
    }
}

From source file:org.dataaccessioner.DataAccessioner.java

/**
 * @param args the command line arguments
 * @throws org.apache.commons.cli.ParseException
 *//*w w w .  j av a2s.  c om*/
public static void main(String[] args) throws ParseException {
    DataAccessioner da = new DataAccessioner();
    //Default settings
    String collectionName = "";
    String accessionNumber = "";
    String submitterName = "";
    String srcNote = "";
    String addNote = "";
    String runTime = "";

    Options options = new Options();
    options.addOption("c", true, "Collection Name (required if no GUI)");
    options.addOption("a", true, "Accession Number (required if no GUI)");
    options.addOption("n", true, "Submitter name (required if no GUI)");
    options.addOption(Option.builder().hasArg().longOpt("about-srcnote")
            .desc("Note about the source (optional)").argName("SRC NOTE").build());
    options.addOption(Option.builder().hasArg().longOpt("add-note").desc("Additional note (optional)")
            .argName("ADDL NOTE").build());
    options.addOption("u", false, "Do not start GUI; requires a source and destination");
    options.addOption("v", false, "print version information");
    options.addOption("h", false, "print this message");

    OptionGroup fitsOptions = new OptionGroup();
    fitsOptions.addOption(new Option("s", false, "Run FITS on source"));
    fitsOptions.addOption(new Option("x", false, "Don't run FITS; only copy"));
    options.addOptionGroup(fitsOptions);

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("h")) {
        printHelp(options);
        System.exit(0);
    }
    if (cmd.hasOption("v")) {
        System.out.println(DataAccessioner.VERSION);
        System.exit(0);
    }
    if (cmd.hasOption("c")) {
        collectionName = cmd.getOptionValue("c");
    }
    if (cmd.hasOption("a")) {
        accessionNumber = cmd.getOptionValue("a");
    }
    if (cmd.hasOption("n")) {
        submitterName = cmd.getOptionValue("n");
    }
    if (cmd.hasOption("about-srcnote")) {
        srcNote = cmd.getOptionValue("about-srcnote");
    }
    if (cmd.hasOption("add-note")) {
        addNote = cmd.getOptionValue("add-note");
    }

    try {
        if (cmd.hasOption("x")) {
            da.fits = null;
        } else {
            logger.info("Starting FITS");
            da.fits = new Fits();
        }
    } catch (FitsException ex) {
        System.err.println("FITS failed to initialize.");
        Exceptions.printStackTrace(ex);
    }
    //Get the destination & source
    File destination = null;
    List<File> sources = new ArrayList<File>();
    if (!cmd.getArgList().isEmpty()) {
        destination = new File((String) cmd.getArgList().remove(0));

        //validate sources or reject them
        for (Object sourceObj : cmd.getArgList()) {
            File source = new File(sourceObj.toString());
            if (source.canRead()) {
                sources.add(source);
            }
        }
    }

    if (cmd.hasOption("u")) {//Unattended
        if (collectionName.isEmpty() || accessionNumber.isEmpty() || submitterName.isEmpty()) {
            System.err.println(
                    "A collection name, a submitter name, and an accession number must be provided if not using the GUI.");
            printHelp(options);
        } else if (destination == null || !(destination.isDirectory() && destination.canWrite())) {
            String destinationStr = "<blank>";
            if (destination != null) {
                destinationStr = destination.toString();
            }
            System.err.println("Cannot run automatically. The destination (" + destinationStr
                    + ") is either not a valid or writable directory.");
            printHelp(options);
        } else if (sources.isEmpty()) {
            System.err.println("Cannot run automatically. At least one valid source is required.");
            printHelp(options);
        } else {
            HashMap<String, String> daCmdlnMetadata = new HashMap<>();
            daCmdlnMetadata.put("collectionName", collectionName);
            daCmdlnMetadata.put("accessionNumber", accessionNumber);
            daCmdlnMetadata.put("submitterName", submitterName);
            daCmdlnMetadata.put("aboutSourceNote", srcNote);
            daCmdlnMetadata.put("addNote", addNote);
            da.runUnattended(destination, sources, daCmdlnMetadata);
        }

    } else { //Start GUI
        try {
            // Set cross-platform Java L&F (also called "Metal")
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException e) {
            // handle exception
        } catch (ClassNotFoundException e) {
            // handle exception
        } catch (InstantiationException e) {
            // handle exception
        } catch (IllegalAccessException e) {
            // handle exception
        }
        DASwingView view = new DASwingView(da);
        view.pack();
        view.setVisible(true);
    }

}

From source file:org.domainmath.gui.etc.ResultDialog.java

/**
 * @param args the command line arguments
 *///from   w ww  .j  a va  2 s  .  c o  m
public static void main(String args[]) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException ex) {
    }
    /* Create and display the dialog */
    java.awt.EventQueue.invokeLater(() -> {
        ResultDialog dialog = new ResultDialog(null, true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent e) {
                System.exit(0);
            }
        });
    });
}

From source file:org.domainmath.gui.MainFrame.java

public static void main(String args[]) {
    try {/* w w  w. ja  va2  s  .  c  om*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException ex) {
    }
    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            new MainFrame(null).setVisible(true);

        }
    });
}

From source file:org.domainmath.gui.update.UpdateFrame.java

/**
 * @param args the command line arguments
 *///from  www.  ja  va 2 s  .  c  o m
public static void main(String args[]) {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException ex) {
    }
    /* Create and display the form */
    java.awt.EventQueue.invokeLater(() -> {
        new UpdateFrame().setVisible(true);
    });
}