public void beginDraw() {
    //    long t0 = System.currentTimeMillis();

    if (document == null) {
      document = new Document(new Rectangle(width, height));
      try {
        if (file != null) {
          // BufferedOutputStream output = new BufferedOutputStream(stream, 16384);
          output = new BufferedOutputStream(new FileOutputStream(file), 16384);

        } else if (output == null) {
          throw new RuntimeException(
              "PGraphicsPDF requires a path " + "for the location of the output file.");
        }
        writer = PdfWriter.getInstance(document, output);
        document.open();
        content = writer.getDirectContent();
        //        template = content.createTemplate(width, height);

      } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Problem saving the PDF file.");
      }

      //      System.out.println("beginDraw fonts " + (System.currentTimeMillis() - t));
      g2 = content.createGraphics(width, height, getMapper());
      //      g2 = template.createGraphics(width, height, mapper);
    }
    //    System.out.println("beginDraw " + (System.currentTimeMillis() - t0));
    super.beginDraw();
  }
  public void dispose() {
    if (readyForFrames) finish();

    try {
      QTSession.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #3
0
 public void pre() {
   if (serialAvailableMethod != null && invokeSerialAvailable) {
     invokeSerialAvailable = false;
     try {
       serialAvailableMethod.invoke(parent, this);
     } catch (Exception e) {
       System.err.println("Error, disabling serialAvailable() for " + port.getPortName());
       System.err.println(e.getLocalizedMessage());
       serialAvailableMethod = null;
     }
   }
 }
  public void preIntroSetup() {
    try {

      int bgWidth = env.bgImg.getWidth(env);
      int bgHeight = env.bgImg.getHeight(env);
      int[] bgPixels = new int[bgWidth * bgHeight];
      for (int i = 0; i < bgPixels.length; i++) if (bgPixels[i] != 0) System.out.print(bgPixels[i]);
      overlay = new PImage(bgWidth, bgHeight);
      overlay.format = ARGB;
      overlay.pixels = bgPixels;
      runNum = 0;
      controls.setEnabled(false);

      /** * get into looping */
      afterFirstStreaming = true;
      /** overview shut */
      draw();
      /*theCamera.moveToNow(new FVector(0.0f, 0.0f, 1000));
      theCamera.lookAtNow(new FVector(0.0f, 1.0f, 0));
      */
      draw();
      ortho(-1500, 800, -800, 800, 1000, 2000);
      loadPixels();
      noStroke();
      getOverviewShut();
      afterOverviewShot = true;
      draw();
      loop();

      /** give the environment the hint to swop the surfaces */
      env.addThem();
      /** * intro */
      theCamera.moveToNow(new FVector(-200.0f, 950.0f, 1000));
      theCamera.lookAtNow(new FVector(-200.51917f, 851.8057f, 0));
      theCamera.lookAtInter(
          new FVector(1341.8213f, 757.865f, 0), new Integer(4000), new Integer(3));
      Object[] actionObjects = {new FVector(0, 0, -88), new Integer(2000), new Integer(0)};
      theCamera.queueAction("lookAtInter", 4000, actionObjects);
      theCamera.moveToNow(new FVector(-500.51917f, 951.8057f, 200));
      theCamera.moveToInter(
          new FVector(1341.8213f, 857.865f, 200), new Integer(4000), new Integer(3));
      Object[] actionObjects2 = {
        new FVector(0, 800, Camera.maxCameraHeight), new Integer(2000), new Integer(1)
      };
      theCamera.queueAction("moveToInter", 0, actionObjects2);
      Object[] actionObjects3 = {Boolean.valueOf(true)};
      theCamera.queueAction("setControlsEnabled", 3500, actionObjects3);
    } catch (Exception e) {
      e.printStackTrace();
      env.setErrorDisplay(
          "Das Applet konnte nicht gestartet werden. Eventuell ist dies ein Speicherproblem. Bitte stoppen sie alle anderen Java-Anwendungen. GGf. muss der Browser neu gestartet werden um den Cache zu leeren.");
    }
  }
Beispiel #5
0
 public static Library load(File folder) {
   try {
     return new Library(folder);
     //    } catch (IgnorableException ig) {
     //      Base.log(ig.getMessage());
   } catch (Error err) {
     // Handles UnsupportedClassVersionError and others
     err.printStackTrace();
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   return null;
 }
Beispiel #6
0
 /**
  * @generate serialEvent.xml
  * @webref serial:events
  * @usage web_application
  * @param event the port where new data is available
  */
 public void serialEvent(SerialPortEvent event) {
   if (event.getEventType() == SerialPortEvent.RXCHAR) {
     int toRead;
     try {
       while (0 < (toRead = port.getInputBufferBytesCount())) {
         // this method can be called from the context of another thread
         synchronized (buffer) {
           // read one byte at a time if the sketch is using serialEvent
           if (serialEventMethod != null) {
             toRead = 1;
           }
           // enlarge buffer if necessary
           if (buffer.length < inBuffer + toRead) {
             byte temp[] = new byte[buffer.length << 1];
             System.arraycopy(buffer, 0, temp, 0, inBuffer);
             buffer = temp;
           }
           // read an array of bytes and copy it into our buffer
           byte[] read = port.readBytes(toRead);
           System.arraycopy(read, 0, buffer, inBuffer, read.length);
           inBuffer += read.length;
         }
         if (serialEventMethod != null) {
           if ((0 < bufferUntilSize && bufferUntilSize <= inBuffer - readOffset)
               || (0 == bufferUntilSize && bufferUntilByte == buffer[inBuffer - 1])) {
             try {
               // serialEvent() is invoked in the context of the current (serial) thread
               // which means that serialization and atomic variables need to be used to
               // guarantee reliable operation (and better not draw() etc..)
               // serialAvailable() does not provide any real benefits over using
               // available() and read() inside draw - but this function has no
               // thread-safety issues since it's being invoked during pre in the context
               // of the Processing applet
               serialEventMethod.invoke(parent, this);
             } catch (Exception e) {
               System.err.println("Error, disabling serialEvent() for " + port.getPortName());
               System.err.println(e.getLocalizedMessage());
               serialEventMethod = null;
             }
           }
         }
         invokeSerialAvailable = true;
       }
     } catch (SerialPortException e) {
       throw new RuntimeException(
           "Error reading from serial port " + e.getPortName() + ": " + e.getExceptionType());
     }
   }
 }
Beispiel #7
0
 public int getNextByte() {
   int byteToReturn = -1;
   try {
     byteToReturn = fileArray[fileIndex];
     if (byteToReturn != 0) {
       byteToReturn = byteToReturn & 0xff;
     }
     fileIndex++;
   } catch (Exception e) {
     System.out.println("Problem with getNextByte()");
     e.printStackTrace();
     fileIndex = 0;
   }
   return byteToReturn;
 }
Beispiel #8
0
  public void run() {
    while (Thread.currentThread() == thread) {
      try {
        Socket socket = server.accept();
        Client client = new Client(parent, socket);

        if (clientValidationMethod != null) {
          try {
            clientValidationMethod.invoke(parent, new Object[] {this, client});
          } catch (Exception e) {
            // System.err.println("Disabling serverEvent() for port " + port);
            e.printStackTrace();
          }
        }

        if (client.active()) {
          synchronized (clients) {
            addClient(client);
            if (serverEventMethod != null) {
              try {
                serverEventMethod.invoke(parent, new Object[] {this, client});
              } catch (Exception e) {
                // System.err.println("Disabling serverEvent() for port " + port);
                e.printStackTrace();
              }
            }
          }
        }
      } catch (SocketException e) {
        // thrown when server.close() is called and server is waiting on accept
        System.err.println("Server SocketException: " + e.getMessage());
        thread = null;
      } catch (IOException e) {
        // errorMessage("run", e);
        e.printStackTrace();
        thread = null;
      }
      try {
        Thread.sleep(8);
      } catch (InterruptedException ex) {
      }
    }
  }
  /** Call to explicitly go to the next page from within a single draw(). */
  public void nextPage() {
    PStyle savedStyle = getStyle();
    g2.dispose();

    try {
      //    writer.setPageEmpty(false);  // maybe useful later
      document.newPage(); // is this bad if no addl pages are made?
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (textMode == SHAPE) {
      g2 = content.createGraphicsShapes(width, height);
    } else if (textMode == MODEL) {
      g2 = content.createGraphics(width, height, mapper);
    }
    style(savedStyle);

    // should there be a beginDraw/endDraw in here?
  }
Beispiel #10
0
  /** Ignore. */
  public void run() {

    try {

      while (running) {

        if (!pachubePOSTurl.equals("") && localSensorsAdded) {
          try {
            updateLocalSensors(dOut);
            int response = dOut.updatePachube();
            if (response != 200) {
              System.out.println("There was an error posting: " + response);
              if (response == 401) {
                System.out.println(
                    "Incorrect API key, or you are trying to update a feed that does not belong to you.");
              } else if (response == 404) {
                System.out.println("The Pachube feed you are trying to update does not exist.");
              }
            } else {

              System.out.print("Pachube updated with local sensor values: ");

              for (int i = 0; i < totalLocalSensors; i++) {
                System.out.print(localSensor[i].value + "\t");
              }
              System.out.println();
            }
          } catch (Exception e) {
            System.err.println("Problem running DataOut...");
            e.printStackTrace();
            postThread = null;
          }
        }

        try {
          sleep(POST_RATE);
        } catch (Exception e) {
          System.err.println("DataOut: There was a problem sleeping.");
          e.printStackTrace();
        }
      }

    } catch (Exception e) {
      System.err.println("DataOut: There was a problem running.");
      e.printStackTrace();
    }
  }
  // Goes online to get user authentication from Flickr.
  public void getAuthentication() {
    AuthInterface authInterface = flickr.getAuthInterface();

    try {
      frob = authInterface.getFrob();
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      URL authURL = authInterface.buildAuthenticationUrl(Permission.WRITE, frob);

      // open the authentication URL in a browser
      open(authURL.toExternalForm());
    } catch (Exception e) {
      e.printStackTrace();
    }

    println("You have 15 seconds to approve the app!");
    int startedWaiting = millis();
    int waitDuration = 15 * 1000; // wait 10 seconds
    while ((millis() - startedWaiting) < waitDuration) {
      // just wait
    }
    println("Done waiting");

    try {
      auth = authInterface.getToken(frob);
      println("Authentication success");
      // This token can be used until the user revokes it.
      token = auth.getToken();
      // save it for future use
      saveToken(token);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // complete authentication
    authenticateWithToken(token);
  }
Beispiel #12
0
  /**
   * Move through a list of stack frames, searching for references to code found in the current
   * sketch. Return with a RunnerException that contains the location of the error, or if nothing is
   * found, just return with a RunnerException that wraps the error message itself.
   */
  protected SketchException findException(
      String message, ObjectReference or, ThreadReference thread) {
    try {
      // use to dump the stack for debugging
      //      for (StackFrame frame : thread.frames()) {
      //        System.out.println("frame: " + frame);
      //      }

      List<StackFrame> frames = thread.frames();
      for (StackFrame frame : frames) {
        try {
          Location location = frame.location();
          String filename = null;
          filename = location.sourceName();
          int lineNumber = location.lineNumber() - 1;
          SketchException rex = build.placeException(message, filename, lineNumber);
          if (rex != null) {
            return rex;
          }
        } catch (AbsentInformationException e) {
          // Any of the thread.blah() methods can throw an AbsentInformationEx
          // if that bit of data is missing. If so, just write out the error
          // message to the console.
          // e.printStackTrace();  // not useful
          exception = new SketchException(message);
          exception.hideStackTrace();
          listener.statusError(exception);
        }
      }
    } catch (IncompatibleThreadStateException e) {
      // This shouldn't happen, but if it does, print the exception in case
      // it's something that needs to be debugged separately.
      e.printStackTrace();
    }
    // before giving up, try to extract from the throwable object itself
    // since sometimes exceptions are re-thrown from a different context
    try {
      // assume object reference is Throwable, get stack trace
      Method method =
          ((ClassType) or.referenceType())
              .concreteMethodByName("getStackTrace", "()[Ljava/lang/StackTraceElement;");
      ArrayReference result =
          (ArrayReference)
              or.invokeMethod(
                  thread, method, new ArrayList<Value>(), ObjectReference.INVOKE_SINGLE_THREADED);
      // iterate through stack frames and pull filename and line number for each
      for (Value val : result.getValues()) {
        ObjectReference ref = (ObjectReference) val;
        method =
            ((ClassType) ref.referenceType())
                .concreteMethodByName("getFileName", "()Ljava/lang/String;");
        StringReference strref =
            (StringReference)
                ref.invokeMethod(
                    thread, method, new ArrayList<Value>(), ObjectReference.INVOKE_SINGLE_THREADED);
        String filename = strref == null ? "Unknown Source" : strref.value();
        method = ((ClassType) ref.referenceType()).concreteMethodByName("getLineNumber", "()I");
        IntegerValue intval =
            (IntegerValue)
                ref.invokeMethod(
                    thread, method, new ArrayList<Value>(), ObjectReference.INVOKE_SINGLE_THREADED);
        int lineNumber = intval.intValue() - 1;
        SketchException rex = build.placeException(message, filename, lineNumber);
        if (rex != null) {
          return rex;
        }
      }
      //      for (Method m : ((ClassType) or.referenceType()).allMethods()) {
      //        System.out.println(m + " | " + m.signature() + " | " + m.genericSignature());
      //      }
      // Implemented for 2.0b9, writes a stack trace when there's an internal error inside core.
      method = ((ClassType) or.referenceType()).concreteMethodByName("printStackTrace", "()V");
      //      System.err.println("got method " + method);
      or.invokeMethod(
          thread, method, new ArrayList<Value>(), ObjectReference.INVOKE_SINGLE_THREADED);

    } catch (Exception e) {
      e.printStackTrace();
    }
    // Give up, nothing found inside the pile of stack frames
    SketchException rex = new SketchException(message);
    // exception is being created /here/, so stack trace is not useful
    rex.hideStackTrace();
    return rex;
  }
  // xively\u304b\u3089\u306e\u30c7\u30fc\u30bf\u53d6\u5f97
  // \u73fe\u5728\u306e\u65e5\u4ed8\u304b\u30892\u65e5\u3055\u304b\u306e\u307c\u3063\u305f\u65e5\u4ed8\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97
  public String[] getDataFromXively(String URL, String MY_KEY) {

    // \u73fe\u5728\u306e\u65e5\u4ed8\u3092\u53d6\u5f97
    Calendar cal = Calendar.getInstance();
    // \u6307\u5b9a\u3057\u305f\u65e5\u6570\u3092\u52a0\u7b97
    cal.add(Calendar.DATE, -10);

    // \u57fa\u6e96\u65e5(\u73fe\u5728\u3088\u308a7\u65e5\u524d\u306e\u65e5\u4ed8\u3092\u57fa\u6e96\u65e5\u3068\u3057\u3066\u3044\u308b)\u3088\u308a\u5f8c\u306e\u65e5\u4ed8\u306b\u306a\u3063\u305f\u5834\u5408\u306f\u521d\u671f\u5316
    Calendar before1 = Calendar.getInstance();
    before1.add(Calendar.DATE, -1);
    int result = cal.compareTo(before1);
    if (result > 0) {
      cal = Calendar.getInstance();
      cal.add(Calendar.DATE, -2);
    }
    // \u6307\u5b9a\u3057\u305f\u65e5\u4ed8\u3092Data\u578b\u3067\u53d6\u5f97
    Date theDate = cal.getTime();
    println("data: " + theDate);

    // \u6307\u5b9a\u3057\u305f\u65e5\u4ed8\u3092ISO
    // 8601(UTC)\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u6587\u5b57\u5217\u5316
    SimpleDateFormat dateFormat = getDateFormat_ISO8601();
    String startDate = dateFormat.format(theDate);
    println("format: " + startDate);

    // \u623b\u308a\u5024\u7528\u914d\u5217
    String[] retlines = new String[0];
    String[] dataLines = new String[0];

    // \u6587\u5b57\u5217\u683c\u7d0d\u7528\u306e\u52d5\u7684\u914d\u5217
    ArrayList<String> strList = new ArrayList<String>();

    // xively\u3078\u306eURL\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u4f5c\u6210
    // String strDuration = "&duration=1days&interval=300";  //
    // 300\u79d2\u9593\u9694\u30671\u65e5\u5206\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97
    // String URL_REQUEST = URL + "?start=" + startDate + strDuration + "&limit=450" + "?key=" +
    // MY_KEY;
    String strDuration =
        "&duration=6hours&interval=0"; // 1\u79d2\u9593\u9694\u30671\u65e5\u5206\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97
    String URL_REQUEST =
        URL + "?start=" + startDate + strDuration + "&limit=450" + "?key=" + MY_KEY;

    println(URL_REQUEST);

    // xively\u304b\u3089\u306e\u30c7\u30fc\u30bf\u53d6\u5f97(\u53d6\u5f97\u3067\u304d\u306a\u3044\u5834\u5408\u306f\u4f55\u3082\u3057\u306a\u3044)
    try {
      // xivly\u304b\u3089\u306e\u30c7\u30fc\u30bf\u3092\u4e00\u6642\u7684\u306b\u683c\u7d0d
      dataLines = loadStrings(URL_REQUEST);
    } catch (Exception e) {
      // \u53d6\u5f97\u3067\u304d\u306a\u3044\u5834\u5408
      e.printStackTrace();
      dataLines = null;
    }

    // \u53d6\u5f97\u3067\u304d\u306a\u3044\u5834\u5408
    if (dataLines == null) {
      background(60);
      text("error!", width / 2, height / 2);
      dataLines = new String[0];
      strList.clear();
    }

    // xivly\u304b\u3089\u306e\u30c7\u30fc\u30bf\u3092\u52d5\u7684\u914d\u5217\u306b\u8ffd\u52a0
    for (int i = 0; i < dataLines.length; i++) {
      strList.add(dataLines[i]);
    }

    // \u623b\u308a\u5024\u7528\u914d\u5217\u3078\u30c7\u30fc\u30bf\u3092\u30b3\u30d4\u30fc
    retlines = new String[strList.size()];
    for (int i = 0; i < strList.size(); i++) {
      retlines[i] = strList.get(i);
    }

    return retlines;
  }
Beispiel #14
0
  // runs the thread. this is the thread's loop
  public void run() {
    // do this as long as the thread is running
    while (running) {
      try {
        // read bytes in from the serial port, and get a dataArray back:
        /*
         New in 1.4: checks to see if the port has been initialized.
        If not, assumes it's to read from a file and tries to do so.
        */
        if (port != null) {
          dataArray = getPacket();
        } else {
          if (bytesAvailable() > 0) {
            dataArray = getPacket(fileArray);
          } else {
            running = false;
          }
        }

        if (dataArray != null) {
          dataFrame = new XBeeDataFrame(dataArray);

          switch (dataFrame.apiId) {
            case ZNET_IOPACKET:
              // process a ZNet IO packet
              dataFrame.parseZNetFrame();
              break;
            case SERIES1_RX16PACKET:
              dataFrame.parseXBeeRX16Frame();
              // process a series 1 packet
              break;
            case SERIES1_IOPACKET:
              dataFrame.parseXBeeIOFrame();
              // process a series 1 packet
              break;
          }
        }
        // when we have a dataArray, set available = true:
        available = true;

        // not being used at the moment, since XBeeEvent is not getting triggered:
        // if we have a valid data frame, generate an event:
        if (xBeeMethod != null && dataArray != null) {
          // generate an XBeeEvent:
          try {
            xBeeMethod.invoke(parent, new Object[] {this});
          } catch (Exception e) {
            System.out.println("Problem with XBeeEvent()");
            e.printStackTrace();
            xBeeMethod = null;
          }
        }

        // gives the main sketch back the processor
        try {
          sleep(sleepRate); // Should we sleep?
        } catch (Exception e) {
          // Nothing for now. We'll get here if interrupt() is called
        }
      } catch (Exception e) {
        System.out.println("Exception in XBeeReader.run():");
        e.printStackTrace();
      }
    }
    running = false;
    fileEmpty = true;
  }