示例#1
0
  public static String getHelpFile(final String sTopic) {

    String sPath = SextanteGUI.getHelpPath() + File.separator + Locale.getDefault().getLanguage();

    final File dir = new File(sPath);
    if (!dir.exists()) {
      sPath = SextanteGUI.getHelpPath() + File.separator + Locale.ENGLISH.getLanguage();
    }
    return sPath + File.separator + "general" + File.separator + sTopic + ".html";
  }
示例#2
0
  protected void setOutputRendering() {

    if (m_Alg != null) {
      final OutputRenderingSettingsDialog dialog = new OutputRenderingSettingsDialog(m_Alg);
      dialog.setVisible(true);
      final HashMap<String, Object> set = dialog.getSettings();
      if (set != null) {
        SextanteGUI.getDataRenderer().setRenderingForAlgorithm(m_Alg.getCommandLineName(), set);
        SextanteGUI.getDataRenderer().save();
      }
    }
  }
示例#3
0
  protected void executeSelectedAlgorithmIteratively(final int iParameterToIterateOver) {

    try {
      if (m_Alg != null) {
        final GeoAlgorithm alg = m_Alg.getNewInstance();
        final int iRet =
            SextanteGUI.getGUIFactory().showAlgorithmDialog(alg, m_ParentDialog.getDialog(), null);
        if (iRet == IGUIFactory.OK) {
          final ParametersSet params = m_Alg.getParameters();
          final int iParamCount = params.getNumberOfParameters();
          int iVectorLayers = 0;
          for (int i = 0; i < iParamCount; i++) {
            final Parameter param = m_Alg.getParameters().getParameter(i);
            if (param instanceof ParameterVectorLayer) {
              if (iVectorLayers == iParameterToIterateOver) {
                GeoAlgorithmExecutors.executeIterative(
                    alg, m_ParentDialog.getDialog(), param.getParameterName());
                break;
              }
              iVectorLayers++;
            }
          }
        }
      }
    } catch (final Exception e) {
      Sextante.addErrorToLog(e);
    }
  }
示例#4
0
  protected void executeAsBatchInGIS() {

    if (m_Alg != null) {
      SextanteGUI.getGUIFactory()
          .showBatchProcessingFromGISDialog(m_Alg, m_ParentDialog.getDialog());
    }
  }
示例#5
0
  /**
   * Returns the path where help files for a given algorithm are found
   *
   * @param alg the GeoAlgorithm
   * @param bForceCurrentLocale if true, returns the path to the current locale, even if it does not
   *     exist. If false, it will return the path corresponding to the default locale (english) in
   *     case the one corresponding to the current locale does not exist.
   * @return the help path for this algorithm
   */
  public static String getHelpPath(final GeoAlgorithm alg, final boolean bForceLocale) {

    String sPackage = alg.getClass().getPackage().toString();
    sPackage = sPackage.substring(8);
    String sPath =
        SextanteGUI.getHelpPath()
            + File.separator
            + Locale.getDefault().getLanguage()
            + File.separator
            + sPackage;

    final File dir = new File(sPath);
    if (!dir.exists() && !bForceLocale) {
      sPath =
          SextanteGUI.getHelpPath()
              + File.separator
              + Locale.ENGLISH.getLanguage()
              + File.separator
              + sPackage;
    }

    return sPath;
  }
示例#6
0
  private void updateListOfMostRecentAlgorithms() {

    final boolean bShowMostRecent =
        new Boolean(SextanteGUI.getSettingParameterValue(SextanteGeneralSettings.SHOW_MOST_RECENT))
            .booleanValue();
    if (bShowMostRecent) {
      final GeoAlgorithm[] recent = History.getRecentlyUsedAlgs();
      final DefaultMutableTreeNode recentNode =
          new DefaultMutableTreeNode(Sextante.getText("RecentAlgorithms"));
      for (int i = 0; i < recent.length; i++) {
        final DefaultMutableTreeNode node = new DefaultMutableTreeNode(recent[i]);
        recentNode.add(node);
      }
      final DefaultMutableTreeNode mainNode =
          (DefaultMutableTreeNode) new TreePath(jTree.getModel().getRoot()).getLastPathComponent();
      mainNode.remove(0);
      mainNode.insert(recentNode, 0);
    }
  }
