home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / ProductFrame.java < prev    next >
Text File  |  1997-07-30  |  12KB  |  294 lines

  1. package borland.samples.intl.gui;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.util.*;
  6. import borland.jbcl.layout.*;
  7. import borland.jbcl.control.*;
  8. import borland.jbcl.view.*;
  9. import borland.jbcl.util.*;
  10.  
  11. import borland.samples.intl.application.*;
  12. import borland.samples.intl.beans.*;
  13. import borland.samples.intl.beans.event.*;
  14.  
  15. public class ProductFrame extends DecoratedFrame implements LocaleChangeListener{
  16.   private static ProductFrame productFrame = null;
  17.  
  18.   GridBagLayout gridBagLayout1 = new GridBagLayout();
  19.   GridBagLayout gridBagLayout2 = new GridBagLayout();
  20.   GridBagLayout gridBagLayout3 = new GridBagLayout();
  21.  
  22.   GridLayout gridLayout1 = new GridLayout();
  23.   GridLayout gridLayout2 = new GridLayout();
  24.   GridLayout gridLayout3 = new GridLayout();
  25.  
  26.   XYLayout xYLayout1 = new XYLayout();
  27.  
  28.   ViewOnlyNavigationBar viewOnlyNavigationBar = new ViewOnlyNavigationBar();
  29.  
  30.   CheckboxPanel checkboxPanel1 = new CheckboxPanel();
  31.  
  32.   BevelPanel bevelPanel1 = new BevelPanel();
  33.   BevelPanel bevelPanel2 = new BevelPanel();
  34.   BevelPanel bevelPanel3 = new BevelPanel();
  35.   BevelPanel bevelPanel4 = new BevelPanel();
  36.   BevelPanel bevelPanel5 = new BevelPanel();
  37.   BevelPanel bevelPanel6 = new BevelPanel();
  38.  
  39.   LabelControl labelControl1 = new LabelControl();
  40.   LabelControl labelControl2 = new LabelControl();
  41.   LabelControl labelControl4 = new LabelControl();
  42.   FieldControl fieldControl1 = new FieldControl();
  43.   FieldControl fieldControl2 = new FieldControl();
  44.   WrappingTextViewer wrappingTextViewer1 = new WrappingTextViewer();
  45.   LabelControl labelControl6 = new LabelControl();
  46.   ImageControl imageControl1 = new ImageControl();
  47.   ButtonControl buttonControl1 = new ButtonControl();
  48.   ButtonControl buttonControl2 = new ButtonControl();
  49.   ButtonControl buttonControl3 = new ButtonControl();
  50.  
  51.   private static AppDataModule appDataModule = AppDataModule.getDataModule();
  52.   ResourceBundle textRes = ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes");
  53.  
  54.   public static ProductFrame getInstance() {
  55.     if (productFrame == null) {
  56.       productFrame = new ProductFrame();
  57.       productFrame.pack();
  58.       //Center the window
  59.       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  60.       Dimension frameSize = productFrame.getPreferredSize();
  61.       if (frameSize.height > screenSize.height)
  62.     frameSize.height = screenSize.height;
  63.       if (frameSize.width > screenSize.width)
  64.     frameSize.width = screenSize.width;
  65.       productFrame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
  66.       productFrame.setSize(frameSize.width + 10, frameSize.height + 10);
  67.     }
  68.     return productFrame;
  69.   }
  70.  
  71.   protected ProductFrame() {
  72.     try {
  73.       jbInit();
  74.       LocaleChangeManager.getLocaleChangeManager().addLocaleChangeListener(this);
  75.     }
  76.     catch (Exception e) {
  77.       borland.jbcl.util.Diagnostic.printStackTrace(e);
  78.     };
  79.   }
  80.  
  81.   void jbInit() throws Exception{
  82.     this.setLayout(gridBagLayout2);
  83.  
  84.     this.add(labelControl1, new GridBagConstraints2(0, 0, 3, 1, 100.0, 0.0
  85.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  86.  
  87.     this.add(checkboxPanel1, new GridBagConstraints2(0, 1, 3, 1, 100.0, 0.0
  88.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  89.  
  90.     xYLayout1.setWidth(200);
  91.     xYLayout1.setHeight(200);
  92.     bevelPanel1.setLayout(xYLayout1);
  93.     bevelPanel1.add(imageControl1, new XYConstraints(0, 0, 200, 200));
  94.     bevelPanel1.setEnabled(false);
  95.  
  96.     this.add(bevelPanel1, new GridBagConstraints2(2, 2, 1, 3, 0.0, 0.0
  97.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  98.  
  99.     bevelPanel2.setLayout(gridBagLayout1);
  100.     bevelPanel2.setBevelInner(BevelPanel.FLAT);
  101.     bevelPanel2.add(labelControl2, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  102.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  103.     bevelPanel2.add(fieldControl2, new GridBagConstraints2(1, 0, 1, 1, 100.0, 0.0
  104.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  105.     bevelPanel2.add(labelControl4, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
  106.             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  107.     bevelPanel2.add(fieldControl1, new GridBagConstraints2(1, 1, 1, 1, 100.0, 0.0
  108.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  109.     bevelPanel2.add(labelControl6, new GridBagConstraints2(0, 2, 2, 1, 100.0, 0.0
  110.             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  111.     bevelPanel2.add(wrappingTextViewer1, new GridBagConstraints2(0, 3, 2, 2, 100.0, 100.0
  112.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  113.  
  114.     this.add(bevelPanel2, new GridBagConstraints2(0, 2, 2, 3, 100.0, 100.0
  115.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  116.  
  117.     this.add(viewOnlyNavigationBar, new GridBagConstraints2(0, 5, 3, 1, 100.0, 0.0
  118.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  119.  
  120.     bevelPanel4.setLayout(gridLayout1);
  121.     gridLayout1.setRows(1);
  122.     gridLayout1.setColumns(3);
  123.     gridLayout1.setHgap(20);
  124.     bevelPanel4.setMargins(new Insets(10, 10, 10, 10));
  125.     bevelPanel4.add(buttonControl1, null);
  126.     bevelPanel4.add(buttonControl2, null);
  127.     bevelPanel4.add(buttonControl3, null);
  128.  
  129.     this.add(bevelPanel4, new GridBagConstraints2(0, 6, 3, 1, 100.0, 0.0
  130.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  131.  
  132.     imageControl1.setDataSet(appDataModule.getProductsDataSet());
  133.     imageControl1.setColumnName("image");
  134.     imageControl1.setReadOnly(true);
  135.  
  136.     labelControl1.setFont(new Font("serif", 1, 24));
  137.     labelControl1.setText(textRes.getString("The_Borland_Store"));
  138.     labelControl1.setAlignment(Label.LEFT);
  139.  
  140.     checkboxPanel1.setOrientation(0);
  141.     checkboxPanel1.setGrouped(true);
  142.     checkboxPanel1.setLabels(new String[] {textRes.getString("All_Products"),
  143.                        textRes.getString("Software_Products"),
  144.                        textRes.getString("Deskware_Products"),
  145.                        textRes.getString("Bodyware_Products")});
  146.     checkboxPanel1.setSelectedIndex(0);
  147.     checkboxPanel1.addItemListener(new ProductFrame_checkboxPanel1_itemAdapter(this));
  148.  
  149.  
  150.     labelControl2.setText(textRes.getString("Item_No"));
  151.     fieldControl2.setColumnName("sku");
  152.     fieldControl2.setDataSet(appDataModule.getProductsDataSet());
  153.     fieldControl2.setReadOnly(true);
  154.     fieldControl2.setEnabled(false);
  155.     fieldControl2.setBackground(SystemColor.control);
  156.     fieldControl2.setAlignment(Alignment.RIGHT);
  157.     labelControl4.setText(textRes.getString("Unit_Price"));
  158. //    labelControl5.setColumnName("unit_price");
  159. //    labelControl5.setDataSet(appDataModule.getProductsDataSet());
  160.     fieldControl1.setColumnName("unit_price");
  161.     fieldControl1.setDataSet(appDataModule.getProductsDataSet());
  162.     fieldControl1.setReadOnly(true);
  163.     fieldControl1.setEnabled(false);
  164.     fieldControl1.setAlignment(Alignment.RIGHT);
  165.     fieldControl1.setBackground(SystemColor.control);
  166.     labelControl6.setText(textRes.getString("Description"));
  167.  
  168.     buttonControl1.setLabel(textRes.getString("Add_to_Order"));
  169.     buttonControl1.addActionListener(new ProductFrame_buttonControl1_actionAdapter(this));
  170.     buttonControl2.setLabel(textRes.getString("View_Order"));
  171.     buttonControl2.addActionListener(new ProductFrame_buttonControl2_actionAdapter(this));
  172.     buttonControl3.setLabel(textRes.getString("Close"));
  173.     buttonControl3.addActionListener(new ProductFrame_buttonControl3_actionAdapter(this));
  174.  
  175.  
  176.     viewOnlyNavigationBar.setDataSet(appDataModule.getProductsDataSet());
  177.  
  178.     this.setTitle(textRes.getString("Borland_Store_Products"));
  179.  
  180.     wrappingTextViewer1.setColumnName("description");
  181.     wrappingTextViewer1.setDataSet(appDataModule.getProductsDataSet());
  182.  
  183.   }
  184.  
  185.   protected void processWindowEvent(WindowEvent e) {
  186.     if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  187.       this.setVisible(false);
  188.     }
  189.   }
  190.  
  191.   void checkboxPanel1_itemStateChanged(java.awt.event.ItemEvent e) {
  192.   // filter products based upon the type of category
  193.     if (e.getItem().equals(textRes.getString("All_Products"))) {
  194. //      System.out.println("Setting NO_PRODUCT_FILTER");
  195.       appDataModule.filterProducts(AppDataModule.NO_PRODUCT_FILTER);
  196.     } else {
  197. //      System.out.println("Setting filter on: " + checkboxPanel1.getSelectedIndex());
  198.       appDataModule.filterProducts(checkboxPanel1.getSelectedIndex());
  199.     }
  200.   }
  201.  
  202.   void buttonControl1_actionPerformed(java.awt.event.ActionEvent e) {
  203.     this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  204.     WelcomeFrame.getInstance().setAllowOrderViewing(false);
  205.     OrderFrame.getInstance().setBatchUpdateMode(true);
  206.     appDataModule.addProductToOrderLineItem();
  207.     OrderFrame.getInstance().setBatchUpdateMode(false);
  208.     this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  209.   }
  210.  
  211.   public void localeChanged(LocaleChangeEvent e) {
  212.     textRes = ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes", e.getLocale());
  213.     labelControl1.setText(textRes.getString("The_Borland_Store"));
  214.  
  215.     checkboxPanel1.setLabels(new String[] {textRes.getString("All_Products"),
  216.                        textRes.getString("Software_Products"),
  217.                        textRes.getString("Deskware_Products"),
  218.                        textRes.getString("Bodyware_Products")});
  219.     checkboxPanel1.setSelectedIndex(0);
  220.  
  221.     labelControl2.setText(textRes.getString("Item_No"));
  222.     labelControl4.setText(textRes.getString("Unit_Price"));
  223.     labelControl6.setText(textRes.getString("Description"));
  224.  
  225.     buttonControl1.setLabel(textRes.getString("Add_to_Order"));
  226.     buttonControl2.setLabel(textRes.getString("View_Order"));
  227.     buttonControl3.setLabel(textRes.getString("Close"));
  228.     this.setTitle(textRes.getString("Borland_Store_Products"));
  229.     this.pack();
  230.   }
  231.  
  232.   
  233.   void buttonControl2_actionPerformed(java.awt.event.ActionEvent e) {
  234.     this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  235.     WelcomeFrame.getInstance().setAllowOrderViewing(false);
  236.     appDataModule.initializeOrder();
  237.     OrderFrame.getInstance().setVisible(true);
  238.     this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  239.   }
  240.   
  241.   void buttonControl3_actionPerformed(java.awt.event.ActionEvent e) {
  242.     this.setVisible(false);
  243.   }
  244.  
  245. }
  246.  
  247. class ProductFrame_checkboxPanel1_itemAdapter implements java.awt.event.ItemListener {
  248.   ProductFrame adaptee;
  249.  
  250.   ProductFrame_checkboxPanel1_itemAdapter(ProductFrame adaptee) {
  251.     this.adaptee = adaptee;
  252.   }
  253.  
  254.   public void itemStateChanged(java.awt.event.ItemEvent e) {
  255.     adaptee.checkboxPanel1_itemStateChanged(e);
  256.   }
  257. }
  258.  
  259. class ProductFrame_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
  260.   ProductFrame adaptee;
  261.  
  262.   ProductFrame_buttonControl1_actionAdapter(ProductFrame adaptee) {
  263.     this.adaptee = adaptee;
  264.   }
  265.  
  266.   public void actionPerformed(java.awt.event.ActionEvent e) {
  267.     adaptee.buttonControl1_actionPerformed(e);
  268.   }
  269. }
  270.  
  271. class ProductFrame_buttonControl2_actionAdapter implements java.awt.event.ActionListener {
  272.   ProductFrame adaptee;
  273.  
  274.   ProductFrame_buttonControl2_actionAdapter(ProductFrame adaptee) {
  275.     this.adaptee = adaptee;
  276.   }
  277.  
  278.   public void actionPerformed(java.awt.event.ActionEvent e) {
  279.     adaptee.buttonControl2_actionPerformed(e);
  280.   }
  281. }
  282.  
  283. class ProductFrame_buttonControl3_actionAdapter implements java.awt.event.ActionListener {
  284.   ProductFrame adaptee;
  285.  
  286.   ProductFrame_buttonControl3_actionAdapter(ProductFrame adaptee) {
  287.     this.adaptee = adaptee;
  288.   }
  289.  
  290.   public void actionPerformed(java.awt.event.ActionEvent e) {
  291.     adaptee.buttonControl3_actionPerformed(e);
  292.   }
  293. }
  294.