comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet130a.d @ 120:536e43f63c81

Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661 ===D2=== * added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements used these templates to work with strict type storage rules of dmd-2.053 * com.ibm.icu now also compilable with D2, but not tested yet * small fixes Snippet288 - shared data is in TLS ===Phobos=== * fixed critical bugs in Phobos implemention completely incorrect segfault prone fromStringz (Linux's port ruthless killer) terrible, incorrect StringBuffer realization (StyledText killer) * fixed small bugs as well Snippet72 - misprint in the snippet * implemented missed functionality for Phobos ByteArrayOutputStream implemented (image loading available) formatting correctly works for all DWT's cases As a result, folowing snippets now works with Phobos (Snippet### - what is fixed): Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting Snippet48, 282 - crash on image loading Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText Snippet244 - hang-up ===Tango=== * few changes for the latest Tango trunc-r5661 * few small performance improvments ===General=== * implMissing-s for only one version changed to implMissingInTango/InPhobos * incorrect calls to Format in toString-s fixed * fixed loading \uXXXX characters in ResourceBundle * added good UTF-8 support for StyledText, TextLayout (Win32) and friends UTF functions revised and tested. It is now in java.nonstandard.*Utf modules StyledText and TextLayout (Win32) modules revised for UTF-8 support * removed small diferences in most identical files in *.swt.* folders *.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32 now 179 of 576 (~31%) files in *.swt.* folders are fully identical * Win32: snippets now have right subsystem, pretty icons and native system style controls * small fixes in snippets Snippet44 - it's not Snippet44 Snippet212 - functions work with different images and offsets arrays Win32: Snippet282 - crash on close if the button has an image Snippet293 - setGrayed is commented and others Win32: As a result, folowing snippets now works Snippet68 - color doesn't change Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above) Snippet193 - no tabel headers
author Denis Shelomovskij <verylonglogin.reg@gmail.com>
date Sat, 09 Jul 2011 15:50:20 +0300
parents 9f4c18c268b2
children
comparison
equal deleted inserted replaced
119:d00e8db0a568 120:536e43f63c81
42 import std.conv; 42 import std.conv;
43 import std.stdio; 43 import std.stdio;
44 } 44 }
45 45
46 46
47 void main(String[] args){ 47 void main() {
48 Snippet130.main(args); 48 Display display = new Display();
49 Shell shell = new Shell(display);
50 shell.setLayout(new GridLayout());
51 Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
52 text.setLayoutData(new GridData(GridData.FILL_BOTH));
53 int[] nextId = new int[1];
54 Button b = new Button(shell, SWT.PUSH);
55 b.setText("invoke long running job");
56
57 b.addSelectionListener(new class SelectionAdapter {
58 public void widgetSelected(SelectionEvent e) {
59 Runnable longJob = new class Runnable {
60 bool done = false;
61 int id;
62 public void run() {
63 Thread thread = new Thread({
64 id = nextId[0]++;
65 display.syncExec( dgRunnable( &printStart, text, id ));
66 for (int i = 0; i < 6; i++) {
67 if (display.isDisposed()) return;
68 version(Tango){
69 Trace.formatln("do task that takes a long time in a separate thread {} {}/6", id, i);
70 } else { // Phobos
71 writefln("do task that takes a long time in a separate thread %s %s/6", id, i);
72 }
73 Thread.sleep(500);
74 }
75 /*
76 for (int i = 0; i < 100000; i++) {
77 if (display.isDisposed()) return;
78 Stdout.formatln("do task that takes a long time in a separate thread {}", id);
79 }
80 */
81 if (display.isDisposed()) return;
82 display.syncExec( dgRunnable( &printEnd, text, id ));
83 done = true;
84 display.wake();
85 }); // thread = ...
86 thread.start();
87
88 while (!done && !shell.isDisposed()) {
89 if (!display.readAndDispatch())
90 display.sleep();
91 }
92 }
93 }; // Runnable longJob = ...
94 BusyIndicator.showWhile(display, longJob);
95 } // widgetSelected();
96 }); // addSelectionListener
97
98
99 shell.setSize(250, 150);
100 shell.open();
101 while (!shell.isDisposed()) {
102 if (!display.readAndDispatch())
103 display.sleep();
104 }
105 display.dispose();
49 } 106 }
50 107
51 public class Snippet130 { 108 void printStart(Text text, int id ) {
109 if (text.isDisposed()) return;
110 version(Tango){
111 Trace.formatln( "Start long running task {}", id );
112 } else { // Phobos
113 writefln( "Start long running task %s", id );
114 }
115 text.append("\nStart long running task "~to!(String)(id));
116 }
52 117
53 public static void main(String[] args) { 118 void printEnd(Text text, int id ) {
54 Display display = new Display(); 119 if (text.isDisposed()) return;
55 Shell shell = new Shell(display); 120 version(Tango){
56 shell.setLayout(new GridLayout()); 121 Trace.formatln( "Completed long running task {}", id );
57 Text text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); 122 } else { // Phobos
58 text.setLayoutData(new GridData(GridData.FILL_BOTH)); 123 writefln( "Completed long running task %s", id );
59 int[] nextId = new int[1];
60 Button b = new Button(shell, SWT.PUSH);
61 b.setText("invoke long running job");
62
63 b.addSelectionListener(new class() SelectionAdapter {
64 public void widgetSelected(SelectionEvent e) {
65 Runnable longJob = new class() Runnable {
66 bool done = false;
67 int id;
68 public void run() {
69 Thread thread = new Thread({
70 id = nextId[0]++;
71 display.syncExec( dgRunnable( &printStart, text, id ));
72 for (int i = 0; i < 6; i++) {
73 if (display.isDisposed()) return;
74 version(Tango){
75 Trace.formatln("do task that takes a long time in a separate thread {} {}/6", id, i);
76 } else { // Phobos
77 writefln("do task that takes a long time in a separate thread %s %s/6", id, i);
78 }
79 Thread.sleep(500);
80 }
81 /*
82 for (int i = 0; i < 100000; i++) {
83 if (display.isDisposed()) return;
84 Stdout.formatln("do task that takes a long time in a separate thread {}", id);
85 }
86 */
87 if (display.isDisposed()) return;
88 display.syncExec( dgRunnable( &printEnd, text, id ));
89 done = true;
90 display.wake();
91 }); // thread = ...
92 thread.start();
93
94 while (!done && !shell.isDisposed()) {
95 if (!display.readAndDispatch())
96 display.sleep();
97 }
98 }
99 }; // Runnable longJob = ...
100 BusyIndicator.showWhile(display, longJob);
101 } // widgetSelected();
102 }); // addSelectionListener
103
104
105 shell.setSize(250, 150);
106 shell.open();
107 while (!shell.isDisposed()) {
108 if (!display.readAndDispatch())
109 display.sleep();
110 }
111 display.dispose();
112 } 124 }
113 private static void printStart(Text text, int id ) { 125 text.append("\nCompleted long running task "~to!(String)(id));
114 if (text.isDisposed()) return;
115 version(Tango){
116 Trace.formatln( "Start long running task {}", id );
117 } else { // Phobos
118 writefln( "Start long running task %s", id );
119 }
120 text.append("\nStart long running task "~to!(String)(id));
121 }
122 private static void printEnd(Text text, int id ) {
123 if (text.isDisposed()) return;
124 version(Tango){
125 Trace.formatln( "Completed long running task {}", id );
126 } else { // Phobos
127 writefln( "Completed long running task %s", id );
128 }
129 text.append("\nCompleted long running task "~to!(String)(id));
130 }
131 } 126 }