Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet218.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 |
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.Snippet218; | |
15 /* | |
16 * SWT StyledText snippet: use gradient background. | |
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.layout.FillLayout; | |
28 import org.eclipse.swt.widgets.Display; | |
29 import org.eclipse.swt.widgets.Shell; | |
30 import org.eclipse.swt.widgets.Event; | |
31 import org.eclipse.swt.widgets.Listener; | |
32 import org.eclipse.swt.graphics.FontData; | |
33 import org.eclipse.swt.graphics.Font; | |
34 import org.eclipse.swt.graphics.Rectangle; | |
35 import org.eclipse.swt.graphics.GC; | |
36 import org.eclipse.swt.graphics.Image; | |
37 | |
38 import java.lang.all; | |
39 | |
112 | 40 version(Tango){ |
41 import Math = tango.math.Math; | |
42 } else { // Phobos | |
43 import Math = std.algorithm; | |
44 } | |
45 | |
28 | 46 version(JIVE){ |
47 import jive.stacktrace; | |
48 } | |
49 | |
50 void main() { | |
51 static String text = "Plans do not materialize out of nowhere, nor are they entirely static. To ensure the planning process is " | |
52 "transparent and open to the entire Eclipse community, we (the Eclipse PMC) post plans in an embryonic " | |
53 "form and revise them throughout the release cycle. \n" | |
54 "The first part of the plan deals with the important matters of release deliverables, release milestones, target " | |
55 "operating environments, and release-to-release compatibility. These are all things that need to be clear for " | |
56 "any release, even if no features were to change. \n"; | |
57 static Image oldImage; | |
58 | |
59 | |
60 Display display = new Display(); | |
61 Shell shell = new Shell(display); | |
62 shell.setLayout(new FillLayout()); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
63 StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER); |
28 | 64 styledText.setText(text); |
65 FontData data = display.getSystemFont().getFontData()[0]; | |
66 Font font = new Font(display, data.getName(), 16f, SWT.BOLD); | |
67 styledText.setFont(font); | |
68 styledText.setForeground(display.getSystemColor (SWT.COLOR_BLUE)); | |
69 | |
70 void onResize (Event event) { | |
71 Rectangle rect = styledText.getClientArea (); | |
72 Image newImage = new Image (display, 1, Math.max (1, rect.height)); | |
73 GC gc = new GC (newImage); | |
74 gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE)); | |
75 gc.setBackground (display.getSystemColor (SWT.COLOR_YELLOW)); | |
76 gc.fillGradientRectangle (rect.x, rect.y, 1, rect.height, true); | |
77 gc.dispose (); | |
78 styledText.setBackgroundImage (newImage); | |
79 if (oldImage !is null) oldImage.dispose (); | |
80 oldImage = newImage; | |
81 } | |
82 | |
83 styledText.addListener (SWT.Resize, dgListener(&onResize)); | |
84 | |
85 shell.setSize(700, 400); | |
86 shell.open(); | |
87 while (!shell.isDisposed()) { | |
88 if (!display.readAndDispatch()) | |
89 display.sleep(); | |
90 } | |
91 if (oldImage !is null) oldImage.dispose (); | |
92 font.dispose(); | |
93 display.dispose(); | |
94 } |