Mercurial > projects > dwt2
comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet288.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 8ae65ae167f5 |
children | 536e43f63c81 |
comparison
equal
deleted
inserted
replaced
111:b6e9904989ed | 112:9f4c18c268b2 |
---|---|
29 import org.eclipse.swt.widgets.ToolItem; | 29 import org.eclipse.swt.widgets.ToolItem; |
30 import org.eclipse.swt.widgets.FileDialog; | 30 import org.eclipse.swt.widgets.FileDialog; |
31 | 31 |
32 import java.lang.all; | 32 import java.lang.all; |
33 | 33 |
34 import tango.io.FilePath; | 34 version(Tango){ |
35 import tango.io.model.IFile; | 35 import tango.io.FilePath; |
36 //import tango.core.Thread; | 36 import tango.io.model.IFile; |
37 import tango.io.Stdout; | 37 //import tango.core.Thread; |
38 import tango.util.Convert; | 38 import tango.io.Stdout; |
39 import tango.core.Exception; | 39 import tango.util.Convert; |
40 import tango.core.Exception; | |
41 } else { // Phobos | |
42 import std.path; | |
43 import std.stream; | |
44 import std.stdio; | |
45 import std.conv; | |
46 import core.exception; | |
47 import core.thread : ThreadException; | |
48 struct FileConst { | |
49 static const PathSeparatorChar = sep; | |
50 } | |
51 } | |
40 | 52 |
41 static Display display; | 53 static Display display; |
42 static Shell shell; | 54 static Shell shell; |
43 static GC shellGC; | 55 static GC shellGC; |
44 static Color shellBackground; | 56 static Color shellBackground; |
45 static ImageLoader[] loader; | 57 static ImageLoader[] loader; |
46 static ImageData[][] imageDataArray; | 58 static ImageData[][] imageDataArray; |
47 static Thread[] animateThread; | 59 static Thread[] animateThread; |
48 static Image[][] image; | 60 static Image[][] image; |
49 private static ToolItem[] item; | 61 private static ToolItem[] item; |
50 static final bool useGIFBackground = false; | 62 static const bool useGIFBackground = false; |
51 | 63 |
52 void main () { | 64 void main () { |
53 display = new Display(); | 65 display = new Display(); |
54 Shell shell = new Shell (display); | 66 Shell shell = new Shell (display); |
55 shellBackground = shell.getBackground(); | 67 shellBackground = shell.getBackground(); |
56 FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); | 68 FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); |
57 dialog.setText("Select Multiple Animated GIFs"); | 69 dialog.setText("Select Multiple Animated GIFs"); |
58 dialog.setFilterExtensions(["*.gif"]); | 70 dialog.setFilterExtensions(["*.gif"]); |
59 char[] filename = dialog.open(); | 71 String filename = dialog.open(); |
60 char[][] filenames = dialog.getFileNames(); | 72 String[] filenames = dialog.getFileNames(); |
61 int numToolBarItems = filenames.length; | 73 int numToolBarItems = filenames.length; |
62 if (numToolBarItems > 0) { | 74 if (numToolBarItems > 0) { |
63 try { | 75 version(Tango){ |
64 loadAllImages((new FilePath(filename)).parent, filenames); | 76 try { |
65 } catch (SWTException e) { | 77 loadAllImages((new FilePath(filename)).parent, filenames); |
66 Stdout.print("There was an error loading an image.").newline; | 78 } catch (SWTException e) { |
67 e.printStackTrace(); | 79 Stdout.print("There was an error loading an image.").newline; |
80 e.printStackTrace(); | |
81 } | |
82 } else { // Phobos | |
83 try { | |
84 loadAllImages(filename.getDirName, filenames); | |
85 } catch (SWTException e) { | |
86 writeln("There was an error loading an image."); | |
87 e.printStackTrace(); | |
88 } | |
68 } | 89 } |
69 ToolBar toolBar = new ToolBar (shell, SWT.FLAT | SWT.BORDER | SWT.WRAP); | 90 ToolBar toolBar = new ToolBar (shell, SWT.FLAT | SWT.BORDER | SWT.WRAP); |
70 item = new ToolItem[numToolBarItems]; | 91 item = new ToolItem[numToolBarItems]; |
71 for (int i = 0; i < numToolBarItems; i++) { | 92 for (int i = 0; i < numToolBarItems; i++) { |
72 item[i] = new ToolItem (toolBar, SWT.PUSH); | 93 item[i] = new ToolItem (toolBar, SWT.PUSH); |
89 display.dispose (); | 110 display.dispose (); |
90 } | 111 } |
91 Thread.joinAll(); | 112 Thread.joinAll(); |
92 } | 113 } |
93 | 114 |
94 private static void loadAllImages(char[] directory, char[][] filenames) { | 115 private static void loadAllImages(String directory, String[] filenames) { |
95 int numItems = filenames.length; | 116 int numItems = filenames.length; |
96 loader.length = numItems; | 117 loader.length = numItems; |
97 imageDataArray.length = numItems; | 118 imageDataArray.length = numItems; |
98 image.length = numItems; | 119 image.length = numItems; |
99 for (int i = 0; i < numItems; i++) { | 120 for (int i = 0; i < numItems; i++) { |
196 | 217 |
197 /* If we have just drawn the last image, decrement the repeat count and start again. */ | 218 /* If we have just drawn the last image, decrement the repeat count and start again. */ |
198 if (imageDataIndex == imageDataArray[id].length - 1) repeatCount--; | 219 if (imageDataIndex == imageDataArray[id].length - 1) repeatCount--; |
199 } | 220 } |
200 } catch (SWTException ex) { | 221 } catch (SWTException ex) { |
201 Stdout.print("There was an error animating the GIF").newline; | 222 version(Tango){ |
223 Stdout.print("There was an error animating the GIF").newline; | |
224 } else { // Phobos | |
225 writeln("There was an error animating the GIF"); | |
226 } | |
202 ex.printStackTrace(); | 227 ex.printStackTrace(); |
203 } | 228 } |
204 } | 229 } |
205 }; | 230 }; |
206 animateThread[ii].start(); | 231 animateThread[ii].start(); |