|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
com.ccg.swing.RFrame
public class RFrame
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:
Resources class can help simplify this and make the text
which appears on your components localized.
To see a simple demonstration of this, take a look at the DialogTest.java Java code and its associated msgs/DialogTest.properties files.
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 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.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.awt.MenuContainer |
|---|
getFont, postEvent |
| Constructor Detail |
|---|
public RFrame()
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.
init(java.lang.String)public RFrame(ResourceBundle rb)
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.
init(java.lang.String)| Method Detail |
|---|
public void init(String tag)
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
tag - The leading tag identifier to use for retrieving attributes from the
property file.Resources.setFrameValues(com.ccg.util.TagLookup, javax.swing.JFrame, com.ccg.awt.ImageHolder)public void setResourceBundle(ResourceBundle val)
resource bundle to retrieve strings from
val - New ResourceBundle value to assign.getResourceBundle()public ResourceBundle getResourceBundle()
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.
setResourceBundle(java.util.ResourceBundle)public final TagLookup getTagLookup(String tag)
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.
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).
TagLookup object.
public void createMenuBar(String tag,
Object o)
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.
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.RMenuBarpublic final JButton createButton(String tag)
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.
tag - The prefix tag to use when pulling the button's attributes from the
resource file.
JButton object which has been initialized with values
from the frames associated resource bundle.createButton(String,Object)
public JButton createButton(String tag,
Object o)
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.
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).
JButton object which has been initialized with values
from the frames associated resource bundle.createButton(String)public void setRStockDialogs(RStockDialogs val)
RStockDialogs object for standard pop-up
messages/questions.
val - New RStockDialogs value to assign.getRStockDialogs()public RStockDialogs getRStockDialogs()
RStockDialogs object for standard pop-up
messages/questions.
setRStockDialogs(com.ccg.swing.RStockDialogs)
public final void showMessage(String tag,
Object[] args)
This is a convenience function which displays a modal message box. See
the showMessage method in the
RStockDialogs class for more details.
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.RStockDialogs.showMessage(java.lang.String, java.lang.Object[])
public final boolean showYesNo(String tag,
Object[] args)
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.
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.RStockDialogs.showYesNo(java.lang.String, java.lang.Object[])
public final boolean showOKCancel(String tag,
Object[] args)
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.
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.RStockDialogs.showOKCancel(java.lang.String, java.lang.Object[])
public final int showYesNoCancel(String tag,
Object[] args)
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.
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.
JOptionPane.YES_OPTION, JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION, JOptionPane.CLOSED_OPTION.RStockDialogs.showYesNoCancel(java.lang.String, java.lang.Object[])
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||