ed68f8a4e6822bb703ea6a46d0fcc08c001d56ca
[jalviewjs.git] / site / swingjs / j2s / swingjs / test / converter / Converter.js
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;
5 this.usaPanel = null;
6 this.metricDistances = null;
7 this.usaDistances = null;
8 this.dataModel = null;
9 this.mainPane = 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 ();
16 });
17 Clazz.makeConstructor (c$, 
18 function () {
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));
31 if (false) {
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);
41 });
42 Clazz.defineMethod (c$, "resetMaxValues", 
43 function (resetCurrentValues) {
44 var metricMultiplier = this.metricPanel.getMultiplier ();
45 var usaMultiplier = this.usaPanel.getMultiplier ();
46 var maximum = 10000;
47 if (metricMultiplier > usaMultiplier) {
48 maximum = Clazz.doubleToInt (10000 * (usaMultiplier / metricMultiplier));
49 }this.dataModel.setMaximum (maximum);
50 if (resetCurrentValues) {
51 this.dataModel.setDoubleValue (maximum);
52 }}, "~B");
53 c$.initLookAndFeel = Clazz.defineMethod (c$, "initLookAndFeel", 
54  function () {
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";
65 } else {
66 System.err.println ("Unexpected value of LOOKANDFEEL specified: " + swingjs.test.converter.Converter.LOOKANDFEEL);
67 lookAndFeel = javax.swing.UIManager.getCrossPlatformLookAndFeelClassName ();
68 }try {
69 javax.swing.UIManager.setLookAndFeel (lookAndFeel);
70 } catch (e$$) {
71 if (Clazz.exceptionOf (e$$, ClassNotFoundException)) {
72 var e = e$$;
73 {
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.");
77 }
78 } else if (Clazz.exceptionOf (e$$, javax.swing.UnsupportedLookAndFeelException)) {
79 var e = e$$;
80 {
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.");
83 }
84 } else if (Clazz.exceptionOf (e$$, Exception)) {
85 var e = e$$;
86 {
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.");
89 e.printStackTrace ();
90 }
91 } else {
92 throw e$$;
93 }
94 }
95 }});
96 Clazz.overrideMethod (c$, "init", 
97 function () {
98 this.resize (300, 170);
99 this.createAndShowGUI ();
100 });
101 Clazz.defineMethod (c$, "createAndShowGUI", 
102  function () {
103 swingjs.test.converter.Converter.initLookAndFeel ();
104 var converter =  new swingjs.test.converter.Converter ();
105 converter.mainPane.setOpaque (true);
106 this.add (converter.mainPane);
107 });
108 Clazz.defineStatics (c$,
109 "MULTICOLORED", false,
110 "LOOKANDFEEL", null);
111 });