Пример #1
1
  /**
   * Loads the drawing. By convention this method is invoked on a worker thread.
   *
   * @param progress A ProgressIndicator to inform the user about the progress of the operation.
   * @return The Drawing that was loaded.
   */
  protected Drawing loadDrawing(ProgressIndicator progress) throws IOException {
    Drawing drawing = createDrawing();
    if (getParameter("datafile") != null) {
      URL url = new URL(getDocumentBase(), getParameter("datafile"));
      URLConnection uc = url.openConnection();

      // Disable caching. This ensures that we always request the
      // newest version of the drawing from the server.
      // (Note: The server still needs to set the proper HTTP caching
      // properties to prevent proxies from caching the drawing).
      if (uc instanceof HttpURLConnection) {
        ((HttpURLConnection) uc).setUseCaches(false);
      }

      // Read the data into a buffer
      int contentLength = uc.getContentLength();
      InputStream in = uc.getInputStream();
      try {
        if (contentLength != -1) {
          in = new BoundedRangeInputStream(in);
          ((BoundedRangeInputStream) in).setMaximum(contentLength + 1);
          progress.setProgressModel((BoundedRangeModel) in);
          progress.setIndeterminate(false);
        }
        BufferedInputStream bin = new BufferedInputStream(in);
        bin.mark(512);

        // Read the data using all supported input formats
        // until we succeed
        IOException formatException = null;
        for (InputFormat format : drawing.getInputFormats()) {
          try {
            bin.reset();
          } catch (IOException e) {
            uc = url.openConnection();
            in = uc.getInputStream();
            in = new BoundedRangeInputStream(in);
            ((BoundedRangeInputStream) in).setMaximum(contentLength + 1);
            progress.setProgressModel((BoundedRangeModel) in);
            bin = new BufferedInputStream(in);
            bin.mark(512);
          }
          try {
            bin.reset();
            format.read(bin, drawing, true);
            formatException = null;
            break;
          } catch (IOException e) {
            formatException = e;
          }
        }
        if (formatException != null) {
          throw formatException;
        }
      } finally {
        in.close();
      }
    }
    return drawing;
  }
  public static void main(String args[]) throws IOException {
    LoaderOptions options = LoaderOptions.parseArgs(args);
    try {
      SSTableLoader loader =
          new SSTableLoader(options.directory, new ExternalClient(options), options);
      SSTableLoader.LoaderFuture future = loader.stream(options.ignores);

      if (options.noProgress) {
        future.get();
      } else {
        ProgressIndicator indicator = new ProgressIndicator(future.getPendingFiles());
        indicator.start();
        System.out.println("");
        while (!future.isDone()) {
          if (indicator.printProgress()) {
            // We're done with streaming
            System.out.println("\nWaiting for targets to rebuild indexes ...");
            future.get();
            assert future.isDone();
          } else {
            try {
              Thread.sleep(1000L);
            } catch (Exception e) {
            }
          }
        }
      }

      System.exit(0); // We need that to stop non daemonized threads
    } catch (Exception e) {
      System.err.println(e.getMessage());
      if (options.debug) e.printStackTrace(System.err);
      System.exit(1);
    }
  }
Пример #3
0
 /**
  * Allow to update the progress status of the current component loading process. As the instance
  * of TPTLazyLoader is passed to your LazyLoader implementation, you may update the progress from
  * there.
  *
  * @param progress new progress. Must be specified from 0.0 to 1.0, which reflects 0% ... 100%
  *     interval. If set to 0.0, a progress indicator will be swithced to indeterminate mode,
  *     displaying an endless wheel.
  */
 public void setLoadingProgress(float progress) {
   if (progress == 0.0f) {
     progressBar.setIndeterminate(true);
   } else {
     progressBar.setIndeterminate(false);
     progressBar.setValue(progress);
   }
 }
Пример #4
0
 protected void initUI() {
   setSizeFull();
   errorLabel.setWidth(null);
   loadingLabel.setWidth(null);
   progressBar.setIndeterminate(true);
   progressBar.setPollingInterval(500);
   progressBar.setWidth("50%");
   progressBar.setImmediate(true);
 }
  private void onPaymentReceived(ActionEvent actionEvent) {
    log.debug("onPaymentReceived");
    confirmFiatReceivedButton.setDisable(true);
    statusLabel.setText("Sending message to trading peer...");
    statusProgressIndicator.setVisible(true);
    statusProgressIndicator.setProgress(-1);
    root = statusProgressIndicator.getScene().getRoot();
    // We deactivate mouse interaction to avoid that user leaves screen
    root.setMouseTransparent(true);

    model.fiatPaymentReceived();
  }
  /**
   * We assume that the initial indexing has been done and a set of reference objects has been found
   * and indexed in the separate directory. However further documents were added and they now need
   * to get a ranked list of reference objects. So we (i) get all these new documents missing the
   * field "ro-order" and (ii) add this field.
   *
   * @param indexPath the index to update
   * @throws IOException
   */
  public void updateIndex(String indexPath) throws IOException {
    IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexPath)));
    int numDocs = reader.numDocs();
    boolean hasDeletions = reader.hasDeletions();
    int countUpdated = 0;

    IndexReader readerRo = DirectoryReader.open(FSDirectory.open(new File(indexPath + "-ro")));
    ImageSearcher searcher =
        new GenericImageSearcher(numReferenceObjectsUsed, featureClass, featureFieldName);
    Map<String, Analyzer> perField = new HashMap<String, Analyzer>(1);
    perField.put("ro-order", new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION));
    PerFieldAnalyzerWrapper aWrapper =
        new PerFieldAnalyzerWrapper(new SimpleAnalyzer(LuceneUtils.LUCENE_VERSION), perField);

    IndexWriter iw =
        new IndexWriter(
            FSDirectory.open(new File(indexPath)),
            new IndexWriterConfig(LuceneUtils.LUCENE_VERSION, aWrapper)
                .setOpenMode(IndexWriterConfig.OpenMode.CREATE));
    StringBuilder sb = new StringBuilder(256);
    // Needed for check whether the document is deleted.
    Bits liveDocs = MultiFields.getLiveDocs(reader);

    for (int i = 0; i < numDocs; i++) {
      if (reader.hasDeletions() && !liveDocs.get(i)) continue; // if it is deleted, just ignore it.
      Document document = reader.document(i);
      if (document.getField("ro-order") == null) { // if the field is not here we create it.
        ImageSearchHits hits = searcher.search(document, readerRo);
        sb.delete(0, sb.length());
        for (int j = 0; j < numReferenceObjectsUsed; j++) {
          sb.append(hits.doc(j).getValues("ro-id")[0]);
          sb.append(' ');
        }
        // System.out.println(sb.toString());
        document.add(new TextField("ro-order", sb.toString(), Field.Store.YES));
        iw.updateDocument(
            new Term(
                DocumentBuilder.FIELD_NAME_IDENTIFIER,
                document.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]),
            document);
        countUpdated++;
      }

      // progress report
      progress.setNumDocsProcessed(progress.getNumDocsProcessed() + 1);

      // debug:
      System.out.println("countUpdated = " + countUpdated);
    }
    iw.commit();
    iw.close();
  }
Пример #7
0
    private void doRun() {
      myIndicator = ProgressManager.getInstance().getProgressIndicator();

      final List<Change> changesToRefresh = new ArrayList<Change>();
      try {
        ChangesUtil.processChangesByVcs(
            myProject,
            myChanges,
            new ChangesUtil.PerVcsProcessor<Change>() {
              public void process(AbstractVcs vcs, List<Change> changes) {
                final RollbackEnvironment environment = vcs.getRollbackEnvironment();
                if (environment != null) {
                  changesToRefresh.addAll(changes);

                  if (myIndicator != null) {
                    myIndicator.setText(vcs.getDisplayName() + ": performing rollback...");
                    myIndicator.setIndeterminate(false);
                    myIndicator.checkCanceled();
                  }
                  environment.rollbackChanges(
                      changes,
                      myExceptions,
                      new RollbackProgressModifier(changes.size(), myIndicator));
                  if (myIndicator != null) {
                    myIndicator.setText2("");
                    myIndicator.checkCanceled();
                  }

                  if (myExceptions.isEmpty() && myDeleteLocallyAddedFiles) {
                    deleteAddedFilesLocally(changes);
                  }
                }
              }
            });
      } catch (ProcessCanceledException e) {
        // still do refresh
      }

      if (myIndicator != null) {
        myIndicator.startNonCancelableSection();
        myIndicator.setIndeterminate(true);
        myIndicator.setText2("");
        myIndicator.setText(VcsBundle.message("progress.text.synchronizing.files"));
      }

      doRefresh(myProject, changesToRefresh);

      AbstractVcsHelper.getInstance(myProject)
          .showErrors(myExceptions, VcsBundle.message("changes.action.rollback.text"));
    }
