PageRenderTime 303ms CodeModel.GetById 299ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 87 lines | 49 code | 12 blank | 26 comment | 8 complexity | 014b27fb9773ff796fa82c9ad5f9959c 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
23package org.gjt.sp.jedit.search;
24
25import org.gjt.sp.jedit.Buffer;
26import org.gjt.sp.jedit.EditPane;
27import org.gjt.sp.jedit.MiscUtilities;
28import org.gjt.sp.jedit.jEdit;
29
30public class HyperSearchFileNode implements HyperSearchNode
31{
32	public String path;
33	public Buffer buffer;
34	public boolean showFullPath = true;
35
36	private static String fileSep = System.getProperty("file.separator");
37	static
38	{
39		if (fileSep.equals("\\"))
40			fileSep = "\\\\";
41	}
42
43	//{{{ HyperSearchFileNode constructor
44	public HyperSearchFileNode(String path)
45	{
46		this.path = path;
47	} //}}}
48
49	//{{{ getBuffer() method
50	public Buffer getBuffer()
51	{
52		if(buffer == null)
53			buffer = jEdit.openFile(null,path);
54		return buffer;
55	} //}}}
56
57	//{{{ goTo() method
58	public void goTo(final EditPane editPane)
59	{
60		Buffer buffer = getBuffer();
61		if(buffer == null)
62			return;
63
64		editPane.setBuffer(buffer);
65	} //}}}
66	
67	//{{{ toString() method
68	public String toString()
69	{
70		if (showFullPath)
71			return path;
72		String paths[] = path.split(fileSep);
73		return paths[paths.length - 1];
74	} //}}}
75	
76	//{{{ equals() method
77	public boolean equals(Object compareObj)
78	{
79		if (!(compareObj instanceof HyperSearchFileNode))
80			return false;
81		HyperSearchFileNode otherResult = (HyperSearchFileNode)compareObj;
82		
83		return path.equals(MiscUtilities.resolveSymlinks(otherResult.path))
84			&& buffer.equals(otherResult.buffer);		
85	}//}}}
86	
87}