Exemplo n.º 1
0
  private void init() {

    m_iExecuteIterativeMenuCount = 0;
    this.setPreferredSize(new java.awt.Dimension(350, 380));
    this.setSize(new java.awt.Dimension(350, 380));
    final BorderLayout thisLayout = new BorderLayout();
    this.setLayout(thisLayout);
    jTree = new JTree();
    jTree.setOpaque(false);
    jTree.setCellRenderer(new AlgorithmTreeCellRenderer());
    final MouseListener ml =
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            m_Alg = null;
            m_Action = null;
            menuItemExecute.setVisible(false);
            menuItemExecuteAsBatch.setVisible(false);
            for (int i = 0; i < EXECUTE_ITERATIVE_MENU_COUNT; i++) {
              menuItemExecuteIterative[i].setVisible(false);
            }
            for (int j = 0; j < menuItemToolboxAction.length; j++) {
              menuItemToolboxAction[j].setVisible(false);
            }
            menuItemExecuteAsBatchFromGIS.setVisible(false);
            menuItemShowHelp.setVisible(false);
            m_Path = jTree.getPathForLocation(e.getX(), e.getY());
            updateSelectedAlgorithm();

            // Create again DataObjects here to get feature selections changes (if there are)
            SextanteGUI.getInputFactory().createDataObjects();

            if (e.getButton() == MouseEvent.BUTTON1) {
              if (e.getClickCount() == 2) {
                executeSelectedAlgorithm();
              }
            } else if (e.getButton() == MouseEvent.BUTTON3) {
              showPopupMenu(e);
            }
          }
        };
    jTree.addMouseListener(ml);
    jTree.addKeyListener(
        new KeyListener() {
          public void keyPressed(final KeyEvent e) {}

          public void keyReleased(final KeyEvent e) {}

          public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
              executeSelectedAlgorithm();
            }

            if (e.getKeyChar() == KeyEvent.VK_SPACE) {
              showPopupMenu(e);
            }
          }
        });

    jTree.addTreeSelectionListener(
        new TreeSelectionListener() {

          public void valueChanged(final TreeSelectionEvent e) {
            m_Path = e.getPath();
            updateSelectedAlgorithm();
          }
        });

    jScrollPane = new TransparentScrollPane(jTree);
    jScrollPane.setSize(new java.awt.Dimension(350, 380));
    if (m_BackgroundImg != null) {
      jScrollPane.setBackgroundImage(m_BackgroundImg);
    }
    this.add(jScrollPane, BorderLayout.CENTER);

    popupMenu = new JPopupMenu("Menu");

    menuItemExecute = new JMenuItem(Sextante.getText("Run"));
    menuItemExecute.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            executeSelectedAlgorithm();
          }
        });
    popupMenu.add(menuItemExecute);

    menuItemExecuteIterative = new JMenuItem[EXECUTE_ITERATIVE_MENU_COUNT];
    for (int i = 0; i < menuItemExecuteIterative.length; i++) {
      final int iParameter = i;
      menuItemExecuteIterative[i] = new JMenuItem();
      menuItemExecuteIterative[i].addActionListener(
          new ActionListener() {
            public void actionPerformed(final ActionEvent evt) {
              executeSelectedAlgorithmIteratively(iParameter);
            }
          });
      popupMenu.add(menuItemExecuteIterative[i]);
    }

    final IToolboxRightButtonAction[] actions = SextanteGUI.getToolboxRightButtonActions();
    menuItemToolboxAction = new JMenuItem[actions.length];
    for (int i = 0; i < actions.length; i++) {
      final IToolboxRightButtonAction action = actions[i];
      menuItemToolboxAction[i] = new JMenuItem();
      menuItemToolboxAction[i].setText(action.getDescription());
      menuItemToolboxAction[i].addActionListener(
          new ActionListener() {
            public void actionPerformed(final ActionEvent evt) {
              action.execute(m_Alg);
            }
          });
      popupMenu.add(menuItemToolboxAction[i]);
    }

    menuItemExecuteAsBatch = new JMenuItem(Sextante.getText("Execute_as_batch_process"));
    menuItemExecuteAsBatch.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            executeAsBatch();
          }
        });
    popupMenu.add(menuItemExecuteAsBatch);

    menuItemExecuteAsBatchFromGIS =
        new JMenuItem(Sextante.getText("Execute_as_batch_process__using_layers_from_GIS_app"));
    menuItemExecuteAsBatchFromGIS.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            executeAsBatchInGIS();
          }
        });
    popupMenu.add(menuItemExecuteAsBatchFromGIS);
    popupMenu.addSeparator();

    menuItemSetOutputRendering = new JMenuItem(Sextante.getText("set_output_rendering"));
    menuItemSetOutputRendering.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            setOutputRendering();
          }
        });
    popupMenu.add(menuItemSetOutputRendering);
    popupMenu.addSeparator();

    final JMenuItem menuItemExpand = new JMenuItem(Sextante.getText("Expand_all"));
    menuItemExpand.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            expandAll();
          }
        });
    popupMenu.add(menuItemExpand);

    final JMenuItem menuItemCollapse = new JMenuItem(Sextante.getText("Collapse_all"));
    menuItemCollapse.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            collapseAll();
          }
        });
    popupMenu.add(menuItemCollapse);

    menuItemShowOnlyActive = new JCheckBoxMenuItem(Sextante.getText("Show_active_only"));
    menuItemShowOnlyActive.addItemListener(
        new ItemListener() {
          public void itemStateChanged(final ItemEvent e) {
            SextanteGUI.setShowOnlyActiveAlgorithms(e.getStateChange() == ItemEvent.SELECTED);
            fillTree(m_sLastSearchString, m_bLastSearchIncludedHelpFiles);
            collapseAll();
          }
        });
    menuItemShowOnlyActive.setSelected(SextanteGUI.getShowOnlyActiveAlgorithms());
    popupMenu.add(menuItemShowOnlyActive);

    popupMenu.addSeparator();

    menuItemShowHelp = new JMenuItem(Sextante.getText("Show_help"));
    menuItemShowHelp.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            showHelp();
          }
        });
    popupMenu.add(menuItemShowHelp);
  }
