Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-01-02 07:33:08 +0000
committerslewis2008-01-02 07:33:08 +0000
commit71a9da9297db0e73e55f76cdb0bceda2eb66b80a (patch)
tree745a467698d6da54661f16c0945b000a3da3bbfd /examples/bundles/org.eclipse.ecf.example.collab
parentb23b6de3a7c2dc55c1bee9b3f20e00691a95be56 (diff)
downloadorg.eclipse.ecf-71a9da9297db0e73e55f76cdb0bceda2eb66b80a.tar.gz
org.eclipse.ecf-71a9da9297db0e73e55f76cdb0bceda2eb66b80a.tar.xz
org.eclipse.ecf-71a9da9297db0e73e55f76cdb0bceda2eb66b80a.zip
Updates to screen capture capability
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.example.collab')
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java81
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ChatComposite.java6
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ImageWrapper.java45
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ShowImageShell.java118
4 files changed, 183 insertions, 67 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java
index e049b6755..3dad3741a 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java
@@ -10,10 +10,14 @@
*****************************************************************************/
package org.eclipse.ecf.example.collab.share;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -36,14 +40,13 @@ import org.eclipse.ecf.internal.example.collab.ui.FileReceiverUI;
import org.eclipse.ecf.internal.example.collab.ui.ImageWrapper;
import org.eclipse.ecf.internal.example.collab.ui.LineChatClientView;
import org.eclipse.ecf.internal.example.collab.ui.LineChatView;
+import org.eclipse.ecf.internal.example.collab.ui.ShowImageShell;
import org.eclipse.ecf.internal.example.collab.ui.hyperlink.EclipseCollabHyperlinkDetector;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewPart;
@@ -78,6 +81,8 @@ public class EclipseCollabSharedObject extends GenericSharedObject {
public static final String ID = "chat";
private static final String DEFAULT_WINDOW_TITLE = "Chat";
+ private static final String HANDLE_SHOW_IMAGE_START_MSG = "handleShowImageStart";
+ private static final String HANDLE_SHOW_IMAGE_DATA_MSG = "handleShowImageData";
private String windowTitle = DEFAULT_WINDOW_TITLE;
private String downloadDirectory = "";
@@ -504,39 +509,69 @@ public class EclipseCollabSharedObject extends GenericSharedObject {
}
}
- public void sendImage(ID toID, ImageWrapper wrapper) {
+ private static byte[] compress(byte[] source) throws IOException {
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final ZipOutputStream zos = new ZipOutputStream(bos);
+ final ByteArrayInputStream bis = new ByteArrayInputStream(source);
+ int read = 0;
+ final byte[] buf = new byte[16192];
+ zos.putNextEntry(new ZipEntry("bytes"));
+ while ((read = bis.read(buf)) != -1) {
+ zos.write(buf, 0, read);
+ }
+ zos.finish();
+ zos.flush();
+ return bos.toByteArray();
+ }
+
+ public void sendImage(ID toID, ImageData imageData) {
try {
- forwardMsgTo(toID, SharedObjectMsg.createMsg(null, HANDLE_SHOW_IMAGE_MSG, localContainerID, wrapper));
+ forwardMsgTo(toID, SharedObjectMsg.createMsg(null, HANDLE_SHOW_IMAGE_START_MSG, localContainerID, localUser.getNickname(), new ImageWrapper(imageData)));
+ final byte[] compressedData = compress(imageData.data);
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream(8096);
+ int startPos = 0;
+ while (startPos <= compressedData.length) {
+ bos.reset();
+ final int length = Math.min(compressedData.length - startPos, 8096);
+ bos.write(compressedData, startPos, length);
+ startPos += 8096;
+ bos.flush();
+ final Boolean done = new Boolean((compressedData.length - startPos) < 0);
+ forwardMsgTo(toID, SharedObjectMsg.createMsg(null, HANDLE_SHOW_IMAGE_DATA_MSG, localContainerID, bos.toByteArray(), done));
+ }
} catch (final Exception e) {
- log("Exception on sendShowTextMsg to remote clients", e);
+ log("Exception on sendImage", e);
}
}
- protected void handleShowImage(ID id, final ImageWrapper wrapper) {
+ ShowImageShell showImageShell = null;
+
+ protected void handleShowImageStart(final ID id, final String fromUser, final ImageWrapper imageWrapper) {
final Display display = localGUI.getTextControl().getDisplay();
display.asyncExec(new Runnable() {
public void run() {
- try {
- final Image image = new Image(display, wrapper.createImageData());
- final Shell shell = new Shell(display);
- shell.setBounds(image.getBounds());
- shell.addDisposeListener(new DisposeListener() {
+ if (showImageShell == null) {
+ showImageShell = new ShowImageShell(display, id, imageWrapper, new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
- image.dispose();
+ showImageShell = null;
}
});
-
- shell.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent e) {
- e.gc.drawImage(image, 0, 0);
- }
- });
- shell.open();
- } catch (final IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ showImageShell.setText("Screen capture from " + fromUser);
+ showImageShell.open();
}
+ }
+ });
+ }
+ protected void handleShowImageData(final ID id, final byte[] data, final Boolean done) {
+ final Display display = localGUI.getTextControl().getDisplay();
+ display.asyncExec(new Runnable() {
+ public void run() {
+ if (showImageShell != null && showImageShell.getSenderID().equals(id)) {
+ showImageShell.addData(data);
+ if (done.booleanValue())
+ showImageShell.showImage();
+ }
}
});
}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ChatComposite.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ChatComposite.java
index 92788d2d7..8beea8fcd 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ChatComposite.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ChatComposite.java
@@ -77,6 +77,7 @@ import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
@@ -461,10 +462,11 @@ public class ChatComposite extends Composite {
gc.drawRectangle(downX, downY, e.x - downX, e.y - downY);
gc.setForeground(whiteColor);
gc.drawRectangle(downX - 1, downY - 1, e.x - downX + 2, e.y - downY + 2);
+ setCursor(new Cursor(getDisplay(), SWT.CURSOR_SIZESE));
}
}
});
-
+ shell.setCursor(new Cursor(getDisplay(), SWT.CURSOR_CROSS));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
@@ -495,7 +497,7 @@ public class ChatComposite extends Composite {
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {
- view.lch.sendImage(targetID, new ImageWrapper(image.getImageData()));
+ view.lch.sendImage(targetID, image.getImageData());
}
super.buttonPressed(buttonId);
}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ImageWrapper.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ImageWrapper.java
index b8d6696b1..10ce31792 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ImageWrapper.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ImageWrapper.java
@@ -10,13 +10,7 @@
******************************************************************************/
package org.eclipse.ecf.internal.example.collab.ui;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.Serializable;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
@@ -29,56 +23,23 @@ public class ImageWrapper implements Serializable {
public final int height;
public final int depth;
public final int scanlinePad;
- public byte[] data;
private final int redMask;
private final int greenMask;
private final int blueMask;
- ImageWrapper(ImageData data) {
+ public ImageWrapper(ImageData data) {
width = data.width;
height = data.height;
depth = data.depth;
scanlinePad = data.scanlinePad;
- this.data = null;
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- final ZipOutputStream zos = new ZipOutputStream(bos);
- final ZipEntry entry = new ZipEntry("bytes");
- final ByteArrayInputStream bis = new ByteArrayInputStream(data.data);
- int read = 0;
- final byte[] buf = new byte[16384];
- try {
- zos.putNextEntry(entry);
- while ((read = bis.read(buf)) != -1) {
- zos.write(buf, 0, read);
- }
- zos.finish();
- zos.flush();
- } catch (final IOException e) {
- // Should never happen
- }
- this.data = bos.toByteArray();
redMask = data.palette.redMask;
greenMask = data.palette.greenMask;
blueMask = data.palette.blueMask;
}
- protected byte[] getUncompressedData() throws IOException {
- final ZipInputStream ins = new ZipInputStream(new ByteArrayInputStream(this.data));
- final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- int read = 0;
- final byte[] buf = new byte[16384];
- ins.getNextEntry();
- while ((read = ins.read(buf)) > 0) {
- bos.write(buf, 0, read);
- }
- bos.flush();
- ins.close();
- return bos.toByteArray();
- }
-
- public ImageData createImageData() throws IOException {
+ public ImageData createImageData(byte[] data) {
final PaletteData palette = new PaletteData(redMask, greenMask, blueMask);
- return new ImageData(width, height, depth, palette, scanlinePad, getUncompressedData());
+ return new ImageData(width, height, depth, palette, scanlinePad, data);
}
}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ShowImageShell.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ShowImageShell.java
new file mode 100644
index 000000000..632711347
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ShowImageShell.java
@@ -0,0 +1,118 @@
+/****************************************************************************
+ * Copyright (c) 2007 Composent, Inc. and others.
+ * 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:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.internal.example.collab.ui;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.zip.ZipInputStream;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ *
+ */
+public class ShowImageShell {
+
+ Shell shell;
+ ID senderID;
+ ImageWrapper imageWrapper;
+ List imageData;
+
+ public ShowImageShell(Display display, ID senderID, ImageWrapper imageWrapper, final DisposeListener disposeListener) {
+ this.shell = new Shell(display);
+ this.senderID = senderID;
+ this.imageWrapper = imageWrapper;
+ this.shell.setBounds(0, 0, imageWrapper.width, imageWrapper.height);
+ this.imageData = new ArrayList();
+ this.shell.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ disposeListener.widgetDisposed(e);
+ ShowImageShell.this.senderID = null;
+ ShowImageShell.this.imageWrapper = null;
+ ShowImageShell.this.imageData = null;
+ }
+ });
+ }
+
+ public void setText(String text) {
+ shell.setText(text);
+ }
+
+ public void open() {
+ shell.open();
+ }
+
+ public ID getSenderID() {
+ return senderID;
+ }
+
+ public void addData(byte[] bytes) {
+ this.imageData.add(bytes);
+ }
+
+ public void showImage() {
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try {
+ if (imageData != null) {
+ for (final Iterator i = imageData.iterator(); i.hasNext();) {
+ bos.write((byte[]) i.next());
+ }
+ }
+ bos.flush();
+ } catch (final IOException e) {
+ // should not happen
+ }
+ imageData.clear();
+ final byte[] uncompressedData = uncompress(bos.toByteArray());
+ shell.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ final Image image = new Image(shell.getDisplay(), imageWrapper.createImageData(uncompressedData));
+ ShowImageShell.this.shell.addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent e) {
+ e.gc.drawImage(image, 0, 0);
+ }
+ });
+ ShowImageShell.this.shell.redraw();
+ }
+ });
+ }
+
+ private static byte[] uncompress(byte[] source) {
+ final ZipInputStream ins = new ZipInputStream(new ByteArrayInputStream(source));
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ int read = 0;
+ final byte[] buf = new byte[16192];
+ try {
+ ins.getNextEntry();
+ while ((read = ins.read(buf)) > 0) {
+ bos.write(buf, 0, read);
+ }
+ bos.flush();
+ ins.close();
+ } catch (final IOException e) {
+ // Should not happen
+ }
+ return bos.toByteArray();
+ }
+
+}

Back to the top