List of usage examples for java.lang Runnable Runnable
Runnable
From source file:de.mfo.jsurf.Main.java
/** * @param args//from w w w . ja va2 s. c o m */ public static void main(String[] args) { String jsurf_filename = ""; Options options = new Options(); options.addOption("s", "size", true, "width (and height) of a image (default: " + size + ")"); options.addOption("q", "quality", true, "quality of the rendering: 0 (low), 1 (medium, default), 2 (high), 3 (extreme)"); options.addOption("o", "output", true, "output PNG into this file (- means standard output. Use ./- to denote a file literally named -.)"); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); String cmd_line_syntax = "jsurf [options] jsurf_file"; String help_header = "jsurf is a renderer for algebraic surfaces. If - is specified as a filename the jsurf file is read from standard input. " + "Use ./- to denote a file literally named -."; String help_footer = ""; try { CommandLine cmd = parser.parse(options, args); if (cmd.getArgs().length > 0) jsurf_filename = cmd.getArgs()[0]; else { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); return; } if (cmd.hasOption("output")) { } if (cmd.hasOption("size")) size = Integer.parseInt(cmd.getOptionValue("size")); int quality = 1; if (cmd.hasOption("quality")) quality = Integer.parseInt(cmd.getOptionValue("quality")); switch (quality) { case 0: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.OG_1x1; break; case 2: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.OG_4x4; break; case 3: aam = AntiAliasingMode.SUPERSAMPLING; aap = AntiAliasingPattern.OG_4x4; break; case 1: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.QUINCUNX; } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); System.exit(-1); } catch (NumberFormatException nfe) { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); System.exit(-1); } final Properties jsurf = new Properties(); try { if (jsurf_filename.equals("-")) jsurf.load(System.in); else jsurf.load(new FileReader(jsurf_filename)); FileFormat.load(jsurf, asr); } catch (Exception e) { System.err.println("Unable to read jsurf file " + jsurf_filename); e.printStackTrace(); System.exit(-2); } asr.setAntiAliasingMode(aam); asr.setAntiAliasingPattern(aap); // display the image in a window final String window_title = "jsurf: " + jsurf_filename; SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame f = new JFrame(window_title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSurferRenderPanel p = null; try { p = new JSurferRenderPanel(jsurf); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } f.setContentPane(p); // f.getContentPane().add( new JLabel( new ImageIcon( window_image ) ) ); f.pack(); // f.setResizable( false ); f.setVisible(true); } }); }
From source file:GuardarImagen.AyudaParaImagen.java
/** * @param args the command line arguments */// w ww. jav a2 s . c om public static void main(String args[]) { /* 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(AyudaParaImagen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(AyudaParaImagen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(AyudaParaImagen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(AyudaParaImagen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new AyudaParaImagen().setVisible(true); } }); }
From source file:com.francetelecom.rd.dashboard.pc.DashboardPC.java
/** * Launch the application./*www .ja v a 2s. c o m*/ */ public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { logger.info("Application close, will unpublish node!"); myNode.unPublishFromHomeBus(); } catch (HomeBusException e) { logger.error("Application close, could not unpublish node : " + e.getMessage()); e.printStackTrace(); } } }); EventQueue.invokeLater(new Runnable() { public void run() { try { DashboardPC frame = new DashboardPC(); String nodeId = frame.getIdForType(ID_type_Node); frame.busFactory = new HomeBusFactory(nodeId); try { // temporary solution // fake solution // must remove this sleep after sds will no longer need it Thread.sleep(1000); } catch (Exception e) { logger.error("Error while sleep before node publish! \n" + e.getMessage()); } frame.initNode(nodeId); frame.initDashboardWithRules(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:com.bluemarsh.jswat.console.Main.java
/** * Kicks off the application./* ww w.jav a 2 s .co m*/ * * @param args the command line arguments. */ public static void main(String[] args) { // // An attempt was made early on to use the Console class in java.io, // but that is not designed to handle asynchronous output from // multiple threads, so we just use the usual System.out for output // and System.in for input. Note that automatic flushing is used to // ensure output is shown in a timely fashion. // // // Where console mode seems to work: // - bash // - emacs // // Where console mode does not seem to work: // - NetBeans: output from event listeners is never shown and the // cursor sometimes lags behind the output // // Turn on flushing so printing the prompt will flush // all buffered output generated from other threads. PrintWriter output = new PrintWriter(System.out, true); // Make sure we have the JPDA classes. try { Bootstrap.virtualMachineManager(); } catch (NoClassDefFoundError ncdfe) { output.println(NbBundle.getMessage(Main.class, "MSG_Main_NoJPDA")); System.exit(1); } // Ensure we can create the user directory by requesting the // platform service. Simply asking for it has the desired effect. PlatformProvider.getPlatformService(); // Define the logging configuration. LogManager manager = LogManager.getLogManager(); InputStream is = Main.class.getResourceAsStream("logging.properties"); try { manager.readConfiguration(is); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(1); } // Print out some useful debugging information. logSystemDetails(); // Add a shutdown hook to make sure we exit cleanly. Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { // Save the command aliases. CommandParser parser = CommandProvider.getCommandParser(); parser.saveSettings(); // Save the runtimes to persistent storage. RuntimeManager rm = RuntimeProvider.getRuntimeManager(); rm.saveRuntimes(); // Save the sessions to persistent storage and have them // close down in preparation to exit. SessionManager sm = SessionProvider.getSessionManager(); sm.saveSessions(true); } })); // Initialize the command parser and load the aliases. CommandParser parser = CommandProvider.getCommandParser(); parser.loadSettings(); parser.setOutput(output); // Create an OutputAdapter to display debuggee output. OutputAdapter adapter = new OutputAdapter(output); SessionManager sessionMgr = SessionProvider.getSessionManager(); sessionMgr.addSessionManagerListener(adapter); // Create a SessionWatcher to monitor the session status. SessionWatcher swatcher = new SessionWatcher(); sessionMgr.addSessionManagerListener(swatcher); // Create a BreakpointWatcher to monitor the breakpoints. BreakpointWatcher bwatcher = new BreakpointWatcher(); sessionMgr.addSessionManagerListener(bwatcher); // Add the watchers and adapters to the open sessions. Iterator<Session> iter = sessionMgr.iterateSessions(); while (iter.hasNext()) { Session s = iter.next(); s.addSessionListener(adapter); s.addSessionListener(swatcher); } // Find and run the RC file. try { runStartupFile(parser, output); } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); } // Process command line arguments. try { processArguments(args); } catch (ParseException pe) { // Report the problem and keep going. System.err.println("Option parsing failed: " + pe.getMessage()); logger.log(Level.SEVERE, null, pe); } // Display a helpful greeting. output.println(NbBundle.getMessage(Main.class, "MSG_Main_Welcome")); if (jdbEmulationMode) { output.println(NbBundle.getMessage(Main.class, "MSG_Main_Jdb_Emulation")); } // Enter the main loop of processing user input. BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); while (true) { // Keep the prompt format identical to jdb for compatibility // with emacs and other possible wrappers. output.print("> "); output.flush(); try { String command = input.readLine(); // A null value indicates end of stream. if (command != null) { performCommand(output, parser, command); } // Sleep briefly to give the event processing threads, // and the automatic output flushing, a chance to catch // up before printing the input prompt again. Thread.sleep(250); } catch (InterruptedException ie) { logger.log(Level.WARNING, null, ie); } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); output.println(NbBundle.getMessage(Main.class, "ERR_Main_IOError", ioe)); } catch (Exception x) { // Don't ever let an internal bug (e.g. in the command parser) // hork the console, as it really irritates people. logger.log(Level.SEVERE, null, x); output.println(NbBundle.getMessage(Main.class, "ERR_Main_Exception", x)); } } }
From source file:com.loy.MicroServiceConsole.java
public static void main(String[] args) throws SQLException { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override// w ww . j a va2s. com public void run() { killProcess(); } })); String[] arg = { "-tcp", "-tcpAllowOthers" }; Server server = Server.createTcpServer(arg); server.start(); init(); }
From source file:lookandfeel.SynthDialog.java
public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { try { //Set the look and feel. initLookAndFeel();/* ww w. j a va 2 s . c o m*/ //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); } catch (Exception ex) { ex.printStackTrace(); } new SynthDialog().setVisible(true); } }); }
From source file:gtu._work.ui.DirectoryCompareUI.java
/** * Auto-generated main method to display this JFrame *//*from www .j a va 2 s. c om*/ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { DirectoryCompareUI inst = new DirectoryCompareUI(); inst.setLocationRelativeTo(null); gtu.swing.util.JFrameUtil.setVisible(true, inst); } }); System.out.println("done..."); }
From source file:edu.mit.fss.examples.ISSFederate.java
/** * The main method. This configures the Orekit data path, creates the * ISS federate objects and launches the associated graphical user * interface.//from w w w. ja v a2s .c om * * @param args the arguments * @throws RTIexception the RTI exception * @throws URISyntaxException */ public static void main(String[] args) throws RTIexception, URISyntaxException { BasicConfigurator.configure(); boolean headless = false; logger.debug("Setting Orekit data path."); System.setProperty(DataProvidersManager.OREKIT_DATA_PATH, new File(ISSFederate.class.getResource("/orekit-data.zip").toURI()).getAbsolutePath()); logger.trace("Creating federate instance."); final ISSFederate federate = new ISSFederate(); logger.trace("Setting minimum step duration and time step."); long timeStep = 60 * 1000, minimumStepDuration = 100; federate.setMinimumStepDuration(minimumStepDuration); federate.setTimeStep(timeStep); try { logger.debug("Loading TLE data from file."); BufferedReader br = new BufferedReader(new InputStreamReader( federate.getClass().getClassLoader().getResourceAsStream("edu/mit/fss/examples/data.tle"))); final SpaceSystem satellite; final SurfaceSystem station1, station2, station3; while (br.ready()) { if (br.readLine().matches(".*ISS.*")) { logger.debug("Found ISS data."); logger.trace("Adding FSS supplier space system."); satellite = new SpaceSystem("FSS Supplier", new TLE(br.readLine(), br.readLine()), 5123e3); federate.addObject(satellite); logger.trace("Adding Keio ground station."); station1 = new SurfaceSystem("Keio", new GeodeticPoint(FastMath.toRadians(35.551929), FastMath.toRadians(139.647119), 300), satellite.getState().getDate(), 5123e3, 5); federate.addObject(station1); logger.trace("Adding SkolTech ground station."); station2 = new SurfaceSystem("SkolTech", new GeodeticPoint(FastMath.toRadians(55.698679), FastMath.toRadians(37.571994), 200), satellite.getState().getDate(), 5123e3, 5); federate.addObject(station2); logger.trace("Adding MIT ground station."); station3 = new SurfaceSystem("MIT", new GeodeticPoint(FastMath.toRadians(42.360184), FastMath.toRadians(-71.093742), 100), satellite.getState().getDate(), 5123e3, 5); federate.addObject(station3); try { logger.trace("Setting inital time."); federate.setInitialTime( satellite.getInitialState().getDate().toDate(TimeScalesFactory.getUTC()).getTime()); } catch (IllegalArgumentException | OrekitException e) { logger.error(e.getMessage()); e.printStackTrace(); } if (!headless) { logger.debug("Launching the graphical user interface."); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { MemberFrame frame = new MemberFrame(federate, new MultiComponentPanel( Arrays.asList(new SpaceSystemPanel(federate, satellite), new SurfaceSystemPanel(federate, station1), new SurfaceSystemPanel(federate, station2), new SurfaceSystemPanel(federate, station3)))); frame.pack(); frame.setVisible(true); } }); } break; } } br.close(); } catch (InvocationTargetException | InterruptedException | OrekitException | IOException e) { e.printStackTrace(); logger.fatal(e); } logger.trace("Setting federate name, type, and FOM path."); federate.getConnection().setFederateName("ISS"); federate.getConnection().setFederateType("FSS Supplier"); federate.getConnection().setFederationName("FSS"); federate.getConnection().setFomPath( new File(federate.getClass().getClassLoader().getResource("edu/mit/fss/hla/fss.xml").toURI()) .getAbsolutePath()); federate.getConnection().setOfflineMode(false); federate.connect(); if (headless) { federate.setMinimumStepDuration(10); federate.initialize(); federate.run(); } }
From source file:layout.FlowLayoutDemo.java
public static void main(String[] args) { /* Use an appropriate Look and Feel */ try {/*w w w. j a v a 2 s . c o m*/ //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } /* Turn off metal's use of bold fonts */ UIManager.put("swing.boldMetal", Boolean.FALSE); //Schedule a job for the event dispatchi thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); }
From source file:awskinesis.AmazonKinesisApplicationSample.java
public static void main(String[] args) throws Exception { init();//from w w w . j av a 2s . co m if (args.length == 1 && "delete-resources".equals(args[0])) { deleteResources(); return; } String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID(); KinesisClientLibConfiguration kinesisClientLibConfiguration = new KinesisClientLibConfiguration( SAMPLE_APPLICATION_NAME, SAMPLE_APPLICATION_STREAM_NAME, credentialsProvider, workerId) .withRegionName("cn-north-1"); kinesisClientLibConfiguration.withInitialPositionInStream(SAMPLE_APPLICATION_INITIAL_POSITION_IN_STREAM); IRecordProcessorFactory recordProcessorFactory = new AmazonKinesisApplicationRecordProcessorFactory(); final Worker worker = new Worker(recordProcessorFactory, kinesisClientLibConfiguration); System.out.printf("Running %s to process stream %s as worker %s...\n", SAMPLE_APPLICATION_NAME, SAMPLE_APPLICATION_STREAM_NAME, workerId); int exitCode = 0; try { worker.run(); } catch (Throwable t) { System.err.println("Caught throwable while processing data."); t.printStackTrace(); exitCode = 1; } // add a shutdown hook to stop the server Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { LOG.info("########### shoutdown begin...."); worker.shutdown(); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } LOG.info("########### shoutdown end...."); } })); System.exit(exitCode); }