com.ccg.swing
Class RFrame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by com.ccg.swing.RFrame
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class RFrame
extends JFrame

A resource based JFrame.

This class extends the JFrame class for the purpose of moving all of the text strings and messages that might be associated with the frame (or its actions) such that they come from an associated resource bundle.

This can greatly simplify the work of the programmer (they won't need to worry about the text that their application displays - and can instead focus on how the application behaves). In addition, if used properly, your application will automatically be capable of supporting multiple languages.

To use this as your top level frame, you follow these basic steps:

To see a simple demonstration of this, take a look at the DialogTest.java Java code and its associated msgs/DialogTest.properties files.

Since:
1.0
Version:
$Revision: 1.3 $
Author:
$Author: pkb $
See Also:
Resources, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
RFrame()
          Bare initialization of the object.
RFrame(ResourceBundle rb)
          Initialization of object where a specific set of resources is assigned.
 
Method Summary
 JButton createButton(String tag)
          Create a button and initialize it with values from the frame's resource bundle.
 JButton createButton(String tag, Object o)
          Create a button, initialize it and add a action handler.
 void createMenuBar(String tag, Object o)
          Dynamically builds an entire menu bar from the resource file.
 ResourceBundle getResourceBundle()
          Get the resource bundle to retrieve strings from.
 RStockDialogs getRStockDialogs()
          Get the RStockDialogs object for standard pop-up messages/questions.
 TagLookup getTagLookup(String tag)
          Get a TagLookup object using the frames resources.
 void init(String tag)
          Initialize the frame with properties retrieved from the resource bundle.
 void setResourceBundle(ResourceBundle val)
          Set the resource bundle to retrieve strings from
 void setRStockDialogs(RStockDialogs val)
          Set the RStockDialogs object for standard pop-up messages/questions.
 void showMessage(String tag, Object[] args)
          Show a standard message box based on resource contents.
 boolean showOKCancel(String tag, Object[] args)
          Show a standard OK/cancel question based on resource contents.
 boolean showYesNo(String tag, Object[] args)
          Show a standard yes/no question based on resource contents.
 int showYesNoCancel(String tag, Object[] args)
          Show a standard Yes/No/Cancel question based on resource contents.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

RFrame

public RFrame()
Bare initialization of the object.

This constructor does the minimal amount of initialization of the object. Typically, one will add their components to the frame, pack it, initialize the frame properties, and then show the frame.

Since:
1.0
See Also:
init(java.lang.String)

RFrame

public RFrame(ResourceBundle rb)
Initialization of object where a specific set of resources is assigned.

This constructor does the minimal amount of initialization of the object, however, it does assign the resource bundle which will be used to retrieve resource information related to the frame.

Since:
1.0
See Also:
init(java.lang.String)
Method Detail

init

public void init(String tag)
Initialize the frame with properties retrieved from the resource bundle.

This method uses the setFrameValues method from the Resources class to initialize the attributes of the frame base on properties specified in the resource bundle. If you use this method, it should be done JUST prior to your "show()" as it can make the frame such that it can't be resized (do any sizing/packing PRIOR to invoking this method).

For example, if one specified a tag of "frame", then they might have corresponding properties set in their resource file:

         frame.title=DialogTest
         frame.foreground=black
         frame.background=cyan
         frame.resizable=false
        
 

Parameters:
tag - The leading tag identifier to use for retrieving attributes from the property file.
Since:
1.0
See Also:
Resources.setFrameValues(com.ccg.util.TagLookup, javax.swing.JFrame, com.ccg.awt.ImageHolder)

setResourceBundle

public void setResourceBundle(ResourceBundle val)
Set the resource bundle to retrieve strings from

Parameters:
val - New ResourceBundle value to assign.
See Also:
getResourceBundle()

getResourceBundle

public ResourceBundle getResourceBundle()
Get the resource bundle to retrieve strings from.

This method will return the resources associated with the frame. If never explicitly set, we will assume that we should load them from the default resources for the frame's class.

Returns:
Current ResourceBundle value assigned.
See Also:
setResourceBundle(java.util.ResourceBundle)

getTagLookup

public final TagLookup getTagLookup(String tag)
Get a TagLookup object using the frames resources.

This method returns a TagLookup object that is created with the tag you specify and the RFrame's resource bundle. This can be much easier to work with than a standard resource bundle.

Parameters:
tag - An optional prefix "tag" to be used when retreiving info from the resource bundle (it can be null if you don't want a prefix).
Returns:
A handy-dandy TagLookup object.
Since:
1.0

createMenuBar

public void createMenuBar(String tag,
                          Object o)
Dynamically builds an entire menu bar from the resource file.

This method will dynamically build and associate a menu bar for the frame from the associated resource bundle. All "callback" actions defined in the resource file will be invoked upon the object ('o') passed.

As an example, lets assume the following methods were defined in the callback handler object passed:


 public void exit() {
        System.exit(0);
 }
 
 public void errorTest() {
        System.err.println("This is only a test!");
 }
 

If the 'tag' was set to "mb", then the following would define a "File" menu with two actions "Test" and "Exit" that would invoke the above two methods when selected by the user:

         mb.0=file
 
         file.text=File
         file.mnemonic=f
         file.0=test
         file.1=exit
 
         test.text=Error Test
         test.mnemonic=t
         test.type=action
         test.action=errorTest
 
         exit.text=Exit
         exit.mnemonic=x
         exit.type=action
         exit.action=exit
        
 

You can define some fairly complex menus in this fashion. Please refer to the RMenuBar class for additional information.

Parameters:
tag - The "tag" identifier used to define the menu bar in the resource bundle.
o - The associated object which provide the "action handlers" for the menu bar actions defined.
Since:
1.0
See Also:
RMenuBar

createButton

public final JButton createButton(String tag)
Create a button and initialize it with values from the frame's resource bundle.

This method is used to create a new JButton object and initialize the buttons appearance based upon the contents of the frame's resource bundle. For example, you could pass the tag of "show" and then configure the following in your resource bundle:

         #
         # The resources for the Show button
         #
         show.background=0xFF0000
         show.foreground=white
         show.text=Show
         show.mnemonic=s
         show.tooltip=Press this to see a message!
        
 

Refer to the setButtonValues and setValues methods in the Resources class for more details about the attributes.

Parameters:
tag - The prefix tag to use when pulling the button's attributes from the resource file.
Returns:
A JButton object which has been initialized with values from the frames associated resource bundle.
Since:
1.0
See Also:
createButton(String,Object)

createButton

public JButton createButton(String tag,
                            Object o)
Create a button, initialize it and add a action handler.

This method is used to create a new JButton object and initialize the buttons appearance based upon the contents of the frame's resource bundle. For example, you could pass the tag of "show" and then configure the following in your resource bundle:

         #
         # The resources for the Show button
         #
         show.background=0xFF0000
         show.foreground=white
         show.text=Show
         show.mnemonic=s
         show.tooltip=Press this to see a message!
         show.action=showMessage
        
 

Refer to the setButtonValues and setValues methods in the Resources class for more details about the attributes.

Parameters:
tag - The prefix tag to use when pulling the button's attributes from the resource file.
o - An arbitrary object. If the resource bundle defines a ".action" attribute (you may pass null).
Returns:
A JButton object which has been initialized with values from the frames associated resource bundle.
Since:
1.0
See Also:
createButton(String)

setRStockDialogs

public void setRStockDialogs(RStockDialogs val)
Set the RStockDialogs object for standard pop-up messages/questions.

Parameters:
val - New RStockDialogs value to assign.
See Also:
getRStockDialogs()

getRStockDialogs

public RStockDialogs getRStockDialogs()
Get the RStockDialogs object for standard pop-up messages/questions.

Returns:
Current RStockDialogs value assigned.
See Also:
setRStockDialogs(com.ccg.swing.RStockDialogs)

showMessage

public final void showMessage(String tag,
                              Object[] args)
Show a standard message box based on resource contents.

This is a convenience function which displays a modal message box. See the showMessage method in the RStockDialogs class for more details.

Parameters:
tag - The leading "tag" which is used to look for attributes from the RFrame's resource bundle.
args - Pass null here unless you need to have variables subsituted in your "TAG.text" text.
Since:
1.0
See Also:
RStockDialogs.showMessage(java.lang.String, java.lang.Object[])

showYesNo

public final boolean showYesNo(String tag,
                               Object[] args)
Show a standard yes/no question based on resource contents.

This is a convenience function which displays a modal message box prompting the user to respond Yes or No. See the showYesNo method in the RStockDialogs class for more details.

Parameters:
tag - The leading "tag" which is used to look for attributes from the RFrame's resource bundle.
args - Pass null here unless you need to have variables subsituted in your "TAG.text" text.
Since:
1.0
See Also:
RStockDialogs.showYesNo(java.lang.String, java.lang.Object[])

showOKCancel

public final boolean showOKCancel(String tag,
                                  Object[] args)
Show a standard OK/cancel question based on resource contents.

This is a convenience function which displays a modal message box prompting the user to respond OK or Canel. See the showOKCancel method in the RStockDialogs class for more details.

Parameters:
tag - The leading "tag" which is used to look for attributes from the RFrame's resource bundle.
args - Pass null here unless you need to have variables subsituted in your "TAG.text" text.
Since:
1.0
See Also:
RStockDialogs.showOKCancel(java.lang.String, java.lang.Object[])

showYesNoCancel

public final int showYesNoCancel(String tag,
                                 Object[] args)
Show a standard Yes/No/Cancel question based on resource contents.

This is a convenience function which displays a modal message box prompting the user to respond Yes, No or Canel. See the showYesNoCancel method in the RStockDialogs class for more details.

Parameters:
tag - The leading "tag" which is used to look for attributes from the RFrame's resource bundle.
args - Pass null here unless you need to have variables subsituted in your "TAG.text" text.
Returns:
One of the following constants: JOptionPane.YES_OPTION, JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION, JOptionPane.CLOSED_OPTION.
Since:
1.0
See Also:
RStockDialogs.showYesNoCancel(java.lang.String, java.lang.Object[])


Copyright 1998-1998-2006 null. All Rights Reserved.