home *** CD-ROM | disk | FTP | other *** search
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.LayoutManager;
- import java.awt.Panel;
- import java.awt.Polygon;
- import java.awt.Rectangle;
- import java.awt.Scrollbar;
- import java.util.StringTokenizer;
- import java.util.Vector;
-
- public class TreeView extends Panel {
- public static final int LEFT = 0;
- public static final int RIGHT = 1;
- // $FF: renamed from: UP int
- public static final int field_0 = 2;
- public static final int DOWN = 3;
- public static final int CHILD = 0;
- public static final int NEXT = 1;
- public static final int LAST = 2;
- private TreeNode rootNode;
- private TreeNode mouseOverNode;
- private TreeNode selectedNode;
- private TreeNode topVisibleNode;
- Scrollbar sbV;
- int sbVPosition;
- int sbVWidth;
- long sbVTimer;
- private int count;
- private int viewCount;
- private Color bgHighlightColor;
- private Color fgHighlightColor;
- private Color fgMouseOverColor;
- private Color cLineColor;
- private Color cFolderCColor;
- private Color cFolderOColor;
- private Color cLeafColor;
- private Color cToolTipFC;
- private Color cToolTipBC;
- private Color cMouseOverFrame;
- private int viewHeight;
- private int viewWidth;
- private int viewWidest;
- int cellSize;
- int clickSize;
- int imageInset;
- int textInset;
- int textBaseLine;
- // $FF: renamed from: fm java.awt.FontMetrics
- private FontMetrics field_1;
- long timeMouseDown;
- int doubleClickResolution;
- protected Image im1;
- protected Image imgBG;
- // $FF: renamed from: g1 java.awt.Graphics
- protected Graphics field_2;
- private String[] treeStructure;
- int[] xPts;
- int[] yPts;
- int iStep;
- String sStyle;
- String sMouseOver;
- Font fFont;
- String dblClick;
- String sToolTip;
- TreeNode newNode;
- TreeNode oldNode;
- TreeNode oldSNode;
- String flgBorder;
- boolean mouseOver;
- boolean flgToolTip;
- boolean flgMouseOverRect;
- private Polygon poly;
- // $FF: renamed from: e java.util.Vector
- private Vector field_3;
- // $FF: renamed from: v java.util.Vector
- private Vector field_4;
-
- void TreeView_MouseExit(Event event) {
- if (this.oldSNode != null) {
- if (this.flgToolTip) {
- this.flgToolTip = false;
- this.redraw();
- }
-
- this.mouseOver = false;
- this.drawNodeText(this.oldSNode, (this.field_4.indexOf(this.oldSNode) - this.sbVPosition) * this.cellSize, true);
- ((Component)this).repaint();
- this.oldNode = null;
- }
-
- }
-
- public TreeView() {
- this.sbVWidth = 16;
- this.sbVTimer = -1L;
- this.bgHighlightColor = Color.blue;
- this.fgHighlightColor = Color.white;
- this.fgMouseOverColor = Color.red;
- this.cLineColor = Color.black;
- this.cFolderCColor = Color.black;
- this.cFolderOColor = Color.black;
- this.cLeafColor = Color.black;
- this.cToolTipFC = Color.black;
- this.cToolTipBC = Color.yellow;
- this.cMouseOverFrame = Color.red;
- this.viewHeight = 300;
- this.viewWidth = 300;
- this.cellSize = 16;
- this.clickSize = 8;
- this.imageInset = 3;
- this.textInset = 6;
- this.textBaseLine = 3;
- this.doubleClickResolution = 333;
- this.iStep = 3;
- this.sStyle = "AXAA";
- this.sMouseOver = "none";
- this.fFont = new Font("Dialog", 0, 12);
- this.dblClick = "no";
- this.sToolTip = "yes";
- this.mouseOver = false;
- this.flgToolTip = false;
- this.flgMouseOverRect = false;
- super.setLayout(new BorderLayout());
- ((Container)this).add("East", this.sbV = new Scrollbar(1));
- }
-
- public TreeView(TreeNode head) {
- this();
- this.selectedNode = this.rootNode = head;
- this.count = 1;
- }
-
- public void setBackground(Color c) {
- super.setBackground(c);
- ((Component)this).invalidate();
- }
-
- public void setStyle(String s) {
- this.sStyle = s;
- ((Component)this).invalidate();
- }
-
- public void setMouseOverStyle(String s) {
- this.sMouseOver = s;
- ((Component)this).invalidate();
- }
-
- public void setNode(String s) {
- this.recount();
-
- for(int i = 0; i < this.count; ++i) {
- TreeNode tn = (TreeNode)this.field_3.elementAt(i);
- if (tn.text != null && s.equals(tn.text)) {
- this.selectedNode = tn;
- if (tn.depth > 0) {
- TreeNode tn1 = tn.parent;
- tn1.expand();
-
- while(tn1.parent != null) {
- tn1 = tn1.parent;
- tn1.expand();
- }
-
- tn.parent.expand();
- this.resetVector();
- this.selectedNode = tn;
- }
-
- if (this.viewable(tn)) {
- this.sbVPosition = this.field_4.indexOf(tn);
- this.sbV.setValue(this.sbVPosition);
- }
-
- this.redraw();
- }
- }
-
- }
-
- public void setForeground(Color c) {
- super.setForeground(c);
- ((Component)this).invalidate();
- }
-
- public void setToolTipForeColor(Color c) {
- this.cToolTipFC = c;
- ((Component)this).invalidate();
- }
-
- public void setToolTipBackColor(Color c) {
- this.cToolTipBC = c;
- ((Component)this).invalidate();
- }
-
- public void setFgHilite(Color c) {
- this.fgHighlightColor = c;
- ((Component)this).invalidate();
- }
-
- public void setMouseOverFrameColor(Color c) {
- this.cMouseOverFrame = c;
- ((Component)this).invalidate();
- }
-
- public void setBgHilite(Color c) {
- this.bgHighlightColor = c;
- ((Component)this).invalidate();
- }
-
- public void setMOHilite(Color c) {
- this.fgMouseOverColor = c;
- ((Component)this).invalidate();
- }
-
- public void setLineColor(Color c) {
- this.cLineColor = c;
- ((Component)this).invalidate();
- }
-
- public void setLineStep(int i) {
- this.iStep = i;
- ((Component)this).invalidate();
- }
-
- public void setFolderOColor(Color c) {
- this.cFolderOColor = c;
- ((Component)this).invalidate();
- }
-
- public void setFolderCColor(Color c) {
- this.cFolderCColor = c;
- ((Component)this).invalidate();
- }
-
- public void setLeafColor(Color c) {
- this.cLeafColor = c;
- ((Component)this).invalidate();
- }
-
- public void setBorder(String s) {
- this.flgBorder = s;
- ((Component)this).invalidate();
- }
-
- public void setFont(Font f) {
- if (f != null) {
- this.fFont = f;
- }
-
- ((Component)this).invalidate();
- }
-
- public void setDblClick(String s) {
- this.dblClick = s;
- ((Component)this).invalidate();
- }
-
- public void setToolTip(String s) {
- this.sToolTip = s;
- ((Component)this).invalidate();
- }
-
- public void setBGImage(Image img) {
- this.imgBG = img;
- ((Component)this).invalidate();
- }
-
- public void insert(TreeNode newNode, TreeNode relativeNode, int position, boolean expand) {
- if (newNode != null && relativeNode != null) {
- if (this.exists(relativeNode)) {
- switch (position) {
- case 0:
- this.addChild(newNode, relativeNode, expand);
- return;
- case 1:
- this.addSibling(newNode, relativeNode, expand);
- return;
- case 2:
- this.addSibling(newNode, relativeNode, expand);
- return;
- default:
- }
- }
- }
- }
-
- public TreeNode getRootNode() {
- return this.rootNode;
- }
-
- public TreeNode getMouseOverNode() {
- return this.mouseOverNode;
- }
-
- public int getCount() {
- return this.count;
- }
-
- public int getViewCount() {
- return this.viewCount;
- }
-
- boolean viewable(TreeNode node) {
- for(int i = 0; i < this.viewCount; ++i) {
- if (node == this.field_4.elementAt(i)) {
- return true;
- }
- }
-
- return false;
- }
-
- boolean viewable(String s) {
- if (s == null) {
- return false;
- } else {
- for(int i = 0; i < this.viewCount; ++i) {
- TreeNode tn = (TreeNode)this.field_4.elementAt(i);
- if (tn.text != null && s.equals(tn.text)) {
- return true;
- }
- }
-
- return false;
- }
- }
-
- public boolean exists(TreeNode node) {
- this.recount();
-
- for(int i = 0; i < this.count; ++i) {
- if (node == this.field_3.elementAt(i)) {
- return true;
- }
- }
-
- return false;
- }
-
- public boolean exists(String s) {
- this.recount();
- if (s == null) {
- return false;
- } else {
- for(int i = 0; i < this.count; ++i) {
- TreeNode tn = (TreeNode)this.field_3.elementAt(i);
- if (tn.text != null && s.equals(tn.text)) {
- return true;
- }
- }
-
- return false;
- }
- }
-
- public void append(TreeNode newNode, boolean expand) {
- if (this.rootNode == null) {
- this.rootNode = newNode;
- this.selectedNode = this.rootNode;
- this.count = 1;
- } else {
- this.addSibling(newNode, this.rootNode, expand);
- }
- }
-
- void addChild(TreeNode newNode, TreeNode relativeNode, boolean expand) {
- if (relativeNode.child == null) {
- relativeNode.child = newNode;
- newNode.parent = relativeNode;
- if (expand) {
- relativeNode.expand();
- }
-
- ++this.count;
- } else {
- this.addSibling(newNode, relativeNode.child, expand);
- }
-
- ++relativeNode.numberOfChildren;
- }
-
- void addSibling(TreeNode newNode, TreeNode siblingNode, boolean expand) {
- TreeNode tempNode;
- for(tempNode = siblingNode; tempNode.sibling != null; tempNode = tempNode.sibling) {
- }
-
- tempNode.sibling = newNode;
- newNode.parent = tempNode.parent;
- if (expand) {
- newNode.expand();
- }
-
- ++this.count;
- }
-
- public TreeNode remove(String s) {
- this.recount();
-
- for(int i = 0; i < this.count; ++i) {
- TreeNode tn = (TreeNode)this.field_3.elementAt(i);
- if (tn.text != null && s.equals(tn.text)) {
- this.remove(tn);
- return tn;
- }
- }
-
- return null;
- }
-
- public void removeSelected() {
- if (this.selectedNode != null) {
- this.remove(this.selectedNode);
- }
-
- }
-
- public void remove(TreeNode node) {
- if (this.exists(node)) {
- if (node == this.selectedNode) {
- int index = this.field_4.indexOf(this.selectedNode);
- if (index == -1) {
- index = this.field_3.indexOf(this.selectedNode);
- }
-
- if (index > this.viewCount - 1) {
- index = this.viewCount - 1;
- }
-
- if (index > 0) {
- this.changeSelection((TreeNode)this.field_4.elementAt(index - 1));
- } else if (this.viewCount > 0) {
- this.changeSelection((TreeNode)this.field_4.elementAt(1));
- }
- }
-
- if (node.parent != null) {
- if (node.parent.child == node) {
- if (node.sibling != null) {
- node.parent.child = node.sibling;
- } else {
- node.parent.child = null;
- node.parent.collapse();
- }
- } else {
- TreeNode tn;
- for(tn = node.parent.child; tn.sibling != node; tn = tn.sibling) {
- }
-
- if (node.sibling != null) {
- tn.sibling = node.sibling;
- } else {
- tn.sibling = null;
- }
- }
- } else if (node == this.rootNode) {
- if (node.sibling == null) {
- this.rootNode = null;
- } else {
- this.rootNode = node.sibling;
- }
- } else {
- TreeNode tn;
- for(tn = this.rootNode; tn.sibling != node; tn = tn.sibling) {
- }
-
- if (node.sibling != null) {
- tn.sibling = node.sibling;
- } else {
- tn.sibling = null;
- }
- }
-
- this.recount();
- }
- }
-
- private void recount() {
- this.count = 0;
- this.field_3 = new Vector();
- if (this.rootNode != null) {
- this.rootNode.depth = 0;
- this.traverse(this.rootNode);
- }
-
- }
-
- protected void drawToolTip(Graphics g2, int x, int y, String s, FontMetrics fm, Color bc, Color fc) {
- if (this.sToolTip.toLowerCase().equals("yes")) {
- Dimension d = ((Component)this).size();
- if (x + fm.stringWidth(s) > d.width - this.sbVWidth && y > 0) {
- String sWord = "";
- String tmpS = "";
- String tmpS1 = "";
- String tmpS2 = "";
- String tmpS3 = "";
- int pos = 0;
- x = 0;
- pos = s.indexOf(32, pos);
- if (pos == -1) {
- for(int i = 0; i < s.length(); ++i) {
- if (x + fm.stringWidth(tmpS1) < d.width - (this.sbVWidth + 10)) {
- tmpS1 = tmpS1 + s.charAt(i);
- } else {
- tmpS2 = tmpS2 + s.charAt(i);
- }
- }
- } else {
- StringTokenizer parser = new StringTokenizer(s.trim(), " ");
-
- while(parser.hasMoreTokens()) {
- try {
- sWord = parser.nextToken();
- if (tmpS.equals("")) {
- tmpS = sWord;
- } else {
- tmpS = tmpS + " " + sWord;
- }
-
- if (x + fm.stringWidth(tmpS) > d.width - (this.sbVWidth + 10)) {
- if (!tmpS1.trim().equals("")) {
- tmpS2 = tmpS3;
- break;
- }
-
- tmpS1 = tmpS3;
- tmpS = "";
- tmpS3 = "";
- }
-
- if (tmpS3.equals("")) {
- tmpS3 = sWord;
- } else {
- tmpS3 = tmpS3 + " " + sWord;
- }
- } catch (Exception var16) {
- }
- }
-
- if (!tmpS3.equals("")) {
- if (tmpS1.trim().equals("")) {
- tmpS1 = tmpS3;
- } else {
- tmpS2 = tmpS3;
- }
- }
- }
-
- if (y + fm.getHeight() > d.height) {
- y = d.height - fm.getHeight() - 2;
- }
-
- g2.setColor(bc);
- if (tmpS2.equals("")) {
- g2.fillRect(x, y, d.width - 1 - x - this.sbVWidth, fm.getHeight() + 2);
- g2.setColor(fc);
- g2.drawRect(x, y, d.width - 1 - x - this.sbVWidth, fm.getHeight() + 2);
- this.field_2.drawString(tmpS1, x + 5, y + this.cellSize - this.textBaseLine);
- } else {
- g2.fillRect(x, y, d.width - 1 - x - this.sbVWidth, fm.getHeight() * 2 + 2);
- g2.setColor(fc);
- g2.drawRect(x, y, d.width - 1 - x - this.sbVWidth, fm.getHeight() * 2 + 2);
- this.field_2.drawString(tmpS1, x + 5, y + this.cellSize - this.textBaseLine);
- this.field_2.drawString(tmpS2, x + 5, y + fm.getHeight() + this.cellSize - this.textBaseLine);
- }
-
- this.flgToolTip = true;
- }
-
- }
- }
-
- private void traverse(TreeNode node) {
- ++this.count;
- this.field_3.addElement(node);
- if (node.child != null) {
- node.child.depth = node.depth + 1;
- this.traverse(node.child);
- }
-
- if (node.sibling != null) {
- node.sibling.depth = node.depth;
- this.traverse(node.sibling);
- }
-
- }
-
- private void resetVector() {
- this.field_4 = new Vector(this.count);
- this.viewWidest = 30;
- if (this.count < 1) {
- this.viewCount = 0;
- } else {
- this.rootNode.depth = 0;
- this.vectorize(this.rootNode);
- this.viewCount = this.field_4.size();
- }
- }
-
- private void vectorize(TreeNode node) {
- if (node != null) {
- this.field_4.addElement(node);
- if (node.isExpanded()) {
- node.child.depth = node.depth + 1;
- this.vectorize(node.child);
- }
-
- if (node.sibling != null) {
- node.sibling.depth = node.depth;
- this.vectorize(node.sibling);
- }
-
- }
- }
-
- public boolean handleEvent(Event event) {
- if (event.target == this.sbV) {
- if (event.arg == null) {
- return false;
- }
-
- if (this.sbVPosition != (Integer)event.arg) {
- this.sbVPosition = (Integer)event.arg;
- if (this.sbVPosition < 0) {
- this.sbVPosition = 0;
- } else {
- this.redraw();
- }
- }
- }
-
- if (event.target == this && event.id == 505) {
- this.TreeView_MouseExit(event);
- return true;
- } else {
- return super.handleEvent(event);
- }
- }
-
- public boolean mouseMove(Event event, int x, int y) {
- try {
- int index = y / this.cellSize + this.sbVPosition;
- if (index > this.viewCount - 1) {
- if (this.oldSNode != null) {
- this.mouseOver = false;
- this.drawNodeText(this.oldSNode, (this.field_4.indexOf(this.oldSNode) - this.sbVPosition) * this.cellSize, true);
- ((Component)this).repaint();
- }
-
- this.oldNode = null;
- this.mouseOverNode = null;
- this.flgToolTip = false;
- this.redraw();
- }
-
- this.newNode = (TreeNode)this.field_4.elementAt(index);
- if (this.newNode != this.oldNode) {
- if (this.flgToolTip) {
- this.flgToolTip = false;
- this.redraw();
- }
-
- if (this.flgMouseOverRect) {
- this.flgMouseOverRect = false;
- this.redraw();
- }
-
- if (this.oldSNode != null) {
- this.mouseOver = false;
- this.drawNodeText(this.oldSNode, (this.field_4.indexOf(this.oldSNode) - this.sbVPosition) * this.cellSize, true);
- }
-
- this.mouseOver = true;
- this.drawNodeText(this.newNode, (this.field_4.indexOf(this.newNode) - this.sbVPosition) * this.cellSize, true);
- ((Component)this).repaint();
- this.oldNode = this.newNode;
- }
-
- ((Component)this).repaint();
- } catch (Exception var5) {
- }
-
- return super.mouseMove(event, x, y);
- }
-
- public boolean mouseDown(Event event, int x, int y) {
- int index = y / this.cellSize + this.sbVPosition;
- if (index > this.viewCount - 1) {
- this.mouseOverNode = null;
- return false;
- } else {
- TreeNode oldNode = this.selectedNode;
- TreeNode newNode = (TreeNode)this.field_4.elementAt(index);
- int newDepth = newNode.getDepth();
- Rectangle toggleBox = new Rectangle(this.cellSize * newDepth + this.cellSize / 4, (index - this.sbVPosition) * this.cellSize + this.clickSize / 2, this.clickSize, this.clickSize);
- if (toggleBox.inside(x, y)) {
- newNode.toggle();
- this.redraw();
- } else {
- this.changeSelection(newNode);
- if (this.dblClick.toLowerCase().equals("yes")) {
- if (newNode == oldNode && event.when - this.timeMouseDown < (long)this.doubleClickResolution) {
- newNode.toggle();
- this.redraw();
- this.sendActionEvent(event);
- return false;
- }
-
- this.timeMouseDown = event.when;
- this.redraw();
- } else {
- if (newNode != oldNode || event.when - this.timeMouseDown >= (long)this.doubleClickResolution) {
- newNode.toggle();
- this.redraw();
- this.sendActionEvent(event);
- return false;
- }
-
- this.timeMouseDown = event.when;
- }
- }
-
- return true;
- }
- }
-
- public boolean keyDown(Event event, int key) {
- int index = this.field_4.indexOf(this.selectedNode);
- switch (key) {
- case 10:
- TreeNode newNode = (TreeNode)this.field_4.elementAt(index);
- this.changeSelection(newNode);
- newNode.toggle();
- this.redraw();
- event.id = 501;
- event.arg = new String(this.selectedNode.getText());
- return false;
- case 1006:
- if (this.selectedNode.isExpanded()) {
- this.selectedNode.toggle();
- this.redraw();
- break;
- }
- case 1004:
- if (index > 0) {
- --index;
- this.changeSelection((TreeNode)this.field_4.elementAt(index));
- this.redraw();
- ((Component)this).requestFocus();
- }
- break;
- case 1007:
- if (this.selectedNode.isExpandable() && !this.selectedNode.isExpanded()) {
- this.selectedNode.toggle();
- this.redraw();
- break;
- } else if (!this.selectedNode.isExpandable()) {
- break;
- }
- case 1005:
- if (index < this.viewCount - 1) {
- ++index;
- this.changeSelection((TreeNode)this.field_4.elementAt(index));
- this.redraw();
- ((Component)this).requestFocus();
- }
- }
-
- return false;
- }
-
- private void sendActionEvent(Event event) {
- int id = event.id;
- Object arg = event.arg;
- event.id = 1001;
- event.arg = new String(this.selectedNode.getText());
- ((Component)this).postEvent(event);
- event.id = id;
- event.arg = arg;
- }
-
- public TreeNode getSelectedNode() {
- return this.selectedNode;
- }
-
- public String getSelectedText() {
- return this.selectedNode == null ? null : this.selectedNode.getText();
- }
-
- private void changeSelection(TreeNode node) {
- if (node != this.selectedNode) {
- TreeNode oldNode = this.selectedNode;
- this.selectedNode = node;
- this.drawNodeText(oldNode, (this.field_4.indexOf(oldNode) - this.sbVPosition) * this.cellSize, true);
- this.drawNodeText(node, (this.field_4.indexOf(node) - this.sbVPosition) * this.cellSize, true);
- int index = this.field_4.indexOf(this.selectedNode);
- if (index < this.sbVPosition) {
- --this.sbVPosition;
- this.sbV.setValue(this.sbVPosition);
- this.redraw();
- } else if (index >= this.sbVPosition + (this.viewHeight - this.cellSize / 2) / this.cellSize) {
- ++this.sbVPosition;
- this.sbV.setValue(this.sbVPosition);
- this.redraw();
- } else {
- ((Component)this).repaint();
- }
- }
- }
-
- public void update(Graphics g) {
- this.paint(g);
- }
-
- public void paint(Graphics g) {
- Dimension d = ((Component)this).size();
- if (d.width == this.viewWidth && d.height == this.viewHeight) {
- if (Beans.isDesignTime()) {
- this.resetVector();
- ((Container)this).layout();
- this.drawTree();
- }
- } else {
- this.redraw();
- }
-
- g.drawImage(this.im1, 0, 0, this);
- }
-
- public void redraw() {
- this.resetVector();
- if (this.viewCount > this.viewHeight / this.cellSize) {
- System.out.println("viewCount: " + this.viewCount + " | viewHeight/cellSize: " + this.viewHeight / this.cellSize);
- this.sbV.setValues(this.sbVPosition, this.viewHeight / this.cellSize, 0, this.viewCount - 2);
- this.sbV.setPageIncrement(1);
- this.sbVWidth = 16;
- ((Component)this).getParent().paintAll(((Component)this).getParent().getGraphics());
- this.sbV.show();
- ((Container)this).layout();
- } else {
- this.sbV.hide();
- this.sbVWidth = 0;
- this.sbVPosition = 0;
- ((Container)this).layout();
- }
-
- this.drawTree();
- ((Component)this).repaint();
- }
-
- public void drawTree() {
- Dimension d = ((Component)this).size();
- if (d.width != this.viewWidth || d.height != this.viewHeight || this.field_2 == null) {
- this.im1 = ((Component)this).createImage(d.width, d.height);
- if (this.field_2 != null) {
- this.field_2.dispose();
- }
-
- this.field_2 = this.im1.getGraphics();
- this.viewWidth = d.width;
- this.viewHeight = d.height;
- }
-
- this.field_2.setFont(this.fFont);
- this.setFont(this.fFont);
- this.field_1 = ((Component)this).getFontMetrics(this.fFont);
- this.field_2.setColor(((Component)this).getBackground());
- if (this.imgBG != null) {
- for(int x = 0; x < d.width; x += this.imgBG.getWidth(this)) {
- for(int i = 0; i < d.height; i += this.imgBG.getHeight(this)) {
- this.field_2.drawImage(this.imgBG, x, i, this.imgBG.getWidth(this), this.imgBG.getHeight(this), Color.black, this);
- }
- }
-
- ((Component)this).repaint();
- } else {
- this.field_2.fillRect(0, 0, this.viewWidth, this.viewHeight);
- }
-
- int lastOne = this.sbVPosition + this.viewHeight / this.cellSize;
- if (lastOne > this.viewCount) {
- lastOne = this.viewCount;
- }
-
- for(int i = this.sbVPosition; i < lastOne; ++i) {
- TreeNode node = (TreeNode)this.field_4.elementAt(i);
- int x = this.cellSize * (node.depth + 1);
- int y = (i - this.sbVPosition) * this.cellSize;
- if (this.sStyle.charAt(2) != 'X') {
- this.field_2.setColor(((Component)this).getForeground());
- if (node.sibling != null) {
- int k = this.field_4.indexOf(node.sibling) - i;
- if (k > lastOne) {
- k = lastOne;
- }
-
- this.drawDotLine(x - this.cellSize / 2, y + this.cellSize / 2, x - this.cellSize / 2, y + this.cellSize / 2 + k * this.cellSize);
- }
-
- for(int m = 0; m < i; ++m) {
- TreeNode sib = (TreeNode)this.field_4.elementAt(m);
- if (sib.sibling == node && m < this.sbVPosition) {
- this.drawDotLine(x - this.cellSize / 2, 0, x - this.cellSize / 2, y + this.cellSize / 2);
- }
- }
-
- if (node.isExpanded()) {
- this.drawDotLine(x + this.cellSize / 2, y + this.cellSize, x + this.cellSize / 2, y + this.cellSize + this.cellSize / 2);
- }
-
- this.field_2.setColor(((Component)this).getForeground());
- this.drawDotLine(x - this.cellSize / 2, y + this.cellSize / 2, x + this.cellSize / 2, y + this.cellSize / 2);
- }
-
- if (this.sStyle.charAt(0) == 'A') {
- if (node.isExpandable()) {
- this.field_2.setColor(((Component)this).getBackground());
- this.field_2.fillRect(this.cellSize * node.depth + this.cellSize / 4, y + this.clickSize / 2, this.clickSize, this.clickSize);
- this.field_2.setColor(this.cLineColor);
- this.field_2.drawRect(this.cellSize * node.depth + this.cellSize / 4, y + this.clickSize / 2, this.clickSize, this.clickSize);
- this.field_2.drawLine(this.cellSize * node.depth + this.cellSize / 4 + 2, y + this.cellSize / 2, this.cellSize * node.depth + this.cellSize / 4 + this.clickSize - 2, y + this.cellSize / 2);
- if (!node.isExpanded()) {
- this.field_2.drawLine(this.cellSize * node.depth + this.cellSize / 2, y + this.clickSize / 2 + 2, this.cellSize * node.depth + this.cellSize / 2, y + this.clickSize / 2 + this.clickSize - 2);
- }
- }
- } else if (node.isExpandable()) {
- this.xPts = new int[4];
- this.yPts = new int[4];
- if (!node.isExpanded()) {
- if (this.sStyle.charAt(0) == 'E' || this.sStyle.charAt(0) == 'F') {
- this.field_2.setColor(this.cFolderCColor);
- this.xPts[0] = this.cellSize * node.depth + this.cellSize / 4 + 1;
- this.xPts[1] = this.cellSize * node.depth + this.cellSize / 4 + this.clickSize;
- this.xPts[2] = this.cellSize * node.depth + this.cellSize / 4 + 1;
- this.xPts[3] = this.cellSize * node.depth + this.cellSize / 4 + 1;
- this.yPts[0] = y + 1;
- this.yPts[1] = y + this.cellSize / 2;
- this.yPts[2] = y + this.cellSize - 1;
- this.yPts[3] = y + 1;
- this.poly = new Polygon(this.xPts, this.yPts, this.xPts.length);
- this.field_2.fillPolygon(this.poly);
- }
-
- if (this.sStyle.charAt(0) == 'B' || this.sStyle.charAt(0) == 'C' || this.sStyle.charAt(0) == 'D') {
- this.field_2.setColor(this.cFolderCColor);
- this.field_2.fillRect(this.cellSize * node.depth + this.cellSize / 4, y + this.clickSize / 2, this.clickSize + 2, this.clickSize + 2);
- }
- } else {
- if (this.sStyle.charAt(0) == 'C' || this.sStyle.charAt(0) == 'E') {
- this.field_2.setColor(this.cFolderOColor);
- this.xPts[0] = this.cellSize * node.depth + this.cellSize / 4 - 2;
- this.xPts[1] = this.cellSize * node.depth + this.cellSize / 4 - 2 + this.clickSize + 2;
- this.xPts[2] = this.cellSize * node.depth + this.cellSize / 4 - 2 + (this.clickSize + 2) / 2;
- this.xPts[3] = this.cellSize * node.depth + this.cellSize / 4 - 2;
- this.yPts[0] = y + 3;
- this.yPts[1] = y + 3;
- this.yPts[2] = y + this.cellSize - 3;
- this.yPts[3] = y + 3;
- this.poly = new Polygon(this.xPts, this.yPts, this.xPts.length);
- this.field_2.fillPolygon(this.poly);
- }
-
- if (this.sStyle.charAt(0) == 'D' || this.sStyle.charAt(0) == 'F') {
- this.field_2.setColor(this.cFolderOColor);
- this.xPts[0] = this.cellSize * node.depth + this.cellSize / 4 - 2 + (this.clickSize + 2) / 2;
- this.xPts[1] = this.cellSize * node.depth + this.cellSize / 4 - 2 + this.clickSize + 2;
- this.xPts[2] = this.cellSize * node.depth + this.cellSize / 4 - 2;
- this.xPts[3] = this.cellSize * node.depth + this.cellSize / 4 - 2 + (this.clickSize + 2) / 2;
- this.yPts[0] = y + 3;
- this.yPts[1] = y + this.cellSize - 3;
- this.yPts[2] = y + this.cellSize - 3;
- this.yPts[3] = y + 3;
- this.poly = new Polygon(this.xPts, this.yPts, this.xPts.length);
- this.field_2.fillPolygon(this.poly);
- }
-
- if (this.sStyle.charAt(0) == 'B') {
- this.field_2.setColor(this.cFolderOColor);
- this.xPts[0] = this.cellSize * node.depth + this.cellSize / 4 + 1;
- this.xPts[1] = this.cellSize * node.depth + this.cellSize / 4 + this.clickSize;
- this.xPts[2] = this.cellSize * node.depth + this.cellSize / 4 + 1;
- this.xPts[3] = this.cellSize * node.depth + this.cellSize / 4 + 1;
- this.yPts[0] = y + 1;
- this.yPts[1] = y + this.cellSize / 2;
- this.yPts[2] = y + this.cellSize - 1;
- this.yPts[3] = y + 1;
- this.poly = new Polygon(this.xPts, this.yPts, this.xPts.length);
- this.field_2.fillPolygon(this.poly);
- }
- }
- } else if (this.sStyle.charAt(1) == 'A') {
- this.field_2.setColor(this.cLeafColor);
- this.field_2.fillRect(this.cellSize * node.depth + this.cellSize / 4, y + this.clickSize / 2, this.clickSize, this.clickSize);
- }
-
- Image nodeImage = node.getImage();
- if (this.sStyle.charAt(3) == 'A') {
- if (this.sStyle.charAt(0) != 'X' && this.sStyle.charAt(2) == 'X') {
- --x;
- }
-
- if (this.sStyle.charAt(2) == 'X' && this.sStyle.charAt(0) == 'X') {
- x -= 10;
- }
-
- if (nodeImage != null) {
- this.field_2.drawImage(nodeImage, x + this.imageInset, y, this);
- }
- }
-
- if (node.text != null) {
- this.drawNodeText(node, y, node == this.selectedNode);
- }
- }
-
- if (this.flgBorder.toLowerCase().equals("yes")) {
- this.field_2.setColor(((Component)this).getForeground());
- this.field_2.drawRect(0, 0, this.viewWidth - this.sbVWidth - 1, this.viewHeight - 1);
- }
-
- }
-
- private void drawNodeText(TreeNode node, int yPosition, boolean eraseBackground) {
- int depth = node.depth;
- int textOffset = (depth + 1) * this.cellSize + this.cellSize + this.textInset;
- if (this.sStyle.charAt(3) != 'A') {
- textOffset -= 15;
- if (this.sStyle.charAt(2) == 'X') {
- textOffset -= 5;
- }
- } else if (this.sStyle.charAt(0) == 'X' && this.sStyle.charAt(2) == 'X') {
- textOffset -= 5;
- }
-
- Color fg;
- if (node == this.selectedNode) {
- fg = this.fgHighlightColor;
- Color bg = this.bgHighlightColor;
- this.mouseOverNode = node;
- if (eraseBackground) {
- this.field_2.setColor(bg);
- this.field_2.fillRect(textOffset - 1, yPosition + 1, this.field_1.stringWidth(node.text) + 4, this.cellSize - 1);
- }
- } else {
- fg = ((Component)this).getForeground();
- Color bg = ((Component)this).getBackground();
- if (this.mouseOver) {
- fg = this.fgMouseOverColor;
- this.mouseOverNode = node;
- this.oldSNode = node;
- }
- }
-
- this.field_2.setColor(fg);
- this.field_2.drawString(node.text, textOffset, yPosition + this.cellSize - this.textBaseLine);
- if (this.mouseOver) {
- if (this.sMouseOver.toLowerCase().equals("rect")) {
- this.field_2.setColor(this.cMouseOverFrame);
- this.field_2.drawRect(textOffset - 1, yPosition + 1, this.field_1.stringWidth(node.text) + 1, this.cellSize - 1);
- this.flgMouseOverRect = true;
- }
-
- if (this.sMouseOver.toLowerCase().equals("line")) {
- this.field_2.setColor(this.cMouseOverFrame);
- this.field_2.drawRect(textOffset - 1, yPosition + 1 + this.field_1.getHeight(), this.field_1.stringWidth(node.text) + 1, 1);
- this.flgMouseOverRect = true;
- }
-
- this.drawToolTip(this.field_2, textOffset - 1, yPosition + 1, node.text, this.field_1, this.cToolTipBC, this.cToolTipFC);
- this.mouseOver = false;
- }
-
- }
-
- private void drawDotLine(int x0, int y0, int x1, int y1) {
- this.field_2.setColor(this.cLineColor);
- int iStep1;
- if (this.sStyle.charAt(2) == 'A') {
- iStep1 = this.iStep;
- } else {
- iStep1 = 1;
- }
-
- if (y0 == y1) {
- for(int i = x0; i < x1; i += iStep1) {
- this.field_2.drawLine(i, y0, i, y1);
- }
-
- } else {
- for(int i = y0; i < y1; i += iStep1) {
- this.field_2.drawLine(x0, i, x1, i);
- }
-
- }
- }
-
- public void setTreeStructure(String[] s) {
- this.rootNode = this.selectedNode = this.topVisibleNode = null;
- this.treeStructure = s;
-
- try {
- this.parseTreeStructure();
- } catch (InvalidTreeNodeException e) {
- System.out.println(e);
- }
- }
-
- public String[] getTreeStructure() {
- return this.treeStructure;
- }
-
- private void parseTreeStructure() throws InvalidTreeNodeException {
- String[] tempStructure = null;
- String entry = null;
- tempStructure = this.treeStructure;
- entry = tempStructure[0];
- if (this.findLastPreSpace(entry) > -1) {
- throw new InvalidTreeNodeException();
- } else {
- TreeNode node = new TreeNode(entry.trim());
- node.setDepth(0);
- this.append(node, false);
-
- for(int i = 1; i < tempStructure.length; ++i) {
- entry = tempStructure[i];
- int indentLevel = this.findLastPreSpace(entry);
- if (indentLevel == -1) {
- throw new InvalidTreeNodeException();
- }
-
- TreeNode currentNode = this.rootNode;
-
- for(int j = 0; j < indentLevel; ++j) {
- int numberOfChildren = currentNode.numberOfChildren;
- TreeNode tempNode = null;
- if (numberOfChildren > 0) {
- for(tempNode = currentNode.child; tempNode.sibling != null; tempNode = tempNode.sibling) {
- }
- }
-
- if (tempNode == null) {
- break;
- }
-
- currentNode = tempNode;
- }
-
- int diff = indentLevel - currentNode.getDepth();
- if (diff > 1) {
- throw new InvalidTreeNodeException();
- }
-
- node = new TreeNode(entry.trim());
- node.setDepth(indentLevel);
- if (diff == 1) {
- this.insert(node, currentNode, 0, false);
- } else {
- this.insert(node, currentNode, 1, false);
- }
- }
-
- }
- }
-
- private int findLastPreSpace(String s) {
- int length = s.length();
- if (s.charAt(0) != ' ') {
- return -1;
- } else {
- for(int i = 1; i < length; ++i) {
- if (s.charAt(i) != ' ') {
- return i;
- }
- }
-
- return -1;
- }
- }
-
- public synchronized Dimension preferredSize() {
- return new Dimension(175, 125);
- }
-
- public synchronized Dimension minimumSize() {
- return new Dimension(50, 50);
- }
-
- public void setLayout(LayoutManager lm) {
- }
- }
-