1 11 package org.eclipse.ui.internal.forms.widgets; 12 13 import java.util.Hashtable ; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.graphics.*; 17 18 19 public abstract class ObjectSegment extends ParagraphSegment { 20 public static final int TOP = 1; 21 22 public static final int MIDDLE = 2; 23 24 public static final int BOTTOM = 3; 25 26 private int alignment = BOTTOM; 27 private boolean nowrap=false; 28 private Rectangle bounds; 29 private String objectId; 30 31 public int getVerticalAlignment() { 32 return alignment; 33 } 34 35 void setVerticalAlignment(int alignment) { 36 this.alignment = alignment; 37 } 38 39 public String getObjectId() { 40 return objectId; 41 } 42 43 void setObjectId(String objectId) { 44 this.objectId = objectId; 45 } 46 47 protected abstract Point getObjectSize(Hashtable resourceTable, int wHint); 48 49 public boolean advanceLocator(GC gc, int wHint, Locator loc, 50 Hashtable objectTable, boolean computeHeightOnly) { 51 Point objectSize = getObjectSize(objectTable, wHint); 52 int iwidth = 0; 53 int iheight = 0; 54 boolean newLine = false; 55 56 if (objectSize != null) { 57 iwidth = objectSize.x + (isSelectable()?2:0); 58 iheight = objectSize.y + (isSelectable()?2:0); 59 } 60 if (wHint != SWT.DEFAULT && !nowrap && loc.x + iwidth > wHint) { 61 if (computeHeightOnly) 63 loc.collectHeights(); 64 loc.x = loc.indent; 65 loc.x += iwidth; 66 loc.y += loc.rowHeight; 67 loc.width = loc.indent + iwidth; 68 loc.rowHeight = iheight; 69 loc.leading = 0; 70 newLine = true; 71 } else { 72 loc.x += iwidth; 73 loc.width += iwidth; 74 loc.rowHeight = Math.max(loc.rowHeight, iheight); 75 } 76 return newLine; 77 } 78 79 public boolean contains(int x, int y) { 80 if (bounds==null) 81 return false; 82 return bounds.contains(x, y); 83 } 84 public boolean intersects(Rectangle rect) { 85 if (bounds==null) 86 return false; 87 return bounds.intersects(rect); 88 } 89 90 public Rectangle getBounds() { 91 return bounds; 92 } 93 94 public boolean isSelectable() { 95 return false; 96 } 97 100 public boolean isNowrap() { 101 return nowrap; 102 } 103 106 public void setNowrap(boolean nowrap) { 107 this.nowrap = nowrap; 108 } 109 public void paint(GC gc, boolean hover, Hashtable resourceTable, boolean selected, SelectionData selData, Rectangle repaintRegion) { 110 } 111 112 115 public void layout(GC gc, int width, Locator loc, Hashtable resourceTable, 116 boolean selected) { 117 Point size = getObjectSize(resourceTable, width); 118 119 int objWidth = 0; 120 int objHeight = 0; 121 if (size != null) { 122 objWidth = size.x + (isSelectable()?2:0); 123 objHeight = size.y + (isSelectable()?2:0); 124 } else 125 return; 126 loc.width = objWidth; 127 128 if (!nowrap && loc.x + objWidth > width) { 129 loc.newLine(); 131 loc.rowCounter++; 132 } 133 int ix = loc.x; 134 int iy = loc.y; 135 136 if (alignment==MIDDLE) 137 iy = loc.getMiddle(objHeight, false); 138 else if (alignment==BOTTOM) 139 iy = loc.getBaseline(objHeight, false); 140 loc.x += objWidth; 141 loc.rowHeight = Math.max(loc.rowHeight, objHeight); 142 bounds = new Rectangle(ix, iy, objWidth, objHeight); 143 } 144 147 public void computeSelection(GC gc, Hashtable resourceTable, SelectionData selData) { 148 } 151 } 152 | Popular Tags |