]> source.dussan.org Git - vaadin-framework.git/commitdiff
added test case
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 5 Dec 2008 17:03:40 +0000 (17:03 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 5 Dec 2008 17:03:40 +0000 (17:03 +0000)
svn changeset:6103/svn branch:trunk

src/com/itmill/toolkit/tests/tickets/Ticket2292.java [new file with mode: 0644]

diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2292.java b/src/com/itmill/toolkit/tests/tickets/Ticket2292.java
new file mode 100644 (file)
index 0000000..4967c24
--- /dev/null
@@ -0,0 +1,88 @@
+package com.itmill.toolkit.tests.tickets;\r
+\r
+import java.awt.Color;\r
+import java.awt.Graphics;\r
+import java.awt.image.BufferedImage;\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
+import java.net.URL;\r
+\r
+import javax.imageio.ImageIO;\r
+\r
+import com.itmill.toolkit.terminal.DownloadStream;\r
+import com.itmill.toolkit.terminal.ExternalResource;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.CheckBox;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.Link;\r
+import com.itmill.toolkit.ui.Window;\r
+\r
+public class Ticket2292 extends com.itmill.toolkit.Application {\r
+\r
+    @Override\r
+    public void init() {\r
+        final Window main = new Window(getClass().getName().substring(\r
+                getClass().getName().lastIndexOf(".") + 1));\r
+        setMainWindow(main);\r
+\r
+        ExternalResource icon = new ExternalResource("./icon.png");\r
+        main\r
+                .addComponent(new Label(\r
+                        "Note, run with trailing slash in url to have a working icon. Icon is built by servlet with a slow method, so it will show the bug (components not firing requestLayout)"));\r
+        Button b = new Button();\r
+        main.addComponent(b);\r
+        b.setIcon(icon);\r
+\r
+        CheckBox checkBox = new CheckBox();\r
+        main.addComponent(checkBox);\r
+        checkBox.setIcon(icon);\r
+\r
+        Link l = new Link("l", icon);\r
+        main.addComponent(l);\r
+\r
+    }\r
+\r
+    @Override\r
+    public DownloadStream handleURI(URL context, String relativeUri) {\r
+        if (!relativeUri.contains("icon.png")) {\r
+            return null;\r
+        }\r
+\r
+        // be slow to show bug\r
+        try {\r
+            Thread.sleep(2000);\r
+        } catch (InterruptedException e1) {\r
+            // TODO Auto-generated catch block\r
+            e1.printStackTrace();\r
+        }\r
+\r
+        BufferedImage image = new BufferedImage(200, 200,\r
+                BufferedImage.TYPE_INT_RGB);\r
+        Graphics drawable = image.getGraphics();\r
+        drawable.setColor(Color.lightGray);\r
+        drawable.fillRect(0, 0, 200, 200);\r
+        drawable.setColor(Color.yellow);\r
+        drawable.fillOval(25, 25, 150, 150);\r
+        drawable.setColor(Color.blue);\r
+        drawable.drawRect(0, 0, 199, 199);\r
+\r
+        // Use the parameter to create dynamic content.\r
+        drawable.setColor(Color.black);\r
+        drawable.drawString("Tex", 75, 100);\r
+\r
+        try {\r
+            // Write the image to a buffer.\r
+            ByteArrayOutputStream imagebuffer = new ByteArrayOutputStream();\r
+            ImageIO.write(image, "png", imagebuffer);\r
+\r
+            // Return a stream from the buffer.\r
+            ByteArrayInputStream istream = new ByteArrayInputStream(imagebuffer\r
+                    .toByteArray());\r
+            return new DownloadStream(istream, null, null);\r
+        } catch (IOException e) {\r
+            return null;\r
+        }\r
+    }\r
+\r
+}\r