blob: c38a82365a112b9dd4727e0814c7c223d32787af (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.blam.operation;
import java.util.Arrays;
import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.ui.plugin.util.Displays;
import org.eclipse.osee.framework.ui.skynet.blam.AbstractBlam;
import org.eclipse.osee.framework.ui.skynet.blam.VariableMap;
import org.eclipse.osee.framework.ui.skynet.widgets.dialog.ImageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Listener;
/**
* Capture an image within the bounds of OSEE workbench.
*
* @author Donald G. Dunne
*/
public class ImageCaptureBlam extends AbstractBlam {
public Point topLeftPoint;
public Point botRightPoint;
public boolean listenerAdded = false;
@Override
public String getName() {
return "Image Capture";
}
public void runOperation(VariableMap variableMap, IProgressMonitor monitor) throws Exception {
Displays.ensureInDisplayThread(new Runnable() {
@Override
public void run() {
System.out.println("Starting Image Capture...");
topLeftPoint = null;
botRightPoint = null;
Display.getDefault().addFilter(SWT.MouseUp, displayKeysListener);
}
});
}
Listener displayKeysListener = new Listener() {
public void handleEvent(org.eclipse.swt.widgets.Event event) {
if (event.type == SWT.MouseUp) {
if (topLeftPoint == null) {
topLeftPoint = event.display.getCursorLocation();
print("\nFirst Mouse Event " + topLeftPoint + "\n");
} else {
botRightPoint = event.display.getCursorLocation();
print("Second Mouse Event " + botRightPoint + "\n");
GC gc = new GC(Display.getCurrent());
Image image =
new Image(Display.getCurrent(), botRightPoint.x - topLeftPoint.x, botRightPoint.y - topLeftPoint.y);
gc.copyArea(image, topLeftPoint.x, topLeftPoint.y);
gc.dispose();
Display.getDefault().removeFilter(SWT.MouseUp, displayKeysListener);
ImageDialog diag = new ImageDialog(image, Display.getCurrent().getActiveShell());
diag.open();
}
}
}
};
@Override
public String getXWidgetsXml() {
return "<xWidgets></xWidgets>";
}
@Override
public String getDescriptionUsage() {
return "Mouse Down on top left location, Mouse Up on bottom right. Only works within bounds of workbench window.";
}
public Collection<String> getCategories() {
return Arrays.asList("Util");
}
}
|