Example #1
0
 /**
  * 「終了」イベントです。
  *
  * @param e イベント情報
  * @throws Exception 処理例外
  */
 protected void exitActionPerformed(ActionEvent e) throws Exception {
   // 終了
   if (ACMessageBox.showOkCancel("終了しますか?") != ACMessageBox.RESULT_OK) {
     return;
   }
   System.exit(0);
 }
Example #2
0
  /**
   * 「比較」イベントです。
   *
   * @param e イベント情報
   * @throws Exception 処理例外
   */
  protected void compareActionPerformed(ActionEvent e) throws Exception {
    // 比較

    if (!new File(getPdf1().getText()).exists()) {
      ACMessageBox.showExclamation("PDF1が見つかりません。");
      return;
    }
    if (!new File(getPdf2().getText()).exists()) {
      ACMessageBox.showExclamation("PDF2が見つかりません。");
      return;
    }

    final PdfReader p1 = new PdfReader(getPdf1().getText());
    final PdfReader p2 = new PdfReader(getPdf2().getText());
    final int pages1 = p1.getNumberOfPages();
    final int pages2 = p2.getNumberOfPages();

    if (pages1 != pages2) {
      if (pages1 > pages2) {
        ACMessageBox.showExclamation("PDF1よりもPDF2のページ数が少ないです。");
        return;
      }
      if (ACMessageBox.showOkCancel(
              "PDFのページ数が異なります。" + ACConstants.LINE_SEPARATOR + "PDF1のすべてのページがPDF2に含まれるかで比較しますか?")
          != ACMessageBox.RESULT_OK) {
        return;
      }
    }

    new Runnable() {
      private boolean firstLock;

      public void run() {
        final int stopKeyCode = KeyEvent.VK_CAPS_LOCK;
        firstLock = Toolkit.getDefaultToolkit().getLockingKeyState(stopKeyCode);

        LinkedList<Integer> pages = new LinkedList<Integer>();
        for (int i = 1; i <= pages2; i++) {
          pages.add(new Integer(i));
        }

        errorCount = 0;
        pageOfProcessed = 0;
        pageOfCount = pages1;
        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= pages1; i++) {
          try {
            boolean match = false;
            byte[] b1 = p1.getPageContent(i);
            Iterator<Integer> it = pages.iterator();
            while (it.hasNext()) {
              int page = ((Integer) it.next()).intValue();
              byte[] b2 = p2.getPageContent(page);
              if (Arrays.equals(b1, b2)) {
                sb.append("○PDF1(" + i + ") = PDF2(" + page + ")" + ACConstants.LINE_SEPARATOR);
                match = true;
                it.remove();
                break;
              }
            }
            if (!match) {
              sb.append("×PDF1(" + i + ") 【一致なし】" + ACConstants.LINE_SEPARATOR);
              errorCount++;
            }
          } catch (Exception ex) {
            sb.append("※PDF1(" + i + ") 【処理例外】" + ACConstants.LINE_SEPARATOR);
            errorCount++;
          }

          setProgress(sb);
          pageOfProcessed = i;

          if (Toolkit.getDefaultToolkit().getLockingKeyState(stopKeyCode) != firstLock) {
            getResult()
                .setText(
                    "!比較中断("
                        + pageOfProcessed
                        + " / "
                        + pageOfCount
                        + ") / 不一致数:"
                        + errorCount
                        + " 件"
                        + ACConstants.LINE_SEPARATOR
                        + sb.toString());
            return;
          }
        }

        getResult()
            .setText(
                "■比較完了("
                    + pageOfProcessed
                    + " / "
                    + pageOfCount
                    + ") / 不一致数:"
                    + errorCount
                    + " 件"
                    + ACConstants.LINE_SEPARATOR
                    + sb.toString());
      }
    }.run();
  }