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
|
|
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, SWT.WRAP | DWT.BORDER);
|
|
59 styledText.setText(text);
|
|
60 FontData data = display.getSystemFont().getFontData()[0];
|
|
61 Font font = new Font(display, data.getName(), 16f, SWT.BOLD);
|
|
62 styledText.setFont(font);
|
|
63 styledText.setForeground(display.getSystemColor (SWT.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 (SWT.COLOR_WHITE));
|
|
70 gc.setBackground (display.getSystemColor (SWT.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 (SWT.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 }
|