01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.preferences;
11:
12: import org.eclipse.swt.SWT;
13: import org.eclipse.swt.custom.Bullet;
14: import org.eclipse.swt.custom.StyleRange;
15: import org.eclipse.swt.custom.StyledText;
16: import org.eclipse.swt.graphics.Color;
17: import org.eclipse.swt.graphics.GlyphMetrics;
18: import org.eclipse.swt.layout.GridData;
19: import org.eclipse.swt.widgets.Composite;
20: import org.eclipse.swt.widgets.Control;
21: import org.eclipse.swt.widgets.Display;
22:
23: /**
24: * Each line of the given text is preceded by a bullet.
25: */
26: public class BulletListBlock {
27:
28: private StyledText fStyledText;
29: private boolean fEnabled;
30: private String fText;
31:
32: public BulletListBlock() {
33: fEnabled = true;
34: fText = ""; //$NON-NLS-1$
35: }
36:
37: public Control createControl(Composite parent) {
38: fStyledText = new StyledText(parent, SWT.FLAT | SWT.BORDER
39: | SWT.READ_ONLY);
40:
41: final GridData data = new GridData(GridData.FILL_HORIZONTAL
42: | GridData.FILL_VERTICAL);
43: fStyledText.setLayoutData(data);
44: configureStyledText(fText, fEnabled);
45:
46: return fStyledText;
47: }
48:
49: public void setText(String text) {
50: fText = text;
51: configureStyledText(fText, fEnabled);
52: }
53:
54: public void setEnabled(boolean enabled) {
55: fEnabled = enabled;
56: configureStyledText(fText, fEnabled);
57: }
58:
59: private void configureStyledText(String text, boolean enabled) {
60: if (fStyledText == null)
61: return;
62:
63: fStyledText.setText(text);
64: int count = fStyledText.getCharCount();
65: if (count == 0)
66: return;
67:
68: Color foreground = enabled ? null : Display.getDefault()
69: .getSystemColor(SWT.COLOR_DARK_GRAY);
70:
71: fStyledText.setStyleRange(new StyleRange(0, count, foreground,
72: null));
73:
74: StyleRange styleRange = new StyleRange(0, count, foreground,
75: null);
76: styleRange.metrics = new GlyphMetrics(0, 0, 20);
77: fStyledText.setLineBullet(0, fStyledText.getLineCount(),
78: new Bullet(styleRange));
79:
80: fStyledText.setEnabled(enabled);
81: }
82: }
|