Custom swing component: size

Hi,

I would like to create a custom cell with a width and height that depends on the cells around it.
Can I access from the editorContext the surrounding cells?
If not, given a node, can I find the corresponding cell and its size?

Thanks,

Federico

7 comments

Class CellTraversalUtil has some methods for traversing the cell hierarchy that you might find useful.

0

Hi Federico,

yes, this is possible. You may take the HorizontalLineCellProvider as a starting point. So what you basically need is the current editor cell and then use this cell to check for values. For instance:

editorContext.getEditorComponent().findNodeCell(currentRoot).getParent().getHeight();

Hope that helps.

Cheers

Ben

 

1

@Sergej: Oh, I didn't know that one. Looks quite helpful for what we are just about to do.

0

Actually, I have a question in this context:

public void bar {
// some code
// even more code
}

Imagine the caret is placed at "{". For this piece of code, I'd like to navigate to "// some code" over the EditorCells. But it doesn't give me what I expected. For instance:

EditorCell selectedCell = editorContext.getSelectedCell(); // selected cell is bar()
EditorCell statementListCell = CellTraversalUtil.getNextSibling(selectedCell);

Why is the StatementList the next sibling? How do I get to "// some code"? The "leaf" methods don't help...

Any hints are greatly appreciated!

 

0

You can explore the cell tree using Cell Explorer (right-click somewhere in the editor -> Language Debug -> Show Cell in Explorer), the hierarchy may not be obvious just from the look of the editor. There's also DfsTraverserIterable (or CellTraversalUtil.iterateTree in current master) which you can use to walk the cell tree and manually look for an appropriate cell.

0

Thank you for all the comments, they all helped!

0

Please sign in to leave a comment.