1 14 package org.wings; 15 16 import org.wings.plaf.MenuBarCG; 17 18 import javax.swing.*; 19 import java.awt.*; 20 import java.util.ArrayList ; 21 22 38 public class SMenuBar extends SContainer { 39 42 private transient SingleSelectionModel selectionModel; 43 44 private boolean paintBorder = true; 45 private Insets margin = null; 46 47 50 public SMenuBar() { 51 super(); 52 setSelectionModel(new DefaultSingleSelectionModel()); 53 } 54 55 61 public SingleSelectionModel getSelectionModel() { 62 return selectionModel; 63 } 64 65 73 public void setSelectionModel(SingleSelectionModel model) { 74 SingleSelectionModel oldValue = selectionModel; 75 this.selectionModel = model; 76 } 77 78 79 84 public SMenuItem add(SMenuItem c) { 85 super.add(c); 86 return c; 87 } 88 89 96 public SMenuItem getMenuItem(int index) { 97 SComponent c = (SComponent) super.getComponent(index); 98 if (c instanceof SMenuItem) 99 return (SMenuItem) c; 100 return null; 101 } 102 103 108 public int getMenuCount() { 109 return getComponentCount(); 110 } 111 112 119 public int getComponentIndex(SComponent c) { 120 int ncomponents = this.getComponentCount(); 121 for (int i = 0; i < ncomponents; i++) { 122 SComponent comp = getComponent(i); 123 if (comp == c) 124 return i; 125 } 126 return -1; 127 } 128 129 135 public void setSelected(SComponent sel) { 136 SingleSelectionModel model = getSelectionModel(); 137 int index = getComponentIndex(sel); 138 model.setSelectedIndex(index); 139 } 140 141 146 public boolean isSelected() { 147 return selectionModel.isSelected(); 148 } 149 150 155 public boolean isBorderPainted() { 156 return paintBorder; 157 } 158 159 168 public void setBorderPainted(boolean b) { 169 boolean oldValue = paintBorder; 170 paintBorder = b; 171 } 172 173 180 187 188 199 public void setMargin(Insets m) { 200 Insets old = margin; 201 this.margin = m; 202 208 } 209 210 217 public Insets getMargin() { 218 if (margin == null) { 219 return new Insets(0, 0, 0, 0); 220 } else { 221 return margin; 222 } 223 } 224 225 226 229 public void menuSelectionChanged(boolean isIncluded) { 230 } 231 232 241 public String paramString() { 242 String paintBorderString = (paintBorder ? 243 "true" : "false"); 244 String marginString = (margin != null ? 245 margin.toString() : ""); 246 247 return super.paramString() + 248 ",margin=" + marginString + 249 ",paintBorder=" + paintBorderString; 250 } 251 252 public void setCG(MenuBarCG cg) { 253 super.setCG(cg); 254 } 255 256 259 public void closeAllMenus() { 260 265 } 266 267 public ArrayList getMenus() { 268 ArrayList menus = new ArrayList (); 269 if (isVisible()) { 270 SPopupMenu pmenu = getComponentPopupMenu(); 271 if (pmenu != null) { 272 menus.add(pmenu); 273 } 274 for (int i = 0; i < getComponentCount(); i++) { 275 SMenu menu = (SMenu)getComponent(i); 276 if (menus.contains(menu)) { 277 remove(menu); 278 } 279 menus.add(menu); 280 } 281 } 282 return menus; 283 } 284 } 285 286 287 | Popular Tags |