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