home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / OrderFrame.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  17.6 KB  |  429 lines

  1.  
  2. package borland.samples.intl.gui;
  3.  
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import java.util.*;
  7. import borland.jbcl.layout.*;
  8. import borland.jbcl.control.*;
  9. import borland.jbcl.view.*;
  10. import borland.jbcl.util.*;
  11.  
  12. import borland.samples.intl.application.*;
  13. import borland.samples.intl.beans.*;
  14. import borland.samples.intl.beans.event.*;
  15. import borland.samples.intl.util.*;
  16.  
  17. public class OrderFrame extends DecoratedFrame implements LocaleChangeListener {
  18.   private static OrderFrame orderFrame = null;
  19.   private int captionMargin = 10;
  20.   private boolean viewingOrders = false;
  21.   private boolean batchUpdateMode = false;
  22.  
  23.   GridControl orderLineItemGridControl = new GridControl();
  24.   private static AppDataModule appDataModule = AppDataModule.getDataModule();
  25.  
  26.   GridBagLayout gridBagLayout1 = new GridBagLayout();
  27.   GridBagLayout gridBagLayout2 = new GridBagLayout();
  28.  
  29.   GridLayout gridLayout2 = new GridLayout();
  30.   GridLayout gridLayout4 = new GridLayout();
  31.   GridLayout gridLayout5 = new GridLayout();
  32.  
  33.   BevelPanel headerPanel = new BevelPanel();
  34.   BevelPanel customerDataPanel = new BevelPanel();
  35.   BevelPanel buttonPanel = new BevelPanel();
  36.   BevelPanel exchangeRatePanel = new BevelPanel();
  37.   BevelPanel summaryPanel = new BevelPanel();
  38.   BevelPanel paymentMethodPanel = new BevelPanel();
  39.   
  40.   TabsetPanel customerTabSetPanel = new TabsetPanel();
  41.  
  42.   LabelControl orderNoLabel = new LabelControl();
  43.   LabelControl titleLabel = new LabelControl();
  44.   LabelControl orderDateLabel = new LabelControl();
  45.   LabelControl exchangeRateLabel = new LabelControl();
  46.   LabelControl subtotalLabel = new LabelControl();
  47.   LabelControl shippingLabel = new LabelControl();
  48.   LabelControl taxLabel = new LabelControl();
  49.   LabelControl totalLabel = new LabelControl();
  50.  
  51.   ButtonControl removeItemButton = new ButtonControl();
  52.   ButtonControl cancelOrderButton = new ButtonControl();
  53.   ButtonControl completeOrderButton = new ButtonControl();
  54.  
  55.   FieldControl orderNoField = new FieldControl();
  56.   FieldControl orderDateField = new FieldControl();
  57.   FieldControl exchangeRateField = new FieldControl();
  58.   FieldControl subtotalField = new FieldControl();
  59.   FieldControl localSubtotalField = new FieldControl();
  60.   FieldControl shippingField = new FieldControl();
  61.   FieldControl localShippingField = new FieldControl();
  62.   FieldControl taxField = new FieldControl();
  63.   FieldControl localTaxField = new FieldControl();
  64.   FieldControl totalField = new FieldControl();
  65.   FieldControl localTotalField = new FieldControl();
  66.  
  67.   SoldToPanel soldToPanel = new SoldToPanel();
  68.   ShipToPanel shipToPanel = new ShipToPanel();
  69.  
  70.   LabelControl paymentMethodLabel = new LabelControl();
  71.   ChoiceControl paymentMethodField = new ChoiceControl();
  72.   LabelControl creditCardNoLabel = new LabelControl();
  73.   FieldControl creditCardNoField = new FieldControl();
  74.   LabelControl expirationDateLabel = new LabelControl();
  75.   FieldControl expirationDateField = new FieldControl();
  76.  
  77.   ViewOnlyNavigationBar viewOnlyNavigationBar = new ViewOnlyNavigationBar();
  78.  
  79.   ResourceBundle textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes");
  80.  
  81.   //Construct the frame
  82.   public OrderFrame() {
  83.     try {
  84.       jbInit();
  85.     }
  86.     catch (Exception e) {
  87.       borland.jbcl.util.Diagnostic.printStackTrace(e);
  88.     };
  89.   }
  90.  
  91.   public static OrderFrame getInstance() {
  92.     if (orderFrame == null) {
  93.       orderFrame = new OrderFrame();
  94.       orderFrame.pack();
  95.       //Center the window
  96.       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  97.       Dimension frameSize = orderFrame.getPreferredSize();
  98.       if (frameSize.height > screenSize.height)
  99.     frameSize.height = screenSize.height;
  100.       if (frameSize.width > screenSize.width)
  101.     frameSize.width = screenSize.width;
  102.       orderFrame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
  103.     }
  104.     return orderFrame;
  105.   }
  106.  
  107.   void jbInit() throws Exception{
  108.     this.setLayout(gridBagLayout1);
  109.     this.setTitle(textRes.getString("Order_frame_title"));
  110.  
  111.     orderNoLabel.setText(textRes.getString("order_no"));
  112.     orderNoField.setDataSet(appDataModule.getOrderDataSet());
  113.     orderNoField.setColumnName("order_no");
  114.     orderNoField.setBackground(SystemColor.control);
  115.  
  116.     titleLabel.setText(textRes.getString("Form_title"));
  117.     titleLabel.setAlignment(Label.CENTER);
  118.  
  119.     orderDateLabel.setText(textRes.getString("order_date"));
  120.     orderDateField.setDataSet(appDataModule.getOrderDataSet());
  121.     orderDateField.setColumnName("order_date");
  122.     orderDateField.setBackground(SystemColor.control);
  123.     
  124.     headerPanel.setLayout(gridBagLayout2);
  125.     headerPanel.setBevelInner(BevelPanel.FLAT);
  126.     headerPanel.add(orderNoLabel, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  127.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
  128.     headerPanel.add(orderNoField, new GridBagConstraints2(1, 0, 1, 1, 0.0, 0.0
  129.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  130.     headerPanel.add(titleLabel, new GridBagConstraints2(2, 0, 4, 1, 100.0, 0.0
  131.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  132.     headerPanel.add(orderDateLabel, new GridBagConstraints2(6, 0, 1, 1, 0.0, 0.0
  133.             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  134.     headerPanel.add(orderDateField, new GridBagConstraints2(7, 0, 1, 1, 0.0, 0.0
  135.             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0));
  136.     headerPanel.setEnabled(false);
  137.  
  138.     this.add(headerPanel, new GridBagConstraints2(0, 0, 6, 1, 100.0, 0.0
  139.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  140.  
  141.     customerTabSetPanel.setLabels(new String[] {textRes.getString("Sold_To"), textRes.getString("Ship_To") });
  142.     customerTabSetPanel.add(soldToPanel, textRes.getString("Sold_To"));
  143.     customerTabSetPanel.add(shipToPanel, textRes.getString("Ship_To"));
  144.     customerTabSetPanel.setSelectedIndex(0);
  145.     this.add(customerTabSetPanel, new GridBagConstraints2(0, 1, 6, 4, 100.0, 0.0
  146.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  147.  
  148.     orderLineItemGridControl.setAutoInsert(false);
  149.     orderLineItemGridControl.setShowPopup(false);
  150.     orderLineItemGridControl.setDataSet(appDataModule.getOrderLineItemDataSet());
  151.     orderLineItemGridControl.setPreferredSize(new Dimension(0, 100));
  152.  
  153.     this.add(orderLineItemGridControl, new GridBagConstraints2(0, 5, 6, 4, 100.0, 100.0
  154.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  155.  
  156.     paymentMethodLabel.setText(textRes.getString("payment_method"));
  157.     paymentMethodField.setItems(appDataModule.getPaymentMethodDataSet(), "credit_card_name");
  158.     paymentMethodField.setDataSet(appDataModule.getOrderDataSet());
  159.     paymentMethodField.setColumnName("payment_method");
  160.     creditCardNoLabel.setText(textRes.getString("credit_card_no"));
  161.     creditCardNoField.setDataSet(appDataModule.getOrderDataSet());
  162.     creditCardNoField.setColumnName("credit_card_no");
  163.     expirationDateLabel.setText(textRes.getString("card_expiration_date"));
  164.     expirationDateField.setDataSet(appDataModule.getOrderDataSet());
  165.     expirationDateField.setColumnName("card_expiration_date");
  166.  
  167.     exchangeRateLabel.setText(textRes.getString("Exchange_rate"));
  168.     exchangeRateField.setDataSet(appDataModule.getExchangeRateDataSet());
  169.     exchangeRateField.setColumnName("exchange_rate");
  170.  
  171.     gridLayout5.setRows(4);
  172.     gridLayout5.setColumns(2);
  173.     gridLayout5.setHgap(10);
  174.     paymentMethodPanel.setLayout(gridLayout5);
  175.     paymentMethodPanel.add(paymentMethodLabel, null);
  176.     paymentMethodPanel.add(creditCardNoLabel, null);
  177.     paymentMethodPanel.add(paymentMethodField, null);
  178.     paymentMethodPanel.add(creditCardNoField, null);
  179.     paymentMethodPanel.add(expirationDateLabel, null);
  180.     paymentMethodPanel.add(exchangeRateLabel, null);
  181.     paymentMethodPanel.add(expirationDateField, null);
  182.     paymentMethodPanel.add(exchangeRateField, null);
  183.     paymentMethodPanel.setBevelInner(BevelPanel.FLAT);
  184.     paymentMethodPanel.setMargins(new Insets(10, 30, 5, 30));
  185.     
  186.     this.add(paymentMethodPanel, new GridBagConstraints2(0, 9, 2, 4, 60.0, 0.0
  187.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  188.  
  189.     subtotalLabel.setText(textRes.getString("Subtotal"));
  190.     subtotalField.setDataSet(appDataModule.getOrderLineItemDataSet());
  191.     subtotalField.setColumnName("subtotal");
  192.     subtotalField.setAlignment(Alignment.RIGHT);
  193.     subtotalField.setBackground(SystemColor.control);
  194.     localSubtotalField.setDataSet(appDataModule.getOrderLineItemDataSet());
  195.     localSubtotalField.setColumnName("local_subtotal");
  196.     localSubtotalField.setBackground(SystemColor.control);
  197.     localSubtotalField.setAlignment(Alignment.RIGHT);
  198.     
  199.     shippingLabel.setText(textRes.getString("Shipping_&_Handling"));
  200.     shippingField.setDataSet(appDataModule.getOrderLineItemDataSet());
  201.     shippingField.setColumnName("shipping");
  202.     shippingField.setBackground(SystemColor.control);
  203.     shippingField.setAlignment(Alignment.RIGHT);
  204.     localShippingField.setDataSet(appDataModule.getOrderLineItemDataSet());
  205.     localShippingField.setColumnName("local_shipping");
  206.     localShippingField.setBackground(SystemColor.control);
  207.     localShippingField.setAlignment(Alignment.RIGHT);
  208.  
  209.     taxLabel.setText(textRes.getString("Sales_tax"));
  210.     taxField.setDataSet(appDataModule.getOrderLineItemDataSet());
  211.     taxField.setColumnName("tax");
  212.     taxField.setAlignment(Alignment.RIGHT);
  213.     taxField.setBackground(SystemColor.control);
  214.     localTaxField.setDataSet(appDataModule.getOrderLineItemDataSet());
  215.     localTaxField.setColumnName("local_tax");
  216.     localTaxField.setAlignment(Alignment.RIGHT);
  217.     localTaxField.setBackground(SystemColor.control);
  218.  
  219.     totalLabel.setText(textRes.getString("Total"));
  220.     totalField.setDataSet(appDataModule.getOrderLineItemDataSet());
  221.     totalField.setColumnName("total");
  222.     totalField.setAlignment(Alignment.RIGHT);
  223.     totalField.setBackground(SystemColor.control);
  224.     localTotalField.setDataSet(appDataModule.getOrderLineItemDataSet());
  225.     localTotalField.setColumnName("local_total");
  226.     localTotalField.setAlignment(Alignment.RIGHT);
  227.     localTotalField.setBackground(SystemColor.control);
  228.  
  229.     gridLayout4.setRows(4);
  230.     gridLayout4.setColumns(3);
  231.     summaryPanel.setLayout(gridLayout4);
  232.     summaryPanel.add(subtotalLabel, null);
  233.     summaryPanel.add(subtotalField, null);
  234.     summaryPanel.add(localSubtotalField, null);
  235.     summaryPanel.add(shippingLabel, null);
  236.     summaryPanel.add(shippingField, null);
  237.     summaryPanel.add(localShippingField, null);
  238.     summaryPanel.add(taxLabel, null);
  239.     summaryPanel.add(taxField, null);
  240.     summaryPanel.add(localTaxField, null);
  241.     summaryPanel.add(totalLabel, null);
  242.     summaryPanel.add(totalField, null);
  243.     summaryPanel.add(localTotalField, null);
  244.     summaryPanel.setBevelInner(BevelPanel.FLAT);
  245.     summaryPanel.setEnabled(false);
  246.  
  247.     this.add(summaryPanel, new GridBagConstraints2(2, 9, 4, 4, 40.0, 0.0
  248.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  249.  
  250.     gridLayout2.setRows(1);
  251.     gridLayout2.setColumns(3);
  252.     gridLayout2.setHgap(10);
  253.     buttonPanel.setLayout(gridLayout2);
  254.     removeItemButton.setLabel(textRes.getString("Remove_Item"));
  255.     removeItemButton.addActionListener(new OrderFrame_removeItemButton_actionAdapter(this));
  256.     buttonPanel.add(removeItemButton, null);
  257.     cancelOrderButton.setLabel(textRes.getString("Cancel_Order"));
  258.     cancelOrderButton.addActionListener(new OrderFrame_cancelOrderButton_actionAdapter(this));
  259.     buttonPanel.add(cancelOrderButton, null);
  260.     completeOrderButton.setLabel(textRes.getString("Submit_Order"));
  261.     completeOrderButton.addActionListener(new OrderFrame_completeOrderButton_actionAdapter(this));
  262.     buttonPanel.add(completeOrderButton, null);
  263.     buttonPanel.setMargins(new Insets(10, 10, 10, 10));
  264.     this.add(buttonPanel, new GridBagConstraints2(0, 13, 6, 1, 100.0, 0.0
  265.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  266.  
  267.     viewOnlyNavigationBar.setVisible(false);
  268.     viewOnlyNavigationBar.setDataSet(appDataModule.getOrderDataSet());
  269.     this.add(viewOnlyNavigationBar, new GridBagConstraints2(0, 14, 6, 1, 100.0, 0.0
  270.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  271.  
  272.     LocaleChangeManager.getLocaleChangeManager().addLocaleChangeListener(this);
  273.   }
  274.   
  275.   public void setViewingOrders(boolean viewingOrders) {
  276.     this.viewingOrders = viewingOrders;
  277.     soldToPanel.setEnabled(!viewingOrders);
  278.     shipToPanel.setEnabled(!viewingOrders);
  279.     orderLineItemGridControl.setReadOnly(viewingOrders);
  280.     paymentMethodPanel.setEnabled(!viewingOrders);
  281.   }
  282.  
  283.   public void setVisible(boolean visible) {
  284.     if (visible) {
  285.       if (viewingOrders) {
  286.     viewOnlyNavigationBar.setVisible(true);
  287.     buttonPanel.setVisible(false);
  288.       } else {
  289.     viewOnlyNavigationBar.setVisible(false);
  290.     buttonPanel.setVisible(true);
  291.       }
  292.     } else {
  293.       if (viewingOrders) {
  294.     WelcomeFrame.getInstance().setAllowProductBrowsing(true);
  295.     appDataModule.browseCustomerOrders(false);
  296.     setViewingOrders(false);
  297.       }
  298.     }
  299.     super.setVisible(visible);
  300.   }
  301.  
  302.   public void setBatchUpdateMode(boolean batchUpdateMode) {
  303.     this.batchUpdateMode = batchUpdateMode;
  304.     orderLineItemGridControl.setBatchMode(batchUpdateMode);
  305.   }
  306.  
  307.   public boolean getBatchUpdateMode() {
  308.     return batchUpdateMode;
  309.   }
  310.  
  311.   protected void processWindowEvent(WindowEvent e) {
  312.     if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  313.       this.setVisible(false);
  314.     }
  315.   }
  316.   
  317.   void removeItemButton_actionPerformed(ActionEvent e) {
  318.     appDataModule.removeCurrentLineItem();
  319.   }
  320.  
  321.   
  322.   void cancelOrderButton_actionPerformed(ActionEvent e) {
  323.     appDataModule.cancelOrder();
  324.     this.setVisible(false);
  325.     WelcomeFrame.getInstance().setAllowOrderViewing(true);
  326.     WelcomeFrame.getInstance().setVisible(true);
  327.   }
  328.   
  329.   void completeOrderButton_actionPerformed(ActionEvent e) {
  330.     try {
  331.       String password = null;
  332.       boolean savePassword = false;
  333.       if (appDataModule.isPasswordNeededToSaveOrder()) {
  334.     String password1 = null;
  335.     String password2 = null;
  336.  
  337.     PasswordDialog passwordDialog = new PasswordDialog(this, textRes.getString("Password"));
  338.     passwordDialog.show();
  339.     password1 = passwordDialog.getPassword();
  340.     if (password1 == null) {
  341.       return;
  342.     }
  343.     passwordDialog = new PasswordDialog(this, textRes.getString("Password_confirmation"));
  344.     passwordDialog.show();
  345.     password2 = passwordDialog.getPassword();
  346.     if (!password1.equals(password2)) {
  347.       Message message = new Message();
  348.       message.setFrame(this);
  349.       message.setLabels(new String [] { textRes.getString("OK") });
  350.       message.setMessage(textRes.getString("Passwords_different"));
  351.       message.setVisible(true);
  352.       return;
  353.     }
  354.     password = password2;
  355.     savePassword = true;
  356.       }
  357.  
  358.       if (appDataModule.saveOrder(password)) {
  359.     this.setVisible(false);
  360.     WelcomeFrame.getInstance().setAllowOrderViewing(true);
  361.     WelcomeFrame.getInstance().requestFocus();
  362.       }
  363.  
  364.     } catch (Exception ex) {
  365.       borland.jbcl.util.Diagnostic.printStackTrace(ex);
  366.     }
  367.   }
  368.  
  369.   public void localeChanged(LocaleChangeEvent e) {
  370.     textRes = ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes", e.getLocale());
  371.  
  372.     this.setTitle(textRes.getString("Order_frame_title"));
  373.     orderNoLabel.setText(textRes.getString("order_no"));
  374.     titleLabel.setText(textRes.getString("Form_title"));
  375.     orderDateLabel.setText(textRes.getString("order_date"));
  376.     customerTabSetPanel.setLabels(new String[] {textRes.getString("Sold_To"), textRes.getString("Ship_To") });
  377.     paymentMethodLabel.setText(textRes.getString("payment_method"));
  378.     creditCardNoLabel.setText(textRes.getString("credit_card_no"));
  379.     expirationDateLabel.setText(textRes.getString("card_expiration_date"));
  380.     exchangeRateLabel.setText(textRes.getString("Exchange_rate"));
  381.     subtotalLabel.setText(textRes.getString("Subtotal"));
  382.     shippingLabel.setText(textRes.getString("Shipping_&_Handling"));
  383.     taxLabel.setText(textRes.getString("Sales_tax"));
  384.     totalLabel.setText(textRes.getString("Total"));
  385.     removeItemButton.setLabel(textRes.getString("Remove_Item"));
  386.     cancelOrderButton.setLabel(textRes.getString("Cancel_Order"));
  387.     completeOrderButton.setLabel(textRes.getString("Submit_Order"));
  388.  
  389.     this.pack();
  390.   }
  391.  
  392. }
  393.  
  394. class OrderFrame_removeItemButton_actionAdapter implements java.awt.event.ActionListener {
  395.   OrderFrame adaptee;
  396.  
  397.   OrderFrame_removeItemButton_actionAdapter(OrderFrame adaptee) {
  398.     this.adaptee = adaptee;
  399.   }
  400.  
  401.   public void actionPerformed(ActionEvent e) {
  402.     adaptee.removeItemButton_actionPerformed(e);
  403.   }
  404. }
  405.  
  406. class OrderFrame_cancelOrderButton_actionAdapter implements java.awt.event.ActionListener {
  407.   OrderFrame adaptee;
  408.  
  409.   OrderFrame_cancelOrderButton_actionAdapter(OrderFrame adaptee) {
  410.     this.adaptee = adaptee;
  411.   }
  412.  
  413.   public void actionPerformed(ActionEvent e) {
  414.     adaptee.cancelOrderButton_actionPerformed(e);
  415.   }
  416. }
  417.  
  418. class OrderFrame_completeOrderButton_actionAdapter implements java.awt.event.ActionListener {
  419.   OrderFrame adaptee;
  420.  
  421.   OrderFrame_completeOrderButton_actionAdapter(OrderFrame adaptee) {
  422.     this.adaptee = adaptee;
  423.   }
  424.  
  425.   public void actionPerformed(ActionEvent e) {
  426.     adaptee.completeOrderButton_actionPerformed(e);
  427.   }
  428. }
  429.