예제 #1
0
  /**
   * Processes an idChanged event. Search is different from all other navigators in that you while
   * search tree is synchronized the highlighting doesn't occur unless selected from the search
   * navigator.
   */
  public void idChanged(HelpModelEvent e) {
    ID id = e.getID();
    URL url = e.getURL();
    HelpModel helpModel = searchnav.getModel();
    debug("idChanged(" + e + ")");

    if (e.getSource() != helpModel) {
      debug("Internal inconsistency!");
      debug("  " + e.getSource() + " != " + helpModel);
      throw new Error("Internal error");
    }

    TreePath s = tree.getSelectionPath();
    if (s != null) {
      Object o = s.getLastPathComponent();
      // should require only a TreeNode
      if (o instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode tn = (DefaultMutableTreeNode) o;
        SearchTOCItem item = (SearchTOCItem) tn.getUserObject();
        if (item != null) {
          ID nId = item.getID();
          if (nId != null && nId.equals(id)) {
            return;
          }
        }
      }
    }

    DefaultMutableTreeNode node = findIDorURL(topNode, id, url);
    if (node == null) {
      // node doesn't exist. Need to clear the selection.
      debug("node didn't exist");
      tree.clearSelection();
      return;
    }
    TreePath path = new TreePath(node.getPath());
    tree.expandPath(path);
    tree.setSelectionPath(path);
    tree.scrollPathToVisible(path);
  }
예제 #2
0
    public void valueChanged(TreeSelectionEvent e) {

      JTree tree = FunctionFactorySherpaHelper.GetJTree();

      DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
      if (node == null) {
        return;
      }
      Object node_object = node.getUserObject();

      if (node.isLeaf()) {

        try {
          // analytic Sherpa functions.
          Function rf = (Function) node_object;
          try {
            if (rf instanceof Polynomial) {
              rf = new Polynomial(1);
            } else {
              rf = (Function) rf.clone();
            }
          } catch (CloneNotSupportedException ex) {
            rf = null;
          }

          FunctionFactorySherpaHelper.SetFunction(rf);

        } catch (ClassCastException e1) {

          // templates, tables and user files
          try {
            DefaultCustomModel model = (DefaultCustomModel) node_object;

            String functionName = model.getFunctionName();

            SherpaFunction function = new SherpaFunction();

            URL url = model.getUrl();
            String path = url.getPath();
            function.addPath(path);

            String name = model.getName();

            if (path.contains("/tables/")) {
              name = "tablemodel";
            }
            if (path.contains("/functions/")) {
              name = "usermodel";
            }
            if (path.contains("/templates/")) {
              name = "templatemodel";
            }

            function.setUserID(name);
            function.setName(name);
            function.setFunctionName(functionName);

            // Converting a DefaultCustomModel to a SherpaFunction might
            // require more than this. We'll see as we go further down
            // the road...

            // First, we need to break up the comma-separated string
            // parameters into something that can actually be used to
            // build instances of Function.

            String[] parNames = model.getParnames().split("\\,");
            String[] parVals = model.getParvals().split("\\,");
            String[] parMins = model.getParmins().split("\\,");
            String[] parMaxs = model.getParmaxs().split("\\,");
            String[] parFrozen = model.getParfrozen().split("\\,");

            int npars = parNames.length;

            if (npars != parVals.length
                || npars != parMins.length
                || npars != parMaxs.length
                || npars != parFrozen.length) {
              ExceptionHandler.handleException(
                  new Exception("Parameter lists wih different lengths."));
              tree.clearSelection();
              FunctionFactorySherpaHelper.dispose();
              return;
            }

            // now we loop over the parameter lists, building
            // each parameter in turn and adding it to the Function.

            for (int i = 0; i < npars; i++) {
              SherpaFParameter functionParameter = null;
              try {

                double value = Double.valueOf(parVals[i]);
                double min = Double.valueOf(parMins[i]);
                double max = Double.valueOf(parMaxs[i]);

                functionParameter =
                    new SherpaFParameter(parNames[i], value, min, max, new NonSupportedUnits(""));

                String frozen = parFrozen[i];
                if (frozen != null) {
                  boolean fixed = (frozen.equalsIgnoreCase("True")) ? true : false;
                  functionParameter.setFixed(fixed);
                }

              } catch (NumberFormatException ex) {
                ExceptionHandler.handleException(ex);
                tree.clearSelection();
                FunctionFactorySherpaHelper.dispose();
                return;
              } catch (ArrayIndexOutOfBoundsException ex) {
                ExceptionHandler.handleException(ex);
                tree.clearSelection();
                FunctionFactorySherpaHelper.dispose();
                return;
              }

              function.addParameter(functionParameter);
            }

            FunctionFactorySherpaHelper.SetFunction(function);

          } catch (ClassCastException e2) {
          }
        }
        tree.clearSelection();
        FunctionFactorySherpaHelper.dispose();
      }
    }