示例#7
0
  /**
   * Returns true if the help file associated with an algorithm contains a given search string
   *
   * @param alg the GeoAlgorithm
   * @param string a string to search
   * @return true if the help file associated with the algorithm contains the search string
   */
  public static boolean containsStringInHelpFile(final GeoAlgorithm alg, final String string) {

    String line;

    BufferedReader br = null;
    InputStreamReader is = null;
    FileInputStream fis = null;

    final String sName = alg.getName().toLowerCase();
    if (sName.indexOf(string) != -1) {
      return true;
    }

    try {
      final String sFilename = SextanteGUI.getAlgorithmHelpFilename(alg, false);
      fis = new FileInputStream(sFilename);
      is = new InputStreamReader(fis);
      br = new BufferedReader(is);

      while (null != (line = br.readLine())) {
        line = line.toLowerCase();
        if (line.indexOf(string) != -1) {
          br.close();
          is.close();
          fis.close();
          return true;
        }
      }
    } catch (final Exception e) {
      // Sextante.addErrorToLog(e);
    } finally {
      try {
        br.close();
        is.close();
        fis.close();
      } catch (final Exception e) {
      }
    }

    return false;
  }
示例#8
0
  protected void executeSelectedAlgorithm() {

    try {
      if (m_Alg != null) {
        final GeoAlgorithm alg = m_Alg.getNewInstance();
        final int iRet =
            SextanteGUI.getGUIFactory().showAlgorithmDialog(alg, m_ParentDialog.getDialog(), null);
        if (iRet == IGUIFactory.OK) {
          final String[] cmd = alg.getAlgorithmAsCommandLineSentences();
          if (cmd != null) {
            History.addToHistory(cmd);
          }
          GeoAlgorithmExecutors.execute(alg, m_ParentDialog.getDialog());
          updateListOfMostRecentAlgorithms();
        }
      } else if (m_Action != null) {
        m_Action.execute();
      }
    } catch (final Exception e) {
      Sextante.addErrorToLog(e);
    }
  }
