/** * Inserts a separator at the specified position. * * @param index an integer specifying the position at which to insert the menu separator * @exception IllegalArgumentException if the value of <code>index</code> < 0 */ @Override public void insertSeparator(int index) { if (index < 0) { throw new IllegalArgumentException("index less than zero."); } popupMenu.insertSeperator(index); }
/** * Inserts a new menu item with the specified text at a given position. * * @param s the text for the menu item to add * @param pos an integer specifying the position at which to add the new menu item * @exception IllegalArgumentException when the value of <code>pos</code> < 0 */ @Override public void insert(String s, int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } popupMenu.insert(new JMenuItem(s), pos); }
/** * Constructs a new SJMenu. * * <p>|---------|---------| | labelID | itemID | |---------| itemID | | itemID | menuID->| itemID * | |---------| * * @param name the name of the menu. This is the text of the menu label. * @param labelID This is the ID of the menu button (ie, what is shown by default before anything * is clicked). * @param menuID This is the ID of the list of items that shows when you click the menu button. * @param itemID This is the ID of the items themselves. */ public SJMenu(String name, String labelID, String menuID, String itemID) { super(name); setWidgetID(labelID); popupMenu = new SJPopupMenu(menuID); popupMenu.setInvoker(this); this.itemID = itemID; delegate = new SJMenuPaintingDelegate(this); setIcon(buildIcon()); }
/** * Removes the menu item at the specified index from this menu. * * @param pos the position of the item to be removed * @exception IllegalArgumentException if the value of <code>pos</code> < 0, or if <code>pos * </code> is greater than the number of menu items */ @Override public void remove(int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } if (pos > getItemCount()) { throw new IllegalArgumentException("index greater than the number of items."); } if (popupMenu != null) popupMenu.remove(pos); }
/** * Inserts a new menu item attached to the specified <code>Action</code> object at a given * position. * * @param a the <code>Action</code> object for the menu item to add * @param pos an integer specifying the position at which to add the new menu item * @exception IllegalArgumentException if the value of <code>pos</code> < 0 */ @Override public JMenuItem insert(Action a, int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } SJMenuItem mi = new SJMenuItem(a, itemID); popupMenu.insert(mi, pos); return mi; }
/** * Inserts the specified <code>JMenuitem</code> at a given position. * * @param mi the <code>JMenuitem</code> to add * @param pos an integer specifying the position at which to add the new <code>JMenuitem</code> * @return the new menu item * @exception IllegalArgumentException if the value of <code>pos</code> < 0 */ @Override public JMenuItem insert(JMenuItem mi, int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } AccessibleContext ac = mi.getAccessibleContext(); ac.setAccessibleParent(this); popupMenu.insert(mi, pos); return mi; }
/** * Adds the specified component to this container at the given position. If <code>index</code> * equals -1, the component will be appended to the end. * * @param c the <code>Component</code> to add * @param index the position at which to insert the component * @return the <code>Component</code> added * @see #remove * @see java.awt.Container#add(Component, int) */ @Override public Component add(Component c, int index) { if (c instanceof JComponent) { AccessibleContext ac = ((JComponent) c).getAccessibleContext(); if (ac != null) { ac.setAccessibleParent(this); } } popupMenu.add(c, index); return c; }
/** * Returns an array of <code>Component</code>s of the menu's subcomponents. Note that this returns * all <code>Component</code>s in the popup menu, including separators. * * @return an array of <code>Component</code>s or an empty array if there is no popup menu */ @Override public Component[] getMenuComponents() { if (popupMenu != null) return popupMenu.getComponents(); return new Component[0]; }
/** * Returns the component at position <code>n</code>. * * @param n the position of the component to be returned * @return the component requested, or <code>null</code> if there is no popup menu */ @Override public Component getMenuComponent(int n) { if (popupMenu != null) return popupMenu.getComponent(n); return null; }
/** * Returns the number of components on the menu. * * @return an integer containing the number of components on the menu */ @Override public int getMenuComponentCount() { int componentCount = 0; if (popupMenu != null) componentCount = popupMenu.getComponentCount(); return componentCount; }
/** Removes all menu items from this menu. */ @Override public void removeAll() { if (popupMenu != null) popupMenu.removeAll(); }
/** * Removes the component <code>c</code> from this menu. * * @param c the component to be removed */ @Override public void remove(Component c) { if (popupMenu != null) popupMenu.remove(c); }
/** * Removes the specified menu item from this menu. If there is no popup menu, this method will * have no effect. * * @param item the <code>JMenuItem</code> to be removed from the menu */ @Override public void remove(JMenuItem item) { if (popupMenu != null) popupMenu.remove(item); }
/** Appends a new separator to the end of the menu. */ @Override public void addSeparator() { popupMenu.addSeparator(); }
/** * Appends a menu item to the end of this menu. Returns the menu item added. * * @param menuItem the <code>JMenuitem</code> to be added * @return the <code>JMenuItem</code> added */ @Override public JMenuItem add(JMenuItem menuItem) { AccessibleContext ac = menuItem.getAccessibleContext(); ac.setAccessibleParent(this); return popupMenu.add(menuItem); }
@Override public boolean isPopupMenuVisible() { return popupMenu.isVisible(); }