Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Layout listeners and calculate preferred size
Layout listeners and calculate preferred size [message #199645] Mon, 17 October 2005 16:15
Brad Reynolds is currently offline Brad ReynoldsFriend
Messages: 309
Registered: July 2009
Senior Member
I have 4 viewports and each have their own layout, of course. I have
the need for figures in each viewport to determine the size of figures
in other viewports. Previously I had done this with syncing of the
layouts by performing an evaluation after layout had occurred. I
decided to get rid of the syncing and to evaluate the sizes of all
figures at once and then push the needed information down to the
individual layouts. So when the figures are invalidated, my aggregator
is invalidated and when layout is invoked on any of the layouts my
aggregator receives the request and if it's invalid as well it evaluates
the sizes and pushes the data down to it's layouts. This works great
except for when calls are made to layout.calculatePreferredSize(). In
my calculate method I call the internal layout. This doesn't fire
events to the listeners thus my aggregator couldn't run. I was trying
to keep dependencies on the aggregator out of my layout, it was just
simpler that way. Does anyone see a way to handle this without creating
any dependencies? The way I've hacked it up now is that on my figure I
overrode layout and made it public. So in calculate preferred size I
check to see if the figure is an instance of my figure and then call
layout(). This allows for the LayoutNotifier to be invoked and the
event fires.

The other thing I wanted to ask about is the fact that if I add a layout
listener to a figure and then set the layout the listeners don't fire.
This seems a little odd to me. The reason for it is that the listeners
are attached to the internaly LayoutNofitifer and aren't stored at the
figure level. So when a layout is set it seems to lose all listeners.
I would understand this behavior if I was attaching the listeners to an
individual layout but if I'm attaching at the figure level I don't care
about the layout instance. This can be seen with the following snippet:

public class LayoutListenerTest {
void run() {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

FigureCanvas canvas = new FigureCanvas(shell);
IFigure content = new Figure();
canvas.setContents(content);

content.addLayoutListener(new LayoutListener.Stub() {
public boolean layout(IFigure container) {
System.out.println("layout"); //$NON-NLS-1$
return false;
}
});
content.setLayoutManager(new StackLayout());

IFigure rect = new RectangleFigure();
content.add(rect);

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}

display.dispose();
}

public static void main(String[] args) {
new LayoutListenerTest().run();
}
}

If I were to move the attaching of the listener to after setting the
layout I receive notifications.

Thanks,
Brad
Previous Topic:Does support Marque Tool autoscrolling?
Next Topic:problem with repaint()
Goto Forum:
  


Current Time: Tue Nov 12 17:29:42 GMT 2024

Powered by FUDForum. Page generated in 0.02719 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top