@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); }
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); } } // }}}