/** ***************** Main to run the game ****************** */ public static void main(String[] args) { // Use EDT, was running into exceptions before so I added this SwingUtilities.invokeLater( new Runnable() { @Override public void run() { new TicTac(); } }); }
public static void main(String[] args) { try { // non-throwing message printer Kdu_sysout_message sysout = new Kdu_sysout_message(false); // exception-throwing message printer Kdu_sysout_message syserr = new Kdu_sysout_message(true); // non-throwing formatted printer Kdu_message_formatter formattedSysout = new Kdu_message_formatter(sysout); // throwing formatted printer Kdu_message_formatter formattedSyserr = new Kdu_message_formatter(syserr); Kdu_global.Kdu_customize_warnings(formattedSysout); Kdu_global.Kdu_customize_errors(formattedSyserr); } catch (KduException e) { System.err.printf("Exception during Kdu stream tie: %s\n", e.getMessage()); } if (args.length != 1) { System.err.println("You must supply a filename (JP2, JPX or raw code-stream)"); System.exit(0); } final String filename = args[0]; SwingUtilities.invokeLater( new Runnable() { public void run() { Haikdu app = new Haikdu(filename); } }); }
public static void main(String[] args) { // args = new String[]{"nothing=junk"}; RSF par = new RSF(args); // RSFFrame sf = new RSFFrame(); // // // // ArrayList<String> cubes = new ArrayList<String>(); ArrayList<String> points = new ArrayList<String>(); ArrayList<String> lines = new ArrayList<String>(); for (String arg : args) { if (arg.contains("cube")) { String cube = par.getString(arg.split("=")[0], ""); System.err.printf("Found cube: %s\n", cube); cubes.add(cube); } else if (arg.contains("point")) { String point = par.getString(arg.split("=")[0], ""); System.err.printf("Found point: %s\n", point); points.add(point); } else if (arg.contains("line")) { String line = par.getString(arg.split("=")[0], ""); System.err.printf("Found line: %s\n", line); lines.add(line); } } final String[] cubeNames = new String[cubes.size()]; for (int i = 0; i < cubes.size(); ++i) { cubeNames[i] = cubes.get(i); } final String[] lineNames = new String[lines.size()]; for (int i = 0; i < lines.size(); ++i) { lineNames[i] = lines.get(i); } final String[] pointNames = new String[points.size()]; for (int i = 0; i < points.size(); ++i) { pointNames[i] = points.get(i); } SwingUtilities.invokeLater( new Runnable() { public void run() { RSFFrame frame = new RSFFrame(); for (String name : cubeNames) { frame.addRSFCube(name); } for (String name : lineNames) { frame.addRSFLine(name); } for (String name : pointNames) { frame.addRSFPoint(name); } } }); }
void rotationFinished() { SwingUtilities.invokeLater( new Runnable() { public void run() { animationPanel = null; listener.animationFinished(); listener = null; } }); }
public static void main(String[] args) { // read arguments and respond correctly File in; File out; String tileDirectory; if (args.length == 0 || args.length > 2) { in = null; out = null; tileDirectory = ""; System.err.println("Incorrect number of arguments. Required: Filename (tileset path)"); System.exit(0); } else if (args.length == 1) { // load old file in = new File(args[0]); out = in; Scanner s = null; try { s = new Scanner(in); } catch (FileNotFoundException e) { System.out.println("Could not find input file."); System.exit(0); } tileDirectory = s.nextLine(); } else { in = null; out = new File(args[0]); tileDirectory = args[1]; try { File f = new File(tileDirectory); if (!f.isDirectory()) { throw new IOException("Tileset does not exist"); } } catch (IOException e) { System.err.println(e); System.out.println("This error is likely thanks to an invalid tileset path"); System.exit(0); } } MapBuilder test = new MapBuilder("Map Editor", in, out, tileDirectory); // Build GUI SwingUtilities.invokeLater( new Runnable() { public void run() { test.CreateAndDisplayGUI(); } }); }
/** simply dump status info to the textarea */ private void sout(final String s) { Runnable soutRunner = new Runnable() { public void run() { if (ttaStatus.getText().equals("")) { ttaStatus.setText(s); } else { ttaStatus.setText(ttaStatus.getText() + "\n" + s); } } }; if (ThreadUtils.isInEDT()) { soutRunner.run(); } else { SwingUtilities.invokeLater(soutRunner); } }
public void end() { final int[] selected = table.getSelectedRows(); model.clear(rows.size()); Iterator i = rows.iterator(); while (i.hasNext()) { model.addEntry((Map) i.next()); } rows.clear(); if (SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater( new Runnable() { public void run() { model.fireListeners(); fixSelection(selected); } }); } else { model.fireListeners(); fixSelection(selected); } }
public void fadeOut() { super.setVisible(true); try { final float desacel = 0.1f; while (BlurGlass.this.getAlpha() - desacel >= 0.0f) { SwingUtilities.invokeLater( new Runnable() { public void run() { BlurGlass.this.setAlpha(BlurGlass.this.getAlpha() - desacel); } }); Thread.sleep(50); } BlurGlass.this.setAlpha(0.0f); } catch (Exception e) { Dialogos.error("Error en fadeout", e); } // super.setVisible(false); // BlurGlass.this.setAlpha(0.2f); // setAlpha(0.2f); super.setVisible(false); }
protected void importImagery() { try { // Read the data and save it in a temp file. File sourceFile = ExampleUtil.saveResourceToTempFile(IMAGE_PATH, ".tif"); // Create a raster reader to read this type of file. The reader is created from the // currently // configured factory. The factory class is specified in the Configuration, and a different // one can be // specified there. DataRasterReaderFactory readerFactory = (DataRasterReaderFactory) WorldWind.createConfigurationComponent(AVKey.DATA_RASTER_READER_FACTORY_CLASS_NAME); DataRasterReader reader = readerFactory.findReaderFor(sourceFile, null); // Before reading the raster, verify that the file contains imagery. AVList metadata = reader.readMetadata(sourceFile, null); if (metadata == null || !AVKey.IMAGE.equals(metadata.getStringValue(AVKey.PIXEL_FORMAT))) throw new Exception("Not an image file."); // Read the file into the raster. read() returns potentially several rasters if there are // multiple // files, but in this case there is only one so just use the first element of the returned // array. DataRaster[] rasters = reader.read(sourceFile, null); if (rasters == null || rasters.length == 0) throw new Exception("Can't read the image file."); DataRaster raster = rasters[0]; // Determine the sector covered by the image. This information is in the GeoTIFF file or // auxiliary // files associated with the image file. final Sector sector = (Sector) raster.getValue(AVKey.SECTOR); if (sector == null) throw new Exception("No location specified with image."); // Request a sub-raster that contains the whole image. This step is necessary because only // sub-rasters // are reprojected (if necessary); primary rasters are not. int width = raster.getWidth(); int height = raster.getHeight(); // getSubRaster() returns a sub-raster of the size specified by width and height for the // area indicated // by a sector. The width, height and sector need not be the full width, height and sector // of the data, // but we use the full values of those here because we know the full size isn't huge. If it // were huge // it would be best to get only sub-regions as needed or install it as a tiled image layer // rather than // merely import it. DataRaster subRaster = raster.getSubRaster(width, height, sector, null); // Tne primary raster can be disposed now that we have a sub-raster. Disposal won't affect // the // sub-raster. raster.dispose(); // Verify that the sub-raster can create a BufferedImage, then create one. if (!(subRaster instanceof BufferedImageRaster)) throw new Exception("Cannot get BufferedImage."); BufferedImage image = ((BufferedImageRaster) subRaster).getBufferedImage(); // The sub-raster can now be disposed. Disposal won't affect the BufferedImage. subRaster.dispose(); // Create a SurfaceImage to display the image over the specified sector. final SurfaceImage si1 = new SurfaceImage(image, sector); // On the event-dispatch thread, add the imported data as an SurfaceImageLayer. SwingUtilities.invokeLater( new Runnable() { public void run() { // Add the SurfaceImage to a layer. SurfaceImageLayer layer = new SurfaceImageLayer(); layer.setName("Imported Surface Image"); layer.setPickEnabled(false); layer.addRenderable(si1); // Add the layer to the model and update the application's layer panel. insertBeforeCompass(AppFrame.this.getWwd(), layer); AppFrame.this.getLayerPanel().update(AppFrame.this.getWwd()); // Set the view to look at the imported image. ExampleUtil.goTo(getWwd(), sector); } }); } catch (Exception e) { e.printStackTrace(); } }
// Thread's run method aimed at creating a bitmap asynchronously public void run() { Drawing drawing = new Drawing(); PicText rawPicText = new PicText(); String s = ((PicText) element).getText(); rawPicText.setText(s); drawing.add( rawPicText); // bug fix: we must add a CLONE of the PicText, otherwise it loses it former // parent... (then pb with the view ) drawing.setNotparsedCommands( "\\newlength{\\jpicwidth}\\settowidth{\\jpicwidth}{" + s + "}" + CR_LF + "\\newlength{\\jpicheight}\\settoheight{\\jpicheight}{" + s + "}" + CR_LF + "\\newlength{\\jpicdepth}\\settodepth{\\jpicdepth}{" + s + "}" + CR_LF + "\\typeout{JPICEDT INFO: \\the\\jpicwidth, \\the\\jpicheight, \\the\\jpicdepth }" + CR_LF); RunExternalCommand.Command commandToRun = RunExternalCommand.Command.BITMAP_CREATION; // RunExternalCommand command = new RunExternalCommand(drawing, contentType,commandToRun); boolean isWriteTmpTeXfile = true; String bitmapExt = "png"; // [pending] preferences String cmdLine = "{i}/unix/tetex/create_bitmap.sh {p} {f} " + bitmapExt + " " + fileDPI; // [pending] preferences ContentType contentType = getContainer().getContentType(); RunExternalCommand.isGUI = false; // System.out, no dialog box // [pending] debug RunExternalCommand command = new RunExternalCommand(drawing, contentType, cmdLine, isWriteTmpTeXfile); command .run(); // synchronous in an async. thread => it's ok (anyway, we must way until the LaTeX // process has completed) if (wantToComputeLatexDimensions) { // load size of text: try { File logFile = new File(command.getTmpPath(), command.getTmpFilePrefix() + ".log"); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(logFile)); } catch (FileNotFoundException fnfe) { System.out.println("Cannot find log file! " + fnfe.getMessage()); System.out.println(logFile); } catch (IOException ioex) { System.out.println("Log file IO exception"); ioex.printStackTrace(); } // utile ? System.out.println("Log file created! file=" + logFile); getDimensionsFromLogFile(reader, (PicText) element); syncStringLocation(); // update dimensions syncBounds(); syncFrame(); SwingUtilities.invokeLater( new Thread() { public void run() { repaint(null); } }); // repaint(null); // now that dimensions are available, we force a repaint() [pending] // smart-repaint ? } catch (Exception e) { e.printStackTrace(); } } if (wantToGetBitMap) { // load image: try { File bitmapFile = new File(command.getTmpPath(), command.getTmpFilePrefix() + "." + bitmapExt); this.image = ImageIO.read(bitmapFile); System.out.println( "Bitmap created! file=" + bitmapFile + ", width=" + image.getWidth() + "pixels, height=" + image.getHeight() + "pixels"); if (image == null) return; syncStringLocation(); // sets strx, stry, and dimensions of text syncBounds(); // update the AffineTransform that will be applied to the bitmap before displaying on screen PicText te = (PicText) element; text2ModelTr.setToIdentity(); // reset PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf); text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR ! text2ModelTr.translate(te.getLeftX(), te.getTopY()); text2ModelTr.scale( te.getWidth() / image.getWidth(), -(te.getHeight() + te.getDepth()) / image.getHeight()); // [pending] should do something special to avoid dividing by 0 or setting a rescaling // factor to 0 [non invertible matrix] (java will throw an exception) syncFrame(); SwingUtilities.invokeLater( new Thread() { public void run() { repaint(null); } }); // repaint(null); // now that bitmap is available, we force a repaint() [pending] // smart-repaint ? } catch (Exception e) { e.printStackTrace(); } } }