Skip to main content

Important update: back to AWTEventListener

5 replies [Last post]
alexfromsun
Offline
Joined: 2005-09-05
Points: 0

Yes, yes, JXLayer doesn't use the nice InputContext trick any more
and returned to the old good AWTEventListener

Note:
With the latest update I restored the proxy InputContext,
JXLayer supports both modes now

InputContext was a good try to transparently listen AWTEvents for unrestricted environments, like unsigned applets
unfortunately it failed because Piet Block discovered that InputContext is disabled for read-only textComponents

A LayerUI gets inputEvents from the InputContext by default, to enable the AWTEventListener you should use a special method:

<br />
AbstractLayerUI.registerAWTEventListener(JXLayer l,  long eventMask)<br />

call from the installUI() to catch events for the layer and its hierarchy

<br />
      public void installUI(JComponent c) {<br />
           super.installUI(c);<br />
           // listens for keyboard and focus events<br />
           registerAWTEventListener((JXLayer)c,<br />
                 AWTEvent.KEY_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK)<br />
      }<br />

don't forget to call unregisterAWTEventListener() from the uninstallUI(), please see the javadoc for more information

AWTEventListener doesn't work for unsigned applets,
registerEventListener() method requires permission to add the AWTEventListener

Thanks
alexp

Message was edited by: alexfromsun

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pietblok
Offline
Joined: 2003-07-17
Points: 0

Hi Alex,

Yes, mouse drawing does work fine now on non editable text components.

But, as you pointed out, it is now mandatory to register the required event mask, for the mouse drawing LayerUI they are the AWTEvent.MOUSE_EVENT_MASK and AWTEvent.MOUSE_MOTION_EVENT_MASK.

Users that implemented LayerUI's will find that, if they do not override the installUI method as you described, their LayerUI's will not work anymore with the new version.

Meanwhile, I am exploring another aspect of LayerUI's. Somewhere in the documentation it is mentioned that one LayerUI instance may apply to multiple JXLayer instances. I was curious what would happen if one actually did that.

For one, state information collected and maintained in the LayerUI itself, would apply to all JXLayers. So I implemented a LayerUI that stores this state information in a special StateObject that is put as a client property in the affected JXLayer. Now it is possible to create one mouse drawing LayerUI, apply it to two JXLayers, and have different drawings for each JXLayer.

This seems to work ok with one exception: the repainting system (setDirty etc.) seems, under certain conditions (not sure yet what these exactly are), only to work on the first JXLayer.

Now, one wonders why anyone would want to apply one LayerUI to multiple JXLayers. But nevertheless, I thought it worthwhile to explore.

As soon as I have a small working example I will let you know so that you can give your opinion.

Thanks

Piet

alexfromsun
Offline
Joined: 2005-09-05
Points: 0

Hello Piet

> Users that implemented LayerUI's will find that, if they do not override the installUI method as
> you described, their LayerUI's will not work anymore with the new version.

That's right, and I need to write a new blog to describe it
I don't want to register all events by default, because it won't work in unsigned applets,
I'll have to sign MouseScrollableDemo jar to make it run
(not it throws SecurityException when you run it via webstart)

>Meanwhile, I am exploring another aspect of LayerUI's. Somewhere in the documentation it
>is mentioned that one LayerUI instance may apply to multiple JXLayer instances. I was
>curious what would happen if one actually did that.

If LayerUI is not instance of AbstractBufferedLayerUI, it can be shared between multiple layers,
e.g. you can create a single MouseScrollableUI instance and share it

Thanks for your support
alexp

Message was edited by: alexfromsun

pietblok
Offline
Joined: 2003-07-17
Points: 0

Hi Alex

> If LayerUI is not instance of AbstractLayerUI, it can
> be shared between multiple layers,
> e.g. you can create a single MouseScrollableUI
> instance and share it

I am a little confused by what you are saying. I checked you sources for a better understanding, but found that your MouseScrollableUI extends AbstractLayerUI, not LayerUI.

In fact, the only class extending LayerUI directly is AbstractLayerUI.

I wondered previously why LayerUI and AbstractLayerUI are not combined into one class?

What additional functionality has AbstractLayerUI that prevents it from being used as the base class for a shared LayerUI?

Just asking for a better understanding.

Thanks

Piet

alexfromsun
Offline
Joined: 2005-09-05
Points: 0

Hello Piet

There was a typo in my previous message,

(corrected)

I meant not AbstractLayerUI, but AbstractBufferedLayerUI

Thanks

alexp

pietblok
Offline
Joined: 2003-07-17
Points: 0

Ah, that explains it,

Thanks
Piet