use of org.eclipse.swt.graphics.ImageData in project yyl_example by Relucent.
the class ImageCanvasTest method main.
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
ImageViewer ic = new ImageViewer(shell);
shell.setLayout(new FillLayout());
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setText("Open an image file or cancel");
String string = dialog.open();
ImageLoader loader = new ImageLoader();
ImageData[] imageDatas = loader.load(string);
if (imageDatas.length == 0)
return;
else if (imageDatas.length == 1) {
ic.setImage(imageDatas[0]);
} else {
ic.setImages(imageDatas, loader.repeatCount);
}
ic.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
use of org.eclipse.swt.graphics.ImageData in project tdi-studio-se by Talend.
the class IconSelectionController method createCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
*/
public Command createCommand(Button button) {
Object data = button.getData(NAME);
if (data != null) {
if (ICON_SELECTION.equals(data)) {
FileDialog dial = new FileDialog(composite.getShell(), SWT.NONE);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dial.setFilterExtensions(new String[] { "*.jpg", "*.png", "*.gif" });
String propertyName = (String) button.getData(PARAMETER_NAME);
String file = dial.open();
if (file != null) {
if (!file.equals("")) {
//$NON-NLS-1$
if (!elem.getPropertyValue(propertyName).equals(file)) {
ImageData imageData = new ImageData(file);
if (ImageUtils.checkSize(ImageDescriptor.createFromImageData(imageData), ImageUtils.ICON_SIZE.ICON_32)) {
if (elem instanceof IProcess2) {
refreshIcon(imageData);
return new IconSelectionCommand((IProcess2) elem, ImageDescriptor.createFromImageData(imageData), file);
}
} else {
MessageDialog.openError(composite.getShell(), //$NON-NLS-1$
Messages.getString("IconSelectionController.MessageTitle"), //$NON-NLS-1$
Messages.getString("IconSelectionController.Messages"));
}
}
}
}
} else if (ICON_REVERT.equals(data)) {
if (elem instanceof IProcess2) {
Image defaultIcon = RepositoryLabelProvider.getDefaultJobletImage(((IProcess2) elem).getProperty().getItem());
ImageDescriptor imageData = ImageDescriptor.createFromImage(defaultIcon);
refreshIcon(defaultIcon.getImageData());
return new IconSelectionCommand((IProcess2) elem, imageData, null);
}
}
}
return null;
}
use of org.eclipse.swt.graphics.ImageData 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.ImageData in project tdi-studio-se by Talend.
the class AttributeLabelProvider method getAttributeImage.
/**
* Gets the attribute image.
*
* @return The attribute image
*/
private Image getAttributeImage() {
if (attributeImage == null || attributeImage.isDisposed()) {
ImageData imageData = Activator.getImageDescriptor(ISharedImages.ATTRIBUTE_IMG_PATH).getImageData();
attributeImage = new OverlayImageDescriptor(imageData, new ImageDescriptor[0], new Point(IMAGE_WIDTH, IMAGE_HEIGHT)).createImage();
}
return attributeImage;
}
use of org.eclipse.swt.graphics.ImageData in project tdi-studio-se by Talend.
the class ColorController method setButtonColor.
/**
* yzhang Comment method "resetButtonColor".
*
* @param colorBtn
* @param value
*/
private void setButtonColor(Button colorBtn, RGB rgb) {
if (colorBtn.getImage() != null) {
colorBtn.getImage().dispose();
}
ImageData id = createColorImage(colorBtn, rgb);
Image image = new Image(colorBtn.getDisplay(), id, id.getTransparencyMask());
addResourceDisposeListener(colorBtn, image);
colorBtn.setImage(image);
}
Aggregations