1 Clazz.declarePackage ("swingjs.test");
2 Clazz.load (["javax.swing.JApplet", "$.JPanel"], ["swingjs.test.SeeThroughImageApplet", "$.SeeThroughComponent"], ["java.awt.Color", "$.Dimension", "$.Font", "java.awt.event.WindowAdapter", "java.awt.image.BufferedImage", "$.RescaleOp", "java.io.File", "java.net.URL", "javax.imageio.ImageIO", "javax.swing.JFrame", "$.JSlider", "javax.swing.event.ChangeListener"], function () {
3 c$ = Clazz.decorateAsClass (function () {
8 Clazz.instantialize (this, arguments);
9 }, swingjs.test, "SeeThroughComponent", javax.swing.JPanel);
10 Clazz.prepareFields (c$, function () {
11 this.scales = Clazz.newFloatArray (-1, [1, 1, 1, 0.5]);
12 this.offsets = Clazz.newFloatArray (4, 0);
14 Clazz.makeConstructor (c$,
16 Clazz.superConstructor (this, swingjs.test.SeeThroughComponent, []);
18 var img = javax.imageio.ImageIO.read (imageSrc);
19 var w = img.getWidth (null);
20 var h = img.getHeight (null);
21 this.bi = new java.awt.image.BufferedImage (w, h, 2);
22 var g = this.bi.getGraphics ();
23 g.drawImage (img, 0, 0, null);
25 if (Clazz.exceptionOf (e, java.io.IOException)) {
26 System.out.println ("Image could not be read");
31 this.setOpacity (0.5);
33 Clazz.overrideMethod (c$, "getPreferredSize",
35 return new java.awt.Dimension (this.bi.getWidth (null), this.bi.getHeight (null));
37 Clazz.defineMethod (c$, "setOpacity",
39 this.scales[3] = opacity;
40 this.rop = new java.awt.image.RescaleOp (this.scales, this.offsets, null);
42 Clazz.overrideMethod (c$, "paint",
45 g2d.setColor (java.awt.Color.white);
46 g2d.fillRect (0, 0, this.getWidth (), this.getHeight ());
47 g2d.setColor (java.awt.Color.black);
48 g2d.setFont ( new java.awt.Font ("Dialog", 1, 24));
49 g2d.drawString ("JavaScript is cool!", 5, 80);
50 g2d.drawImage (this.bi, this.rop, 0, 0);
51 }, "java.awt.Graphics");
52 c$ = Clazz.decorateAsClass (function () {
54 Clazz.instantialize (this, arguments);
55 }, swingjs.test, "SeeThroughImageApplet", javax.swing.JApplet);
56 Clazz.makeConstructor (c$,
58 Clazz.superConstructor (this, swingjs.test.SeeThroughImageApplet, []);
60 Clazz.makeConstructor (c$,
62 Clazz.superConstructor (this, swingjs.test.SeeThroughImageApplet, []);
63 this.imageSrc = imageSrc;
65 Clazz.overrideMethod (c$, "init",
68 this.imageSrc = this.pathTo (swingjs.test.SeeThroughImageApplet.imageFileName);
70 if (Clazz.exceptionOf (e, java.net.MalformedURLException)) {
77 Clazz.defineMethod (c$, "buildUI",
79 var st = new swingjs.test.SeeThroughComponent (this.imageSrc);
80 this.add ("Center", st);
82 var opacitySlider = new javax.swing.JSlider (0, 100);
83 opacitySlider.addChangeListener (((Clazz.isClassDefined ("swingjs.test.SeeThroughImageApplet$1") ? 0 : swingjs.test.SeeThroughImageApplet.$SeeThroughImageApplet$1$ ()), Clazz.innerTypeInstance (swingjs.test.SeeThroughImageApplet$1, this, Clazz.cloneFinals ("st", st))));
84 var size = st.getPreferredSize ();
85 var sliderSize = opacitySlider.getPreferredSize ();
86 this.resize (size.width, size.height + sliderSize.height);
87 this.add ("South", opacitySlider);
89 if (Clazz.exceptionOf (e, Exception)) {
95 c$.main = Clazz.defineMethod (c$, "main",
97 var f = new javax.swing.JFrame ("See Through Image");
98 f.addWindowListener (((Clazz.isClassDefined ("swingjs.test.SeeThroughImageApplet$2") ? 0 : swingjs.test.SeeThroughImageApplet.$SeeThroughImageApplet$2$ ()), Clazz.innerTypeInstance (swingjs.test.SeeThroughImageApplet$2, this, null)));
101 imageSrc = (( new java.io.File (swingjs.test.SeeThroughImageApplet.imageFileName)).toURI ()).toURL ();
103 if (Clazz.exceptionOf (e, java.net.MalformedURLException)) {
108 var sta = new swingjs.test.SeeThroughImageApplet (imageSrc);
110 f.add ("Center", sta);
114 Clazz.defineMethod (c$, "pathTo",
116 var path = this.getDocumentBase ().toString ();
117 var pt = path.indexOf ("/bin/");
118 if (pt > 0) path = path.substring (0, pt) + "/html/" + path.substring (pt + 5);
119 path = path.substring (0, path.lastIndexOf ("/") + 1) + file;
120 if (path.startsWith ("/")) path = "file://" + path;
121 return new java.net.URL (path);
123 c$.$SeeThroughImageApplet$1$ = function () {
125 c$ = Clazz.declareAnonymous (swingjs.test, "SeeThroughImageApplet$1", null, javax.swing.event.ChangeListener);
126 Clazz.overrideMethod (c$, "stateChanged",
128 var slider = e.getSource ();
129 this.f$.st.setOpacity (slider.getValue () / 100);
130 this.f$.st.repaint ();
131 }, "javax.swing.event.ChangeEvent");
134 c$.$SeeThroughImageApplet$2$ = function () {
136 c$ = Clazz.declareAnonymous (swingjs.test, "SeeThroughImageApplet$2", java.awt.event.WindowAdapter);
137 Clazz.overrideMethod (c$, "windowClosing",
140 }, "java.awt.event.WindowEvent");
143 Clazz.defineStatics (c$,
144 "imageFileName", "examples/duke_skateboard.jpg");