comparison org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/Locator.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children 2755ef2c8ef8
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.ui.internal.forms.widgets.Locator;
14
15 import java.lang.all;
16 import java.util.ArrayList;
17 import java.util.Set;
18
19 public class Locator : Cloneable {
20 public int indent;
21 public int x, y;
22 public int width;
23 public int leading;
24 public int rowHeight;
25 public int marginWidth;
26 public int marginHeight;
27 public int rowCounter;
28 public ArrayList heights;
29
30 public Locator clone(){
31 auto res = new Locator();
32 res.indent = indent;
33 res.x = x;
34 res.y = y;
35 res.width = width;
36 res.leading = leading;
37 res.rowHeight = rowHeight;
38 res.marginWidth = marginWidth;
39 res.marginHeight = marginHeight;
40 res.rowCounter = rowCounter;
41 res.heights = heights;
42 return res;
43 }
44
45 public void newLine() {
46 resetCaret();
47 y += rowHeight;
48 rowHeight = 0;
49 }
50
51 public Locator create() {
52 // try {
53 return cast(Locator)clone();
54 // }
55 // catch (CloneNotSupportedException e) {
56 // return null;
57 // }
58 }
59 public void collectHeights() {
60 heights.add(new ArrayWrapperObject( [ new Integer(rowHeight), new Integer(leading) ] ) );
61 rowCounter++;
62 }
63 public int getBaseline(int segmentHeight) {
64 return getBaseline(segmentHeight, true);
65
66 }
67 public int getMiddle(int segmentHeight, bool text) {
68 if (heights !is null && heights.size() > rowCounter) {
69 Integer [] rdata = arrayFromObject!(Integer)(heights.get(rowCounter));
70 int rheight = rdata[0].value;
71 int rleading = rdata[1].value;
72 if (text)
73 return y + rheight/2 - segmentHeight/2 - rleading;
74 return y + rheight/2 - segmentHeight/2;
75 }
76 return y;
77 }
78 public int getBaseline(int segmentHeight, bool text) {
79 if (heights !is null && heights.size()>rowCounter) {
80 Integer [] rdata = arrayFromObject!(Integer)(heights.get(rowCounter));
81 int rheight = rdata[0].value;
82 int rleading = rdata[1].value;
83 if (text)
84 return y + rheight - segmentHeight - rleading;
85 return y + rheight - segmentHeight;
86 }
87 return y;
88 }
89
90 public void resetCaret() {
91 x = getStartX();
92 }
93 public int getStartX() {
94 return marginWidth + indent;
95 }
96 }