Emulation of SWT's GridLayout in JGo


I’m using SWT-version of JGo 5.1 on Windows.

So far I implemented a component that visualizes connections between several items which are logically grouped into corresponding blocks (see diagram below).

According to their type these blocks are placed on the left/right side of a JGoView. The order of these blocks is predefined.

Blocks are placed vertically one after another.

Left Side Right side

(-) (+)

o----------o o----------o

|Block1 | |Block1" |

|----------| |----------|

|Item A |O---------------------->O|Item M |

|----------| |----------|

|Item B |O---------------------->O|Item N |

|----------| o----------o

|Item C |O …




|Block2 |




|Block3 |


|Item D |O


|Item E |O


|Item F |O


Each block is a JGoSubGraph which contains a RecordNode. Every item of a source side RecordNode (Block1, Block2, Block3) can be connected to zero-or-more RecordNode items on the destination side (Block1"). Each item has a connection port (on right for left-side blocks and on left for right-side blocks).

For some blocks items can be added which results in growing of block and eventually in updating all blocks.

Also position of blocks on the opposite side can change if a longer entry is added which consumes more space than before

In collapsed state JGoSubGraph shows only items which are connected to opposite side (Block2, Block1").

In expanded state JGoSubGraph shows all items (connected and those without connections) (Block1, Block3).

It is required that blocks of the same side have same horizontal alignment and same width.

On any change of block size layout of blocks should be updated to avoid overlapping.

I tried to do it on my own programmatically, but still have problems with alignment and sizing of blocks.

I realized that what I’m trying to implement is same behaviour as SWT’s GridLayout.

Do you know whether JGo library or JGoSWTLayout provide layouting components in the way I described.

Any feedback will be appreciated.

There’s no equivalent to the GridLayout in JGo, but you should be able to accomplish this programmatically.

You could create your own layout method that was invoked whenever a new block was added, expanded, or collapsed.
Given that the vertical order of the blocks on the left is predetermined, you could iterate through that list from top to bottom. If that block is not connected to a block on the right, just position it in the next available position on the left. If that block is connected to a block on the right, determine the lower of the next available block positions for both blocks and place both blocks at the lowest position. Assuming that blocks can exist on the right without being linked to from the left, finding the next available position on the right may require placing several additional non-linked blocks on the right. Once you're done placing all block on the left and their corresponding linked blocks on the right, just add in the remaining blocks on the right and you're done.
The above is probably an oversimplification dues to my lack of understanding of the full requirements, but something like that should be possible.