|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2022 IBM Corporation and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * IBM Corporation - initial API and implementation |
| 13 | + *******************************************************************************/ |
| 14 | +package org.eclipse.swt.tests.win32.snippets; |
| 15 | + |
| 16 | +import java.util.ArrayList; |
| 17 | +import java.util.List; |
| 18 | + |
| 19 | +import org.eclipse.swt.SWT; |
| 20 | +import org.eclipse.swt.graphics.Image; |
| 21 | +import org.eclipse.swt.graphics.ImageData; |
| 22 | +import org.eclipse.swt.program.Program; |
| 23 | +import org.eclipse.swt.widgets.Display; |
| 24 | +import org.eclipse.swt.widgets.Shell; |
| 25 | + |
| 26 | +public class SWTIssue185 { |
| 27 | + |
| 28 | + public static void main(String[] args) { |
| 29 | + final Display display = new Display(); |
| 30 | + |
| 31 | + final List<Image> images = createImages(display, "zip", "jpg", "txt", "pdf", "png", "msi", "theme"); |
| 32 | + |
| 33 | + final Shell shell = new Shell(display); |
| 34 | + |
| 35 | + shell.addListener(SWT.Paint, event -> { |
| 36 | + int x = 0; |
| 37 | + for (Image image : images) { |
| 38 | + event.gc.drawImage(image, x, 0); |
| 39 | + x += image.getImageData().width; |
| 40 | + x += 10; |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + shell.setSize(400, 300); |
| 45 | + shell.open(); |
| 46 | + |
| 47 | + while (!shell.isDisposed()) { |
| 48 | + if (!display.readAndDispatch()) { |
| 49 | + display.sleep(); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + for (Image image : images) { |
| 54 | + image.dispose(); |
| 55 | + } |
| 56 | + |
| 57 | + display.dispose(); |
| 58 | + } |
| 59 | + |
| 60 | + private static List<Image> createImages(Display display, String... extensions) { |
| 61 | + final List<Image> images = new ArrayList<>(); |
| 62 | + for (String extension : extensions) { |
| 63 | + final Program program = Program.findProgram(extension); |
| 64 | + if (program == null) { |
| 65 | + continue; |
| 66 | + } |
| 67 | + final ImageData data = program.getImageData(); |
| 68 | + if (data == null) { |
| 69 | + continue; |
| 70 | + } |
| 71 | + images.add(new Image(display, data)); |
| 72 | + } |
| 73 | + return images; |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments