diff --git a/openide.awt/src/org/openide/awt/DropDownButton.java b/openide.awt/src/org/openide/awt/DropDownButton.java --- a/openide.awt/src/org/openide/awt/DropDownButton.java +++ b/openide.awt/src/org/openide/awt/DropDownButton.java @@ -90,11 +90,13 @@ private static final String ICON_ROLLOVER_SELECTED_LINE = "rolloverSelectedLine"; //NOI18N private PopupMenuListener menuListener; + private boolean arrowHasSeparateState; /** Creates a new instance of MenuToggleButton */ - public DropDownButton( Icon icon, JPopupMenu popup ) { + public DropDownButton( Icon icon, JPopupMenu popup, boolean arrowHasSeparateState) { Parameters.notNull("icon", icon); //NOI18N assert null != icon; + this.arrowHasSeparateState = arrowHasSeparateState; putClientProperty( DropDownButtonFactory.PROP_DROP_DOWN_MENU, popup ); @@ -124,12 +126,16 @@ @Override public void mousePressed( MouseEvent e ) { + if (!isEnabled()) { // when button is disabled no popup should be shown + return; + } 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 ) { + if( (isInArrowArea( e.getPoint() ) || !DropDownButton.this.arrowHasSeparateState) + && menu.getComponentCount() > 0 ) { model._press(); menu.addPopupMenuListener( getMenuListener() ); menu.show( DropDownButton.this, 0, getHeight() ); @@ -243,7 +249,7 @@ Icon orig = regIcons.get( ICON_ROLLOVER ); if( null == orig ) orig = regIcons.get( ICON_NORMAL ); - icon = new IconWithArrow( orig, !mouseInArrowArea ); + icon = new IconWithArrow( orig, arrowHasSeparateState ? !mouseInArrowArea : false ); arrowIcons.put( mouseInArrowArea ? ICON_ROLLOVER : ICON_ROLLOVER_LINE, icon ); } return icon; @@ -258,7 +264,7 @@ orig = regIcons.get( ICON_ROLLOVER ); if( null == orig ) orig = regIcons.get( ICON_NORMAL ); - icon = new IconWithArrow( orig, !mouseInArrowArea ); + icon = new IconWithArrow( orig, arrowHasSeparateState ? !mouseInArrowArea : false ); arrowIcons.put( mouseInArrowArea ? ICON_ROLLOVER_SELECTED : ICON_ROLLOVER_SELECTED_LINE, icon ); } return icon; diff --git a/openide.awt/src/org/openide/awt/DropDownButtonFactory.java b/openide.awt/src/org/openide/awt/DropDownButtonFactory.java --- a/openide.awt/src/org/openide/awt/DropDownButtonFactory.java +++ b/openide.awt/src/org/openide/awt/DropDownButtonFactory.java @@ -80,7 +80,24 @@ * @return A button that is capable of displaying an 'arrow' in its icon to open a popup menu. */ public static JButton createDropDownButton( Icon icon, JPopupMenu dropDownMenu ) { - return new DropDownButton( icon, dropDownMenu ); + return new DropDownButton( icon, dropDownMenu, true); + } + + /** + * Creates JButton badged with a small arrow that shows the provided popup menu when + * clicked. Difference from {@link #createDropDownButton(javax.swing.Icon, javax.swing.JPopupMenu)} + * is that small arrow and button do not have separate state - they both behave + * as a single button which only purpose is to show popup. + * + * @param icon The default icon, cannot be null + * @param dropDownMenu Popup menu to display when the button is clicked. If this parameter is null + * then the button doesn't show any arrow and behaves like a regular JButton. It is possible to add + * the popup menu later using PROP_DROP_DOWN_MENU client property. + * @return A button that is capable of displaying an 'arrow' in its icon to open a popup menu. + * @since X.Y + */ + public static JButton createSimpleDropDownButton( Icon icon, JPopupMenu dropDownMenu) { + return new DropDownButton( icon, dropDownMenu, false); } /**