comparison dwtx/draw2d/graph/NodeList.d @ 98:95307ad235d9

Added Draw2d code, still work in progress
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 00:52:14 +0200
parents
children
comparison
equal deleted inserted replaced
96:b492ba44e44d 98:95307ad235d9
1 /*******************************************************************************
2 * Copyright (c) 2003, 2005 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 dwtx.draw2d.graph.NodeList;
14
15 import dwt.dwthelper.utils;
16 import dwtx.dwtxhelper.Collection;
17 import dwtx.draw2d.graph.Node;
18
19 /**
20 * A list containing nodes.
21 * @author hudsonr
22 * @since 2.1.2
23 */
24 public class NodeList : ArrayList {
25
26 /**
27 * Constructs an empty NodeList.
28 */
29 public this() { }
30
31 /**
32 * Constructs a NodeList with the elements from the specified list.
33 * @param list the list whose elements are to be added to this list
34 */
35 public this(NodeList list) {
36 super(list);
37 }
38
39 void adjustRank (int delta) {
40 if (delta is 0)
41 return;
42 for (int i = 0; i < size(); i++)
43 getNode(i).rank += delta;
44 }
45
46 void resetSortValues() {
47 for (int i = 0; i < size(); i++)
48 getNode(i).sortValue = 0.0;
49 }
50
51 void resetIndices() {
52 for (int i = 0; i < size(); i++)
53 getNode(i).index = 0;
54 }
55
56 void normalizeRanks() {
57 int minRank = Integer.MAX_VALUE;
58 for (int i = 0; i < size(); i++)
59 minRank = Math.min(minRank, getNode(i).rank);
60 adjustRank(-minRank);
61 }
62
63 /**
64 * Returns the Node at the given index.
65 * @param index the index
66 * @return the node at a given index
67 */
68 public Node getNode(int index) {
69 return cast(Node)super.get(index);
70 }
71
72 void resetFlags() {
73 for (int i = 0; i < size(); i++) {
74 getNode(i).flag = false;
75 }
76 }
77
78 }