import com.android.ddmlib.RawImage;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.ImageTransfer;
+import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
private Button mSave;
private IDevice mDevice;
private RawImage mRawImage;
+ private Clipboard mClipboard;
/**
*/
public ScreenShotDialog(Shell parent) {
this(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ mClipboard = new Clipboard(parent.getDisplay());
}
/**
private void createContents(final Shell shell) {
GridData data;
- final int colCount = 4;
+ final int colCount = 5;
shell.setLayout(new GridLayout(colCount, true));
}
});
+ Button copy = new Button(shell, SWT.PUSH);
+ copy.setText("Copy");
+ copy.setToolTipText("Copy the screenshot to the clipboard");
+ data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
+ data.widthHint = 80;
+ copy.setLayoutData(data);
+ copy.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ copy();
+ }
+ });
+
+
// "done" button
Button done = new Button(shell, SWT.PUSH);
done.setText("Done");
}
/**
+ * Copies the content of {@link #mImageLabel} to the clipboard.
+ */
+ private void copy() {
+ mClipboard.setContents(
+ new Object[] {
+ mImageLabel.getImage().getImageData()
+ }, new Transfer[] {
+ ImageTransfer.getInstance()
+ });
+ }
+
+ /**
* Captures a new image from the device, and display it.
*/
private void updateDeviceImage(Shell shell) {
catch (IOException ioe) {
Log.w("ddms", "Unable to save " + fileName + ": " + ioe);
}
-
- if (false) {
- ImageLoader loader = new ImageLoader();
- loader.data = new ImageData[] { imageData };
- // PNG writing not available until 3.3? See bug at:
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=24697
- // GIF writing only works for 8 bits
- // JPEG uses lossy compression
- // BMP has screwed-up colors
- loader.save(fileName, SWT.IMAGE_JPEG);
- }
}
}