1 11 package org.eclipse.ui.internal.forms.widgets; 12 13 import java.util.ArrayList ; 14 15 public class Locator implements Cloneable { 16 public int indent; 17 public int x, y; 18 public int width; 19 public int leading; 20 public int rowHeight; 21 public int marginWidth; 22 public int marginHeight; 23 public int rowCounter; 24 public ArrayList heights; 25 26 public void newLine() { 27 resetCaret(); 28 y += rowHeight; 29 rowHeight = 0; 30 } 31 32 public Locator create() { 33 try { 34 return (Locator)clone(); 35 } 36 catch (CloneNotSupportedException e) { 37 return null; 38 } 39 } 40 public void collectHeights() { 41 heights.add(new int [] { rowHeight, leading} ); 42 rowCounter++; 43 } 44 public int getBaseline(int segmentHeight) { 45 return getBaseline(segmentHeight, true); 46 47 } 48 public int getMiddle(int segmentHeight, boolean text) { 49 if (heights!=null && heights.size()>rowCounter) { 50 int [] rdata = (int[])heights.get(rowCounter); 51 int rheight = rdata[0]; 52 int rleading = rdata[1]; 53 if (text) 54 return y + rheight/2 - segmentHeight/2 - rleading; 55 return y + rheight/2 - segmentHeight/2; 56 } 57 return y; 58 } 59 public int getBaseline(int segmentHeight, boolean text) { 60 if (heights!=null && heights.size()>rowCounter) { 61 int [] rdata = (int[])heights.get(rowCounter); 62 int rheight = rdata[0]; 63 int rleading = rdata[1]; 64 if (text) 65 return y + rheight - segmentHeight - rleading; 66 return y + rheight - segmentHeight; 67 } 68 return y; 69 } 70 71 public void resetCaret() { 72 x = getStartX(); 73 } 74 public int getStartX() { 75 return marginWidth + indent; 76 } 77 } 78 | Popular Tags |