Exemplo n.º 1
0
  // {{{ removeSelectedNode() method
  private void removeSelectedNode() {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    MutableTreeNode value = (MutableTreeNode) path.getLastPathComponent();

    if (path.getPathCount() > 1) {
      // Adjust selection so that repeating some removals
      // behave naturally.
      TreePath parentPath = path.getParentPath();
      MutableTreeNode parent = (MutableTreeNode) parentPath.getLastPathComponent();
      int removingIndex = parent.getIndex(value);
      int nextIndex = removingIndex + 1;
      if (nextIndex < parent.getChildCount()) {
        TreeNode next = parent.getChildAt(nextIndex);
        resultTree.setSelectionPath(parentPath.pathByAddingChild(next));
      } else {
        resultTree.setSelectionPath(parentPath);
      }

      resultTreeModel.removeNodeFromParent(value);
    }

    HyperSearchOperationNode.removeNodeFromCache(value);
    if (resultTreeRoot.getChildCount() == 0) {
      hideDockable();
    }
  } // }}}
Exemplo n.º 2
0
  /**
   * Set the currently selected Variable.
   *
   * @param v select this Variable, must be already in the tree.
   */
  public void setSelected(VariableIF v) {
    if (v == null) return;

    // construct chain of variables
    List<VariableIF> vchain = new ArrayList<>();
    vchain.add(v);

    VariableIF vp = v;
    while (vp.isMemberOfStructure()) {
      vp = vp.getParentStructure();
      vchain.add(0, vp); // reverse
    }

    // construct chain of groups
    List<Group> gchain = new ArrayList<>();
    Group gp = vp.getParentGroup();

    gchain.add(gp);
    while (gp.getParentGroup() != null) {
      gp = gp.getParentGroup();
      gchain.add(0, gp); // reverse
    }

    List<Object> pathList = new ArrayList<>();

    // start at root, work down through the nested groups, if any
    GroupNode gnode = (GroupNode) model.getRoot();
    pathList.add(gnode);
    Group parentGroup = gchain.get(0); // always the root group

    for (int i = 1; i < gchain.size(); i++) {
      parentGroup = gchain.get(i);
      gnode = gnode.findNestedGroup(parentGroup);
      assert gnode != null;
      pathList.add(gnode);
    }

    vp = vchain.get(0);
    VariableNode vnode = gnode.findNestedVariable(vp);
    if (vnode == null) return; // not found
    pathList.add(vnode);

    // now work down through the structure members, if any
    for (int i = 1; i < vchain.size(); i++) {
      vp = vchain.get(i);
      vnode = vnode.findNestedVariable(vp);
      if (vnode == null) return; // not found
      pathList.add(vnode);
    }

    // convert to TreePath, and select it
    Object[] paths = pathList.toArray();
    TreePath treePath = new TreePath(paths);
    tree.setSelectionPath(treePath);
    tree.scrollPathToVisible(treePath);
  }
Exemplo n.º 3
0
  public static void ensureSelection(JTree tree) {
    final TreePath[] paths = tree.getSelectionPaths();

    if (paths != null) {
      for (TreePath each : paths) {
        if (tree.getRowForPath(each) >= 0 && tree.isVisible(each)) {
          return;
        }
      }
    }

    for (int eachRow = 0; eachRow < tree.getRowCount(); eachRow++) {
      TreePath eachPath = tree.getPathForRow(eachRow);
      if (eachPath != null && tree.isVisible(eachPath)) {
        tree.setSelectionPath(eachPath);
        break;
      }
    }
  }
Exemplo n.º 4
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);
  }
  /**
   * Constructs a X509 certificate panel.
   *
   * @param certificates <tt>X509Certificate</tt> objects
   */
  public X509CertificatePanel(Certificate[] certificates) {
    setLayout(new BorderLayout(5, 5));

    // Certificate chain list
    TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
    topPanel.add(
        new JLabel(
            "<html><body><b>"
                + R.getI18NString("service.gui.CERT_INFO_CHAIN")
                + "</b></body></html>"),
        BorderLayout.NORTH);

    DefaultMutableTreeNode top = new DefaultMutableTreeNode();
    DefaultMutableTreeNode previous = top;
    for (int i = certificates.length - 1; i >= 0; i--) {
      Certificate cert = certificates[i];
      DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
      previous.add(next);
      previous = next;
    }
    JTree tree = new JTree(top);
    tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
    tree.setRootVisible(false);
    tree.setExpandsSelectedPaths(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {

          @Override
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            JLabel component =
                (JLabel)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              Object o = ((DefaultMutableTreeNode) value).getUserObject();
              if (o instanceof X509Certificate) {
                component.setText(getSimplifiedName((X509Certificate) o));
              } else {
                // We don't know how to represent this certificate type,
                // let's use the first 20 characters
                String text = o.toString();
                if (text.length() > 20) {
                  text = text.substring(0, 20);
                }
                component.setText(text);
              }
            }
            return component;
          }
        });
    tree.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                valueChangedPerformed(e);
              }
            });
    tree.setSelectionPath(
        new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous))));
    topPanel.add(tree, BorderLayout.CENTER);

    add(topPanel, BorderLayout.NORTH);

    // Certificate details pane
    Caret caret = infoTextPane.getCaret();
    if (caret instanceof DefaultCaret) {
      ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    }

    /*
     * Make JEditorPane respect our default font because we will be using it
     * to just display text.
     */
    infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

    infoTextPane.setOpaque(false);
    infoTextPane.setEditable(false);
    infoTextPane.setContentType("text/html");
    infoTextPane.setText(toString(certificates[0]));

    final JScrollPane certScroll = new JScrollPane(infoTextPane);
    certScroll.setPreferredSize(new Dimension(300, 500));
    add(certScroll, BorderLayout.CENTER);
  }