Пример #8
0
  private void hideSendMsgInfo(Timer timer) {
    timer.stop();
    inputTextArea.setDisable(false);

    FxTimer.runLater(
        Duration.ofMillis(5000),
        () -> {
          sendMsgInfoLabel.setVisible(false);
          sendMsgInfoLabel.setManaged(false);
        });
    sendMsgProgressIndicator.setProgress(0);
    sendMsgProgressIndicator.setVisible(false);
    sendMsgProgressIndicator.setManaged(false);
  }
  private static void export(
      GeoSetExporter exporter, GeoSet geoSet, String filePath, ProgressIndicator progressIndicator)
      throws IOException {

    // export the GeoSet to the file
    if (progressIndicator != null) {
      exporter.setProgressIndicator(progressIndicator);
      progressIndicator.start();
    }
    exporter.export(geoSet, filePath);

    // FIXME this is an ugly hack !!! ???
    if (exporter instanceof TableLinkExporter) {

      TableLinkExporter tableLinkExporter = (TableLinkExporter) exporter;
      TableLink tableLink = null;

      if (geoSet instanceof GeoMap && ((GeoMap) geoSet).tableLinkGetNumber() > 0) {
        tableLink = ((GeoMap) geoSet).tableLinkGet(0); // !!! ???
      } else {
        ika.table.Table table = new ika.table.Table("US-ASCII");
        table.setName("table");
        table.addColumn("ID");
        final int rowCount = tableLinkExporter.getFeatureCount();
        for (int i = 0; i < rowCount; i++) {
          table.addRow(new Object[] {new Double(i)});
        }
        tableLink = new TableLink(table, geoSet);
      }
      tableLinkExporter.exportTableForGeometry(filePath, tableLink);
    }
  }
Пример #10
0
  private void onSendMessage(String inputText, Dispute dispute) {
    DisputeDirectMessage disputeDirectMessage =
        disputeManager.sendDisputeDirectMessage(
            dispute, inputText, new ArrayList<>(tempAttachments));
    tempAttachments.clear();
    scrollToBottom();

    inputTextArea.setDisable(true);
    inputTextArea.clear();

    final Timer timer =
        FxTimer.runLater(
            Duration.ofMillis(500),
            () -> {
              sendMsgInfoLabel.setVisible(true);
              sendMsgInfoLabel.setManaged(true);
              sendMsgInfoLabel.setText("Sending Message...");

              sendMsgProgressIndicator.setProgress(-1);
              sendMsgProgressIndicator.setVisible(true);
              sendMsgProgressIndicator.setManaged(true);
            });

    disputeDirectMessage
        .arrivedProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              if (newValue) {
                hideSendMsgInfo(timer);
              }
            });
    disputeDirectMessage
        .storedInMailboxProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              if (newValue) {
                sendMsgInfoLabel.setVisible(true);
                sendMsgInfoLabel.setManaged(true);
                sendMsgInfoLabel.setText(
                    "Receiver is not online. Message is saved to his mailbox.");
                hideSendMsgInfo(timer);
              }
            });
  }
    protected GeoSet doInBackground() throws Exception {
      try {

        progressIndicator.start();
        this.setProgress(0);
        GeoExportGUI.export(exporter, geoSet, filePath, progressIndicator);

        return null;

      } catch (Exception e) {

        e.printStackTrace();

        // this will be executed in the event dispatching thread.
        ika.utils.ErrorDialog.showErrorDialog("The file could not be exported.", e);
        throw e;
      } finally {
        progressIndicator.complete();
      }
    }
Пример #12
0
  public UploadUnit(
      String url,
      String dbName,
      String driver,
      String userName,
      String password,
      User user,
      TabSheet mainTabs,
      TabSheet subTabs) {
    this.user = user;
    this.mainTabs = mainTabs;
    this.subTabs = subTabs;

    eh = new ExperimentHandler(url, dbName, driver, userName, password);
    this.updateComponents(this.user);

    auth = new Authenticator(url, dbName, driver, userName, password);
    pi.setValue(0f);
    pi.setCaption("Loading...");
    pi.setVisible(false);
  }
Пример #13
0
 private void deleteAddedFilesLocally(final List<Change> changes) {
   if (myIndicator != null) {
     myIndicator.setText("Deleting added files locally...");
     myIndicator.setFraction(0);
   }
   final int changesSize = changes.size();
   for (int i = 0; i < changesSize; i++) {
     final Change c = changes.get(i);
     if (c.getType() == Change.Type.NEW) {
       ContentRevision rev = c.getAfterRevision();
       assert rev != null;
       final File ioFile = rev.getFile().getIOFile();
       if (myIndicator != null) {
         myIndicator.setText2(ioFile.getAbsolutePath());
         myIndicator.setFraction(((double) i) / changesSize);
       }
       FileUtil.delete(ioFile);
     }
   }
   if (myIndicator != null) {
     myIndicator.setText2("");
   }
 }
Пример #14
0
  public static Tuple3<Button, ProgressIndicator, Label> addButtonWithStatus(
      GridPane gridPane, int rowIndex, String buttonTitle, double top) {
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    Button button = new Button(buttonTitle);
    button.setDefaultButton(true);

    ProgressIndicator progressIndicator = new ProgressIndicator(0);
    progressIndicator.setPrefHeight(24);
    progressIndicator.setPrefWidth(24);
    progressIndicator.setVisible(false);

    Label label = new Label();
    label.setPadding(new Insets(5, 0, 0, 0));

    hBox.getChildren().addAll(button, progressIndicator, label);

    GridPane.setRowIndex(hBox, rowIndex);
    GridPane.setColumnIndex(hBox, 1);
    GridPane.setMargin(hBox, new Insets(top, 0, 0, 0));
    gridPane.getChildren().add(hBox);

    return new Tuple3<>(button, progressIndicator, label);
  }
  @FXML
  public void setPasswordClicked(ActionEvent event) {
    if (!pass1.getText().equals(pass2.getText())) {
      informationalAlert(tr("Passwords do not match"), tr("Try re-typing your chosen passwords."));
      return;
    }
    String password = pass1.getText();
    // This is kind of arbitrary and we could do much more to help people pick strong passwords.
    if (password.length() < 4) {
      informationalAlert(
          tr("Password too short"),
          tr("You need to pick a password at least five characters or longer."));
      return;
    }

    fadeIn(progressMeter);
    fadeOut(widgetGrid);
    fadeOut(explanationLabel);
    fadeOut(buttonHBox);

    KeyCrypterScrypt scrypt = new KeyCrypterScrypt(SCRYPT_PARAMETERS);

    // Deriving the actual key runs on a background thread. 500msec is empirical on my laptop
    // (actual val is more like 333 but we give padding time).
    KeyDerivationTasks tasks =
        new KeyDerivationTasks(scrypt, password, estimatedKeyDerivationTime) {
          @Override
          protected void onFinish(KeyParameter aesKey, int timeTakenMsec) {
            // Write the target time to the wallet so we can make the progress bar work when
            // entering the password.
            WalletPasswordController.setTargetTime(Duration.ofMillis(timeTakenMsec));
            // The actual encryption part doesn't take very long as most private keys are derived on
            // demand.
            log.info("Key derived, now encrypting");
            Main.bitcoin.wallet().encrypt(scrypt, aesKey);
            log.info("Encryption done");
            informationalAlert(
                tr("Wallet encrypted"),
                tr("You can remove the password at any time from the settings screen."));
            overlayUI.done();
          }
        };
    progressMeter.progressProperty().bind(tasks.progress);
    tasks.start();
  }
