PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 771 lines | 590 code | 99 blank | 82 comment | 68 complexity | 09b41f92ad56264def1851e1948f3c32 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * HyperSearchResults.java - HyperSearch results
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1998, 1999, 2000, 2001 Slava Pestov
  7. * Portions copyright (C) 2002 Peter Cox
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. package org.gjt.sp.jedit.search;
  24. //{{{ Imports
  25. import javax.swing.*;
  26. import javax.swing.tree.*;
  27. import java.awt.*;
  28. import java.awt.event.*;
  29. import java.util.*;
  30. import org.gjt.sp.jedit.gui.DefaultFocusComponent;
  31. import org.gjt.sp.jedit.gui.RolloverButton;
  32. import org.gjt.sp.jedit.msg.*;
  33. import org.gjt.sp.jedit.*;
  34. //}}}
  35. /**
  36. * HyperSearch results window.
  37. * @author Slava Pestov
  38. * @version $Id: HyperSearchResults.java 5379 2006-05-05 09:01:40Z kpouer $
  39. */
  40. public class HyperSearchResults extends JPanel implements EBComponent,
  41. DefaultFocusComponent
  42. {
  43. public static final String NAME = "hypersearch-results";
  44. //{{{ HyperSearchResults constructor
  45. public HyperSearchResults(View view)
  46. {
  47. super(new BorderLayout());
  48. this.view = view;
  49. caption = new JLabel();
  50. Box toolBar = new Box(BoxLayout.X_AXIS);
  51. toolBar.add(caption);
  52. toolBar.add(Box.createGlue());
  53. ActionHandler ah = new ActionHandler();
  54. clear = new RolloverButton(GUIUtilities.loadIcon("Clear.png"));
  55. clear.setToolTipText(jEdit.getProperty(
  56. "hypersearch-results.clear.label"));
  57. clear.addActionListener(ah);
  58. toolBar.add(clear);
  59. multi = new RolloverButton();
  60. multi.setToolTipText(jEdit.getProperty(
  61. "hypersearch-results.multi.label"));
  62. multi.addActionListener(ah);
  63. toolBar.add(multi);
  64. add(BorderLayout.NORTH, toolBar);
  65. resultTreeRoot = new DefaultMutableTreeNode();
  66. resultTreeModel = new DefaultTreeModel(resultTreeRoot);
  67. resultTree = new JTree(resultTreeModel);
  68. resultTree.setToolTipText("");
  69. resultTree.setCellRenderer(new ResultCellRenderer());
  70. resultTree.setVisibleRowCount(16);
  71. resultTree.setRootVisible(false);
  72. resultTree.setShowsRootHandles(true);
  73. // looks bad with the OS X L&F, apparently...
  74. if(!OperatingSystem.isMacOSLF())
  75. resultTree.putClientProperty("JTree.lineStyle", "Angled");
  76. resultTree.setEditable(false);
  77. resultTree.addKeyListener(new KeyHandler());
  78. resultTree.addMouseListener(new MouseHandler());
  79. JScrollPane scrollPane = new JScrollPane(resultTree);
  80. Dimension dim = scrollPane.getPreferredSize();
  81. dim.width = 400;
  82. scrollPane.setPreferredSize(dim);
  83. add(BorderLayout.CENTER, scrollPane);
  84. } //}}}
  85. //{{{ focusOnDefaultComponent() method
  86. public void focusOnDefaultComponent()
  87. {
  88. resultTree.requestFocus();
  89. } //}}}
  90. //{{{ addNotify() method
  91. public void addNotify()
  92. {
  93. super.addNotify();
  94. EditBus.addToBus(this);
  95. multiStatus = jEdit.getBooleanProperty(
  96. "hypersearch-results.multi");
  97. updateMultiStatus();
  98. } //}}}
  99. //{{{ removeNotify() method
  100. public void removeNotify()
  101. {
  102. super.removeNotify();
  103. EditBus.removeFromBus(this);
  104. jEdit.setBooleanProperty("hypersearch-results.multi",multiStatus);
  105. } //}}}
  106. //{{{ visitBuffers() method
  107. private void visitBuffers(final ResultVisitor visitor, final Buffer buffer)
  108. {
  109. // impl note: since multi-level hierarchies now allowed,
  110. // use traverseNodes to process HyperSearchResult nodes
  111. traverseNodes(resultTreeRoot, new TreeNodeCallbackAdapter() {
  112. public boolean processNode(DefaultMutableTreeNode node) {
  113. Object userObject = node.getUserObject();
  114. if (!(userObject instanceof HyperSearchResult))
  115. return true;
  116. HyperSearchResult result = (HyperSearchResult) userObject;
  117. if (result.pathEquals(buffer.getSymlinkPath()))
  118. visitor.visit(buffer, result);
  119. return true;
  120. }
  121. });
  122. } //}}}
  123. //{{{ handleMessage() method
  124. public void handleMessage(EBMessage msg)
  125. {
  126. if(msg instanceof BufferUpdate)
  127. {
  128. BufferUpdate bmsg = (BufferUpdate)msg;
  129. Buffer buffer = bmsg.getBuffer();
  130. Object what = bmsg.getWhat();
  131. if(what == BufferUpdate.LOADED)
  132. visitBuffers(new BufferLoadedVisitor(),buffer);
  133. else if(what == BufferUpdate.CLOSED)
  134. visitBuffers(new BufferClosedVisitor(),buffer);
  135. }
  136. } //}}}
  137. //{{{ traverseNodes() method
  138. public boolean traverseNodes(DefaultMutableTreeNode node,
  139. HyperSearchTreeNodeCallback callbackInterface)
  140. {
  141. if (!callbackInterface.processNode(node))
  142. return false;
  143. for (Enumeration e = node.children(); e.hasMoreElements();)
  144. {
  145. DefaultMutableTreeNode childNode = (DefaultMutableTreeNode)e.nextElement();
  146. if (!traverseNodes(childNode, callbackInterface))
  147. return false;
  148. }
  149. return true;
  150. } //}}}
  151. //{{{ getTreeModel() method
  152. public DefaultTreeModel getTreeModel()
  153. {
  154. return resultTreeModel;
  155. } //}}}
  156. //{{{ getTree() method
  157. /**
  158. * Returns the result tree.
  159. * @since jEdit 4.1pre9
  160. */
  161. public JTree getTree()
  162. {
  163. return resultTree;
  164. } //}}}
  165. //{{{ searchStarted() method
  166. public void searchStarted()
  167. {
  168. caption.setText(jEdit.getProperty("hypersearch-results.searching"));
  169. } //}}}
  170. //{{{ setSearchStatus() method
  171. public void setSearchStatus(String status)
  172. {
  173. caption.setText(status);
  174. } //}}}
  175. //{{{ searchFailed() method
  176. public void searchFailed()
  177. {
  178. caption.setText(jEdit.getProperty("hypersearch-results.no-results"));
  179. // collapse all nodes, as suggested on user mailing list...
  180. for(int i = 0; i < resultTreeRoot.getChildCount(); i++)
  181. {
  182. DefaultMutableTreeNode node = (DefaultMutableTreeNode)
  183. resultTreeRoot.getChildAt(i);
  184. resultTree.collapsePath(new TreePath(new Object[] {
  185. resultTreeRoot, node }));
  186. }
  187. } //}}}
  188. //{{{ searchDone() method
  189. public void searchDone(final DefaultMutableTreeNode searchNode)
  190. {
  191. final int nodeCount = searchNode.getChildCount();
  192. if (nodeCount < 1)
  193. {
  194. searchFailed();
  195. return;
  196. }
  197. caption.setText(jEdit.getProperty("hypersearch-results.done"));
  198. SwingUtilities.invokeLater(new Runnable()
  199. {
  200. public void run()
  201. {
  202. if(!multiStatus)
  203. {
  204. for(int i = 0; i < resultTreeRoot.getChildCount(); i++)
  205. {
  206. resultTreeRoot.remove(0);
  207. }
  208. }
  209. resultTreeRoot.add(searchNode);
  210. resultTreeModel.reload(resultTreeRoot);
  211. TreePath lastNode = null;
  212. for(int i = 0; i < nodeCount; i++)
  213. {
  214. lastNode = new TreePath(
  215. ((DefaultMutableTreeNode)
  216. searchNode.getChildAt(i))
  217. .getPath());
  218. resultTree.expandPath(lastNode);
  219. }
  220. resultTree.scrollPathToVisible(
  221. new TreePath(new Object[] {
  222. resultTreeRoot,searchNode }));
  223. }
  224. });
  225. } //}}}
  226. //{{{ Private members
  227. private View view;
  228. private JLabel caption;
  229. private JTree resultTree;
  230. private DefaultMutableTreeNode resultTreeRoot;
  231. private DefaultTreeModel resultTreeModel;
  232. private RolloverButton clear;
  233. private RolloverButton multi;
  234. private boolean multiStatus;
  235. //{{{ updateMultiStatus() method
  236. private void updateMultiStatus()
  237. {
  238. if(multiStatus)
  239. multi.setIcon(GUIUtilities.loadIcon("MultipleResults.png"));
  240. else
  241. multi.setIcon(GUIUtilities.loadIcon("SingleResult.png"));
  242. } //}}}
  243. //{{{ goToSelectedNode() method
  244. public static final int M_OPEN = 0;
  245. public static final int M_OPEN_NEW_VIEW = 1;
  246. public static final int M_OPEN_NEW_PLAIN_VIEW = 2;
  247. public static final int M_OPEN_NEW_SPLIT = 3;
  248. private void goToSelectedNode(int mode)
  249. {
  250. TreePath path = resultTree.getSelectionPath();
  251. if(path == null)
  252. return;
  253. DefaultMutableTreeNode node = (DefaultMutableTreeNode)path
  254. .getLastPathComponent();
  255. Object value = node.getUserObject();
  256. // do nothing if clicked "foo (showing n occurrences in m files)"
  257. if(node.getParent() != resultTreeRoot && value instanceof HyperSearchNode)
  258. {
  259. HyperSearchNode n = (HyperSearchNode)value;
  260. Buffer buffer = n.getBuffer();
  261. if(buffer == null)
  262. return;
  263. EditPane pane;
  264. switch(mode)
  265. {
  266. case M_OPEN:
  267. pane = view.goToBuffer(buffer);
  268. break;
  269. case M_OPEN_NEW_VIEW:
  270. pane = jEdit.newView(view,buffer,false).getEditPane();
  271. break;
  272. case M_OPEN_NEW_PLAIN_VIEW:
  273. pane = jEdit.newView(view,buffer,true).getEditPane();
  274. break;
  275. case M_OPEN_NEW_SPLIT:
  276. pane = view.splitHorizontally();
  277. break;
  278. default:
  279. throw new IllegalArgumentException("Bad mode: " + mode);
  280. }
  281. ((HyperSearchNode)value).goTo(pane);
  282. }
  283. } //}}}
  284. //}}}
  285. //{{{ ActionHandler class
  286. public class ActionHandler implements ActionListener
  287. {
  288. public void actionPerformed(ActionEvent evt)
  289. {
  290. Object source = evt.getSource();
  291. if(source == clear)
  292. {
  293. resultTreeRoot.removeAllChildren();
  294. resultTreeModel.reload(resultTreeRoot);
  295. }
  296. else if(source == multi)
  297. {
  298. multiStatus = !multiStatus;
  299. updateMultiStatus();
  300. if(!multiStatus)
  301. {
  302. for(int i = resultTreeRoot.getChildCount() - 2; i >= 0; i--)
  303. {
  304. resultTreeModel.removeNodeFromParent(
  305. (MutableTreeNode)resultTreeRoot
  306. .getChildAt(i));
  307. }
  308. }
  309. }
  310. }
  311. } //}}}
  312. //{{{ KeyHandler class
  313. class KeyHandler extends KeyAdapter
  314. {
  315. public void keyPressed(KeyEvent evt)
  316. {
  317. if(evt.getKeyCode() == KeyEvent.VK_ENTER)
  318. {
  319. goToSelectedNode(M_OPEN);
  320. // fuck me dead
  321. SwingUtilities.invokeLater(new Runnable()
  322. {
  323. public void run()
  324. {
  325. resultTree.requestFocus();
  326. }
  327. });
  328. evt.consume();
  329. }
  330. }
  331. } //}}}
  332. //{{{ MouseHandler class
  333. class MouseHandler extends MouseAdapter
  334. {
  335. //{{{ mousePressed() method
  336. public void mousePressed(MouseEvent evt)
  337. {
  338. if(evt.isConsumed())
  339. return;
  340. TreePath path1 = resultTree.getPathForLocation(
  341. evt.getX(),evt.getY());
  342. if(path1 == null)
  343. return;
  344. resultTree.setSelectionPath(path1);
  345. if (GUIUtilities.isPopupTrigger(evt))
  346. showPopupMenu(evt);
  347. else
  348. {
  349. goToSelectedNode(M_OPEN);
  350. view.toFront();
  351. view.requestFocus();
  352. view.getTextArea().requestFocus();
  353. }
  354. } //}}}
  355. //{{{ Private members
  356. private JPopupMenu popupMenu;
  357. //{{{ showPopupMenu method
  358. private void showPopupMenu(MouseEvent evt)
  359. {
  360. TreePath path = resultTree.getSelectionPath();
  361. DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
  362. popupMenu = new JPopupMenu();
  363. Object userObj = node.getUserObject();
  364. if (userObj instanceof HyperSearchFileNode
  365. || userObj instanceof HyperSearchResult)
  366. {
  367. popupMenu.add(new GoToNodeAction(
  368. "hypersearch-results.open",
  369. M_OPEN));
  370. popupMenu.add(new GoToNodeAction(
  371. "hypersearch-results.open-view",
  372. M_OPEN_NEW_VIEW));
  373. popupMenu.add(new GoToNodeAction(
  374. "hypersearch-results.open-plain-view",
  375. M_OPEN_NEW_PLAIN_VIEW));
  376. popupMenu.add(new GoToNodeAction(
  377. "hypersearch-results.open-split",
  378. M_OPEN_NEW_SPLIT));
  379. }
  380. if (!(userObj instanceof HyperSearchFolderNode))
  381. popupMenu.add(new RemoveTreeNodeAction());
  382. popupMenu.add(new ExpandChildTreeNodesAction());
  383. if (userObj instanceof HyperSearchFolderNode
  384. || userObj instanceof HyperSearchOperationNode)
  385. {
  386. popupMenu.add(new CollapseChildTreeNodesAction());
  387. if (userObj instanceof HyperSearchFolderNode)
  388. popupMenu.add(new NewSearchAction());
  389. }
  390. if (userObj instanceof HyperSearchOperationNode)
  391. {
  392. popupMenu.add(new JPopupMenu.Separator());
  393. HyperSearchOperationNode resultNode = (HyperSearchOperationNode)userObj;
  394. JCheckBoxMenuItem chkItem =
  395. new JCheckBoxMenuItem(jEdit.getProperty("hypersearch-results.tree-view"),
  396. resultNode.isTreeViewDisplayed());
  397. chkItem.addActionListener(new TreeDisplayAction());
  398. popupMenu.add(chkItem);
  399. }
  400. GUIUtilities.showPopupMenu(popupMenu,evt.getComponent(),
  401. evt.getX(),evt.getY());
  402. evt.consume();
  403. } //}}}
  404. //}}}
  405. } //}}}
  406. //{{{ RemoveTreeNodeAction class
  407. class RemoveTreeNodeAction extends AbstractAction
  408. {
  409. public RemoveTreeNodeAction()
  410. {
  411. super(jEdit.getProperty("hypersearch-results.remove-node"));
  412. }
  413. public void actionPerformed(ActionEvent evt)
  414. {
  415. TreePath path = resultTree.getSelectionPath();
  416. if(path == null)
  417. return;
  418. MutableTreeNode value = (MutableTreeNode)path
  419. .getLastPathComponent();
  420. HyperSearchOperationNode.removeNodeFromCache(value);
  421. resultTreeModel.removeNodeFromParent(value);
  422. }
  423. }//}}}
  424. //{{{ RemoveAllTreeNodesAction class
  425. class RemoveAllTreeNodesAction extends AbstractAction
  426. {
  427. public RemoveAllTreeNodesAction()
  428. {
  429. super(jEdit.getProperty("hypersearch-results.remove-all-nodes"));
  430. }
  431. public void actionPerformed(ActionEvent evt)
  432. {
  433. resultTreeRoot = new DefaultMutableTreeNode();
  434. resultTreeModel = new DefaultTreeModel(resultTreeRoot);
  435. resultTree.setModel(resultTreeModel);
  436. }
  437. }//}}}
  438. //{{{ NewSearchAction class
  439. class NewSearchAction extends AbstractAction
  440. {
  441. public NewSearchAction()
  442. {
  443. super(jEdit.getProperty("hypersearch-results.new-search"));
  444. }
  445. public void actionPerformed(ActionEvent evt)
  446. {
  447. TreePath path = resultTree.getSelectionPath();
  448. DefaultMutableTreeNode operNode = (DefaultMutableTreeNode)path.getLastPathComponent();
  449. HyperSearchFolderNode nodeObj = (HyperSearchFolderNode)operNode.getUserObject();
  450. String glob = "*";
  451. SearchFileSet dirList = SearchAndReplace.getSearchFileSet();
  452. if (dirList instanceof DirectoryListSet)
  453. glob = ((DirectoryListSet)dirList).getFileFilter();
  454. SearchAndReplace.setSearchFileSet(new DirectoryListSet(
  455. nodeObj.getNodeFile().getAbsolutePath(),glob,true));
  456. SearchDialog.showSearchDialog(view,null,SearchDialog.DIRECTORY);
  457. }
  458. }//}}}
  459. //{{{ ExpandChildTreeNodesAction class
  460. class ExpandChildTreeNodesAction extends AbstractAction
  461. {
  462. public ExpandChildTreeNodesAction()
  463. {
  464. super(jEdit.getProperty("hypersearch-results.expand-child-nodes"));
  465. }
  466. public void actionPerformed(ActionEvent evt)
  467. {
  468. TreePath path = resultTree.getSelectionPath();
  469. DefaultMutableTreeNode operNode = (DefaultMutableTreeNode)path.getLastPathComponent();
  470. expandAllNodes(operNode);
  471. }
  472. }//}}}
  473. //{{{ CollapseChildTreeNodesAction class
  474. class CollapseChildTreeNodesAction extends AbstractAction
  475. {
  476. public CollapseChildTreeNodesAction()
  477. {
  478. super(jEdit.getProperty("hypersearch-results.collapse-child-nodes"));
  479. }
  480. public void actionPerformed(ActionEvent evt)
  481. {
  482. TreePath path = resultTree.getSelectionPath();
  483. DefaultMutableTreeNode operNode = (DefaultMutableTreeNode)path.getLastPathComponent();
  484. for (Enumeration e = operNode.children(); e.hasMoreElements();)
  485. {
  486. DefaultMutableTreeNode node = (DefaultMutableTreeNode)e.nextElement();
  487. resultTree.collapsePath(new TreePath(node.getPath()));
  488. }
  489. resultTree.scrollPathToVisible(
  490. new TreePath(operNode.getPath()));
  491. }
  492. }//}}}
  493. //{{{ TreeDisplayAction class
  494. class TreeDisplayAction extends AbstractAction
  495. {
  496. //{{{ actionPerformed method
  497. public void actionPerformed(ActionEvent evt)
  498. {
  499. JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) evt.getSource();
  500. boolean curState = menuItem.isSelected();
  501. TreePath path = resultTree.getSelectionPath();
  502. DefaultMutableTreeNode operNode = (DefaultMutableTreeNode)path.getLastPathComponent();
  503. HyperSearchOperationNode operNodeObj = (HyperSearchOperationNode)operNode.getUserObject();
  504. if (curState)
  505. operNodeObj.cacheResultNodes(operNode);
  506. operNode.removeAllChildren();
  507. Exception excp = null;
  508. if (curState)
  509. {
  510. try
  511. {
  512. operNodeObj.insertTreeNodes(resultTree, operNode);
  513. }
  514. catch (Exception ex)
  515. {
  516. operNodeObj.restoreFlatNodes(resultTree, operNode);
  517. menuItem.setSelected(false);
  518. excp = ex;
  519. }
  520. finally
  521. {
  522. ((DefaultTreeModel)resultTree.getModel()).nodeStructureChanged(operNode);
  523. expandAllNodes(operNode);
  524. resultTree.scrollPathToVisible(
  525. new TreePath(operNode.getPath()));
  526. }
  527. if (excp != null)
  528. throw new RuntimeException(excp);
  529. }
  530. else
  531. operNodeObj.restoreFlatNodes(resultTree, operNode);
  532. operNodeObj.setTreeViewDisplayed(menuItem.isSelected());
  533. }
  534. }//}}}
  535. public void expandAllNodes(DefaultMutableTreeNode node)
  536. {
  537. traverseNodes(node, new TreeNodeCallbackAdapter()
  538. {
  539. public boolean processNode(DefaultMutableTreeNode node) {
  540. resultTree.expandPath(new TreePath(node.getPath()));
  541. return true;
  542. }
  543. });
  544. }
  545. //{{{ GoToNodeAction class
  546. class GoToNodeAction extends AbstractAction
  547. {
  548. private int mode;
  549. public GoToNodeAction(String labelProp, int mode)
  550. {
  551. super(jEdit.getProperty(labelProp));
  552. this.mode = mode;
  553. }
  554. public void actionPerformed(ActionEvent evt)
  555. {
  556. goToSelectedNode(mode);
  557. }
  558. }//}}}
  559. //{{{ ResultCellRenderer class
  560. class ResultCellRenderer extends DefaultTreeCellRenderer
  561. {
  562. Font plainFont, boldFont;
  563. //{{{ ResultCellRenderer constructor
  564. ResultCellRenderer()
  565. {
  566. plainFont = UIManager.getFont("Tree.font");
  567. if(plainFont == null)
  568. plainFont = jEdit.getFontProperty("metal.secondary.font");
  569. boldFont = new Font(plainFont.getName(),Font.BOLD,
  570. plainFont.getSize());
  571. } //}}}
  572. //{{{ getTreeCellRendererComponent() method
  573. public Component getTreeCellRendererComponent(JTree tree,
  574. Object value, boolean sel, boolean expanded,
  575. boolean leaf, int row, boolean hasFocus)
  576. {
  577. super.getTreeCellRendererComponent(tree,value,sel,
  578. expanded,leaf,row,hasFocus);
  579. setIcon(null);
  580. DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
  581. if (node.getUserObject() instanceof HyperSearchOperationNode)
  582. {
  583. ResultCellRenderer.this.setFont(boldFont);
  584. class CountNodes implements HyperSearchTreeNodeCallback
  585. {
  586. int bufferCount = 0, resultCount = 0;
  587. public boolean processNode(DefaultMutableTreeNode node)
  588. {
  589. Object userObject = node.getUserObject();
  590. if (userObject instanceof HyperSearchResult)
  591. resultCount++;
  592. else if (userObject instanceof HyperSearchFileNode)
  593. bufferCount++;
  594. return true;
  595. }
  596. }
  597. CountNodes countNodes = new CountNodes();
  598. traverseNodes(node, countNodes);
  599. String property = "hypersearch-results.result-caption";
  600. if (countNodes.bufferCount == 1)
  601. {
  602. property += countNodes.resultCount == 1 ? "1" : "2";
  603. }
  604. Object[] pp = { node.toString(), new Integer(countNodes.resultCount),
  605. new Integer(countNodes.bufferCount) };
  606. setText(jEdit.getProperty(property,pp));
  607. }
  608. else if(node.getUserObject() instanceof HyperSearchFolderNode)
  609. {
  610. ResultCellRenderer.this.setFont(plainFont);
  611. setText(node.toString() + " (" + node.getChildCount() + " files/folders)");
  612. }
  613. else if(node.getUserObject() instanceof HyperSearchFileNode)
  614. {
  615. // file name
  616. ResultCellRenderer.this.setFont(boldFont);
  617. int count = node.getChildCount();
  618. if(count == 1)
  619. {
  620. setText(jEdit.getProperty("hypersearch-results"
  621. + ".file-caption1",new Object[] {
  622. node.getUserObject()
  623. }));
  624. }
  625. else
  626. {
  627. setText(jEdit.getProperty("hypersearch-results"
  628. + ".file-caption",new Object[] {
  629. node.getUserObject(),
  630. new Integer(count)
  631. }));
  632. }
  633. }
  634. else
  635. {
  636. ResultCellRenderer.this.setFont(plainFont);
  637. }
  638. return this;
  639. } //}}}
  640. } //}}}
  641. // these are used to eliminate code duplication. i don't normally use
  642. // the visitor or "template method" pattern, but this code was contributed
  643. // by Peter Cox and i don't feel like changing it around too much.
  644. //{{{ ResultVisitor interface
  645. interface ResultVisitor
  646. {
  647. public void visit(Buffer buffer, HyperSearchResult result);
  648. } //}}}
  649. //{{{ BufferLoadedVisitor class
  650. class BufferLoadedVisitor implements ResultVisitor
  651. {
  652. public void visit(Buffer buffer, HyperSearchResult result)
  653. {
  654. result.bufferOpened(buffer);
  655. }
  656. } //}}}
  657. //{{{ BufferClosedVisitor class
  658. class BufferClosedVisitor implements ResultVisitor
  659. {
  660. public void visit(Buffer buffer, HyperSearchResult result)
  661. {
  662. result.bufferClosed();
  663. }
  664. } //}}}
  665. //{{{ TreeNodeCallbackAdapter class
  666. class TreeNodeCallbackAdapter implements HyperSearchTreeNodeCallback
  667. {
  668. public boolean processNode(DefaultMutableTreeNode node) {
  669. return false;
  670. }
  671. } //}}}
  672. }