Пример #1
0
    public void run() {
      try {
        while (scriptRunning) {
          if (!parent.isPaused() && parent.game.isLoggedIn() && status != "Logging back in") {
            int rand = randomGenerator.nextInt(30);
            switch (rand) {
              case 1:
                parent.camera.setAngle(Methods.random(0, 360));
                break;
              case 2:
                parent.camera.setPitch(Methods.random(40, 100));
                break;
              case 3:
                parent.mouse.setSpeed(Methods.random(5, 9));
                break;
              case 5:
                parent.camera.setPitch(Methods.random(40, 100));
                parent.camera.setAngle(Methods.random(0, 360));
                break;
              default:
                break;
            }
          }

          sleep(Methods.random(2000, 5000));
        }
      } catch (InterruptedException e) {
        log(e.getMessage());
      }
    }
Пример #2
0
    private void decompressTile(final File outputFile, int jp2TileX, int jp2TileY)
        throws IOException {
      final int tileIndex = bandInfo.imageLayout.numXTiles * jp2TileY + jp2TileX;
      final Process process =
          new ProcessBuilder(
                  EXE,
                  "-i",
                  imageFile.getPath(),
                  "-o",
                  outputFile.getPath(),
                  "-r",
                  getLevel() + "",
                  "-t",
                  tileIndex + "")
              .directory(cacheDir)
              .start();

      try {
        final int exitCode = process.waitFor();
        if (exitCode != 0) {
          System.err.println("Failed to uncompress tile: exitCode = " + exitCode);
        }
      } catch (InterruptedException e) {
        System.err.println("InterruptedException: " + e.getMessage());
      }
    }
  /** Initialise. */
  public synchronized void initialise() {

    // wait until application is properly initialised
    while (applicationService == null) {
      // idle in this thread
      try {
        this.wait(6000);
      } catch (InterruptedException e) {
        logger.warn("e.getMessage() = " + e.getMessage());
      }

      if (applicationService != null && applicationService.getErrorLoggerService() != null) {
        this.applicationService.getErrorLoggerService().registerListener(this);
      }
    }

    // set LNF first to avoid component UI errors
    LookAndFeelUtils.setDefaultLNF();

    errorPane = new JXErrorPane();
    errorPane.setPreferredSize(new Dimension(400, 300));
    errorPane.setIcon(ImageUtils.getIcon(ImageUtils.IconName.WARNING_ICON_48));
    errorPane.setErrorReporter(this);
    errorDialog = JXErrorPane.createDialog(null, errorPane);
    errorDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    errorDialog.pack();
  }
Пример #4
0
  @Override
  public void run() {

    try {
      if (Fecs.getApplicationContext() == null) return;

      Long currentTime = System.currentTimeMillis();
      double deltaTime = (currentTime - lastUpdateTime) * 0.001;

      if (getEngineState() == STATE_START) { // last bit is 1 = started
        int s = getCircumstanceState() - 1; // 0 is null state(error)
        if (s >= CircumstanceType.values().length || s < 0)
          throw new Exception("unstable state value with " + String.valueOf(s));
        Circumstance.get(CircumstanceType.values()[s])
            .setParameter("currentTime", currentTime)
            .setParameter("deltaTime", deltaTime)
            .trigger();
        for (Cabin cabin : cabins.values()) updateCabin(cabin, deltaTime);
      }

      lastUpdateTime = currentTime;

      draw();
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    } finally {
      try {
        Thread.sleep(1);
      } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
      }
      SwingUtilities.invokeLater(this);
    }
  }
Пример #5
0
 // Other public methods
 @Override
 public void run() {
   while (clockThread != null) {
     repaint();
     try {
       clockThread.sleep(1000);
     } catch (InterruptedException e) {
       System.out.println(e.getMessage());
     }
   }
 }
Пример #6
0
 public void run() {
   while (run) {
     try {
       sleep(DOTS_DELAY);
     } catch (InterruptedException e) {
       logger.warn("InterruptedException,  " + e.getMessage());
     }
     messageLabel.setText(DOTS[dotIndex] + message + DOTS[dotIndex]);
     dotIndex = (dotIndex + 1) % DOTS.length;
   }
 }
