private static boolean isToolbarAction(DefaultMutableTreeNode node) {
   return node.getParent() != null
       && ((DefaultMutableTreeNode) node.getParent()).getUserObject() instanceof Group
       && ((Group) ((DefaultMutableTreeNode) node.getParent()).getUserObject())
           .getName()
           .equals(ActionsTreeUtil.MAIN_TOOLBAR);
 }
 private static boolean isMoveSupported(JTree tree, int dir) {
   final TreePath[] selectionPaths = tree.getSelectionPaths();
   if (selectionPaths != null) {
     DefaultMutableTreeNode parent = null;
     for (TreePath treePath : selectionPaths)
       if (treePath.getLastPathComponent() != null) {
         final DefaultMutableTreeNode node =
             (DefaultMutableTreeNode) treePath.getLastPathComponent();
         if (parent == null) {
           parent = (DefaultMutableTreeNode) node.getParent();
         }
         if (parent != node.getParent()) {
           return false;
         }
         if (dir > 0) {
           if (parent.getIndex(node) == parent.getChildCount() - 1) {
             return false;
           }
         } else {
           if (parent.getIndex(node) == 0) {
             return false;
           }
         }
       }
     return true;
   }
   return false;
 }
Пример #3
0
 @Override
 public String convertValueToText(
     Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
   String s = super.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
   String newProp = jEdit.getProperty(HIGHLIGHT_PROP);
   if (newProp == null || newProp.isEmpty()) return s;
   DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
   while (node != null && !(node.getUserObject() instanceof HyperSearchOperationNode)) {
     node = (DefaultMutableTreeNode) node.getParent();
   }
   if (node == null) return s;
   if (!newProp.equals(prop)) {
     prop = newProp;
     Font f = (resultTree != null) ? resultTree.getFont() : UIManager.getFont("Tree.font");
     styleTag = HtmlUtilities.style2html(prop, f);
   }
   SearchMatcher matcher = ((HyperSearchOperationNode) node.getUserObject()).getSearchMatcher();
   int i = s.indexOf(": ");
   if (i > 0) i += 2;
   else i = 0;
   Match m;
   List<Integer> matches = new ArrayList<Integer>();
   while ((m = matcher.nextMatch(s.substring(i), true, true, true, false)) != null) {
     matches.add(i + m.start);
     matches.add(i + m.end);
     i += m.end;
   }
   return HtmlUtilities.highlightString(s, styleTag, matches);
 }
Пример #4
0
  private void goToSelectedNode(int mode) {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object value = node.getUserObject();

    // do nothing if clicked "foo (showing n occurrences in m files)"
    if (node.getParent() != resultTreeRoot && value instanceof HyperSearchNode) {
      HyperSearchNode n = (HyperSearchNode) value;
      Buffer buffer = n.getBuffer(view);
      if (buffer == null) return;

      EditPane pane;

      switch (mode) {
        case M_OPEN:
          pane = view.goToBuffer(buffer);
          break;
        case M_OPEN_NEW_VIEW:
          pane = jEdit.newView(view, buffer, false).getEditPane();
          break;
        case M_OPEN_NEW_PLAIN_VIEW:
          pane = jEdit.newView(view, buffer, true).getEditPane();
          break;
        case M_OPEN_NEW_SPLIT:
          pane = view.splitHorizontally();
          break;
        default:
          throw new IllegalArgumentException("Bad mode: " + mode);
      }

      n.goTo(pane);
    }
  } // }}}
Пример #5
0
 public static void moveSelectedRow(final JTree tree, final int direction) {
   final TreePath selectionPath = tree.getSelectionPath();
   final DefaultMutableTreeNode treeNode =
       (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
   final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) treeNode.getParent();
   final int idx = parent.getIndex(treeNode);
   parent.remove(treeNode);
   parent.insert(treeNode, idx + direction);
   ((DefaultTreeModel) tree.getModel()).reload(parent);
   selectNode(tree, treeNode);
 }
