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