Esempio n. 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();
  }
Esempio n. 2
0
  private void setSelectedAlgorithm(int index) {

    if (index >= 0) {

      JButton docsButton = new JButton("Plugin documentation...");

      docsButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              MainUI.getInstance()
                  .showReference(((ConvertAlgorithm) algorithmList.getSelectedValue()).getPlugin());
            }
          });

      JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));

      JPanel upperLeftPanel = new JPanel(new GridBagLayout());

      upperLeftPanel.add(
          docsButton,
          new GridBagConstraints(
              0,
              1,
              1,
              1,
              0.0,
              0.0,
              GridBagConstraints.NORTHWEST,
              GridBagConstraints.NONE,
              new Insets(30, 5, 5, 5),
              0,
              0));

      combo =
          new ToolTipComboBox(
              getComboItems(((ConvertAlgorithm) algorithmList.getSelectedValue()).getPlugin()));
      if (combo.getItemCount() == 0) {
        upperLeftPanel.add(
            new JLabel("There is no input available for this item."),
            new GridBagConstraints(
                0,
                0,
                1,
                1,
                0.0,
                0.0,
                GridBagConstraints.NORTHWEST,
                GridBagConstraints.BOTH,
                new Insets(0, 5, 5, 0),
                0,
                0));
        combo = null;
      } else {
        upperLeftPanel.add(
            combo,
            new GridBagConstraints(
                0,
                0,
                1,
                1,
                0.0,
                0.0,
                GridBagConstraints.NORTHWEST,
                GridBagConstraints.BOTH,
                new Insets(0, 5, 5, 0),
                0,
                0));
      }
      panel.add(upperLeftPanel, null);
      inputsScrollPane.setViewportView(panel);
    } else {
      inputsScrollPane.setViewportView(new JPanel());
    }
    inputsScrollPane.validate();
    inputsScrollPane.repaint();
  }