Share and Enjoy! Alexander Nyßen itemis AG 4 Mittwoch, 27. März 13
Share and Enjoy!Alexander Nyßen
itemis AG
4Mittwoch, 27. März 13
Share and Enjoy!
Alexander Nyßenitemis AG
4(Continue to)
Mittwoch, 27. März 13
GEF 3.x / Zest 1.x• Mature project with quite long history
• Base technology with lot's of users (direct & indirect through GMF/Graphiti)
• Stable API, no breaking API changes since 2004 (GEF 3.0)• Ready for CBI (migration to Git, Maven/Tycho completed)
• But API is organically evolved and there are ~400 bugzillas, out of which several require to break it
Mittwoch, 27. März 13
Some Topics for a Renewal• Re-thinking current componentization
• Support for the E4 application model
• Support for rotation and other transformations
• Support for curved connections
• Support for other rendering platforms than SWT• Multi-touch gestures support• Revision of the command framework
• Revision of connection handling (clipping container)• Various renamings and restructurings on the detail level...
Mittwoch, 27. März 13
Zest 2 (since 2010)• A provisional Zest 2 component was initiated in 2010, to
develop the next generation Zest API.• Goal was to develop a new version of Zest in parallel to
the maintenance of Zest 1.x., with an - up to the final graduation - provisional API
• Sources were intended to be placed in its own Zest2 Git repository, results were published separately via Eclipse Marketplace.
Mittwoch, 27. März 13
GEF4 (since 2011)• GEF4 was initiated - in analogy to Zest 2 - to develop the
next generation Draw2d and GEF (MVC) API.• Similar to Zest2, development was intended to take place in
parallel to maintenance of Draw2d / GEF (MVC) 3.x
• Initial plans (prior to 3.8): • Create new double-precision Geometry API before
Juno release. • Start to migrate the Draw2d and GEF (MVC) code base
on a step-by-step basis afterwards.
Mittwoch, 27. März 13
GEF4 + Zest 2 = GEF4
Modified plan (prior to Juno - 06/12): Unification of both approaches after Juno!
Mittwoch, 27. März 13
GEF4 - A Unified Approach• A unified approach with a shared code base and a
common namespace (org.eclipse.gef4) for all plug-ins.
• Advantages:
• Clear distinction between GEF proper as the production component and GEF4 as the provisional one
• Chance to not only refactor GEF components but the componentization itself, which is only "historically" justified.
Mittwoch, 27. März 13
GEF4 - Status Quo• GEF4 Geometry component was initiated in 2011, work
has been finalized with the Juno release:• Functionally complete (at least for now)• 344 JUnit tests, ~77% instruction coverage
• GEF4 Graphics component was initiated directly after Juno and is currently under work, nearing completion:• Functionally nearly complete but limited tests• "Adjustment" w.r.t. "platform-specific" issues needed
Mittwoch, 27. März 13
GEF4 - Status Quo (continued)• GEF4 Zest was transferred to Git repository (and update-
site) but not yet adopted:• Zest2 plug-ins were renamed to org.eclipse.gef4.zest.*• Dependencies on Draw2d 3.x still have to be factored out
Mittwoch, 27. März 13
GEF4 Geometry• No distinction in low and high precision, but just a single double-
precision API (with built-in imprecision for comparisons).
• Different geometric abstractions for different purposes:• Euclidean (Vector, Straight, Angle)• Projective (Vector3D, Straight3D)• Planar (Point, Dimension, Line, QuadraticCurve, CubicCurve,
BezierCurve, Polyline, PolyBezier, Ellipse, Rectangle, Pie, Arc, Polygon, CurvedPolygon, RoundedRectangle, Ring, Region, Path)
• Conversions to/from AWT and SWT (and between them)
Mittwoch, 27. März 13
GEF4 Planar Geometry - Features• Support for "non-standard" geometries:
• Arbitrary Bezier curves, curved polygons• Approximation via BezierCurves & Interpolation via PolyBeziers
• Characteristics-related core abstractions (IGeometry, ICurve, IShape, IMultiShape)
• Construction-related base-classes (AbstractRectangleBased-Geometry, AbstractPointListBasedGeometry,...)
• Direct support for affine transformations (ITranslatable, IScalable, IRotatable)
• No direct SWT dependencies (SWT-related conversions bundled in optional plug-in)
Mittwoch, 27. März 13
GEF4 Planar Geometry - Overview
Mittwoch, 27. März 13
GEF4 Planar Geometry - Abstractions
Mittwoch, 27. März 13
GEF4 Planar Geometry - Base Classes
Mittwoch, 27. März 13
GEF4 Geometry - Examples
Mittwoch, 27. März 13
GEF4 Geometry - Sample Code
// Bezier approximation of curvesBezierCurve[] fromCurve = curve.toBezier();BezierCurve[] fromShape = shape.getOutline().toBezier();ICurve[] fromPolyShape = polyShape.getOutlineSegments();List<BezierCurve> beziers = new ArrayList<BezierCurve>();for (ICurve c : fromPolyShape) beziers.addAll(Arrays.asList(c.toBezier()));
// PolyBezier interpolationPolyBezier interpolation = PolyBezier.interpolateCubic(p0, p1, p2, p3, ...);
// support for affine transformationsPolygon rhomb = new Rectangle(10, 10, 10, 10).getRotatedCCW(Angle.fromDeg(45));PolyBezier slanted = new Ellipse(100, 100, 100, 50).getRotatedCCW(Angle.fromDeg(30));Ring rotatedClippingArea = region.getRotatedCCW(Angle.fromDeg(300));
Mittwoch, 27. März 13
GEF4 Graphics• Support for rendering (planar) geometries, images, and
text on an underlying Canvas/Graphics• Key abstractions (Font, Image, Color) and transparent
support for multiple widget toolkits (AWT, SWT, JavaFX*)• Save push/pop/restore and get/set of graphics state
• Combinations of advanced graphics features like xor-mode, patterns (color, gradient, image), affine transformations, etc.
• Extensible image processing support (Pixel-Filter, Channel-Filter, Convolution-Filter)
*) Graphics based on JavaFX Canvas already prototyped by Tom Schindl
Mittwoch, 27. März 13
GEF4 Graphics - Features
Mittwoch, 27. März 13
GEF4 Graphics - Overview
Mittwoch, 27. März 13
GEF4 Graphics - Examples
Mittwoch, 27. März 13
GEF4 Graphics - Sample Code
// prepare geometriesfinal Ellipse ellipse = new Ellipse(50, 50, 350, 200);final Rectangle rectangle = new Rectangle(100, 160, 125, 220);final Polygon triangle = new Polygon(260, 170, 190, 300, 330, 300);
// prepare colorsfinal Color red = new Color(255, 0, 0);final Color darkRed = new Color(128, 0, 0);final Color blue = new Color(0, 0, 255);final Color green = new Color(0, 255, 0);final Color darkGreen = new Color(0, 128, 0);
g.setLineWidth(4);g.pushState(); // save the current set of properties on the stack
g.setFill(red).setDraw(darkRed).setDashArray(25, 10);g.fill(ellipse).draw(ellipse.getOutline());
g.restoreState(); // restore the previously saved properties
g.setFill(blue).setLineJoin(LineJoin.ROUND).setLineCap(LineCap.ROUND);g.fill(rectangle).draw(rectangle.getOutline());
g.popState(); // removes the previously saved properties from the stack // and enables the properties that were set in advance
g.setFill(green).setDraw(darkGreen).setLineJoin(LineJoin.MITER);g.fill(triangle).draw(triangle.getOutline());
Mittwoch, 27. März 13
GEF4 Graphics - Sample Code - Gradients
• Java2D:
• GEF4 Graphics (AWT & SWT):
g2d.translate(50, 50);g2d.setPaint(new RadialGradientPaint(new Point(50, 50), 50, new Point( 40, 40), new float[] { 0, .5f, 1 }, new Color[] { new Color(255, 255, 255), new Color(255, 0, 0), new Color(0, 0, 0) }, CycleMethod.REFLECT));g2d.fill(new Rectangle(0, 0, 200, 200));
g.translate(50, 50);Ellipse ellipse = new Ellipse(0, 0, 100, 100);g.setFill(new Gradient.Radial(ellipse, ellipse .getCenter().translate(-10, -10), CycleMode.REFLECT) .addStop(0.0, new Color(255, 255, 255)) .addStop(0.5, new Color(255, 0, 0)) .addStop(1.0, new Color(0, 0, 0)));g.fill(new Rectangle(0, 0, 200, 200));
Mittwoch, 27. März 13
GEF4 Graphics - Sample Code - Gradients
• Java2D:
• GEF4 Graphics (AWT & SWT):
g2d.translate(50, 50);g2d.setPaint(new RadialGradientPaint(new Point(50, 50), 50, new Point( 40, 40), new float[] { 0, .5f, 1 }, new Color[] { new Color(255, 255, 255), new Color(255, 0, 0), new Color(0, 0, 0) }, CycleMethod.REFLECT));g2d.fill(new Rectangle(0, 0, 200, 200));
g.translate(50, 50);Ellipse ellipse = new Ellipse(0, 0, 100, 100);g.setFill(new Gradient.Radial(ellipse, ellipse .getCenter().translate(-10, -10), CycleMode.REFLECT) .addStop(0.0, new Color(255, 255, 255)) .addStop(0.5, new Color(255, 0, 0)) .addStop(1.0, new Color(0, 0, 0)));g.fill(new Rectangle(0, 0, 200, 200));
YOU CAN'T DO THIS IN SWT!
Mittwoch, 27. März 13
GEF4 Graphics - Sample Code - XOR-Painting
• Java2D:
• GEF4 Graphics:
Graphics2D g2d = (Graphics2D) g;g2d.setColor(new Color(0, 0, 255));g2d.fillRect(5, 5, 90, 45);g2d.setComposite(XorComposite.INSTANCE);g2d.setColor(new Color(255, 255, 255));g2d.fillRect(20, 20, 50, 50);g2d.setColor(new Color(255, 0, 0));g2d.fillOval(80, 20, 50, 50);
g.setFill(new Color(0, 0, 255));g.fill(new Rectangle(5, 5, 90, 45));g.setXorMode(true);g.setFill(new Color(255, 255, 255));g.fill(new Rectangle(20, 20, 50, 50));g.setFill(new Color(255, 0, 0));g.fill(new Ellipse(80, 20, 50, 50));
Mittwoch, 27. März 13
GEF4 Graphics - Sample Code - XOR-Painting
• Java2D:
• GEF4 Graphics:
Graphics2D g2d = (Graphics2D) g;g2d.setColor(new Color(0, 0, 255));g2d.fillRect(5, 5, 90, 45);g2d.setComposite(XorComposite.INSTANCE);g2d.setColor(new Color(255, 255, 255));g2d.fillRect(20, 20, 50, 50);g2d.setColor(new Color(255, 0, 0));g2d.fillOval(80, 20, 50, 50);
g.setFill(new Color(0, 0, 255));g.fill(new Rectangle(5, 5, 90, 45));g.setXorMode(true);g.setFill(new Color(255, 255, 255));g.fill(new Rectangle(20, 20, 50, 50));g.setFill(new Color(255, 0, 0));g.fill(new Ellipse(80, 20, 50, 50));
private static class XorComposite implements Composite {public static XorComposite INSTANCE = new XorComposite();
@Override public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) {
return new XorContext(); }}
private static class XorContext implements CompositeContext { @Override public void compose(Raster src, Raster dstIn, WritableRaster dstOut) { int w = Math.min(src.getWidth(), dstIn.getWidth()); int h = Math.min(src.getHeight(), dstIn.getHeight()); int[] srcRgba = new int[4]; int[] dstRgba = new int[4];
for (int x = 0; x < w; x++) {for (int y = 0; y < h; y++) {
src.getPixel(x, y, srcRgba); dstIn.getPixel(x, y, dstRgba); for (int i = 0; i < 3; i++) { dstRgba[i] ^= srcRgba[i]; } dstOut.setPixel(x, y, dstRgba); } } }
@Override public void dispose() {}}
Mittwoch, 27. März 13
GEF4 Graphics - Sample Code - XOR-Painting
• Java2D:
• GEF4 Graphics:
Graphics2D g2d = (Graphics2D) g;g2d.setColor(new Color(0, 0, 255));g2d.fillRect(5, 5, 90, 45);g2d.setComposite(XorComposite.INSTANCE);g2d.setColor(new Color(255, 255, 255));g2d.fillRect(20, 20, 50, 50);g2d.setColor(new Color(255, 0, 0));g2d.fillOval(80, 20, 50, 50);
g.setFill(new Color(0, 0, 255));g.fill(new Rectangle(5, 5, 90, 45));g.setXorMode(true);g.setFill(new Color(255, 255, 255));g.fill(new Rectangle(20, 20, 50, 50));g.setFill(new Color(255, 0, 0));g.fill(new Ellipse(80, 20, 50, 50));
private static class XorComposite implements Composite {public static XorComposite INSTANCE = new XorComposite();
@Override public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) {
return new XorContext(); }}
private static class XorContext implements CompositeContext { @Override public void compose(Raster src, Raster dstIn, WritableRaster dstOut) { int w = Math.min(src.getWidth(), dstIn.getWidth()); int h = Math.min(src.getHeight(), dstIn.getHeight()); int[] srcRgba = new int[4]; int[] dstRgba = new int[4];
for (int x = 0; x < w; x++) {for (int y = 0; y < h; y++) {
src.getPixel(x, y, srcRgba); dstIn.getPixel(x, y, dstRgba); for (int i = 0; i < 3; i++) { dstRgba[i] ^= srcRgba[i]; } dstOut.setPixel(x, y, dstRgba); } } }
@Override public void dispose() {}}
THIS IS TEDIOUS IN AWT/JAVA2D!
Mittwoch, 27. März 13
GEF4 - Outlook (Mid-Term)• GEF4 Layouts is planned:
• Data model for layout computations (based on Draw2d DirectedGraphLayout)
• Set of layout algorithms based on it (Draw2d & Zest)
• GEF4 'Glyphs' is planned:• Figure/Shape abstractions inspired by Draw2d, SVG, and
JavaFX (SceneGraph)• Replacement of 'core' Draw2d abstractions
Mittwoch, 27. März 13
GEF4 - Outlook (Long-Term)• Adoption of migrated Zest components to new
GEF4 Geometry, Graphics, Canvas, Layouts components
• Migration of remaining Draw2d/GEF (MVC) code base, including re-modularization and adoption
Mittwoch, 27. März 13
Share & Enjoy - Please get involved!• Provide detailed feedback for our already finalized
components (bug reports, enhancement requests, etc.) to help us improve them.
• Evaluate early snapshots of our currently developed components (e.g. test GEF4 Graphics component on different window toolkits) to help finalizing them.
• Contribute to discussions (bugzilla, mailing list) related to our planned components to support their conception.
Mittwoch, 27. März 13
Thank You! Questions?http://wiki.eclipse.org/GEF/GEF4
Mittwoch, 27. März 13