1 Clazz.declarePackage ("swingjs.test.converter");
2 Clazz.load (["javax.swing.JApplet", "swingjs.test.converter.ConverterRangeModel"], "swingjs.test.converter.Converter", ["java.awt.Color", "$.Dimension", "javax.swing.BorderFactory", "$.Box", "$.BoxLayout", "$.JPanel", "$.UIManager", "swingjs.test.converter.ConversionPanel", "$.FollowerRangeModel", "$.Unit"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.metricPanel = null;
6 this.metricDistances = null;
7 this.usaDistances = null;
10 Clazz.instantialize (this, arguments);
11 }, swingjs.test.converter, "Converter", javax.swing.JApplet);
12 Clazz.prepareFields (c$, function () {
13 this.metricDistances = new Array (3);
14 this.usaDistances = new Array (4);
15 this.dataModel = new swingjs.test.converter.ConverterRangeModel ();
17 Clazz.makeConstructor (c$,
19 Clazz.superConstructor (this, swingjs.test.converter.Converter, []);
20 this.metricDistances[0] = new swingjs.test.converter.Unit ("Centimeters", 0.01);
21 this.metricDistances[1] = new swingjs.test.converter.Unit ("Meters", 1.0);
22 this.metricDistances[2] = new swingjs.test.converter.Unit ("Kilometers", 1000.0);
23 this.metricPanel = new swingjs.test.converter.ConversionPanel (this, "Metric System", this.metricDistances, this.dataModel);
24 this.usaDistances[0] = new swingjs.test.converter.Unit ("Inches", 0.0254);
25 this.usaDistances[1] = new swingjs.test.converter.Unit ("Feet", 0.305);
26 this.usaDistances[2] = new swingjs.test.converter.Unit ("Yards", 0.914);
27 this.usaDistances[3] = new swingjs.test.converter.Unit ("Miles", 1613.0);
28 this.usaPanel = new swingjs.test.converter.ConversionPanel (this, "U.S. System", this.usaDistances, new swingjs.test.converter.FollowerRangeModel (this.dataModel));
29 this.mainPane = new javax.swing.JPanel ();
30 this.mainPane.setLayout ( new javax.swing.BoxLayout (this.mainPane, 3));
32 this.mainPane.setOpaque (true);
33 this.mainPane.setBackground ( new java.awt.Color (255, 0, 0));
34 }this.mainPane.setBorder (javax.swing.BorderFactory.createEmptyBorder (5, 5, 5, 5));
35 this.mainPane.add (javax.swing.Box.createRigidArea ( new java.awt.Dimension (0, 5)));
36 this.mainPane.add (this.metricPanel);
37 this.mainPane.add (javax.swing.Box.createRigidArea ( new java.awt.Dimension (0, 5)));
38 this.mainPane.add (this.usaPanel);
39 this.mainPane.add (javax.swing.Box.createGlue ());
40 this.resetMaxValues (true);
42 Clazz.defineMethod (c$, "resetMaxValues",
43 function (resetCurrentValues) {
44 var metricMultiplier = this.metricPanel.getMultiplier ();
45 var usaMultiplier = this.usaPanel.getMultiplier ();
47 if (metricMultiplier > usaMultiplier) {
48 maximum = Clazz.doubleToInt (10000 * (usaMultiplier / metricMultiplier));
49 }this.dataModel.setMaximum (maximum);
50 if (resetCurrentValues) {
51 this.dataModel.setDoubleValue (maximum);
53 c$.initLookAndFeel = Clazz.defineMethod (c$, "initLookAndFeel",
55 var lookAndFeel = null;
56 if (swingjs.test.converter.Converter.LOOKANDFEEL != null) {
57 if (swingjs.test.converter.Converter.LOOKANDFEEL.equals ("Metal")) {
58 lookAndFeel = javax.swing.UIManager.getCrossPlatformLookAndFeelClassName ();
59 } else if (swingjs.test.converter.Converter.LOOKANDFEEL.equals ("System")) {
60 lookAndFeel = javax.swing.UIManager.getSystemLookAndFeelClassName ();
61 } else if (swingjs.test.converter.Converter.LOOKANDFEEL.equals ("Motif")) {
62 lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
63 } else if (swingjs.test.converter.Converter.LOOKANDFEEL.equals ("GTK+")) {
64 lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
66 System.err.println ("Unexpected value of LOOKANDFEEL specified: " + swingjs.test.converter.Converter.LOOKANDFEEL);
67 lookAndFeel = javax.swing.UIManager.getCrossPlatformLookAndFeelClassName ();
69 javax.swing.UIManager.setLookAndFeel (lookAndFeel);
71 if (Clazz.exceptionOf (e$$, ClassNotFoundException)) {
74 System.err.println ("Couldn't find class for specified look and feel:" + lookAndFeel);
75 System.err.println ("Did you include the L&F library in the class path?");
76 System.err.println ("Using the default look and feel.");
78 } else if (Clazz.exceptionOf (e$$, javax.swing.UnsupportedLookAndFeelException)) {
81 System.err.println ("Can't use the specified look and feel (" + lookAndFeel + ") on this platform.");
82 System.err.println ("Using the default look and feel.");
84 } else if (Clazz.exceptionOf (e$$, Exception)) {
87 System.err.println ("Couldn't get specified look and feel (" + lookAndFeel + "), for some reason.");
88 System.err.println ("Using the default look and feel.");
96 Clazz.overrideMethod (c$, "init",
98 this.resize (300, 170);
99 this.createAndShowGUI ();
101 Clazz.defineMethod (c$, "createAndShowGUI",
103 swingjs.test.converter.Converter.initLookAndFeel ();
104 var converter = new swingjs.test.converter.Converter ();
105 converter.mainPane.setOpaque (true);
106 this.add (converter.mainPane);
108 Clazz.defineStatics (c$,
109 "MULTICOLORED", false,
110 "LOOKANDFEEL", null);