Exemplo n.º 2
0
  private void updateSelectedAlgorithm() {

    m_Alg = null;
    m_Action = null;

    if (m_Path != null) {
      menuItemExecuteAsBatch.setVisible(false);
      menuItemExecuteAsBatchFromGIS.setVisible(false);
      menuItemExecute.setVisible(false);
      menuItemShowHelp.setVisible(false);
      for (int i = 0; i < menuItemExecuteIterative.length; i++) {
        menuItemExecuteIterative[i].setVisible(false);
      }
      final DefaultMutableTreeNode node = (DefaultMutableTreeNode) m_Path.getLastPathComponent();
      if (!(node.getUserObject() instanceof GeoAlgorithm)) {
        if ((node.getUserObject() instanceof ToolboxAction)) {
          m_Action = (ToolboxAction) node.getUserObject();
        }
        return;
      }
      m_Alg = ((GeoAlgorithm) node.getUserObject());
      menuItemExecuteAsBatch.setVisible(true);
      menuItemShowHelp.setVisible(true);
      menuItemExecute.setVisible(true);
      final Object[] objs = SextanteGUI.getInputFactory().getDataObjects();
      menuItemExecuteAsBatchFromGIS.setVisible(true);
      final boolean bMeets = m_Alg.meetsDataRequirements(objs);
      menuItemExecuteAsBatchFromGIS.setEnabled(bMeets);
      menuItemExecute.setEnabled(bMeets);

      final IToolboxRightButtonAction[] actions = SextanteGUI.getToolboxRightButtonActions();
      for (int i = 0; i < menuItemToolboxAction.length; i++) {
        menuItemToolboxAction[i].setVisible(actions[i].canBeExecutedOnAlgorithm(m_Alg));
      }

      if (bMeets && m_Alg.requiresIndividualVectorLayers()) {
        m_iExecuteIterativeMenuCount = 0;
        final int iParams = m_Alg.getParameters().getNumberOfParameters();
        for (int i = 0; i < iParams; i++) {
          final Parameter param = m_Alg.getParameters().getParameter(i);
          if (param instanceof ParameterVectorLayer) {
            final ParameterVectorLayer pvl = (ParameterVectorLayer) param;
            boolean bMandatory;
            try {
              bMandatory =
                  ((AdditionalInfoVectorLayer) pvl.getParameterAdditionalInfo()).getIsMandatory();
              if (bMandatory) {
                menuItemExecuteIterative[m_iExecuteIterativeMenuCount].setText(
                    Sextante.getText("Run_iterative")
                        + " ("
                        + param.getParameterDescription()
                        + ")");
                menuItemExecuteIterative[m_iExecuteIterativeMenuCount].setVisible(true);
                m_iExecuteIterativeMenuCount++;
              }
            } catch (final NullParameterAdditionalInfoException e) {
            }
          }
        }
      }
    }
  }