use of org.eclipse.swt.graphics.PaletteData in project tdi-studio-se by Talend.
the class InsertionIndicator method addListeners.
/**
* DOC amaumont Comment method "addListeners".
*/
private void addListeners() {
Listener paintListener = new Listener() {
public void handleEvent(Event event) {
Composite composite = (Composite) event.widget;
Rectangle bounds = composite.getBounds();
// //////////////////////////////////////////////////////////
// draw image filled with transparent pixels
RGB transparentColor = new RGB(0, 255, 0);
PaletteData paletteData = new PaletteData(new RGB[] { transparentColor });
ImageData imageData = new ImageData(bounds.width, bounds.height, 1, paletteData);
int transparentPixelValue = imageData.palette.getPixel(transparentColor);
imageData.transparentPixel = transparentPixelValue;
GC gc = event.gc;
final Image image = new Image(gc.getDevice(), imageData);
gc.drawImage(image, 0, 0);
image.dispose();
// ////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////
// draw left arrow
int yCenter = bounds.height / 2;
int widthExternalArrow = 10;
gc.setBackground(colorIndicator);
gc.setForeground(colorIndicator);
if (composite == leftArrowDraggingIndicator) {
// external left arrow
Point leftCrossPoint = new Point(widthExternalArrow, yCenter);
gc.fillPolygon(new int[] { 0, 0, leftCrossPoint.x, leftCrossPoint.y, 0, bounds.height });
gc.drawLine(leftCrossPoint.x, leftCrossPoint.y, bounds.width, leftCrossPoint.y);
} else {
// external right arrow
Point rightCrossPoint = new Point(bounds.width - widthExternalArrow, yCenter);
gc.fillPolygon(new int[] { bounds.width, 0, rightCrossPoint.x, rightCrossPoint.y, bounds.width, bounds.height });
gc.drawLine(rightCrossPoint.x, rightCrossPoint.y, -bounds.width, rightCrossPoint.y);
}
}
};
leftArrowDraggingIndicator.addListener(SWT.Paint, paintListener);
rightArrowDraggingIndicator.addListener(SWT.Paint, paintListener);
}
use of org.eclipse.swt.graphics.PaletteData in project eclipse.platform.swt by eclipse.
the class CTable method initImages.
static void initImages(final Display display) {
PaletteData arrowPalette = new PaletteData(new RGB(0, 0, 0), new RGB(255, 255, 255));
if (display.getData(ID_ARROWDOWN) == null) {
ImageData arrowDown = new ImageData(7, 4, 1, arrowPalette, 1, new byte[] { 0x00, (byte) 0x83, (byte) 0xC7, (byte) 0xEF });
arrowDown.transparentPixel = 0x1;
/* use white for transparency */
display.setData(ID_ARROWDOWN, new Image(display, arrowDown));
}
if (display.getData(ID_ARROWUP) == null) {
ImageData arrowUp = new ImageData(7, 4, 1, arrowPalette, 1, new byte[] { (byte) 0xEF, (byte) 0xC7, (byte) 0x83, 0x00 });
arrowUp.transparentPixel = 0x1;
/* use white for transparency */
display.setData(ID_ARROWUP, new Image(display, arrowUp));
}
PaletteData checkMarkPalette = new PaletteData(new RGB(0, 0, 0), new RGB(252, 3, 251));
byte[] checkbox = new byte[] { 0, 0, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 0, 0 };
ImageData checkmark = new ImageData(7, 7, 1, checkMarkPalette, 1, new byte[] { -4, -8, 112, 34, 6, -114, -34 });
checkmark.transparentPixel = 1;
if (display.getData(ID_CHECKMARK) == null) {
display.setData(ID_CHECKMARK, new Image(display, checkmark));
}
if (display.getData(ID_UNCHECKED) == null) {
PaletteData uncheckedPalette = new PaletteData(new RGB(128, 128, 128), new RGB(255, 255, 255));
ImageData unchecked = new ImageData(11, 11, 1, uncheckedPalette, 2, checkbox);
display.setData(ID_UNCHECKED, new Image(display, unchecked));
}
if (display.getData(ID_GRAYUNCHECKED) == null) {
PaletteData grayUncheckedPalette = new PaletteData(new RGB(128, 128, 128), new RGB(192, 192, 192));
ImageData grayUnchecked = new ImageData(11, 11, 1, grayUncheckedPalette, 2, checkbox);
display.setData(ID_GRAYUNCHECKED, new Image(display, grayUnchecked));
}
display.disposeExec(() -> {
Image unchecked = (Image) display.getData(ID_UNCHECKED);
if (unchecked != null)
unchecked.dispose();
Image grayUnchecked = (Image) display.getData(ID_GRAYUNCHECKED);
if (grayUnchecked != null)
grayUnchecked.dispose();
Image checkmark1 = (Image) display.getData(ID_CHECKMARK);
if (checkmark1 != null)
checkmark1.dispose();
Image arrowDown = (Image) display.getData(ID_ARROWDOWN);
if (arrowDown != null)
arrowDown.dispose();
Image arrowUp = (Image) display.getData(ID_ARROWUP);
if (arrowUp != null)
arrowUp.dispose();
display.setData(ID_UNCHECKED, null);
display.setData(ID_GRAYUNCHECKED, null);
display.setData(ID_CHECKMARK, null);
display.setData(ID_ARROWDOWN, null);
display.setData(ID_ARROWUP, null);
});
}
use of org.eclipse.swt.graphics.PaletteData in project knime-core by knime.
the class KNIMECTabFolderRenderer method blur.
public ImageData blur(final Image src, final int radius, final int sigma) {
float[] kernel = create1DKernel(radius, sigma);
ImageData imgPixels = src.getImageData();
int width = imgPixels.width;
int height = imgPixels.height;
int[] inPixels = new int[width * height];
int[] outPixels = new int[width * height];
int offset = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
RGB rgb = imgPixels.palette.getRGB(imgPixels.getPixel(x, y));
if (rgb.red == 255 && rgb.green == 255 && rgb.blue == 255) {
inPixels[offset] = (rgb.red << 16) | (rgb.green << 8) | rgb.blue;
} else {
inPixels[offset] = (imgPixels.getAlpha(x, y) << 24) | (rgb.red << 16) | (rgb.green << 8) | rgb.blue;
}
offset++;
}
}
convolve(kernel, inPixels, outPixels, width, height, true);
convolve(kernel, outPixels, inPixels, height, width, true);
ImageData dst = new ImageData(imgPixels.width, imgPixels.height, 24, new PaletteData(0xff0000, 0xff00, 0xff));
dst.setPixels(0, 0, inPixels.length, inPixels, 0);
offset = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (inPixels[offset] == -1) {
dst.setAlpha(x, y, 0);
} else {
int a = (inPixels[offset] >> 24) & 0xff;
// if (a < 150) a = 0;
dst.setAlpha(x, y, a);
}
offset++;
}
}
return dst;
}
use of org.eclipse.swt.graphics.PaletteData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_GC method test_copyAreaLorg_eclipse_swt_graphics_ImageII.
@Test
public void test_copyAreaLorg_eclipse_swt_graphics_ImageII() {
Color white = display.getSystemColor(SWT.COLOR_WHITE);
Color blue = display.getSystemColor(SWT.COLOR_BLUE);
RGB whiteRGB = getRealRGB(white);
RGB blueRGB = getRealRGB(blue);
gc.setBackground(white);
gc.fillRectangle(image.getBounds());
gc.setBackground(blue);
gc.fillRectangle(5, 0, 6, 1);
Image image = new Image(display, 12, 12);
gc.copyArea(image, 0, 0);
ImageData imageData = image.getImageData();
PaletteData palette = imageData.palette;
if (DPIUtil.getDeviceZoom() != 100) {
// TODO Fix non integer scaling factors.
if (SwtTestUtil.verbose) {
System.out.println("Excluded test_copyAreaLorg_eclipse_swt_graphics_ImageII(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_graphics_GC)");
}
image.dispose();
return;
}
int pixel = imageData.getPixel(4, 0);
assertEquals(":a:", whiteRGB, palette.getRGB(pixel));
pixel = imageData.getPixel(5, 0);
assertEquals(":b:", blueRGB, palette.getRGB(pixel));
pixel = imageData.getPixel(10, 0);
assertEquals(":c:", blueRGB, palette.getRGB(pixel));
pixel = imageData.getPixel(11, 0);
assertEquals(":d:", whiteRGB, palette.getRGB(pixel));
image.dispose();
}
use of org.eclipse.swt.graphics.PaletteData in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_graphics_GC method test_drawImageLorg_eclipse_swt_graphics_ImageIIIIIIII.
@Test
public void test_drawImageLorg_eclipse_swt_graphics_ImageIIIIIIII() {
Color c1 = new Color(display, 255, 0, 0);
Color c2 = new Color(display, 0, 0, 0);
Color c3 = new Color(display, 255, 255, 0);
PaletteData paletteData = new PaletteData(c1.getRGB(), c2.getRGB(), c3.getRGB());
ImageData data = new ImageData(30, 30, 8, paletteData);
for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
if (x > y)
data.setPixel(x, y, paletteData.getPixel(c1.getRGB()));
else if (x < y)
data.setPixel(x, y, paletteData.getPixel(c2.getRGB()));
else
data.setPixel(x, y, paletteData.getPixel(c3.getRGB()));
}
}
Image image = new Image(display, data);
data = image.getImageData();
data.transparentPixel = paletteData.getPixel(c1.getRGB());
Image imageTransparent = new Image(display, data);
data.transparentPixel = -1;
for (int y = 0; y < data.height; y++) {
for (int x = 0; x < data.width; x++) {
data.setAlpha(x, y, 127);
}
}
Image imageAlpha = new Image(display, data);
gc.drawImage(image, 10, 5, 20, 15, 100, 120, 50, 60);
gc.drawImage(imageTransparent, 10, 5, 20, 15, 100, 120, 10, 10);
gc.drawImage(imageAlpha, 10, 5, 20, 15, 100, 120, 20, 15);
try {
gc.drawImage(null, 10, 5, 20, 15, 100, 120, 50, 60);
// should never get here
fail("No exception thrown");
} catch (IllegalArgumentException e) {
}
image.dispose();
imageAlpha.dispose();
imageTransparent.dispose();
c1.dispose();
c2.dispose();
c3.dispose();
}
Aggregations