home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.awt;
-
- 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.Rectangle;
- import java.awt.Scrollbar;
- import java.util.Vector;
- import symantec.beans.Beans;
-
- public strictfp class TreeView extends Panel {
- public static final int CHILD = 0;
- public static final int NEXT = 1;
- public static final int LAST = 2;
- public static final int SEL_CHANGED = 1006;
- private TreeNode rootNode;
- private TreeNode selectedNode;
- private TreeNode topVisibleNode;
- Scrollbar sbV;
- int sbVPosition;
- int sbVWidth;
- private boolean sbVShow;
- long sbVTimer;
- Scrollbar sbH;
- int sbHPosition;
- int sbHHeight;
- private int sbHSize;
- private int newWidth;
- private boolean sbHShow;
- private int count;
- private int viewCount;
- private int sbHLineIncrement;
- private Color bgHighlightColor;
- private Color fgHighlightColor;
- private int viewHeight;
- private int viewWidth;
- int cellSize;
- int clickSize;
- int imageInset;
- int textInset;
- int textBaseLine;
- // $FF: renamed from: fm java.awt.FontMetrics
- private FontMetrics field_0;
- long timeMouseDown;
- int doubleClickResolution;
- protected boolean isSun1_1;
- boolean forceRedraw;
- protected Image im1;
- // $FF: renamed from: g1 java.awt.Graphics
- protected Graphics field_1;
- // $FF: renamed from: e java.util.Vector
- private Vector field_2;
- // $FF: renamed from: v java.util.Vector
- private Vector field_3;
-
- public TreeView() {
- this.sbVShow = false;
- this.sbVTimer = -1L;
- this.sbHShow = false;
- this.sbHLineIncrement = 4;
- this.bgHighlightColor = Color.blue;
- this.fgHighlightColor = Color.white;
- 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.forceRedraw = false;
- super.setLayout((LayoutManager)null);
- this.sbV = new Scrollbar(1);
- this.sbV.hide();
- ((Container)this).add(this.sbV);
- this.sbH = new Scrollbar(0);
- this.sbH.hide();
- ((Container)this).add(this.sbH);
- this.isSun1_1 = System.getProperty("java.vendor").startsWith("Sun Microsystems Inc.") && (System.getProperty("java.version").startsWith("11") || System.getProperty("java.version").startsWith("1.1"));
- }
-
- public TreeView(TreeNode head) {
- this();
- this.selectedNode = this.rootNode = head;
- this.count = 1;
- }
-
- public void setBackground(Color c) {
- super.setBackground(c);
- ((Component)this).repaint();
- }
-
- public Color getBackground() {
- return super.getBackground();
- }
-
- public void setForeground(Color c) {
- super.setForeground(c);
- ((Component)this).repaint();
- }
-
- public Color getForeground() {
- return super.getForeground();
- }
-
- public void setFgHilite(Color c) {
- this.fgHighlightColor = c;
- ((Component)this).repaint();
- }
-
- public Color getFgHilite() {
- return this.fgHighlightColor;
- }
-
- public void setBgHilite(Color c) {
- this.bgHighlightColor = c;
- this.forceRedraw = true;
- ((Component)this).repaint();
- }
-
- public Color getBgHilite() {
- return this.bgHighlightColor;
- }
-
- public void insert(TreeNode newNode, TreeNode relativeNode, int position) {
- if (newNode != null && relativeNode != null) {
- if (this.exists(relativeNode)) {
- switch (position) {
- case 0:
- this.addChild(newNode, relativeNode);
- return;
- case 1:
- this.addSibling(newNode, relativeNode, false);
- return;
- case 2:
- this.addSibling(newNode, relativeNode, true);
- return;
- default:
- }
- }
- }
- }
-
- public TreeNode getRootNode() {
- return this.rootNode;
- }
-
- 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_3.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_3.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_2.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_2.elementAt(i);
- if (tn.text != null && s.equals(tn.text)) {
- return true;
- }
- }
-
- return false;
- }
- }
-
- public void append(TreeNode newNode) {
- if (this.rootNode == null) {
- this.rootNode = newNode;
- this.selectedNode = this.rootNode;
- this.count = 1;
- this.forceRedraw = true;
- } else {
- this.addSibling(newNode, this.rootNode, true);
- }
- }
-
- void addChild(TreeNode newNode, TreeNode relativeNode) {
- if (relativeNode.child == null) {
- relativeNode.child = newNode;
- newNode.parent = relativeNode;
- ++this.count;
- this.forceRedraw = true;
- } else {
- this.addSibling(newNode, relativeNode.child, true);
- }
-
- ++relativeNode.numberOfChildren;
- }
-
- void addSibling(TreeNode newNode, TreeNode siblingNode) {
- this.addSibling(newNode, siblingNode, true);
- }
-
- void addSibling(TreeNode newNode, TreeNode siblingNode, boolean asLastSibling) {
- if (asLastSibling) {
- TreeNode tempNode;
- for(tempNode = siblingNode; tempNode.sibling != null; tempNode = tempNode.sibling) {
- }
-
- tempNode.sibling = newNode;
- } else {
- newNode.sibling = siblingNode.sibling;
- siblingNode.sibling = newNode;
- }
-
- newNode.parent = siblingNode.parent;
- ++this.count;
- this.forceRedraw = true;
- }
-
- public TreeNode remove(String s) {
- this.recount();
-
- for(int i = 0; i < this.count; ++i) {
- TreeNode tn = (TreeNode)this.field_2.elementAt(i);
- if (tn.text != null && s.equals(tn.text)) {
- this.remove(tn);
- this.forceRedraw = true;
- 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_3.indexOf(this.selectedNode);
- if (index == -1) {
- index = this.field_2.indexOf(this.selectedNode);
- }
-
- if (index > this.viewCount - 1) {
- index = this.viewCount - 1;
- }
-
- if (index > 0) {
- this.changeSelection((TreeNode)this.field_3.elementAt(index - 1));
- } else if (this.viewCount > 1) {
- this.changeSelection((TreeNode)this.field_3.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();
- this.forceRedraw = true;
- }
- }
-
- public void printTree(TreeNode node) {
- if (node != null) {
- System.out.println(node.text);
- this.printTree(node.child);
- this.printTree(node.sibling);
- }
- }
-
- private void recount() {
- this.count = 0;
- this.field_2 = new Vector();
- if (this.rootNode != null) {
- this.rootNode.depth = 0;
- this.traverse(this.rootNode);
- }
-
- }
-
- private void traverse(TreeNode node) {
- ++this.count;
- this.field_2.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_3 = new Vector(this.count);
- if (this.count < 1) {
- this.viewCount = 0;
- } else {
- this.rootNode.depth = 0;
- this.vectorize(this.rootNode, true, this.field_3);
- this.viewCount = this.field_3.size();
- }
- }
-
- private void vectorize(TreeNode node, boolean respectExpanded, Vector nodeVector) {
- if (node != null) {
- nodeVector.addElement(node);
- if (!respectExpanded && node.child != null || node.isExpanded()) {
- node.child.depth = node.depth + 1;
- this.vectorize(node.child, respectExpanded, nodeVector);
- }
-
- if (node.sibling != null) {
- node.sibling.depth = node.depth;
- this.vectorize(node.sibling, respectExpanded, nodeVector);
- }
-
- }
- }
-
- private void debugVector() {
- this.field_3.size();
-
- for(int i = 0; i < this.count; ++i) {
- TreeNode node = (TreeNode)this.field_3.elementAt(i);
- System.out.println(node.text);
- }
-
- }
-
- public boolean handleEvent(Event e) {
- if (e.target == this.sbV && e.arg != null && this.sbVPosition != this.sbV.getValue()) {
- this.sbVPosition = this.sbV.getValue();
- this.forceRedraw = true;
- ((Component)this).repaint();
- }
-
- if (e.target == this.sbH && e.arg != null && this.sbHPosition != this.sbH.getValue()) {
- this.sbHPosition = this.sbH.getValue();
- ((Component)this).repaint();
- }
-
- return (e.target == this.sbV || e.target == this.sbH) && e.id == 501 ? true : super.handleEvent(e);
- }
-
- public boolean mouseDown(Event event, int x, int y) {
- ((Component)this).requestFocus();
- int index = y / this.cellSize + this.sbVPosition;
- if (index > this.viewCount - 1) {
- return false;
- } else {
- TreeNode oldNode = this.selectedNode;
- TreeNode newNode = (TreeNode)this.field_3.elementAt(index);
- int newDepth = newNode.getDepth();
- this.changeSelection(newNode);
- 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 + this.sbHPosition, y)) {
- newNode.toggle();
- this.sendActionEvent(event);
- this.forceRedraw = true;
- ((Component)this).repaint();
- } else {
- if (newNode == oldNode && event.when - this.timeMouseDown < (long)this.doubleClickResolution) {
- newNode.toggle();
- this.sendActionEvent(event);
- this.forceRedraw = true;
- ((Component)this).repaint();
- return false;
- }
-
- this.timeMouseDown = event.when;
- }
-
- return true;
- }
- }
-
- public boolean keyDown(Event event, int key) {
- int index = this.field_3.indexOf(this.selectedNode);
- switch (key) {
- case 10:
- case 13:
- this.sendActionEvent(event);
- ((Component)this).requestFocus();
- break;
- case 1006:
- if (event.modifiers == 2) {
- if (this.sbHPosition > 0) {
- this.sbH.setValue(Math.max(this.sbHPosition -= this.sbHLineIncrement, 0));
- ((Component)this).repaint();
- }
- break;
- } else if (this.selectedNode.isExpanded()) {
- this.selectedNode.toggle();
- this.forceRedraw = true;
- ((Component)this).repaint();
- break;
- }
- case 1004:
- if (index > 0) {
- --index;
- this.changeSelection((TreeNode)this.field_3.elementAt(index));
- ((Component)this).requestFocus();
- }
- break;
- case 1007:
- if (event.modifiers == 2) {
- int max = this.sbH.getMaximum() - (this.isSun1_1 ? ((Component)this).size().width - this.sbVWidth : 0);
- if (this.sbHShow && this.sbHPosition < max) {
- this.sbH.setValue(Math.min(this.sbHPosition += this.sbHLineIncrement, max));
- ((Component)this).repaint();
- }
- break;
- } else if (this.selectedNode.isExpandable() && !this.selectedNode.isExpanded()) {
- this.selectedNode.toggle();
- this.sendActionEvent(event);
- this.forceRedraw = true;
- ((Component)this).repaint();
- break;
- } else if (!this.selectedNode.isExpandable()) {
- break;
- }
- case 1005:
- if (index < this.viewCount - 1) {
- ++index;
- this.changeSelection((TreeNode)this.field_3.elementAt(index));
- ((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_3.indexOf(oldNode) - this.sbVPosition) * this.cellSize, true);
- this.drawNodeText(node, (this.field_3.indexOf(node) - this.sbVPosition) * this.cellSize, true);
- int index = this.field_3.indexOf(this.selectedNode);
- ((Component)this).postEvent(new Event(this, 1006, this.selectedNode));
- if (index < this.sbVPosition) {
- --this.sbVPosition;
- this.sbV.setValue(this.sbVPosition);
- this.forceRedraw = true;
- ((Component)this).repaint();
- } else if (index >= this.sbVPosition + (this.viewHeight - this.sbHHeight) / this.cellSize) {
- ++this.sbVPosition;
- this.sbV.setValue(this.sbVPosition);
- this.forceRedraw = true;
- ((Component)this).repaint();
- } else {
- ((Component)this).repaint();
- }
- }
- }
-
- public void update(Graphics g) {
- this.paint(g);
- }
-
- public void paint(Graphics g) {
- Dimension s = ((Component)this).size();
- if (s.width == this.viewWidth && s.height == this.viewHeight && !this.forceRedraw) {
- if (Beans.isDesignTime()) {
- this.resetVector();
- this.newWidth = this.compWidth(g);
- this.drawTree();
- }
- } else {
- this.redraw(g);
- }
-
- g.translate(-this.sbHPosition, 0);
- g.clearRect(this.sbHPosition, 0, s.width - this.sbVWidth, s.height - this.sbHHeight);
- if (this.sbVShow && this.sbHShow) {
- g.setColor(Color.lightGray);
- g.fillRect(this.sbHPosition + s.width - this.sbVWidth, s.height - this.sbHHeight, this.sbVWidth, this.sbHHeight);
- }
-
- g.clipRect(this.sbHPosition, 0, s.width - this.sbVWidth, s.height - this.sbHHeight);
- g.drawImage(this.im1, 0, 0, this);
- g.setColor(Color.black);
- g.drawRect(this.sbHPosition, 0, s.width - this.sbVWidth - 1, s.height - this.sbHHeight - 1);
- }
-
- public void redraw() {
- this.forceRedraw = true;
- ((Component)this).repaint();
- }
-
- private void redraw(Graphics g) {
- Dimension s = ((Component)this).size();
- this.forceRedraw = false;
- this.resetVector();
- this.newWidth = this.compWidth(g);
- int inRectCount = (s.height - this.sbHHeight) / this.cellSize;
- if (this.viewCount > inRectCount) {
- this.sbVShow = true;
- this.sbVWidth = this.sbV.preferredSize().width;
- } else {
- this.sbVShow = false;
- this.sbVWidth = 0;
- this.sbVPosition = 0;
- }
-
- if (this.newWidth > s.width - this.sbVWidth) {
- this.sbHShow = true;
- this.sbHHeight = this.sbH.preferredSize().height;
- } else {
- this.sbHShow = false;
- this.sbHHeight = 0;
- this.sbHPosition = 0;
- }
-
- this.drawTree();
- if (this.sbVShow) {
- this.sbV.reshape(s.width - this.sbVWidth, 0, this.sbVWidth, s.height - this.sbHHeight);
- this.sbV.setValues(this.sbVPosition, inRectCount, 0, this.viewCount - (this.isSun1_1 ? 0 : inRectCount));
- this.sbV.setPageIncrement(inRectCount - 1);
- this.sbV.show();
- } else {
- this.sbV.hide();
- }
-
- if (this.sbHShow) {
- this.sbH.reshape(0, s.height - this.sbHHeight, s.width - this.sbVWidth, this.sbHHeight);
- this.sbH.setValues(this.sbHPosition, s.width - this.sbVWidth, 0, this.sbHSize - (this.isSun1_1 ? 0 : s.width - this.sbVWidth));
- this.sbH.setPageIncrement(s.width - this.sbVWidth);
- this.sbH.setLineIncrement(this.sbHLineIncrement);
- this.sbH.show();
- } else {
- this.sbH.hide();
- }
- }
-
- private int compWidth(Graphics gg) {
- int size = 0;
- Font f = ((Component)this).getFont();
- if (f == null) {
- f = new Font("TimesRoman", 0, 13);
- gg.setFont(f);
- ((Component)this).setFont(f);
- }
-
- this.field_0 = gg.getFontMetrics();
-
- for(int i = 0; i < this.field_3.size(); ++i) {
- TreeNode node = (TreeNode)this.field_3.elementAt(i);
- int textOffset = (node.depth + 1) * this.cellSize + this.cellSize + this.textInset - (node.getImage() == null ? 12 : 0);
- if (size < textOffset + this.field_0.stringWidth(node.text) + 6) {
- size = textOffset + this.field_0.stringWidth(node.text) + 6;
- }
- }
-
- return size;
- }
-
- public void drawTree() {
- Dimension d = ((Component)this).size();
- int lastOne = this.sbVPosition + (d.height - this.sbHHeight) / this.cellSize + 1;
- if (lastOne > this.viewCount) {
- lastOne = this.viewCount;
- }
-
- if (d.width != this.viewWidth || d.height != this.viewHeight || this.field_1 == null || this.sbHSize != this.newWidth) {
- this.im1 = ((Component)this).createImage(Math.max(this.sbHSize = this.newWidth, d.width), d.height);
- if (this.field_1 != null) {
- this.field_1.dispose();
- }
-
- this.field_1 = this.im1.getGraphics();
- this.viewWidth = d.width;
- this.viewHeight = d.height;
- }
-
- Font f = ((Component)this).getFont();
- if (f == null) {
- f = new Font("TimesRoman", 0, 13);
- ((Component)this).setFont(f);
- }
-
- if (f != null && this.field_1.getFont() == null) {
- this.field_1.setFont(f);
- }
-
- this.field_0 = this.field_1.getFontMetrics();
- this.field_1.setColor(this.getBackground());
- this.field_1.fillRect(0, 0, this.im1.getWidth(this), d.height);
- TreeNode outerNode = null;
- if (!this.field_3.isEmpty()) {
- outerNode = (TreeNode)this.field_3.elementAt(this.sbVPosition);
- }
-
- for(int i = this.sbVPosition; i < lastOne; ++i) {
- TreeNode node = (TreeNode)this.field_3.elementAt(i);
- int x = this.cellSize * (node.depth + 1);
- int y = (i - this.sbVPosition) * this.cellSize;
- this.field_1.setColor(this.getForeground());
- if (node.sibling != null) {
- int k = this.field_3.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_3.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 - 2, x + this.cellSize / 2, y + this.cellSize + this.cellSize / 2);
- }
-
- this.field_1.setColor(this.getForeground());
- this.drawDotLine(x - this.cellSize / 2, y + this.cellSize / 2, x + this.cellSize / 2, y + this.cellSize / 2);
- if (node.isExpandable()) {
- this.field_1.setColor(this.getBackground());
- this.field_1.fillRect(this.cellSize * node.depth + this.cellSize / 4, y + this.clickSize / 2, this.clickSize, this.clickSize);
- this.field_1.setColor(this.getForeground());
- this.field_1.drawRect(this.cellSize * node.depth + this.cellSize / 4, y + this.clickSize / 2, this.clickSize, this.clickSize);
- this.field_1.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_1.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);
- }
- }
-
- Image nodeImage = node.getImage();
- if (nodeImage != null) {
- this.field_1.drawImage(nodeImage, x + this.imageInset, y, this);
- }
-
- if (node.text != null) {
- this.drawNodeText(node, y, node == this.selectedNode);
- }
-
- if (outerNode.depth > node.depth) {
- outerNode = node;
- }
- }
-
- if (outerNode != null) {
- while((outerNode = outerNode.parent) != null) {
- if (outerNode.sibling != null) {
- this.drawDotLine(this.cellSize * (outerNode.depth + 1) - this.cellSize / 2, 0, this.cellSize * (outerNode.depth + 1) - this.cellSize / 2, d.height);
- }
- }
- }
-
- }
-
- private void drawNodeText(TreeNode node, int yPosition, boolean eraseBackground) {
- int depth = node.depth;
- Image nodeImage = node.getImage();
- int textOffset = (depth + 1) * this.cellSize + this.cellSize + this.textInset - (nodeImage == null ? 12 : 0);
- Color fg;
- Color bg;
- if (node == this.selectedNode) {
- fg = this.fgHighlightColor;
- bg = this.bgHighlightColor;
- } else {
- fg = this.getForeground();
- bg = this.getBackground();
- }
-
- if (eraseBackground) {
- this.field_1.setColor(bg);
- this.field_1.fillRect(textOffset - 1, yPosition + 1, this.field_0.stringWidth(node.text) + 4, this.cellSize - 1);
- }
-
- this.field_1.setColor(fg);
- this.field_1.drawString(node.text, textOffset, yPosition + this.cellSize - this.textBaseLine);
- }
-
- private void drawDotLine(int x0, int y0, int x1, int y1) {
- if (y0 == y1) {
- for(int i = x0; i < x1; i += 2) {
- this.field_1.drawLine(i, y0, i, y1);
- }
-
- } else {
- for(int i = y0; i < y1; i += 2) {
- this.field_1.drawLine(x0, i, x1, i);
- }
-
- }
- }
-
- public void setTreeStructure(String[] s) {
- this.rootNode = this.selectedNode = null;
-
- try {
- this.parseTreeStructure(s);
- } catch (InvalidTreeNodeException e) {
- System.out.println(e);
- }
-
- this.forceRedraw = true;
- ((Component)this).repaint();
- }
-
- public String[] getTreeStructure() {
- if (this.rootNode == null) {
- return null;
- } else {
- Vector nodesVector = new Vector(this.count);
- this.rootNode.depth = 0;
- this.vectorize(this.rootNode, false, nodesVector);
- int numNodes = nodesVector.size();
- String[] treeStructure = new String[numNodes];
-
- for(int i = 0; i < numNodes; ++i) {
- TreeNode thisNode = (TreeNode)nodesVector.elementAt(i);
- String treeString = "";
-
- for(int numBlanks = 0; numBlanks < thisNode.depth; ++numBlanks) {
- treeString = treeString + ' ';
- }
-
- treeString = treeString + thisNode.text;
- treeStructure[i] = treeString;
- }
-
- return treeStructure;
- }
- }
-
- private void parseTreeStructure(String[] tempStructure) throws InvalidTreeNodeException {
- for(int i = 0; i < tempStructure.length; ++i) {
- String entry = tempStructure[i];
- int indentLevel = this.findLastPreSpace(entry);
- if (indentLevel == -1) {
- throw new InvalidTreeNodeException();
- }
-
- if (this.rootNode == null) {
- if (indentLevel != 0) {
- throw new InvalidTreeNodeException();
- }
-
- TreeNode node = new TreeNode(entry.trim());
- node.setDepth(indentLevel);
- this.append(node);
- } else {
- TreeNode currentNode;
- for(currentNode = this.rootNode; currentNode.sibling != null; currentNode = currentNode.sibling) {
- }
-
- for(int j = 1; 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();
- }
-
- TreeNode node = new TreeNode(entry.trim());
- node.setDepth(indentLevel);
- if (diff == 1) {
- this.insert(node, currentNode, 0);
- } else {
- this.insert(node, currentNode, 1);
- }
- }
- }
-
- }
-
- private int findLastPreSpace(String s) {
- int length = s.length();
- if (s.charAt(0) != ' ' && s.charAt(0) != '\t') {
- return 0;
- } else {
- for(int i = 1; i < length; ++i) {
- if (s.charAt(i) != ' ' && s.charAt(i) != '\t') {
- 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) {
- }
- }
-