Пример #16
0
  public static void copyWithProgress(
      InputStream inputStream, OutputStream outputStream, ProgressIndicator indicator)
      throws IOException {

    int total = 0;
    int bytesAvailable = inputStream.available();
    int bufferSize = Math.min(bytesAvailable, MAX_BUFFER_SIZE);
    byte[] buffer = new byte[bufferSize];

    int bytesRead = inputStream.read(buffer, 0, bufferSize);
    while (bytesRead > 0) {
      outputStream.write(buffer, 0, bytesRead);
      total += bytesRead;

      if (indicator != null) {
        indicator.showProgress(total);
      }

      bytesAvailable = inputStream.available();
      bufferSize = Math.min(bytesAvailable, MAX_BUFFER_SIZE);
      bytesRead = inputStream.read(buffer, 0, bufferSize);
    }
  }
Пример #17
0
  private void onSelectDispute(Dispute dispute) {
    if (dispute == null) {
      if (root.getChildren().size() > 1) root.getChildren().remove(1);

      selectedDispute = null;
    } else if (selectedDispute != dispute) {
      this.selectedDispute = dispute;

      boolean isTrader = disputeManager.isTrader(dispute);

      TableGroupHeadline tableGroupHeadline = new TableGroupHeadline();
      tableGroupHeadline.setText("Messages");
      tableGroupHeadline.prefWidthProperty().bind(root.widthProperty());
      AnchorPane.setTopAnchor(tableGroupHeadline, 10d);
      AnchorPane.setRightAnchor(tableGroupHeadline, 0d);
      AnchorPane.setBottomAnchor(tableGroupHeadline, 0d);
      AnchorPane.setLeftAnchor(tableGroupHeadline, 0d);

      ObservableList<DisputeDirectMessage> list =
          dispute.getDisputeDirectMessagesAsObservableList();
      SortedList<DisputeDirectMessage> sortedList = new SortedList<>(list);
      sortedList.setComparator((o1, o2) -> o1.getDate().compareTo(o2.getDate()));
      list.addListener((ListChangeListener<DisputeDirectMessage>) c -> scrollToBottom());
      messageListView = new ListView<>(sortedList);
      messageListView.setId("message-list-view");
      messageListView.prefWidthProperty().bind(root.widthProperty());
      messageListView.setMinHeight(150);
      AnchorPane.setTopAnchor(messageListView, 30d);
      AnchorPane.setRightAnchor(messageListView, 0d);
      AnchorPane.setLeftAnchor(messageListView, 0d);

      messagesAnchorPane = new AnchorPane();
      messagesAnchorPane.prefWidthProperty().bind(root.widthProperty());
      VBox.setVgrow(messagesAnchorPane, Priority.ALWAYS);

      inputTextArea = new TextArea();
      inputTextArea.setPrefHeight(70);
      inputTextArea.setWrapText(true);

      Button sendButton = new Button("Send");
      sendButton.setDefaultButton(true);
      sendButton.setOnAction(e -> onSendMessage(inputTextArea.getText(), dispute));
      sendButton.setDisable(true);
      inputTextArea
          .textProperty()
          .addListener(
              (observable, oldValue, newValue) -> {
                sendButton.setDisable(
                    newValue.length() == 0
                        && tempAttachments.size() == 0
                        && dispute.disputeResultProperty().get() == null);
              });

      Button uploadButton = new Button("Add attachments");
      uploadButton.setOnAction(e -> onRequestUpload());

      sendMsgInfoLabel = new Label();
      sendMsgInfoLabel.setVisible(false);
      sendMsgInfoLabel.setManaged(false);
      sendMsgInfoLabel.setPadding(new Insets(5, 0, 0, 0));

      sendMsgProgressIndicator = new ProgressIndicator(0);
      sendMsgProgressIndicator.setPrefHeight(24);
      sendMsgProgressIndicator.setPrefWidth(24);
      sendMsgProgressIndicator.setVisible(false);
      sendMsgProgressIndicator.setManaged(false);

      dispute
          .isClosedProperty()
          .addListener(
              (observable, oldValue, newValue) -> {
                messagesInputBox.setVisible(!newValue);
                messagesInputBox.setManaged(!newValue);
                AnchorPane.setBottomAnchor(messageListView, newValue ? 0d : 120d);
              });
      if (!dispute.isClosed()) {
        HBox buttonBox = new HBox();
        buttonBox.setSpacing(10);
        buttonBox
            .getChildren()
            .addAll(sendButton, uploadButton, sendMsgProgressIndicator, sendMsgInfoLabel);

        if (!isTrader) {
          Button closeDisputeButton = new Button("Close ticket");
          closeDisputeButton.setOnAction(e -> onCloseDispute(dispute));
          closeDisputeButton.setDefaultButton(true);
          Pane spacer = new Pane();
          HBox.setHgrow(spacer, Priority.ALWAYS);
          buttonBox.getChildren().addAll(spacer, closeDisputeButton);
        }

        messagesInputBox = new VBox();
        messagesInputBox.setSpacing(10);
        messagesInputBox.getChildren().addAll(inputTextArea, buttonBox);
        VBox.setVgrow(buttonBox, Priority.ALWAYS);

        AnchorPane.setRightAnchor(messagesInputBox, 0d);
        AnchorPane.setBottomAnchor(messagesInputBox, 5d);
        AnchorPane.setLeftAnchor(messagesInputBox, 0d);

        AnchorPane.setBottomAnchor(messageListView, 120d);

        messagesAnchorPane
            .getChildren()
            .addAll(tableGroupHeadline, messageListView, messagesInputBox);
      } else {
        AnchorPane.setBottomAnchor(messageListView, 0d);
        messagesAnchorPane.getChildren().addAll(tableGroupHeadline, messageListView);
      }

      messageListView.setCellFactory(
          new Callback<ListView<DisputeDirectMessage>, ListCell<DisputeDirectMessage>>() {
            @Override
            public ListCell<DisputeDirectMessage> call(ListView<DisputeDirectMessage> list) {
              return new ListCell<DisputeDirectMessage>() {
                final Pane bg = new Pane();
                final ImageView arrow = new ImageView();
                final Label headerLabel = new Label();
                final Label messageLabel = new Label();
                final HBox attachmentsBox = new HBox();
                final AnchorPane messageAnchorPane = new AnchorPane();
                final Label statusIcon = new Label();
                final double arrowWidth = 15d;
                final double attachmentsBoxHeight = 20d;
                final double border = 10d;
                final double bottomBorder = 25d;
                final double padding = border + 10d;

                {
                  bg.setMinHeight(30);
                  messageLabel.setWrapText(true);
                  headerLabel.setTextAlignment(TextAlignment.CENTER);
                  attachmentsBox.setSpacing(5);
                  statusIcon.setStyle("-fx-font-size: 10;");
                  messageAnchorPane
                      .getChildren()
                      .addAll(bg, arrow, headerLabel, messageLabel, attachmentsBox, statusIcon);
                }

                @Override
                public void updateItem(final DisputeDirectMessage item, boolean empty) {
                  super.updateItem(item, empty);

                  if (item != null && !empty) {
                    /* messageAnchorPane.prefWidthProperty().bind(EasyBind.map(messageListView.widthProperty(),
                    w -> (double) w - padding - GUIUtil.getScrollbarWidth(messageListView)));*/
                    if (!messageAnchorPane.prefWidthProperty().isBound())
                      messageAnchorPane
                          .prefWidthProperty()
                          .bind(
                              messageListView
                                  .widthProperty()
                                  .subtract(padding + GUIUtil.getScrollbarWidth(messageListView)));

                    AnchorPane.setTopAnchor(bg, 15d);
                    AnchorPane.setBottomAnchor(bg, bottomBorder);
                    AnchorPane.setTopAnchor(headerLabel, 0d);
                    AnchorPane.setBottomAnchor(arrow, bottomBorder + 5d);
                    AnchorPane.setTopAnchor(messageLabel, 25d);
                    AnchorPane.setBottomAnchor(attachmentsBox, bottomBorder + 10);

                    boolean senderIsTrader = item.isSenderIsTrader();
                    boolean isMyMsg = isTrader ? senderIsTrader : !senderIsTrader;

                    arrow.setVisible(!item.isSystemMessage());
                    arrow.setManaged(!item.isSystemMessage());
                    statusIcon.setVisible(false);
                    if (item.isSystemMessage()) {
                      headerLabel.setStyle("-fx-text-fill: -bs-green; -fx-font-size: 11;");
                      bg.setId("message-bubble-green");
                      messageLabel.setStyle("-fx-text-fill: white;");
                    } else if (isMyMsg) {
                      headerLabel.setStyle("-fx-text-fill: -fx-accent; -fx-font-size: 11;");
                      bg.setId("message-bubble-blue");
                      messageLabel.setStyle("-fx-text-fill: white;");
                      if (isTrader) arrow.setId("bubble_arrow_blue_left");
                      else arrow.setId("bubble_arrow_blue_right");

                      sendMsgProgressIndicator
                          .progressProperty()
                          .addListener(
                              (observable, oldValue, newValue) -> {
                                if ((double) oldValue == -1 && (double) newValue == 0) {
                                  if (item.arrivedProperty().get()) showArrivedIcon();
                                  else if (item.storedInMailboxProperty().get()) showMailboxIcon();
                                }
                              });

                      if (item.arrivedProperty().get()) showArrivedIcon();
                      else if (item.storedInMailboxProperty().get()) showMailboxIcon();
                      // TODO show that icon on error
                      /*else if (sendMsgProgressIndicator.getProgress() == 0)
                      showNotArrivedIcon();*/
                    } else {
                      headerLabel.setStyle("-fx-text-fill: -bs-light-grey; -fx-font-size: 11;");
                      bg.setId("message-bubble-grey");
                      messageLabel.setStyle("-fx-text-fill: black;");
                      if (isTrader) arrow.setId("bubble_arrow_grey_right");
                      else arrow.setId("bubble_arrow_grey_left");
                    }

                    if (item.isSystemMessage()) {
                      AnchorPane.setLeftAnchor(headerLabel, padding);
                      AnchorPane.setRightAnchor(headerLabel, padding);
                      AnchorPane.setLeftAnchor(bg, border);
                      AnchorPane.setRightAnchor(bg, border);
                      AnchorPane.setLeftAnchor(messageLabel, padding);
                      AnchorPane.setRightAnchor(messageLabel, padding);
                      AnchorPane.setLeftAnchor(attachmentsBox, padding);
                      AnchorPane.setRightAnchor(attachmentsBox, padding);
                    } else if (senderIsTrader) {
                      AnchorPane.setLeftAnchor(headerLabel, padding + arrowWidth);
                      AnchorPane.setLeftAnchor(bg, border + arrowWidth);
                      AnchorPane.setRightAnchor(bg, border);
                      AnchorPane.setLeftAnchor(arrow, border);
                      AnchorPane.setLeftAnchor(messageLabel, padding + arrowWidth);
                      AnchorPane.setRightAnchor(messageLabel, padding);
                      AnchorPane.setLeftAnchor(attachmentsBox, padding + arrowWidth);
                      AnchorPane.setRightAnchor(attachmentsBox, padding);
                      AnchorPane.setRightAnchor(statusIcon, padding);
                    } else {
                      AnchorPane.setRightAnchor(headerLabel, padding + arrowWidth);
                      AnchorPane.setLeftAnchor(bg, border);
                      AnchorPane.setRightAnchor(bg, border + arrowWidth);
                      AnchorPane.setRightAnchor(arrow, border);
                      AnchorPane.setLeftAnchor(messageLabel, padding);
                      AnchorPane.setRightAnchor(messageLabel, padding + arrowWidth);
                      AnchorPane.setLeftAnchor(attachmentsBox, padding);
                      AnchorPane.setRightAnchor(attachmentsBox, padding + arrowWidth);
                      AnchorPane.setLeftAnchor(statusIcon, padding);
                    }

                    AnchorPane.setBottomAnchor(statusIcon, 7d);
                    headerLabel.setText(formatter.formatDateTime(item.getDate()));
                    messageLabel.setText(item.getMessage());
                    if (item.getAttachments().size() > 0) {
                      AnchorPane.setBottomAnchor(
                          messageLabel, bottomBorder + attachmentsBoxHeight + 10);
                      attachmentsBox
                          .getChildren()
                          .add(
                              new Label("Attachments: ") {
                                {
                                  setPadding(new Insets(0, 0, 3, 0));
                                  if (isMyMsg) setStyle("-fx-text-fill: white;");
                                  else setStyle("-fx-text-fill: black;");
                                }
                              });

                      item.getAttachments()
                          .stream()
                          .forEach(
                              attachment -> {
                                final Label icon = new Label();
                                setPadding(new Insets(0, 0, 3, 0));
                                if (isMyMsg) icon.getStyleClass().add("attachment-icon");
                                else icon.getStyleClass().add("attachment-icon-black");

                                AwesomeDude.setIcon(icon, AwesomeIcon.FILE_TEXT);
                                icon.setPadding(new Insets(-2, 0, 0, 0));
                                icon.setTooltip(new Tooltip(attachment.getFileName()));
                                icon.setOnMouseClicked(event -> onOpenAttachment(attachment));
                                attachmentsBox.getChildren().add(icon);
                              });
                    } else {
                      attachmentsBox.getChildren().clear();
                      AnchorPane.setBottomAnchor(messageLabel, bottomBorder + 10);
                    }

                    // TODO There are still some cell rendering issues on updates
                    setGraphic(messageAnchorPane);
                  } else {
                    messageAnchorPane.prefWidthProperty().unbind();

                    AnchorPane.clearConstraints(bg);
                    AnchorPane.clearConstraints(headerLabel);
                    AnchorPane.clearConstraints(arrow);
                    AnchorPane.clearConstraints(messageLabel);
                    AnchorPane.clearConstraints(statusIcon);
                    AnchorPane.clearConstraints(attachmentsBox);

                    setGraphic(null);
                  }
                }

                /*  private void showNotArrivedIcon() {
                    statusIcon.setVisible(true);
                    AwesomeDude.setIcon(statusIcon, AwesomeIcon.WARNING_SIGN, "14");
                    Tooltip.install(statusIcon, new Tooltip("Message did not arrive. Please try to send again."));
                    statusIcon.setTextFill(Paint.valueOf("#dd0000"));
                }*/

                private void showMailboxIcon() {
                  statusIcon.setVisible(true);
                  AwesomeDude.setIcon(statusIcon, AwesomeIcon.ENVELOPE_ALT, "14");
                  Tooltip.install(statusIcon, new Tooltip("Message saved in receivers mailbox"));
                  statusIcon.setTextFill(Paint.valueOf("#0f87c3"));
                }

                private void showArrivedIcon() {
                  statusIcon.setVisible(true);
                  AwesomeDude.setIcon(statusIcon, AwesomeIcon.OK, "14");
                  Tooltip.install(statusIcon, new Tooltip("Message arrived at receiver"));
                  statusIcon.setTextFill(Paint.valueOf("#0f87c3"));
                }
              };
            }
          });

      if (root.getChildren().size() > 1) root.getChildren().remove(1);
      root.getChildren().add(1, messagesAnchorPane);

      scrollToBottom();
    }
  }
