/jEdit/tags/jedit-4-3-pre11/org/gjt/sp/jedit/search/HyperSearchFileNode.java

# · Java · 116 lines · 59 code · 14 blank · 43 comment · 8 complexity · 064619a00ac01322b9fec868d0e1836d MD5 · raw file

  1. /*
  2. * HyperSearchFileNode.java - HyperSearch file node
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2005 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.search;
  23. import org.gjt.sp.jedit.Buffer;
  24. import org.gjt.sp.jedit.EditPane;
  25. import org.gjt.sp.jedit.MiscUtilities;
  26. import org.gjt.sp.jedit.View;
  27. import org.gjt.sp.jedit.jEdit;
  28. /**
  29. * HyperSearch results window.
  30. * @author Slava Pestov
  31. * @version $Id: HyperSearchFileNode.java 9868 2007-06-28 13:35:01Z kpouer $
  32. */
  33. public class HyperSearchFileNode implements HyperSearchNode
  34. {
  35. public String path;
  36. public Buffer buffer;
  37. public boolean showFullPath = true;
  38. private static String fileSep = System.getProperty("file.separator");
  39. static
  40. {
  41. if (fileSep.equals("\\"))
  42. fileSep = "\\\\";
  43. }
  44. //{{{ HyperSearchFileNode constructor
  45. public HyperSearchFileNode(String path)
  46. {
  47. this.path = path;
  48. } //}}}
  49. //{{{ getBuffer() method
  50. public Buffer getBuffer(View view)
  51. {
  52. if(buffer == null)
  53. buffer = jEdit.openFile(view,path);
  54. return buffer;
  55. } //}}}
  56. //{{{ goTo() method
  57. public void goTo(EditPane editPane)
  58. {
  59. Buffer buffer = getBuffer(editPane.getView());
  60. if(buffer == null)
  61. return;
  62. editPane.setBuffer(buffer);
  63. } //}}}
  64. //{{{ toString() method
  65. public String toString()
  66. {
  67. if (showFullPath)
  68. return path;
  69. String[] paths = path.split(fileSep);
  70. return paths[paths.length - 1];
  71. } //}}}
  72. //{{{ equals() method
  73. public boolean equals(Object compareObj)
  74. {
  75. if (!(compareObj instanceof HyperSearchFileNode))
  76. return false;
  77. HyperSearchFileNode otherResult = (HyperSearchFileNode)compareObj;
  78. return path.equals(MiscUtilities.resolveSymlinks(otherResult.path))
  79. && buffer.equals(otherResult.buffer);
  80. }//}}}
  81. /**
  82. * Returns the result count.
  83. *
  84. * @return the result count
  85. * @since jEdit 4.3pre9
  86. */
  87. public int getCount()
  88. {
  89. return count;
  90. }
  91. /**
  92. * Set the result count.
  93. *
  94. * @param count the result count
  95. * @since jEdit 4.3pre9
  96. */
  97. public void setCount(int count)
  98. {
  99. this.count = count;
  100. }
  101. private int count;
  102. }