home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.util.Vector;
-
- class OutlineNode {
- private Outline Owner;
- protected int NodeIndex;
- protected int NodeDepth;
- protected OutlineNodeData NodeData;
- protected OutlineNode ParentNode;
- protected OutlineNode OlderSiblingNode;
- protected OutlineNode YoungerSiblingNode;
- protected int NodeChildren;
- protected OutlineNode FirstChildNode;
- protected boolean IsExpanded;
- private static int currentDrawIdx;
-
- public OutlineNode(Outline owner) {
- this(owner, (OutlineNodeData)null);
- }
-
- public OutlineNode(Outline owner, OutlineNodeData Data) {
- this.OlderSiblingNode = this.YoungerSiblingNode = this;
- this.NodeDepth = -1;
- this.NodeIndex = -1;
- this.NodeChildren = 0;
- this.FirstChildNode = null;
- this.IsExpanded = true;
- this.NodeData = Data;
- this.Owner = owner;
- }
-
- public void attach(OutlineNode relative, int relation) {
- OutlineNode prev = null;
- if (relative != null) {
- if (relation == 0) {
- this.ParentNode = relative;
- ++this.ParentNode.NodeChildren;
- if (this.ParentNode.FirstChildNode == null) {
- prev = null;
- } else {
- prev = this.ParentNode.FirstChildNode.OlderSiblingNode;
- }
-
- this.ParentNode.FirstChildNode = this;
- } else if (relation == 1) {
- this.ParentNode = relative;
- ++relative.NodeChildren;
- if (relative.FirstChildNode == null) {
- relative.FirstChildNode = this;
- prev = null;
- } else {
- prev = relative.FirstChildNode.OlderSiblingNode;
- }
- } else if (relation == 2) {
- this.ParentNode = relative.ParentNode;
- ++this.ParentNode.NodeChildren;
- prev = relative.OlderSiblingNode;
- if (relative == this.ParentNode.FirstChildNode) {
- this.ParentNode.FirstChildNode = this;
- }
- } else if (relation == 3) {
- this.ParentNode = relative.ParentNode;
- ++this.ParentNode.NodeChildren;
- prev = relative;
- }
-
- if (prev != null) {
- this.OlderSiblingNode = prev;
- this.YoungerSiblingNode = prev.YoungerSiblingNode;
- this.YoungerSiblingNode.OlderSiblingNode = this;
- this.OlderSiblingNode.YoungerSiblingNode = this;
- } else {
- this.OlderSiblingNode = this.YoungerSiblingNode = this;
- }
-
- this.NodeDepth = this.ParentNode.NodeDepth + 1;
- this.IsExpanded = false;
- }
- }
-
- public void detach() {
- --this.ParentNode.NodeChildren;
- if (this.ParentNode.NodeChildren == 0) {
- this.ParentNode.FirstChildNode = null;
- } else if (this.ParentNode.FirstChildNode == this) {
- this.ParentNode.FirstChildNode = this.YoungerSiblingNode;
- }
-
- this.YoungerSiblingNode.OlderSiblingNode = this.OlderSiblingNode;
- this.OlderSiblingNode.YoungerSiblingNode = this.YoungerSiblingNode;
- }
-
- public void delete() {
- while(this.FirstChildNode != null) {
- OutlineNode nd = this.FirstChildNode;
- nd.detach();
- nd.delete();
- }
-
- }
-
- public void expand(boolean doExpand) {
- if (this.NodeChildren > 0 && doExpand) {
- this.IsExpanded = true;
- } else {
- this.IsExpanded = false;
- }
- }
-
- final int reindexChildren(int index) {
- this.NodeIndex = index++;
- if (this.FirstChildNode != null) {
- OutlineNode nd = this.FirstChildNode;
- index = nd.reindexChildren(index);
-
- for(OutlineNode var4 = nd.YoungerSiblingNode; var4 != this.FirstChildNode; var4 = var4.YoungerSiblingNode) {
- index = var4.reindexChildren(index);
- }
- }
-
- return index;
- }
-
- final OutlineNode getDescendantWithIndex(int index) {
- if (this.NodeIndex == index) {
- return this;
- } else if (this.NodeChildren == 1) {
- return this.FirstChildNode.getDescendantWithIndex(index);
- } else {
- OutlineNode nd = this.FirstChildNode;
-
- while(nd.YoungerSiblingNode.NodeIndex <= index && nd.YoungerSiblingNode != this.FirstChildNode) {
- nd = nd.YoungerSiblingNode;
- if (nd == this.FirstChildNode) {
- return null;
- }
- }
-
- return nd.getDescendantWithIndex(index);
- }
- }
-
- public int getIndex() {
- return this.NodeIndex;
- }
-
- public int getDepth() {
- return this.NodeDepth;
- }
-
- public OutlineNodeData getData() {
- return this.NodeData;
- }
-
- public int getParent() {
- return this.ParentNode != null ? this.ParentNode.NodeIndex : -1;
- }
-
- public int getYoungerSibling() {
- return this.YoungerSiblingNode != this.ParentNode.FirstChildNode ? this.YoungerSiblingNode.NodeIndex : -1;
- }
-
- public int getOlderSibling() {
- return this != this.ParentNode.FirstChildNode ? this.OlderSiblingNode.NodeIndex : -1;
- }
-
- public int children() {
- return this.NodeChildren;
- }
-
- public int getFirstChild() {
- return this.FirstChildNode != null ? this.FirstChildNode.NodeIndex : -1;
- }
-
- public boolean expanded() {
- return this.IsExpanded;
- }
-
- void drawNode(Graphics g, int wndDrawIdx, Dimension NodeDim, boolean customColor, Color fore, Color back) {
- Color fg = null;
- Rectangle NodeRect = new Rectangle(0, wndDrawIdx * NodeDim.height, NodeDim.width, NodeDim.height);
- FontMetrics m = g.getFontMetrics(g.getFont());
- int ftHeight = (NodeRect.height - 1 + m.getAscent()) / 2;
- NodeRect.x = (this.NodeDepth + 2) * NodeDim.height;
- NodeRect.width = m.stringWidth(this.NodeData.NodeTitle());
- if (this.NodeData.NodeIcon() != null) {
- g.drawImage(this.NodeData.NodeIcon(), NodeRect.x - NodeRect.height + 1, NodeRect.y, NodeRect.height - 2, NodeRect.height - 2, this.Owner);
- } else {
- NodeRect.x -= NodeDim.height;
- }
-
- if (customColor) {
- fg = g.getColor();
- g.setColor(back);
- g.fillRect(NodeRect.x, NodeRect.y, NodeRect.width, NodeRect.height);
- g.setColor(fore);
- }
-
- g.drawString(this.NodeData.NodeTitle(), NodeRect.x, NodeRect.y + ftHeight);
- if (customColor) {
- g.setColor(fg);
- }
-
- this.drawTree(g, wndDrawIdx, NodeDim);
- }
-
- private void drawTree(Graphics g, int wndDrawIdx, Dimension NodeDim) {
- int dim = NodeDim.height;
- Rectangle TreeRect = new Rectangle(dim, dim);
- TreeRect.x = this.NodeDepth * dim;
- TreeRect.y = wndDrawIdx * dim;
- if (this.NodeChildren > 0) {
- Rectangle btn = new Rectangle(TreeRect.x + dim / 4, TreeRect.y + dim / 4, dim / 2, dim / 2);
- if (this.ParentNode.ParentNode != null || this.ParentNode.FirstChildNode != this) {
- g.drawLine(TreeRect.x + dim / 2, TreeRect.y, TreeRect.x + dim / 2, TreeRect.y + dim / 4);
- }
-
- if (this.ParentNode.FirstChildNode != this.YoungerSiblingNode) {
- g.drawLine(TreeRect.x + dim / 2, TreeRect.y + dim / 4 + dim / 2, TreeRect.x + dim / 2, TreeRect.y + dim);
- }
-
- g.drawRect(btn.x, btn.y, btn.width, btn.height);
- g.drawLine(TreeRect.x + dim / 2 + dim / 4, TreeRect.y + dim / 2, TreeRect.x + dim - 1, TreeRect.y + dim / 2);
- g.drawLine(btn.x + 2, btn.y + btn.height / 2, btn.x + btn.width - 2, btn.y + btn.height / 2);
- if (!this.IsExpanded) {
- g.drawLine(btn.x + btn.width / 2, btn.y + 2, btn.x + btn.width / 2, btn.y + btn.height - 2);
- }
- } else {
- if (this.ParentNode.ParentNode != null || this.ParentNode.FirstChildNode != this) {
- g.drawLine(TreeRect.x + dim / 2, TreeRect.y, TreeRect.x + dim / 2, TreeRect.y + dim / 2);
- }
-
- if (this.ParentNode.FirstChildNode != this.YoungerSiblingNode) {
- g.drawLine(TreeRect.x + dim / 2, TreeRect.y + dim / 2, TreeRect.x + dim / 2, TreeRect.y + dim - 1);
- }
-
- g.drawLine(TreeRect.x + dim / 2, TreeRect.y + dim / 2, TreeRect.x + dim - 1, TreeRect.y + dim / 2);
- }
-
- for(OutlineNode nd = this.ParentNode; nd.ParentNode != null; nd = nd.ParentNode) {
- TreeRect.x -= dim;
- if (nd != nd.ParentNode.FirstChildNode.OlderSiblingNode) {
- g.drawLine(TreeRect.x + dim / 2, TreeRect.y, TreeRect.x + dim / 2, TreeRect.y + dim - 1);
- }
- }
-
- }
-
- void getVisibleDescendants(Vector VisibleList) {
- if (this.NodeChildren != 0) {
- if (this.IsExpanded) {
- OutlineNode nd = this.FirstChildNode;
-
- do {
- VisibleList.addElement(nd);
- nd.getVisibleDescendants(VisibleList);
- nd = nd.YoungerSiblingNode;
- } while(nd != this.FirstChildNode);
-
- }
- }
- }
- }
-