1 11 package org.eclipse.ui.internal.forms.widgets; 12 13 import java.util.Hashtable ; 14 15 import org.eclipse.swt.graphics.Color; 16 import org.eclipse.swt.graphics.GC; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.graphics.Point; 19 import org.eclipse.swt.graphics.Rectangle; 20 21 public class BulletParagraph extends Paragraph { 22 public static final int CIRCLE = 1; 23 24 public static final int TEXT = 2; 25 26 public static final int IMAGE = 3; 27 28 private int style = CIRCLE; 29 30 private String text; 31 32 private int CIRCLE_DIAM = 5; 33 34 private int SPACING = 10; 35 36 private int indent = -1; 37 38 private int bindent = -1; 39 40 private Rectangle bbounds; 41 42 47 public BulletParagraph(boolean addVerticalSpace) { 48 super(addVerticalSpace); 49 } 50 51 public int getIndent() { 52 int ivalue = indent; 53 if (ivalue != -1) 54 return ivalue; 55 switch (style) { 56 case CIRCLE: 57 ivalue = CIRCLE_DIAM + SPACING; 58 break; 59 default: 60 ivalue = 20; 61 break; 62 } 63 return getBulletIndent() + ivalue; 64 } 65 66 public int getBulletIndent() { 67 if (bindent != -1) 68 return bindent; 69 return 0; 70 } 71 72 75 public int getBulletStyle() { 76 return style; 77 } 78 79 public void setBulletStyle(int style) { 80 this.style = style; 81 } 82 83 public void setBulletText(String text) { 84 this.text = text; 85 } 86 87 public void setIndent(int indent) { 88 this.indent = indent; 89 } 90 91 public void setBulletIndent(int bindent) { 92 this.bindent = bindent; 93 } 94 95 98 public String getBulletText() { 99 return text; 100 } 101 102 public void layout(GC gc, int width, Locator loc, int lineHeight, 103 Hashtable resourceTable, IHyperlinkSegment selectedLink) { 104 computeRowHeights(gc, width, loc, lineHeight, resourceTable); 105 layoutBullet(gc, loc, lineHeight, resourceTable); 106 super.layout(gc, width, loc, lineHeight, resourceTable, selectedLink); 107 } 108 109 public void paint(GC gc, Rectangle repaintRegion, 110 Hashtable resourceTable, IHyperlinkSegment selectedLink, 111 SelectionData selData) { 112 paintBullet(gc, repaintRegion, resourceTable); 113 super.paint(gc, repaintRegion, resourceTable, selectedLink, selData); 114 } 115 116 private void layoutBullet(GC gc, Locator loc, int lineHeight, 117 Hashtable resourceTable) { 118 int x = loc.x - getIndent() + getBulletIndent(); 119 int rowHeight = ((int[]) loc.heights.get(0))[0]; 120 if (style == CIRCLE) { 121 int y = loc.y + rowHeight / 2 - CIRCLE_DIAM / 2; 122 bbounds = new Rectangle(x, y, CIRCLE_DIAM, CIRCLE_DIAM); 123 } else if (style == TEXT && text != null) { 124 Point textSize = gc.textExtent(text); 126 bbounds = new Rectangle(x, loc.y, textSize.x, textSize.y); 127 } else if (style == IMAGE && text != null) { 128 Image image = (Image) resourceTable.get(text); 129 if (image != null) { 130 Rectangle ibounds = image.getBounds(); 131 int y = loc.y + rowHeight / 2 - ibounds.height / 2; 132 bbounds = new Rectangle(x, y, ibounds.width, ibounds.height); 133 } 134 } 135 } 136 137 public void paintBullet(GC gc, Rectangle repaintRegion, 138 Hashtable resourceTable) { 139 if (bbounds == null) 140 return; 141 int x = bbounds.x; 142 int y = bbounds.y; 143 if (repaintRegion != null) { 144 x -= repaintRegion.x; 145 y -= repaintRegion.y; 146 } 147 if (style == CIRCLE) { 148 Color bg = gc.getBackground(); 149 Color fg = gc.getForeground(); 150 gc.setBackground(fg); 151 gc.fillRectangle(x, y + 1, 5, 3); 152 gc.fillRectangle(x + 1, y, 3, 5); 153 gc.setBackground(bg); 154 } else if (style == TEXT && text != null) { 155 gc.drawText(text, x, y); 156 } else if (style == IMAGE && text != null) { 157 Image image = (Image) resourceTable.get(text); 158 if (image != null) 159 gc.drawImage(image, x, y); 160 } 161 } 162 } 163 | Popular Tags |