Mercurial > projects > dwt2
comparison org.eclipse.jface/src/org/eclipse/jface/dialogs/ImageAndMessageArea.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2006 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 * Frank Benoit <benoit@tionex.de> | |
12 ******************************************************************************/ | |
13 | |
14 module org.eclipse.jface.dialogs.ImageAndMessageArea; | |
15 | |
16 import org.eclipse.jface.dialogs.IDialogConstants; | |
17 | |
18 import org.eclipse.swt.SWT; | |
19 import org.eclipse.swt.events.PaintEvent; | |
20 import org.eclipse.swt.events.PaintListener; | |
21 import org.eclipse.swt.graphics.Color; | |
22 import org.eclipse.swt.graphics.Font; | |
23 import org.eclipse.swt.graphics.Image; | |
24 import org.eclipse.swt.graphics.Point; | |
25 import org.eclipse.swt.graphics.Rectangle; | |
26 import org.eclipse.swt.layout.GridData; | |
27 import org.eclipse.swt.layout.GridLayout; | |
28 import org.eclipse.swt.widgets.Composite; | |
29 import org.eclipse.swt.widgets.Layout; | |
30 import org.eclipse.swt.widgets.Text; | |
31 import org.eclipse.jface.fieldassist.DecoratedField; | |
32 import org.eclipse.jface.fieldassist.FieldDecorationRegistry; | |
33 import org.eclipse.jface.fieldassist.TextControlCreator; | |
34 import org.eclipse.jface.resource.JFaceResources; | |
35 | |
36 import java.lang.all; | |
37 import java.util.Set; | |
38 | |
39 /** | |
40 * Instances of this class provide a message area to display a message and an | |
41 * associated image. | |
42 * <p> | |
43 * This class is not intended to be extended by clients. | |
44 * </p> | |
45 * | |
46 * @since 3.2 | |
47 * @deprecated As of 3.3, this class is no longer necessary. | |
48 * | |
49 */ | |
50 public class ImageAndMessageArea : Composite { | |
51 | |
52 private int BORDER_MARGIN = IDialogConstants.HORIZONTAL_SPACING / 2; | |
53 | |
54 private DecoratedField messageField; | |
55 | |
56 private Composite container; | |
57 | |
58 /** | |
59 * Constructs a new ImageAndMessageArea with an empty decorated field. Calls | |
60 * to <code>setText(String text)</code> and | |
61 * <code>setImage(Image image)</code> are required in order to fill the | |
62 * message area. Also, the instance will be invisible when initially | |
63 * created. | |
64 * <p> | |
65 * The style bit <code>SWT.WRAP</code> should be used if a larger message | |
66 * area is desired. | |
67 * </p> | |
68 * | |
69 * @param parent | |
70 * the parent composite | |
71 * @param style | |
72 * the SWT style bits. Using SWT.WRAP will create a larger | |
73 * message area. | |
74 */ | |
75 public this(Composite parent, int style) { | |
76 super(parent, style); | |
77 container = new Composite(this, style); | |
78 GridLayout glayout = new GridLayout(); | |
79 glayout.numColumns = 2; | |
80 glayout.marginWidth = 0; | |
81 glayout.marginHeight = 0; | |
82 glayout.marginTop = BORDER_MARGIN; | |
83 glayout.marginBottom = BORDER_MARGIN; | |
84 container.setLayout(glayout); | |
85 | |
86 messageField = new DecoratedField(container, SWT.READ_ONLY | style, | |
87 new TextControlCreator()); | |
88 setFont(JFaceResources.getDialogFont()); | |
89 | |
90 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); | |
91 int lineHeight = (cast(Text) messageField.getControl()).getLineHeight(); | |
92 if ((style & SWT.WRAP) > 0) | |
93 gd.heightHint = 2 * lineHeight; | |
94 else | |
95 gd.heightHint = lineHeight; | |
96 | |
97 messageField.getLayoutControl().setLayoutData(gd); | |
98 | |
99 addPaintListener(new class PaintListener { | |
100 /* | |
101 * (non-Javadoc) | |
102 * | |
103 * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent) | |
104 */ | |
105 public void paintControl(PaintEvent e) { | |
106 onPaint(e); | |
107 } | |
108 }); | |
109 | |
110 // sets the layout and size to account for the BORDER_MARGIN between | |
111 // the border drawn around the container and the decorated field. | |
112 setLayout(new class Layout { | |
113 /* | |
114 * (non-Javadoc) | |
115 * | |
116 * @see org.eclipse.swt.widgets.Layout#layout(org.eclipse.swt.widgets.Composite, | |
117 * bool) | |
118 */ | |
119 public void layout(Composite parent, bool changed) { | |
120 Rectangle carea = getClientArea(); | |
121 container.setBounds(carea.x + BORDER_MARGIN, carea.y | |
122 + BORDER_MARGIN, carea.width - (2 * BORDER_MARGIN), | |
123 carea.height - (2 * BORDER_MARGIN)); | |
124 } | |
125 | |
126 /* | |
127 * (non-Javadoc) | |
128 * | |
129 * @see org.eclipse.swt.widgets.Layout#computeSize(org.eclipse.swt.widgets.Composite, | |
130 * int, int, bool) | |
131 */ | |
132 public Point computeSize(Composite parent, int wHint, int hHint, | |
133 bool changed) { | |
134 Point size; | |
135 size = container.computeSize(wHint, hHint, changed); | |
136 | |
137 // size set to account for the BORDER_MARGIN on | |
138 // all sides of the decorated field | |
139 size.x += 4; | |
140 size.y += 4; | |
141 return size; | |
142 } | |
143 }); | |
144 setVisible(false); | |
145 } | |
146 | |
147 /* | |
148 * (non-Javadoc) | |
149 * | |
150 * @see org.eclipse.swt.widgets.Control#setBackground(org.eclipse.swt.graphics.Color) | |
151 */ | |
152 public override void setBackground(Color bg) { | |
153 super.setBackground(bg); | |
154 messageField.getLayoutControl().setBackground(bg); | |
155 messageField.getControl().setBackground(bg); | |
156 container.setBackground(bg); | |
157 } | |
158 | |
159 /** | |
160 * Sets the text in the decorated field which will be displayed in the | |
161 * message area. | |
162 * | |
163 * @param text | |
164 * the text to be displayed in the message area | |
165 * | |
166 * @see org.eclipse.swt.widgets.Text#setText(String string) | |
167 */ | |
168 public void setText(String text) { | |
169 (cast(Text) messageField.getControl()).setText(text); | |
170 } | |
171 | |
172 /** | |
173 * Adds an image to decorated field to be shown in the message area. | |
174 * | |
175 * @param image | |
176 * desired image to be shown in the ImageAndMessageArea | |
177 */ | |
178 public void setImage(Image image) { | |
179 FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault(); | |
180 registry.registerFieldDecoration("messageImage", null, image); //$NON-NLS-1$ | |
181 messageField.addFieldDecoration(registry | |
182 .getFieldDecoration("messageImage"), //$NON-NLS-1$ | |
183 SWT.LEFT | SWT.TOP, false); | |
184 } | |
185 | |
186 /** | |
187 * Draws the message area composite with rounded corners. | |
188 */ | |
189 private void onPaint(PaintEvent e) { | |
190 Rectangle carea = getClientArea(); | |
191 e.gc.setForeground(getForeground()); | |
192 | |
193 // draws the polyline to be rounded in a 2 pixel squared area | |
194 e.gc.drawPolyline([ carea.x, carea.y + carea.height - 1, | |
195 carea.x, carea.y + 2, carea.x + 2, carea.y, | |
196 carea.x + carea.width - 3, carea.y, carea.x + carea.width - 1, | |
197 carea.y + 2, carea.x + carea.width - 1, | |
198 carea.y + carea.height - 1 ]); | |
199 } | |
200 | |
201 /* | |
202 * (non-Javadoc) | |
203 * | |
204 * @see org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font) | |
205 */ | |
206 public override void setFont(Font font) { | |
207 super.setFont(font); | |
208 (cast(Text) messageField.getControl()).setFont(font); | |
209 } | |
210 | |
211 /* | |
212 * (non-Javadoc) | |
213 * | |
214 * @see org.eclipse.swt.widgets.Control#setToolTipText(java.lang.String) | |
215 */ | |
216 public override void setToolTipText(String text) { | |
217 super.setToolTipText(text); | |
218 (cast(Text) messageField.getControl()).setToolTipText(text); | |
219 } | |
220 } |