Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebPopup setCloseOnFocusLoss doesn't work #122

Closed
renato opened this issue May 15, 2014 · 8 comments
Closed

WebPopup setCloseOnFocusLoss doesn't work #122

renato opened this issue May 15, 2014 · 8 comments

Comments

@renato
Copy link

renato commented May 15, 2014

The closeOnFocusLoss property on WebPopup is ignored because the ShadeLayer has its own way to hideAllPopups: the blockClose property, which is inaccessible without manually instantiating a ShadeLayer and doing what PopupManager does.

My nasty workaround for a real modal WebPopup:

Method method = PopupManager.class.getDeclaredMethod("getShadeLayer", JRootPane.class);
method.setAccessible(true);
((ShadeLayer)method.invoke(null, rootPane)).setBlockClose(true);
@mgarin
Copy link
Owner

mgarin commented May 15, 2014

Good point.

I guess I will add three options:

  1. Public access to PopupManager.getShadeLayer () - no idea why I made it private
  2. New webPopup.getPopupLayer () method in WebPopup to retrieve layer it uses
  3. Add blockClose argument into PopupManager.showModalPopup () methods
    I will include those changes into v1.28 update.

And generally - I am trying to do make WebLaF code developer-friendly, so you would be able to access/override/improve as much things as there are available in the library. So if you find any other issues in WebLaF which force your code to be inconvenient - just notify me and I will deal with it :) That also includes any missing methods you might want to see in components and such.

@mgarin
Copy link
Owner

mgarin commented May 15, 2014

By the way - if you like to use Reflection from time to time - ReflectUtils might be really useful for you.
For example the code you used to call hidden method could be converted to this:

final ShadeLayer layer = ReflectUtils.callStaticMethodSafely ( PopupManager.class, "getShadeLayer" );
layer.setBlockClose ( true );

This won't even require any try-catch blocks. And yes, it always makes the method accessible.
But that is just a small note :)

@mgarin mgarin added this to the Enhancements milestone May 15, 2014
@mgarin mgarin self-assigned this May 15, 2014
@renato
Copy link
Author

renato commented May 15, 2014

I need reflection more than I like it, but it's good to be aware of ReflectUtils.

Thank you. :)

@renato
Copy link
Author

renato commented May 15, 2014

One more thing... the callStaticMethodSafely() doesn't work here because the getMethods() on ReflectUtils.java:859 returns only the public methods. The private methods are accessible only with getDeclaredMethods().

@mgarin
Copy link
Owner

mgarin commented May 15, 2014

Nice one, it is actually a bug. If you look further into a similar method callMethod (ReflectUtils.java:1050) - it calls exactly the getDeclaredMethods instead of getMethods. I was fixing it and didn't notice that the static version still have the old method used.

Thanks for noting this one :)

@mgarin
Copy link
Owner

mgarin commented May 15, 2014

Why I have created methods like ReflectUtils.callMethod in the first place is that Class.getMethod(String, Class...) doesn't work the way I want it to.

For example if you have a class with method:

public class MyClass 
{
    public void doSomething ( Object object )
    {
        //
    }
}

And you will try to find it using non-object class type:

myClass.getMethod ( "doSomething", String.class )

You will simply find nothing since you have to provide exact method argument type, supertypes simply won't work. Here is the only way it will work:

myClass.getMethod ( "doSomething", Object.class )

And basically the same applies to constructors.
Well, I guess you might know about this unpleasant thing.

mgarin added a commit that referenced this issue May 18, 2014
#121 - Small fix for FileUtils.getDiskRoots() method
WebDocumentPane custom component added (will be completed in v1.28 release)
DragManager preview added
PopupMenuGenerator preview added
Main README updated with more screenshots
Screenshots moved into a separate directory
mgarin added a commit that referenced this issue May 20, 2014
@mgarin
Copy link
Owner

mgarin commented May 20, 2014

I have committed all of the changes, you can build temporary library version from sources if you want to test it out right away or wait for v1.28 release which will include it.

@mgarin mgarin added the fixed label Jun 26, 2014
@mgarin
Copy link
Owner

mgarin commented Jun 26, 2014

Changes are now available in v1.28 update:
https://github.com/mgarin/weblaf/releases/tag/v1.28

@mgarin mgarin closed this as completed Jun 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants