home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jruntime.z / DualListBox.java < prev    next >
Text File  |  1997-08-25  |  5KB  |  190 lines

  1. // This snippet creates a new about box.
  2. // <File=DualListBox.java>
  3.  
  4. //Title:
  5. //Version:
  6. //Copyright:
  7. //Author:
  8. //Company:
  9. //Description:
  10. //
  11.  
  12. //<PACKAGE>
  13.  
  14. import java.awt.*;
  15. import java.awt.event.*;
  16. import borland.jbcl.layout.*;
  17. import borland.jbcl.control.*;
  18.  
  19. public class DualListBox extends BevelPanel {
  20.   XYLayout xYLayout1 = new XYLayout();
  21.   List source = new List();
  22.   List destination = new List();
  23.   Button addOne = new Button();
  24.   Button addAll = new Button();
  25.   Button removeOne = new Button();
  26.   Button removeAll = new Button();
  27.   Label label1 = new Label();
  28.   Button ok = new Button();
  29.   Button cancel = new Button();
  30.   Label label2 = new Label();
  31.  
  32.   public DualListBox() {
  33.     try {
  34.       jbInit();
  35.     }
  36.     catch (Exception e) {
  37.       e.printStackTrace();
  38.     }
  39.   }
  40.  
  41.   public void jbInit()  throws Exception {
  42.     xYLayout1.setWidth(368);
  43.     xYLayout1.setHeight(231);
  44.     addOne.setLabel(">");
  45.     addOne.addActionListener(new DualListBox_addOne_actionAdapter(this));
  46.     addAll.setLabel(">>");
  47.     addAll.addActionListener(new DualListBox_addAll_actionAdapter(this));
  48.     removeOne.setLabel("<");
  49.     removeOne.addActionListener(new DualListBox_removeOne_actionAdapter(this));
  50.     removeAll.setLabel("<<");
  51.     removeAll.addActionListener(new DualListBox_removeAll_actionAdapter(this));
  52.     label1.setText("Source list");
  53.     ok.setLabel("OK");
  54.     ok.addActionListener(new DualListBox_ok_actionAdapter(this));
  55.     cancel.setLabel("Cancel");
  56.     cancel.addActionListener(new DualListBox_cancel_actionAdapter(this));
  57.     label2.setText("Destination list");
  58.     this.setLayout(xYLayout1);
  59.     this.add(source, new XYConstraints(13, 22, 140, 172));
  60.     this.add(destination, new XYConstraints(214, 20, 140, 176));
  61.     this.add(addOne, new XYConstraints(166, 35, 32, 21));
  62.     this.add(addAll, new XYConstraints(166, 61, 32, 21));
  63.     this.add(removeOne, new XYConstraints(166, 130, 32, 21));
  64.     this.add(removeAll, new XYConstraints(166, 160, 32, 21));
  65.     this.add(label1, new XYConstraints(13, 4, 140, 14));
  66.     this.add(ok, new XYConstraints(198, 206, 78, 21));
  67.     this.add(cancel, new XYConstraints(283, 205, 68, 21));
  68.     this.add(label2, new XYConstraints(213, 3, 140, 17));
  69.   }
  70.   
  71.   void addOne_actionPerformed(ActionEvent e) {
  72.     destination.addItem(source.getSelectedItem());
  73.     source.remove(source.getSelectedIndex());
  74.   }
  75.  
  76.   void addAll_actionPerformed(ActionEvent e) {
  77.     for (int i = 0; i < source.getItemCount(); i++) {
  78.       destination.addItem(source.getItem(i));
  79.     }
  80.     source.removeAll();
  81.   }
  82.  
  83.   void removeOne_actionPerformed(ActionEvent e) {
  84.     source.addItem(destination.getSelectedItem());
  85.     destination.remove(destination.getSelectedIndex());
  86.   }
  87.  
  88.   void removeAll_actionPerformed(ActionEvent e) {
  89.     for (int i = 0; i < destination.getItemCount(); i++) {
  90.       source.addItem(destination.getItem(i));
  91.     }
  92.     destination.removeAll();
  93.   }
  94.  
  95.   void ok_actionPerformed(ActionEvent e) {
  96.  
  97.   }
  98.   
  99.   void cancel_actionPerformed(ActionEvent e) {
  100.  
  101.   }
  102. //<Exclude>
  103.   // Test case
  104.   public static void main(String[] argv) {
  105.     DecoratedFrame frame = new DecoratedFrame();
  106.     DualListBox dlb=new DualListBox();
  107.     dlb.source.addItem("One");
  108.     dlb.source.addItem("Two");
  109.     dlb.source.addItem("Three");
  110.     dlb.source.addItem("Four");
  111.     dlb.source.addItem("Five");
  112.     frame.add(dlb);
  113.     frame.pack();
  114.     frame.show();
  115.   }
  116. //</Exclude>
  117. }
  118.  
  119. class DualListBox_addOne_actionAdapter implements ActionListener {
  120.   DualListBox adaptee;
  121.  
  122.   DualListBox_addOne_actionAdapter(DualListBox adaptee) {
  123.     this.adaptee = adaptee;
  124.   }
  125.  
  126.   public void actionPerformed(ActionEvent e) {
  127.     adaptee.addOne_actionPerformed(e);
  128.   }
  129. }
  130.  
  131. class DualListBox_addAll_actionAdapter implements ActionListener {
  132.   DualListBox adaptee;
  133.  
  134.   DualListBox_addAll_actionAdapter(DualListBox adaptee) {
  135.     this.adaptee = adaptee;
  136.   }
  137.  
  138.   public void actionPerformed(ActionEvent e) {
  139.     adaptee.addAll_actionPerformed(e);
  140.   }
  141. }
  142.  
  143. class DualListBox_removeOne_actionAdapter implements ActionListener {
  144.   DualListBox adaptee;
  145.  
  146.   DualListBox_removeOne_actionAdapter(DualListBox adaptee) {
  147.     this.adaptee = adaptee;
  148.   }
  149.  
  150.   public void actionPerformed(ActionEvent e) {
  151.     adaptee.removeOne_actionPerformed(e);
  152.   }
  153. }
  154.  
  155. class DualListBox_removeAll_actionAdapter implements ActionListener {
  156.   DualListBox adaptee;
  157.  
  158.   DualListBox_removeAll_actionAdapter(DualListBox adaptee) {
  159.     this.adaptee = adaptee;
  160.   }
  161.  
  162.   public void actionPerformed(ActionEvent e) {
  163.     adaptee.removeAll_actionPerformed(e);
  164.   }
  165. }
  166.  
  167. class DualListBox_ok_actionAdapter implements ActionListener {
  168.   DualListBox adaptee;
  169.  
  170.   DualListBox_ok_actionAdapter(DualListBox adaptee) {
  171.     this.adaptee = adaptee;
  172.   }
  173.  
  174.   public void actionPerformed(ActionEvent e) {
  175.     adaptee.ok_actionPerformed(e);
  176.   }
  177. }
  178.  
  179. class DualListBox_cancel_actionAdapter implements ActionListener {
  180.   DualListBox adaptee;
  181.  
  182.   DualListBox_cancel_actionAdapter(DualListBox adaptee) {
  183.     this.adaptee = adaptee;
  184.   }
  185.  
  186.   public void actionPerformed(ActionEvent e) {
  187.     adaptee.cancel_actionPerformed(e);
  188.   }
  189. }
  190.