01: public class TutorialExample2 extends Applet { 02: 03: public void init () { 04: setBackground(Color.lightGray); 05: 06: FigureStyle style = new FigureStyle(); 07: style.foreground = Color.yellow; 08: style.brushSize = 1; 09: 10: Glyph horizontalBox = LayoutKit.hbox(); 11: Glyph ring = FigureKit.circle(FigureMode.Fill, style, 0, 0, 20F); 12: 13: style.foreground = Color.black; 14: Glyph pin = FigureKit.circle(FigureMode.Fill, style, 0, 0, 8F); 15: 16: Glyph pinAndRing = LayoutKit.overlay(); 17: pinAndRing.append(ring); 18: pinAndRing.append(LayoutKit.margin(pin, 6F)); 19: Glyph fixedPin = LayoutKit.fixed(pinAndRing, 20, 20); 20: 21: horizontalBox.append( 22: LayoutKit.margin( 23: fixedPin, 24: 6 25: )); 26: 27: SgraphicsAdapter adapter = new SgraphicsAdapter(horizontalBox); 28: add("Center", adapter); 29: } 30: }
This applet displays a single pin of the package.
Lines 1-10 are the same as the last circle example.
In the circle example, a circle with a margin was appended to the hbox. In this example there are two circles, one on top of the other. The yellow circle is called a ring and is created on line 11. The black circle is called a pin and is created on line 14. To place one on top of the other, an overlay is created on line 16.
An overlay stacks the appended glyphs (The glyphs are drawn in the order inserted).
To get the ring and pin to align properly, the pin has a margin that makes it the same size as the ring. The ring is 20; the pin is 8; the margin is 6. Two margins and one pin is: (2 * 6) + 8 = 20. (Note: there are other ways to do alignment using the LayoutKit.align(...) call.) The margin is created on line 18.
One problem with an overlay is that it has no concept of its size and can stretch and shrink. To make the overlay a fixed size, a fixed glyph is used on line 19.
Finally, a margin of 6 is placed around the fixed overlay on lines 21-25, and the viewer is setup up on line 27. (Note: the margin will not show up when the applet is displayed unless the background of the display differs from the applet's background color.
For comments or questions contact Mike Jones (Mike.Jones@mass.com)