1 14 package org.wings; 15 16 import org.wings.io.Device; 17 import org.wings.plaf.MenuBarCG; 18 import org.wings.plaf.MenuCG; 19 20 import java.io.IOException ; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 29 public class SMenu extends SMenuItem { 30 private boolean popupMenuVisible = false; 31 protected final List menuItems = new ArrayList (); 32 private double widthScaleFactor = 0.7f; 33 34 public SMenu(String text) { 35 super(text); 36 } 37 38 public SMenu() { 39 super(); 40 } 41 42 public SMenu(SIcon i) { 43 super(i); 44 } 45 46 public SMenu(String text, SIcon icon) { 47 super(text, icon); 48 } 49 50 51 54 public void add(SMenuItem menuItem) { 55 menuItems.add(menuItem); 56 menuItem.setParentMenu(this); 57 } 58 59 62 public void add(SComponent menuItem) { 63 menuItems.add(menuItem); 64 menuItem.setParentFrame(getParentFrame()); 65 } 66 67 public void setParentFrame(SFrame f) { 68 super.setParentFrame(f); 69 for (int i = 0; i < menuItems.size(); i++) 70 ((SComponent) menuItems.get(i)).setParentFrame(f); 71 } 72 73 76 public void add(String menuitem) { 77 this.add(new SMenuItem(menuitem)); 78 } 79 80 public SComponent getMenuComponent(int pos) { 81 return (SComponent) menuItems.get(pos); 82 } 83 84 87 public int getMenuComponentCount() { 88 return menuItems.size(); 89 } 90 91 94 public void removeAll() { 95 while (menuItems.size() > 0) { 96 remove(0); 97 } 98 } 99 100 103 public void remove(int pos) { 104 remove(getMenuComponent(pos)); 105 } 106 107 110 public void remove(SComponent comp) { 111 menuItems.remove(comp); 112 comp.setParentFrame(null); 113 } 114 115 public void setCG(MenuBarCG cg) { 116 super.setCG(cg); 117 } 118 119 125 public void setPopupMenuVisible(boolean b) { 126 if (!isEnabled()) 127 return; 128 popupMenuVisible = b; 129 } 130 131 136 public boolean isPopupMenuVisible() { 137 return popupMenuVisible; 138 } 139 140 147 public double getWidthScaleFactor() { 148 return widthScaleFactor; 149 } 150 159 public void setWidthScaleFactor(double widthScaleFactor) { 160 this.widthScaleFactor = widthScaleFactor; 161 } 162 163 166 public int getChildrenCount() { 167 return menuItems.size(); 168 } 169 170 175 public SComponent getChild(int index) { 176 if (getChildrenCount() > index) { 177 return (SComponent)menuItems.get(index); 178 } else { 179 return null; 180 } 181 } 182 183 public void writePopup(Device device) throws IOException { 184 ((MenuCG)getCG()).writePopup(device, this); 185 } 186 } 187 188 189 | Popular Tags |