Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / swingjs / test / FormattedTextFieldDemo.js
index 567921f..4521e7e 100644 (file)
-Clazz.declarePackage ("swingjs.test");\r
-Clazz.load (["java.awt.event.ActionListener", "$.FocusListener", "java.beans.PropertyChangeListener", "javax.swing.JApplet", "$.JFormattedTextField"], "swingjs.test.FormattedTextFieldDemo", ["java.awt.BorderLayout", "$.Color", "$.GridLayout", "java.lang.Boolean", "$.Double", "java.text.NumberFormat", "javax.swing.JFrame", "$.JLabel", "$.JPanel", "$.SwingUtilities", "$.UIManager"], function () {\r
-c$ = Clazz.decorateAsClass (function () {\r
-this.amount = 100000;\r
-this.rate = 7.5;\r
-this.numPeriods = 30;\r
-this.amountLabel = null;\r
-this.rateLabel = null;\r
-this.numPeriodsLabel = null;\r
-this.paymentLabel = null;\r
-this.amountField = null;\r
-this.rateField = null;\r
-this.numPeriodsField = null;\r
-this.paymentField = null;\r
-this.amountFormat = null;\r
-this.percentFormat = null;\r
-this.paymentFormat = null;\r
-if (!Clazz.isClassDefined ("swingjs.test.FormattedTextFieldDemo.SwingJSValidatedNumberField")) {\r
-swingjs.test.FormattedTextFieldDemo.$FormattedTextFieldDemo$SwingJSValidatedNumberField$ ();\r
-}\r
-Clazz.instantialize (this, arguments);\r
-}, swingjs.test, "FormattedTextFieldDemo", javax.swing.JApplet, [java.awt.event.ActionListener, java.beans.PropertyChangeListener, java.awt.event.FocusListener]);\r
-Clazz.overrideMethod (c$, "init", \r
-function () {\r
-this.setLayout ( new java.awt.BorderLayout ());\r
-this.setUpFormats ();\r
-var payment = this.computePayment (this.amount, this.rate, this.numPeriods);\r
-this.amountLabel =  new javax.swing.JLabel (swingjs.test.FormattedTextFieldDemo.amountString);\r
-this.rateLabel =  new javax.swing.JLabel (swingjs.test.FormattedTextFieldDemo.rateString);\r
-this.numPeriodsLabel =  new javax.swing.JLabel (swingjs.test.FormattedTextFieldDemo.numPeriodsString);\r
-this.paymentLabel =  new javax.swing.JLabel (swingjs.test.FormattedTextFieldDemo.paymentString);\r
-this.amountField = Clazz.innerTypeInstance (swingjs.test.FormattedTextFieldDemo.SwingJSValidatedNumberField, this, null, this.amountFormat);\r
-this.amountField.setValue ( new Double (this.amount));\r
-this.amountField.setColumns (10);\r
-this.amountField.addPropertyChangeListener ("value", this);\r
-this.amountField.addActionListener (this);\r
-this.rateField = Clazz.innerTypeInstance (swingjs.test.FormattedTextFieldDemo.SwingJSValidatedNumberField, this, null, this.percentFormat);\r
-this.rateField.setValue ( new Double (this.rate));\r
-this.rateField.setColumns (10);\r
-this.rateField.addPropertyChangeListener ("value", this);\r
-this.rateField.addActionListener (this);\r
-this.rateField.addActionListener (this);\r
-this.numPeriodsField = Clazz.innerTypeInstance (swingjs.test.FormattedTextFieldDemo.SwingJSValidatedNumberField, this, null);\r
-this.numPeriodsField.setValue ( new Integer (this.numPeriods));\r
-this.numPeriodsField.setColumns (10);\r
-this.numPeriodsField.addPropertyChangeListener ("value", this);\r
-this.numPeriodsField.addActionListener (this);\r
-this.paymentField =  new javax.swing.JFormattedTextField (this.paymentFormat);\r
-this.paymentField.setValue ( new Double (payment));\r
-this.paymentField.setColumns (10);\r
-this.paymentField.setEditable (false);\r
-this.paymentField.setForeground (java.awt.Color.red);\r
-this.amountLabel.setLabelFor (this.amountField);\r
-this.rateLabel.setLabelFor (this.rateField);\r
-this.numPeriodsLabel.setLabelFor (this.numPeriodsField);\r
-this.paymentLabel.setLabelFor (this.paymentField);\r
-var labelPane =  new javax.swing.JPanel ( new java.awt.GridLayout (0, 1));\r
-labelPane.add (this.amountLabel);\r
-labelPane.add (this.rateLabel);\r
-labelPane.add (this.numPeriodsLabel);\r
-labelPane.add (this.paymentLabel);\r
-var fieldPane =  new javax.swing.JPanel ( new java.awt.GridLayout (0, 1));\r
-fieldPane.add (this.amountField);\r
-fieldPane.add (this.rateField);\r
-fieldPane.add (this.numPeriodsField);\r
-fieldPane.add (this.paymentField);\r
-this.add (labelPane, "Center");\r
-this.add (fieldPane, "After");\r
-this.resize (270, 100);\r
-});\r
-Clazz.overrideMethod (c$, "propertyChange", \r
-function (e) {\r
-var source = e.getSource ();\r
-System.out.println ("propertyChange " + e);\r
-if (source === this.amountField) {\r
-this.amount = (this.amountField.getValue ()).doubleValue ();\r
-} else if (source === this.rateField) {\r
-this.rate = (this.rateField.getValue ()).doubleValue ();\r
-} else if (source === this.numPeriodsField) {\r
-this.numPeriods = (this.numPeriodsField.getValue ()).intValue ();\r
-}var payment = this.computePayment (this.amount, this.rate, this.numPeriods);\r
-this.paymentField.setValue ( new Double (payment));\r
-}, "java.beans.PropertyChangeEvent");\r
-c$.createAndShowGUI = Clazz.defineMethod (c$, "createAndShowGUI", \r
- function () {\r
-var frame =  new javax.swing.JFrame ("FormattedTextFieldDemo");\r
-frame.setDefaultCloseOperation (3);\r
-frame.add ( new swingjs.test.FormattedTextFieldDemo ());\r
-frame.pack ();\r
-frame.setVisible (true);\r
-});\r
-c$.main = Clazz.defineMethod (c$, "main", \r
-function (args) {\r
-javax.swing.SwingUtilities.invokeLater (((Clazz.isClassDefined ("swingjs.test.FormattedTextFieldDemo$1") ? 0 : swingjs.test.FormattedTextFieldDemo.$FormattedTextFieldDemo$1$ ()), Clazz.innerTypeInstance (swingjs.test.FormattedTextFieldDemo$1, this, null)));\r
-}, "~A");\r
-Clazz.defineMethod (c$, "computePayment", \r
-function (loanAmt, rate, numPeriods) {\r
-var I;\r
-var partial1;\r
-var denominator;\r
-var answer;\r
-numPeriods *= 12;\r
-if (rate > 0.01) {\r
-I = rate / 100.0 / 12.0;\r
-partial1 = Math.pow ((1 + I), (0.0 - numPeriods));\r
-denominator = (1 - partial1) / I;\r
-} else {\r
-denominator = numPeriods;\r
-}answer = (-1 * loanAmt) / denominator;\r
-return answer;\r
-}, "~N,~N,~N");\r
-Clazz.defineMethod (c$, "setUpFormats", \r
- function () {\r
-this.amountFormat = java.text.NumberFormat.getNumberInstance ();\r
-this.percentFormat = java.text.NumberFormat.getNumberInstance ();\r
-this.percentFormat.setMinimumFractionDigits (3);\r
-this.paymentFormat = java.text.NumberFormat.getCurrencyInstance ();\r
-});\r
-Clazz.overrideMethod (c$, "focusGained", \r
-function (e) {\r
-System.out.println ("focusGained " + (e.getSource ()).getText () + " " + (e.getSource ()).getValue ());\r
-}, "java.awt.event.FocusEvent");\r
-Clazz.overrideMethod (c$, "focusLost", \r
-function (e) {\r
-System.out.println ("focusLost " + (e.getSource ()).getText () + " " + (e.getSource ()).getValue ());\r
-}, "java.awt.event.FocusEvent");\r
-Clazz.overrideMethod (c$, "actionPerformed", \r
-function (e) {\r
-System.out.println ("actionEvent " + e);\r
-(e.getSource ()).validateNumber ();\r
-}, "java.awt.event.ActionEvent");\r
-c$.$FormattedTextFieldDemo$SwingJSValidatedNumberField$ = function () {\r
-Clazz.pu$h(self.c$);\r
-c$ = Clazz.decorateAsClass (function () {\r
-Clazz.prepareCallback (this, arguments);\r
-Clazz.instantialize (this, arguments);\r
-}, swingjs.test.FormattedTextFieldDemo, "SwingJSValidatedNumberField", javax.swing.JFormattedTextField);\r
-Clazz.overrideMethod (c$, "invalidEdit", \r
-function () {\r
-this.validateNumber ();\r
-});\r
-Clazz.defineMethod (c$, "validateNumber", \r
-function () {\r
-try {\r
-this.setText (this.getFormatter ().valueToString (this.getValue ()));\r
-} catch (e1) {\r
-if (Clazz.exceptionOf (e1, java.text.ParseException)) {\r
-} else {\r
-throw e1;\r
-}\r
-}\r
-});\r
-c$ = Clazz.p0p ();\r
-};\r
-c$.$FormattedTextFieldDemo$1$ = function () {\r
-Clazz.pu$h(self.c$);\r
-c$ = Clazz.declareAnonymous (swingjs.test, "FormattedTextFieldDemo$1", null, Runnable);\r
-Clazz.overrideMethod (c$, "run", \r
-function () {\r
-javax.swing.UIManager.put ("swing.boldMetal", Boolean.FALSE);\r
-swingjs.test.FormattedTextFieldDemo.createAndShowGUI ();\r
-});\r
-c$ = Clazz.p0p ();\r
-};\r
-Clazz.defineStatics (c$,\r
-"amountString", "Loan Amount: ",\r
-"rateString", "APR (%): ",\r
-"numPeriodsString", "Years: ",\r
-"paymentString", "Monthly Payment: ");\r
-});\r
+Clazz.declarePackage ("swingjs.test");
+Clazz.load (["java.awt.event.ActionListener", "$.FocusListener", "java.beans.PropertyChangeListener", "javax.swing.JApplet", "$.JFormattedTextField"], "swingjs.test.FormattedTextFieldDemo", ["java.awt.BorderLayout", "$.Color", "$.GridLayout", "java.lang.Boolean", "$.Double", "java.text.NumberFormat", "javax.swing.JFrame", "$.JLabel", "$.JPanel", "$.SwingUtilities", "$.UIManager"], function () {
+c$ = Clazz.decorateAsClass (function () {
+this.amount = 100000;
+this.rate = 7.5;
+this.numPeriods = 30;
+this.amountLabel = null;
+this.rateLabel = null;
+this.numPeriodsLabel = null;
+this.paymentLabel = null;
+this.amountField = null;
+this.rateField = null;
+this.numPeriodsField = null;
+this.paymentField = null;
+this.amountFormat = null;
+this.percentFormat = null;
+this.paymentFormat = null;
+if (!Clazz.isClassDefined ("swingjs.test.FormattedTextFieldDemo.SwingJSValidatedNumberField")) {
+swingjs.test.FormattedTextFieldDemo.$FormattedTextFieldDemo$SwingJSValidatedNumberField$ ();
+}
+Clazz.instantialize (this, arguments);
+}, swingjs.test, "FormattedTextFieldDemo", javax.swing.JApplet, [java.awt.event.ActionListener, java.beans.PropertyChangeListener, java.awt.event.FocusListener]);
+Clazz.overrideMethod (c$, "init", 
+function () {
+this.setLayout ( new java.awt.BorderLayout ());
+this.setUpFormats ();
+var payment = this.computePayment (this.amount, this.rate, this.numPeriods);
+this.amountLabel =  new javax.swing.JLabel (swingjs.test.FormattedTextFieldDemo.amountString);
+this.rateLabel =  new javax.swing.JLabel (swingjs.test.FormattedTextFieldDemo.rateString);
+this.numPeriodsLabel =  new javax.swing.JLabel (swingjs.test.FormattedTextFieldDemo.numPeriodsString);
+this.paymentLabel =  new javax.swing.JLabel (swingjs.test.FormattedTextFieldDemo.paymentString);
+this.amountField = Clazz.innerTypeInstance (swingjs.test.FormattedTextFieldDemo.SwingJSValidatedNumberField, this, null, this.amountFormat);
+this.amountField.setValue ( new Double (this.amount));
+this.amountField.setColumns (10);
+this.amountField.addPropertyChangeListener ("value", this);
+this.amountField.addActionListener (this);
+this.rateField = Clazz.innerTypeInstance (swingjs.test.FormattedTextFieldDemo.SwingJSValidatedNumberField, this, null, this.percentFormat);
+this.rateField.setValue ( new Double (this.rate));
+this.rateField.setColumns (10);
+this.rateField.addPropertyChangeListener ("value", this);
+this.rateField.addActionListener (this);
+this.rateField.addActionListener (this);
+this.numPeriodsField = Clazz.innerTypeInstance (swingjs.test.FormattedTextFieldDemo.SwingJSValidatedNumberField, this, null);
+this.numPeriodsField.setValue ( new Integer (this.numPeriods));
+this.numPeriodsField.setColumns (10);
+this.numPeriodsField.addPropertyChangeListener ("value", this);
+this.numPeriodsField.addActionListener (this);
+this.paymentField =  new javax.swing.JFormattedTextField (this.paymentFormat);
+this.paymentField.setValue ( new Double (payment));
+this.paymentField.setColumns (10);
+this.paymentField.setEditable (false);
+this.paymentField.setForeground (java.awt.Color.red);
+this.amountLabel.setLabelFor (this.amountField);
+this.rateLabel.setLabelFor (this.rateField);
+this.numPeriodsLabel.setLabelFor (this.numPeriodsField);
+this.paymentLabel.setLabelFor (this.paymentField);
+var labelPane =  new javax.swing.JPanel ( new java.awt.GridLayout (0, 1));
+labelPane.add (this.amountLabel);
+labelPane.add (this.rateLabel);
+labelPane.add (this.numPeriodsLabel);
+labelPane.add (this.paymentLabel);
+var fieldPane =  new javax.swing.JPanel ( new java.awt.GridLayout (0, 1));
+fieldPane.add (this.amountField);
+fieldPane.add (this.rateField);
+fieldPane.add (this.numPeriodsField);
+fieldPane.add (this.paymentField);
+this.add (labelPane, "Center");
+this.add (fieldPane, "After");
+this.resize (270, 100);
+});
+Clazz.overrideMethod (c$, "propertyChange", 
+function (e) {
+var source = e.getSource ();
+System.out.println ("propertyChange " + e);
+if (source === this.amountField) {
+this.amount = (this.amountField.getValue ()).doubleValue ();
+} else if (source === this.rateField) {
+this.rate = (this.rateField.getValue ()).doubleValue ();
+} else if (source === this.numPeriodsField) {
+this.numPeriods = (this.numPeriodsField.getValue ()).intValue ();
+}var payment = this.computePayment (this.amount, this.rate, this.numPeriods);
+this.paymentField.setValue ( new Double (payment));
+}, "java.beans.PropertyChangeEvent");
+c$.createAndShowGUI = Clazz.defineMethod (c$, "createAndShowGUI", 
+ function () {
+var frame =  new javax.swing.JFrame ("FormattedTextFieldDemo");
+frame.setDefaultCloseOperation (3);
+frame.add ( new swingjs.test.FormattedTextFieldDemo ());
+frame.pack ();
+frame.setVisible (true);
+});
+c$.main = Clazz.defineMethod (c$, "main", 
+function (args) {
+javax.swing.SwingUtilities.invokeLater (((Clazz.isClassDefined ("swingjs.test.FormattedTextFieldDemo$1") ? 0 : swingjs.test.FormattedTextFieldDemo.$FormattedTextFieldDemo$1$ ()), Clazz.innerTypeInstance (swingjs.test.FormattedTextFieldDemo$1, this, null)));
+}, "~A");
+Clazz.defineMethod (c$, "computePayment", 
+function (loanAmt, rate, numPeriods) {
+var I;
+var partial1;
+var denominator;
+var answer;
+numPeriods *= 12;
+if (rate > 0.01) {
+I = rate / 100.0 / 12.0;
+partial1 = Math.pow ((1 + I), (0.0 - numPeriods));
+denominator = (1 - partial1) / I;
+} else {
+denominator = numPeriods;
+}answer = (-1 * loanAmt) / denominator;
+return answer;
+}, "~N,~N,~N");
+Clazz.defineMethod (c$, "setUpFormats", 
+ function () {
+this.amountFormat = java.text.NumberFormat.getNumberInstance ();
+this.percentFormat = java.text.NumberFormat.getNumberInstance ();
+this.percentFormat.setMinimumFractionDigits (3);
+this.paymentFormat = java.text.NumberFormat.getCurrencyInstance ();
+});
+Clazz.overrideMethod (c$, "focusGained", 
+function (e) {
+System.out.println ("focusGained " + (e.getSource ()).getText () + " " + (e.getSource ()).getValue ());
+}, "java.awt.event.FocusEvent");
+Clazz.overrideMethod (c$, "focusLost", 
+function (e) {
+System.out.println ("focusLost " + (e.getSource ()).getText () + " " + (e.getSource ()).getValue ());
+}, "java.awt.event.FocusEvent");
+Clazz.overrideMethod (c$, "actionPerformed", 
+function (e) {
+System.out.println ("actionEvent " + e);
+(e.getSource ()).validateNumber ();
+}, "java.awt.event.ActionEvent");
+c$.$FormattedTextFieldDemo$SwingJSValidatedNumberField$ = function () {
+Clazz.pu$h(self.c$);
+c$ = Clazz.decorateAsClass (function () {
+Clazz.prepareCallback (this, arguments);
+Clazz.instantialize (this, arguments);
+}, swingjs.test.FormattedTextFieldDemo, "SwingJSValidatedNumberField", javax.swing.JFormattedTextField);
+Clazz.overrideMethod (c$, "invalidEdit", 
+function () {
+this.validateNumber ();
+});
+Clazz.defineMethod (c$, "validateNumber", 
+function () {
+try {
+this.setText (this.getFormatter ().valueToString (this.getValue ()));
+} catch (e1) {
+if (Clazz.exceptionOf (e1, java.text.ParseException)) {
+} else {
+throw e1;
+}
+}
+});
+c$ = Clazz.p0p ();
+};
+c$.$FormattedTextFieldDemo$1$ = function () {
+Clazz.pu$h(self.c$);
+c$ = Clazz.declareAnonymous (swingjs.test, "FormattedTextFieldDemo$1", null, Runnable);
+Clazz.overrideMethod (c$, "run", 
+function () {
+javax.swing.UIManager.put ("swing.boldMetal", Boolean.FALSE);
+swingjs.test.FormattedTextFieldDemo.createAndShowGUI ();
+});
+c$ = Clazz.p0p ();
+};
+Clazz.defineStatics (c$,
+"amountString", "Loan Amount: ",
+"rateString", "APR (%): ",
+"numPeriodsString", "Years: ",
+"paymentString", "Monthly Payment: ");
+});