Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java25
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ChatComposite.java170
-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.java134
4 files changed, 14 insertions, 360 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 a30af9813..2bce1a712 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,14 +10,11 @@
*****************************************************************************/
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;
@@ -37,11 +34,12 @@ import org.eclipse.ecf.internal.example.collab.ClientPlugin;
import org.eclipse.ecf.internal.example.collab.ui.ChatLine;
import org.eclipse.ecf.internal.example.collab.ui.EditorHelper;
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.ecf.ui.screencapture.ImageWrapper;
+import org.eclipse.ecf.ui.screencapture.ScreenCaptureUtil;
+import org.eclipse.ecf.ui.screencapture.ShowImageShell;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.events.DisposeEvent;
@@ -515,25 +513,10 @@ public class EclipseCollabSharedObject extends GenericSharedObject {
}
}
- 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_START_MSG, localContainerID, localUser.getNickname(), new ImageWrapper(imageData)));
- final byte[] compressedData = compress(imageData.data);
+ final byte[] compressedData = ScreenCaptureUtil.compress(imageData.data);
final ByteArrayOutputStream bos = new ByteArrayOutputStream(MAX_MESSAGE_SIZE);
int startPos = 0;
while (startPos <= compressedData.length) {
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 c9a27844b..97b126039 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
@@ -19,7 +19,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
@@ -30,13 +29,13 @@ import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.example.collab.share.User;
import org.eclipse.ecf.example.collab.share.io.FileTransferParams;
import org.eclipse.ecf.internal.example.collab.ClientPlugin;
+import org.eclipse.ecf.ui.screencapture.IImageSender;
+import org.eclipse.ecf.ui.screencapture.ScreenCaptureJob;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -70,18 +69,12 @@ import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
-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;
-import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
@@ -89,7 +82,6 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
@@ -101,14 +93,13 @@ import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
-import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.views.IViewCategory;
import org.eclipse.ui.views.IViewDescriptor;
import org.eclipse.ui.views.IViewRegistry;
public class ChatComposite extends Composite {
private static final String CHAT_OUTPUT_FONT = "ChatFont";
- private final LineChatClientView view;
+ final LineChatClientView view;
private Color meColor = null;
private Color otherColor = null;
private Color systemColor = null;
@@ -392,156 +383,15 @@ public class ChatComposite extends Composite {
}
}
- private class ScreenCaptureJob extends UIJob {
-
- private final Color blackColor;
-
- private final Color whiteColor;
-
- private boolean isDragging = false;
-
- private int downX = -1;
-
- private int downY = -1;
-
- private final ID targetID;
-
- public ScreenCaptureJob(Display display, ID targetID) {
- super(display, "Screen capturing...");
- blackColor = new Color(display, 0, 0, 0);
- whiteColor = new Color(display, 255, 255, 255);
- this.targetID = targetID;
- }
-
- public IStatus runInUIThread(IProgressMonitor monitor) {
- final Display display = getDisplay();
- final GC context = new GC(display);
- final Image image = new Image(display, display.getBounds());
- context.copyArea(image, 0, 0);
- context.dispose();
-
- final Shell shell = new Shell(display, SWT.NO_TRIM);
- shell.setLayout(new FillLayout());
- shell.setBounds(display.getBounds());
- final GC gc = new GC(shell);
- shell.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent e) {
- gc.drawImage(image, 0, 0);
- }
- });
-
- shell.addMouseListener(new MouseAdapter() {
- public void mouseDown(MouseEvent e) {
- isDragging = true;
- downX = e.x;
- downY = e.y;
- }
-
- public void mouseUp(MouseEvent e) {
- isDragging = false;
- final int width = Math.max(downX, e.x) - Math.min(downX, e.x);
- final int height = Math.max(downY, e.y) - Math.min(downY, e.y);
- if (width != 0 && height != 0) {
- final Image copy = new Image(display, width, height);
- gc.copyArea(copy, Math.min(downX, e.x), Math.min(downY, e.y));
- shell.close();
- image.dispose();
- blackColor.dispose();
- whiteColor.dispose();
- final Dialog dialog = new ConfirmationDialog(getShell(), targetID, copy, width, height);
- dialog.open();
- }
- }
- });
-
- shell.addMouseMoveListener(new MouseMoveListener() {
- public void mouseMove(MouseEvent e) {
- if (isDragging) {
- gc.drawImage(image, 0, 0);
- gc.setForeground(blackColor);
- 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()) {
- display.sleep();
- }
- }
- return Status.OK_STATUS;
- }
- }
-
- private class ConfirmationDialog extends Dialog {
-
- private final Image image;
-
- private final int width;
-
- private final int height;
-
- private final ID targetID;
-
- private ConfirmationDialog(Shell shell, ID targetID, Image image, int width, int height) {
- super(shell);
- this.image = image;
- this.width = width;
- this.height = height;
- this.targetID = targetID;
- }
-
- protected void buttonPressed(int buttonId) {
- if (buttonId == IDialogConstants.OK_ID) {
- view.lch.sendImage(targetID, image.getImageData());
- }
- super.buttonPressed(buttonId);
- }
-
- protected Control createDialogArea(Composite parent) {
- parent = (Composite) super.createDialogArea(parent);
- final Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- composite.setLayout(new FillLayout());
- composite.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent e) {
- e.gc.drawImage(image, 0, 0);
+ private void sendImage(ID targetID) {
+ if (MessageDialog.openQuestion(null, "Screen Capture", "To initiate screen capture, click OK, wait 5 seconds,\nand then select capture region with arrow cursor.")) {
+ final Job job = new ScreenCaptureJob(getDisplay(), targetID, new IImageSender() {
+ public void sendImage(ID targetID, ImageData imageData) {
+ view.lch.sendImage(targetID, imageData);
}
});
- return parent;
+ job.schedule(5000);
}
-
- protected Point getInitialSize() {
- final Point point = super.getInitialSize();
- if (point.x < width) {
- if (point.y < height) {
- return new Point(width, height);
- } else {
- return new Point(width, point.y);
- }
- } else {
- if (point.y < height) {
- return new Point(point.x, height);
- } else {
- return new Point(point.x, point.y);
- }
- }
- }
-
- public boolean close() {
- image.dispose();
- return super.close();
- }
-
- }
-
- private void sendImage(ID targetID) {
- final Job job = new ScreenCaptureJob(getDisplay(), targetID);
- job.schedule(5000);
}
private void fillTreeContextMenuUser(IMenuManager man, final User user) {
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
deleted file mode 100644
index 10ce31792..000000000
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ImageWrapper.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 Remy Suen, 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:
- * Remy Suen <remy.suen@gmail.com> - initial API and implementation
- ******************************************************************************/
-package org.eclipse.ecf.internal.example.collab.ui;
-
-import java.io.Serializable;
-
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.PaletteData;
-
-public class ImageWrapper implements Serializable {
-
- private static final long serialVersionUID = -834839369167998998L;
-
- public final int width;
- public final int height;
- public final int depth;
- public final int scanlinePad;
-
- private final int redMask;
- private final int greenMask;
- private final int blueMask;
-
- public ImageWrapper(ImageData data) {
- width = data.width;
- height = data.height;
- depth = data.depth;
- scanlinePad = data.scanlinePad;
- redMask = data.palette.redMask;
- greenMask = data.palette.greenMask;
- blueMask = data.palette.blueMask;
- }
-
- public ImageData createImageData(byte[] data) {
- final PaletteData palette = new PaletteData(redMask, greenMask, blueMask);
- 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
deleted file mode 100644
index 4f610153e..000000000
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/ShowImageShell.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/****************************************************************************
- * 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 void close() {
- if (shell != null) {
- shell.getDisplay().asyncExec(new Runnable() {
- public void run() {
- try {
- if (!shell.isDisposed())
- shell.close();
- shell = null;
- } catch (final Exception e) {
- // do nothing
- }
- }
- });
- }
- }
-
- 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