home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
WelcomeFrame.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
16KB
|
419 lines
/*
* Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland as part
* of a Borland product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
* COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
* OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
* OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
* OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
* OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
* CODE FILE.
*/
package borland.samples.intl.gui;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;
import borland.samples.intl.*;
import borland.samples.intl.beans.*;
import borland.samples.intl.beans.event.*;
import borland.samples.intl.application.*;
import borland.samples.intl.gui.resources.TextRes_en;
public class WelcomeFrame extends DecoratedFrame implements LocaleChangeListener{
private static WelcomeFrame welcomeFrame = null;
BevelPanel bevelPanel1 = new BevelPanel();
BevelPanel bevelPanel2 = new BevelPanel();
GridLayout gridLayout1 = new GridLayout();
SplitPanel splitPanel1 = new SplitPanel();
BorderLayout borderLayout1 = new BorderLayout();
ButtonControl browseButton = new ButtonControl();
ButtonControl viewButton = new ButtonControl();
ButtonControl exitButton = new ButtonControl();
GridLayout gridLayout2 = new GridLayout();
LabelControl labelControl1 = new LabelControl();
LocaleChooser localeChooser1 = new LocaleChooser();
WrappingTextViewer wrappingTextViewer1 = new WrappingTextViewer();
InternationalClock internationalClock1 = new InternationalClock();
private static AppDataModule appDataModule = AppDataModule.getDataModule();
ResourceBundle textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes",
LocaleChangeManager.getLocale());
private static boolean runningAsApplet = false;
/**
* Returns the single instance of the WelcomeFrame for the application.
* Also packs and centers the frame.
*
* @return instance of WelcomeFrame
*/
public static WelcomeFrame getInstance() {
if (welcomeFrame == null) {
welcomeFrame = new WelcomeFrame();
}
return welcomeFrame;
}
//Construct the frame
public WelcomeFrame() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
};
}
public void addNotify() {
super.addNotify();
welcomeFrame.pack();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = welcomeFrame.getPreferredSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height / 2;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
welcomeFrame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
welcomeFrame.setSize(frameSize.width, frameSize.height);
}
/**
* Contains component initialization code generated by the visual designer.
*/
public void jbInit() throws Exception{
this.setLayout(borderLayout1);
browseButton.setLabel(textRes.getString("Browse"));
viewButton.setLabel(textRes.getString("View"));
exitButton.setLabel(textRes.getString("Exit"));
gridLayout2.setColumns(3);
gridLayout2.setHgap(20);
bevelPanel1.setLayout(gridLayout2);
bevelPanel1.setMargins(new Insets(10, 10, 10, 10));
bevelPanel1.add(browseButton, null);
bevelPanel1.add(viewButton, null);
bevelPanel1.add(exitButton, null);
gridLayout1.setRows(2);
gridLayout1.setColumns(1);
bevelPanel2.setLayout(gridLayout1);
bevelPanel2.add(bevelPanel1, null);
bevelPanel2.add(internationalClock1, null);
this.add(bevelPanel2, BorderLayout.SOUTH);
wrappingTextViewer1.setText(textRes.getString("WelcomeText"));
wrappingTextViewer1.setFont(new Font("Dialog", 0, 14));
splitPanel1.add(localeChooser1, new PaneConstraints("localeChooser1", "localeChooser1", PaneConstraints.ROOT, 0.35f));
splitPanel1.add(wrappingTextViewer1, new PaneConstraints("wrappingTextViewer1", "localeChooser1", PaneConstraints.RIGHT, 0.65f));
this.add(splitPanel1, BorderLayout.CENTER);
// The following locale choices were initially set using the property
// inspector. However, since the LocaleChooser obtains its list of
// available locales from the JDK and the JDK's locale data is
// incomplete, we added additional locales by hand.
// In JDK 1.1.6, the NumberFormat.getAvailableLocales() method didn't
// return any locales if the JDK classes were in a .ZIP file. Thus
// when the LocaleChooser is used in the designer, no locales are displayed.
localeChooser1.setLocaleChoices(new Locale [] { new java.util.Locale("de", "CH"),
new java.util.Locale("de", "DE"),
new java.util.Locale("en", "CA"),
new java.util.Locale("en", "GB"),
new java.util.Locale("en", "US"),
new java.util.Locale("es", "ES"),
new java.util.Locale("fr", "FR"),
new java.util.Locale("fr", "CA"),
new java.util.Locale("fr", "CH"),
new java.util.Locale("it", "IT"),
new java.util.Locale("it", "CH"),
new java.util.Locale("ja", "JP"),
new java.util.Locale("ko", "KR"),
new java.util.Locale("zh", "TW"),
new java.util.Locale("cs", "CZ"),
new java.util.Locale("hr", "HR"),
new java.util.Locale("tr", "TR"),
new java.util.Locale("sh", "YU"),
new java.util.Locale("sr", "YU"),
new java.util.Locale("pl", "PL"),
new java.util.Locale("el", "GR"),
} );
localeChooser1.addLocaleChangeListener(LocaleChangeManager.getLocaleChangeManager());
browseButton.addActionListener(new WelcomeFrame_browseButton_actionAdapter(this));
viewButton.addActionListener(new WelcomeFrame_viewButton_ActionAdapter(this));
exitButton.addActionListener(new WelcomeFrame_exitButton_ActionAdapter(this));
labelControl1.setText(textRes.getString("Welcome"));
labelControl1.setFont(new Font("Dialog", 2, 24));
this.add(labelControl1, BorderLayout.NORTH);
LocaleChangeManager.getLocaleChangeManager().addLocaleChangeListener(this);
this.setSize(new Dimension(588, 459));
this.setTitle(textRes.getString("WelcomeTitle"));
internationalClock1.setDateStyle(java.text.DateFormat.FULL);
internationalClock1.setTimeStyle(java.text.DateFormat.MEDIUM);
internationalClock1.setAlignment(Label.RIGHT);
internationalClock1.setMargins(new Insets(0, 0, 0, 10));
}
public Dimension getPreferredSize() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
return new Dimension(super.getPreferredSize().width, screenSize.height / 2);
}
/**
* Enables or disables the 'Browse products' button.
* Set false when a user clicks on the 'View previous orders' button
* since product browsing should be disabled in that mode.
* Set true by OrderFrame.java once a user closes the frame
* after having browsed previous orders.
*
* @param allowProductBrowsing enables or disables 'Browse products' button
*/
public void setAllowProductBrowsing(boolean allowProductBrowsing) {
browseButton.setEnabled(allowProductBrowsing);
}
/**
* Enables or disables the 'View previous orders' button.
* Set false by ProductFrame.java once a user has begun entering
* an order since viewing previous orders should be disabled in that mode.
* Set true by OrderFrame.java once a user has completed (either
* cancelled or saved) an order.
*
* @param allowOrderViewing enables or disables 'View previous orders' button
*/
public void setAllowOrderViewing(boolean allowOrderViewing) {
viewButton.setEnabled(allowOrderViewing);
}
/**
* Enables or disables background activity of beans used within the frame.
* Primarily intended for use when run as an applet and the applet's stop()
* method is called, to disable the LocaleChooser bean's spinning globe
* animation and InternationalClock bean's clock.
*
* @param enabled if false, disables frame's background activity
*/
public void setBackgroundActivityEnabled(boolean enabled) {
localeChooser1.setAnimationEnabled(enabled);
internationalClock1.setClockEnabled(enabled);
}
/**
* Resolves any as yet unresolved data when user closes the frame.
* If running as an applet, just hides the frame, otherwise exits.
* <B>NOTE</B> When using a DecoratedFrame, a registered
* WINDOW_CLOSING event listener will NOT be called. Thus to
* perform custom processing upon window close events for frames
* extending DecoratedFrame, it is necessary to override
* DecoratedFrame's processWindowEvent method.
*
* @param e WindowEvent describing the event to be processed
*/
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
appDataModule.resolveData();
// If we're running as an applet, hide the
// window but don't exit
if (runningAsApplet) {
if (OrderFrame.getInstance().getViewingOrders()) {
appDataModule.browseCustomerOrders(false);
OrderFrame.getInstance().setViewingOrders(false);
}
appDataModule.cancelOrder();
setAllowProductBrowsing(true);
setAllowOrderViewing(true);
this.setVisible(false);
ProductFrame.getInstance().setVisible(false);
OrderFrame.getInstance().setVisible(false);
} else {
this.dispose();
ProductFrame.getInstance().dispose();
OrderFrame.getInstance().dispose();
System.exit(0);
}
}
}
/**
* Launches the product browsing frame (ProductFrame.java).
*
* @param e ActionEvent describing the action performed
*/
void browseButton_actionPerformed(java.awt.event.ActionEvent e) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
ProductFrame.getInstance().setVisible(true);
this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
/**
* Prompts the user to select an existing customer (via CustomerLookupDialog.java),
* and initializes the OrderFrame for viewing the selected customer's previous orders.
*
* @param e ActionEvent describing the action performed
*/
void viewButton_actionPerformed(java.awt.event.ActionEvent e) {
try {
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// Create and display the modal customer lookup dialog. Selection of
// a customer row, password verification, and setting up of the
// data module to retrieve the customer's orders all takes place
// within CustomerLookupDialog.java.
CustomerLookupDialog customerLookupDialog = new CustomerLookupDialog(this, true);
customerLookupDialog.show();
this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
if (customerLookupDialog.isValidCustomer()) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
appDataModule.browseCustomerOrders(true);
setAllowProductBrowsing(false);
ProductFrame.getInstance().setVisible(false);
OrderFrame.getInstance().setViewingOrders(true);
OrderFrame.getInstance().setVisible(true);
this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
} catch (Exception ex) {
borland.jbcl.util.Diagnostic.printStackTrace(ex);
}
}
// When user presses 'Exit' button, resolve any as of yet
// unresolved data. If running as an applet, just hide
// the frame, otherwise exit.
void exitButton_actionPerformed(java.awt.event.ActionEvent e) {
appDataModule.resolveData();
if (runningAsApplet) {
if (OrderFrame.getInstance().getViewingOrders()) {
appDataModule.browseCustomerOrders(false);
OrderFrame.getInstance().setViewingOrders(false);
}
appDataModule.cancelOrder();
setAllowProductBrowsing(true);
setAllowOrderViewing(true);
this.setVisible(false);
ProductFrame.getInstance().setVisible(false);
OrderFrame.getInstance().setVisible(false);
} else {
this.dispose();
ProductFrame.getInstance().dispose();
OrderFrame.getInstance().dispose();
System.exit(0);
}
}
/**
* Resets WelcomeFrame components for newly selected locale.
* Updates resource bundle for new locale and resizes and centers
* frame based on new preferred size of localizable elements.
*
* @param e LocaleChangeEvent specifying new locale
*/
public void localeChanged(LocaleChangeEvent e) {
textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes", e.getLocale());
browseButton.setLabel(textRes.getString("Browse"));
browseButton.invalidate();
viewButton.setLabel(textRes.getString("View"));
viewButton.invalidate();
exitButton.setLabel(textRes.getString("Exit"));
exitButton.invalidate();
wrappingTextViewer1.setText(textRes.getString("WelcomeText"));
wrappingTextViewer1.setLocale(e.getLocale());
wrappingTextViewer1.invalidate();
labelControl1.setText(textRes.getString("Welcome"));
labelControl1.invalidate();
internationalClock1.setLocale(e.getLocale());
localeChooser1.invalidate();
setTitle(textRes.getString("WelcomeTitle"));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = welcomeFrame.getPreferredSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height / 2;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
setSize(frameSize.width, frameSize.height);
validate();
}
/**
* Sets WelcomeFrame to run in applet mode.
* Must be called before WelcomeFrame is initialized.
* When run in applet mode, closing the frame or
* pressing 'Exit' does not invoke System.exit(),
* which would cause an applet security violation.
*
* @param runningAsApplet if true, sets applet mode
*/
public static void setRunningAsApplet(boolean runAsApplet) {
runningAsApplet = runAsApplet;
}
}
class WelcomeFrame_viewButton_ActionAdapter implements ActionListener{
WelcomeFrame adaptee;
WelcomeFrame_viewButton_ActionAdapter(WelcomeFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
adaptee.viewButton_actionPerformed(e);
}
}
class WelcomeFrame_exitButton_ActionAdapter implements ActionListener{
WelcomeFrame adaptee;
WelcomeFrame_exitButton_ActionAdapter(WelcomeFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
adaptee.exitButton_actionPerformed(e);
}
}
class WelcomeFrame_browseButton_actionAdapter implements java.awt.event.ActionListener{
WelcomeFrame adaptee;
WelcomeFrame_browseButton_actionAdapter(WelcomeFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
adaptee.browseButton_actionPerformed(e);
}
}