From: Liam M. <lm...@WP...> - 2004-11-12 23:50:35
|
After looking through a few more SWT docs, I found a package I must have overlooked before -- org.eclipse.swt.graphics -- that handles drawing simple shapes. There's a class called GC that can draw rectangles, gradient rectangles, rounded rectangles, etc. However, it looks like it might be more difficult to use than GEF (though not impossible). The key part of the existing code base, where all of this fits in, is ObjBenchView.createPartControl(Composite). This is the entry point to the view, where we get a reference to a "Composite" object, which as far as I can tell is more or less like a JComponent object, as far as its place in the heirarchy goes. I've been looking into GEF the last few days (as you know), and it has a nice component-oriented system. You create a "Figure" (which is the parent class for different types of shapes, including RoundedRectangle) and add it to a FigureCanvas; the FigureCanvas is a go-between between the SWT Composite object and the GEF Figure objects. This makes it really easy to add/remove things; all you need to do is add these RoundedRectangles to the parent, and the layout manager handles their placement. SWT's drawing is a little more like the AWT. You create a new GC object, using the passed-in Composite object's Display: GC gc = new GC(parent.getDisplay()); Then you just call draw methods on the GC object, like this: gc.drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight); This is a little more difficult to deal with. Now the view is not only responsible for adding and removing, but for doing the drawing as well.. unless we go passing the gc object to the component to be added, in which case the component needs to be concerned about its placement. What happens if we remove the 2nd component out of 5? We'll have to worry about redrawing the other 3. As this is more low-level, it will be harder to code well, or rather we'll have to do more. So there's a trade-off; do we stick with GEF, that makes everything easier, or do we write something around SWT, so that we don't force users to include extra plug-ins? |