Java Reference
In-Depth Information
public final static int LINE = 101;
public final static int RECTANGLE = 102;
public final static int CIRCLE = 103;
public final static int CURVE = 104;
public final static int TEXT = 105;
// Initial conditions
public final static int DEFAULT_ELEMENT_TYPE = LINE;
public final static Color DEFAULT_ELEMENT_COLOR = Color.BLUE;
public final static Font DEFAULT_FONT = new Font("Serif", Font.BOLD, 12);
}
Directory "Sketcher 4 creating text elements"
There are now icons defined for the text menu item and toolbar button, and there's a constant, TEXT , that
identifies the text element type. There's also a default Font object that you can use to initialize a Font mem-
ber of the SketcherFrame class. Add the following member to SketcherFrame :
private Font textFont = DEFAULT_FONT;
// Default font for text elements
The textFont member stores the current font for text elements. You add a mechanism for changing the
font later. The view class wants access to the textFont member for creating text elements, so add the fol-
lowing method to the SketcherFrame class:
public Font getFont() {
return textFont;
}
Directory "Sketcher 4 creating text elements"
This complements the methods that provide access to the SketcherFrame members that record the cur-
rent element type and color.
You don't need any more code to add the menu item for text to the Element menu or to add a text button
to the toolbar. The existing code in the createRadioButtonDropDown() and createToolbar() methods
take care of these. The event handling by textAction object deals with setting the element type and updat-
ing the menu checks.
You do have to do something about the status bar though. You must add an extra case for TEXT to the
switch statement in the setTypePane() member of the StatusBar class:
public void setTypePane(int elementType) {
String text = null; // Text for the type pane
switch(elementType) {
// Case statements for other element types as before...
Search WWH ::




Custom Search