The next step is to tile the pins horizontally. First, a Pin class is made:
01: public class Pin extends MonoGlyph { 02: private String name_; 03: 04: public Pin (String name, float size) { 05: name_ = name; 06: 07: FigureStyle style = new FigureStyle(); 08: style.foreground = Color.yellow; 09: style.brushSize = 1; 10: 11: Glyph ring = LayoutKit.align(FigureKit.circle(FigureMode.Fill, style, 0, 0, size), 0.5F, 0.5F); 12: 13: style.foreground = Color.black; 14: Glyph pin = LayoutKit.align(FigureKit.circle(FigureMode.Fill, style, 0, 0, size/2.5F), 0.5F, 0.5F); 15: 16: Glyph pinAndRing = LayoutKit.overlay(); 17: pinAndRing.append(ring); 18: pinAndRing.append(pin); 19: 20: Glyph fixedPin = LayoutKit.align(LayoutKit.fixed(pinAndRing, size, size), 0, 0); 21: 22: setBody(fixedPin); 23: } 24: }
The code for Pin is almost exactly like example 2. However, Pin has a member variable for the name of the pin on line 2. The name_ variable, set by the constructor, keeps track the pin's name.
Next, tiling pins.
01: public class TutorialExample3 extends Applet { 02: 03: public void init () { 04: setBackground(Color.gray); 05: 06: FigureStyle style = new FigureStyle(); 07: style.foreground = Color.yellow; 08: style.brushSize = 1; 09: 10: Glyph horizontalRow = LayoutKit.hbox(); 11: 12: for (int col = 0; col < 8; col++) 13: horizontalRow.append( 14: LayoutKit.margin( 15: new Pin("FakeName", 20F), 16: 6 17: ) 18: ); 19: 20: SgraphicsAdapter adapter = new SgraphicsAdapter(horizontalRow); 21: 22: add("Center", adapter); 23: } 24: }
On line 7 a horizontal box is created. A horizontal box will tile horizontally and align vertically. The for loop on line 12 appends 8 pins to the horizontal box. The pin created on line 15 sets the row to 0, the column to the loop count, and the size to 20. Line 14 creates a margin of 6. The margin adds space on all four sides of the pin; therefore, the size of the glyph appended to the horizontal box is 32 by 32.
LayoutKit is a factory that creates boxes, margins, overlays, and other layout objects. The kit hides the classes that are used to implement the layout objects by returning a reference to a Glyph interface. FigureKit is a factory that creates squares, circles, and other drawable objects. FigureKit also hides implementation like LayoutKit by returning a Glyph reference. The only difference between the kits is that FigureKit produces objects that can only be used as leaves in the glyph tree, and LayoutKit produces objects that can be used anywhere in the tree. (However, it would not make sense to use them as a leaf glyph; what would it display?)
You might want to review the LayoutKit and FigureKit API.
For comments or questions contact Mike Jones (Mike.Jones@mass.com)