home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 September / dppcpro0998.iso / Rwc / Sybase / Install.exe / samples.z / Form_Choice.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-25  |  6.7 KB  |  324 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Choice;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.Event;
  8. import java.awt.Font;
  9. import java.awt.FontMetrics;
  10. import java.awt.Insets;
  11. import java.awt.Label;
  12. import java.awt.Rectangle;
  13. import java.awt.TextField;
  14. import java.awt.Window;
  15. import java.awt.event.ActionEvent;
  16. import java.awt.event.ActionListener;
  17. import java.awt.event.ItemEvent;
  18. import java.awt.event.ItemListener;
  19. import java.util.EventObject;
  20. import powersoft.powerj.event.AWTEvent;
  21. import powersoft.powerj.ui.ResizePercentLayout;
  22.  
  23. class Form_Choice extends Applet implements ItemListener, ActionListener {
  24.    boolean __mainForm;
  25.    private Choice choice_1 = new Choice();
  26.    private TextField textf_text = new TextField();
  27.    private TextField textf_index = new TextField();
  28.    private TextField textf_count = new TextField();
  29.    private TextField textf_addNewItem = new TextField();
  30.    private Button cb_add = new Button();
  31.    private TextField textf_selectByText = new TextField();
  32.    private Button cb_selectByString = new Button();
  33.    private TextField textf_selectByIndex = new TextField();
  34.    private Button cb_selectByIndex = new Button();
  35.    private Label label_1 = new Label();
  36.    private Label label_2 = new Label();
  37.    private Label label_3 = new Label();
  38.  
  39.    public Rectangle DURectangle(int var1, int var2, int var3, int var4) {
  40.       String var5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  41.       FontMetrics var6 = ((Component)this).getFontMetrics(((Component)this).getFont());
  42.       double var7 = (double)(var6 != null ? var6.stringWidth(var5) / var5.length() : 0);
  43.       double var9 = var6 != null ? (double)var6.getHeight() / (double)2.0F : (double)0.0F;
  44.       return new Rectangle((int)Math.round(var7 * (double)var1 / (double)4.0F), (int)Math.round(var9 * (double)var2 / (double)4.0F), (int)Math.round(var7 * (double)var3 / (double)4.0F), (int)Math.round(var9 * (double)var4 / (double)4.0F));
  45.    }
  46.  
  47.    public void DUPositionComponent(Component var1, int var2, int var3, int var4, int var5, Insets var6) {
  48.       Rectangle var7 = this.DURectangle(var2, var3, var4, var5);
  49.       if (var1 != this && var6 != null) {
  50.          var7.x += var6.left;
  51.          var7.y += var6.top;
  52.       }
  53.  
  54.       var1.setBounds(var7);
  55.    }
  56.  
  57.    public void setMainForm(boolean var1) {
  58.       this.__mainForm = var1;
  59.    }
  60.  
  61.    public boolean isMainForm() {
  62.       return this.__mainForm;
  63.    }
  64.  
  65.    public boolean create() throws Exception {
  66.       Container var1 = this.getContentPane();
  67.       Font var2 = new Font("Dialog", 0, 12);
  68.       ((Component)this).setFont(var2);
  69.       boolean var3 = true;
  70.       Insets var4 = (Insets)var1.getInsets().clone();
  71.       ((Component)var1).setBackground(Color.lightGray);
  72.       ((Component)var1).setForeground(Color.black);
  73.       ResizePercentLayout var5 = new ResizePercentLayout();
  74.       var1.setLayout(var5);
  75.       var1.add(this.choice_1);
  76.       var1.add(this.textf_text);
  77.       var1.add(this.textf_index);
  78.       var1.add(this.textf_count);
  79.       var1.add(this.textf_addNewItem);
  80.       var1.add(this.cb_add);
  81.       var1.add(this.textf_selectByText);
  82.       var1.add(this.cb_selectByString);
  83.       var1.add(this.textf_selectByIndex);
  84.       var1.add(this.cb_selectByIndex);
  85.       var1.add(this.label_1);
  86.       var1.add(this.label_2);
  87.       var1.add(this.label_3);
  88.       this.DUPositionComponent(this, 0, 0, 231, 166, var4);
  89.       this.choice_1.addItemListener(this);
  90.       this.DUPositionComponent(this.choice_1, 72, 10, 65, 15, var4);
  91.       this.choice_1.setFont(var2);
  92.       this.choice_1.setBackground(Color.lightGray);
  93.       this.choice_1.setForeground(Color.black);
  94.       this.choice_1.setEnabled(true);
  95.       this.choice_1.setVisible(true);
  96.       this.choice_1.addItem("Item one");
  97.       this.choice_1.addItem("Item two");
  98.       this.choice_1.addItem("Item three");
  99.       this.choice_1.addItem("Item four");
  100.       this.choice_1.addItem("Item five");
  101.       this.textf_text.setEditable(false);
  102.       this.DUPositionComponent(this.textf_text, 72, 36, 65, 14, var4);
  103.       this.textf_text.setFont(var2);
  104.       this.textf_text.setBackground(Color.lightGray);
  105.       this.textf_text.setForeground(Color.black);
  106.       this.textf_text.setEnabled(true);
  107.       this.textf_text.setVisible(true);
  108.       this.textf_text.setText("Item one");
  109.       this.textf_index.setEditable(false);
  110.       this.DUPositionComponent(this.textf_index, 72, 55, 65, 14, var4);
  111.       this.textf_index.setFont(var2);
  112.       this.textf_index.setBackground(Color.lightGray);
  113.       this.textf_index.setForeground(Color.black);
  114.       this.textf_index.setEnabled(true);
  115.       this.textf_index.setVisible(true);
  116.       this.textf_index.setText("0");
  117.       this.textf_count.setEditable(false);
  118.       this.DUPositionComponent(this.textf_count, 72, 76, 65, 14, var4);
  119.       this.textf_count.setFont(var2);
  120.       this.textf_count.setBackground(Color.lightGray);
  121.       this.textf_count.setForeground(Color.black);
  122.       this.textf_count.setEnabled(true);
  123.       this.textf_count.setVisible(true);
  124.       this.textf_count.setText("5");
  125.       this.DUPositionComponent(this.textf_addNewItem, 72, 95, 65, 14, var4);
  126.       this.textf_addNewItem.setFont(var2);
  127.       this.textf_addNewItem.setBackground(Color.lightGray);
  128.       this.textf_addNewItem.setForeground(Color.black);
  129.       this.textf_addNewItem.setEnabled(true);
  130.       this.textf_addNewItem.setVisible(true);
  131.       this.textf_addNewItem.setText("Default item");
  132.       this.cb_add.addActionListener(this);
  133.       this.DUPositionComponent(this.cb_add, 147, 95, 76, 14, var4);
  134.       this.cb_add.setFont(var2);
  135.       this.cb_add.setBackground(Color.lightGray);
  136.       this.cb_add.setForeground(Color.black);
  137.       this.cb_add.setEnabled(true);
  138.       this.cb_add.setVisible(true);
  139.       this.cb_add.setLabel("Add New Item");
  140.       this.DUPositionComponent(this.textf_selectByText, 72, 116, 65, 14, var4);
  141.       this.textf_selectByText.setFont(var2);
  142.       this.textf_selectByText.setBackground(Color.lightGray);
  143.       this.textf_selectByText.setForeground(Color.black);
  144.       this.textf_selectByText.setEnabled(true);
  145.       this.textf_selectByText.setVisible(true);
  146.       this.cb_selectByString.addActionListener(this);
  147.       this.DUPositionComponent(this.cb_selectByString, 147, 116, 76, 14, var4);
  148.       this.cb_selectByString.setFont(var2);
  149.       this.cb_selectByString.setBackground(Color.lightGray);
  150.       this.cb_selectByString.setForeground(Color.black);
  151.       this.cb_selectByString.setEnabled(true);
  152.       this.cb_selectByString.setVisible(true);
  153.       this.cb_selectByString.setLabel("Select String");
  154.       this.DUPositionComponent(this.textf_selectByIndex, 72, 135, 65, 14, var4);
  155.       this.textf_selectByIndex.setFont(var2);
  156.       this.textf_selectByIndex.setBackground(Color.lightGray);
  157.       this.textf_selectByIndex.setForeground(Color.black);
  158.       this.textf_selectByIndex.setEnabled(true);
  159.       this.textf_selectByIndex.setVisible(true);
  160.       this.cb_selectByIndex.addActionListener(this);
  161.       this.DUPositionComponent(this.cb_selectByIndex, 147, 135, 76, 14, var4);
  162.       this.cb_selectByIndex.setFont(var2);
  163.       this.cb_selectByIndex.setBackground(Color.lightGray);
  164.       this.cb_selectByIndex.setForeground(Color.black);
  165.       this.cb_selectByIndex.setEnabled(true);
  166.       this.cb_selectByIndex.setVisible(true);
  167.       this.cb_selectByIndex.setLabel("Select By Index");
  168.       this.DUPositionComponent(this.label_1, 7, 76, 65, 12, var4);
  169.       this.label_1.setText("Number of Items:");
  170.       this.label_1.setAlignment(0);
  171.       this.label_1.setFont(var2);
  172.       this.label_1.setBackground(Color.lightGray);
  173.       this.label_1.setForeground(Color.black);
  174.       this.label_1.setEnabled(true);
  175.       this.label_1.setVisible(true);
  176.       this.DUPositionComponent(this.label_2, 42, 55, 30, 12, var4);
  177.       this.label_2.setText("Index:");
  178.       this.label_2.setAlignment(0);
  179.       this.label_2.setFont(var2);
  180.       this.label_2.setBackground(Color.lightGray);
  181.       this.label_2.setForeground(Color.black);
  182.       this.label_2.setEnabled(true);
  183.       this.label_2.setVisible(true);
  184.       this.DUPositionComponent(this.label_3, 45, 36, 26, 10, var4);
  185.       this.label_3.setText("Text:");
  186.       this.label_3.setAlignment(0);
  187.       this.label_3.setFont(var2);
  188.       this.label_3.setBackground(Color.lightGray);
  189.       this.label_3.setForeground(Color.black);
  190.       this.label_3.setEnabled(true);
  191.       this.label_3.setVisible(true);
  192.       var5.setResizePercent(this.choice_1, new Rectangle(0, 0, 0, 0));
  193.       var5.setResizePercent(this.textf_text, new Rectangle(0, 0, 0, 0));
  194.       var5.setResizePercent(this.textf_index, new Rectangle(0, 0, 0, 0));
  195.       var5.setResizePercent(this.textf_count, new Rectangle(0, 0, 0, 0));
  196.       var5.setResizePercent(this.textf_addNewItem, new Rectangle(0, 0, 0, 0));
  197.       var5.setResizePercent(this.cb_add, new Rectangle(0, 0, 0, 0));
  198.       var5.setResizePercent(this.textf_selectByText, new Rectangle(0, 0, 0, 0));
  199.       var5.setResizePercent(this.cb_selectByString, new Rectangle(0, 0, 0, 0));
  200.       var5.setResizePercent(this.textf_selectByIndex, new Rectangle(0, 0, 0, 0));
  201.       var5.setResizePercent(this.cb_selectByIndex, new Rectangle(0, 0, 0, 0));
  202.       var5.setResizePercent(this.label_1, new Rectangle(0, 0, 0, 0));
  203.       var5.setResizePercent(this.label_2, new Rectangle(0, 0, 0, 0));
  204.       var5.setResizePercent(this.label_3, new Rectangle(0, 0, 0, 0));
  205.       return var3;
  206.    }
  207.  
  208.    public synchronized void destroy() {
  209.       if (this instanceof Window) {
  210.          ((Window)this).dispose();
  211.       } else {
  212.          ((Container)this).removeNotify();
  213.       }
  214.  
  215.       if (this.isMainForm()) {
  216.          System.gc();
  217.          System.runFinalization();
  218.          System.exit(0);
  219.       }
  220.  
  221.    }
  222.  
  223.    public boolean defaultHandleEvent(Event var1) {
  224.       this.defaultProcessEvent(new AWTEvent(var1));
  225.       return false;
  226.    }
  227.  
  228.    public void defaultProcessEvent(java.awt.AWTEvent var1) {
  229.       super.processEvent(var1);
  230.    }
  231.  
  232.    public void itemStateChanged(ItemEvent var1) {
  233.       Object var2 = ((EventObject)var1).getSource();
  234.       if (var2 == this.choice_1) {
  235.          this.choice_1_itemStateChanged(var1);
  236.       } else {
  237.          this.unhandledEvent("java.awt.event.ItemListener", "itemStateChanged", var1);
  238.       }
  239.  
  240.    }
  241.  
  242.    public void actionPerformed(ActionEvent var1) {
  243.       Object var2 = ((EventObject)var1).getSource();
  244.       if (var2 == this.cb_add) {
  245.          this.cb_add_actionPerformed(var1);
  246.       } else if (var2 == this.cb_selectByString) {
  247.          this.cb_selectByString_actionPerformed(var1);
  248.       } else if (var2 == this.cb_selectByIndex) {
  249.          this.cb_selectByIndex_actionPerformed(var1);
  250.       } else {
  251.          this.unhandledEvent("java.awt.event.ActionListener", "actionPerformed", var1);
  252.       }
  253.  
  254.    }
  255.  
  256.    public boolean Form_Choice_WindowDestroy(Event var1) {
  257.       ((Component)this).hide();
  258.       this.destroy();
  259.       return false;
  260.    }
  261.  
  262.    public Form_Choice() {
  263.    }
  264.  
  265.    private void updateSelectionInfo() {
  266.       int var1 = this.choice_1.getSelectedIndex();
  267.       this.textf_index.setText(Integer.toString(var1));
  268.       this.textf_text.setText(this.choice_1.getSelectedItem());
  269.    }
  270.  
  271.    public boolean handleEvent(Event var1) {
  272.       return this.defaultHandleEvent(var1);
  273.    }
  274.  
  275.    public void unhandledEvent(String var1, String var2, Object var3) {
  276.    }
  277.  
  278.    public void processEvent(java.awt.AWTEvent var1) {
  279.       this.defaultProcessEvent(var1);
  280.    }
  281.  
  282.    public Container getContentPane() {
  283.       return this;
  284.    }
  285.  
  286.    public boolean choice_1_itemStateChanged(ItemEvent var1) {
  287.       this.updateSelectionInfo();
  288.       return false;
  289.    }
  290.  
  291.    public boolean cb_add_actionPerformed(ActionEvent var1) {
  292.       this.choice_1.addItem(this.textf_addNewItem.getText());
  293.       int var2 = this.choice_1.countItems();
  294.       this.textf_count.setText(Integer.toString(var2));
  295.       return false;
  296.    }
  297.  
  298.    public boolean cb_selectByString_actionPerformed(ActionEvent var1) {
  299.       this.choice_1.select(this.textf_selectByText.getText());
  300.       this.updateSelectionInfo();
  301.       return false;
  302.    }
  303.  
  304.    public boolean cb_selectByIndex_actionPerformed(ActionEvent var1) {
  305.       int var2 = 0;
  306.       int var3 = -1;
  307.       String var4 = this.textf_selectByIndex.getText();
  308.  
  309.       try {
  310.          var3 = Integer.parseInt(var4);
  311.       } catch (NumberFormatException var5) {
  312.          var3 = -1;
  313.       }
  314.  
  315.       var2 = this.choice_1.countItems();
  316.       if (var3 >= 0 && var3 < var2) {
  317.          this.choice_1.select(var3);
  318.       }
  319.  
  320.       this.updateSelectionInfo();
  321.       return false;
  322.    }
  323. }
  324.