Пример #7
0
  private static void openURL_old(String url) throws IOException {
    switch (jvm) {
      case MAC:
        Runtime.getRuntime().exec(new String[] {"/usr/bin/open", url});
        break;

      case WINDOWS:
        Process process = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
        // This avoids a memory leak on some versions of Java on Windows.
        // That's hinted at in
        // <http://developer.java.sun.com/developer/qow/archive/68/>.
        try {
          process.waitFor();
          process.exitValue();
        } catch (InterruptedException ie) {
          throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
        }
        break;
      case OTHER:
        if (new File("/usr/bin/gnome-open").exists()) {
          Runtime.getRuntime().exec(new String[] {"/usr/bin/gnome-open", url});
        } else if (new File("/usr/bin/kde-open").exists()) {
          Runtime.getRuntime().exec(new String[] {"/usr/bin/kde-open", url});
        }

        break;
      case SPECIFIED:
        process = Runtime.getRuntime().exec(new String[] {specifiedBrowser, url});
        try {
          process.waitFor();
          process.exitValue();
        } catch (InterruptedException ie) {
          throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
        }
        break;
    }
  }
  protected String executeScriptWithResult(final String script) {
    if (script.length() == 0) return null;

    final boolean pollingCallback = !script.contains("getCallbacks");
    final Object[] result = new Object[1];
    if (!SwingUtilities.isEventDispatchThread()) {
      try {
        SwingUtilities.invokeAndWait(
            new Runnable() {
              public void run() {
                webBrowser.runInSequence(
                    new Runnable() {
                      public void run() {
                        result[0] = webBrowser.executeJavascriptWithResult(script);
                        if (debug && pollingCallback) {
                          log.info("After invokeLater, executeJavascriptWithResult " + result[0]);
                        }
                      }
                    });
              }
            });
      } catch (InterruptedException e) {
        log.severe("Cannot execute script with result: " + e.getMessage());
      } catch (InvocationTargetException e) {
        log.severe("Cannot execute script with result: " + e.getMessage());
      }
    } else {
      webBrowser.runInSequence(
          new Runnable() {
            public void run() {
              result[0] = webBrowser.executeJavascriptWithResult(script);
              if (debug && pollingCallback) {
                log.info("After executeJavascriptWithResult " + result[0]);
              }
            }
          });
    }

    if (pollingCallback) {
      logJavaScript(script, result[0]);
    }
    return result[0] != null ? result[0].toString() : null;
  }
Пример #9
0
  public void setActivo(boolean val) {
    glass.setVisible(val);
    setVisible(val);
    JLayeredPane.getLayeredPaneAbove(glass).moveToFront(glass);

    if (val) {
      synchronized (syncMonitor) {
        try {
          if (SwingUtilities.isEventDispatchThread()) {
            EventQueue theQueue = getToolkit().getSystemEventQueue();
            while (isVisible()) {
              AWTEvent event = theQueue.getNextEvent();
              Object source = event.getSource();

              if (event instanceof ActiveEvent) {
                ((ActiveEvent) event).dispatch();
              } else if (source instanceof Component) {
                ((Component) source).dispatchEvent(event);
              } else if (source instanceof MenuComponent) {
                ((MenuComponent) source).dispatchEvent(event);
              } else {
                System.out.println("No se puede despachar: " + event);
              }
            }
          } else {
            while (isVisible()) {
              syncMonitor.wait();
            }
          }
        } catch (InterruptedException ignored) {
          System.out.println("Excepción de interrupción: " + ignored.getMessage());
        }
      }
    } else {
      synchronized (syncMonitor) {
        setVisible(false);
        glass.setVisible(false);
        syncMonitor.notifyAll();

        eliminarDelContenedor();
      }
    }
  }
Пример #10
0
  private static BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
      return (BufferedImage) image;

    } else {
      MediaTracker tracker = new MediaTracker(null /*not sure how this is used*/);
      tracker.addImage(image, 0);
      try {
        tracker.waitForAll();
      } catch (InterruptedException e) {
        throw new IOException(e.getMessage());
      }
      BufferedImage bufImage =
          new BufferedImage(
              image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);

      Graphics g = bufImage.createGraphics();
      g.drawImage(image, 0, 0, null);
      return bufImage;
    }
  }
