package bmsi.fsp; import java.awt.*; import java.awt.peer.MenuBarPeer; import java.io.IOException; import java.util.Vector; class FSMenuBar extends PWin implements MenuBarPeer { private MenuBar target; private Vector menu = new Vector(); private Menu helpMenu; private Menu sysMenu; public void dispose() { setVisible(false); } public void postKey(int k) { } FSMenuBar(MenuBar m,FSToolkit toolkit) { super(toolkit.wm); target = m; setBounds(0,0,getScreenCols(),1); /* Although JDK 1.1 will add the MenuItems to a MenuPeer, it will not add Menus to a MenuBarPeer, so we have to do it ourselves. Wierd. */ // java.awt in JDK 1.0 will addNotify a parent menu before it's submenus! // We have to addNotify() ourselves for the child Menus in this case. Menu menu = m.getHelpMenu(); if (menu != null) { //if (menu.getPeer() == null) // menu.addNotify(); if (menu.getPeer() != null) addHelpMenu(menu); } int n = m.getMenuCount(); for (int i = 0; i < n; ++i) { menu = m.getMenu(i); //if (menu.getPeer() == null) // menu.addNotify(); if (menu.getPeer() != null) addMenu(menu); } } private synchronized String[] getNames() { int n = menu.size(); String[] s = new String[n + 2]; s[0] = "#"; for (int i = 0; i < n; ++i) s[i + 1] = ((Menu)menu.elementAt(i)).getName(); if (helpMenu != null) s[n + 1] = helpMenu.getName(); return s; } protected void paint(int x,int y,int w,int h) throws IOException { String[] s = getNames(); // FIXME: check whether more than one line needed int end = loc.width; char[] c = new char[end]; int pos = 0; int len = 0; for (int i = 0; i < s.length - 1; ++i) { String name = s[i]; len = name.length(); name.getChars(0,len,c,pos); pos += len; c[pos++] = ' '; } String name = s[s.length - 1]; if (name != null) { len = name.length(); end -= len; name.getChars(0,len,c,end); } else len = 0; setAttr(TI.A_DIM+TI.A_REVERSE); write(0,0,c,0,pos); fill(0,pos,end - pos,1,' '); if (len > 0) write(end,0,c,end,len); } public void addHelpMenu(Menu m) { helpMenu = m; } public void addMenu(Menu m) { menu.addElement(m); } public void delMenu(int pos) { menu.removeElementAt(pos); } }