jwo.utils.gui
Class ComponentFactory

java.lang.Object
  extended byjwo.utils.gui.ComponentFactory

public class ComponentFactory
extends Object

Provides the facilities to create customised components with a similar look and feel.

Version:
2.1, 22nd January, 2004.
Author:
Jo Wood

Constructor Summary
ComponentFactory(Component component)
          Initialises the factory with the settings from the given component.
 
Method Summary
 Border defaultBorder()
          The standard border to be placed around components.
 Font getFont()
          Reports the standard font used by factory components.
 Font getSmallFont()
          Reports the standard font used by 'small' factory components.
 JButton makeButton(String text)
          Creates a button with the standard font for this component.
 JCheckBox makeCheckBox(String text, boolean state)
          Creates a check box with the standard font for this component.
 JComboBox makeComboBox()
          Creates a combo box with the standard font for this component.
 JComboBox makeComboBox(String[] entries)
          Creates a combo box with the given initial list of options in the standard font for this component.
 JEditorPane makeEditorPane()
          Creates a text area capable of displaying HTML.
 HTMLRadioButton makeHTMLRadioButton()
          Creates a blank, unselected HTML radio button ready to display any HTML code.
 HTMLRadioButton makeHTMLRadioButton(String text, boolean state)
          Creates an HTML radio button capable of displaying any HTML code.
 ImageIcon makeImage(String fileName)
          Creates an icon image that can be displayed in a component.
 JLabel makeLabel(String text)
          Creates a centred label with the standard font for this component.
 JLabel makeLabel(String text, int alignment)
          Creates a label with given alignment in the standard font for this component.
 JList makeList(ListModel listModel)
          Creates a list box with the standard font for this component.
 JList makeList(Object[] listData)
          Creates a list box with the standard font for this component.
 JList makeList(Vector listData)
          Creates a list box with the standard font for this component.
 JRadioButton makeRadioButton(String text, boolean state)
          Creates a radio button with the standard font for this component.
 JButton makeSmallButton(String text)
          Creates a small button with a smaller version of the standard font for this component.
 JLabel makeSmallLabel(String text)
          Creates a smaller centred label in the standard font for this component.
 JLabel makeSmallLabel(String text, int alignment)
          Creates a smaller label with given alignment in the standard font for this component.
 JTextArea makeTextArea(String text)
          Creates a text area with the standard font for this component.
 JTextField makeTextField(int width)
          Creates a text field with the standard font for this component.
 JTextField makeTextField(String text, int width)
          Creates a text field with the standard font for this component.
 JPanel makeTitledBorder(String text)
          Creates panel with a titled border with the given text.
 JPanel makeTitledBorder(String text, SGLayout layout)
          Creates panel with a titled border with the given text and layout.
 JToggleButton makeToggleButton(String text, boolean state)
          Creates a toggle button with the standard font for this component.
 URL searchFile(String fileName)
          Looks for a given file in the classpath of the VM that uses this class.
 void setInteraction(boolean interaction)
          Sets the interaction mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentFactory

public ComponentFactory(Component component)
Initialises the factory with the settings from the given component.

Parameters:
component - Component containing settings for customised components.
Method Detail

setInteraction

public void setInteraction(boolean interaction)
Sets the interaction mode. If not interactive, text will be non-editable and interactive components will be ghosted.

Parameters:
interaction - Determines if components are interactive.

searchFile

public URL searchFile(String fileName)
Looks for a given file in the classpath of the VM that uses this class. Will search in the 'images' sub-directory too. Useful for loading icon images. This method allows images in JAR files to be loaded in the same way as unarchived files.

Parameters:
fileName - Name of the file to search for (should be relative path).
Returns:
Fully specified URL of the fileName to search for.

makeLabel

public JLabel makeLabel(String text)
Creates a centred label with the standard font for this component.

Parameters:
text - Text to display as label.
Returns:
Label to display.

makeLabel

public JLabel makeLabel(String text,
                        int alignment)
Creates a label with given alignment in the standard font for this component.

Parameters:
text - Text to display as label.
alignment - Label alignment (JLabel.LEFT, JLabel.CENTER, JLabel.RIGHT).
Returns:
Label to display.

makeSmallLabel

public JLabel makeSmallLabel(String text)
Creates a smaller centred label in the standard font for this component.

Parameters:
text - Text to display as label.
Returns:
Label to display.

makeSmallLabel

public JLabel makeSmallLabel(String text,
                             int alignment)
Creates a smaller label with given alignment in the standard font for this component.

