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

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/gui/ToolBarManager.java

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