/bundles/plugins-trunk/Ancestor/src/gatchan/jedit/ancestor/AncestorToolBar.java

# · Java · 96 lines · 62 code · 8 blank · 26 comment · 15 complexity · 52ac7c207f261c607c28b26a10678182 MD5 · raw file

  1. /*
  2. * AncestorToolBar.java - The ancestor toolbar
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2007, 2011 Matthieu Casanova
  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. * 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. package gatchan.jedit.ancestor;
  22. import org.gjt.sp.jedit.Buffer;
  23. import org.gjt.sp.jedit.View;
  24. import org.gjt.sp.jedit.MiscUtilities;
  25. import org.gjt.sp.jedit.io.VFS;
  26. import org.gjt.sp.jedit.io.VFSManager;
  27. import javax.swing.*;
  28. import java.util.LinkedList;
  29. /**
  30. * @author Matthieu Casanova
  31. * @version $Id: Server.java,v 1.33 2007/01/05 15:15:17 matthieu Exp $
  32. */
  33. public class AncestorToolBar extends JToolBar
  34. {
  35. private final View view;
  36. private final LinkedList<String> list = new LinkedList<String>();
  37. //{{{ AncestorToolBar constructor
  38. public AncestorToolBar(View view)
  39. {
  40. this.view = view;
  41. } //}}}
  42. //{{{ setBuffer() method
  43. void setBuffer(Buffer buffer)
  44. {
  45. String path = buffer.getPath();
  46. list.clear();
  47. while (true)
  48. {
  49. list.addFirst(path);
  50. VFS _vfs = VFSManager.getVFSForPath(path);
  51. String parent = _vfs.getParentOfPath(path);
  52. if (path == null || MiscUtilities.pathsEqual(path, parent))
  53. break;
  54. path = parent;
  55. }
  56. int count = getComponentCount() - 1;
  57. int nbTokens = list.size();
  58. if (nbTokens < count)
  59. {
  60. for (int i = 0; i < count - nbTokens; i++)
  61. {
  62. remove(0);
  63. }
  64. }
  65. else if (nbTokens > count)
  66. {
  67. for (int i = 0; i < nbTokens - count; i++)
  68. {
  69. add(new AncestorButton(), 0);
  70. }
  71. }
  72. int i = 0;
  73. int nb = list.size();
  74. for (String fileName : list)
  75. {
  76. VFS _vfs = VFSManager.getVFSForPath(fileName);
  77. boolean browseable = (_vfs.getCapabilities() & VFS.BROWSE_CAP) != 0;
  78. AncestorButton button = (AncestorButton) getComponent(i);
  79. button.setAncestor(new Ancestor(view, fileName, _vfs.getFileName(fileName)));
  80. i++;
  81. button.setEnabled(browseable && nb != i);
  82. if (nb - 1 == i)
  83. {
  84. button.setText("<html><b>" + button.getText() + "</b></html>");
  85. }
  86. }
  87. } //}}}
  88. }