# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\projects\nb.m9\openide\awt # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: nbproject/project.properties *** D:\projects\nb.m9\openide\awt\nbproject\project.properties Base (1.10) --- D:\projects\nb.m9\openide\awt\nbproject\project.properties Locally Modified (Based On 1.10) *************** *** 24,27 **** #javadoc.apichanges=${basedir}/api/apichanges.xml javadoc.apichanges=${basedir}/apichanges.xml ! spec.version.base=6.10.0 --- 24,27 ---- #javadoc.apichanges=${basedir}/api/apichanges.xml javadoc.apichanges=${basedir}/apichanges.xml ! spec.version.base=6.11.0 Index: src/org/openide/awt/IconWithArrow.java *** D:\projects\nb.m9\openide\awt\src\org\openide\awt\IconWithArrow.java No Base Revision --- D:\projects\nb.m9\openide\awt\src\org\openide\awt\IconWithArrow.java Locally New *************** *** 1,0 **** --- 1,85 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.openide.awt; + + import java.awt.Color; + import java.awt.Component; + import java.awt.Graphics; + import javax.swing.Icon; + import javax.swing.ImageIcon; + import javax.swing.UIManager; + import org.openide.util.Utilities; + + /** + * An icon that paints a small arrow to the right of the provided icon. + * + * @author S. Aubrecht + * @since 6.11 + */ + class IconWithArrow implements Icon { + + private Icon orig; + private Icon arrow = new ImageIcon( Utilities.loadImage( "org/openide/awt/resources/arrow.png" ) ); //NOI18N + private boolean paintRollOver; + + private static final int GAP = 6; + + /** Creates a new instance of IconWithArrow */ + public IconWithArrow( Icon orig, boolean paintRollOver ) { + this.orig = orig; + this.paintRollOver = paintRollOver; + } + + public void paintIcon( Component c, Graphics g, int x, int y ) { + int height = getIconHeight(); + orig.paintIcon( c, g, x, y+(height-orig.getIconHeight())/2 ); + + arrow.paintIcon( c, g, x+GAP+orig.getIconWidth(), y+(height-arrow.getIconHeight())/2 ); + + if( paintRollOver ) { + Color brighter = UIManager.getColor( "controlHighlight" ); //NOI18N + Color darker = UIManager.getColor( "controlShadow" ); //NOI18N + if( null == brighter || null == darker ) { + brighter = c.getBackground().brighter(); + darker = c.getBackground().darker(); + } + if( null != brighter && null != darker ) { + g.setColor( brighter ); + g.drawLine( x+orig.getIconWidth()+1, y, + x+orig.getIconWidth()+1, y+getIconHeight() ); + g.setColor( darker ); + g.drawLine( x+orig.getIconWidth()+2, y, + x+orig.getIconWidth()+2, y+getIconHeight() ); + } + } + } + + public int getIconWidth() { + return orig.getIconWidth() + GAP + arrow.getIconWidth(); + } + + public int getIconHeight() { + return Math.max( orig.getIconHeight(), arrow.getIconHeight() ); + } + + public static int getArrowAreaWidth() { + return GAP/2 + 5; + } + } Index: src/org/openide/awt/DropDownToggleButton.java *** D:\projects\nb.m9\openide\awt\src\org\openide\awt\DropDownToggleButton.java No Base Revision --- D:\projects\nb.m9\openide\awt\src\org\openide\awt\DropDownToggleButton.java Locally New *************** *** 1,0 **** --- 1,348 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.openide.awt; + + import java.awt.Point; + import java.awt.event.MouseAdapter; + import java.awt.event.MouseEvent; + import java.awt.event.MouseMotionAdapter; + import java.beans.PropertyChangeEvent; + import java.beans.PropertyChangeListener; + import java.util.HashMap; + import java.util.Map; + import javax.swing.Icon; + import javax.swing.JPopupMenu; + import javax.swing.JToggleButton; + import javax.swing.event.PopupMenuEvent; + import javax.swing.event.PopupMenuListener; + + /** + * JToggleButton with a small arrow that displays popup menu when clicked. + * + * @author S. Aubrecht + * @since 6.11 + */ + class DropDownToggleButton extends JToggleButton { + + private boolean mouseInArrowArea = false; + + private Map regIcons = new HashMap( 5 ); + private Map arrowIcons = new HashMap( 5 ); + + private static final String ICON_NORMAL = "normal"; //NOI18N + private static final String ICON_PRESSED = "pressed"; //NOI18N + private static final String ICON_ROLLOVER = "rollover"; //NOI18N + private static final String ICON_ROLLOVER_SELECTED = "rolloverSelected"; //NOI18N + private static final String ICON_SELECTED = "selected"; //NOI18N + private static final String ICON_DISABLED = "disabled"; //NOI18N + private static final String ICON_DISABLED_SELECTED = "disabledSelected"; //NOI18N + + private static final String ICON_ROLLOVER_LINE = "rolloverLine"; //NOI18N + private static final String ICON_ROLLOVER_SELECTED_LINE = "rolloverSelectedLine"; //NOI18N + + private PopupMenuListener menuListener; + + /** Creates a new instance of DropDownToggleButton */ + public DropDownToggleButton( Icon icon, JPopupMenu popup ) { + assert null != icon; + + putClientProperty( DropDownButtonFactory.PROP_DROP_DOWN_MENU, popup ); + + setIcon( icon ); + + resetIcons(); + + addPropertyChangeListener( DropDownButtonFactory.PROP_DROP_DOWN_MENU,new PropertyChangeListener() { + public void propertyChange( PropertyChangeEvent e ) { + resetIcons(); + } + }); + + addMouseMotionListener( new MouseMotionAdapter() { + public void mouseMoved( MouseEvent e ) { + if( null != getPopupMenu() ) { + mouseInArrowArea = isInArrowArea( e.getPoint() ); + updateRollover( _getRolloverIcon(), _getRolloverSelectedIcon() ); + } + } + }); + + addMouseListener( new MouseAdapter() { + public void mousePressed( MouseEvent e ) { + if( isInArrowArea( e.getPoint() ) && null != getPopupMenu() ) { + JPopupMenu menu = getPopupMenu(); + if( getModel() instanceof Model ) { + ((Model)getModel())._press(); + menu.addPopupMenuListener( getMenuListener() ); + } + menu.show( DropDownToggleButton.this, 0, getHeight() ); + } + } + + public void mouseEntered( MouseEvent e ) { + if( hasPopupMenu() ) { + mouseInArrowArea = isInArrowArea( e.getPoint() ); + updateRollover( _getRolloverIcon(), _getRolloverSelectedIcon() ); + } + } + + public void mouseExited( MouseEvent e ) { + mouseInArrowArea = false; + if( hasPopupMenu() ) { + updateRollover( _getRolloverIcon(), _getRolloverSelectedIcon() ); + } + } + }); + + setModel( new Model() ); + } + + private PopupMenuListener getMenuListener() { + if( null == menuListener ) { + menuListener = new PopupMenuListener() { + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + } + + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + if( getModel() instanceof Model ) { + ((Model)getModel())._release(); + } + JPopupMenu menu = getPopupMenu(); + if( null != menu ) + menu.removePopupMenuListener( this ); + } + + public void popupMenuCanceled(PopupMenuEvent e) { + } + }; + } + return menuListener; + } + + private void updateRollover( Icon rollover, Icon rolloverSelected ) { + super.setRolloverIcon( rollover ); + super.setRolloverSelectedIcon( rolloverSelected ); + } + + private void resetIcons() { + Icon icon = regIcons.get( ICON_NORMAL ); + if( null != icon ) + setIcon( icon ); + + icon = regIcons.get( ICON_PRESSED ); + if( null != icon ) + setPressedIcon( icon ); + + icon = regIcons.get( ICON_ROLLOVER ); + if( null != icon ) + setRolloverIcon( icon ); + + icon = regIcons.get( ICON_ROLLOVER_SELECTED ); + if( null != icon ) + setRolloverSelectedIcon( icon ); + + icon = regIcons.get( ICON_SELECTED ); + if( null != icon ) + setSelectedIcon( icon ); + + icon = regIcons.get( ICON_DISABLED ); + if( null != icon ) + setDisabledIcon( icon ); + + icon = regIcons.get( ICON_DISABLED_SELECTED ); + if( null != icon ) + setDisabledSelectedIcon( icon ); + } + + private Icon _getRolloverIcon() { + IconWithArrow icon = null; + icon = arrowIcons.get( mouseInArrowArea ? ICON_ROLLOVER : ICON_ROLLOVER_LINE ); + if( null == icon ) { + Icon orig = regIcons.get( ICON_ROLLOVER ); + if( null == orig ) + orig = regIcons.get( ICON_NORMAL ); + icon = new IconWithArrow( orig, !mouseInArrowArea ); + arrowIcons.put( mouseInArrowArea ? ICON_ROLLOVER : ICON_ROLLOVER_LINE, icon ); + } + return icon; + } + + private Icon _getRolloverSelectedIcon() { + IconWithArrow icon = null; + icon = arrowIcons.get( mouseInArrowArea ? ICON_ROLLOVER_SELECTED : ICON_ROLLOVER_SELECTED_LINE ); + if( null == icon ) { + Icon orig = regIcons.get( ICON_ROLLOVER_SELECTED ); + if( null == orig ) + orig = regIcons.get( ICON_ROLLOVER ); + if( null == orig ) + orig = regIcons.get( ICON_NORMAL ); + icon = new IconWithArrow( orig, !mouseInArrowArea ); + arrowIcons.put( mouseInArrowArea ? ICON_ROLLOVER_SELECTED : ICON_ROLLOVER_SELECTED_LINE, icon ); + } + return icon; + } + + JPopupMenu getPopupMenu() { + Object menu = getClientProperty( DropDownButtonFactory.PROP_DROP_DOWN_MENU ); + if( null != menu && menu instanceof JPopupMenu ) { + return (JPopupMenu)menu; + } + return null; + } + + boolean hasPopupMenu() { + return null != getPopupMenu(); + } + + private boolean isInArrowArea( Point p ) { + return p.getLocation().x >= getWidth() - IconWithArrow.getArrowAreaWidth() - getInsets().right; + } + + @Override + public void setIcon(Icon icon) { + assert null != icon; + regIcons.put( ICON_NORMAL, icon ); + IconWithArrow arrow = new IconWithArrow( icon, false ); + arrowIcons.put( ICON_NORMAL, arrow ); + arrowIcons.remove( ICON_ROLLOVER_LINE ); + arrowIcons.remove( ICON_ROLLOVER_SELECTED_LINE ); + arrowIcons.remove( ICON_ROLLOVER ); + arrowIcons.remove( ICON_ROLLOVER_SELECTED ); + super.setIcon( hasPopupMenu() ? arrow : icon ); + } + + private IconWithArrow updateIcons( Icon orig, String iconType ) { + IconWithArrow arrow = null; + if( null == orig ) { + regIcons.remove( iconType ); + arrowIcons.remove( iconType ); + } else { + regIcons.put( iconType, orig ); + arrow = new IconWithArrow( orig, false ); + arrowIcons.put( iconType, arrow ); + } + return arrow; + } + + @Override + public void setPressedIcon(Icon icon) { + IconWithArrow arrow = updateIcons( icon, ICON_PRESSED ); + super.setPressedIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setSelectedIcon(Icon icon) { + IconWithArrow arrow = updateIcons( icon, ICON_SELECTED ); + super.setSelectedIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setRolloverIcon(Icon icon) { + IconWithArrow arrow = updateIcons( icon, ICON_ROLLOVER ); + arrowIcons.remove( ICON_ROLLOVER_LINE ); + arrowIcons.remove( ICON_ROLLOVER_SELECTED_LINE ); + super.setRolloverIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setRolloverSelectedIcon(Icon icon) { + IconWithArrow arrow = updateIcons( icon, ICON_ROLLOVER_SELECTED ); + arrowIcons.remove( ICON_ROLLOVER_SELECTED_LINE ); + super.setRolloverSelectedIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setDisabledIcon(Icon icon) { + //TODO use 'disabled' arrow icon + IconWithArrow arrow = updateIcons( icon, ICON_DISABLED ); + super.setDisabledIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setDisabledSelectedIcon(Icon icon) { + //TODO use 'disabled' arrow icon + IconWithArrow arrow = updateIcons( icon, ICON_DISABLED_SELECTED ); + super.setDisabledSelectedIcon( hasPopupMenu() ? arrow : icon ); + } + + private class Model extends JToggleButton.ToggleButtonModel { + private boolean _pressed = false; + + public void setPressed(boolean b) { + if( mouseInArrowArea || _pressed ) + return; + super.setPressed( b ); + } + + public void _press() { + if((isPressed()) || !isEnabled()) { + return; + } + + stateMask |= PRESSED + ARMED; + + fireStateChanged(); + _pressed = true; + } + + public void _release() { + _pressed = false; + mouseInArrowArea = false; + setArmed( false ); + setPressed( false ); + setRollover( false ); + } + + @Override + protected void fireStateChanged() { + if( _pressed ) + return; + super.fireStateChanged(); + } + + @Override + public void setArmed(boolean b) { + if( _pressed ) + return; + super.setArmed(b); + } + + @Override + public void setEnabled(boolean b) { + if( _pressed ) + return; + super.setEnabled(b); + } + + @Override + public void setSelected(boolean b) { + if( _pressed ) + return; + super.setSelected(b); + } + + @Override + public void setRollover(boolean b) { + if( _pressed ) + return; + super.setRollover(b); + } + } + } Index: src/org/openide/awt/DropDownButtonFactory.java *** D:\projects\nb.m9\openide\awt\src\org\openide\awt\DropDownButtonFactory.java No Base Revision --- D:\projects\nb.m9\openide\awt\src\org\openide\awt\DropDownButtonFactory.java Locally New *************** *** 1,0 **** --- 1,72 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.openide.awt; + + import javax.swing.Icon; + import javax.swing.JButton; + import javax.swing.JPopupMenu; + import javax.swing.JToggleButton; + + /** + * Factory creating buttons with a small arrow icon that shows a popup menu when clicked. + * The default button behavior hasn't changed. + * + * @author S. Aubrecht + * @since 6.11 + */ + public final class DropDownButtonFactory { + + /** + * Use this property name to assign or remove popup menu to/from buttons created by this factory, + * e.g. dropDownButton.putClientProperty( PROP_DROP_DOWN_MENU, new JPopupMenu() ) + * The property value must be JPopupMenu, removing this property removes the arrow from the button. + */ + public static final String PROP_DROP_DOWN_MENU = "dropDownMenu"; + + /** Creates a new instance of DropDownButtonFactory */ + private DropDownButtonFactory() { + } + + /** + * Creates JButton with a small arrow that shows the provided popup menu when clicked. + * + * @param icon The default icon, can be null + * @param dropDownMenu Popup menu to display when the arrow 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. + */ + public static JButton createDropDownButton( Icon icon, JPopupMenu dropDownMenu ) { + return new DropDownButton( icon, dropDownMenu ); + } + + /** + * Creates JToggleButton with a small arrow that shows the provided popup menu when clicked. + * + * @param icon The default icon, can be null + * @param dropDownMenu Popup menu to display when the arrow is clicked. If this parameter is null + * then the button doesn't show any arrow and behaves like a regular JToggleButton. It is possible to add + * the popup menu later using PROP_DROP_DOWN_MENU client property. + * @return A toggle-button that is capable of displaying an 'arrow' in its icon to open a popup menu. + */ + public static JToggleButton createDropDownToggleButton( Icon icon, JPopupMenu dropDownMenu ) { + return new DropDownToggleButton( icon, dropDownMenu ); + } + } Index: apichanges.xml *** D:\projects\nb.m9\openide\awt\apichanges.xml Base (1.10) --- D:\projects\nb.m9\openide\awt\apichanges.xml Locally Modified (Based On 1.10) *************** *** 23,28 **** --- 23,42 ---- AWT API + + + Added factory class for drop-down buttons + + + + + + Added a factory class that can create special buttons with a small arrow icon that brings up a popup menu when clicked. + + + + + Added TabbedPane with closeable tabs Index: src/org/openide/awt/DropDownButton.java *** D:\projects\nb.m9\openide\awt\src\org\openide\awt\DropDownButton.java No Base Revision --- D:\projects\nb.m9\openide\awt\src\org\openide\awt\DropDownButton.java Locally New *************** *** 1,0 **** --- 1,351 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.openide.awt; + + import java.awt.Point; + import java.awt.event.MouseAdapter; + import java.awt.event.MouseEvent; + import java.awt.event.MouseMotionAdapter; + import java.beans.PropertyChangeEvent; + import java.beans.PropertyChangeListener; + import java.util.HashMap; + import java.util.Map; + import javax.swing.DefaultButtonModel; + import javax.swing.Icon; + import javax.swing.JButton; + import javax.swing.JPopupMenu; + import javax.swing.event.PopupMenuEvent; + import javax.swing.event.PopupMenuListener; + + /** + * JButton with a small arrow that displays popup menu when clicked. + * + * @author S. Aubrecht + * @since 6.11 + */ + class DropDownButton extends JButton { + + private boolean mouseInArrowArea = false; + + private Map regIcons = new HashMap( 5 ); + private Map arrowIcons = new HashMap( 5 ); + + private static final String ICON_NORMAL = "normal"; //NOI18N + private static final String ICON_PRESSED = "pressed"; //NOI18N + private static final String ICON_ROLLOVER = "rollover"; //NOI18N + private static final String ICON_ROLLOVER_SELECTED = "rolloverSelected"; //NOI18N + private static final String ICON_SELECTED = "selected"; //NOI18N + private static final String ICON_DISABLED = "disabled"; //NOI18N + private static final String ICON_DISABLED_SELECTED = "disabledSelected"; //NOI18N + + private static final String ICON_ROLLOVER_LINE = "rolloverLine"; //NOI18N + private static final String ICON_ROLLOVER_SELECTED_LINE = "rolloverSelectedLine"; //NOI18N + + private PopupMenuListener menuListener; + + /** Creates a new instance of MenuToggleButton */ + public DropDownButton( Icon icon, JPopupMenu popup ) { + assert null != icon; + + putClientProperty( DropDownButtonFactory.PROP_DROP_DOWN_MENU, popup ); + + setIcon( icon ); + + resetIcons(); + + addPropertyChangeListener( DropDownButtonFactory.PROP_DROP_DOWN_MENU,new PropertyChangeListener() { + public void propertyChange( PropertyChangeEvent e ) { + resetIcons(); + } + }); + + addMouseMotionListener( new MouseMotionAdapter() { + public void mouseMoved( MouseEvent e ) { + if( null != getPopupMenu() ) { + mouseInArrowArea = isInArrowArea( e.getPoint() ); + updateRollover( _getRolloverIcon(), _getRolloverSelectedIcon() ); + } + } + }); + + addMouseListener( new MouseAdapter() { + public void mousePressed( MouseEvent e ) { + if( isInArrowArea( e.getPoint() ) && null != getPopupMenu() ) { + JPopupMenu menu = getPopupMenu(); + if( getModel() instanceof Model ) { + ((Model)getModel())._press(); + menu.addPopupMenuListener( getMenuListener() ); + } + menu.show( DropDownButton.this, 0, getHeight() ); + } + } + + public void mouseEntered( MouseEvent e ) { + if( hasPopupMenu() ) { + mouseInArrowArea = isInArrowArea( e.getPoint() ); + updateRollover( _getRolloverIcon(), _getRolloverSelectedIcon() ); + } + } + + public void mouseExited( MouseEvent e ) { + mouseInArrowArea = false; + if( hasPopupMenu() ) { + updateRollover( _getRolloverIcon(), _getRolloverSelectedIcon() ); + } + } + }); + + setModel( new Model() ); + } + + private PopupMenuListener getMenuListener() { + if( null == menuListener ) { + menuListener = new PopupMenuListener() { + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + } + + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + if( getModel() instanceof Model ) { + ((Model)getModel())._release(); + } + JPopupMenu menu = getPopupMenu(); + if( null != menu ) + menu.removePopupMenuListener( this ); + } + + public void popupMenuCanceled(PopupMenuEvent e) { + } + }; + } + return menuListener; + } + + private void updateRollover( Icon rollover, Icon rolloverSelected ) { + super.setRolloverIcon( rollover ); + super.setRolloverSelectedIcon( rolloverSelected ); + } + + private void resetIcons() { + Icon icon = regIcons.get( ICON_NORMAL ); + if( null != icon ) + setIcon( icon ); + + icon = regIcons.get( ICON_PRESSED ); + if( null != icon ) + setPressedIcon( icon ); + + icon = regIcons.get( ICON_ROLLOVER ); + if( null != icon ) + setRolloverIcon( icon ); + + icon = regIcons.get( ICON_ROLLOVER_SELECTED ); + if( null != icon ) + setRolloverSelectedIcon( icon ); + + icon = regIcons.get( ICON_SELECTED ); + if( null != icon ) + setSelectedIcon( icon ); + + icon = regIcons.get( ICON_DISABLED ); + if( null != icon ) + setDisabledIcon( icon ); + + icon = regIcons.get( ICON_DISABLED_SELECTED ); + if( null != icon ) + setDisabledSelectedIcon( icon ); + } + + private Icon _getRolloverIcon() { + IconWithArrow icon = null; + icon = arrowIcons.get( mouseInArrowArea ? ICON_ROLLOVER : ICON_ROLLOVER_LINE ); + if( null == icon ) { + Icon orig = regIcons.get( ICON_ROLLOVER ); + if( null == orig ) + orig = regIcons.get( ICON_NORMAL ); + icon = new IconWithArrow( orig, !mouseInArrowArea ); + arrowIcons.put( mouseInArrowArea ? ICON_ROLLOVER : ICON_ROLLOVER_LINE, icon ); + } + return icon; + } + + private Icon _getRolloverSelectedIcon() { + IconWithArrow icon = null; + icon = arrowIcons.get( mouseInArrowArea ? ICON_ROLLOVER_SELECTED : ICON_ROLLOVER_SELECTED_LINE ); + if( null == icon ) { + Icon orig = regIcons.get( ICON_ROLLOVER_SELECTED ); + if( null == orig ) + orig = regIcons.get( ICON_ROLLOVER ); + if( null == orig ) + orig = regIcons.get( ICON_NORMAL ); + icon = new IconWithArrow( orig, !mouseInArrowArea ); + arrowIcons.put( mouseInArrowArea ? ICON_ROLLOVER_SELECTED : ICON_ROLLOVER_SELECTED_LINE, icon ); + } + return icon; + } + + JPopupMenu getPopupMenu() { + Object menu = getClientProperty( DropDownButtonFactory.PROP_DROP_DOWN_MENU ); + if( null != menu && menu instanceof JPopupMenu ) { + return (JPopupMenu)menu; + } + return null; + } + + boolean hasPopupMenu() { + return null != getPopupMenu(); + } + + private boolean isInArrowArea( Point p ) { + return p.getLocation().x >= getWidth() - IconWithArrow.getArrowAreaWidth() - getInsets().right; + } + + @Override + public void setIcon(Icon icon) { + assert null != icon; + regIcons.put( ICON_NORMAL, icon ); + IconWithArrow arrow = new IconWithArrow( icon, false ); + arrowIcons.put( ICON_NORMAL, arrow ); + arrowIcons.remove( ICON_ROLLOVER_LINE ); + arrowIcons.remove( ICON_ROLLOVER_SELECTED_LINE ); + arrowIcons.remove( ICON_ROLLOVER ); + arrowIcons.remove( ICON_ROLLOVER_SELECTED ); + super.setIcon( hasPopupMenu() ? arrow : icon ); + } + + private IconWithArrow updateIcons( Icon orig, String iconType ) { + IconWithArrow arrow = null; + if( null == orig ) { + regIcons.remove( iconType ); + arrowIcons.remove( iconType ); + } else { + regIcons.put( iconType, orig ); + arrow = new IconWithArrow( orig, false ); + arrowIcons.put( iconType, arrow ); + } + return arrow; + } + + @Override + public void setPressedIcon(Icon icon) { + IconWithArrow arrow = updateIcons( icon, ICON_PRESSED ); + super.setPressedIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setSelectedIcon(Icon icon) { + IconWithArrow arrow = updateIcons( icon, ICON_SELECTED ); + super.setSelectedIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setRolloverIcon(Icon icon) { + IconWithArrow arrow = updateIcons( icon, ICON_ROLLOVER ); + arrowIcons.remove( ICON_ROLLOVER_LINE ); + arrowIcons.remove( ICON_ROLLOVER_SELECTED_LINE ); + super.setRolloverIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setRolloverSelectedIcon(Icon icon) { + IconWithArrow arrow = updateIcons( icon, ICON_ROLLOVER_SELECTED ); + arrowIcons.remove( ICON_ROLLOVER_SELECTED_LINE ); + super.setRolloverSelectedIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setDisabledIcon(Icon icon) { + //TODO use 'disabled' arrow icon + IconWithArrow arrow = updateIcons( icon, ICON_DISABLED ); + super.setDisabledIcon( hasPopupMenu() ? arrow : icon ); + } + + @Override + public void setDisabledSelectedIcon(Icon icon) { + //TODO use 'disabled' arrow icon + IconWithArrow arrow = updateIcons( icon, ICON_DISABLED_SELECTED ); + super.setDisabledSelectedIcon( hasPopupMenu() ? arrow : icon ); + } + + + private class Model extends DefaultButtonModel { + private boolean _pressed = false; + + public void setPressed(boolean b) { + if( mouseInArrowArea || _pressed ) + return; + super.setPressed( b ); + } + + public void _press() { + if((isPressed()) || !isEnabled()) { + return; + } + + stateMask |= PRESSED + ARMED; + + fireStateChanged(); + _pressed = true; + } + + public void _release() { + _pressed = false; + mouseInArrowArea = false; + setArmed( false ); + setPressed( false ); + setRollover( false ); + setSelected( false ); + } + + @Override + protected void fireStateChanged() { + if( _pressed ) + return; + super.fireStateChanged(); + } + + @Override + public void setArmed(boolean b) { + if( _pressed ) + return; + super.setArmed(b); + } + + @Override + public void setEnabled(boolean b) { + if( _pressed ) + return; + super.setEnabled(b); + } + + @Override + public void setSelected(boolean b) { + if( _pressed ) + return; + super.setSelected(b); + } + + @Override + public void setRollover(boolean b) { + if( _pressed ) + return; + super.setRollover(b); + } + } + } Index: src/org/openide/awt/resources/arrow.png *** D:\projects\nb.m9\openide\awt\src\org\openide\awt\resources\arrow.png No Base Revision --- D:\projects\nb.m9\openide\awt\src\org\openide\awt\resources\arrow.png Locally New *************** *** 1,0 **** --- 1,1 ---- + [Binary File Locally New]