Mercurial > projects > dwt2
comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet211.d @ 28:69b1fa94a4a8
Added SWT snippets
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 22 Mar 2009 15:17:04 +0100 |
parents | |
children | 4e5843b771cc |
comparison
equal
deleted
inserted
replaced
27:1bf55a6eb092 | 28:69b1fa94a4a8 |
---|---|
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.Snippet211; | |
15 /* | |
16 * SWT StyledText snippet: use rise and font with StyleRange. | |
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 | |
25 import org.eclipse.swt.SWT; | |
26 import org.eclipse.swt.custom.StyledText; | |
27 import org.eclipse.swt.custom.StyleRange; | |
28 import org.eclipse.swt.layout.FillLayout; | |
29 import org.eclipse.swt.widgets.Display; | |
30 import org.eclipse.swt.widgets.Shell; | |
31 import org.eclipse.swt.widgets.Event; | |
32 import org.eclipse.swt.widgets.Listener; | |
33 import org.eclipse.swt.graphics.FontData; | |
34 import org.eclipse.swt.graphics.Font; | |
35 import org.eclipse.swt.graphics.Rectangle; | |
36 import org.eclipse.swt.graphics.GC; | |
37 import org.eclipse.swt.graphics.Image; | |
38 import java.lang.all; | |
39 version(JIVE){ | |
40 import jive.stacktrace; | |
41 } | |
42 | |
43 void main() { | |
44 static String text = | |
45 "You can set any font you want in a range. You can also set a baseline rise and all other old features" | |
46 " like background and foreground, and mix them any way you want. Totally awesome."; | |
47 | |
48 Display display = new Display(); | |
49 Shell shell = new Shell(display); | |
50 shell.setLayout(new FillLayout()); | |
51 StyledText styledText = new StyledText(shell, SWT.WRAP | DWT.BORDER); | |
52 styledText.setText(text); | |
53 FontData data = styledText.getFont().getFontData()[0]; | |
54 Font font1 = new Font(display, data.getName(), data.getHeight() * 2f, data.getStyle()); | |
55 Font font2 = new Font(display, data.getName(), data.getHeight() * 4f / 5, data.getStyle()); | |
56 StyleRange[] styles = new StyleRange[8]; | |
57 styles[0] = new StyleRange(); | |
58 styles[0].font = font1; | |
59 styles[1] = new StyleRange(); | |
60 styles[1].rise = data.getHeight() / 3; | |
61 styles[2] = new StyleRange(); | |
62 styles[2].background = display.getSystemColor(SWT.COLOR_GREEN); | |
63 styles[3] = new StyleRange(); | |
64 styles[3].foreground = display.getSystemColor(SWT.COLOR_MAGENTA); | |
65 styles[4] = new StyleRange(); | |
66 styles[4].font = font2; | |
67 styles[4].foreground = display.getSystemColor(SWT.COLOR_BLUE);; | |
68 styles[4].underline = true; | |
69 styles[5] = new StyleRange(); | |
70 styles[5].rise = -data.getHeight() / 3; | |
71 styles[5].strikeout = true; | |
72 styles[5].underline = true; | |
73 styles[6] = new StyleRange(); | |
74 styles[6].font = font1; | |
75 styles[6].foreground = display.getSystemColor(SWT.COLOR_YELLOW); | |
76 styles[6].background = display.getSystemColor(SWT.COLOR_BLUE); | |
77 styles[7] = new StyleRange(); | |
78 styles[7].rise = data.getHeight() / 3; | |
79 styles[7].underline = true; | |
80 styles[7].fontStyle = SWT.BOLD; | |
81 styles[7].foreground = display.getSystemColor(SWT.COLOR_RED); | |
82 styles[7].background = display.getSystemColor(SWT.COLOR_BLACK); | |
83 | |
84 int[] ranges = [16, 4, 61, 13, 107, 10, 122, 10, 134, 3, 143, 6, 160, 7, 168, 7]; | |
85 styledText.setStyleRanges(ranges, styles); | |
86 | |
87 shell.setSize(300, 300); | |
88 shell.open(); | |
89 while (!shell.isDisposed()) { | |
90 if (!display.readAndDispatch()) | |
91 display.sleep(); | |
92 } | |
93 font1.dispose(); | |
94 font2.dispose(); | |
95 display.dispose(); | |
96 | |
97 } |