예제 #3
0
파일: TreeUtil.java 프로젝트: jexp/idea2
  public static ActionCallback showAndSelect(
      final JTree tree,
      int top,
      int bottom,
      final int row,
      final int previous,
      boolean addToSelection,
      final boolean scroll) {
    final TreePath path = tree.getPathForRow(row);

    if (path == null) return new ActionCallback.Done();

    final int size = tree.getRowCount();
    if (size == 0) {
      tree.clearSelection();
      return new ActionCallback.Done();
    }
    if (top < 0) {
      top = 0;
    }
    if (bottom >= size) {
      bottom = size - 1;
    }

    if (row >= tree.getRowCount()) return new ActionCallback.Done();

    if (!tree.isValid()) {
      tree.validate();
    }

    final Rectangle rowBounds = tree.getRowBounds(row);
    if (rowBounds == null) return new ActionCallback.Done();

    Rectangle topBounds = tree.getRowBounds(top);
    if (topBounds == null) {
      topBounds = rowBounds;
    }

    Rectangle bottomBounds = tree.getRowBounds(bottom);
    if (bottomBounds == null) {
      bottomBounds = rowBounds;
    }

    Rectangle bounds = topBounds.union(bottomBounds);
    bounds.x = rowBounds.x;
    bounds.width = rowBounds.width;

    final Rectangle visible = tree.getVisibleRect();
    if (visible.contains(bounds)) {
      bounds = null;
    } else {
      final Component comp =
          tree.getCellRenderer()
              .getTreeCellRendererComponent(
                  tree, path.getLastPathComponent(), true, true, false, row, false);

      if (comp instanceof SimpleColoredComponent) {
        final SimpleColoredComponent renderer = ((SimpleColoredComponent) comp);
        final Dimension scrollableSize = renderer.computePreferredSize(true);
        bounds.width = scrollableSize.width;
      }
    }

    final ActionCallback callback = new ActionCallback();

    if (!tree.isRowSelected(row)) {
      if (addToSelection) {
        tree.getSelectionModel().addSelectionPath(tree.getPathForRow(row));
      } else {
        tree.setSelectionRow(row);
      }
    }

    if (bounds != null) {
      final Range<Integer> range = getExpandControlRange(tree, path);
      if (range != null) {
        int delta = bounds.x - range.getFrom().intValue();
        bounds.x -= delta;
        bounds.width -= delta;
      }

      if (visible.width < bounds.width) {
        bounds.width = visible.width;
      }

      final Rectangle b1 = bounds;
      final Runnable runnable =
          new Runnable() {
            public void run() {
              if (scroll) {
                tree.scrollRectToVisible(b1);
              }
              callback.setDone();
            }
          };

      if (ApplicationManager.getApplication().isUnitTestMode()) {
        runnable.run();
      } else {
        SwingUtilities.invokeLater(runnable);
      }
    } else {
      callback.setDone();
    }

    return callback;
  }