Пример #18
0
  /**
   * Displays a progress indicator and then invokes <code>loadDrawing</code> on a worker thread.
   * Displays the drawing panel when done successfully. Displays an error message when done
   * unsuccessfully.
   *
   * @see #loadDrawing
   */
  @Override
  public final void init() {
    // set the language of the applet
    if (getParameter("Locale") != null) {
      Locale.setDefault(new Locale(getParameter("Locale")));
    }

    final ResourceBundleUtil labels =
        ResourceBundleUtil.getBundle("org.jhotdraw.samples.svg.Labels");

    // Set look and feel
    // -----------------
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Throwable e) {
      // Do nothing.
      // If we can't set the desired look and feel, UIManager does
      // automaticaly the right thing for us.
    }

    // Set our own popup factory, because the one that comes with Mac OS X
    // creates translucent popups which is not useful for color selection
    // using pop menus.
    try {
      PopupFactory.setSharedInstance(new PopupFactory());
    } catch (Throwable e) {
      // If we can't set the popup factory, we have to use what is there.
    }

    // Display a progress indicator while we are loading the drawing
    // ----------------------------------------------------------
    Container c = getContentPane();
    final ProgressIndicator progress =
        new ProgressIndicator(getName(), labels.getString("progressInitializing"));
    c.add(progress);
    progress.revalidate();

    // Load the drawing using a worker thread
    // --------------------------------------
    new Worker<Drawing>() {

      @Override
      protected Drawing construct() throws Exception {
        Thread t =
            new Thread() {

              @Override
              public void run() {
                try {
                  drawingComponent = createDrawingComponent();
                } catch (Throwable t) {
                  t.printStackTrace();
                }
              }
            };
        t.start();
        try {
          progress.setNote(labels.getString("progressLoading"));
          Drawing drawing = loadDrawing(progress);
          progress.setNote(labels.getString("progressOpeningEditor"));
          progress.setIndeterminate(true);
          return drawing;
        } finally {
          t.join();
        }
      }

      @Override
      protected void done(Drawing result) {
        Container c = getContentPane();
        c.removeAll();
        c.setLayout(new BorderLayout());
        c.add(drawingComponent.getComponent());
        initComponents();
        if (result != null) {
          setDrawing(result);
        }
        drawingComponent.revalidate();
        ((JComponent) c).revalidate();
      }

      @Override
      protected void failed(Throwable error) {
        Drawing d = createDrawing();
        String message = (error.getMessage() == null) ? error.toString() : error.getMessage();
        SVGTextAreaFigure txt =
            new SVGTextAreaFigure(
                labels.getFormatted("messageLoadFailed", getParameter("DrawingURL"), message));
        txt.setBounds(new Point2D.Double(0, 0), new Point2D.Double(getWidth(), getHeight()));
        d.add(txt);
        done(d);
        /*
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        c.removeAll();
        Throwable error = result;
        error.printStackTrace();
        String message = (error.getMessage() == null) ? error.toString() : error.getMessage();
        MessagePanel mp = new MessagePanel(
        UIManager.getIcon("OptionPane.errorIcon"),
        labels.getFormatted("messageLoadFailed", htmlencode(getParameter("DrawingURL")), htmlencode(message)));
        c.add(mp);
        mp.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
        if ("close".equals(evt.getActionCommand())) {
        close();
        }
        }
        });
        mp.revalidate();
        */
      }

      @Override
      protected void finished() {
        long end = System.currentTimeMillis();
        System.out.println("AbstractDrawingApplet startup latency:" + (end - start));
      }
    }.start();
  }
