/plugins/Ancestor/tags/release-1-0-0/src/gatchan/jedit/ancestor/AncestorToolBar.java

# · Java · 70 lines · 60 code · 6 blank · 4 comment · 11 complexity · 8d0c794983b1d653917b0a58b27c2a63 MD5 · raw file

  1. package gatchan.jedit.ancestor;
  2. import org.gjt.sp.jedit.Buffer;
  3. import org.gjt.sp.jedit.View;
  4. import org.gjt.sp.jedit.MiscUtilities;
  5. import org.gjt.sp.jedit.io.VFS;
  6. import org.gjt.sp.jedit.io.VFSManager;
  7. import javax.swing.*;
  8. import java.awt.*;
  9. import java.util.LinkedList;
  10. /**
  11. * @author Matthieu Casanova
  12. * @version $Id: Server.java,v 1.33 2007/01/05 15:15:17 matthieu Exp $
  13. */
  14. public class AncestorToolBar extends JToolBar
  15. {
  16. private View view;
  17. private Component glue = Box.createGlue();
  18. private final LinkedList<String> list = new LinkedList<String>();
  19. public AncestorToolBar(View view)
  20. {
  21. this.view = view;
  22. add(glue);
  23. setFloatable(false);
  24. }
  25. void setBuffer(Buffer buffer)
  26. {
  27. String path = buffer.getPath();
  28. VFS _vfs = VFSManager.getVFSForPath(path);
  29. list.clear();
  30. while (true)
  31. {
  32. list.addFirst(path);
  33. String parent = _vfs.getParentOfPath(path);
  34. if (path == null || MiscUtilities.pathsEqual(path,parent))
  35. break;
  36. path = parent;
  37. }
  38. int count = getComponentCount() - 1;
  39. int nbTokens = list.size();
  40. if (nbTokens < count)
  41. {
  42. for (int i = 0;i<count - nbTokens;i++)
  43. {
  44. remove(0);
  45. }
  46. }
  47. else if (nbTokens > count)
  48. {
  49. for (int i = 0;i<nbTokens-count;i++)
  50. {
  51. add(new AncestorButton(), 0);
  52. }
  53. }
  54. int i = 0;
  55. int nb = list.size();
  56. for (String fileName : list)
  57. {
  58. AncestorButton button = (AncestorButton) getComponent(i);
  59. button.setAncestor(new Ancestor(view, fileName, _vfs.getFileName(fileName)));
  60. i++;
  61. button.setEnabled(nb != i);
  62. }
  63. }
  64. }