home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Inprise / TRIAL / JBUILDER / JSAMPLES.Z / SoldToPanel.java < prev    next >
Text File  |  1998-05-08  |  6KB  |  140 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.  
  21. package borland.samples.intl.gui;
  22.  
  23. import java.awt.*;
  24. import java.awt.event.*;
  25. import java.util.*;
  26. import borland.jbcl.layout.*;
  27. import borland.jbcl.control.*;
  28.  
  29. import borland.samples.intl.application.*;
  30. import borland.samples.intl.beans.*;
  31. import borland.samples.intl.beans.event.*;
  32.  
  33. public class SoldToPanel extends BevelPanel implements LocaleChangeListener {
  34.   private AppDataModule appDataModule = AppDataModule.getDataModule();
  35.  
  36.   LabelControl customerNoLabel = new LabelControl();
  37.   LabelControl customerNoField = new LabelControl();
  38.   BevelPanel customerNoPanel = new BevelPanel();
  39.   BorderLayout borderLayout1 = new BorderLayout();
  40.   InterchangeableCustomerInfoPanel customerInfoPanel;
  41.   ButtonControl lookupCustomerButton = new ButtonControl();
  42.   GridBagLayout gridBagLayout1 = new GridBagLayout();
  43.   GridBagLayout gridBagLayout2 = new GridBagLayout();
  44.   ResourceBundle textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes",
  45.                                                               LocaleChangeManager.getLocale());
  46.   ResourceBundle guiRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.GuiRes",
  47.                                                              LocaleChangeManager.getLocale());
  48.  
  49.   public SoldToPanel() {
  50.     try {
  51.       // customerInfoPanel is loaded at runtime, so we can't design it using
  52.       // the designer.  But we get it and set its properties here so it can
  53.       // be added to the panel in jbInit()
  54.       customerInfoPanel = (InterchangeableCustomerInfoPanel) guiRes.getObject("SoldToCustomerInfoPanel");
  55.       customerInfoPanel.localeChanged(new LocaleChangeEvent(this, LocaleChangeManager.getLocale()));
  56.       jbInit();
  57.       LocaleChangeManager.getLocaleChangeManager().addLocaleChangeListener(this);
  58.     }
  59.     catch (Exception e) {
  60.       e.printStackTrace();
  61.     }
  62.   }
  63.  
  64.   public void jbInit() throws Exception{
  65.     lookupCustomerButton.setLabel(textRes.getString("Find_customer"));
  66.     lookupCustomerButton.addActionListener(new SoldToPanel_lookupCustomerButton_actionAdapter(this));
  67.     customerNoLabel.setText(textRes.getString("Customer_No"));
  68.     customerNoLabel.setAlignment(Label.RIGHT);
  69.     customerNoField.setDataSet(appDataModule.getCustomerDataSet());
  70.     customerNoField.setColumnName("customer_no");
  71.     customerNoField.setAlignment(Label.RIGHT);
  72.     customerNoPanel.setLayout(gridBagLayout2);
  73.     customerNoPanel.setBevelInner(BevelPanel.FLAT);
  74.     customerNoPanel.add(customerNoLabel, null);
  75.     customerNoPanel.add(customerNoField, null);
  76.     customerNoPanel.add(lookupCustomerButton, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
  77.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  78.     customerNoPanel.add(customerNoLabel, new GridBagConstraints2(1, 0, 3, 1, 100.0, 0.0
  79.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
  80.     customerNoPanel.add(customerNoField, new GridBagConstraints2(4, 0, 1, 1, 0.0, 0.0
  81.             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 10), 0, 0));
  82.     this.setLayout(borderLayout1);
  83.  
  84.     this.add((Panel) customerInfoPanel, BorderLayout.CENTER);
  85.     this.add(customerNoPanel, BorderLayout.NORTH);
  86.  
  87.   }
  88.  
  89.   
  90.   void lookupCustomerButton_actionPerformed(ActionEvent e) {
  91.      try {
  92.        Component component = this;
  93.        Frame frame = null;
  94.  
  95.        while ((component = component.getParent()) != null) {
  96.          if (component instanceof Frame) {
  97.            frame = (Frame) component;
  98.            break;
  99.          }
  100.        }
  101.  
  102.        if (frame == null) {
  103.          frame = new Frame();
  104.        }
  105.        CustomerLookupDialog customerLookupDialog = new CustomerLookupDialog(frame, true);
  106.        customerLookupDialog.show();
  107.        if (customerLookupDialog.isValidCustomer()) {
  108.          appDataModule.syncCustomerNoWithCurrentOrder();
  109.        }
  110.      } catch (Exception ex) {
  111.        borland.jbcl.util.Diagnostic.printStackTrace(ex);
  112.      }
  113.      
  114.   }
  115.  
  116.   public void localeChanged(LocaleChangeEvent e) {
  117.     textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes", e.getLocale());
  118.     guiRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.GuiRes", e.getLocale());
  119.     customerNoLabel.setText(textRes.getString("Customer_No"));
  120.     lookupCustomerButton.setLabel(textRes.getString("Find_customer"));
  121.     this.remove((Panel) customerInfoPanel);
  122.     customerInfoPanel = (InterchangeableCustomerInfoPanel) guiRes.getObject("SoldToCustomerInfoPanel");
  123.     customerInfoPanel.localeChanged(e);
  124.     this.add((Panel) customerInfoPanel, BorderLayout.CENTER);
  125.   }
  126.  
  127. }
  128.  
  129. class SoldToPanel_lookupCustomerButton_actionAdapter implements java.awt.event.ActionListener{
  130.   SoldToPanel adaptee;
  131.  
  132.   SoldToPanel_lookupCustomerButton_actionAdapter(SoldToPanel adaptee) {
  133.     this.adaptee = adaptee;
  134.   }
  135.  
  136.   public void actionPerformed(ActionEvent e) {
  137.     adaptee.lookupCustomerButton_actionPerformed(e);
  138.   }
  139. }
  140.