Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
55 changes: 55 additions & 0 deletions test/org/apache/tomcat/websocket/TestDrawMessage.java
Original file line number Diff line number Diff line change
@@ -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> 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);
}
}
4 changes: 4 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@
</subsection>
<subsection name="Web applications">
<changelog>
<fix>
Examples: Draw axis-aligned rectangles and ellipses as lines in the
WebSocket drawboard. (sainadh777)
</fix>
<update>
Manager: Drop session handling dedicated to extracting the locale from
Tapestry attributes, used for locale session sorting. (remm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down