summaryrefslogtreecommitdiff
path: root/NET/worlds/console/Tree.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-03 16:38:41 -0700
committerFuwn <[email protected]>2021-05-03 16:38:41 -0700
commite1e781bb2135ef78592226f1a3eaba4925702f1f (patch)
tree8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/console/Tree.java
downloadworlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz
worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip
:star:HEADmain
Diffstat (limited to 'NET/worlds/console/Tree.java')
-rw-r--r--NET/worlds/console/Tree.java303
1 files changed, 303 insertions, 0 deletions
diff --git a/NET/worlds/console/Tree.java b/NET/worlds/console/Tree.java
new file mode 100644
index 0000000..bdcaf0d
--- /dev/null
+++ b/NET/worlds/console/Tree.java
@@ -0,0 +1,303 @@
+/* */ package NET.worlds.console;
+/* */
+/* */ import NET.worlds.scape.LibraryDropTarget;
+/* */ import java.util.Hashtable;
+/* */ import java.util.Vector;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public class Tree
+/* */ extends TreePanel
+/* */ implements MainCallback, LibraryDropTarget
+/* */ {
+/* */ private static final long serialVersionUID = -1919976160954835913L;
+/* 33 */ private int openItem = -1;
+/* 34 */ private int changeItem = -1;
+/* */
+/* */
+/* */ private TreeCallback owner;
+/* */
+/* */ private boolean registered;
+/* */
+/* */
+/* */ public Tree() {}
+/* */
+/* */
+/* */ public Tree(TreeCallback owner)
+/* */ {
+/* 47 */ this();
+/* 48 */ setOwner(owner);
+/* */ }
+/* */
+/* */ public void setOwner(TreeCallback owner)
+/* */ {
+/* 53 */ this.owner = owner;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public void change(TreeNode root, Object current)
+/* */ {
+/* 64 */ delayRepaints(true);
+/* 65 */ removeAllElements();
+/* 66 */ addElement(root);
+/* 67 */ int index = search(0, current, new Hashtable());
+/* 68 */ assert (index != -1);
+/* 69 */ sync(index);
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public void change(TreeNode root, Vector<TreeNode> lineage)
+/* */ {
+/* 77 */ delayRepaints(true);
+/* 78 */ removeAllElements();
+/* 79 */ TreeNode parent = root;
+/* 80 */ addElement(root);
+/* 81 */ int index = 1;
+/* 82 */ for (int j = 0; j < lineage.size(); j++) {
+/* 83 */ Object lookingFor = lineage.elementAt(j);
+/* 84 */ Vector<TreeNode> v = getSortedChildren(parent);
+/* 85 */ parent.setOpen(true);
+/* 86 */ int count = v.size();
+/* 87 */ int foundIndex = -1;
+/* 88 */ for (int i = 0; i < count; i++) {
+/* 89 */ TreeNode child = (TreeNode)v.elementAt(i);
+/* 90 */ int tmp = index + i;
+/* 91 */ insertElementAt(child, tmp);
+/* 92 */ if ((foundIndex == -1) && (child.getObject().equals(lookingFor))) {
+/* 93 */ foundIndex = tmp;
+/* 94 */ parent = child;
+/* */ }
+/* */ }
+/* 97 */ assert (foundIndex != -1);
+/* 98 */ index = foundIndex + 1;
+/* */ }
+/* 100 */ sync(index - 1);
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public void update()
+/* */ {
+/* 111 */ Vector<TreeNode> newTree = new Vector();
+/* 112 */ int count = countElements();
+/* 113 */ for (int i = 0; i < count; i++) {
+/* 114 */ TreeNode e1 = elementAt(i);
+/* 115 */ if (e1.getParent() == null) {
+/* 116 */ newTree.addElement(e1);
+/* 117 */ recurseAddChildren(newTree, e1);
+/* */ }
+/* */ }
+/* */
+/* */
+/* 122 */ TreeNode selected = getSelectedNode();
+/* 123 */ count = newTree.size();
+/* */
+/* 125 */ for (int i = 0; i < count; i++)
+/* 126 */ if (((TreeNode)newTree.elementAt(i)).equals(selected))
+/* */ break;
+/* 128 */ int hitem = i < count ? i : Math.min(count - 1, getSelectedIndex());
+/* 129 */ delayRepaints(true);
+/* 130 */ reset(newTree);
+/* 131 */ sync(hitem);
+/* */ }
+/* */
+/* */ private void sync(int selected)
+/* */ {
+/* */ try
+/* */ {
+/* 138 */ select(selected);
+/* 139 */ Object treeNode = getSelectedNode().getObject();
+/* */
+/* 141 */ if (treeNode != null) {
+/* 142 */ this.owner.treeChange(treeNode);
+/* 143 */ delayRepaints(false);
+/* */ }
+/* */ }
+/* */ catch (Exception localException) {}
+/* */ }
+/* */
+/* */
+/* */ private Vector<TreeNode> getSortedChildren(TreeNode parent)
+/* */ {
+/* 152 */ Vector<TreeNode> unsorted = parent.getChildren();
+/* 153 */ Vector<TreeNode> sorted = new Vector(unsorted.size());
+/* */
+/* 155 */ if (unsorted != null) {
+/* 156 */ int icount = unsorted.size();
+/* 157 */ for (int i = 0; i < icount; i++) {
+/* 158 */ TreeNode e = (TreeNode)unsorted.elementAt(i);
+/* 159 */ if (parent.shouldSort()) {
+/* 160 */ int jcount = sorted.size();
+/* */
+/* 162 */ for (int j = 0; j < jcount; j++)
+/* */ {
+/* 164 */ if (((TreeNode)sorted.elementAt(j)).toString().compareTo(e.toString()) > 0)
+/* */ break; }
+/* 166 */ sorted.insertElementAt(e, j);
+/* */ } else {
+/* 168 */ sorted.insertElementAt(e, i);
+/* */ }
+/* */ } }
+/* 171 */ return sorted;
+/* */ }
+/* */
+/* */ private Vector<TreeNode> getCurrentChildren(TreeNode parent) {
+/* 175 */ Vector<TreeNode> ret = new Vector();
+/* 176 */ int count = countElements();
+/* 177 */ for (int i = 0; i < count; i++) {
+/* 178 */ TreeNode ele = elementAt(i);
+/* 179 */ if (ele.getParent() == parent)
+/* 180 */ ret.addElement(ele);
+/* */ }
+/* 182 */ return ret;
+/* */ }
+/* */
+/* */ private static TreeNode maybeUseOldChild(TreeNode newChild, Vector<TreeNode> oldChildren)
+/* */ {
+/* 187 */ int count = oldChildren.size();
+/* 188 */ for (int i = 0; i < count; i++) {
+/* 189 */ TreeNode oldChild = (TreeNode)oldChildren.elementAt(i);
+/* 190 */ if (oldChild.equals(newChild))
+/* 191 */ return oldChild;
+/* */ }
+/* 193 */ return newChild;
+/* */ }
+/* */
+/* */ private void recurseAddChildren(Vector<TreeNode> newTree, TreeNode oldEle) {
+/* 197 */ if (oldEle.isOpen()) {
+/* 198 */ Vector<TreeNode> oldChildren = getCurrentChildren(oldEle);
+/* 199 */ Vector<TreeNode> newChildren = getSortedChildren(oldEle);
+/* 200 */ int count = newChildren.size();
+/* 201 */ for (int i = 0; i < count; i++) {
+/* 202 */ TreeNode child = (TreeNode)newChildren.elementAt(i);
+/* 203 */ child = maybeUseOldChild(child, oldChildren);
+/* 204 */ newTree.addElement(child);
+/* 205 */ recurseAddChildren(newTree, child);
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* */ private int search(int index, Object obj, Hashtable<TreeNode, TreeNode> lookedAt) {
+/* 211 */ TreeNode e = elementAt(index);
+/* 212 */ if (e.getObject().equals(obj))
+/* 213 */ return index;
+/* 214 */ if (!lookedAt.containsKey(e)) {
+/* 215 */ lookedAt.put(e, e);
+/* 216 */ index++;
+/* 217 */ Vector<TreeNode> v = getSortedChildren(e);
+/* 218 */ e.setOpen(true);
+/* 219 */ if (v != null) {
+/* 220 */ int count = v.size();
+/* 221 */ for (int i = 0; i < count; i++)
+/* 222 */ insertElementAt((TreeNode)v.elementAt(i), index + i);
+/* 223 */ for (int i = 0; i < count; i++) {
+/* 224 */ int found = search(index + i, obj, lookedAt);
+/* 225 */ if (found != -1)
+/* 226 */ return found;
+/* */ }
+/* 228 */ for (int i = 0; i < count; i++)
+/* 229 */ removeElementAt(index);
+/* */ }
+/* 231 */ e.setOpen(false);
+/* */ }
+/* 233 */ return -1;
+/* */ }
+/* */
+/* */ private void register() {
+/* 237 */ if (!this.registered) {
+/* 238 */ Main.register(this);
+/* 239 */ this.registered = true;
+/* */ }
+/* */ }
+/* */
+/* */ public void treeSelect(int item)
+/* */ {
+/* 245 */ if (item != getSelectedIndex()) {
+/* 246 */ select(item);
+/* 247 */ this.changeItem = item;
+/* 248 */ register();
+/* */ }
+/* */ }
+/* */
+/* */ public void treeOpen(int item)
+/* */ {
+/* 254 */ if (this.openItem == -1) {
+/* 255 */ this.openItem = item;
+/* 256 */ register();
+/* */ }
+/* */ }
+/* */
+/* */ public void setFocus(boolean hasFocus)
+/* */ {
+/* 262 */ boolean hadFocus = hasFocus();
+/* 263 */ super.setFocus(hasFocus);
+/* 264 */ if (hadFocus != hasFocus)
+/* 265 */ this.owner.treeFocusChanged(hasFocus);
+/* */ }
+/* */
+/* */ public synchronized void mainCallback() {
+/* 269 */ delayRepaints(true);
+/* 270 */ int i = this.changeItem;
+/* 271 */ this.changeItem = -1;
+/* 272 */ if (i != -1)
+/* 273 */ this.owner.treeChange(elementAt(i).getObject());
+/* 274 */ i = this.openItem;
+/* 275 */ this.openItem = -1;
+/* 276 */ if (i != -1) {
+/* 277 */ TreeNode e = elementAt(i);
+/* 278 */ boolean isOpen = !e.isOpen();
+/* 279 */ e.setOpen(isOpen);
+/* 280 */ i++;
+/* 281 */ if (isOpen) {
+/* 282 */ v = getSortedChildren(e);
+/* 283 */ if (v != null) {
+/* 284 */ count = v.size();
+/* 285 */ for (j = 0; j < count; j++)
+/* 286 */ insertElementAt((TreeNode)v.elementAt(j), i++);
+/* */ }
+/* */ } else {
+/* 289 */ while ((i < countElements()) && (e.isDescendant(elementAt(i)))) { Vector<TreeNode> v;
+/* 290 */ int count; int j; removeElementAt(i); } }
+/* 291 */ repaint();
+/* */ }
+/* 293 */ delayRepaints(false);
+/* 294 */ this.registered = false;
+/* 295 */ Main.unregister(this);
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\Tree.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file