Пример #11
0
  public void run() {
    /**
     * /////test part//// mPoint testp1 = new mPoint(1,1,3,0.5f); mPoint testp2 = new
     * mPoint(70,50,20,0.5f); // mMath.LinearInterpolation(testp1,testp2); //
     * System.out.println(testp1.x+" \n"+testp2.x);
     *
     * <p>canvas.drawLine(testp1,testp2);
     *
     * <p>// mPoint3 p[] = {new mPoint3(1,2,3),new mPoint3(2,1,3),new mPoint3(3,4,5)}; mPoint p[] =
     * {new mPoint(70,1,3,1),new mPoint(1,40,3,1),new mPoint(70,60,5,1)}; canvas.fillTriangle(p);
     */

    /**
     * --the way to create objects in a world mOject obj = new mObject(...); mWorld w = new
     * mWorld(); w.add(obj); --draw it mCamera cam = new mCamera(...); cam.capture(w); //cam will
     * refresh the bufferedImage own.repaint(); //will refresh the window with bufferedImage
     */
    mCube cube = new mCube(new mPoint3(0, 90, -80), 100, 100, 100);
    //	mCube cube2 = new mCube(new mPoint3(-300,300,0),500,500,500);
    mCone cone = new mCone(new mPoint3(0, 50, 0), 80, 200);
    mObject obj = new mObject();
    obj = createRandomSurface(obj, 0, 200, 60, 260);
    /*obj.shape = new mShape();
    obj.pos=new mPoint3(50,0,0);
    mPoint3[] points={
    	obj.pos,
    	new mPoint3(50,50,0),
    	new mPoint3(100,0,0),
    	new mPoint3(100,50,0)
    };
    short[][] tripoints = {
    		{0,0},
    		{3,2},
    		{1,3}
    };
    short[][] linepoints = new short[2][0];
    obj.center = new mVector3(0,0,0);
    obj.shape.set(points,linepoints,tripoints);
    obj.refer = new mReferenceTransformation(new mPoint3(obj.pos,obj.center),
    		new mVector3(0,1,0),
    		new mVector3(1,0,0));*/
    mGrid grid = new mGrid(100);

    mWorld w = new mWorld();
    w.add(cube);
    //	w.add(cube2);
    w.add(grid);
    w.add(cone);
    w.add(obj);

    mCamera cam = new mCamera(canvas);

    cam.capture(w);
    own.repaint(speed);

    /*
    CoordinateTransformation.test();

    mTriangle tri = new mTriangle(p);
    /*
    for(int i=0;i<20;i++){
    	cube.rotate((float)Math.PI/40,(float)Math.PI/40,(float)Math.PI/40);
    	cube.move(new mVector3(0,5,0));
    try{
    	this.sleep(90);
    	}catch(InterruptedException e){
    		System.err.println(e.getMessage());
    	}
    	canvas.clear();
    	cam.capture(w);
    	own.repaint();
    }//*/

    for (int i = 0; i < 10; i++) {
      cube.rotate(0, (float) Math.PI / 20, (float) Math.PI / 20); // (float)Math.PI/20);
      cube.move(new mVector3(10, 0, 10));
      try {
        this.sleep(speed);
      } catch (InterruptedException e) {
        System.err.println(e.getMessage());
      }
      canvas.clear();
      cam.capture(w);
      own.repaint(speed); // timeout = 60
    } // */
    for (int i = 0; i < 20; i++) {
      cube.rotate((float) Math.PI / 40, 0, (float) Math.PI / 40); // (float)Math.PI/20);
      cube.move(new mVector3(-10, -5, 0));
      try {
        this.sleep(speed);
      } catch (InterruptedException e) {
        System.err.println(e.getMessage());
      }
      canvas.clear();
      cam.capture(w);
      own.repaint(speed);
    } // */
    //	int time = 0;
    while (true) {
      cam.rotate((float) Math.PI / 30, 0, 0);
      //	time++;
      //	float move = 30*(float)Math.sin((float)time/5);
      //	cam.move(new mVector3(move,move,move));
      try {
        this.sleep(speed);
      } catch (InterruptedException e) {
        System.err.println(e.getMessage());
      }
      canvas.clear();
      cam.capture(w);
      own.repaint(speed);
    } // */
  }