Mercurial > projects > dwt2
annotate 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 |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * yidabu at gmail dot com ( D China http://www.d-programming-language-china.org/ ) | |
12 *******************************************************************************/ | |
13 | |
14 module org.eclipse.swt.snippets.Snippet222; | |
15 /* | |
16 * example snippet: StyledText bulleted list example | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.2 | |
22 */ | |
23 | |
24 import org.eclipse.swt.SWT; | |
25 import org.eclipse.swt.custom.StyledText; | |
26 import org.eclipse.swt.custom.StyleRange; | |
27 import org.eclipse.swt.custom.PaintObjectEvent; | |
28 import org.eclipse.swt.custom.PaintObjectListener; | |
29 import org.eclipse.swt.custom.Bullet; | |
30 import org.eclipse.swt.custom.ST; | |
31 import org.eclipse.swt.layout.GridData; | |
32 import org.eclipse.swt.layout.FillLayout; | |
33 import org.eclipse.swt.widgets.Display; | |
34 import org.eclipse.swt.widgets.Shell; | |
35 import org.eclipse.swt.widgets.Button; | |
36 import org.eclipse.swt.widgets.Event; | |
37 import org.eclipse.swt.widgets.Listener; | |
38 import org.eclipse.swt.graphics.FontData; | |
39 import org.eclipse.swt.graphics.Font; | |
40 import org.eclipse.swt.graphics.TextLayout; | |
41 import org.eclipse.swt.graphics.GlyphMetrics; | |
112 | 42 version(Tango){ |
43 import tango.util.Convert; | |
44 } else { // Phobos | |
45 import std.conv; | |
46 } | |
28 | 47 |
48 import java.lang.all; | |
49 version(JIVE){ | |
50 import jive.stacktrace; | |
51 } | |
52 | |
53 void main() { | |
54 Display display = new Display(); | |
55 Shell shell = new Shell(display); | |
56 shell.setText("StyledText Bullet Example"); | |
57 shell.setLayout(new FillLayout()); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
58 StyledText styledText = new StyledText (shell, SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); |
28 | 59 StringBuffer text = new StringBuffer(); |
60 text.append("Here is StyledText with some bulleted lists:\n\n"); | |
112 | 61 for (int i = 0; i < 4; i++) text.append("Red Bullet List Item " ~ to!(String)(i) ~ "\n"); |
28 | 62 text.append("\n"); |
112 | 63 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(String)(i) ~ "\n"); |
64 for (int i = 0; i < 4; i++) text.append("Sub List Item " ~ to!(String)(i) ~ "\n"); | |
65 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(String)(2+i) ~ "\n"); | |
28 | 66 text.append("\n"); |
112 | 67 for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " ~ to!(String)(i) ~ "\n"); |
28 | 68 styledText.setText(text.toString()); |
69 | |
70 StyleRange style0 = new StyleRange(); | |
71 style0.metrics = new GlyphMetrics(0, 0, 40); | |
72 style0.foreground = display.getSystemColor(SWT.COLOR_RED); | |
73 Bullet bullet0 = new Bullet (style0); | |
74 StyleRange style1 = new StyleRange(); | |
75 style1.metrics = new GlyphMetrics(0, 0, 50); | |
76 style1.foreground = display.getSystemColor(SWT.COLOR_BLUE); | |
77 Bullet bullet1 = new Bullet (ST.BULLET_NUMBER | ST.BULLET_TEXT, style1); | |
78 bullet1.text = "."; | |
79 StyleRange style2 = new StyleRange(); | |
80 style2.metrics = new GlyphMetrics(0, 0, 80); | |
81 style2.foreground = display.getSystemColor(SWT.COLOR_GREEN); | |
82 Bullet bullet2 = new Bullet (ST.BULLET_TEXT, style2); | |
83 bullet2.text = "\u2713"; | |
84 StyleRange style3 = new StyleRange(); | |
85 style3.metrics = new GlyphMetrics(0, 0, 50); | |
86 Bullet bullet3 = new Bullet (ST.BULLET_CUSTOM, style2); | |
87 | |
88 styledText.setLineBullet(2, 4, bullet0); | |
89 styledText.setLineBullet(7, 2, bullet1); | |
90 styledText.setLineBullet(9, 4, bullet2); | |
91 styledText.setLineBullet(13, 2, bullet1); | |
92 styledText.setLineBullet(16, 4, bullet3); | |
93 | |
94 styledText.addPaintObjectListener(new class() PaintObjectListener { | |
95 public void paintObject(PaintObjectEvent event) { | |
96 Display display = event.display; | |
97 StyleRange style = event.style; | |
98 Font font = style.font; | |
99 if (font is null) font = styledText.getFont(); | |
100 TextLayout layout = new TextLayout(display); | |
101 layout.setAscent(event.ascent); | |
102 layout.setDescent(event.descent); | |
103 layout.setFont(font); | |
112 | 104 layout.setText("\u2023 1." ~ to!(String)( event.bulletIndex) ~ ")"); |
28 | 105 layout.draw(event.gc, event.x + 10, event.y); |
106 layout.dispose(); | |
107 } | |
108 }); | |
109 shell.open(); | |
110 while (!shell.isDisposed()) { | |
111 if (!display.readAndDispatch()) display.sleep(); | |
112 } | |
113 display.dispose (); | |
114 } | |
115 |