Пример #19
0
  private BorderPane webViewScene() {
    url = new TextField();
    url.setPrefWidth(800);
    browser = new WebView();
    engine = browser.getEngine();

    url.setText(fileUrl);
    engine.load(fileUrl);

    history = browser.getEngine().getHistory();

    backButton = new Button(null, new ImageView(new Image("res/BrowserIcons/back.png")));
    backButton.setOnAction(
        (ActionEvent e) -> {
          if (!checkIntConnection(defaultUrl)) {
            alert();
          } else browser.getEngine().load(goBack());
        });
    backButton.addEventHandler(
        MouseEvent.MOUSE_ENTERED, event -> backButton.setEffect(new DropShadow()));
    backButton.addEventHandler(MouseEvent.MOUSE_EXITED, event -> backButton.setEffect(null));

    forwardButton = new Button(null, new ImageView(new Image("res/BrowserIcons/forward.png")));
    forwardButton.setOnAction(
        (ActionEvent e) -> {
          if (!checkIntConnection(defaultUrl)) {
            alert();
          } else browser.getEngine().load(goForward());
        });
    forwardButton.addEventHandler(
        MouseEvent.MOUSE_ENTERED, event -> forwardButton.setEffect(new DropShadow()));
    forwardButton.addEventHandler(MouseEvent.MOUSE_EXITED, event -> forwardButton.setEffect(null));

    reloadButton = new Button(null, new ImageView(new Image("res/BrowserIcons/reload.png")));
    reloadButton.setOnAction(
        event -> {
          if (!checkIntConnection(defaultUrl)) {
            alert();
          } else browser.getEngine().reload();
        });
    reloadButton.addEventHandler(
        MouseEvent.MOUSE_ENTERED, event -> reloadButton.setEffect(new DropShadow()));
    reloadButton.addEventHandler(MouseEvent.MOUSE_EXITED, event -> reloadButton.setEffect(null));

    goButton = new Button(null, new ImageView(new Image("res/BrowserIcons/go.jpg")));
    goButton.setOnAction(
        event -> {
          // adding the http or https prefix if user didn't type it
          if (!checkIntConnection(defaultUrl)) {
            alert();
          } else {
            if (url.getText().length() > 7
                && (url.getText(0, 7).equals("http://") || url.getText(0, 8).equals("https://"))) {
              browser.getEngine().load(url.getText());
            } else if (url.getText().length() > 7 && !url.getText(0, 7).equals("http://")) {
              browser.getEngine().load("http://" + url.getText());
            } else {
              browser.getEngine().load("https://" + url.getText());
            }
          }
        });
    goButton.addEventHandler(
        MouseEvent.MOUSE_ENTERED, event -> goButton.setEffect(new DropShadow()));
    goButton.addEventHandler(MouseEvent.MOUSE_EXITED, event -> goButton.setEffect(null));

    webHistoryComboBox = new ComboBox();
    webHistoryComboBox.setPromptText("Web History");
    webHistoryComboBox.setPrefWidth(200);
    webHistoryComboBox.setOnAction(
        event -> {
          // Navigate to the link in the history index
          int offset =
              webHistoryComboBox.getSelectionModel().getSelectedIndex() - history.getCurrentIndex();
          history.go(offset);
        });

    // Displying browse history in a combo box
    history
        .getEntries()
        .addListener(
            (ListChangeListener<WebHistory.Entry>)
                c -> {
                  c.next();
                  for (WebHistory.Entry e : c.getRemoved())
                    webHistoryComboBox.getItems().remove(e.getUrl());
                  for (WebHistory.Entry e : c.getAddedSubList())
                    webHistoryComboBox.getItems().add(e.getUrl());
                });

    // Enabling and Disabling back and forward buttons
    browser
        .getEngine()
        .getLoadWorker()
        .stateProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              if (!browser.getEngine().getHistory().getEntries().isEmpty()) {
                int index = browser.getEngine().getHistory().getCurrentIndex();
                url.setText(browser.getEngine().getHistory().getEntries().get(index).getUrl());
                if (index == 0) {
                  backButton.setDisable(true);
                } else {
                  backButton.setDisable(false);
                }
                if (browser.getEngine().getHistory().getEntries().size() == 1) {
                  forwardButton.setDisable(true);
                } else if (index < browser.getEngine().getHistory().getEntries().size() - 2) {
                  forwardButton.setDisable(false);
                } else if (index < browser.getEngine().getHistory().getEntries().size() - 1) {
                  forwardButton.setDisable(false);
                } else if (index == browser.getEngine().getHistory().getEntries().size() - 1) {
                  forwardButton.setDisable(true);
                }
              }
            });

    progress.setPrefSize(25, 25);
    progress.visibleProperty().bind(browser.getEngine().getLoadWorker().runningProperty());
    BorderPane border = new BorderPane();
    HBox topBar = new HBox();
    topBar.setAlignment(Pos.CENTER);
    topBar.setSpacing(10);
    topBar.setPadding(new Insets(10, 10, 10, 10));
    topBar
        .getChildren()
        .addAll(
            progress, reloadButton, url, goButton, backButton, forwardButton, webHistoryComboBox);

    border.setTop(topBar);
    border.setCenter(browser);
    border.setPrefHeight(Screen.getPrimary().getVisualBounds().getHeight());
    border.setPrefWidth(Screen.getPrimary().getVisualBounds().getWidth());

    return border;
  }
