diff options
author | Alex Clayton <alex.clayton@isode.com> | 2016-02-26 16:51:13 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2016-03-09 16:44:17 (GMT) |
commit | 8f112a856705b800d1a8797bec5d9396a9c00b34 (patch) | |
tree | 6468ad42172e1d1f68138a26679dbaf85b58e6b9 /src/com/isode/stroke/elements | |
parent | 8fe752626726ca8d058ce437127a37d5d738a5eb (diff) | |
download | stroke-8f112a856705b800d1a8797bec5d9396a9c00b34.zip stroke-8f112a856705b800d1a8797bec5d9396a9c00b34.tar.bz2 |
Add Whiteboard Functionality
Add the Whiteboard classes to stroke.
Test-information:
Unit tests all pass.
Change-Id: Id409c09d0fc1f82864e5d706c413b9d984a7db82
Diffstat (limited to 'src/com/isode/stroke/elements')
15 files changed, 752 insertions, 1 deletions
diff --git a/src/com/isode/stroke/elements/DiscoInfo.java b/src/com/isode/stroke/elements/DiscoInfo.java index 35786e7..78e43ff 100644 --- a/src/com/isode/stroke/elements/DiscoInfo.java +++ b/src/com/isode/stroke/elements/DiscoInfo.java @@ -3,7 +3,7 @@ * All rights reserved. */ /* - * Copyright (c) 2010-2015, Isode Limited, London, England. + * Copyright (c) 2010-2016, Isode Limited, London, England. * All rights reserved. */ package com.isode.stroke.elements; @@ -33,6 +33,7 @@ public class DiscoInfo extends Payload { public static final String JingleTransportsS5BFeature = "urn:xmpp:jingle:transports:s5b:1"; public static final String Bytestream = "http://jabber.org/protocol/bytestreams"; public static final String MessageDeliveryReceiptsFeature = "urn:xmpp:receipts"; + public static final String WhiteboardFeature = "http://swift.im/whiteboard"; public static class Identity implements Comparable<Identity> { private final String name_; diff --git a/src/com/isode/stroke/elements/WhiteboardColor.java b/src/com/isode/stroke/elements/WhiteboardColor.java new file mode 100644 index 0000000..f40f618 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardColor.java @@ -0,0 +1,69 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardColor { + + private final int red_, green_, blue_; + private int alpha_; + + public WhiteboardColor() { + this(0,0,0,255); + } + + public WhiteboardColor(int red,int green,int blue) { + this(red,green,blue,255); + } + + public WhiteboardColor(int red,int green,int blue,int alpha) { + red_ = red; + green_ = green; + blue_ = blue; + alpha_ = alpha; + } + + public WhiteboardColor(String hex) { + alpha_ = 255; + int value = Integer.parseInt(hex.substring(1)); + red_ = (value >> 16) & 0xFF; + green_ = (value >> 8) & 0xFF; + blue_ = value & 0xFF; + } + + public String toHex() { + int value = (red_ << 16) + (green_ << 8) + blue_; + StringBuilder builder = new StringBuilder(Integer.toHexString(value)); + while (builder.length() < 6) { + builder.insert(0, '0'); + } + builder.insert(0, '#'); + return builder.toString(); + } + + public int getRed() { + return red_; + } + + public int getGreen() { + return green_; + } + + public int getBlue() { + return blue_; + } + + public int getAlpha() { + return alpha_; + } + + public void setAlpha(int alpha) { + alpha_ = alpha; + } +} diff --git a/src/com/isode/stroke/elements/WhiteboardDeleteOperation.java b/src/com/isode/stroke/elements/WhiteboardDeleteOperation.java new file mode 100644 index 0000000..87ab226 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardDeleteOperation.java @@ -0,0 +1,33 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardDeleteOperation extends WhiteboardOperation { + + private String elementID_ = ""; + + public WhiteboardDeleteOperation() { + // Empty Constructor + } + + public WhiteboardDeleteOperation(WhiteboardDeleteOperation other) { + super(other); + this.elementID_ = other.elementID_; + } + + public String getElementID() { + return elementID_; + } + + public void setElementID(String id) { + elementID_ = id; + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardElement.java b/src/com/isode/stroke/elements/WhiteboardElement.java new file mode 100644 index 0000000..5e2912a --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardElement.java @@ -0,0 +1,30 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public abstract class WhiteboardElement { + + private String id_ = ""; + + public WhiteboardElement() { + // Empty Constructor + } + + public abstract void accept(WhiteboardElementVisitor visitor); + + public final String getID() { + return id_; + } + + public final void setID(String id) { + id_ = id; + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardElementVisitor.java b/src/com/isode/stroke/elements/WhiteboardElementVisitor.java new file mode 100644 index 0000000..0853373 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardElementVisitor.java @@ -0,0 +1,21 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public interface WhiteboardElementVisitor { + + public void visit(WhiteboardLineElement element); + public void visit(WhiteboardFreehandPathElement element); + public void visit(WhiteboardRectElement element); + public void visit(WhiteboardPolygonElement element); + public void visit(WhiteboardTextElement element); + public void visit(WhiteboardEllipseElement element); + +} diff --git a/src/com/isode/stroke/elements/WhiteboardEllipseElement.java b/src/com/isode/stroke/elements/WhiteboardEllipseElement.java new file mode 100644 index 0000000..4cadc81 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardEllipseElement.java @@ -0,0 +1,71 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardEllipseElement extends WhiteboardElement { + + private final int cx_, cy_, rx_, ry_; + private WhiteboardColor penColor_; + private WhiteboardColor brushColor_; + private int penWidth_; + + public WhiteboardEllipseElement(int cx, int cy, int rx, int ry) { + cx_ = cx; + cy_ = cy; + rx_ = rx; + ry_ = ry; + } + + public int getCX() { + return cx_; + } + + public int getCY() { + return cy_; + } + + public int getRX() { + return rx_; + } + + public int getRY() { + return ry_; + } + + public WhiteboardColor getPenColor() { + return penColor_; + } + + public void setPenColor(WhiteboardColor color) { + penColor_ = color; + } + + public WhiteboardColor getBrushColor() { + return brushColor_; + } + + public void setBrushColor(WhiteboardColor color) { + brushColor_ = color; + } + + public int getPenWidth() { + return penWidth_; + } + + public void setPenWidth(int penWidth) { + penWidth_ = penWidth; + } + + @Override + public void accept(WhiteboardElementVisitor visitor) { + visitor.visit(this); + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardFreehandPathElement.java b/src/com/isode/stroke/elements/WhiteboardFreehandPathElement.java new file mode 100644 index 0000000..3885841 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardFreehandPathElement.java @@ -0,0 +1,65 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class WhiteboardFreehandPathElement extends WhiteboardElement { + + private List<Point> points_ = new ArrayList<Point>(); + private WhiteboardColor color_ = new WhiteboardColor(); + private int penWidth_ = 0; + + public WhiteboardFreehandPathElement() { + // Empty Constructor + } + + public void setPoints(Collection<? extends Point> points) { + points_.clear(); + points_.addAll(points_); + } + + public List<Point> getPoints() { + return new ArrayList<Point>(points_); + } + + public WhiteboardColor getColor() { + return color_; + } + + public void setColor(WhiteboardColor color) { + color_ = color; + } + + public int getPenWidth() { + return penWidth_; + } + + public void setPenWidth(int penWidth) { + penWidth_ = penWidth; + } + + @Override + public void accept(WhiteboardElementVisitor visitor) { + visitor.visit(this); + } + + public static class Point { + public final int x; + public final int y; + public Point(int x,int y) { + this.x = x; + this.y = y; + } + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardInsertOperation.java b/src/com/isode/stroke/elements/WhiteboardInsertOperation.java new file mode 100644 index 0000000..b4c9722 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardInsertOperation.java @@ -0,0 +1,33 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardInsertOperation extends WhiteboardOperation { + + private WhiteboardElement element_; + + public WhiteboardInsertOperation() { + // Empty Constructor + } + + public WhiteboardInsertOperation(WhiteboardInsertOperation other) { + super(other); + this.element_ = other.element_; + } + + public WhiteboardElement getElement() { + return element_; + } + + public void setElement(WhiteboardElement element) { + element_ = element; + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardLineElement.java b/src/com/isode/stroke/elements/WhiteboardLineElement.java new file mode 100644 index 0000000..df4ab9b --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardLineElement.java @@ -0,0 +1,64 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardLineElement extends WhiteboardElement { + + private final int x1_, x2_, y1_, y2_; + + private WhiteboardColor color_ = new WhiteboardColor(); + + private int penWidth_ = 1; + + public WhiteboardLineElement(int x1,int y1,int x2,int y2) { + x1_ = x1; + y1_ = y1; + x2_ = x2; + y2_ = y2; + } + + public int x1() { + return x1_; + } + + public int x2() { + return x2_; + } + + public int y1() { + return y1_; + } + + public int y2() { + return y2_; + } + + public WhiteboardColor getColor() { + return color_; + } + + public void setColor(WhiteboardColor color) { + color_ = color; + } + + public int getPenWidth() { + return penWidth_; + } + + public void setPenWidth(int penWidth) { + penWidth_ = penWidth; + } + + @Override + public void accept(WhiteboardElementVisitor visitor) { + visitor.visit(this); + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardOperation.java b/src/com/isode/stroke/elements/WhiteboardOperation.java new file mode 100644 index 0000000..d980f7c --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardOperation.java @@ -0,0 +1,52 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardOperation { + + private String id_ = ""; + private String parentID_ = ""; + private int pos_ = 0; + + public WhiteboardOperation() { + // Empty Constructor + } + + public WhiteboardOperation(WhiteboardOperation other) { + this.id_ = other.id_; + this.parentID_ = other.parentID_; + this.pos_ = other.pos_; + } + + public String getID() { + return id_; + } + + public void setID(String id) { + id_ = id; + } + + public String getParentID() { + return parentID_; + } + + public void setParentID(String parentID) { + parentID_ = parentID; + } + + public int getPos() { + return pos_; + } + + public void setPos(int pos) { + pos_ = pos; + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardPayload.java b/src/com/isode/stroke/elements/WhiteboardPayload.java new file mode 100644 index 0000000..337f6bb --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardPayload.java @@ -0,0 +1,67 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardPayload extends Payload { + + private String data_; + private Type type_; + private WhiteboardElement element_; + private WhiteboardOperation operation_; + + public enum Type { + UnknownType, + Data, + SessionRequest, + SessionAccept, + SessionTerminate; + } + + public WhiteboardPayload() { + this(Type.Data); + } + + public WhiteboardPayload(Type type) { + type_ = type; + } + + public void setData(String data) { + data_ = data; + } + + public String getData() { + return data_; + } + + public Type getType() { + return type_; + } + + public void setType(Type type) { + type_ = type; + } + + public WhiteboardElement getElement() { + return element_; + } + + public void setElement(WhiteboardElement element) { + element_ = element; + } + + public WhiteboardOperation getOperation() { + return operation_; + } + + public void setOperation(WhiteboardOperation operation) { + operation_ = operation; + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardPolygonElement.java b/src/com/isode/stroke/elements/WhiteboardPolygonElement.java new file mode 100644 index 0000000..3beb1c7 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardPolygonElement.java @@ -0,0 +1,70 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class WhiteboardPolygonElement extends WhiteboardElement { + + private final List<Point> points_ = new ArrayList<Point>(); + private WhiteboardColor penColor_; + private WhiteboardColor brushColor_; + private int penWidth_ = 0; + + public List<Point> getPoints() { + return new ArrayList<Point>(points_); + } + + public void setPoints(Collection<? extends Point> points) { + points_.clear(); + points_.addAll(points); + } + + public WhiteboardColor getPenColor() { + return penColor_; + } + + public void setPenColor(WhiteboardColor color) { + penColor_ = color; + } + + public WhiteboardColor getBrushColor() { + return brushColor_; + } + + public void setBrushColor(WhiteboardColor color) { + brushColor_ = color; + } + + public int getPenWidth() { + return penWidth_; + } + + public void setPenWidth(int penWidth) { + penWidth_ = penWidth; + } + + @Override + public void accept(WhiteboardElementVisitor visitor) { + visitor.visit(this); + } + + public static class Point { + public final int x; + public final int y; + public Point(int x,int y) { + this.x = x; + this.y = y; + } + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardRectElement.java b/src/com/isode/stroke/elements/WhiteboardRectElement.java new file mode 100644 index 0000000..205c8c1 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardRectElement.java @@ -0,0 +1,71 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardRectElement extends WhiteboardElement { + + private int x_, y_, width_, height_; + private WhiteboardColor penColor_; + private WhiteboardColor brushColor_; + private int penWidth_ = 1; + + public WhiteboardRectElement(int x, int y, int width, int height) { + x_ = x; + y_ = y; + width_ = width; + height_ = height; + } + + public int getX() { + return x_; + } + + public int getY() { + return y_; + } + + public int getWidth() { + return width_; + } + + public int getHeight() { + return height_; + } + + public WhiteboardColor getPenColor() { + return penColor_; + } + + public void setPenColor(WhiteboardColor color) { + penColor_ = color; + } + + public WhiteboardColor getBrushColor() { + return brushColor_; + } + + public void setBrushColor(WhiteboardColor color) { + brushColor_ = color; + } + + public int getPenWidth() { + return penWidth_; + } + + public void setPenWidth(int penWidth) { + penWidth_ = penWidth; + } + + @Override + public void accept(WhiteboardElementVisitor visitor) { + visitor.visit(this); + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardTextElement.java b/src/com/isode/stroke/elements/WhiteboardTextElement.java new file mode 100644 index 0000000..487aec0 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardTextElement.java @@ -0,0 +1,61 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardTextElement extends WhiteboardElement { + + private final int x_, y_; + private int size_; + private String text_; + private WhiteboardColor color_; + + public WhiteboardTextElement(int x, int y) { + x_ = x; + y_ = y; + } + + public void setText(String text) { + text_ = text; + } + + public String getText() { + return text_; + } + + public int getX() { + return x_; + } + + public int getY() { + return y_; + } + + public WhiteboardColor getColor() { + return color_; + } + + public void setColor(WhiteboardColor color) { + color_ = color; + } + + public int getSize() { + return size_; + } + + public void setSize(int size) { + size_ = size; + } + + @Override + public void accept(WhiteboardElementVisitor visitor) { + visitor.visit(this); + } + +} diff --git a/src/com/isode/stroke/elements/WhiteboardUpdateOperation.java b/src/com/isode/stroke/elements/WhiteboardUpdateOperation.java new file mode 100644 index 0000000..9ca5e32 --- /dev/null +++ b/src/com/isode/stroke/elements/WhiteboardUpdateOperation.java @@ -0,0 +1,43 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.elements; + +public class WhiteboardUpdateOperation extends WhiteboardOperation { + + private WhiteboardElement element_; + private int newPos_ = 0; + + public WhiteboardUpdateOperation() { + // Empty Constructor + } + + public WhiteboardUpdateOperation(WhiteboardUpdateOperation other) { + super(other); + this.element_ = other.element_; + this.newPos_ = other.newPos_; + } + + public WhiteboardElement getElement() { + return element_; + } + + public void setElement(WhiteboardElement element) { + element_ = element; + } + + public int getNewPos() { + return newPos_; + } + + public void setNewPos(int newPos) { + newPos_ = newPos; + } + +} |