home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JREFRNCE.Z / FindFrame.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  10.0 KB  |  270 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. //Title:        Cliffhanger Adventure Gear
  22. //Version:      
  23. //Copyright:    Copyright (c) 1997 Borland International, Inc.
  24. //Author:       Application Methods, Inc.
  25. //Description:  Cliffhanger Adventure Gear order entry system
  26.  
  27. package borland.reference.cliffhanger;
  28.  
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import borland.jbcl.layout.*;
  32. import borland.jbcl.control.*;
  33. import borland.jbcl.dataset.*;
  34. import java.util.*;
  35.  
  36. /**
  37.  * FindFrame is the DecoratedFrame class that is used as a base class from
  38.  * which the other Find forms are inherited. This find forms allows users
  39.  * to lookup orders, customers, or products by searching on a value for
  40.  * a single column in the respective dataset. A grid displays all the records
  41.  * for the respective datasets, and the grid will try to find the closet
  42.  * matching record as the user types in the search value.
  43.  */
  44. public class FindFrame extends DecoratedFrame {
  45.   private static FindFrame myFindFrame;
  46.   BevelPanel bevelPanel1 = new BevelPanel();
  47.   GridControl gridControl1 = new GridControl();
  48.   ChoiceControl choiceControl1 = new ChoiceControl();
  49.   LabelControl labelControl1 = new LabelControl();
  50.   LabelControl labelControl2 = new LabelControl();
  51.   BevelPanel bevelPanel2 = new BevelPanel();
  52.   BevelPanel bevelPanel3 = new BevelPanel();
  53.   ButtonControl btnClose = new ButtonControl();
  54.   ButtonControl btnGoto = new ButtonControl();
  55.   BorderLayout borderLayout2 = new BorderLayout();
  56.   GridBagLayout gridBagLayout1 = new GridBagLayout();
  57.   GridBagLayout gridBagLayout2 = new GridBagLayout();
  58.   BorderLayout borderLayout3 = new BorderLayout();
  59.   LocatorControl locatorControl1 = new LocatorControl();
  60.   ResourceBundle res = Res.getBundle("borland.reference.cliffhanger.Res");
  61.   BevelPanel bevelPanel4 = new BevelPanel();
  62.   ImageControl imageControl1 = new ImageControl();
  63.   GridBagLayout gridBagLayout3 = new GridBagLayout();
  64.   StatusBar statusBar1 = new StatusBar();
  65.  
  66.   /**
  67.    * The constructor is protected. Use the getFindFrame method to get
  68.    * an instance of the class.
  69.    */
  70.   protected FindFrame() {
  71.     try {
  72.       jbInit();
  73.     }
  74.     catch (Exception e) {
  75.       e.printStackTrace();
  76.     };
  77.   }
  78.  
  79.   /**
  80.    * Method generated and maintained by JBuilder designer to initialize
  81.    * control properties.
  82.    */
  83.   private void jbInit() throws Exception{
  84.     this.setSize(new Dimension(500, 350));
  85.     this.setTitle(res.getString("FF_Find"));
  86.     this.addWindowListener(new FindFrame_this_windowAdapter(this));
  87.     this.setExitOnClose(false);
  88.     this.setLayout(borderLayout3);
  89.     bevelPanel1.setLayout(borderLayout2);
  90.     bevelPanel1.setBevelOuter(BevelPanel.FLAT);
  91.     gridControl1.setDefaultColumnWidth(80);
  92.     gridControl1.setFont(new Font("Dialog", 0, 12));
  93.     gridControl1.setReadOnly(true);
  94.     choiceControl1.addItemListener(new FindFrame_choiceControl1_itemAdapter(this));
  95.     labelControl1.setText(res.getString("FF_Field"));
  96.     labelControl2.setColumnName("");
  97.     labelControl2.setText(res.getString("FF_Value"));
  98.     bevelPanel2.setBevelInner(BevelPanel.FLAT);
  99.     bevelPanel2.setBevelOuter(BevelPanel.FLAT);
  100.     bevelPanel3.setBevelInner(BevelPanel.FLAT);
  101.     bevelPanel3.setBevelOuter(BevelPanel.FLAT);
  102.     locatorControl1.addKeyListener(new FindFrame_locatorControl1_keyAdapter(this));
  103.     bevelPanel2.setLayout(gridBagLayout2);
  104.     bevelPanel3.setLayout(gridBagLayout1);
  105.     btnClose.setActionCommand("");
  106.     btnClose.setLabel(res.getString("FF_Close"));
  107.     btnClose.addActionListener(new FindFrame_btnClose_actionAdapter(this));
  108.     btnGoto.setActionCommand("");
  109.     btnGoto.setLabel(res.getString("FF_Go_To"));
  110.     bevelPanel4.setBevelInner(BevelPanel.FLAT);
  111.     imageControl1.setImageName(".\\graphics\\findBanner.jpg");
  112.     statusBar1.setBevelOuter(BevelPanel.LOWERED);
  113.     statusBar1.setFont(new Font("Dialog", 0, 10));
  114.     bevelPanel4.setLayout(gridBagLayout3);
  115.     btnGoto.addActionListener(new FindFrame_btnGoto_actionAdapter(this));
  116.     this.add(bevelPanel1, BorderLayout.NORTH);
  117.     bevelPanel1.add(bevelPanel2, BorderLayout.CENTER);
  118.     bevelPanel2.add(choiceControl1, new GridBagConstraints2(1, 0, 2, 1, 100.0, 0.0
  119.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 5), 0, 0));
  120.     bevelPanel2.add(labelControl1, new GridBagConstraints2(0, 0, 1, 1, 10.0, 50.0
  121.             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 10, 1, 0), 0, 0));
  122.     bevelPanel2.add(labelControl2, new GridBagConstraints2(0, 1, 1, 1, 10.0, 50.0
  123.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 10, 5, 0), 0, 0));
  124.     bevelPanel2.add(locatorControl1, new GridBagConstraints2(1, 1, 2, 1, 100.0, 0.0
  125.             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 5), 206, 0));
  126.     bevelPanel1.add(bevelPanel3, BorderLayout.EAST);
  127.     bevelPanel3.add(btnClose, new GridBagConstraints2(0, 0, 1, 1, 100.0, 100.0
  128.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(4, 10, 4, 4), 50, 0));
  129.     bevelPanel3.add(btnGoto, new GridBagConstraints2(0, 1, 1, 1, 100.0, 100.0
  130.             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(4, 10, 4, 4), 0, 0));
  131.     bevelPanel1.add(bevelPanel4, BorderLayout.NORTH);
  132.     bevelPanel4.add(imageControl1, new GridBagConstraints2(0, 0, 1, 1, 1.0, 1.0
  133.             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, -65));
  134.     this.add(gridControl1, BorderLayout.CENTER);
  135.     this.add(statusBar1, BorderLayout.SOUTH);
  136.   }
  137.  
  138.   /**
  139.    * Class method to access the singleton instance of the class
  140.    */
  141.   public static FindFrame getFindFrame() {
  142.     if (myFindFrame == null)
  143.       myFindFrame = new FindFrame();
  144.  
  145.     return myFindFrame;
  146.   }
  147.  
  148.   /**
  149.    * When the Go To button is clicked, the concrete Find forms should
  150.    * override this event handler to show the appropriate form for the
  151.    * record selected.
  152.    */
  153.   void btnGoto_actionPerformed(ActionEvent e) {
  154.   }
  155.  
  156.   /**
  157.    * The itemStateChanged event is triggered when the user selects a new
  158.    * item off the choiceControl's drop down list of possible fields to
  159.    * search on. Reset the text property of the locatorControl to be ready
  160.    * for a new search value.
  161.    */
  162.   void choiceControl1_itemStateChanged(ItemEvent e) {
  163.     locatorControl1.setText("");
  164.   }
  165.  
  166.   /**
  167.    * When the user types in the locatorControl, make sure that the ColumnName
  168.    * property of the locatorControl is set to the column name selected in the
  169.    * ChoiceControl.
  170.    */
  171.   void locatorControl1_keyPressed(KeyEvent e) {
  172.     // Set the columnName property of the locatorControl
  173.     // if it is not set.
  174.     try {
  175.       if ((locatorControl1.getColumnName() == null) ||
  176.       (locatorControl1.getDataSet().getColumn(locatorControl1.getColumnName()).getCaption().compareTo(choiceControl1.getSelectedItem()) != 0)) {
  177.     Column [] columns = locatorControl1.getDataSet().getColumns();
  178.     for (int index = 0; index < columns.length; index++) {
  179.       if (columns[index].getCaption().compareTo(choiceControl1.getSelectedItem()) == 0) {
  180.         locatorControl1.setColumnName(columns[index].getColumnName());
  181.         break;
  182.       }
  183.     }
  184.       }
  185.     } catch (Exception ex) {
  186.       ex.printStackTrace();
  187.     }
  188.   }
  189.  
  190.   /**
  191.    * When Close button is clicked, call this frame's windowClosing
  192.    * event handler to properly handle all dataset pending updates.
  193.    */
  194.   void btnClose_actionPerformed(ActionEvent e) {
  195.     // Close the FindFrame
  196.     this.this_windowClosing(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  197.   }
  198.  
  199.   /**
  200.    * When closing the window, set visible property to false, and dispose of the
  201.    * frame.
  202.    */
  203.   void this_windowClosing(WindowEvent e) {
  204.       setVisible(false);
  205.       dispose();
  206.   }
  207.  
  208. }
  209.  
  210. class FindFrame_btnGoto_actionAdapter implements java.awt.event.ActionListener{
  211.   FindFrame adaptee;
  212.  
  213.   FindFrame_btnGoto_actionAdapter(FindFrame adaptee) {
  214.     this.adaptee = adaptee;
  215.   }
  216.  
  217.   public void actionPerformed(ActionEvent e) {
  218.     adaptee.btnGoto_actionPerformed(e);
  219.   }
  220. }
  221.  
  222. class FindFrame_choiceControl1_itemAdapter implements java.awt.event.ItemListener{
  223.   FindFrame adaptee;
  224.  
  225.   FindFrame_choiceControl1_itemAdapter(FindFrame adaptee) {
  226.     this.adaptee = adaptee;
  227.   }
  228.  
  229.   public void itemStateChanged(ItemEvent e) {
  230.     adaptee.choiceControl1_itemStateChanged(e);
  231.   }
  232. }
  233.  
  234. class FindFrame_locatorControl1_keyAdapter extends java.awt.event.KeyAdapter {
  235.   FindFrame adaptee;
  236.  
  237.   FindFrame_locatorControl1_keyAdapter(FindFrame adaptee) {
  238.     this.adaptee = adaptee;
  239.   }
  240.  
  241.   public void keyPressed(KeyEvent e) {
  242.     adaptee.locatorControl1_keyPressed(e);
  243.   }
  244. }
  245.  
  246. class FindFrame_this_windowAdapter extends java.awt.event.WindowAdapter {
  247.   FindFrame adaptee;
  248.  
  249.   FindFrame_this_windowAdapter(FindFrame adaptee) {
  250.     this.adaptee = adaptee;
  251.   }
  252.  
  253.   public void windowClosing(WindowEvent e) {
  254.     adaptee.this_windowClosing(e);
  255.   }
  256. }
  257.  
  258. class FindFrame_btnClose_actionAdapter implements java.awt.event.ActionListener{
  259.   FindFrame adaptee;
  260.  
  261.   FindFrame_btnClose_actionAdapter(FindFrame adaptee) {
  262.     this.adaptee = adaptee;
  263.   }
  264.  
  265.   public void actionPerformed(ActionEvent e) {
  266.     adaptee.btnClose_actionPerformed(e);
  267.   }
  268. }
  269.  
  270.