home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
OrderFrame.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
20KB
|
476 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.util.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import borland.jbcl.view.*;
import borland.jbcl.util.*;
import borland.samples.intl.application.*;
import borland.samples.intl.beans.*;
import borland.samples.intl.beans.event.*;
import borland.jbcl.model.*;
public class OrderFrame extends DecoratedFrame implements LocaleChangeListener{
private static OrderFrame orderFrame = null;
private int captionMargin = 10;
private boolean viewingOrders = false;
private boolean batchUpdateMode = false;
GridControl orderLineItemGridControl = new GridControl();
private static AppDataModule appDataModule = AppDataModule.getDataModule();
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridBagLayout gridBagLayout2 = new GridBagLayout();
GridLayout gridLayout2 = new GridLayout();
GridLayout gridLayout4 = new GridLayout();
GridLayout gridLayout5 = new GridLayout();
BevelPanel headerPanel = new BevelPanel();
BevelPanel customerDataPanel = new BevelPanel();
BevelPanel buttonPanel = new BevelPanel();
BevelPanel exchangeRatePanel = new BevelPanel();
BevelPanel summaryPanel = new BevelPanel();
BevelPanel paymentMethodPanel = new BevelPanel();
TabsetPanel customerTabSetPanel = new TabsetPanel();
LabelControl orderNoLabel = new LabelControl();
LabelControl titleLabel = new LabelControl();
LabelControl orderDateLabel = new LabelControl();
LabelControl exchangeRateLabel = new LabelControl();
LabelControl subtotalLabel = new LabelControl();
LabelControl shippingLabel = new LabelControl();
LabelControl taxLabel = new LabelControl();
LabelControl totalLabel = new LabelControl();
ButtonControl removeItemButton = new ButtonControl();
ButtonControl cancelOrderButton = new ButtonControl();
ButtonControl completeOrderButton = new ButtonControl();
FieldControl orderNoField = new FieldControl();
FieldControl orderDateField = new FieldControl();
FieldControl exchangeRateField = new FieldControl();
FieldControl subtotalField = new FieldControl();
FieldControl localSubtotalField = new FieldControl();
FieldControl shippingField = new FieldControl();
FieldControl localShippingField = new FieldControl();
FieldControl taxField = new FieldControl();
FieldControl localTaxField = new FieldControl();
FieldControl totalField = new FieldControl();
FieldControl localTotalField = new FieldControl();
SoldToPanel soldToPanel = new SoldToPanel();
ShipToPanel shipToPanel = new ShipToPanel();
LabelControl paymentMethodLabel = new LabelControl();
// ChoiceControl paymentMethodField = new ChoiceControl();
FieldControl paymentMethodField = new FieldControl();
LabelControl creditCardNoLabel = new LabelControl();
FieldControl creditCardNoField = new FieldControl();
LabelControl expirationDateLabel = new LabelControl();
FieldControl expirationDateField = new FieldControl();
ViewOnlyNavigationBar viewOnlyNavigationBar = new ViewOnlyNavigationBar();
ResourceBundle textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes",
LocaleChangeManager.getLocale());
//Construct the frame
public OrderFrame() {
try {
jbInit();
}
catch (Exception e) {
borland.jbcl.util.Diagnostic.printStackTrace(e);
};
}
public static OrderFrame getInstance() {
if (orderFrame == null) {
orderFrame = new OrderFrame();
}
return orderFrame;
}
public void addNotify() {
super.addNotify();
orderFrame.pack();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = orderFrame.getPreferredSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
orderFrame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}
void jbInit() throws Exception{
this.setLayout(gridBagLayout1);
this.setSize(new Dimension(653, 505));
this.setTitle(textRes.getString("Order_frame_title"));
orderNoLabel.setText(textRes.getString("order_no"));
orderNoField.setDataSet(appDataModule.getOrderDataSet());
orderNoField.setColumnName("order_no");
orderNoField.setBackground(SystemColor.control);
titleLabel.setText(textRes.getString("Form_title"));
titleLabel.setAlignment(Label.CENTER);
orderDateLabel.setText(textRes.getString("order_date"));
orderDateField.setDataSet(appDataModule.getOrderDataSet());
orderDateField.setColumnName("order_date");
orderDateField.setBackground(SystemColor.control);
headerPanel.setLayout(gridBagLayout2);
headerPanel.setBevelInner(BevelPanel.FLAT);
headerPanel.add(orderNoLabel, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
headerPanel.add(orderNoField, new GridBagConstraints2(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
headerPanel.add(titleLabel, new GridBagConstraints2(2, 0, 4, 1, 100.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
headerPanel.add(orderDateLabel, new GridBagConstraints2(6, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
headerPanel.add(orderDateField, new GridBagConstraints2(7, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0));
headerPanel.setEnabled(false);
this.add(headerPanel, new GridBagConstraints2(0, 0, 6, 1, 100.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
customerTabSetPanel.setLabels(new String[] {textRes.getString("Sold_To"), textRes.getString("Ship_To") });
customerTabSetPanel.add(soldToPanel, textRes.getString("Sold_To"));
customerTabSetPanel.add(shipToPanel, textRes.getString("Ship_To"));
customerTabSetPanel.setSelectedIndex(0);
this.add(customerTabSetPanel, new GridBagConstraints2(0, 1, 6, 4, 100.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 18));
orderLineItemGridControl.setAutoInsert(false);
orderLineItemGridControl.setShowPopup(false);
orderLineItemGridControl.setDataSet(appDataModule.getOrderLineItemDataSet());
orderLineItemGridControl.setPreferredSize(new Dimension(0, 100));
// orderLineItemGridControl.setNavigateOnEnter(false);
this.add(orderLineItemGridControl, new GridBagConstraints2(0, 5, 6, 4, 100.0, 100.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
paymentMethodLabel.setText(textRes.getString("payment_method"));
// paymentMethodField.setItems(appDataModule.getPaymentMethodDataSet(), "credit_card_name");
paymentMethodField.setDataSet(appDataModule.getOrderDataSet());
paymentMethodField.setColumnName("payment_method");
creditCardNoLabel.setText(textRes.getString("credit_card_no"));
creditCardNoField.setDataSet(appDataModule.getOrderDataSet());
creditCardNoField.setColumnName("credit_card_no");
expirationDateLabel.setText(textRes.getString("card_expiration_date"));
expirationDateField.setDataSet(appDataModule.getOrderDataSet());
expirationDateField.setColumnName("card_expiration_date");
exchangeRateLabel.setText(textRes.getString("Exchange_rate"));
exchangeRateField.setDataSet(appDataModule.getExchangeRateDataSet());
exchangeRateField.setColumnName("exchange_rate");
gridLayout5.setRows(4);
gridLayout5.setColumns(2);
gridLayout5.setHgap(10);
paymentMethodPanel.setLayout(gridLayout5);
paymentMethodPanel.add(paymentMethodLabel, null);
paymentMethodPanel.add(creditCardNoLabel, null);
paymentMethodPanel.add(paymentMethodField, null);
paymentMethodPanel.add(creditCardNoField, null);
paymentMethodPanel.add(expirationDateLabel, null);
paymentMethodPanel.add(exchangeRateLabel, null);
paymentMethodPanel.add(expirationDateField, null);
paymentMethodPanel.add(exchangeRateField, null);
paymentMethodPanel.setBevelInner(BevelPanel.FLAT);
paymentMethodPanel.setMargins(new Insets(10, 30, 5, 30));
this.add(paymentMethodPanel, new GridBagConstraints2(0, 9, 2, 4, 60.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
subtotalLabel.setText(textRes.getString("Subtotal"));
subtotalField.setDataSet(appDataModule.getOrderLineItemDataSet());
subtotalField.setColumnName("subtotal");
subtotalField.setAlignment(Alignment.RIGHT);
subtotalField.setBackground(SystemColor.control);
localSubtotalField.setDataSet(appDataModule.getOrderLineItemDataSet());
localSubtotalField.setColumnName("local_subtotal");
localSubtotalField.setBackground(SystemColor.control);
localSubtotalField.setAlignment(Alignment.RIGHT);
shippingLabel.setText(textRes.getString("Shipping_&_Handling"));
shippingField.setDataSet(appDataModule.getOrderLineItemDataSet());
shippingField.setColumnName("shipping");
shippingField.setBackground(SystemColor.control);
shippingField.setAlignment(Alignment.RIGHT);
localShippingField.setDataSet(appDataModule.getOrderLineItemDataSet());
localShippingField.setColumnName("local_shipping");
localShippingField.setBackground(SystemColor.control);
localShippingField.setAlignment(Alignment.RIGHT);
taxLabel.setText(textRes.getString("Sales_tax"));
taxField.setDataSet(appDataModule.getOrderLineItemDataSet());
taxField.setColumnName("tax");
taxField.setAlignment(Alignment.RIGHT);
taxField.setBackground(SystemColor.control);
localTaxField.setDataSet(appDataModule.getOrderLineItemDataSet());
localTaxField.setColumnName("local_tax");
localTaxField.setAlignment(Alignment.RIGHT);
localTaxField.setBackground(SystemColor.control);
totalLabel.setText(textRes.getString("Total"));
totalField.setDataSet(appDataModule.getOrderLineItemDataSet());
totalField.setColumnName("total");
totalField.setAlignment(Alignment.RIGHT);
totalField.setBackground(SystemColor.control);
localTotalField.setDataSet(appDataModule.getOrderLineItemDataSet());
localTotalField.setColumnName("local_total");
localTotalField.setAlignment(Alignment.RIGHT);
localTotalField.setBackground(SystemColor.control);
gridLayout4.setRows(4);
gridLayout4.setColumns(3);
summaryPanel.setLayout(gridLayout4);
summaryPanel.add(subtotalLabel, null);
summaryPanel.add(subtotalField, null);
summaryPanel.add(localSubtotalField, null);
summaryPanel.add(shippingLabel, null);
summaryPanel.add(shippingField, null);
summaryPanel.add(localShippingField, null);
summaryPanel.add(taxLabel, null);
summaryPanel.add(taxField, null);
summaryPanel.add(localTaxField, null);
summaryPanel.add(totalLabel, null);
summaryPanel.add(totalField, null);
summaryPanel.add(localTotalField, null);
summaryPanel.setBevelInner(BevelPanel.FLAT);
summaryPanel.setEnabled(false);
this.add(summaryPanel, new GridBagConstraints2(2, 9, 4, 4, 40.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
gridLayout2.setRows(1);
gridLayout2.setColumns(3);
gridLayout2.setHgap(10);
buttonPanel.setLayout(gridLayout2);
removeItemButton.setLabel(textRes.getString("Remove_Item"));
removeItemButton.addActionListener(new OrderFrame_removeItemButton_actionAdapter(this));
buttonPanel.add(removeItemButton, null);
cancelOrderButton.setLabel(textRes.getString("Cancel_Order"));
cancelOrderButton.addActionListener(new OrderFrame_cancelOrderButton_actionAdapter(this));
buttonPanel.add(cancelOrderButton, null);
completeOrderButton.setLabel(textRes.getString("Submit_Order"));
completeOrderButton.addActionListener(new OrderFrame_completeOrderButton_actionAdapter(this));
buttonPanel.add(completeOrderButton, null);
buttonPanel.setMargins(new Insets(10, 10, 10, 10));
this.add(buttonPanel, new GridBagConstraints2(0, 13, 6, 1, 100.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
viewOnlyNavigationBar.setVisible(false);
viewOnlyNavigationBar.setDataSet(appDataModule.getOrderDataSet());
this.add(viewOnlyNavigationBar, new GridBagConstraints2(0, 14, 6, 1, 100.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
LocaleChangeManager.getLocaleChangeManager().addLocaleChangeListener(this);
}
public void setViewingOrders(boolean viewingOrders) {
this.viewingOrders = viewingOrders;
soldToPanel.setEnabled(!viewingOrders);
shipToPanel.setEnabled(!viewingOrders);
orderLineItemGridControl.setReadOnly(viewingOrders);
paymentMethodPanel.setEnabled(!viewingOrders);
}
public boolean getViewingOrders() {
return viewingOrders;
}
public void setVisible(boolean visible) {
if (visible) {
if (viewingOrders) {
viewOnlyNavigationBar.setVisible(true);
buttonPanel.setVisible(false);
} else {
viewOnlyNavigationBar.setVisible(false);
buttonPanel.setVisible(true);
}
} else {
if (viewingOrders) {
WelcomeFrame.getInstance().setAllowProductBrowsing(true);
appDataModule.browseCustomerOrders(false);
setViewingOrders(false);
}
}
super.setVisible(visible);
}
public void setBatchUpdateMode(boolean batchUpdateMode) {
this.batchUpdateMode = batchUpdateMode;
orderLineItemGridControl.setBatchMode(batchUpdateMode);
}
public boolean getBatchUpdateMode() {
return batchUpdateMode;
}
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
this.setVisible(false);
}
}
void removeItemButton_actionPerformed(ActionEvent e) {
appDataModule.removeCurrentLineItem();
}
void cancelOrderButton_actionPerformed(ActionEvent e) {
appDataModule.cancelOrder();
this.setVisible(false);
WelcomeFrame.getInstance().setAllowOrderViewing(true);
WelcomeFrame.getInstance().setVisible(true);
}
void completeOrderButton_actionPerformed(ActionEvent e) {
try {
String password = null;
boolean savePassword = false;
if (appDataModule.isPasswordNeededToSaveOrder()) {
String password1 = null;
String password2 = null;
PasswordDialog passwordDialog = new PasswordDialog(this, textRes.getString("Password"));
passwordDialog.show();
password1 = passwordDialog.getPassword();
if (password1 == null) {
return;
}
passwordDialog = new PasswordDialog(this, textRes.getString("Password_confirmation"));
passwordDialog.show();
password2 = passwordDialog.getPassword();
if (!password1.equals(password2)) {
Message message = new Message();
message.setFrame(this);
message.setLabels(new String [] { textRes.getString("OK") });
message.setMessage(textRes.getString("Passwords_different"));
message.setVisible(true);
return;
}
password = password2;
savePassword = true;
}
if (appDataModule.saveOrder(password)) {
this.setVisible(false);
WelcomeFrame.getInstance().setAllowOrderViewing(true);
WelcomeFrame.getInstance().requestFocus();
}
} catch (Exception ex) {
borland.jbcl.util.Diagnostic.printStackTrace(ex);
}
}
public void localeChanged(LocaleChangeEvent e) {
textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes", e.getLocale());
setLocale(e.getLocale());
this.setTitle(textRes.getString("Order_frame_title"));
orderNoLabel.setText(textRes.getString("order_no"));
orderNoLabel.invalidate();
titleLabel.setText(textRes.getString("Form_title"));
titleLabel.invalidate();
orderDateLabel.setText(textRes.getString("order_date"));
orderDateLabel.invalidate();
customerTabSetPanel.setLabels(new String[] {textRes.getString("Sold_To"), textRes.getString("Ship_To") });
customerTabSetPanel.invalidate();
paymentMethodLabel.setText(textRes.getString("payment_method"));
paymentMethodLabel.invalidate();
creditCardNoLabel.setText(textRes.getString("credit_card_no"));
creditCardNoLabel.invalidate();
expirationDateLabel.setText(textRes.getString("card_expiration_date"));
expirationDateLabel.invalidate();
exchangeRateLabel.setText(textRes.getString("Exchange_rate"));
exchangeRateLabel.invalidate();
subtotalLabel.setText(textRes.getString("Subtotal"));
subtotalLabel.invalidate();
shippingLabel.setText(textRes.getString("Shipping_&_Handling"));
shippingLabel.invalidate();
taxLabel.setText(textRes.getString("Sales_tax"));
taxLabel.invalidate();
totalLabel.setText(textRes.getString("Total"));
totalLabel.invalidate();
removeItemButton.setLabel(textRes.getString("Remove_Item"));
removeItemButton.invalidate();
cancelOrderButton.setLabel(textRes.getString("Cancel_Order"));
cancelOrderButton.invalidate();
completeOrderButton.setLabel(textRes.getString("Submit_Order"));
completeOrderButton.invalidate();
this.pack();
}
}
class OrderFrame_removeItemButton_actionAdapter implements java.awt.event.ActionListener {
OrderFrame adaptee;
OrderFrame_removeItemButton_actionAdapter(OrderFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.removeItemButton_actionPerformed(e);
}
}
class OrderFrame_cancelOrderButton_actionAdapter implements java.awt.event.ActionListener {
OrderFrame adaptee;
OrderFrame_cancelOrderButton_actionAdapter(OrderFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.cancelOrderButton_actionPerformed(e);
}
}
class OrderFrame_completeOrderButton_actionAdapter implements java.awt.event.ActionListener {
OrderFrame adaptee;
OrderFrame_completeOrderButton_actionAdapter(OrderFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.completeOrderButton_actionPerformed(e);
}
}