1 22 23 package org.gjt.sp.jedit.gui; 24 25 import java.awt.*; 27 import java.util.*; 28 import org.gjt.sp.jedit.*; 29 31 public class ToolBarManager 32 { 33 public ToolBarManager(Container top, Container bottom) 35 { 36 this.top = top; 37 this.bottom = bottom; 38 } 40 public void addToolBar(int group, int layer, Component toolbar) 42 { 43 Entry entry = new Entry(layer, toolbar); 44 45 if (group == View.TOP_GROUP) 46 addToolBar(top, topToolBars, entry); 47 else if (group == View.BOTTOM_GROUP) 48 addToolBar(bottom, bottomToolBars, entry); 49 else 50 throw new InternalError ("Invalid tool bar group"); 51 } 53 public void removeToolBar(Component toolbar) 55 { 56 removeToolBar(top, topToolBars, toolbar); 57 removeToolBar(bottom, bottomToolBars, toolbar); 58 } 60 62 private Container top; 64 private Container bottom; 65 66 private ArrayList topToolBars = new ArrayList(); 67 private ArrayList bottomToolBars = new ArrayList(); 68 70 private void addToolBar(Container group, ArrayList toolbars, 72 Entry entry) 73 { 74 for(int i = 0; i < toolbars.size(); i++) 76 { 77 if(entry.layer > ((Entry)toolbars.get(i)).layer) 78 { 79 toolbars.add(i,entry); 80 group.add(entry.toolbar,i); 81 return; 82 } 83 } 84 85 toolbars.add(entry); 87 group.add(entry.toolbar); 88 } 90 private void removeToolBar(Container group, ArrayList toolbars, 92 Component toolbar) 93 { 94 for(int i = 0; i < toolbars.size(); i++) 95 { 96 if(toolbar == ((Entry)toolbars.get(i)).toolbar) 97 { 98 group.remove(toolbar); 99 toolbars.remove(i); 100 101 return; 102 } 103 } 104 } 106 108 static class Entry 110 { 111 int layer; 112 Component toolbar; 113 114 Entry(int layer, Component toolbar) 115 { 116 this.layer = layer; 117 this.toolbar = toolbar; 118 } 119 } } 121 | Popular Tags |