Parameters:
text - Text to display as label.
alignment - Label alignment (JLabel.LEFT, JLabel.CENTER, JLabel.RIGHT).
Returns:
Label to display.

makeTextField

public JTextField makeTextField(int width)
Creates a text field with the standard font for this component.

Parameters:
width - Number of characters to display.
Returns:
Text field to display.

makeTextField

public JTextField makeTextField(String text,
                                int width)
Creates a text field with the standard font for this component.

Parameters:
text - Initial text to be displayed.
width - Number of characters to display.
Returns:
Text field to display.

makeButton

public JButton makeButton(String text)
Creates a button with the standard font for this component.

Parameters:
text - Text to be displayed in button.
Returns:
Button to display.

makeSmallButton

public JButton makeSmallButton(String text)
Creates a small button with a smaller version of the standard font for this component.

Parameters:
text - Text to be displayed in button.
Returns:
Button to display.

makeCheckBox

public JCheckBox makeCheckBox(String text,
                              boolean state)
Creates a check box with the standard font for this component.

Parameters:
text - Text to be displayed next to check box.
state - Initial state of check box.
Returns:
Check box to display.

makeRadioButton

public JRadioButton makeRadioButton(String text,
                                    boolean state)
Creates a radio button with the standard font for this component.

Parameters:
text - Text to be displayed next to radio button.
state - Initial state of radio button.
Returns:
Radio button to display.

makeHTMLRadioButton

public HTMLRadioButton makeHTMLRadioButton()
Creates a blank, unselected HTML radio button ready to display any HTML code.

Returns:
Radio button to display.

makeHTMLRadioButton

public HTMLRadioButton makeHTMLRadioButton(String text,
                                           boolean state)
Creates an HTML radio button capable of displaying any HTML code.

Parameters:
text - Text to be displayed next to radio button.
state - Initial state of radio button.
Returns:
Radio button to display.

makeToggleButton

public JToggleButton makeToggleButton(String text,
                                      boolean state)
Creates a toggle button with the standard font for this component.

Parameters:
text - Text to be displayed in toggle button.
state - Initial state of toggle button.
Returns:
Toggle button to display.

makeComboBox

public JComboBox makeComboBox()
Creates a combo box with the standard font for this component.

Returns:
Combo box to display.

makeComboBox

public JComboBox makeComboBox(String[] entries)
Creates a combo box with the given initial list of options in the standard font for this component.

Returns:
Combo box to display.

makeList

public JList makeList(Object[] listData)
Creates a list box with the standard font for this component.

Parameters:
listData - Array of objects to be initially displayed in list box. The objects should either be strings, have a toString() method or be icons. If they are not, the list will have to implement a custom display.
Returns:
List to display.

makeList

public JList makeList(Vector listData)
Creates a list box with the standard font for this component.

Parameters:
listData - Vector of objects to be initially displayed in list box. The objects should either be strings, have a toString() method or be icons. If they are not, the list will have to implement a custom display.
Returns:
List to display.

makeList

public JList makeList(ListModel listModel)
Creates a list box with the standard font for this component.

Parameters:
listModel - ListModel containing objects to be initially displayed in list box. The objects should either be strings, have a toString() method or be icons. If they are not, the list will have to implement a custom display.
Returns:
List to display.

makeTextArea

public JTextArea makeTextArea(String text)
Creates a text area with the standard font for this component.

Parameters:
text - Initial text to be displayed.
Returns:
Text area to display.

makeEditorPane

public JEditorPane makeEditorPane()
Creates a text area capable of displaying HTML.


makeTitledBorder

public JPanel makeTitledBorder(String text)
Creates panel with a titled border with the given text.

Parameters:
text - Text to display in title.
Returns:
Panel with title.

makeTitledBorder

public JPanel makeTitledBorder(String text,
                               SGLayout layout)
Creates panel with a titled border with the given text and layout.

Parameters:
text - Text to display in title.
layout - Scaled grid layout used to arrange content.
Returns:
Panel with title.

makeImage

public ImageIcon makeImage(String fileName)
Creates an icon image that can be displayed in a component.

Parameters:
fileName - Name of image to search for.
Returns:
Image to display or null if not found.

defaultBorder

public Border defaultBorder()
The standard border to be placed around components.

Returns:
Border to be placed around components.

getFont

public Font getFont()
Reports the standard font used by factory components.

Returns:
Font used by factory components.

getSmallFont

public Font getSmallFont()
Reports the standard font used by 'small' factory components.

Returns:
Font used by small factory components.


Copyright Jo Wood, 1996-2004, last modified, 3rd September, 2004