Example #1
0
    @Override
    public void run() {
      final File gifFile =
          new File(FileUtils.getCapturePath(), System.currentTimeMillis() + ".gif");
      gifFilePath = gifFile.getAbsolutePath();
      try {
        if (!gifFile.exists()) {
          gifFile.createNewFile();
        }
        gifcodec gifCodec = new gifcodec();
        gifCodec.init(gifFilePath, targetWidth, targetHeight, 0);

        long ts = 0;
        while (true) {
          log(" encodeQueue size =" + captureQueue.size());
          if ((count >= 5 || stop) && captureQueue.isEmpty()) {
            break;
          }
          //                    if (gifFile.length() + getFrameSize() > maxFileSize) {
          //                        log("reach maxFileSize ,exit.");
          //                        reachMaxFileSize();
          //                        break;
          //                    }
          try {
            log(" GifEncodeThread try to take ByteBuffer from encodeQueue");
            Frame frame = captureQueue.take();
            log(" GifEncodeThread encode ");

            count++;
            gifCodec.encode(
                frame.getBuffer(),
                frame.getWidth(),
                frame.getHeight(),
                frame.getRowStride(),
                frame.getTs(),
                0);

            frame.setBuffer(null);
            //                        Thread.sleep(100);
          } catch (InterruptedException e) {
            // e.printStackTrace();
          }
        }
        // finishEncode();
        // callback

        if (gifCodec.release() == 0) {
          gifCodec.seteof(targetWidth, targetHeight, ts, 0);
          //                    sendResult(Status.OK, gifFilePath);
          log("================== GifEncodeThread encode success====================");
        } else {
          //                    sendResult(Status.ENCODE_FAILED, null);
          log("================== GifEncodeThread encode failed====================");
        }

      } catch (Exception e) {
        //
      }
    }
  public static void main(String s[]) {
    initParams(s);
    initAdapters();
    f = new Frame();
    final int[] modifiers = {InputEvent.SHIFT_MASK, InputEvent.CTRL_MASK};
    final String[] modifierNames = {"InputEvent.SHIFT_MASK", "InputEvent.CTRL_MASK"};
    f.setLayout(new FlowLayout());
    f.addMouseWheelListener(
        new MouseWheelListener() {
          public void mouseWheelMoved(MouseWheelEvent e) {
            System.out.println("WHEEL " + e);
          }
        });
    f.setSize(300, 300);
    f.setVisible(true);

    try {
      robot = new Robot();
      robot.delay(500);
      robot.mouseMove(
          f.getLocationOnScreen().x + f.getWidth() / 2,
          f.getLocationOnScreen().y + f.getHeight() / 2);
      if (autorun) {
        // testing buttons 1, 2, 3 only
        testPlainButtons();
        robot.delay(500);

        // testing buttons 1, 2, 3 with SHIFT, CTRL, ALT keyboard modifiers
        testButtonsWithShift();
        robot.delay(500);

        testButtonsWithControl();
        robot.delay(500);

        testButtonsWithAlt();
        robot.delay(500);
      } else {
        switch (testModifier) {
          case SHIFT:
            f.addMouseListener(adapterTest2);
            break;
          case CTRL:
            f.addMouseListener(adapterTest3);
            break;
          case ALT:
            f.addMouseListener(adapterTest4);
            break;
          default: // NONE inclusive
            f.addMouseListener(adapterTest1);
        }
      }
    } catch (Exception e) {
      throw new RuntimeException("Test failed.");
    }
  }