Beispiel #1
0
  private void showConversion() {
    if (combo == null) {
      return;
    }
    JPanel mainPanel = new JPanel();
    if (algorithmList.getSelectedValue() == null) {
      JOptionPane.showMessageDialog(
          this,
          "Please select a conversion algorithm first.",
          "Conversion",
          JOptionPane.INFORMATION_MESSAGE);
      return;
    }

    final ConvertingPlugin algorithm =
        ((ConvertAlgorithm) algorithmList.getSelectedValue()).getPlugin();
    if ((combo.getSelectedIndex() < 0) || (combo.getSelectedIndex() >= combo.getItemCount())) {
      JOptionPane.showMessageDialog(
          this,
          "Please choose inputs for all items.",
          "Conversion",
          JOptionPane.INFORMATION_MESSAGE);
      return;
    }

    UISettings.getInstance().setLastUsedConversion(algorithm.getName());

    MainUI.getInstance()
        .addAction(
            algorithm,
            LogStateMachine.START,
            new Object[] {comboItems.get(combo.getSelectedIndex())});

    SwingWorker worker =
        new SwingWorker() {
          MiningResult result;
          StopWatch timer = new StopWatch();

          public Object construct() {
            Message.add("Start conversion.");
            timer.start();
            try {
              if (algorithm instanceof DoNotCreateNewInstance) {
                result =
                    algorithm.convert((ProvidedObject) comboItems.get(combo.getSelectedIndex()));
              } else {
                result =
                    ((ConvertingPlugin) algorithm.getClass().newInstance())
                        .convert((ProvidedObject) comboItems.get(combo.getSelectedIndex()));
              }
            } catch (IllegalAccessException ex) {
              Message.add(
                  "No new instantiation of "
                      + algorithm.getName()
                      + " could be made, using"
                      + " old instance instead",
                  Message.ERROR);
              result = algorithm.convert((ProvidedObject) comboItems.get(combo.getSelectedIndex()));
            } catch (InstantiationException ex) {
              Message.add(
                  "No new instantiation of "
                      + algorithm.getName()
                      + " could be made, using"
                      + " old instance instead",
                  Message.ERROR);
              result = algorithm.convert((ProvidedObject) comboItems.get(combo.getSelectedIndex()));
            }
            return result;
          }

          public void finished() {
            timer.stop();
            Message.add("Conversion duration: " + timer.formatDuration());
            MainUI.getInstance()
                .addAction(
                    algorithm,
                    LogStateMachine.COMPLETE,
                    (result instanceof Provider) ? ((Provider) result).getProvidedObjects() : null);

            getContentPane().removeAll();
            getContentPane().add(result.getVisualization(), BorderLayout.CENTER);
            getContentPane().validate();
            getContentPane().repaint();
          }
        };
    worker.start();
  }