示例#9
0
  /**
   * Fills the tree with the algorithms that match a search criteria
   *
   * @param sSearchString The search string to look for in the algorithms context help
   * @param bSearchInFiles true if it should search in help files. if false, it will only search in
   *     algorithm names
   * @return the number of algorithms that match the given criteria
   */
  public int fillTree(final String sSearchString, final boolean bSearchInHelpFiles) {

    m_sLastSearchString = sSearchString;
    m_bLastSearchIncludedHelpFiles = bSearchInHelpFiles;

    int iCount = 0;
    String sGroup, sSubgroup;
    final DefaultMutableTreeNode mainNode =
        new DefaultMutableTreeNode(Sextante.getText("Algorithms"));
    final HashMap<Object, HashMap<String, HashMap<String, DefaultMutableTreeNode>>> groups =
        new HashMap<Object, HashMap<String, HashMap<String, DefaultMutableTreeNode>>>();

    setCursor(new Cursor(Cursor.WAIT_CURSOR));

    // algorithms
    final HashMap<String, HashMap<String, GeoAlgorithm>> algs = Sextante.getAlgorithms();
    final Set<String> groupKeys = algs.keySet();
    final Iterator<String> groupIter = groupKeys.iterator();
    while (groupIter.hasNext()) {
      final String groupKey = groupIter.next();
      final HashMap<String, GeoAlgorithm> groupAlgs = algs.get(groupKey);
      final Set keys = groupAlgs.keySet();
      final Iterator iter = keys.iterator();
      while (iter.hasNext()) {
        final GeoAlgorithm alg = groupAlgs.get(iter.next());
        if (m_Filter.accept(alg)) {
          if (bSearchInHelpFiles) {
            if (!HelpIO.containsStringInHelpFile(alg, sSearchString)) {
              continue;
            }
          } else {
            if ((sSearchString != null) && !alg.getName().toLowerCase().contains(sSearchString)) {
              continue;
            }
          }
          iCount++;
          final AlgorithmGroupConfiguration conf =
              AlgorithmGroupsOrganizer.getGroupConfiguration(alg);
          if (conf != null) {
            if (!conf.isShow()) {
              continue;
            }
            sGroup = conf.getGroup();
            sSubgroup = conf.getSubgroup();
          } else {
            sGroup = groupKey;
            sSubgroup = alg.getGroup();
          }
          HashMap<String, HashMap<String, DefaultMutableTreeNode>> group = groups.get(sGroup);
          if (group == null) {
            group = new HashMap<String, HashMap<String, DefaultMutableTreeNode>>();
            groups.put(sGroup, group);
          }
          HashMap<String, DefaultMutableTreeNode> subgroup = group.get(sSubgroup);
          if (subgroup == null) {
            subgroup = new HashMap<String, DefaultMutableTreeNode>();
            group.put(sSubgroup, subgroup);
          }
          subgroup.put(alg.getName(), new DefaultMutableTreeNode(alg));
        }
      }
    }

    // toolbox actions
    final HashMap<NameAndIcon, ArrayList<ToolboxAction>> allActions =
        SextanteGUI.getToolboxActions();
    final Set<NameAndIcon> actionsKeys = allActions.keySet();
    final Iterator<NameAndIcon> actionsIter = actionsKeys.iterator();
    while (actionsIter.hasNext()) {
      final NameAndIcon nai = actionsIter.next();
      final ArrayList<ToolboxAction> actions = allActions.get(nai);
      for (int i = 0; i < actions.size(); i++) {
        final ToolboxAction ita = actions.get(i);
        if ((sSearchString != null) && !ita.getName().toLowerCase().contains(sSearchString)) {
          continue;
        }
        iCount++;
        sSubgroup = ita.getGroup();
        HashMap<String, HashMap<String, DefaultMutableTreeNode>> group = groups.get(nai.getName());
        if (group == null) {
          group = groups.get(nai);
        }
        if (group == null) {
          group = new HashMap<String, HashMap<String, DefaultMutableTreeNode>>();
          groups.put(nai, group);
        }
        HashMap<String, DefaultMutableTreeNode> subgroup = group.get(sSubgroup);
        if (subgroup == null) {
          subgroup = new HashMap<String, DefaultMutableTreeNode>();
          group.put(sSubgroup, subgroup);
        }
        subgroup.put(ita.getName(), new DefaultMutableTreeNode(ita));
      }
    }

    final Set<Object> set = groups.keySet();
    final Iterator<Object> iter = set.iterator();
    while (iter.hasNext()) {
      final Object key = iter.next();
      final DefaultMutableTreeNode node = new DefaultMutableTreeNode(key);
      addNodeInSortedOrder(mainNode, node);
      final HashMap<String, HashMap<String, DefaultMutableTreeNode>> g = groups.get(key);
      final Set<String> set2 = g.keySet();
      final Iterator<String> iter2 = set2.iterator();
      while (iter2.hasNext()) {
        final String sKey2 = iter2.next();
        final DefaultMutableTreeNode node2 = new DefaultMutableTreeNode(sKey2);
        addNodeInSortedOrder(node, node2);
        final HashMap<String, DefaultMutableTreeNode> g2 = g.get(sKey2);
        final Set<String> set3 = g2.keySet();
        final Iterator<String> iter3 = set3.iterator();
        while (iter3.hasNext()) {
          final String sKey3 = iter3.next();
          final DefaultMutableTreeNode node3 = g2.get(sKey3);
          addNodeInSortedOrder(node2, node3);
        }
      }
    }

    final boolean bShowMostRecent =
        new Boolean(SextanteGUI.getSettingParameterValue(SextanteGeneralSettings.SHOW_MOST_RECENT))
            .booleanValue();
    if (bShowMostRecent) {
      final GeoAlgorithm[] recent = History.getRecentlyUsedAlgs();
      final DefaultMutableTreeNode recentNode =
          new DefaultMutableTreeNode(Sextante.getText("RecentAlgorithms"));
      for (int i = 0; i < recent.length; i++) {
        final DefaultMutableTreeNode node = new DefaultMutableTreeNode(recent[i]);
        recentNode.add(node);
      }
      mainNode.insert(recentNode, 0);
    }

    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

    jTree.setModel(new DefaultTreeModel(mainNode));

    if (sSearchString != null) {
      expandAll();
    }

    m_ParentDialog.setAlgorithmsCount(iCount);

    return iCount;
  }
示例#10
0
  protected void showHelp() {

    if (m_Alg != null) {
      SextanteGUI.getGUIFactory().showHelpDialog(m_Alg);
    }
  }
示例#11
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);
  }
示例#12
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) {
            }
          }
        }
      }
    }
  }