Пример #6
0
  /** Sets the value for the given node at the given column to the given value. */
  public void setValueAt(Object value, Object node, int col) {
    DefaultMutableTreeNode tree_node = (DefaultMutableTreeNode) node;
    Object node_value = tree_node.getUserObject();

    switch (col) {
        // Name (not supported)
      case 0:
        break;
        // Value
      case 1:
        DefaultMutableTreeNode parent_node = (DefaultMutableTreeNode) tree_node.getParent();

        // First child of root is always the element name
        if (parent_node == getRoot() && parent_node.getIndex((TreeNode) node) == 0) {
          ConfigElement elt = (ConfigElement) parent_node.getUserObject();
          elt.setName((String) value);
          tree_node.setUserObject(value);
        } else if (node_value instanceof PropertyDefinition) {
          // Hey, we're editing a property definition. If it's type is not a
          // configuration element, we're probably editing a summary list of
          // the valuesof the children.
          if (((PropertyDefinition) node_value).getType() != ConfigElement.class) {
            ConfigElement elt = (ConfigElement) parent_node.getUserObject();
            PropertyDefinition prop_def = (PropertyDefinition) node_value;
            StringTokenizer tokenizer = new StringTokenizer((String) value, ", ");
            int idx = 0;
            while (tokenizer.hasMoreTokens()) {
              String token = tokenizer.nextToken();

              // Make sure we don't overrun the property values
              if ((idx >= prop_def.getPropertyValueDefinitionCount()) && (!prop_def.isVariable())) {
                break;
              }

              // Convert the value to the appropriate type
              Object new_value = null;
              Class type = prop_def.getType();
              if (type == Boolean.class) {
                new_value = new Boolean(token);
              } else if (type == Integer.class) {
                new_value = new Integer(token);
              } else if (type == Float.class) {
                new_value = new Float(token);
              } else if (type == String.class) {
                new_value = new String(token);
              } else if (type == ConfigElementPointer.class) {
                new_value = new ConfigElementPointer(token);
              }

              setProperty(new_value, elt, prop_def.getToken(), idx);

              // Get the node for the current property value and update it
              if (idx < tree_node.getChildCount()) {
                DefaultMutableTreeNode child_node =
                    (DefaultMutableTreeNode) tree_node.getChildAt(idx);
                child_node.setUserObject(new_value);
              } else {
                // Insert the new property
                DefaultMutableTreeNode new_node = new DefaultMutableTreeNode(new_value);
                tree_node.add(new_node);
                fireTreeNodesInserted(
                    this,
                    new Object[] {getPathToRoot(tree_node)},
                    new int[] {tree_node.getIndex(new_node)},
                    new Object[] {new_node});
              }
              ++idx;
            }
          }
        } else {
          // Parent is a ConfigElement ... must be a single-valued property
          if (parent_node.getUserObject() instanceof ConfigElement) {
            ConfigElement elt = (ConfigElement) parent_node.getUserObject();
            int desc_idx = parent_node.getIndex(tree_node);

            // If the parent is the root, take into account the extra name
            // and type nodes
            if (parent_node == getRoot()) {
              desc_idx -= 2;
            }
            PropertyDefinition prop_def =
                (PropertyDefinition) elt.getDefinition().getPropertyDefinitions().get(desc_idx);
            setProperty(value, elt, prop_def.getToken(), 0);
            tree_node.setUserObject(value);
          } else {
            // Parent must be a PropertyDefinition
            PropertyDefinition prop_def = (PropertyDefinition) parent_node.getUserObject();
            int value_idx = parent_node.getIndex(tree_node);
            DefaultMutableTreeNode elt_node = (DefaultMutableTreeNode) parent_node.getParent();
            ConfigElement elt = (ConfigElement) elt_node.getUserObject();
            setProperty(value, elt, prop_def.getToken(), value_idx);
            tree_node.setUserObject(value);
          }
        }
        fireTreeNodesChanged(
            this,
            new Object[] {getPathToRoot(parent_node)},
            new int[] {parent_node.getIndex(tree_node)},
            new Object[] {tree_node});
        break;
      default:
        throw new IllegalArgumentException("Invalid column: " + col);
    }
  }