home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Choice;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.FlowLayout;
- import java.awt.Font;
- import java.awt.Frame;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import java.awt.Label;
- import java.awt.LayoutManager;
- import java.awt.Panel;
- import java.awt.TextComponent;
- import java.awt.TextField;
- import java.awt.Window;
- import java.awt.event.InputEvent;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowListener;
- import java.text.ChoiceFormat;
- import java.text.DateFormat;
- import java.text.Format;
- import java.text.MessageFormat;
- import java.text.NumberFormat;
- import java.util.Date;
- import java.util.EventObject;
- import java.util.Locale;
- import java.util.ResourceBundle;
-
- class MessageFormatFrame extends Frame implements WindowListener, ItemListener, KeyListener {
- Label label1;
- Label label2;
- TextField patternText;
- Label label3;
- Label label4;
- Label label5;
- Label labelArg;
- Label labelForm;
- TextField arg1Text;
- TextField arg2Text;
- TextField arg3Text;
- Choice arg1Type;
- Choice arg2Type;
- Choice arg3Type;
- Label label6;
- Choice localeMenu;
- Label localeLabel;
- Label label13;
- Label label14;
- TextField resultText;
- Label label7;
- Label label8;
- Label label9;
- TextField choice1Num;
- TextField choice2Num;
- TextField choice3Num;
- TextField choice4Num;
- TextField choice1Text;
- TextField choice2Text;
- TextField choice3Text;
- TextField choice4Text;
- Label label10;
- Label label11;
- Label label12;
- TextField arg4Text;
- Choice arg4Type;
- private static final String creditString = "v1.1a7, Demos";
- private static final String copyrightString = "";
- private static final String copyrightString2 = "";
- private static final int FIELD_COLUMNS = 60;
- private static final int NUMBER = 0;
- private static final int DATE = 1;
- private static final int CHOICE = 2;
- private static final int NONE = 3;
- private static final boolean DEBUG = false;
- private Locale[] locales;
- private DemoApplet applet;
- private ChoiceFormat choiceFormat;
-
- public MessageFormatFrame(DemoApplet var1) {
- super("Message Formatting Demo");
- this.applet = var1;
- ((Window)this).addWindowListener(this);
- this.init();
- this.start();
- }
-
- public void init() {
- this.locales = Utility.getG7Locales();
- this.buildGUI();
- }
-
- public void start() {
- this.arg1Text.setText("3");
- this.arg1Type.select(2);
- this.arg2Text.setText("MyDisk");
- this.arg2Type.select(3);
- this.arg3Text.setText("3 Mar 96");
- this.arg3Type.select(1);
- this.arg4Text.setText("");
- this.arg4Type.select(0);
- this.patternText.setText("The disk '%1' contained %0 on %2.");
- this.choice1Num.setText("0");
- this.choice2Num.setText("1");
- this.choice3Num.setText("2");
- this.resetFormat();
- this.doFormatting();
- }
-
- public void resetFormat() {
- Locale var1 = this.locales[this.localeMenu.getSelectedIndex()];
- this.getClass().getClassLoader();
- this.choice4Num.setText("");
- this.choice4Text.setText("");
- ResourceBundle var2 = ResourceBundle.getBundle("ChoiceResource", var1);
- this.patternText.setText(var2.getString("patternText"));
- this.choice1Text.setText(var2.getString("choice1"));
- this.choice2Text.setText(var2.getString("choice2"));
- this.choice3Text.setText(var2.getString("choice3"));
- }
-
- public Format createFormat(Choice var1) {
- int var2 = var1.getSelectedIndex();
- Locale var3 = this.locales[this.localeMenu.getSelectedIndex()];
- Object var4 = null;
- if (var2 == 0) {
- var4 = NumberFormat.getInstance(var3);
- } else if (var2 == 1) {
- var4 = DateFormat.getDateInstance(2, var3);
- } else if (var2 == 2) {
- var4 = this.choiceFormat;
- }
-
- return (Format)var4;
- }
-
- public void doFormatting() {
- double[] var1 = new double[]{this.doubleValue(this.choice1Num.getText()), this.doubleValue(this.choice2Num.getText()), this.doubleValue(this.choice3Num.getText()), this.doubleValue(this.choice4Num.getText())};
- String[] var2 = new String[]{this.choice1Text.getText(), this.choice2Text.getText(), this.choice3Text.getText(), this.choice4Text.getText()};
- this.choiceFormat = new ChoiceFormat(var1, var2);
- Format[] var3 = new Format[]{this.createFormat(this.arg1Type), this.createFormat(this.arg2Type), this.createFormat(this.arg3Type), this.createFormat(this.arg4Type)};
- MessageFormat var4 = new MessageFormat(this.patternText.getText());
- Object[] var5 = new Object[]{this.createObject(this.arg1Type, this.arg1Text), this.createObject(this.arg2Type, this.arg2Text), this.createObject(this.arg3Type, this.arg3Text), this.createObject(this.arg4Type, this.arg4Text)};
- Object var6 = null;
-
- try {
- var9 = ((Format)var4).format(var5);
- } catch (Exception var8) {
- this.errorText("format threw an exception: " + ((Throwable)var8).toString());
- var9 = "ERROR";
- }
-
- this.resultText.setText(var9);
- }
-
- public void itemStateChanged(ItemEvent var1) {
- if (((EventObject)var1).getSource() != this.arg1Type && ((EventObject)var1).getSource() != this.arg2Type && ((EventObject)var1).getSource() != this.arg3Type && ((EventObject)var1).getSource() != this.arg4Type) {
- if (((EventObject)var1).getSource() == this.localeMenu) {
- this.resetFormat();
- this.doFormatting();
- }
-
- } else {
- this.doFormatting();
- }
- }
-
- public void keyPressed(KeyEvent var1) {
- }
-
- public void keyReleased(KeyEvent var1) {
- if (((EventObject)var1).getSource() != this.choice1Text && ((EventObject)var1).getSource() != this.choice2Text && ((EventObject)var1).getSource() != this.choice3Text && ((EventObject)var1).getSource() != this.choice4Text) {
- if (((EventObject)var1).getSource() != this.choice1Num && ((EventObject)var1).getSource() != this.choice2Num && ((EventObject)var1).getSource() != this.choice3Num && ((EventObject)var1).getSource() != this.choice4Num) {
- if (((EventObject)var1).getSource() != this.arg1Text && ((EventObject)var1).getSource() != this.arg2Text && ((EventObject)var1).getSource() != this.arg3Text && ((EventObject)var1).getSource() != this.arg4Text) {
- if (((EventObject)var1).getSource() == this.patternText) {
- ((InputEvent)var1).consume();
- this.doFormatting();
- }
-
- } else {
- ((InputEvent)var1).consume();
- this.doFormatting();
- }
- } else {
- ((InputEvent)var1).consume();
- this.doFormatting();
- }
- } else {
- ((InputEvent)var1).consume();
- this.doFormatting();
- }
- }
-
- public void keyTyped(KeyEvent var1) {
- }
-
- public void windowClosed(WindowEvent var1) {
- }
-
- public void windowDeiconified(WindowEvent var1) {
- }
-
- public void windowIconified(WindowEvent var1) {
- }
-
- public void windowActivated(WindowEvent var1) {
- }
-
- public void windowDeactivated(WindowEvent var1) {
- }
-
- public void windowOpened(WindowEvent var1) {
- }
-
- public void windowClosing(WindowEvent var1) {
- ((Component)this).setVisible(false);
- ((Frame)this).dispose();
- if (this.applet != null) {
- this.applet.demoClosed();
- } else {
- System.exit(0);
- }
- }
-
- double doubleValue(String var1) {
- try {
- return Double.valueOf(var1);
- } catch (Exception var2) {
- return Double.POSITIVE_INFINITY;
- }
- }
-
- void constrainedAdd(GridBagConstraints var1, Container var2, Component var3, Font var4) {
- GridBagLayout var5 = (GridBagLayout)var2.getLayout();
- if (var4 != null) {
- var3.setFont(var4);
- }
-
- var5.setConstraints(var3, var1);
- var2.add(var3);
- }
-
- Choice cloneChoice(Choice var1) {
- Choice var2 = new Choice();
-
- for(int var3 = 0; var3 < var1.getItemCount(); ++var3) {
- var2.addItem(var1.getItem(var3));
- }
-
- ((Component)var2).setFont(((Component)var1).getFont());
- return var2;
- }
-
- void addWithFont(Container var1, Component var2, Font var3) {
- if (var3 != null) {
- var2.setFont(var3);
- }
-
- var1.add(var2);
- }
-
- private void buildGUI() {
- ((Container)this).setLayout(new FlowLayout(1, 2, 2));
- ((Component)this).setBackground(Color.white);
- Panel var1 = new Panel();
- this.label6 = new Label("Message Format Demo", 1);
- this.label6.setFont(Utility.titleFont);
- ((Container)var1).add(this.label6);
- Panel var2 = new Panel();
- this.label13 = new Label("v1.1a7, Demos");
- this.label13.setFont(Utility.creditFont);
- ((Container)var2).add(this.label13);
- ((Container)var1).add(var2);
- Utility.fixGrid(var1, 1);
- Panel var3 = new Panel();
- this.addWithFont(var3, new Label("Result", 2), Utility.labelFont);
- this.addWithFont(var3, this.resultText = new TextField(60), Utility.editFont);
- this.addWithFont(var3, new Label("Pattern", 2), Utility.labelFont);
- this.addWithFont(var3, this.patternText = new TextField(60), Utility.editFont);
- this.patternText.addKeyListener(this);
- Utility.fixGrid(var3, 2);
- Panel var4 = new Panel();
- this.localeLabel = new Label("Locale:", 0);
- this.localeLabel.setFont(Utility.labelFont);
- this.localeMenu = new Choice();
- this.localeMenu.addItemListener(this);
- Locale.getDefault();
-
- for(int var5 = 0; var5 < this.locales.length; ++var5) {
- if (this.locales[var5].getCountry().length() > 0) {
- this.localeMenu.addItem(this.locales[var5].getDisplayName());
- if (this.locales[var5].equals(Locale.getDefault())) {
- this.localeMenu.select(var5);
- }
- }
- }
-
- this.localeMenu.setFont(Utility.choiceFont);
- Panel var6 = new Panel();
- ((Container)var6).add(this.localeLabel);
- ((Container)var6).add(this.localeMenu);
- ((Container)var4).add(var6);
- this.arg1Type = new Choice();
- this.arg1Type.setFont(Utility.choiceFont);
- this.arg1Type.addItem("Number");
- this.arg1Type.addItem("Date");
- this.arg1Type.addItem("Choice");
- this.arg1Type.addItem("None");
- this.arg1Type.addItemListener(this);
- Panel var7 = new Panel();
- this.addWithFont(var7, new Label(" "), Utility.labelFont);
- this.addWithFont(var7, new Label("Arguments", 0), Utility.labelFont);
- this.addWithFont(var7, new Label("0", 2), Utility.labelFont);
- this.addWithFont(var7, this.arg1Text = new TextField(12), Utility.editFont);
- this.addWithFont(var7, new Label("1", 2), Utility.labelFont);
- this.addWithFont(var7, this.arg2Text = new TextField(12), Utility.editFont);
- this.addWithFont(var7, new Label("2", 2), Utility.labelFont);
- this.addWithFont(var7, this.arg3Text = new TextField(12), Utility.editFont);
- this.addWithFont(var7, new Label("3", 2), Utility.labelFont);
- this.addWithFont(var7, this.arg4Text = new TextField(12), Utility.editFont);
- this.arg1Text.addKeyListener(this);
- this.arg2Text.addKeyListener(this);
- this.arg3Text.addKeyListener(this);
- this.arg4Text.addKeyListener(this);
- Utility.fixGrid(var7, 2);
- Panel var8 = new Panel();
- this.addWithFont(var8, new Label(" "), Utility.labelFont);
- this.addWithFont(var8, new Label("Formats", 0), Utility.labelFont);
- this.addWithFont(var8, new Label("0", 2), Utility.labelFont);
- this.addWithFont(var8, this.arg1Type, Utility.choiceFont);
- this.addWithFont(var8, new Label("1", 2), Utility.labelFont);
- this.addWithFont(var8, this.arg2Type = this.cloneChoice(this.arg1Type), Utility.choiceFont);
- this.addWithFont(var8, new Label("2", 2), Utility.labelFont);
- this.addWithFont(var8, this.arg3Type = this.cloneChoice(this.arg1Type), Utility.choiceFont);
- this.addWithFont(var8, new Label("3", 2), Utility.labelFont);
- this.addWithFont(var8, this.arg4Type = this.cloneChoice(this.arg1Type), Utility.choiceFont);
- this.arg2Type.addItemListener(this);
- this.arg3Type.addItemListener(this);
- this.arg4Type.addItemListener(this);
- Utility.fixGrid(var8, 2);
- Panel var9 = new Panel();
- this.addWithFont(var9, new Label(">=", 0), Utility.labelFont);
- this.addWithFont(var9, new Label("Choice Strings", 0), Utility.labelFont);
- this.addWithFont(var9, this.choice1Num = new TextField(4), Utility.editFont);
- this.addWithFont(var9, this.choice1Text = new TextField(16), Utility.editFont);
- this.addWithFont(var9, this.choice2Num = new TextField(4), Utility.editFont);
- this.addWithFont(var9, this.choice2Text = new TextField(16), Utility.editFont);
- this.addWithFont(var9, this.choice3Num = new TextField(4), Utility.editFont);
- this.addWithFont(var9, this.choice3Text = new TextField(16), Utility.editFont);
- this.addWithFont(var9, this.choice4Num = new TextField(4), Utility.editFont);
- this.addWithFont(var9, this.choice4Text = new TextField(16), Utility.editFont);
- this.choice1Text.addKeyListener(this);
- this.choice2Text.addKeyListener(this);
- this.choice3Text.addKeyListener(this);
- this.choice4Text.addKeyListener(this);
- this.choice1Num.addKeyListener(this);
- this.choice2Num.addKeyListener(this);
- this.choice3Num.addKeyListener(this);
- this.choice4Num.addKeyListener(this);
- Utility.fixGrid(var9, 2);
- ((Container)this).add(var1);
- ((Container)this).add(var3);
- ((Container)this).add(var4);
- Panel var10 = new Panel();
- ((Container)var10).add(var7);
- XBorderPanel var11 = new XBorderPanel();
- ((Component)var11).setBackground(Color.lightGray);
- ((Container)var11).setLayout((LayoutManager)null);
- ((Component)var11).setSize(8, 130);
- ((Container)var10).add(var11);
- ((Container)var10).add(var8);
- XBorderPanel var12 = new XBorderPanel();
- ((Component)var12).setBackground(Color.lightGray);
- ((Container)var12).setLayout((LayoutManager)null);
- ((Component)var12).setSize(8, 130);
- ((Container)var10).add(var12);
- ((Container)var10).add(var9);
- Utility.fixGrid(var10, 5);
- Utility.setInsets(var10, var11, new Insets(20, 20, 2, 2));
- Utility.setInsets(var10, var12, new Insets(20, 20, 2, 20));
- ((Container)this).add(var10);
- Panel var13 = new Panel();
- this.addWithFont(var13, new Label("", 0), Utility.creditFont);
- this.addWithFont(var13, new Label("", 0), Utility.creditFont);
- Utility.fixGrid(var13, 1);
- ((Container)this).add(var13);
- }
-
- private Object createObject(Choice var1, TextField var2) {
- int var3 = var1.getSelectedIndex();
- String var4 = ((TextComponent)var2).getText();
- Object var5 = null;
-
- try {
- if (var3 != 0 && var3 != 2) {
- if (var3 == 1) {
- var5 = new Long((new Date(var4)).getTime() + 1L);
- } else if (var3 == 3) {
- var5 = var4;
- }
- } else {
- var5 = new Double(var4);
- }
- } catch (RuntimeException var6) {
- }
-
- return var5;
- }
-
- private void errorText(String var1) {
- }
- }
-