comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet222.d @ 112:9f4c18c268b2

Update to compile and execute with dmd 2.052.
author kntroh
date Wed, 16 Mar 2011 21:53:53 +0900
parents 4e5843b771cc
children 536e43f63c81
comparison
equal deleted inserted replaced
111:b6e9904989ed 112:9f4c18c268b2
37 import org.eclipse.swt.widgets.Listener; 37 import org.eclipse.swt.widgets.Listener;
38 import org.eclipse.swt.graphics.FontData; 38 import org.eclipse.swt.graphics.FontData;
39 import org.eclipse.swt.graphics.Font; 39 import org.eclipse.swt.graphics.Font;
40 import org.eclipse.swt.graphics.TextLayout; 40 import org.eclipse.swt.graphics.TextLayout;
41 import org.eclipse.swt.graphics.GlyphMetrics; 41 import org.eclipse.swt.graphics.GlyphMetrics;
42 import tango.text.Text; 42 version(Tango){
43 alias Text!(char) StringBuffer; 43 import tango.util.Convert;
44 import tango.util.Convert; 44 } else { // Phobos
45 import std.conv;
46 }
45 47
46 import java.lang.all; 48 import java.lang.all;
47 version(JIVE){ 49 version(JIVE){
48 import jive.stacktrace; 50 import jive.stacktrace;
49 } 51 }
54 shell.setText("StyledText Bullet Example"); 56 shell.setText("StyledText Bullet Example");
55 shell.setLayout(new FillLayout()); 57 shell.setLayout(new FillLayout());
56 StyledText styledText = new StyledText (shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); 58 StyledText styledText = new StyledText (shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
57 StringBuffer text = new StringBuffer(); 59 StringBuffer text = new StringBuffer();
58 text.append("Here is StyledText with some bulleted lists:\n\n"); 60 text.append("Here is StyledText with some bulleted lists:\n\n");
59 for (int i = 0; i < 4; i++) text.append("Red Bullet List Item " ~ to!(char[])(i) ~ "\n"); 61 for (int i = 0; i < 4; i++) text.append("Red Bullet List Item " ~ to!(String)(i) ~ "\n");
60 text.append("\n"); 62 text.append("\n");
61 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(char[])(i) ~ "\n"); 63 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(String)(i) ~ "\n");
62 for (int i = 0; i < 4; i++) text.append("Sub List Item " ~ to!(char[])(i) ~ "\n"); 64 for (int i = 0; i < 4; i++) text.append("Sub List Item " ~ to!(String)(i) ~ "\n");
63 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(char[])(2+i) ~ "\n"); 65 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(String)(2+i) ~ "\n");
64 text.append("\n"); 66 text.append("\n");
65 for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " ~ to!(char[])(i) ~ "\n"); 67 for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " ~ to!(String)(i) ~ "\n");
66 styledText.setText(text.toString()); 68 styledText.setText(text.toString());
67 69
68 StyleRange style0 = new StyleRange(); 70 StyleRange style0 = new StyleRange();
69 style0.metrics = new GlyphMetrics(0, 0, 40); 71 style0.metrics = new GlyphMetrics(0, 0, 40);
70 style0.foreground = display.getSystemColor(SWT.COLOR_RED); 72 style0.foreground = display.getSystemColor(SWT.COLOR_RED);
97 if (font is null) font = styledText.getFont(); 99 if (font is null) font = styledText.getFont();
98 TextLayout layout = new TextLayout(display); 100 TextLayout layout = new TextLayout(display);
99 layout.setAscent(event.ascent); 101 layout.setAscent(event.ascent);
100 layout.setDescent(event.descent); 102 layout.setDescent(event.descent);
101 layout.setFont(font); 103 layout.setFont(font);
102 layout.setText("\u2023 1." ~ to!(char[])( event.bulletIndex) ~ ")"); 104 layout.setText("\u2023 1." ~ to!(String)( event.bulletIndex) ~ ")");
103 layout.draw(event.gc, event.x + 10, event.y); 105 layout.draw(event.gc, event.x + 10, event.y);
104 layout.dispose(); 106 layout.dispose();
105 } 107 }
106 }); 108 });
107 shell.open(); 109 shell.open();