home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Button;
- import java.awt.Choice;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Insets;
- import java.awt.Label;
- import java.awt.Rectangle;
- import java.awt.TextField;
- import java.awt.Window;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.util.EventObject;
- import powersoft.powerj.event.AWTEvent;
- import powersoft.powerj.ui.ResizePercentLayout;
-
- class Form_Choice extends Applet implements ItemListener, ActionListener {
- boolean __mainForm;
- private Choice choice_1 = new Choice();
- private TextField textf_text = new TextField();
- private TextField textf_index = new TextField();
- private TextField textf_count = new TextField();
- private TextField textf_addNewItem = new TextField();
- private Button cb_add = new Button();
- private TextField textf_selectByText = new TextField();
- private Button cb_selectByString = new Button();
- private TextField textf_selectByIndex = new TextField();
- private Button cb_selectByIndex = new Button();
- private Label label_1 = new Label();
- private Label label_2 = new Label();
- private Label label_3 = new Label();
-
- public Rectangle DURectangle(int var1, int var2, int var3, int var4) {
- String var5 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- FontMetrics var6 = ((Component)this).getFontMetrics(((Component)this).getFont());
- double var7 = (double)(var6 != null ? var6.stringWidth(var5) / var5.length() : 0);
- double var9 = var6 != null ? (double)var6.getHeight() / (double)2.0F : (double)0.0F;
- 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));
- }
-
- public void DUPositionComponent(Component var1, int var2, int var3, int var4, int var5, Insets var6) {
- Rectangle var7 = this.DURectangle(var2, var3, var4, var5);
- if (var1 != this && var6 != null) {
- var7.x += var6.left;
- var7.y += var6.top;
- }
-
- var1.setBounds(var7);
- }
-
- public void setMainForm(boolean var1) {
- this.__mainForm = var1;
- }
-
- public boolean isMainForm() {
- return this.__mainForm;
- }
-
- public boolean create() throws Exception {
- Container var1 = this.getContentPane();
- Font var2 = new Font("Dialog", 0, 12);
- ((Component)this).setFont(var2);
- boolean var3 = true;
- Insets var4 = (Insets)var1.getInsets().clone();
- ((Component)var1).setBackground(Color.lightGray);
- ((Component)var1).setForeground(Color.black);
- ResizePercentLayout var5 = new ResizePercentLayout();
- var1.setLayout(var5);
- var1.add(this.choice_1);
- var1.add(this.textf_text);
- var1.add(this.textf_index);
- var1.add(this.textf_count);
- var1.add(this.textf_addNewItem);
- var1.add(this.cb_add);
- var1.add(this.textf_selectByText);
- var1.add(this.cb_selectByString);
- var1.add(this.textf_selectByIndex);
- var1.add(this.cb_selectByIndex);
- var1.add(this.label_1);
- var1.add(this.label_2);
- var1.add(this.label_3);
- this.DUPositionComponent(this, 0, 0, 231, 166, var4);
- this.choice_1.addItemListener(this);
- this.DUPositionComponent(this.choice_1, 72, 10, 65, 15, var4);
- this.choice_1.setFont(var2);
- this.choice_1.setBackground(Color.lightGray);
- this.choice_1.setForeground(Color.black);
- this.choice_1.setEnabled(true);
- this.choice_1.setVisible(true);
- this.choice_1.addItem("Item one");
- this.choice_1.addItem("Item two");
- this.choice_1.addItem("Item three");
- this.choice_1.addItem("Item four");
- this.choice_1.addItem("Item five");
- this.textf_text.setEditable(false);
- this.DUPositionComponent(this.textf_text, 72, 36, 65, 14, var4);
- this.textf_text.setFont(var2);
- this.textf_text.setBackground(Color.lightGray);
- this.textf_text.setForeground(Color.black);
- this.textf_text.setEnabled(true);
- this.textf_text.setVisible(true);
- this.textf_text.setText("Item one");
- this.textf_index.setEditable(false);
- this.DUPositionComponent(this.textf_index, 72, 55, 65, 14, var4);
- this.textf_index.setFont(var2);
- this.textf_index.setBackground(Color.lightGray);
- this.textf_index.setForeground(Color.black);
- this.textf_index.setEnabled(true);
- this.textf_index.setVisible(true);
- this.textf_index.setText("0");
- this.textf_count.setEditable(false);
- this.DUPositionComponent(this.textf_count, 72, 76, 65, 14, var4);
- this.textf_count.setFont(var2);
- this.textf_count.setBackground(Color.lightGray);
- this.textf_count.setForeground(Color.black);
- this.textf_count.setEnabled(true);
- this.textf_count.setVisible(true);
- this.textf_count.setText("5");
- this.DUPositionComponent(this.textf_addNewItem, 72, 95, 65, 14, var4);
- this.textf_addNewItem.setFont(var2);
- this.textf_addNewItem.setBackground(Color.lightGray);
- this.textf_addNewItem.setForeground(Color.black);
- this.textf_addNewItem.setEnabled(true);
- this.textf_addNewItem.setVisible(true);
- this.textf_addNewItem.setText("Default item");
- this.cb_add.addActionListener(this);
- this.DUPositionComponent(this.cb_add, 147, 95, 76, 14, var4);
- this.cb_add.setFont(var2);
- this.cb_add.setBackground(Color.lightGray);
- this.cb_add.setForeground(Color.black);
- this.cb_add.setEnabled(true);
- this.cb_add.setVisible(true);
- this.cb_add.setLabel("Add New Item");
- this.DUPositionComponent(this.textf_selectByText, 72, 116, 65, 14, var4);
- this.textf_selectByText.setFont(var2);
- this.textf_selectByText.setBackground(Color.lightGray);
- this.textf_selectByText.setForeground(Color.black);
- this.textf_selectByText.setEnabled(true);
- this.textf_selectByText.setVisible(true);
- this.cb_selectByString.addActionListener(this);
- this.DUPositionComponent(this.cb_selectByString, 147, 116, 76, 14, var4);
- this.cb_selectByString.setFont(var2);
- this.cb_selectByString.setBackground(Color.lightGray);
- this.cb_selectByString.setForeground(Color.black);
- this.cb_selectByString.setEnabled(true);
- this.cb_selectByString.setVisible(true);
- this.cb_selectByString.setLabel("Select String");
- this.DUPositionComponent(this.textf_selectByIndex, 72, 135, 65, 14, var4);
- this.textf_selectByIndex.setFont(var2);
- this.textf_selectByIndex.setBackground(Color.lightGray);
- this.textf_selectByIndex.setForeground(Color.black);
- this.textf_selectByIndex.setEnabled(true);
- this.textf_selectByIndex.setVisible(true);
- this.cb_selectByIndex.addActionListener(this);
- this.DUPositionComponent(this.cb_selectByIndex, 147, 135, 76, 14, var4);
- this.cb_selectByIndex.setFont(var2);
- this.cb_selectByIndex.setBackground(Color.lightGray);
- this.cb_selectByIndex.setForeground(Color.black);
- this.cb_selectByIndex.setEnabled(true);
- this.cb_selectByIndex.setVisible(true);
- this.cb_selectByIndex.setLabel("Select By Index");
- this.DUPositionComponent(this.label_1, 7, 76, 65, 12, var4);
- this.label_1.setText("Number of Items:");
- this.label_1.setAlignment(0);
- this.label_1.setFont(var2);
- this.label_1.setBackground(Color.lightGray);
- this.label_1.setForeground(Color.black);
- this.label_1.setEnabled(true);
- this.label_1.setVisible(true);
- this.DUPositionComponent(this.label_2, 42, 55, 30, 12, var4);
- this.label_2.setText("Index:");
- this.label_2.setAlignment(0);
- this.label_2.setFont(var2);
- this.label_2.setBackground(Color.lightGray);
- this.label_2.setForeground(Color.black);
- this.label_2.setEnabled(true);
- this.label_2.setVisible(true);
- this.DUPositionComponent(this.label_3, 45, 36, 26, 10, var4);
- this.label_3.setText("Text:");
- this.label_3.setAlignment(0);
- this.label_3.setFont(var2);
- this.label_3.setBackground(Color.lightGray);
- this.label_3.setForeground(Color.black);
- this.label_3.setEnabled(true);
- this.label_3.setVisible(true);
- var5.setResizePercent(this.choice_1, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.textf_text, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.textf_index, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.textf_count, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.textf_addNewItem, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.cb_add, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.textf_selectByText, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.cb_selectByString, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.textf_selectByIndex, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.cb_selectByIndex, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.label_1, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.label_2, new Rectangle(0, 0, 0, 0));
- var5.setResizePercent(this.label_3, new Rectangle(0, 0, 0, 0));
- return var3;
- }
-
- public synchronized void destroy() {
- if (this instanceof Window) {
- ((Window)this).dispose();
- } else {
- ((Container)this).removeNotify();
- }
-
- if (this.isMainForm()) {
- System.gc();
- System.runFinalization();
- System.exit(0);
- }
-
- }
-
- public boolean defaultHandleEvent(Event var1) {
- this.defaultProcessEvent(new AWTEvent(var1));
- return false;
- }
-
- public void defaultProcessEvent(java.awt.AWTEvent var1) {
- super.processEvent(var1);
- }
-
- public void itemStateChanged(ItemEvent var1) {
- Object var2 = ((EventObject)var1).getSource();
- if (var2 == this.choice_1) {
- this.choice_1_itemStateChanged(var1);
- } else {
- this.unhandledEvent("java.awt.event.ItemListener", "itemStateChanged", var1);
- }
-
- }
-
- public void actionPerformed(ActionEvent var1) {
- Object var2 = ((EventObject)var1).getSource();
- if (var2 == this.cb_add) {
- this.cb_add_actionPerformed(var1);
- } else if (var2 == this.cb_selectByString) {
- this.cb_selectByString_actionPerformed(var1);
- } else if (var2 == this.cb_selectByIndex) {
- this.cb_selectByIndex_actionPerformed(var1);
- } else {
- this.unhandledEvent("java.awt.event.ActionListener", "actionPerformed", var1);
- }
-
- }
-
- public boolean Form_Choice_WindowDestroy(Event var1) {
- ((Component)this).hide();
- this.destroy();
- return false;
- }
-
- public Form_Choice() {
- }
-
- private void updateSelectionInfo() {
- int var1 = this.choice_1.getSelectedIndex();
- this.textf_index.setText(Integer.toString(var1));
- this.textf_text.setText(this.choice_1.getSelectedItem());
- }
-
- public boolean handleEvent(Event var1) {
- return this.defaultHandleEvent(var1);
- }
-
- public void unhandledEvent(String var1, String var2, Object var3) {
- }
-
- public void processEvent(java.awt.AWTEvent var1) {
- this.defaultProcessEvent(var1);
- }
-
- public Container getContentPane() {
- return this;
- }
-
- public boolean choice_1_itemStateChanged(ItemEvent var1) {
- this.updateSelectionInfo();
- return false;
- }
-
- public boolean cb_add_actionPerformed(ActionEvent var1) {
- this.choice_1.addItem(this.textf_addNewItem.getText());
- int var2 = this.choice_1.countItems();
- this.textf_count.setText(Integer.toString(var2));
- return false;
- }
-
- public boolean cb_selectByString_actionPerformed(ActionEvent var1) {
- this.choice_1.select(this.textf_selectByText.getText());
- this.updateSelectionInfo();
- return false;
- }
-
- public boolean cb_selectByIndex_actionPerformed(ActionEvent var1) {
- int var2 = 0;
- int var3 = -1;
- String var4 = this.textf_selectByIndex.getText();
-
- try {
- var3 = Integer.parseInt(var4);
- } catch (NumberFormatException var5) {
- var3 = -1;
- }
-
- var2 = this.choice_1.countItems();
- if (var3 >= 0 && var3 < var2) {
- this.choice_1.select(var3);
- }
-
- this.updateSelectionInfo();
- return false;
- }
- }
-