KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > forms > widgets > Locator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.forms.widgets;
12
13 import java.util.ArrayList JavaDoc;
14
15 public class Locator implements Cloneable JavaDoc {
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 JavaDoc 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 JavaDoc 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