Benoker / DockingFrames

http://www.docking-frames.org
96 stars 46 forks source link

Dock action icon gets disabled twice / wrong disabled icon #59

Closed ThomasH closed 7 years ago

ThomasH commented 7 years ago

Hi Beni, I've stumbled over a little rendering issue while fine tuning my new theme. I've seen that the disabled icon for dock actions seem to get converted to disabled state twice. When I explicitly set a disabled icon for my action, this icon gets also converted to a default disabled icon.

I think the problem is in DockUtilities.disabledIcon in the second part where you paint the icon on an image and convert it using UIManager.getLookAndFeel().getDisabledIcon(...). In my test case the icon is a ForwardIcon from RoundRectButton and thus is already painted in disabled state.

This seems only be a problem when I add actions of type CButton. If the CButton is added to a CDropDownButton the rendering seems to be ok.

This is how it looks like (first action in example below) -> top: expected, bottom: observed wrong_disabled_icon

Need to zoom in to see the problem as it is rather hard to see.

How to reproduce: Use Eclipse theme (I have not tested any other theme). Add a dock action of type CButton to a dockable with an icon Add a dock action of type CButton to a dockable with an icon and an explicitly set disabled icon (set both actions to disabled!)

Observed: Rendered icon of first action is gray (but almost solid gray as it is converted by getDisabledIcon twice) Rendered icon of second action is gray version of the explicitly set disabled icon and not the real icon

ThomasH commented 7 years ago

If I change the following lines the problem seems to be gone (at least in my test cases). Please check if this has any side effects I'm not aware of:

DockUtilities.disabledIcon( JComponent parent, Icon icon ) From

if( parent != null ){
    int width = icon.getIconWidth();
    int height = icon.getIconHeight();
    if( width > 0 && height > 0 ){
        BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB );
        Graphics g = image.createGraphics();
        icon.paintIcon( parent, g, 0, 0 );
        g.dispose();
        icon = new ImageIcon( image );
--->    result = UIManager.getLookAndFeel().getDisabledIcon( parent, icon );   <----
    }
}

To

if( parent != null ){
    int width = icon.getIconWidth();
    int height = icon.getIconHeight();
    if( width > 0 && height > 0 ){
        BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB );
        Graphics g = image.createGraphics();
        icon.paintIcon( parent, g, 0, 0 );
        g.dispose();
        icon = new ImageIcon( image );
        result = icon; // UIManager.getLookAndFeel().getDisabledIcon( parent, icon );
    }
}
Benoker commented 7 years ago

In your code the icon is just copied? Maybe some other themes will not like this.

I'll play around a bit to reproduce the issue, test your code, maybe find a good solution.

ThomasH commented 7 years ago

If you need a working example, I can probably provide you one. To reproduce you should simply add a CButton to a dockable which is disabled.

I don't know if other themes have the same issue. But the icon.getPaintIcon() delegates at sometime to BasicButtonModel.getPaintIcon(Boolean enabled) which in turn already creates a disabled version (and correct one) of the requested icon. This icon gets converted to disabled again by DockUtilities.disabledIcon() from above. At least those themes which use the MiniButtonContent and BasicButtonModel should have the problem, I think. As MiniButtonContent returns a ForwardIcon which can not be converted to disabled state by UIManager.getDisabledIcon().

My "fix" was only a simple test where the problem comes from. At least for the eclipse theme, my glass theme and my new dark flat theme the fix seems to work pretty well.

Benoker commented 7 years ago

I've uploaded a bugfix. Tested it with all themes, menus and drop-down-menus. Painting of disabled buttons show now work better, and nothing else has changed.

ThomasH commented 7 years ago

Tried my applications with the new version ... works like charm. Thank you