Summary: This page describes the classes to create and manage the buttons, combo
boxes, pull dowm menus and so on on the tool bar at the top of the screen.
|
Relevant major classes of Java SE: java.awt.*, javax.swing.*, java.util.*, java.awt.image.*, java.io.*,
javax.imageio.* etc.
|
Classes on this page: DrawMenu, MenuConstants, MenuUtil, GuidancePanel, StatusPanel, DrawImangeIcon |
1. Overview
2. Class DrawMenu
return=>page top
public class DrawMenu
Method
|
Description
|
createHomeTabPanel
|
public JPanel createHomeTabPanel()
Creates the menu group for the Home tab, adds the menu group
to the panel and then return the panel.
|
createShapeTabPanel
|
public JPanel createShapeTabPanel()
Creates the menu group for the Shape tab, adds the menu group
to the panel and then return the panel.
|
createHelpTabPanel
|
public JPanel createHelpTabPanel()
Creates the menu group for the Help tab, adds the menu group
to the panel and then return the panel.
|
createFileGroup
|
public JPanel createFileGroup()
Creates the menus for the file operation, adds them to the panel and then
return the panel.
|
createPageGroup
|
public JPanel createPageGroup()
Creates the menus for the page operation, adds them to the panel and then
return the panel.
|
createEditGroup
|
public JPanel createEditGroup()
Creates the menus for the editing operation(cut,/copy&paste), adds
them to the panel and then return the panel.
|
createShapeGroup
|
public JPanel createShapeGroup()
Creates the menus for the creating a shape operation, adds them
to the panel and then return the panel.
|
createShapeStyleGroup
|
public JPanel createShapeStyleGroup()
Creates the menus for the setting a shape attribute operaion, adds
them to the panel and then return the panel.
|
createShapeLayoutGroup
|
public JPanel createShapeLayoutGroup()
Creates the menus for the shapes layout operaion, adds them to the panel
and then return the panel.
|
createFontStyleGroup
|
public JPanel createFontStyleGroup()
Creates the menus for the font operaion, adds them to the panel and then return the panel.
|
createDebugTestGroup
|
public JPanel createDebugTestGroup()
Creates the menus for the debug and test operaion, adds them
to the panel and then return the panel.
|
3. Class MenuConstants
return=>page top
Field
|
Description
|
imageWidth,
imageHeight
|
public final static int imageWidth=20, imageHeight=20;
The size of image to be added to the buttons on the toolbar.
|
menuItemImageWidth,
menuItemImageHeight
|
public final static int menuItemImageWidth=64, menuItemImageHeight=10;
The size of image to be added to the menu items of pulldown menus.
|
buttonWidth, buttonHeight
|
public final static int buttonWidth=22, buttonHeight=22;
The size of buttons on the toolbar
|
DefaultFont
|
public final static Font DefaultFont=new Font(Font.DIALOG, Font.PLAIN,
12);
The default font for the text on labels.
|
menuFont
|
public final static Font menuFont=new Font(Font.DIALOG, Font.BOLD, 12);
The font for the text on the buttons on the toolbar.
|
menuItemFont
|
public final static Font menuItemFont=new Font(Font.DIALOG, Font.BOLD,
11);
The font for the text on the menu items.
|
4. Class MenuUtil
return=>page top
public class MenuUtil
Field
|
Description
|
MenuComponentList
|
ArrayList MenuComponentList
The ArrayList to which menu components - buttons, combo boxes
etc. - are added.
|
Method
|
Description
|
setMenuComponent
|
public void setMenuComponent(Component component)
Parameters:
component - The Component object such as buttons, combo boxes etc.
Processing:
Adds the component to the MenuComponentList.
|
removeMenuComponent
|
public void removeMenuComponent(Component component)
Parameters:
component - The Component object such as buttons, combo boxes etc.
Processing:
Removes the component from the MenuComponentList.
|
getMenuComponent
|
public Component getMenuComponent(String name)
Parameters:
name - The Component name.
Returns:
Returns the menu component specified by the name.
Processing:
If the menu component isn't found, returns null. If the mulitiple menu component are found, returns the first one.
This method uses the getMenuComponents method.
|
getMenuComponents
|
public Component[] getMenuComponents(String name)
Parameters:
name - The Component name.
Returns:
Returns the menu components specified by the name.
If the menu component isn't found, returns the array of 0-length.
Processing:
: Ignore the difference of " ", "_"
or lower/upper case to compare the name to component names.
|
getChildComponent |
public Component getChildComponent(Container parent, String name, String
simpleClassName)
Parameters:
parent - The Container object.
name - The component name to be retrieved.
simpleClassName - A simple class name of the Component object to be retrieved
such as "JComponent", "JMenuItem", "JCheckBoxMenuItem"
and so on.
Returns:
The child Component object whose parent is specified by the parent and whose name and class name are specified by the
name and simpleClassName. If the child Component object is not found, returns null. If the multiple
child Component objects are found, returns the first one.
Processing:
This method uses the getChildComponents method.
|
getChildComponents |
private Component[] getChildComponents(Container parent, String name, String
simpleClassName)
Parameters:
parent - The Container object.
name - The component name to be retrieved.
simpleClassName - A simple class name of the Component object to be retrieved
such as "JComponent", "JMenuItem", "JCheckBoxMenuItem"
and so on.
Returns:
The array of the child Component objects of the parent whose name and class
name matches with the name and simpleClassName. If the child Component object is not found, returns the array of 0-length.
Processing:
This method uses the getComponents method.
|
getComponents |
private void getComponents(Container container, Vector vector)
Parameters:
container - The Container object.
vector - stores the child components of the container when this method called recursively.
Processing:
If the container is a JMenu (javax.swing.JMenu) object, then calls the jMenu.getMenuComponents
method to get the child components, otherwise call the Container.getComponents
method.
If the children are found, calls this method recursively to find the grandchildren
Component objects.
|
resetSelectedMenu
Components
|
public void resetSelectedMenuComponents()
Deselects all the menu components excluding the font menu components in
the MenuComponentList by calling setSelected method.
|
printMenuComponent |
public void printMenuComponent(Container parent)
Prints the information of the parent and its child components.
|
6. Class GuidancePanel
return=>page top
public class GuidancePanel extends JPanel
The guidance panel is located above the tool bar and has two label - viewLabel and guidanceLabel.
Field
|
Description
|
glassPane
|
static JPanel glassPane
The glassPane object on which the GuidancePanel is defined. The glassPane
is got in the DrawMain by the javax.swing.JFrame.getGlassPane method.
|
viewLabel
|
static JLabel viewLabel
The label on which the current sheet size, zoom factor and page are displayed.
|
guidanceLabel
|
static JLabel guidanceLabel
The label on which the current settings are displayed.
|
guidancePanelBounds
|
final static Rectangle guidancePanelBounds=new Rectangle(160, 0, 1200,
22);
The rectangle which determines the position and size of the GuidancePanel
on the glassPane.
|
Method
|
Description
|
Constructor
|
public GuidancePanel()
Creates the viewLabel and guidanceLabel, and arrange them.
|
showViewMessage
|
public static void showViewMessage(String message)
Shows the message on the viewLabel.
|
showSettingsMessage
|
public static void showSettingsMessage(String message)
Shows the message on the guidanceLabel.
|
7. Class StatusPanel
return=>page top
public class StatusPanel extends JPanel
P class="L0">
The statusPanel is located at the bottom of the window. On the statusPanel,
the mouse motion and the mouse hit information are displayed. If the mouse
is operated in the text box, the mouse motion in the text box,
the selected text or the clicked position in the text are
displayed.
Method
|
Description
|
Constructor
|
public StatusPanel()
Creates two JPanel objects by the createPanel method and adds them above
and below to this panel.
|
createLabel
|
public JLabel createLabel()
Creates a JPanel object for displaying text.
|
showText
|
public void showText(int i, String text)
If i equals 0, then display the text on the above label, otherwise on ethe
below label.
|
8. Class DrawImageIcon
return=>page top
public class DrawImageIcon
∙ Retrieves the ImageIcon object for the button or the menu item from the images file.
∙ Resizes the image to the specified size.
Method
|
Description
|
get
(static)
|
public static ImageIcon get(String imageName, int width, int height)
Parameters:
imageName - The image name.
width - The width of the image to be retrieved.
height - The height of the image to be retrieved.
Processing:
Write the image specified by the imageName to the BufferedImage object by the getBufferedImage method and retrieves a new BufferedImage object whose size equals the width and height by the getScaledInstance method of the BufferedImage.
Finally, creates a ImageIcon object using the new BufferedImage and returns
it.
|
getBufferedImage
(static)
|
protected static BufferedImage getBufferedImage(String imageName)
Parameters:
imageName - The image name.
Processing:
Creates the file path using the imageName and read the image to the BufferedImage object by the ImageIO.read method.
|
|