KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > BulletListBlock


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.preferences;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.custom.Bullet;
15 import org.eclipse.swt.custom.StyleRange;
16 import org.eclipse.swt.custom.StyledText;
17 import org.eclipse.swt.graphics.Color;
18 import org.eclipse.swt.graphics.GlyphMetrics;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Display;
23
24 /**
25  * Each line of the given text is preceded by a bullet.
26  */

27 public class BulletListBlock {
28
29     private StyledText fStyledText;
30     private boolean fEnabled;
31     private String JavaDoc fText;
32     
33     public BulletListBlock() {
34         fEnabled= true;
35         fText= ""; //$NON-NLS-1$
36
}
37
38     public Control createControl(Composite parent) {
39         fStyledText= new StyledText(parent, SWT.FLAT | SWT.BORDER | SWT.READ_ONLY);
40         
41         final GridData data= new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
42         fStyledText.setLayoutData(data);
43         configureStyledText(fText, fEnabled);
44         
45         return fStyledText;
46     }
47
48     public void setText(String JavaDoc text) {
49         fText= text;
50         configureStyledText(fText, fEnabled);
51     }
52     
53     public void setEnabled(boolean enabled) {
54         fEnabled= enabled;
55         configureStyledText(fText, fEnabled);
56     }
57
58     private void configureStyledText(String JavaDoc text, boolean enabled) {
59         if (fStyledText == null)
60             return;
61         
62         fStyledText.setText(text);
63         int count= fStyledText.getCharCount();
64         if (count == 0)
65             return;
66         
67         Color foreground= enabled ? null : Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
68
69         fStyledText.setStyleRange(new StyleRange(0, count, foreground, null));
70                     
71         StyleRange styleRange= new StyleRange(0, count, foreground, null);
72         styleRange.metrics= new GlyphMetrics(0, 0, 20);
73         fStyledText.setLineBullet(0, fStyledText.getLineCount(), new Bullet(styleRange));
74         
75         fStyledText.setEnabled(enabled);
76     }
77 }
78
Popular Tags