/plugins/BufferList/trunk/bufferlist/BufferListTreeNode.java

# · Java · 143 lines · 77 code · 22 blank · 44 comment · 4 complexity · 7dd2380edc4cbdbf2d7569a2208ec636 MD5 · raw file

  1. /*{{{ header
  2. * BufferListNode - tree node representation for BufferList
  3. * Copyright (c) 2004 Karsten Pilz
  4. *
  5. * :tabSize=4:indentSize=4:noTabs=false:maxLineLen=0:folding=explicit:collapseFolds=0:
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. *}}}
  21. */
  22. package bufferlist;
  23. // {{{ imports
  24. import javax.swing.tree.DefaultMutableTreeNode;
  25. import org.gjt.sp.jedit.Buffer;
  26. // }}}
  27. /**
  28. * This is the tree node.
  29. */
  30. public class BufferListTreeNode extends DefaultMutableTreeNode
  31. {
  32. private static final long serialVersionUID = 1L;
  33. // {{{instance variables
  34. /**
  35. * Path to this node in VFS. UserObject represents the label of the node and
  36. * so getUserObject()!=user_path for directory nodes.
  37. */
  38. private String user_path;
  39. // private boolean used = false;
  40. private boolean expanded;
  41. private boolean isConnected;
  42. // private int reused = 0; // NOTE: debug only
  43. // }}}
  44. // {{{ +BufferListTreeNode(Object userObject) : <init>
  45. public BufferListTreeNode(Object userObject)
  46. {
  47. super(userObject);
  48. init(userObject);
  49. } // }}}
  50. // {{{ +BufferListTreeNode(Object userObject, boolean allowsChildren) :
  51. // <init>
  52. public BufferListTreeNode(Object userObject, boolean allowsChildren)
  53. {
  54. super(userObject, allowsChildren);
  55. init(userObject);
  56. } // }}}
  57. public void reset()
  58. {
  59. // reused += 1; // NOTE: debug only
  60. // used = false;
  61. expanded = false;
  62. isConnected = false;
  63. //restore label of the node
  64. if (isDirNode())
  65. {
  66. setUserObject(user_path);
  67. }
  68. }
  69. private void init(Object userObject)
  70. {
  71. if (userObject instanceof Buffer)
  72. {
  73. user_path = ((Buffer) userObject).getPath();
  74. }
  75. else if (userObject instanceof String)
  76. {
  77. user_path = (String) userObject;
  78. }
  79. else
  80. {
  81. user_path = "ERROR";
  82. }
  83. reset();
  84. }
  85. public void setExpanded(boolean expanded)
  86. {
  87. this.expanded = expanded;
  88. }
  89. public void setConnected()
  90. {
  91. isConnected = true;
  92. }
  93. public boolean isConnected()
  94. {
  95. return isConnected;
  96. }
  97. /*
  98. * public String getReused() { Integer obj = new Integer(reused); return
  99. * obj.toString(); }
  100. */
  101. public String getUserPath()
  102. {
  103. return user_path;
  104. }
  105. public Buffer getBuffer()
  106. {
  107. return (Buffer) getUserObject();
  108. }
  109. public boolean isExpanded()
  110. {
  111. return expanded;
  112. }
  113. public boolean isBuffer()
  114. {
  115. return (getUserObject() instanceof Buffer);
  116. }
  117. public boolean isDirNode()
  118. {
  119. return (getUserObject() instanceof String);
  120. }
  121. }