home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / inprise / JSAMPLES.Z / ProductFrame.java < prev    next >
Text File  |  1998-05-08  |  14KB  |  329 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20. package borland.samples.intl.gui;
  21.  
  22. import java.awt.*;
  23. import java.awt.event.*;
  24. import java.util.*;
  25. import borland.jbcl.layout.*;
  26. import borland.jbcl.control.*;
  27. import borland.jbcl.view.*;
  28. import borland.jbcl.util.*;
  29.  
  30. import borland.samples.intl.application.*;
  31. import borland.samples.intl.beans.*;
  32. import borland.samples.intl.beans.event.*;
  33.  
  34. public class ProductFrame extends DecoratedFrame implements LocaleChangeListener{
  35.   private static ProductFrame productFrame = null;
  36.  
  37.   GridBagLayout gridBagLayout1 = new GridBagLayout();
  38.   GridBagLayout gridBagLayout2 = new GridBagLayout();
  39.   GridBagLayout gridBagLayout3 = new GridBagLayout();
  40.  
  41.   GridLayout gridLayout1 = new GridLayout();
  42.   GridLayout gridLayout2 = new GridLayout();
  43.   GridLayout gridLayout3 = new GridLayout();
  44.  
  45.   XYLayout xYLayout1 = new XYLayout();     
  46.  
  47.   ViewOnlyNavigationBar viewOnlyNavigationBar = new ViewOnlyNavigationBar();
  48.  
  49.   CheckboxPanel checkboxPanel1 = new CheckboxPanel();
  50.  
  51.   BevelPanel bevelPanel1 = new BevelPanel();
  52.   BevelPanel bevelPanel2 = new BevelPanel();
  53.   BevelPanel bevelPanel3 = new BevelPanel();
  54.   BevelPanel bevelPanel4 = new BevelPanel();                
  55.   BevelPanel bevelPanel5 = new BevelPanel();
  56.   BevelPanel bevelPanel6 = new BevelPanel();
  57.  
  58.   LabelControl labelControl1 = new LabelControl();
  59.   LabelControl labelControl2 = new LabelControl();
  60.   LabelControl labelControl3 = new LabelControl();
  61.   LabelControl labelControl4 = new LabelControl();
  62.   LabelControl labelControl5 = new LabelControl();
  63.   WrappingTextViewer wrappingTextViewer1 = new WrappingTextViewer();
  64.   LabelControl labelControl6 = new LabelControl();
  65.   ImageControl imageControl1 = new ImageControl();
  66.   ButtonControl buttonControl1 = new ButtonControl();
  67.   ButtonControl buttonControl2 = new ButtonControl();
  68.   ButtonControl buttonControl3 = new ButtonControl();
  69.  
  70.   private static AppDataModule appDataModule = AppDataModule.getDataModule();
  71.   ResourceBundle textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes",
  72.                                                               LocaleChangeManager.getLocale());
  73.  
  74.   public static ProductFrame getInstance() {
  75.     if (productFrame == null) {
  76.       productFrame = new ProductFrame();
  77.     }
  78.     return productFrame;
  79.   }
  80.  
  81.   protected ProductFrame() {
  82.     try {
  83.       jbInit();
  84.       // For cosmetic reasons, because we want the wrappingTextViewer's to be
  85.       // the same height as its ImageControl neighbor, we set its preferred size
  86.       // to be smaller than its neighbor.  This effectively removes the size of
  87.       // the wrappingTextViewer from the calculation of the packed frame.
  88.       // Note that the wrappingTextViewer can accommodate any non-zero size.
  89.       wrappingTextViewer1.setPreferredSize(new Dimension(50, 50));
  90.       LocaleChangeManager.getLocaleChangeManager().addLocaleChangeListener(this);
  91.     }
  92.     catch (Exception e) {
  93.       borland.jbcl.util.Diagnostic.printStackTrace(e);
  94.     };
  95.   }
  96.  
  97.   public void addNotify() {
  98.     super.addNotify();
  99.     productFrame.pack();
  100.     //Center the window
  101.     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  102.     Dimension frameSize = productFrame.getPreferredSize();
  103.     if (frameSize.height > screenSize.height)
  104.       frameSize.height = screenSize.height;
  105.     if (frameSize.width > screenSize.width)
  106.       frameSize.width = screenSize.width;
  107.     productFrame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
  108.   }
  109.  
  110.   void jbInit() throws Exception{
  111.     this.setLayout(gridBagLayout2);
  112.  
  113.     this.add(labelControl1, new GridBagConstraints2(0, 0, 3, 1, 100.0, 0.0
  114.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  115.  
  116.     this.add(checkboxPanel1, new GridBagConstraints2(0, 1, 3, 1, 100.0, 0.0
  117.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  118.  
  119.     xYLayout1.setWidth(200);
  120.     xYLayout1.setHeight(200);
  121.     bevelPanel1.setLayout(xYLayout1);
  122.     bevelPanel1.add(imageControl1, new XYConstraints(0, 0, 200, 200));
  123.     bevelPanel1.setEnabled(false);
  124.  
  125.     this.add(bevelPanel1, new GridBagConstraints2(2, 2, 1, 3, 0.0, 0.0
  126.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  127.  
  128.     bevelPanel2.setLayout(gridBagLayout1);
  129.     bevelPanel2.setBevelInner(BevelPanel.FLAT);
  130.     bevelPanel2.add(labelControl2, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  131.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 0, 10), 0, 0));
  132.     bevelPanel2.add(labelControl3, new GridBagConstraints2(1, 0, 1, 1, 100.0, 0.0
  133.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));
  134.     bevelPanel2.add(labelControl4, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
  135.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 0, 10), 0, 0));
  136.     bevelPanel2.add(labelControl5, new GridBagConstraints2(1, 1, 1, 1, 100.0, 0.0
  137.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));
  138.     bevelPanel2.add(labelControl6, new GridBagConstraints2(0, 2, 2, 1, 100.0, 0.0
  139.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));
  140.     bevelPanel2.add(wrappingTextViewer1, new GridBagConstraints2(0, 3, 2, 2, 100.0, 100.0
  141.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  142.  
  143.     this.add(bevelPanel2, new GridBagConstraints2(0, 2, 2, 3, 100.0, 100.0
  144.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  145.  
  146.     this.add(viewOnlyNavigationBar, new GridBagConstraints2(0, 5, 3, 1, 100.0, 0.0
  147.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  148.  
  149.     bevelPanel4.setLayout(gridLayout1);
  150.     gridLayout1.setRows(1);
  151.     gridLayout1.setColumns(3);
  152.     gridLayout1.setHgap(20);
  153.     bevelPanel4.setMargins(new Insets(10, 10, 10, 10));
  154.     bevelPanel4.add(buttonControl1, null);
  155.     bevelPanel4.add(buttonControl2, null);
  156.     bevelPanel4.add(buttonControl3, null);
  157.  
  158.     this.add(bevelPanel4, new GridBagConstraints2(0, 6, 3, 1, 100.0, 0.0
  159.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  160.  
  161.     imageControl1.setDataSet(appDataModule.getProductsDataSet());
  162.     imageControl1.setColumnName("image");
  163.     imageControl1.setReadOnly(true);
  164.  
  165.     labelControl1.setFont(new Font("serif", 1, 24));
  166.     labelControl1.setText(textRes.getString("The_Borland_Store"));
  167.     labelControl1.setAlignment(Label.LEFT);
  168.  
  169.     checkboxPanel1.setOrientation(0);
  170.     checkboxPanel1.setGrouped(true);
  171.     checkboxPanel1.setLabels(new String[] {textRes.getString("All_Products"),
  172.                                            textRes.getString("Software_Products"),
  173.                                            textRes.getString("Deskware_Products"),
  174.                                            textRes.getString("Bodyware_Products")});
  175.     checkboxPanel1.setSelectedIndex(0);
  176.     checkboxPanel1.addItemListener(new ProductFrame_checkboxPanel1_itemAdapter(this));
  177.  
  178.  
  179.     labelControl2.setText(textRes.getString("Item_No"));
  180.     labelControl3.setColumnName("sku");
  181.     labelControl3.setDataSet(appDataModule.getProductsDataSet());
  182.     labelControl3.setAlignment(Label.RIGHT);
  183.     labelControl4.setText(textRes.getString("Unit_Price"));
  184.     labelControl5.setColumnName("unit_price");
  185.     labelControl5.setDataSet(appDataModule.getProductsDataSet());
  186.     labelControl5.setAlignment(Label.RIGHT);
  187.     labelControl6.setText(textRes.getString("Description"));
  188.  
  189.     buttonControl1.setLabel(textRes.getString("Add_to_Order"));
  190.     buttonControl1.addActionListener(new ProductFrame_buttonControl1_actionAdapter(this));
  191.     buttonControl2.setLabel(textRes.getString("View_Order"));
  192.     buttonControl2.addActionListener(new ProductFrame_buttonControl2_actionAdapter(this));
  193.     buttonControl3.setLabel(textRes.getString("Close"));
  194.     buttonControl3.addActionListener(new ProductFrame_buttonControl3_actionAdapter(this));
  195.  
  196.  
  197.     viewOnlyNavigationBar.setDataSet(appDataModule.getProductsDataSet());
  198.  
  199.     this.setSize(new Dimension(478, 392));
  200.     this.setTitle(textRes.getString("Borland_Store_Products"));
  201.  
  202.     wrappingTextViewer1.setColumnName("description");
  203.     wrappingTextViewer1.setDataSet(appDataModule.getProductsDataSet());
  204.  
  205.   }
  206.  
  207.   protected void processWindowEvent(WindowEvent e) {
  208.     if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  209.       this.setVisible(false);
  210.     }
  211.   }
  212.  
  213.   void checkboxPanel1_itemStateChanged(java.awt.event.ItemEvent e) {
  214.   // filter products based upon the type of category
  215.     if (e.getItem().equals(textRes.getString("All_Products"))) {
  216. //      System.out.println("Setting NO_PRODUCT_FILTER");
  217.       appDataModule.filterProducts(AppDataModule.NO_PRODUCT_FILTER);
  218.     } else {
  219. //      System.out.println("Setting filter on: " + checkboxPanel1.getSelectedIndex());
  220.       appDataModule.filterProducts(checkboxPanel1.getSelectedIndex());
  221.     }
  222.   }
  223.  
  224.   void buttonControl1_actionPerformed(java.awt.event.ActionEvent e) {
  225.     this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  226.     WelcomeFrame.getInstance().setAllowOrderViewing(false);
  227.     OrderFrame.getInstance().setBatchUpdateMode(true);
  228.     appDataModule.addProductToOrderLineItem();
  229.     OrderFrame.getInstance().setBatchUpdateMode(false);
  230.     this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  231.   }
  232.  
  233.   public void localeChanged(LocaleChangeEvent e) {
  234.     textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes", e.getLocale());
  235.     labelControl1.setText(textRes.getString("The_Borland_Store"));
  236.     labelControl1.invalidate();
  237.  
  238.     int currentIndex = checkboxPanel1.getSelectedIndex();
  239.     checkboxPanel1.setLabels(new String[] {textRes.getString("All_Products"),
  240.                                            textRes.getString("Software_Products"),
  241.                                            textRes.getString("Deskware_Products"),
  242.                                            textRes.getString("Bodyware_Products")});
  243.     checkboxPanel1.invalidate();
  244.     checkboxPanel1.setSelectedIndex(currentIndex);
  245.  
  246.     labelControl2.setText(textRes.getString("Item_No"));
  247.     labelControl2.invalidate();
  248.     labelControl4.setText(textRes.getString("Unit_Price"));
  249.     labelControl4.invalidate();
  250.     labelControl6.setText(textRes.getString("Description"));
  251.     labelControl6.invalidate();
  252.  
  253.     buttonControl1.setLabel(textRes.getString("Add_to_Order"));
  254.     buttonControl1.invalidate();
  255.     buttonControl2.setLabel(textRes.getString("View_Order"));
  256.     buttonControl2.invalidate();
  257.     buttonControl3.setLabel(textRes.getString("Close"));
  258.     buttonControl3.invalidate();
  259.  
  260.     wrappingTextViewer1.setLocale(e.getLocale());
  261.     wrappingTextViewer1.invalidate();
  262.  
  263.     this.setTitle(textRes.getString("Borland_Store_Products"));
  264.     this.pack();
  265.   }
  266.  
  267.   
  268.   void buttonControl2_actionPerformed(java.awt.event.ActionEvent e) {
  269.     this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  270.     WelcomeFrame.getInstance().setAllowOrderViewing(false);
  271.     appDataModule.initializeOrder();
  272.     OrderFrame.getInstance().setVisible(true);
  273.     this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  274.   }
  275.   
  276.   void buttonControl3_actionPerformed(java.awt.event.ActionEvent e) {
  277.     this.setVisible(false);
  278.   }
  279.  
  280. }
  281.  
  282. class ProductFrame_checkboxPanel1_itemAdapter implements java.awt.event.ItemListener {
  283.   ProductFrame adaptee;
  284.  
  285.   ProductFrame_checkboxPanel1_itemAdapter(ProductFrame adaptee) {
  286.     this.adaptee = adaptee;
  287.   }
  288.  
  289.   public void itemStateChanged(java.awt.event.ItemEvent e) {
  290.     adaptee.checkboxPanel1_itemStateChanged(e);
  291.   }
  292. }
  293.  
  294. class ProductFrame_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
  295.   ProductFrame adaptee;
  296.  
  297.   ProductFrame_buttonControl1_actionAdapter(ProductFrame adaptee) {
  298.     this.adaptee = adaptee;
  299.   }
  300.  
  301.   public void actionPerformed(java.awt.event.ActionEvent e) {
  302.     adaptee.buttonControl1_actionPerformed(e);
  303.   }
  304. }
  305.  
  306. class ProductFrame_buttonControl2_actionAdapter implements java.awt.event.ActionListener {
  307.   ProductFrame adaptee;
  308.  
  309.   ProductFrame_buttonControl2_actionAdapter(ProductFrame adaptee) {
  310.     this.adaptee = adaptee;
  311.   }
  312.  
  313.   public void actionPerformed(java.awt.event.ActionEvent e) {
  314.     adaptee.buttonControl2_actionPerformed(e);
  315.   }
  316. }
  317.  
  318. class ProductFrame_buttonControl3_actionAdapter implements java.awt.event.ActionListener {
  319.   ProductFrame adaptee;
  320.  
  321.   ProductFrame_buttonControl3_actionAdapter(ProductFrame adaptee) {
  322.     this.adaptee = adaptee;
  323.   }
  324.  
  325.   public void actionPerformed(java.awt.event.ActionEvent e) {
  326.     adaptee.buttonControl3_actionPerformed(e);
  327.   }
  328. }
  329.