Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkgilmer2006-03-12 21:29:48 +0000
committerkgilmer2006-03-12 21:29:48 +0000
commit5751677128139cd14d835ac466ac3fee0d6c7b4f (patch)
treeeec7d90ea4c4321b5fb1a2c7835a63ea4b01ae73
parent79b3057e4bbe94f8ad64b60611507bf51a7813a3 (diff)
downloadorg.eclipse.ecf-5751677128139cd14d835ac466ac3fee0d6c7b4f.tar.gz
org.eclipse.ecf-5751677128139cd14d835ac466ac3fee0d6c7b4f.tar.xz
org.eclipse.ecf-5751677128139cd14d835ac466ac3fee0d6c7b4f.zip
Added copyright and comments.
-rw-r--r--doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/ScribbleView.java30
-rw-r--r--doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/AbstractTool.java50
-rw-r--r--doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Box.java18
-rw-r--r--doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/DrawSettings.java16
-rw-r--r--doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Line.java17
-rw-r--r--doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ListContentProvider.java14
-rw-r--r--doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Oval.java17
-rw-r--r--doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Pencil.java14
-rw-r--r--doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ToolboxLabelProvider.java16
9 files changed, 161 insertions, 31 deletions
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/ScribbleView.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/ScribbleView.java
index 790bbf184..2eb5b6d2d 100644
--- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/ScribbleView.java
+++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/ScribbleView.java
@@ -5,13 +5,12 @@
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Chris Aniszczyk <zx@us.ibm.com> - initial API and implementation
+ * Ken Gilmer <kgilmer@gmail.com>
******************************************************************************/
package org.eclipse.ecf.tutorial.scribbleshare;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -36,9 +35,6 @@ import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -84,12 +80,17 @@ public class ScribbleView extends ViewPart {
this.channel = channel;
}
+ /**
+ * This is called when a remote client calls <code>sendTool</code>.
+ * @param message
+ */
public void handleDrawLine(byte[] message) {
ByteArrayInputStream bins = new ByteArrayInputStream(message);
// DataInputStream dins = new DataInputStream(bins);
try {
ObjectInputStream ois = new ObjectInputStream(bins);
AbstractTool tool = (AbstractTool) ois.readObject();
+ //Apply the tool to the local canvas.
tool.draw(canvas);
} catch (IOException e1) {
// TODO Auto-generated catch block
@@ -104,9 +105,11 @@ public class ScribbleView extends ViewPart {
if (channel != null && currentTool != null) {
try {
ByteArrayOutputStream bouts = new ByteArrayOutputStream();
+ // create a byte array from serialized Tool
ObjectOutputStream douts = new ObjectOutputStream(bouts);
douts.writeObject(tool);
+ // send serialized tool to other clients.
channel.sendMessage(bouts.toByteArray());
} catch (Exception e) {
e.printStackTrace();
@@ -148,10 +151,12 @@ public class ScribbleView extends ViewPart {
toolbox.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
currentTool = (AbstractTool) ((StructuredSelection) toolbox.getSelection()).getFirstElement();
+ //Apply the drawSettings to the currently selected tool.
currentTool.setDrawSettings(drawSettings);
}
});
+ //Create the UI widgets to modify the DrawSettings instance.
createSettings(paletteComposite);
Label separator = new Label(backgroundComposite, SWT.SEPARATOR | SWT.VERTICAL/* SWT.NONE */);
@@ -164,10 +169,13 @@ public class ScribbleView extends ViewPart {
Listener listener = new Listener() {
public void handleEvent(Event event) {
if (currentTool != null) {
+ //Have the tool interpret the mouse events.
currentTool.handleUIEvent(event, canvas);
+ //If the tool interaction is complete, send the tool to other clients for rendering.
if (currentTool.isComplete()) {
sendTool(currentTool);
+ //Only do this once per Tool.
currentTool.setComplete(false);
}
}
@@ -179,11 +187,7 @@ public class ScribbleView extends ViewPart {
}
private void createSettings(Composite paletteComposite) {
- {
- Label l = new Label(paletteComposite, SWT.NONE);
- l.setText("Settings");
- }
-
+ // Size of Pen (drawWidth) set on the GC.
{
Label l = new Label(paletteComposite, SWT.NONE);
l.setText("Pen Size");
@@ -199,7 +203,7 @@ public class ScribbleView extends ViewPart {
});
}
-
+ //Toggles the antialias property on the GC.
{
final Button b = new Button(paletteComposite, SWT.CHECK);
b.setText("Antialias");
@@ -217,6 +221,10 @@ public class ScribbleView extends ViewPart {
}
+ /**
+ * Create the list of tools available to be used. Add new subclasses of AbstractTool here.
+ * @return
+ */
private List createTools() {
List toolList = new ArrayList();
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/AbstractTool.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/AbstractTool.java
index b60ac67ad..97bc3e411 100644
--- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/AbstractTool.java
+++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/AbstractTool.java
@@ -1,15 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM, Inc and Composent, Inc. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Ken Gilmer <kgilmer@gmail.com> - initial API and implementation
+ ******************************************************************************/
+
package org.eclipse.ecf.tutorial.scribbleshare.toolbox;
import java.io.Serializable;
-import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
+/**
+ * Common functionality for all tools. Handles common variables and settings.
+ * @author kgilmer
+ *
+ */
abstract public class AbstractTool implements Serializable {
protected int startX, startY, endX, endY;
@@ -18,20 +30,29 @@ abstract public class AbstractTool implements Serializable {
protected boolean isComplete = false;
protected DrawSettings drawSettings;
-/*
- public void setCoordinates(int startX, int startY, int endX, int endY) {
- this.startX = startX;
- this.startY = startY;
- this.endX = endX;
- this.endY = endY;
- } */
+ /**
+ *
+ * @return Name of tool.
+ */
abstract public String getName();
+ /**
+ * @return Image of tool, for use in tool palette view.
+ */
abstract public Image getImage();
+ /**
+ * Causes to tool to create it's output. May be called from remote clients.
+ * @param canvas
+ */
abstract public void draw(final Canvas canvas);
+ /**
+ * Have a tool handle a mouse event. Used for local events only.
+ * @param event
+ * @param canvas
+ */
abstract public void handleUIEvent(Event event, Canvas canvas);
protected void setupGC(GC gc) {
@@ -44,10 +65,17 @@ abstract public class AbstractTool implements Serializable {
}
+ /**
+ * Used to determine when an event should be sent to remote clients.
+ * @return
+ */
public boolean isPenDown() {
return penDown;
}
+ /**Used to determine when an event should be sent to remote clients.
+ * @return
+ */
public boolean isComplete() {
return isComplete;
}
@@ -56,6 +84,10 @@ abstract public class AbstractTool implements Serializable {
isComplete = b;
}
+ /**
+ * Set the drawSettings. Effects the GC and how shapes are drawn.
+ * @param drawSettings
+ */
public void setDrawSettings(DrawSettings drawSettings) {
this.drawSettings = drawSettings;
}
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Box.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Box.java
index da79faa78..b6b46af17 100644
--- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Box.java
+++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Box.java
@@ -1,15 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM, Inc and Composent, Inc. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Ken Gilmer <kgilmer@gmail.com> - initial API and implementation
+ ******************************************************************************/
+
package org.eclipse.ecf.tutorial.scribbleshare.toolbox;
-import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
+/**
+ * Creates a box shape.
+ *
+ * @author kgilmer
+ *
+ */
public class Box extends AbstractTool {
private static final long serialVersionUID = -165859440014182966L;
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/DrawSettings.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/DrawSettings.java
index 0db3cb7c2..963d760b3 100644
--- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/DrawSettings.java
+++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/DrawSettings.java
@@ -1,10 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM, Inc and Composent, Inc. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Ken Gilmer <kgilmer@gmail.com> - initial API and implementation
+ ******************************************************************************/
+
package org.eclipse.ecf.tutorial.scribbleshare.toolbox;
import java.io.Serializable;
import org.eclipse.swt.graphics.RGB;
+/**
+ * Changable settings for the GC. Used in the UI and AbstractTool to set the GC.
+ * @author kgilmer
+ *
+ */
public class DrawSettings implements Serializable {
+ private static final long serialVersionUID = -8547433052358403391L;
+
private int penWidth;
private RGB backgroundColor;
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Line.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Line.java
index 596743c31..528b0f859 100644
--- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Line.java
+++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Line.java
@@ -1,15 +1,26 @@
package org.eclipse.ecf.tutorial.scribbleshare.toolbox;
-import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
+/*******************************************************************************
+ * Copyright (c) 2006 IBM, Inc and Composent, Inc. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Ken Gilmer <kgilmer@gmail.com> - initial API and implementation
+ ******************************************************************************/
+
+/**
+ * A line shape.
+ * @author kgilmer
+ *
+ */
public class Line extends AbstractTool {
private static final long serialVersionUID = -165859440014182966L;
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ListContentProvider.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ListContentProvider.java
index 92ba620c1..1b5a07a7b 100644
--- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ListContentProvider.java
+++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ListContentProvider.java
@@ -1,3 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM, Inc and Composent, Inc. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Ken Gilmer <kgilmer@gmail.com> - initial API and implementation
+ ******************************************************************************/
+
package org.eclipse.ecf.tutorial.scribbleshare.toolbox;
import java.util.List;
@@ -5,6 +14,11 @@ import java.util.List;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
+/**
+ * Palette consists of a List of AbstractTools.
+ * @author kgilmer
+ *
+ */
public class ListContentProvider implements IStructuredContentProvider {
public Object[] getElements(Object inputElement) {
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Oval.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Oval.java
index badf7ed2f..e7c5dc2a9 100644
--- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Oval.java
+++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Oval.java
@@ -1,15 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM, Inc and Composent, Inc. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Ken Gilmer <kgilmer@gmail.com> - initial API and implementation
+ ******************************************************************************/
+
package org.eclipse.ecf.tutorial.scribbleshare.toolbox;
-import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
+/**
+ * An oval shape.
+ * @author kgilmer
+ *
+ */
public class Oval extends AbstractTool {
private static final long serialVersionUID = -165859440014182966L;
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Pencil.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Pencil.java
index 527a799e1..63fd19734 100644
--- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Pencil.java
+++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/Pencil.java
@@ -1,3 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM, Inc and Composent, Inc. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Ken Gilmer <kgilmer@gmail.com> - initial API and implementation
+ ******************************************************************************/
+
package org.eclipse.ecf.tutorial.scribbleshare.toolbox;
import org.eclipse.swt.SWT;
@@ -8,6 +17,11 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
+/**
+ * Freeform draw tool.
+ * @author kgilmer
+ *
+ */
public class Pencil extends AbstractTool {
private static final long serialVersionUID = -111458978163259455L;
private static int lastX;
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ToolboxLabelProvider.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ToolboxLabelProvider.java
index e82cb918d..2a8b2e57f 100644
--- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ToolboxLabelProvider.java
+++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/scribbleshare/toolbox/ToolboxLabelProvider.java
@@ -1,11 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM, Inc and Composent, Inc. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Ken Gilmer <kgilmer@gmail.com> - initial API and implementation
+ ******************************************************************************/
+
package org.eclipse.ecf.tutorial.scribbleshare.toolbox;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;
+/**
+ * Label provider, requires <code>AbstractTool</code> class.
+ * @author kgilmer
+ *
+ */
public class ToolboxLabelProvider implements ITableLabelProvider {
public Image getColumnImage(Object element, int columnIndex) {

Back to the top