diff --git a/TODO.md b/TODO.md index c289a1048bc6..62f14ad550ac 100644 --- a/TODO.md +++ b/TODO.md @@ -997,16 +997,6 @@ These are bugs, correctness issues, or missing functionality that may affect pro --- -### 90. Example WebSocket Draw Message (1 item) - -| # | File:Line | Description | Fix Idea | Effort | Difficulty | -|---|-----------|-------------|----------|--------|------------| -| 90.1 | `DrawMessage.java:163` | Axis-aligned rectangles should be drawn as lines | Add a check: if `x1 == x2` or `y1 == y2`, draw a line instead of a rectangle. | 0.25 day | Low | - -**Total estimated effort: 0.25 day, Low difficulty** - ---- - ### 91. Example WebSocket Client Blocking (2 items) | # | File:Line | Description | Fix Idea | Effort | Difficulty | diff --git a/test/org/apache/tomcat/websocket/TestDrawMessage.java b/test/org/apache/tomcat/websocket/TestDrawMessage.java new file mode 100644 index 000000000000..b1091fa3285c --- /dev/null +++ b/test/org/apache/tomcat/websocket/TestDrawMessage.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.websocket; + +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.geom.Line2D; + +import org.easymock.Capture; +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Test; + +import websocket.drawboard.DrawMessage; + +public class TestDrawMessage { + + @Test + public void testAxisAlignedRectangleDrawnAsLine() { + assertDrawsLine(3, 5, 20, 5, 30); + } + + @Test + public void testAxisAlignedEllipseDrawnAsLine() { + assertDrawsLine(4, 20, 5, 30, 5); + } + + private static void assertDrawsLine(int type, double x1, double y1, double x2, double y2) { + Graphics2D graphics = EasyMock.createNiceMock(Graphics2D.class); + Capture shape = EasyMock.newCapture(); + graphics.draw(EasyMock.capture(shape)); + EasyMock.expectLastCall().once(); + EasyMock.replay(graphics); + + DrawMessage message = new DrawMessage(type, (byte) 0, (byte) 0, (byte) 0, (byte) 0, 1, x1, x2, y1, y2); + message.draw(graphics); + + EasyMock.verify(graphics); + Assert.assertTrue(shape.getValue() instanceof Line2D); + } +} diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 971c15b324ad..49ab4adc91c6 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -393,6 +393,10 @@ + + Examples: Draw axis-aligned rectangles and ellipses as lines in the + WebSocket drawboard. (sainadh777) + Manager: Drop session handling dedicated to extracting the locale from Tapestry attributes, used for locale session sorting. (remm) diff --git a/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java b/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java index 33de5572ee1e..4d4dd8387244 100644 --- a/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java +++ b/webapps/examples/WEB-INF/classes/websocket/drawboard/DrawMessage.java @@ -160,9 +160,12 @@ public void draw(Graphics2D g) { y2 = this.y1; } - // TODO: If (x1 == x2 || y1 == y2) draw as line. + if (x1 == x2 || y1 == y2) { + // Draw axis-aligned shapes as lines to match the behavior in the HTML5 Canvas. + Line2D line = new Line2D.Double(x1, y1, x2, y2); + g.draw(line); - if (type == 3) { + } else if (type == 3) { // Draw a rectangle. Rectangle2D rect = new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1);