PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/ToolBarManager.java

#
Java | 122 lines | 70 code | 17 blank | 35 comment | 10 complexity | 05cd2be05242c1fdd648ea9ac09e44c7 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. * ToolBarManager.java - Handles tool bars for the View
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2002 mike dillon
  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.gui;
  23. //{{{ Imports
  24. import java.awt.*;
  25. import java.util.*;
  26. import java.util.List;
  27. import org.gjt.sp.jedit.*;
  28. //}}}
  29. public class ToolBarManager
  30. {
  31. //{{{ ToolBarManager constructor
  32. public ToolBarManager(Container top, Container bottom)
  33. {
  34. this.top = top;
  35. this.bottom = bottom;
  36. } //}}}
  37. //{{{ addToolBar() method
  38. public void addToolBar(int group, int layer, Component toolbar)
  39. {
  40. Entry entry = new Entry(layer, toolbar);
  41. if (group == View.TOP_GROUP)
  42. addToolBar(top, topToolBars, entry);
  43. else if (group == View.BOTTOM_GROUP)
  44. addToolBar(bottom, bottomToolBars, entry);
  45. else
  46. throw new InternalError("Invalid tool bar group");
  47. } //}}}
  48. //{{{ removeToolBar() method
  49. public void removeToolBar(Component toolbar)
  50. {
  51. removeToolBar(top, topToolBars, toolbar);
  52. removeToolBar(bottom, bottomToolBars, toolbar);
  53. } //}}}
  54. //{{{ Private members
  55. //{{{ Instance variables
  56. private Container top;
  57. private Container bottom;
  58. private List<Entry> topToolBars = new ArrayList<Entry>();
  59. private List<Entry> bottomToolBars = new ArrayList<Entry>();
  60. //}}}
  61. //{{{ addToolBar() method
  62. private static void addToolBar(Container group, List<Entry> toolbars,
  63. Entry entry)
  64. {
  65. // See if we should place this toolbar before any others
  66. for(int i = 0; i < toolbars.size(); i++)
  67. {
  68. if(entry.layer > toolbars.get(i).layer)
  69. {
  70. toolbars.add(i,entry);
  71. group.add(entry.toolbar,i);
  72. return;
  73. }
  74. }
  75. // Place the toolbar at the bottom of the group
  76. toolbars.add(entry);
  77. group.add(entry.toolbar);
  78. } //}}}
  79. //{{{ removeToolBar() method
  80. private static void removeToolBar(Container group, List<Entry> toolbars,
  81. Component toolbar)
  82. {
  83. for(int i = 0; i < toolbars.size(); i++)
  84. {
  85. if(toolbar == toolbars.get(i).toolbar)
  86. {
  87. group.remove(toolbar);
  88. toolbars.remove(i);
  89. return;
  90. }
  91. }
  92. } //}}}
  93. //}}}
  94. //{{{ Entry class
  95. private static class Entry
  96. {
  97. int layer;
  98. Component toolbar;
  99. Entry(int layer, Component toolbar)
  100. {
  101. this.layer = layer;
  102. this.toolbar = toolbar;
  103. }
  104. } //}}}
  105. }