/** * Overridden to toggle the enabled state of various * RSyntaxTextArea-specific menu items. * * If you set the popup menu via {@link #setPopupMenu(JPopupMenu)}, you * will want to override this method, especially if you removed any of the * menu items in the default popup menu. * * @param popupMenu The popup menu. This will never be <code>null</code>. * @see #createPopupMenu() * @see #setPopupMenu(JPopupMenu) */ @Override protected void configurePopupMenu(JPopupMenu popupMenu) { super.configurePopupMenu(popupMenu); // They may have overridden createPopupMenu()... if (popupMenu!=null && popupMenu.getComponentCount()>0 && foldingMenu!=null) { foldingMenu.setEnabled(foldManager. isCodeFoldingSupportedAndEnabled()); } }
@Override public void mousePressed( MouseEvent e ) { popupMenuOperation = false; JPopupMenu menu = getPopupMenu(); if ( menu != null && getModel() instanceof Model ) { Model model = (Model) getModel(); if ( !model._isPressed() ) { if( isInArrowArea( e.getPoint() ) && menu.getComponentCount() > 0 ) { model._press(); menu.addPopupMenuListener( getMenuListener() ); menu.show( DropDownButton.this, 0, getHeight() ); popupMenuOperation = true; } } else { model._release(); menu.removePopupMenuListener( getMenuListener() ); popupMenuOperation = true; } } }
@Override public void mousePressed( MouseEvent e ) { popupMenuOperation = false; JPopupMenu menu = getPopupMenu(); if ( menu != null && getModel() instanceof Model ) { Model model = (Model) getModel(); if ( !model._isPressed() ) { if( isInArrowArea( e.getPoint() ) && menu.getComponentCount() > 0 ) { model._press(); menu.addPopupMenuListener( getMenuListener() ); menu.show( DropDownToggleButton.this, 0, getHeight() ); popupMenuOperation = true; } } else { model._release(); menu.removePopupMenuListener( getMenuListener() ); popupMenuOperation = true; } } }
popup.insert(panelCustomMethod, popup.getComponentCount());
/** * Returns the number of menu items and separators in the popup menu. * * @return The number of menu items and separators. * @see #addMenuItem(JMenuItem) * @see #addSeparator() * @see #insertMenuItem(JMenuItem, int) * @see #removeItem(int) */ public int getItemCount() { return popupMenu.getComponentCount(); }
private static void addSeparatorIfAnyComponentsAdded(JPopupMenu popup, int componentCountBevore) { if (popup.getComponentCount() > componentCountBevore) { popup.addSeparator(); } }
public void addDefaultPopupMenuItems(JPopupMenu menu, final JTableHeader header) { if (menu.getComponentCount() > 0) menu.addSeparator(); JMenuItem selectCols = new JMenuItem("Select Columns..."); selectCols.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showSelectionDialog(header); } }); menu.add(selectCols); }
private int getMenuIndexByGravity(JMenuItem item) { Double gravity = this.actionGravityMap.get(item); Double gravityX; for (int i=0; i < popup.getComponentCount(); i++ ){ gravityX = this.actionGravityMap.get(popup.getComponent(i)); if (gravity < gravityX){ return i; } } return popup.getComponentCount(); }
@ScriptFunction(jsDoc = COUNT_JSDOC) @Override public int getCount() { return super.getComponentCount(); }
/** Adds a separator to the supplied menu. The separator will only be added, if the previous item is not a separator. */ protected void maybeAddSeparator(JMenu m) { JPopupMenu pm = m.getPopupMenu(); if (pm.getComponentCount() > 0 // && !(pm.getComponent(pm.getComponentCount() - 1) instanceof JSeparator)) { m.addSeparator(); } }
/** * Adds a separator to the popup menu if there are menu items on it already. * * @param popup the popup menu. */ public static void addSeparatorIfNecessary(JPopupMenu popup) { int count = popup.getComponentCount(); if (count > 0 && !(popup.getComponent(count - 1) instanceof JSeparator)) { popup.addSeparator(); } }
@Override public void addSeparator() { int count = target.getComponentCount(); boolean canAddSeparator = count != 0 && target.getComponent(count-1).getClass() != JPopupMenu.Separator.class; if ( canAddSeparator ) target.addSeparator(); }
/** * Check if the popup menu should stay hidden although {@link #setPopupMenuVisible(boolean)} is invoked. * <p/> * The default implementation is to check if it contains any menu items. You could override this method to change the * default behavior. * * @return true if the popup menu should stay invisible. Otherwise false. */ protected boolean shouldHidePopupMenu() { return getPopupMenu().getComponentCount() == 0; }
public static Component findMenuComponent(JPopupMenu menu, String menuComponentName) { for (int i = 0; i < menu.getComponentCount(); i++) { Component component = menu.getComponent(i); if (menuComponentName.equals(component.getName())) return component; } return null; }
@Override public void addSeparator() { int count = target.getComponentCount(); boolean canAddSeparator = count != 0 && target.getComponent(count-1).getClass() != JPopupMenu.Separator.class; if ( canAddSeparator ) target.addSeparator(); }
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { if ( menu.getComponentCount() == 0 ) { JComponent content = buildContent(); defaultSize = content.getPreferredSize(); menu.add( content ); } beforeShow(); }
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { if ( menu.getComponentCount() == 0 ) { JComponent content = buildContent(); defaultSize = content.getPreferredSize(); menu.add( content ); } beforeShow(); }
private boolean fitsOnScreen(final JPopupMenu popupMenu, final Component component) { final int itemCount = popupMenu.getComponentCount(); return itemCount < getMaxMenuItemCount() && (popupMenu.getPreferredSize().height + component.getPreferredSize().height) < MAX_HEIGHT; }
/** * Sets the action commands of all menu items to the specified command */ private void setMenuCommands(JPopupMenu menu, String command) { for (int i = 0; i < menu.getComponentCount() ; i++) { JMenuItem item = (JMenuItem) menu.getComponent(i); item.setActionCommand(command); } } // setMenuCommands
protected void initPopup() { if (popupMenu == null) { popupMenu = new JPopupMenu("TabPopup"); popupMenu.add(new SelectNextTabAction()); popupMenu.add(new SelectPreviousTabAction()); popupMenu.addSeparator(); } for (int i = 3, size = popupMenu.getComponentCount(); i < size; i++) popupMenu.remove(3); for (ToolWindowTab tab : toolWindow.getToolWindowTabs()) popupMenu.add(new SelectTabAction(tab)); }