use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.
the class WindowsImageTransfer method nativeToJava.
protected Object nativeToJava(TransferData transferData) {
final Object o = super.nativeToJava(transferData);
final byte[] bytes = (byte[]) o;
try {
final InputStream bis = new PrependWinBMPHeaderFilterInputStream(new UncompressDibFilterInputStream(new ByteArrayInputStream(bytes)));
final ImageData[] data = new ImageLoader().load(bis);
if (data.length < 1) {
return null;
}
return data[0];
} catch (IOException e) {
return null;
}
}
use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.
the class WindowsImageTransfer method javaToNative.
protected void javaToNative(Object object, TransferData transferData) {
final ImageData imgData = (ImageData) object;
final ImageLoader loader = new ImageLoader();
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final byte[] bytes;
loader.data = new ImageData[] { imgData };
loader.save(new RemoveWinBMPHeaderFilterOutputStream(bos), SWT.IMAGE_BMP);
bytes = bos.toByteArray();
super.javaToNative(bytes, transferData);
}
use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.
the class GraphicalWidgetBase method regenerateCaches.
protected void regenerateCaches(final int width, final int height) {
// For performance reasons, we defer regeneration until we exit fast mode
if (!this.fast) {
if (View.isDrawingOK()) {
// Recompute the cached data in the background
// new Thread () {
// public void run() {
boolean needsRepaint = false;
// Recompute the midground cache if it is dirty
if (cachedMidgroundDirty) {
needsRepaint = true;
if ((width == 0) || (height == 0)) {
throw new IllegalArgumentException("Width or Height on a widget is 0. This " + "should have been prevented in setShape " + "Size");
}
// Create a temporary canvas on which to draw the midground
Image img = new Image(null, width, height);
GC gc = new GC(img);
SWTGraphics g = new SWTGraphics(gc);
g.setAntialias(SWT.OFF);
// Use the renderer & clipper to paint the midground nicely
g.setBackgroundColor(getSelectionColor());
renderer.paintMidground(g);
// value.
if (OSUtils.WINDOWS) {
ImageData id = img.getImageData();
id.alpha = displayAlpha.determineAlpha(false);
img.dispose();
img = new Image(null, id);
}
// WARNING: this might dispose img, or it might return it
// DO NOT DISPOSE img!
Image newFG = clipper.clip(img);
// Clean the cache
cachedMidgroundDirty = false;
cachedMidground.dispose();
cachedMidground = newFG;
// cachedMidgroundData = newFG.getImageData();
// Dispose of temporary resources
// newFG.dispose();
g.dispose();
gc.dispose();
}
// Recompute the background cache if it is dirty
if (cachedBackgroundDirty) {
needsRepaint = true;
Image newBG = null;
// Check if background is present
byte[] bgImageData = model.getImage();
if (bgImageData != null) {
ImageData bg = new ImageData(new ByteArrayInputStream(bgImageData));
newBG = clipper.clip(new Image(null, bg.scaledTo(width, height)));
}
// Clean the cache
cachedBackgroundDirty = false;
if (cachedBackground != null) {
cachedBackground.dispose();
}
cachedBackground = newBG;
}
// Make sure the results of our update are shown
if (needsRepaint && View.isDrawingOK()) {
// WindowUtil.globalDisplay.syncExec(
// new Runnable() {
// public void run() {
repaint();
// }
// }
// );
}
// }
// }.start();
}
}
}
use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.
the class GraphicalWidgetBase method updateImage.
public synchronized void updateImage() {
// Mark the caches as dirty so that no one will use them
synchronized (this.flagLock) {
this.cachedBackgroundDirty = true;
}
// Confirm that the image is readable (throws an exception if it is not)
if (model.getImage() != null) {
new ImageData(new ByteArrayInputStream(model.getImage()));
}
this.renderer.updateData();
regenerateCaches();
}
use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.
the class WindowUtil method getOpenHandCursor.
/**
* Returns a hand cursor.
*
* IMPORTANT: this cursor must be disposed when its creator is disposed,
* or we will have a memory link.
*
* @return a hew hand cursor
*/
public static Cursor getOpenHandCursor() {
if (OPEN_HAND_CURSOR == null) {
ImageData curData = GraphicsUtil.getImageDataFromResource("edu/cmu/cs/hcii/cogtool/resources/open_hand.gif");
if (curData == null) {
return null;
}
OPEN_HAND_CURSOR = new Cursor(GLOBAL_DISPLAY, curData, 8, 8);
}
return OPEN_HAND_CURSOR;
}
Aggregations