1 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 27 public class BulletListBlock { 28 29 private StyledText fStyledText; 30 private boolean fEnabled; 31 private String fText; 32 33 public BulletListBlock() { 34 fEnabled= true; 35 fText= ""; } 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 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 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 |