Пример #20
0
  private static File makeIndexFiles(
      final List<IndexableAdapter> indexes,
      final File outDir,
      final ProgressIndicator progress,
      final List<String> mergedDimensions,
      final List<String> mergedMetrics,
      final Function<ArrayList<Iterable<Rowboat>>, Iterable<Rowboat>> rowMergerFn)
      throws IOException {
    Map<String, String> metricTypes = Maps.newTreeMap(Ordering.<String>natural().nullsFirst());
    for (IndexableAdapter adapter : indexes) {
      for (String metric : adapter.getAvailableMetrics()) {
        metricTypes.put(metric, adapter.getMetricType(metric));
      }
    }
    final Interval dataInterval;

    /** *********** Main index.drd file ************* */
    progress.progress();
    long startTime = System.currentTimeMillis();
    File indexFile = new File(outDir, "index.drd");

    FileOutputStream fileOutputStream = null;
    FileChannel channel = null;
    try {
      fileOutputStream = new FileOutputStream(indexFile);
      channel = fileOutputStream.getChannel();
      channel.write(ByteBuffer.wrap(new byte[] {IndexIO.CURRENT_VERSION_ID}));

      GenericIndexed.fromIterable(mergedDimensions, GenericIndexed.stringStrategy)
          .writeToChannel(channel);
      GenericIndexed.fromIterable(mergedMetrics, GenericIndexed.stringStrategy)
          .writeToChannel(channel);

      DateTime minTime = new DateTime(Long.MAX_VALUE);
      DateTime maxTime = new DateTime(0l);

      for (IndexableAdapter index : indexes) {
        minTime = JodaUtils.minDateTime(minTime, index.getDataInterval().getStart());
        maxTime = JodaUtils.maxDateTime(maxTime, index.getDataInterval().getEnd());
      }

      dataInterval = new Interval(minTime, maxTime);
      serializerUtils.writeString(channel, String.format("%s/%s", minTime, maxTime));
    } finally {
      Closeables.closeQuietly(channel);
      channel = null;
      Closeables.closeQuietly(fileOutputStream);
      fileOutputStream = null;
    }
    IndexIO.checkFileSize(indexFile);
    log.info(
        "outDir[%s] completed index.drd in %,d millis.",
        outDir, System.currentTimeMillis() - startTime);

    /** *********** Setup Dim Conversions ************* */
    progress.progress();
    startTime = System.currentTimeMillis();

    IOPeon ioPeon = new TmpFileIOPeon();
    ArrayList<FileOutputSupplier> dimOuts = Lists.newArrayListWithCapacity(mergedDimensions.size());
    Map<String, Integer> dimensionCardinalities = Maps.newHashMap();
    ArrayList<Map<String, IntBuffer>> dimConversions =
        Lists.newArrayListWithCapacity(indexes.size());

    for (IndexableAdapter index : indexes) {
      dimConversions.add(Maps.<String, IntBuffer>newHashMap());
    }

    for (String dimension : mergedDimensions) {
      final FlattenedArrayWriter<String> writer =
          new FlattenedArrayWriter<String>(ioPeon, dimension, GenericIndexed.stringStrategy);
      writer.open();

      List<Indexed<String>> dimValueLookups = Lists.newArrayListWithCapacity(indexes.size());
      DimValueConverter[] converters = new DimValueConverter[indexes.size()];
      for (int i = 0; i < indexes.size(); i++) {
        Indexed<String> dimValues = indexes.get(i).getDimValueLookup(dimension);
        if (dimValues != null) {
          dimValueLookups.add(dimValues);
          converters[i] = new DimValueConverter(dimValues);
        }
      }

      Iterable<String> dimensionValues =
          CombiningIterable.createSplatted(
              Iterables.transform(
                  dimValueLookups,
                  new Function<Indexed<String>, Iterable<String>>() {
                    @Override
                    public Iterable<String> apply(@Nullable Indexed<String> indexed) {
                      return Iterables.transform(
                          indexed,
                          new Function<String, String>() {
                            @Override
                            public String apply(@Nullable String input) {
                              return (input == null) ? "" : input;
                            }
                          });
                    }
                  }),
              Ordering.<String>natural().nullsFirst());

      int count = 0;
      for (String value : dimensionValues) {
        value = value == null ? "" : value;
        writer.write(value);

        for (int i = 0; i < indexes.size(); i++) {
          DimValueConverter converter = converters[i];
          if (converter != null) {
            converter.convert(value, count);
          }
        }

        ++count;
      }
      dimensionCardinalities.put(dimension, count);

      FileOutputSupplier dimOut =
          new FileOutputSupplier(IndexIO.makeDimFile(outDir, dimension), true);
      dimOuts.add(dimOut);

      writer.close();
      serializerUtils.writeString(dimOut, dimension);
      ByteStreams.copy(writer.combineStreams(), dimOut);
      for (int i = 0; i < indexes.size(); ++i) {
        DimValueConverter converter = converters[i];
        if (converter != null) {
          dimConversions.get(i).put(dimension, converters[i].getConversionBuffer());
        }
      }

      ioPeon.cleanup();
    }
    log.info(
        "outDir[%s] completed dim conversions in %,d millis.",
        outDir, System.currentTimeMillis() - startTime);

    /** *********** Walk through data sets and merge them ************ */
    progress.progress();
    startTime = System.currentTimeMillis();

    ArrayList<Iterable<Rowboat>> boats = Lists.newArrayListWithCapacity(indexes.size());

    for (int i = 0; i < indexes.size(); ++i) {
      final IndexableAdapter adapter = indexes.get(i);

      final int[] dimLookup = new int[mergedDimensions.size()];
      int count = 0;
      for (String dim : adapter.getAvailableDimensions()) {
        dimLookup[count] = mergedDimensions.indexOf(dim.toLowerCase());
        count++;
      }

      final int[] metricLookup = new int[mergedMetrics.size()];
      count = 0;
      for (String metric : adapter.getAvailableMetrics()) {
        metricLookup[count] = mergedMetrics.indexOf(metric);
        count++;
      }

      boats.add(
          new MMappedIndexRowIterable(
              Iterables.transform(
                  indexes.get(i).getRows(),
                  new Function<Rowboat, Rowboat>() {
                    @Override
                    public Rowboat apply(@Nullable Rowboat input) {
                      int[][] newDims = new int[mergedDimensions.size()][];
                      int j = 0;
                      for (int[] dim : input.getDims()) {
                        newDims[dimLookup[j]] = dim;
                        j++;
                      }

                      Object[] newMetrics = new Object[mergedMetrics.size()];
                      j = 0;
                      for (Object met : input.getMetrics()) {
                        newMetrics[metricLookup[j]] = met;
                        j++;
                      }

                      return new Rowboat(
                          input.getTimestamp(), newDims, newMetrics, input.getRowNum());
                    }
                  }),
              mergedDimensions,
              dimConversions.get(i),
              i));
    }

    Iterable<Rowboat> theRows = rowMergerFn.apply(boats);

    CompressedLongsSupplierSerializer littleEndianTimeWriter =
        CompressedLongsSupplierSerializer.create(
            ioPeon, "little_end_time", ByteOrder.LITTLE_ENDIAN);
    CompressedLongsSupplierSerializer bigEndianTimeWriter =
        CompressedLongsSupplierSerializer.create(ioPeon, "big_end_time", ByteOrder.BIG_ENDIAN);

    littleEndianTimeWriter.open();
    bigEndianTimeWriter.open();

    ArrayList<VSizeIndexedWriter> forwardDimWriters =
        Lists.newArrayListWithCapacity(mergedDimensions.size());
    for (String dimension : mergedDimensions) {
      VSizeIndexedWriter writer =
          new VSizeIndexedWriter(ioPeon, dimension, dimensionCardinalities.get(dimension));
      writer.open();
      forwardDimWriters.add(writer);
    }

    ArrayList<MetricColumnSerializer> metWriters =
        Lists.newArrayListWithCapacity(mergedMetrics.size());
    for (Map.Entry<String, String> entry : metricTypes.entrySet()) {
      String metric = entry.getKey();
      String typeName = entry.getValue();
      if ("float".equals(typeName)) {
        metWriters.add(new FloatMetricColumnSerializer(metric, outDir, ioPeon));
      } else {
        ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(typeName);

        if (serde == null) {
          throw new ISE("Unknown type[%s]", typeName);
        }

        metWriters.add(new ComplexMetricColumnSerializer(metric, outDir, ioPeon, serde));
      }
    }
    for (MetricColumnSerializer metWriter : metWriters) {
      metWriter.open();
    }

    int rowCount = 0;
    long time = System.currentTimeMillis();
    List<IntBuffer> rowNumConversions = Lists.newArrayListWithCapacity(indexes.size());
    for (IndexableAdapter index : indexes) {
      int[] arr = new int[index.getNumRows()];
      Arrays.fill(arr, INVALID_ROW);
      rowNumConversions.add(IntBuffer.wrap(arr));
    }

    for (Rowboat theRow : theRows) {
      progress.progress();
      littleEndianTimeWriter.add(theRow.getTimestamp());
      bigEndianTimeWriter.add(theRow.getTimestamp());

      final Object[] metrics = theRow.getMetrics();
      for (int i = 0; i < metrics.length; ++i) {
        metWriters.get(i).serialize(metrics[i]);
      }

      int[][] dims = theRow.getDims();
      for (int i = 0; i < dims.length; ++i) {
        List<Integer> listToWrite =
            (i >= dims.length || dims[i] == null) ? null : Ints.asList(dims[i]);
        forwardDimWriters.get(i).write(listToWrite);
      }

      for (Map.Entry<Integer, TreeSet<Integer>> comprisedRow :
          theRow.getComprisedRows().entrySet()) {
        final IntBuffer conversionBuffer = rowNumConversions.get(comprisedRow.getKey());

        for (Integer rowNum : comprisedRow.getValue()) {
          while (conversionBuffer.position() < rowNum) {
            conversionBuffer.put(INVALID_ROW);
          }
          conversionBuffer.put(rowCount);
        }
      }

      if ((++rowCount % 500000) == 0) {
        log.info(
            "outDir[%s] walked 500,000/%,d rows in %,d millis.",
            outDir, rowCount, System.currentTimeMillis() - time);
        time = System.currentTimeMillis();
      }
    }

    for (IntBuffer rowNumConversion : rowNumConversions) {
      rowNumConversion.rewind();
    }

    final File littleEndianFile = IndexIO.makeTimeFile(outDir, ByteOrder.LITTLE_ENDIAN);
    littleEndianFile.delete();
    OutputSupplier<FileOutputStream> out = Files.newOutputStreamSupplier(littleEndianFile, true);
    littleEndianTimeWriter.closeAndConsolidate(out);
    IndexIO.checkFileSize(littleEndianFile);

    final File bigEndianFile = IndexIO.makeTimeFile(outDir, ByteOrder.BIG_ENDIAN);
    bigEndianFile.delete();
    out = Files.newOutputStreamSupplier(bigEndianFile, true);
    bigEndianTimeWriter.closeAndConsolidate(out);
    IndexIO.checkFileSize(bigEndianFile);

    for (int i = 0; i < mergedDimensions.size(); ++i) {
      forwardDimWriters.get(i).close();
      ByteStreams.copy(forwardDimWriters.get(i).combineStreams(), dimOuts.get(i));
    }

    for (MetricColumnSerializer metWriter : metWriters) {
      metWriter.close();
    }

    ioPeon.cleanup();
    log.info(
        "outDir[%s] completed walk through of %,d rows in %,d millis.",
        outDir, rowCount, System.currentTimeMillis() - startTime);

    /** ********** Create Inverted Indexes ************ */
    startTime = System.currentTimeMillis();

    final File invertedFile = new File(outDir, "inverted.drd");
    Files.touch(invertedFile);
    out = Files.newOutputStreamSupplier(invertedFile, true);
    for (int i = 0; i < mergedDimensions.size(); ++i) {
      long dimStartTime = System.currentTimeMillis();
      String dimension = mergedDimensions.get(i);

      File dimOutFile = dimOuts.get(i).getFile();
      final MappedByteBuffer dimValsMapped = Files.map(dimOutFile);

      if (!dimension.equals(serializerUtils.readString(dimValsMapped))) {
        throw new ISE("dimensions[%s] didn't equate!?  This is a major WTF moment.", dimension);
      }
      Indexed<String> dimVals =
          GenericIndexed.readFromByteBuffer(dimValsMapped, GenericIndexed.stringStrategy);
      log.info("Starting dimension[%s] with cardinality[%,d]", dimension, dimVals.size());

      FlattenedArrayWriter<ImmutableConciseSet> writer =
          new FlattenedArrayWriter<ImmutableConciseSet>(
              ioPeon, dimension, ConciseCompressedIndexedInts.objectStrategy);
      writer.open();

      for (String dimVal : IndexedIterable.create(dimVals)) {
        progress.progress();
        List<Iterable<Integer>> convertedInverteds = Lists.newArrayListWithCapacity(indexes.size());
        for (int j = 0; j < indexes.size(); ++j) {
          convertedInverteds.add(
              new ConvertingIndexedInts(
                  indexes.get(j).getInverteds(dimension, dimVal), rowNumConversions.get(j)));
        }

        ConciseSet bitset = new ConciseSet();
        for (Integer row :
            CombiningIterable.createSplatted(
                convertedInverteds, Ordering.<Integer>natural().nullsFirst())) {
          if (row != INVALID_ROW) {
            bitset.add(row);
          }
        }

        writer.write(ImmutableConciseSet.newImmutableFromMutable(bitset));
      }
      writer.close();

      serializerUtils.writeString(out, dimension);
      ByteStreams.copy(writer.combineStreams(), out);
      ioPeon.cleanup();

      log.info(
          "Completed dimension[%s] in %,d millis.",
          dimension, System.currentTimeMillis() - dimStartTime);
    }
    log.info(
        "outDir[%s] completed inverted.drd in %,d millis.",
        outDir, System.currentTimeMillis() - startTime);

    final ArrayList<String> expectedFiles =
        Lists.newArrayList(
            Iterables.concat(
                Arrays.asList(
                    "index.drd", "inverted.drd", "time_BIG_ENDIAN.drd", "time_LITTLE_ENDIAN.drd"),
                Iterables.transform(mergedDimensions, GuavaUtils.formatFunction("dim_%s.drd")),
                Iterables.transform(
                    mergedMetrics, GuavaUtils.formatFunction("met_%s_LITTLE_ENDIAN.drd")),
                Iterables.transform(
                    mergedMetrics, GuavaUtils.formatFunction("met_%s_BIG_ENDIAN.drd"))));

    Map<String, File> files = Maps.newLinkedHashMap();
    for (String fileName : expectedFiles) {
      files.put(fileName, new File(outDir, fileName));
    }

    File smooshDir = new File(outDir, "smoosher");
    smooshDir.mkdir();

    for (Map.Entry<String, File> entry : Smoosh.smoosh(outDir, smooshDir, files).entrySet()) {
      entry.getValue().delete();
    }

    for (File file : smooshDir.listFiles()) {
      Files.move(file, new File(outDir, file.getName()));
    }

    if (!smooshDir.delete()) {
      log.info(
          "Unable to delete temporary dir[%s], contains[%s]",
          smooshDir, Arrays.asList(smooshDir.listFiles()));
      throw new IOException(String.format("Unable to delete temporary dir[%s]", smooshDir));
    }

    createIndexDrdFile(
        IndexIO.CURRENT_VERSION_ID,
        outDir,
        GenericIndexed.fromIterable(mergedDimensions, GenericIndexed.stringStrategy),
        GenericIndexed.fromIterable(mergedMetrics, GenericIndexed.stringStrategy),
        dataInterval);

    return outDir;
  }
 public void ensureFinished() {
   if (myProcessIndicator != null && !myProcessIndicator.isCanceled()) {
     finish();
   }
 }
  private void scheduleCacheUpdate(@NotNull final DumbModeTask task, boolean forceDumbMode) {
    if (ApplicationManager.getApplication().isInternal()) LOG.info("schedule " + task);
    final Application application = ApplicationManager.getApplication();

    if (application.isUnitTestMode()
        || application.isHeadlessEnvironment()
        || !forceDumbMode && !myDumb && application.isReadAccessAllowed()) {
      final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
      if (indicator != null) {
        indicator.pushState();
      }
      try {
        HeavyProcessLatch.INSTANCE.processStarted();
        task.performInDumbMode(indicator != null ? indicator : new EmptyProgressIndicator());
      } finally {
        HeavyProcessLatch.INSTANCE.processFinished();
        if (indicator != null) {
          indicator.popState();
        }
        Disposer.dispose(task);
      }
      return;
    }

    UIUtil.invokeLaterIfNeeded(
        new DumbAwareRunnable() {
          @Override
          public void run() {
            if (myProject.isDisposed()) {
              return;
            }
            final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
            myProgresses.put(task, indicator);
            Disposer.register(
                task,
                new Disposable() {
                  @Override
                  public void dispose() {
                    application.assertIsDispatchThread();
                    myProgresses.remove(task);
                  }
                });
            // ok to test and set the flag like this, because the change is always done from
            // dispatch thread
            if (!myDumb) {
              // always change dumb status inside write action.
              // This will ensure all active read actions are completed before the app goes dumb
              boolean startSuccess =
                  application.runWriteAction(
                      new Computable<Boolean>() {
                        @Override
                        public Boolean compute() {
                          myDumb = true;
                          try {
                            myPublisher.enteredDumbMode();
                          } catch (Throwable e) {
                            LOG.error(e);
                          }

                          try {
                            startBackgroundProcess(task, indicator);
                          } catch (Throwable e) {
                            LOG.error("Failed to start background index update task", e);
                            return false;
                          }
                          return true;
                        }
                      });
              if (!startSuccess) {
                updateFinished();
              }
            } else {
              myUpdatesQueue.addLast(task);
            }
          }
        });
  }
  public ConfigurationsDialogBuilder create(
      DependencyDotFileGenerator dependencyDotFileGenerator,
      GradleScriptPreferences preferences,
      Os os,
      String outputFileName) {
    this.outputFileName = outputFileName;
    this.dependencyDotFileGenerator = dependencyDotFileGenerator;
    this.preferences = preferences;
    this.os = os;
    dialog = new ConfigurationChoiceDialog(this);
    dialog.setResizable(true);
    dialog.initStyle(UTILITY);
    dialog.initModality(APPLICATION_MODAL);
    dialog.setIconified(false);
    dialog.centerOnScreen();
    dialog.borderPanel = BorderPaneBuilder.create().styleClass("dialog").build();
    dialog.stackPane = new StackPane();

    StackPane stackPane = dialog.stackPane;

    dialog.log = new TextArea();

    TextArea log = dialog.log;
    BorderPane borderPanel = dialog.borderPanel;

    // message
    dialog.configurationsBox = new VBox();

    VBox configurationsBox = dialog.configurationsBox;

    dialog.configurationsBox = configurationsBox;
    dialog.progressIndicator = new ProgressIndicator();

    ProgressIndicator progressIndicator = dialog.progressIndicator;

    stackPane.getChildren().add(log);
    stackPane.getChildren().add(progressIndicator);
    progressIndicator.setPrefSize(50, 50);
    progressIndicator.setMaxSize(50, 50);
    configurationsBox.setSpacing(15);
    configurationsBox.setAlignment(CENTER_LEFT);
    dialog.scrollPane = new ScrollPane();

    ScrollPane scrollPane = dialog.scrollPane;

    scrollPane.setContent(configurationsBox);
    dialog.borderPanel.setCenter(stackPane);
    BorderPane.setAlignment(configurationsBox, CENTER_LEFT);
    BorderPane.setMargin(configurationsBox, new Insets(MARGIN, MARGIN, MARGIN, 2 * MARGIN));

    // buttons
    dialog.buttonsPanel = new HBox();

    final HBox buttonsPanel = dialog.buttonsPanel;

    buttonsPanel.setSpacing(MARGIN);
    buttonsPanel.setAlignment(BOTTOM_CENTER);
    BorderPane.setMargin(buttonsPanel, new Insets(0, 0, 1.5 * MARGIN, 0));
    borderPanel.setBottom(buttonsPanel);
    borderPanel
        .widthProperty()
        .addListener(
            new ChangeListener<Number>() {
              public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
                buttonsPanel.layout();
              }
            });
    dialog.scene = new Scene(borderPanel);
    dialog.setScene(dialog.scene);

    URL resource =
        ConfigurationsDialogBuilder.class.getResource(
            "/com/nurflugel/gradle/ui/dialogservice/dialog.css");
    String externalForm = resource.toExternalForm();

    // dialog.borderPanel.styleClass("dialog");
    dialog.getScene().getStylesheets().add(externalForm);

    return this;
  }
 public void initialize() {
   progressMeter.setOpacity(0);
 }
 private static void setText(String text) {
   ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
   if (progressIndicator != null) {
     progressIndicator.setText(text);
   }
 }
  /**
   * Creates a set of reference objects and stores it in a new index (name "<indexPath>-ro"). Then
   * creates ordered lists of reference object positions for each data item in the index with given
   * feature. Finally a new index (name "<indexPath>-ms") is created where all the original
   * documents as well as the new data are stored.
   *
   * @param indexPath the path to the original index
   * @throws IOException
   */
  public void createIndex(String indexPath) throws IOException {
    IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexPath)));
    int numDocs = reader.numDocs();

    if (numDocs < numReferenceObjects) {
      throw new UnsupportedOperationException("Too few documents in index.");
    }

    // progress report
    progress.setNumDocsAll(numDocs);
    progress.setCurrentState(State.RoSelection);

    boolean hasDeletions = reader.hasDeletions();

    // init reference objects:
    IndexWriter iw = LuceneUtils.createIndexWriter(indexPath + "-ro", true);
    HashSet<Integer> referenceObjsIds = new HashSet<Integer>(numReferenceObjects);

    double numDocsDouble = (double) numDocs;
    while (referenceObjsIds.size() < numReferenceObjects) {
      referenceObjsIds.add((int) (numDocsDouble * Math.random()));
    }
    int count = 0;

    if (hasDeletions) {
      System.err.println(
          "WARNING: There are deleted docs in your index. You should "
              + "optimize your index before using this method.");
    }

    // progress report
    progress.setCurrentState(State.RoIndexing);

    // find them in the index and put them into a separate index:
    for (int i : referenceObjsIds) {
      count++;
      Document document = reader.document(i);
      document.add(new Field("ro-id", count + "", StringField.TYPE_STORED));
      iw.addDocument(document);
    }
    iw.commit();
    iw.close();

    // progress report
    progress.setCurrentState(State.Indexing);

    // now find the reference objects for each entry ;)
    IndexReader readerRo = DirectoryReader.open(FSDirectory.open(new File(indexPath + "-ro")));
    ImageSearcher searcher =
        new GenericImageSearcher(numReferenceObjectsUsed, featureClass, featureFieldName);
    Map<String, Analyzer> analyzerPerField = new HashMap<String, Analyzer>();
    analyzerPerField.put("ro-order", new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION));
    PerFieldAnalyzerWrapper aWrapper =
        new PerFieldAnalyzerWrapper(
            new SimpleAnalyzer(LuceneUtils.LUCENE_VERSION), analyzerPerField);

    iw =
        new IndexWriter(
            FSDirectory.open(new File(indexPath)),
            new IndexWriterConfig(LuceneUtils.LUCENE_VERSION, aWrapper)
                .setOpenMode(IndexWriterConfig.OpenMode.CREATE));
    StringBuilder sb = new StringBuilder(256);
    // Needed for check whether the document is deleted.
    Bits liveDocs = MultiFields.getLiveDocs(reader);

    for (int i = 0; i < numDocs; i++) {
      if (reader.hasDeletions() && !liveDocs.get(i)) continue; // if it is deleted, just ignore it.
      Document document = reader.document(i);
      ImageSearchHits hits = searcher.search(document, readerRo);
      sb.delete(0, sb.length());
      for (int j = 0; j < numReferenceObjectsUsed; j++) {
        sb.append(hits.doc(j).getValues("ro-id")[0]);
        sb.append(' ');
      }
      // System.out.println(sb.toString());
      document.add(new TextField("ro-order", sb.toString(), Field.Store.YES));
      iw.updateDocument(
          new Term(
              DocumentBuilder.FIELD_NAME_IDENTIFIER,
              document.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]),
          document);

      // progress report
      progress.setNumDocsProcessed(progress.getNumDocsProcessed() + 1);
    }
    iw.commit();
    iw.close();

    // progress report
    progress.setCurrentState(State.Idle);
  }