Den 15.06.2011 18:35, skrev Greg Brown:
Why might you need to know what type of skin is installed on a component? Maybe 
there is another alternative that might address your use case?

My use case is to avoid the problem described in the subject. I don't want to edit when I double click the branch controls (double clicking happens when you collapse and expand in rapid succession). I wrote a utility class that I install on the TreeView like this:

getComponentMouseButtonListeners().add(new DoubleClickTreeAdapter(this) {
    public void doubleClicked(TreeNode node) {
        editNode(node);
    }
});

The doubleClicked() callback is invoked when an actual double click occured. editNode() opens my editor for the current node, this is _not_ an inline editor, it opens a BoxPane with a Form and some other stuff inside a TabPane to the right of the TreeView.

The DoubleClickTreeAdapter.java looks like this:

public abstract class DoubleClickTreeAdapter implements ComponentMouseButtonListener {
    private TreeView treeView;

    public DoubleClickTreeAdapter(TreeView treeView) {
        this.treeView = treeView;
    }

public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
        if (count == 2 && button == Mouse.Button.LEFT) {
            Sequence.Tree.Path path = treeView.getNodeAt(y);
            if (path != null) {
TreeNode node = (TreeNode) Sequence.Tree.get(treeView.getTreeData(), path);
                if (node instanceof TreeBranch) {
if (Theme.getTheme().getSkinClass(TreeView.class).isAssignableFrom(TerraTreeViewSkin.class)) { Integer indent = (Integer) treeView.getStyles().get("indent"); Integer spacing = (Integer) treeView.getStyles().get("spacing"); int baseNodeX = path.getLength() * (indent + spacing);
                        if (x > baseNodeX)
                            doubleClicked(node);
                    } else {
// Add support for other skins here, default to allow double click anywhere for unknown skins
                        doubleClicked(node);
                    }
                } else {
                    doubleClicked(node);
                }
            }
        } else if (count == 1 && treeView.getNodeAt(y) == null)
            treeView.clearSelection();
        return true;
    }

    public abstract void doubleClicked(TreeNode node);
}

As you can see, I check that the TreeViewSkin is infact TerraTreeViewSkin, so that I know I can relay on the indent and spacing to determine if I clicked on or to the left of a branch control, or on the actual node icon/text.

I will default to call doubleClicked() if there is a non-standard skin installed, but I can easily add more checks for different skins.

(I removed the empty mouseDown/mouseUp calls from the code above).

-- Edvin

Reply via email to