X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fswingjs%2Fj2s%2Fswingjs%2Ftest%2FJumbledImageApplet.js;fp=site%2Fswingjs%2Fj2s%2Fswingjs%2Ftest%2FJumbledImageApplet.js;h=69b33dc4233b518f272d01cbe53168d058a28c55;hp=a9201bc7d221a78b45e8adfbacddb374840335a2;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=7301a2415adab88038b291fc54caeeb3a5a47a44 diff --git a/site/swingjs/j2s/swingjs/test/JumbledImageApplet.js b/site/swingjs/j2s/swingjs/test/JumbledImageApplet.js index a9201bc..69b33dc 100644 --- a/site/swingjs/j2s/swingjs/test/JumbledImageApplet.js +++ b/site/swingjs/j2s/swingjs/test/JumbledImageApplet.js @@ -1,154 +1,154 @@ -Clazz.declarePackage ("swingjs.test"); -Clazz.load (["javax.swing.JApplet", "$.JPanel"], ["swingjs.test.JumbledImageApplet", "$.JumbledImage"], ["java.awt.Dimension", "java.awt.event.ActionListener", "$.WindowAdapter", "java.io.File", "java.net.URL", "java.util.Random", "javax.imageio.ImageIO", "javax.swing.JButton", "$.JFrame"], function () { -c$ = Clazz.decorateAsClass (function () { -this.numlocs = 2; -this.numcells = 0; -this.cells = null; -this.bi = null; -this.w = 0; -this.h = 0; -this.cw = 0; -this.ch = 0; -Clazz.instantialize (this, arguments); -}, swingjs.test, "JumbledImage", javax.swing.JPanel); -Clazz.prepareFields (c$, function () { -this.numcells = this.numlocs * this.numlocs; -}); -Clazz.makeConstructor (c$, -function (imageSrc) { -Clazz.superConstructor (this, swingjs.test.JumbledImage, []); -try { -this.bi = javax.imageio.ImageIO.read (imageSrc); -this.w = this.bi.getWidth (null); -this.h = this.bi.getHeight (null); -} catch (e) { -if (Clazz.exceptionOf (e, java.io.IOException)) { -System.out.println ("Image could not be read"); -} else { -throw e; -} -} -this.cw = Clazz.doubleToInt (this.w / this.numlocs); -this.ch = Clazz.doubleToInt (this.h / this.numlocs); -this.cells = Clazz.newIntArray (this.numcells, 0); -for (var i = 0; i < this.numcells; i++) { -this.cells[i] = i; -} -}, "java.net.URL"); -Clazz.defineMethod (c$, "jumble", -function () { -var rand = new java.util.Random (); -var ri; -for (var i = 0; i < this.numcells; i++) { -while ((ri = rand.nextInt (this.numlocs)) == i) ; -var tmp = this.cells[i]; -this.cells[i] = this.cells[ri]; -this.cells[ri] = tmp; -} -}); -Clazz.overrideMethod (c$, "getPreferredSize", -function () { -return new java.awt.Dimension (this.w, this.h); -}); -Clazz.overrideMethod (c$, "paint", -function (g) { -var dx; -var dy; -for (var x = 0; x < this.numlocs; x++) { -var sx = x * this.cw; -for (var y = 0; y < this.numlocs; y++) { -var sy = y * this.ch; -var cell = this.cells[x * this.numlocs + y]; -dx = (Clazz.doubleToInt (cell / this.numlocs)) * this.cw; -dy = (cell % this.numlocs) * this.ch; -g.drawImage (this.bi, dx, dy, dx + this.cw, dy + this.ch, sx, sy, sx + this.cw, sy + this.ch, null); -} -} -}, "java.awt.Graphics"); -c$ = Clazz.decorateAsClass (function () { -this.imageSrc = null; -this.jumbledImage = null; -Clazz.instantialize (this, arguments); -}, swingjs.test, "JumbledImageApplet", javax.swing.JApplet); -Clazz.makeConstructor (c$, -function () { -Clazz.superConstructor (this, swingjs.test.JumbledImageApplet, []); -}); -Clazz.makeConstructor (c$, -function (imageSrc) { -Clazz.superConstructor (this, swingjs.test.JumbledImageApplet, []); -this.imageSrc = imageSrc; -}, "java.net.URL"); -Clazz.overrideMethod (c$, "init", -function () { -try { -this.imageSrc = this.pathTo (swingjs.test.JumbledImageApplet.imageFileName); -} catch (e) { -if (Clazz.exceptionOf (e, java.net.MalformedURLException)) { -} else { -throw e; -} -} -this.buildUI (); -}); -Clazz.defineMethod (c$, "buildUI", -function () { -var ji = new swingjs.test.JumbledImage (this.imageSrc); -this.add ("Center", ji); -var jumbleButton = new javax.swing.JButton ("Jumble"); -jumbleButton.addActionListener (((Clazz.isClassDefined ("swingjs.test.JumbledImageApplet$1") ? 0 : swingjs.test.JumbledImageApplet.$JumbledImageApplet$1$ ()), Clazz.innerTypeInstance (swingjs.test.JumbledImageApplet$1, this, Clazz.cloneFinals ("ji", ji)))); -var jumbleSize = ji.getPreferredSize (); -this.resize (jumbleSize.width, jumbleSize.height + 40); -this.add ("South", jumbleButton); -}); -c$.main = Clazz.defineMethod (c$, "main", -function (s) { -var f = new javax.swing.JFrame ("Jumbled Image"); -f.addWindowListener (((Clazz.isClassDefined ("swingjs.test.JumbledImageApplet$2") ? 0 : swingjs.test.JumbledImageApplet.$JumbledImageApplet$2$ ()), Clazz.innerTypeInstance (swingjs.test.JumbledImageApplet$2, this, null))); -var imageSrc = null; -try { -imageSrc = (( new java.io.File (swingjs.test.JumbledImageApplet.imageFileName)).toURI ()).toURL (); -} catch (e) { -if (Clazz.exceptionOf (e, java.net.MalformedURLException)) { -} else { -throw e; -} -} -var jumbler = new swingjs.test.JumbledImageApplet (imageSrc); -jumbler.buildUI (); -f.add ("Center", jumbler); -f.pack (); -f.setVisible (true); -}, "~A"); -Clazz.defineMethod (c$, "pathTo", - function (file) { -var path = this.getDocumentBase ().toString (); -var pt = path.indexOf ("/bin/"); -if (pt > 0) path = path.substring (0, pt) + "/html/" + path.substring (pt + 5); -path = path.substring (0, path.lastIndexOf ("/") + 1) + file; -if (path.startsWith ("/")) path = "file://" + path; -return new java.net.URL (path); -}, "~S"); -c$.$JumbledImageApplet$1$ = function () { -Clazz.pu$h(self.c$); -c$ = Clazz.declareAnonymous (swingjs.test, "JumbledImageApplet$1", null, java.awt.event.ActionListener); -Clazz.overrideMethod (c$, "actionPerformed", -function (e) { -var b = e.getSource (); -this.f$.ji.jumble (); -this.f$.ji.repaint (); -}, "java.awt.event.ActionEvent"); -c$ = Clazz.p0p (); -}; -c$.$JumbledImageApplet$2$ = function () { -Clazz.pu$h(self.c$); -c$ = Clazz.declareAnonymous (swingjs.test, "JumbledImageApplet$2", java.awt.event.WindowAdapter); -Clazz.overrideMethod (c$, "windowClosing", -function (e) { -System.exit (0); -}, "java.awt.event.WindowEvent"); -c$ = Clazz.p0p (); -}; -Clazz.defineStatics (c$, -"imageFileName", "examples/duke_skateboard.jpg"); -}); +Clazz.declarePackage ("swingjs.test"); +Clazz.load (["javax.swing.JApplet", "$.JPanel"], ["swingjs.test.JumbledImageApplet", "$.JumbledImage"], ["java.awt.Dimension", "java.awt.event.ActionListener", "$.WindowAdapter", "java.io.File", "java.net.URL", "java.util.Random", "javax.imageio.ImageIO", "javax.swing.JButton", "$.JFrame"], function () { +c$ = Clazz.decorateAsClass (function () { +this.numlocs = 2; +this.numcells = 0; +this.cells = null; +this.bi = null; +this.w = 0; +this.h = 0; +this.cw = 0; +this.ch = 0; +Clazz.instantialize (this, arguments); +}, swingjs.test, "JumbledImage", javax.swing.JPanel); +Clazz.prepareFields (c$, function () { +this.numcells = this.numlocs * this.numlocs; +}); +Clazz.makeConstructor (c$, +function (imageSrc) { +Clazz.superConstructor (this, swingjs.test.JumbledImage, []); +try { +this.bi = javax.imageio.ImageIO.read (imageSrc); +this.w = this.bi.getWidth (null); +this.h = this.bi.getHeight (null); +} catch (e) { +if (Clazz.exceptionOf (e, java.io.IOException)) { +System.out.println ("Image could not be read"); +} else { +throw e; +} +} +this.cw = Clazz.doubleToInt (this.w / this.numlocs); +this.ch = Clazz.doubleToInt (this.h / this.numlocs); +this.cells = Clazz.newIntArray (this.numcells, 0); +for (var i = 0; i < this.numcells; i++) { +this.cells[i] = i; +} +}, "java.net.URL"); +Clazz.defineMethod (c$, "jumble", +function () { +var rand = new java.util.Random (); +var ri; +for (var i = 0; i < this.numcells; i++) { +while ((ri = rand.nextInt (this.numlocs)) == i) ; +var tmp = this.cells[i]; +this.cells[i] = this.cells[ri]; +this.cells[ri] = tmp; +} +}); +Clazz.overrideMethod (c$, "getPreferredSize", +function () { +return new java.awt.Dimension (this.w, this.h); +}); +Clazz.overrideMethod (c$, "paint", +function (g) { +var dx; +var dy; +for (var x = 0; x < this.numlocs; x++) { +var sx = x * this.cw; +for (var y = 0; y < this.numlocs; y++) { +var sy = y * this.ch; +var cell = this.cells[x * this.numlocs + y]; +dx = (Clazz.doubleToInt (cell / this.numlocs)) * this.cw; +dy = (cell % this.numlocs) * this.ch; +g.drawImage (this.bi, dx, dy, dx + this.cw, dy + this.ch, sx, sy, sx + this.cw, sy + this.ch, null); +} +} +}, "java.awt.Graphics"); +c$ = Clazz.decorateAsClass (function () { +this.imageSrc = null; +this.jumbledImage = null; +Clazz.instantialize (this, arguments); +}, swingjs.test, "JumbledImageApplet", javax.swing.JApplet); +Clazz.makeConstructor (c$, +function () { +Clazz.superConstructor (this, swingjs.test.JumbledImageApplet, []); +}); +Clazz.makeConstructor (c$, +function (imageSrc) { +Clazz.superConstructor (this, swingjs.test.JumbledImageApplet, []); +this.imageSrc = imageSrc; +}, "java.net.URL"); +Clazz.overrideMethod (c$, "init", +function () { +try { +this.imageSrc = this.pathTo (swingjs.test.JumbledImageApplet.imageFileName); +} catch (e) { +if (Clazz.exceptionOf (e, java.net.MalformedURLException)) { +} else { +throw e; +} +} +this.buildUI (); +}); +Clazz.defineMethod (c$, "buildUI", +function () { +var ji = new swingjs.test.JumbledImage (this.imageSrc); +this.add ("Center", ji); +var jumbleButton = new javax.swing.JButton ("Jumble"); +jumbleButton.addActionListener (((Clazz.isClassDefined ("swingjs.test.JumbledImageApplet$1") ? 0 : swingjs.test.JumbledImageApplet.$JumbledImageApplet$1$ ()), Clazz.innerTypeInstance (swingjs.test.JumbledImageApplet$1, this, Clazz.cloneFinals ("ji", ji)))); +var jumbleSize = ji.getPreferredSize (); +this.resize (jumbleSize.width, jumbleSize.height + 40); +this.add ("South", jumbleButton); +}); +c$.main = Clazz.defineMethod (c$, "main", +function (s) { +var f = new javax.swing.JFrame ("Jumbled Image"); +f.addWindowListener (((Clazz.isClassDefined ("swingjs.test.JumbledImageApplet$2") ? 0 : swingjs.test.JumbledImageApplet.$JumbledImageApplet$2$ ()), Clazz.innerTypeInstance (swingjs.test.JumbledImageApplet$2, this, null))); +var imageSrc = null; +try { +imageSrc = (( new java.io.File (swingjs.test.JumbledImageApplet.imageFileName)).toURI ()).toURL (); +} catch (e) { +if (Clazz.exceptionOf (e, java.net.MalformedURLException)) { +} else { +throw e; +} +} +var jumbler = new swingjs.test.JumbledImageApplet (imageSrc); +jumbler.buildUI (); +f.add ("Center", jumbler); +f.pack (); +f.setVisible (true); +}, "~A"); +Clazz.defineMethod (c$, "pathTo", + function (file) { +var path = this.getDocumentBase ().toString (); +var pt = path.indexOf ("/bin/"); +if (pt > 0) path = path.substring (0, pt) + "/html/" + path.substring (pt + 5); +path = path.substring (0, path.lastIndexOf ("/") + 1) + file; +if (path.startsWith ("/")) path = "file://" + path; +return new java.net.URL (path); +}, "~S"); +c$.$JumbledImageApplet$1$ = function () { +Clazz.pu$h(self.c$); +c$ = Clazz.declareAnonymous (swingjs.test, "JumbledImageApplet$1", null, java.awt.event.ActionListener); +Clazz.overrideMethod (c$, "actionPerformed", +function (e) { +var b = e.getSource (); +this.f$.ji.jumble (); +this.f$.ji.repaint (); +}, "java.awt.event.ActionEvent"); +c$ = Clazz.p0p (); +}; +c$.$JumbledImageApplet$2$ = function () { +Clazz.pu$h(self.c$); +c$ = Clazz.declareAnonymous (swingjs.test, "JumbledImageApplet$2", java.awt.event.WindowAdapter); +Clazz.overrideMethod (c$, "windowClosing", +function (e) { +System.exit (0); +}, "java.awt.event.WindowEvent"); +c$ = Clazz.p0p (); +}; +Clazz.defineStatics (c$, +"imageFileName", "examples/duke_skateboard.jpg"); +});