Mercurial > projects > dwt-samples
comparison snippets/styledtext/Snippet222.d @ 155:04d05db6dca4
styledtext: Snippet211, Snippet213, Snippet217, Snippet218, Snippet222, Snippet244
author | yidabu <yidabu@gmail.com> |
---|---|
date | Fri, 22 Aug 2008 07:27:56 +0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
154:57cb6d948bf7 | 155:04d05db6dca4 |
---|---|
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 styledtext.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 dwt.DWT; | |
25 import dwt.custom.StyledText; | |
26 import dwt.custom.StyleRange; | |
27 import dwt.custom.PaintObjectEvent; | |
28 import dwt.custom.PaintObjectListener; | |
29 import dwt.custom.Bullet; | |
30 import dwt.custom.ST; | |
31 import dwt.layout.GridData; | |
32 import dwt.layout.FillLayout; | |
33 import dwt.widgets.Display; | |
34 import dwt.widgets.Shell; | |
35 import dwt.widgets.Button; | |
36 import dwt.widgets.Event; | |
37 import dwt.widgets.Listener; | |
38 import dwt.graphics.FontData; | |
39 import dwt.graphics.Font; | |
40 import dwt.graphics.TextLayout; | |
41 import dwt.graphics.GlyphMetrics; | |
42 import tango.text.Text; | |
43 alias Text!(char) StringBuffer; | |
44 import tango.util.Convert; | |
45 | |
46 import dwt.dwthelper.utils; | |
47 version(JIVE){ | |
48 import jive.stacktrace; | |
49 } | |
50 | |
51 void main() { | |
52 Display display = new Display(); | |
53 Shell shell = new Shell(display); | |
54 shell.setText("StyledText Bullet Example"); | |
55 shell.setLayout(new FillLayout()); | |
56 StyledText styledText = new StyledText (shell, DWT.FULL_SELECTION | DWT.BORDER | DWT.WRAP | DWT.V_SCROLL); | |
57 StringBuffer text = new StringBuffer(); | |
58 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"); | |
60 text.append("\n"); | |
61 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(char[])(i) ~ "\n"); | |
62 for (int i = 0; i < 4; i++) text.append("Sub List Item " ~ to!(char[])(i) ~ "\n"); | |
63 for (int i = 0; i < 2; i++) text.append("Numbered List Item " ~ to!(char[])(2+i) ~ "\n"); | |
64 text.append("\n"); | |
65 for (int i = 0; i < 4; i++) text.append("Custom Draw List Item " ~ to!(char[])(i) ~ "\n"); | |
66 styledText.setText(text.toString()); | |
67 | |
68 StyleRange style0 = new StyleRange(); | |
69 style0.metrics = new GlyphMetrics(0, 0, 40); | |
70 style0.foreground = display.getSystemColor(DWT.COLOR_RED); | |
71 Bullet bullet0 = new Bullet (style0); | |
72 StyleRange style1 = new StyleRange(); | |
73 style1.metrics = new GlyphMetrics(0, 0, 50); | |
74 style1.foreground = display.getSystemColor(DWT.COLOR_BLUE); | |
75 Bullet bullet1 = new Bullet (ST.BULLET_NUMBER | ST.BULLET_TEXT, style1); | |
76 bullet1.text = "."; | |
77 StyleRange style2 = new StyleRange(); | |
78 style2.metrics = new GlyphMetrics(0, 0, 80); | |
79 style2.foreground = display.getSystemColor(DWT.COLOR_GREEN); | |
80 Bullet bullet2 = new Bullet (ST.BULLET_TEXT, style2); | |
81 bullet2.text = "\u2713"; | |
82 StyleRange style3 = new StyleRange(); | |
83 style3.metrics = new GlyphMetrics(0, 0, 50); | |
84 Bullet bullet3 = new Bullet (ST.BULLET_CUSTOM, style2); | |
85 | |
86 styledText.setLineBullet(2, 4, bullet0); | |
87 styledText.setLineBullet(7, 2, bullet1); | |
88 styledText.setLineBullet(9, 4, bullet2); | |
89 styledText.setLineBullet(13, 2, bullet1); | |
90 styledText.setLineBullet(16, 4, bullet3); | |
91 | |
92 styledText.addPaintObjectListener(new class() PaintObjectListener { | |
93 public void paintObject(PaintObjectEvent event) { | |
94 Display display = event.display; | |
95 StyleRange style = event.style; | |
96 Font font = style.font; | |
97 if (font is null) font = styledText.getFont(); | |
98 TextLayout layout = new TextLayout(display); | |
99 layout.setAscent(event.ascent); | |
100 layout.setDescent(event.descent); | |
101 layout.setFont(font); | |
102 layout.setText("\u2023 1." ~ to!(char[])( event.bulletIndex) ~ ")"); | |
103 layout.draw(event.gc, event.x + 10, event.y); | |
104 layout.dispose(); | |
105 } | |
106 }); | |
107 shell.open(); | |
108 while (!shell.isDisposed()) { | |
109 if (!display.readAndDispatch()) display.sleep(); | |
110 } | |
111 display.dispose (); | |
112 } | |
113 |