summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-02-26 16:51:13 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-03-09 16:44:17 (GMT)
commit8f112a856705b800d1a8797bec5d9396a9c00b34 (patch)
tree6468ad42172e1d1f68138a26679dbaf85b58e6b9 /src/com/isode/stroke/whiteboard/WhiteboardServer.java
parent8fe752626726ca8d058ce437127a37d5d738a5eb (diff)
downloadstroke-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/whiteboard/WhiteboardServer.java')
-rw-r--r--src/com/isode/stroke/whiteboard/WhiteboardServer.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/com/isode/stroke/whiteboard/WhiteboardServer.java b/src/com/isode/stroke/whiteboard/WhiteboardServer.java
new file mode 100644
index 0000000..7685671
--- /dev/null
+++ b/src/com/isode/stroke/whiteboard/WhiteboardServer.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.whiteboard;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.isode.stroke.elements.WhiteboardOperation;
+
+public class WhiteboardServer {
+
+ private final List<WhiteboardOperation> operations_ = new ArrayList<WhiteboardOperation>();
+
+ public void handleLocalOperationReceived(WhiteboardOperation operation) {
+ operations_.add(operation);
+ }
+
+ public WhiteboardOperation handleClientOperationReceived(WhiteboardOperation newOperation) {
+
+ if (operations_.isEmpty() ||
+ newOperation.getParentID().equals(operations_.get(operations_.size()-1).getID())) {
+ operations_.add(newOperation);
+ return newOperation;
+ }
+ for (int i = (operations_.size()-1); i >= 0; i--) {
+ WhiteboardOperation operation = operations_.get(i);
+ while (newOperation.getParentID().equals(operation.getParentID())) {
+ WhiteboardTransformer.Pair tResult =
+ WhiteboardTransformer.transform(newOperation, operation);
+ if (i == (operations_.size()-1)) {
+ operations_.add(tResult.second);
+ return tResult.second;
+ }
+ else {
+ newOperation = tResult.second;
+ i++;
+ operation = operations_.get(i);
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Server:\n");
+ for (WhiteboardOperation op : operations_) {
+ builder.append(op.getID());
+ builder.append(" '");
+ builder.append(op.getParentID());
+ builder.append("' ");
+ builder.append(op.getPos());
+ builder.append("\n");
+ }
+ return builder.toString();
+ }
+
+ public void print() {
+ System.out.println(this);
+ }
+
+}