Example usage for javax.swing JTree convertValueToText

List of usage examples for javax.swing JTree convertValueToText

Introduction

In this page you can find the example usage for javax.swing JTree convertValueToText.

Prototype

public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row,
        boolean hasFocus) 

Source Link

Document

Called by the renderers to convert the specified value to text.

Usage

From source file:MainClass.java

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {

    Object tip = null;/*w w w. j  a va  2  s. c om*/
    if (value != null) {

        if (value instanceof DefaultMutableTreeNode) {
            tip = ((DefaultMutableTreeNode) value).getUserObject();
        } else {
            tip = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
        }
        renderer.setToolTipText((String) tip);
    }
    renderer.setText((String) tip);
    return renderer;
}

From source file:CheckBoxNodeTreeSample.java

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {

    Component returnValue;//from  w  w  w  .  j  a  va 2  s.com
    if (leaf) {

        String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, false);
        leafRenderer.setText(stringValue);
        leafRenderer.setSelected(false);

        leafRenderer.setEnabled(tree.isEnabled());

        if (selected) {
            leafRenderer.setForeground(selectionForeground);
            leafRenderer.setBackground(selectionBackground);
        } else {
            leafRenderer.setForeground(textForeground);
            leafRenderer.setBackground(textBackground);
        }

        if ((value != null) && (value instanceof DefaultMutableTreeNode)) {
            Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
            if (userObject instanceof CheckBoxNode) {
                CheckBoxNode node = (CheckBoxNode) userObject;
                leafRenderer.setText(node.getText());
                leafRenderer.setSelected(node.isSelected());
            }
        }
        returnValue = leafRenderer;
    } else {
        returnValue = nonLeafRenderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
                hasFocus);
    }
    return returnValue;
}

From source file:ToolTipTreeCellRenderer.java

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    if (value != null) {
        Object tipKey;//from  ww w  . j  av  a  2 s  .co m
        if (value instanceof DefaultMutableTreeNode) {
            tipKey = ((DefaultMutableTreeNode) value).getUserObject();
        } else {
            tipKey = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
        }
        renderer.setToolTipText((String) tipTable.get(tipKey));
    }
    return renderer;
}

From source file:TreeTips.java

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    if (value != null) {
        Object tipKey;//w ww.  j  a v  a2 s.c  o  m
        if (value instanceof DefaultMutableTreeNode) {
            tipKey = ((DefaultMutableTreeNode) value).getUserObject();
        } else {
            tipKey = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
        }
        Object tip = tipTable.get(tipKey);
        if (tip != null) {
            renderer.setToolTipText(tip.toString());
        } else {
            renderer.setToolTipText(null);
        }
    }
    return renderer;
}

From source file:org.executequery.gui.browser.TreeFindAction.java

protected boolean changed(JComponent comp, String searchString, Position.Bias bias) {

    if (StringUtils.isBlank(searchString)) {

        return false;
    }//from  w  w w.j  a v a2  s .  com

    JTree tree = (JTree) comp;
    String prefix = searchString;

    if (ignoreCase()) {

        prefix = prefix.toUpperCase();
    }

    boolean wildcardStart = prefix.startsWith("*");
    if (wildcardStart) {

        prefix = prefix.substring(1);

    } else {

        prefix = "^" + prefix;
    }
    prefix = prefix.replaceAll("\\*", ".*");

    Matcher matcher = Pattern.compile(prefix).matcher("");
    List<TreePath> matchedPaths = new ArrayList<TreePath>();
    for (int i = 1; i < tree.getRowCount(); i++) {

        TreePath path = tree.getPathForRow(i);
        String text = tree.convertValueToText(path.getLastPathComponent(), tree.isRowSelected(i),
                tree.isExpanded(i), true, i, false);

        if (ignoreCase()) {

            text = text.toUpperCase();
        }

        //            if ((wildcardStart && text.contains(prefix)) || text.startsWith(prefix, 0)) {
        //
        //                matchedPaths.add(path);
        //            }

        matcher.reset(text);
        if (matcher.find()) {

            matchedPaths.add(path);
        }

    }

    foundValues(matchedPaths);

    return !(matchedPaths.isEmpty());
}

From source file:org.executequery.gui.browser.TreeFindAction.java

public TreePath getNextMatch(JTree tree, String prefix, int startingRow, Position.Bias bias) {

    int max = tree.getRowCount();
    if (prefix == null) {
        throw new IllegalArgumentException();
    }/*w w  w  .  ja  va2s  . c om*/
    if (startingRow < 0 || startingRow >= max) {
        throw new IllegalArgumentException();
    }

    if (ignoreCase()) {
        prefix = prefix.toUpperCase();
    }

    // start search from the next/previous element froom the
    // selected element
    int increment = (bias == null || bias == Position.Bias.Forward) ? 1 : -1;

    int row = startingRow;
    do {

        TreePath path = tree.getPathForRow(row);
        String text = tree.convertValueToText(path.getLastPathComponent(), tree.isRowSelected(row),
                tree.isExpanded(row), true, row, false);

        if (ignoreCase()) {

            text = text.toUpperCase();
        }

        if (text.startsWith(prefix)) {

            return path;
        }

        row = (row + increment + max) % max;

    } while (row != startingRow);

    return null;
}