Skip to main content

Is There A BalloonTip Component In Java?

80 replies [Last post]
mijzcx
Offline
Joined: 2004-09-11

Is there a BalloonTip component in java? Swing in particular or maybe in any other libraries?

Thank You.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joshy
Offline
Joined: 2003-07-02

I wouldn't worry about going back to Java 1.4. Java 5 has become our baseline for all new applications. Navigating the differences between 5 and 6 is doable, but Java 1.4 is just missing so much.

leouser
Offline
Joined: 2005-12-12

hmmm, it looks like we may be able to do translucent windows on Windows. Ive been reading about some styles you can set on a particular window to make it see through and also click through. Id like to just make it see through, though maybe someone would want click through as well. From what I gather this capability is from Windows 2000 onward. Ill have to try it out tomorrow. :)

Maybe if Im successful the name can be changed to ComponentTransmorgifier. That doesn't sound very good does it?

BH

Anthony Petrov

Hi,

That's right. Windows (as well as X) allows you to make translucent
windows... but toplevels only :( You're not able to make a child window
a translucent one. This, IMO, is a terrible limitation in Windows/X API.

Look at SetLayeredWindowAttributes/UpdateLayeredWindow Win API functions
for more information.

--
best regards,
Anthony

leouser
Offline
Joined: 2005-12-12

yes,

that sounds right. Im going to look at the Windows calls next. X it appears supports "pseudo transparency", which apparently means that when you make a new X Window you can set its background image to be what is rendered on the root X Window. That's ok but Id rather have a layered effect. I believe to get the layered effect the Composite extension must be used. Im going to have to get my X installation updated to include this and try to build transparency with that. It isn't just the Composite that needs to be there but also the Damage and the Render extensions, I believe. From what I gather you can do this in an isolated program or as part of a bunch of programs that are working with a composite manager.

BH

Anthony Petrov

That's right,

you may take a look at xcompmgr source to get an idea on setting
transparency level for the whole window. After that, take a look at this
thread: http://people.freedesktop.org/~pasc/xorg/msg04644.html
It seems very interesting, though I wasn't able to get it work... Will you?

--
best regards,
Anthony

leouser
Offline
Joined: 2005-12-12

Hmm, Ive kind of got this working on Windows. Though the monkey wrench so far appears that it does not play nicely with Swing so far. I keep on getting these images painted permanently to my screen, which is not what we want at all. It does seem to work okay-dokey with the natives though.

BH

oleg_sukhodolsky
Offline
Joined: 2006-02-06

I think you need to disable direct draw to have better results.

leouser
Offline
Joined: 2005-12-12

yes, that appears to change things quite dramatically. It even appears to work with shaping in play.

I haven't tried the UpdateLayeredWindow function yet, so Im not sure how that would alter things. It would be nice to be able to do this without having to turn things off.

BH

leouser
Offline
Joined: 2005-12-12

using the opengl pipeline with SetLayeredWindowAttributes does not work very well at all. Its not as bad as having direct draw enabled which leaves artifacts all over the screen. But it is bad enough that you get a nice black rectangle where the swing widget is supposed to be.

From looking at UpdateLayeredWindow it appears as though its supposed to be the function by which things are drawn. Im not sure how to stick this into the Java process. I guess it'd need to repaint itself when a WM_PAINT event occurs and also when Swing repaints itself. Another factor is how could we get the painting to be directed to the image that functions as the window? Maybe Im misunderstanding the function...

BH

joshy
Offline
Joined: 2003-07-02

Every time I've talked to the Java2D and AWT guys about shaped Windows they said it would probably hinder graphics acceleration. I suspect that if you want to run with shaped windows on an OS that doesn't have a full compositing window manager (ie: OSX, Vista, or X + extensions), then you'll have to drop accelleration.

leouser
Offline
Joined: 2005-12-12

shaping appears to work ok with the opengl pipeline, as far as I can tell.

I was thinking that translucency could be supplied on Windows if this simple forumla was met:
1. no direct draw on
2. no opengl pipeline on
3. If the windows API supports the layered windows api

#3 we can detect by doing some DLL loading. Im not sure about #1 or #2. We can pass #1 if the noddraw flag is set. #2 we could just check to see if the opengl flag is set to true. Im not certain but wasn't the opengl pipeline supposed to be turned on by default for Java 6?

Im not sure how to strategise this on X. First there needs to be proof the AWT is going to work with the Composite extension. If so we can just check to see if the Composite extension and its various other extensions are supported. If not, then what? Do we just veto it or do we try to fall back on "pseudo transparency" with the background being set to the root window? Would anyone even want that?

It sounds like the Mac peers have a method called setAlpha which turns on the transparency. So with fingures crossed, there may be no need to do any native diddling.

BH

leouser
Offline
Joined: 2005-12-12

I think just looking for opengl being turned on will do, from Chris Campbell's blog:
'Everytime I write about the OGL pipeline, the first question that is asked (without fail) is "Will the OGL pipeline be enabled by default?"... Well, the answer is still "no". It will never be enabled by default on the Windows platform (the DirectX-based pipelines are a better bet on Windows). However, I certainly hope that someday (Mustang? Dolphin?) the OGL pipeline will be enabled by default on Solaris and Linux, but only if we detect a "compatible" system, meaning hardware accelerated drivers are installed, bug-free, and performant.'

I don't think we need to worry about windows API calls being made on *Nixes.

BH

leouser
Offline
Joined: 2005-12-12

heh, apparently another factor against UpdateLayeredWindow is that you can't have child controls. They aren't painted and it looks like they don't respond to the mouse. That doesn't sound good.

BH

Anthony Petrov

Actually you can :) Look at the WM_PRINT Windows message or something
similar. You may order your window to draw itself (including all its
children) into specified DC. The DC may be a bitmap DC that you'd use
with UpdateLayeredWindow. :)
The main problem with this function is that you have to decide when to
update your window... Do you have an answer? :)

--
best regards,
Anthony

joshy
Offline
Joined: 2003-07-02

I think it could be done by hooking in a custom RepaintManager. That would let you know when the app window wants to be redrawn. It shouldn't be too hard to plug in a custom one which just makes a note of the request and delgates to the previous one.

Anthony Petrov

Well joshy,

The main question is the performance though. We certainly can invoke the
UpdateLayeredWindow for each changed pixel but is it worth doing so?
Remember, the function updates the WHOLE window, not just some specified
area. :(

--
best regards,
Anthony

leouser
Offline
Joined: 2005-12-12

That sounds like a de-optimisation, yikes. Though on the other hand, wouldn't regular Windows apps suffer from this same performance drop?

Interesting, so you can get your children painted with the "update" method. I ran into more than one person complaining about their buttons and such not showing up and the answer was: "doesn't work".

BH

leouser
Offline
Joined: 2005-12-12

yikes, I can see why people say "Translucency support not quite there on Solaris/Linux". Ive finally got a Xcomposite lib built and was testing out redirecting a Java window and it crashed the XServer. :( Not sure why yet, but it does.

BH

Anthony Petrov

Hi Brian,

It's not the only reason. If/when you get it work, you'd see a numerous
artifacts all over your screen. So, it's just not usable yet...
unfortunately.

--
best regards,
Anthony

Joshua Marinacci

I don't know but I'll find out.
- Josh

On Oct 9, 2006, at 11:42 AM, swing@javadesktop.org wrote:

> Do you know if Mac ships with the source of its Peer
> implementations? Im trying to guess how hard it will be for
> someone to develop this on the Mac side.
>
> BH
> [Message sent by forum member 'leouser' (leouser)]
>
> http://forums.java.net/jive/thread.jspa?messageID=161271

- Blasting forth in three part harmony!

[att1.html]

leouser
Offline
Joined: 2005-12-12

aha, it appears Ive ran into a monkey wrench. The X implementation uses the sun.misc.Unsafe class, but if we try to load it without the Shaping class on the bootclasspath, we get a SecurityException. I may have to replicate the functionality or find an instance of Unsafe in the X classes and use that.

Loading of the class may work this way:
1. User calls a static factory method to acquire the "ComponentShaper" instance.
2. The factory returns the Singleton instance or it loads it and then returns it.
3. Loading happens by loading the library identified by the environment variable COMPONENT_SHAPER, maybe it should be SHAPER_PATH. Then the factory method queries a static native method that is also implemented by the library. This returns the java class name that is associated with the libarary. This in turn results in the implementation being created.

BH

leouser
Offline
Joined: 2005-12-12

allright, it appears we don't have to rely upon the Unsafe class after all. I switched the byte sticking code over to a direct ByteBuffer and everything appears ok again. :)
Thankfully JNI has some functions to deal with direct ByteBuffers.

BH

leouser
Offline
Joined: 2005-12-12

Ive got the initial unification of the various implementations posted here:
https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?...

The X implementation no longer needs jlong.h, so the user should be able to compile without digging around in the Java source looking for the various headers.

The class is called ComponentShaper for now and until a better name becomes apparent. The package is org.component.shaper until there is some decision if it should be a JDIC project or something else entirely.

BH

leouser
Offline
Joined: 2005-12-12

cool, at least on the X side, and I suspect on the Windows side as well, you can change the shape over time. So if you had an application that wanted to do animations with the toplevel's shape it should be possible. I don't know what application that would be, I think Ive seen media players that allow the user to morph the shape of application but that isn't what Id call animation. Maybe this would help people develop toy programs like a dancing mouse moving around the users screen?

BH

Joshua Marinacci

I'm sure we can think of some cool things to do with morphing windows.

What about a rotating cube window. Or a OSX Dashboard like overlay
window that zooms in. Or windows that have a StarTrek The Next
Generation stretch into warp drive effect when they are closed?
Trust me, we'll find something to do with it. :)

- J

On Oct 11, 2006, at 9:18 AM, swing@javadesktop.org wrote:

> cool, at least on the X side, and I suspect on the Windows side as
> well, you can change the shape over time. So if you had an
> application that wanted to do animations with the toplevel's shape
> it should be possible. I don't know what application that would
> be, I think Ive seen media players that allow the user to morph the
> shape of application but that isn't what Id call animation. Maybe
> this would help people develop toy programs like a dancing mouse
> moving around the users screen?
>
> BH
> [Message sent by forum member 'leouser' (leouser)]
>
> http://forums.java.net/jive/thread.jspa?messageID=162019

- Blasting forth in three part harmony!

[att1.html]

Joshua Marinacci

I just got a message back from Scott at Apple on the OSX stuff:

On Oct 9, 2006, at 4:25 PM, Joshua Marinacci wrote:
Hi Scott. A developer working on the open JDK (leouser, the guy who
fixed all the bugs and came on stage at last May's JavaOne) has
started working on shaped / translucent windows for Frame. He has a
version working for Windows and X using JNI hooks. He would like to
know if the source to Apple's AWT peers is available anywhere so he
could do the same thing on Mac.

Check out this example code:

http://developer.apple.com/samplecode/RoundTransparentWindow/index.html

I believe what you're basically doing is creating a clear window that
has a view in the shape you want.

Scott

On Oct 11, 2006, at 9:35 AM, Joshua Marinacci wrote:

> I'm sure we can think of some cool things to do with morphing windows.
>
> What about a rotating cube window. Or a OSX Dashboard like overlay
> window that zooms in. Or windows that have a StarTrek The Next
> Generation stretch into warp drive effect when they are closed?
> Trust me, we'll find something to do with it. :)
>
> - J
>
> On Oct 11, 2006, at 9:18 AM, swing@javadesktop.org wrote:
>
>> cool, at least on the X side, and I suspect on the Windows side as
>> well, you can change the shape over time. So if you had an
>> application that wanted to do animations with the toplevel's shape
>> it should be possible. I don't know what application that would
>> be, I think Ive seen media players that allow the user to morph
>> the shape of application but that isn't what Id call animation.
>> Maybe this would help people develop toy programs like a dancing
>> mouse moving around the users screen?
>>
>> BH
>> [Message sent by forum member 'leouser' (leouser)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=162019
>
> - Blasting forth in three part harmony!
>
>

- Blasting forth in three part harmony!

[att1.html]

[Edited by: invalidname]

leouser
Offline
Joined: 2005-12-12

Ive got a couple of new API methods in place:
1. clearComponentsShaping that allows you to turn off shaping of a Component.

2. isShaped, which returns true if the Component is shaped. Im not sure if it should just do this or return an enum:
None
Shape
Image

Im also thinking of adding a method that returns the current Object that shaped the Component. Maybe:
Object getShaper(Component c);

I guess this one hinges on how useful it would be to the developer to be able to query for the shape. It gets rid of the need to track what was the shaper on the devlopers side and it probably won't be that hard to put together.

BH

leouser
Offline
Joined: 2005-12-12

Well, it looks like we can use this in Java 5 but it requires some modifications. The problem appears to be that the SunToolkit does not have a public awtLock/awtUnlock set of methods, they appear to be private in some way. Without these methods things do not work. We can overcome this with reflection but that in turn will make the code a little harder to use. The user may have put a SecurityManager in place that will guard against the access violations that reflection is doing. Im going to see if I can get this to run against the Motif peers next. If that's successful we may be able to go back to Java 4, but that would be a very lucky circumstance.

BH

leouser
Offline
Joined: 2005-12-12

I believe we have the Motif toolkit peers working now. So the user will be able to shape their windows regardless of whether or not X or Motif is used. Im able to take this back to Java 5. Ive tried working with this on a Java 4 but their is some problem loading the native code, don't know what.

BH

leouser
Offline
Joined: 2005-12-12

Hmm, I guess we may not have to resort to reflection after all. It appears that in JNI you can access private or package private methods. Not sure if its a good thing that you can do this but you can.

BH

leouser
Offline
Joined: 2005-12-12

applying this original question to the ComponentShaper, Ive been able to create a primitive Balloon with a JToolTip. I just watched in the JToolTip for the addNotify to be invoked and I shaped the toplevel. With my feeble balloon image I drew it gave an Ok(well...) balloon shape for the tip.

BH

leouser
Offline
Joined: 2005-12-12

'For Windows, I think the method to call would be
SetWindowRegion which requires a pointer to the Window in question. This may be a long in WObjectPeer which has the descriptive comment of:
// The Windows handle for the native widget.

thankfully there looks like there is a public method to get this information.

BH '

Almost but not quite, WWindowPeer holds a pointer, WObjectPeer we can't reference because it is package private. SetWindowRgn appears to be the method. After trying to mess around with MFC stuff(and realising that this stuff doesn't come with the Express version of C++) I focused on using GDI instead. At this point Im able to create a elliptical window or JFrame on Windows. There is definately a difference between how Frames are handled on X as opposed to Windows. On X, I think the frame decorations surround the shaped window. So you have a toolbar. On Windows it appears that the decorations are shaped as well, meaning that the top bar is visible but missing pieces of itself.

Im not sure if the Windows api supports shaping via images at this level, Ill have to do some research into it. If not, we will have to see if we can extract geometry from images.

BH

leouser
Offline
Joined: 2005-12-12

Things are going Ok on the Windows side. The code almost seems there... it should be able to support images and shapes. The big problem now seems to be that the shapes are inverted. This is ok for circles and rectangles but not good with Path2D instances.

It also looks like holes in the shape will be accepted. I just did a test where I had an image of the outline of a rectangle used as the shaping data and it gave me the outline of a rectangle as the window.

BH

leouser
Offline
Joined: 2005-12-12

allright, I guess I fixed the problem 2 seconds after I wrote the last post. :) My Path2D test appears to be working fine now. I guess the next step will be to create an API that is the same as the X side of things. After that, the focus should be on:
1. Having one API, the implementation will be hidden behind the scenes.

It will be interesting to see how well things are supported on X. I believe the Shape API has been in existence since 1988, so it has been a long time for X implementations to implement it.

BH

Joshua Marinacci

That sounds great. I've been thinking that the API should support
two fallbacks as well.

On the Mac we can get a shaped window by setting the bg color of the
frame to 0,0,0,0. Then you can draw whatever you want. It doesn't
work perfectly all the time and sometimes has issues with shadows,
but it's a good fallback until we get the JNI version on Mac working.

We could also have a general fallback for cases where the other
versions fail, say because you are using the wrong version of java or
the libs can't be found or the platform isn't supported. In this case
we could do the screenshot hack to fake a shaped window.

This would let developers ship on all platforms with a reasonable
default when things go wrong.

This is shaping up to be a great project. I can't wait to try it out.
Thanks,
Josh

On Oct 9, 2006, at 11:15 AM, swing@javadesktop.org wrote:

> allright, I guess I fixed the problem 2 seconds after I wrote the
> last post. :) My Path2D test appears to be working fine now. I
> guess the next step will be to create an API that is the same as
> the X side of things. After that, the focus should be on:
> 1. Having one API, the implementation will be hidden behind the
> scenes.
>
> It will be interesting to see how well things are supported on X.
> I believe the Shape API has been in existence since 1988, so it has
> been a long time for X implementations to implement it.
>
> BH
> [Message sent by forum member 'leouser' (leouser)]
>
> http://forums.java.net/jive/thread.jspa?messageID=161255

- Blasting forth in three part harmony!

[att1.html]

leouser
Offline
Joined: 2005-12-12

Do you know if Mac ships with the source of its Peer implementations? Im trying to guess how hard it will be for someone to develop this on the Mac side.

BH

leouser
Offline
Joined: 2005-12-12

Ive put up the Windows src here:
https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?...

Its essentially the same API as the X API, they just don't have a common interface between them.

Further testing has shown that the Windows shaping api supports shaping Buttons and such as well. So we appear to be able to do the same things on X as on Windows, which is good. :)

BH

Richard Bair

Cool!

What was the decision about doing this in JDIC or something like that
--- is it possible? Or does it require changes in core?

Richard

On Oct 6, 2006, at 7:11 AM, swing@javadesktop.org wrote:

> It appears that the Shape based shaping of Windows is now working:
> https://www.dev.java.net/files/forums/2899/1463/1442/shapeGPWindow.png
>
> This one was produced by using a Path2D.Float instance.
>
> BH
> [Message sent by forum member 'leouser' (leouser)]
>
> http://forums.java.net/jive/thread.jspa?messageID=160627

leouser
Offline
Joined: 2005-12-12

'Cool!

What was the decision about doing this in JDIC or something like that
--- is it possible? Or does it require changes in core?

Richard

On Oct 6, 2006, at 7:11 AM, swing@javadesktop.org wrote:

> It appears that the Shape based shaping of Windows is now working:
> https://www.dev.java.net/files/forums/2899/1463/1442/shapeGPWindow.png
>
> This one was produced by using a Path2D.Float instance.
>
> BH
> [Message sent by forum member 'leouser' (leouser)]
>
> http://forums.java.net/jive/thread.jspa?messageID=160627'

I must have missed this post! Yes, we are at a stage where I believe on the X side we can dispense with having to meddle with what already exists. I can't vouch for Windows or Mac or whatever but it appears that the machinery just works on X. :)

for the Shape API, the method looks something like this:
public static void shapeComponent(Component c, Shape s, int x, int y);

where c, is the Component
s is the Shape
x and y are the coordinates within the Bounds of the Component where it should be placed. Just imagine a BufferedImage with the same dimensions as the Component and a graphics call fill(s), where the origin has been translated to x and y. The resulting fill gives you the shape.

BH

leouser
Offline
Joined: 2005-12-12

For Windows, I think the method to call would be
SetWindowRegion which requires a pointer to the Window in question. This may be a long in WObjectPeer which has the descriptive comment of:
// The Windows handle for the native widget.

thankfully there looks like there is a public method to get this information.

BH

Richard Bair

Coool. Next question: when can I run this code on my desktop :-)
(without going through the jdk project process).

Richard

On Oct 6, 2006, at 10:41 AM, swing@javadesktop.org wrote:

> For Windows, I think the method to call would be
> SetWindowRegion which requires a pointer to the Window in
> question. This may be a long in WObjectPeer which has the
> descriptive comment of:
> // The Windows handle for the native widget.
>
> thankfully there looks like there is a public method to get this
> information.
>
> BH
> [Message sent by forum member 'leouser' (leouser)]
>
> http://forums.java.net/jive/thread.jspa?messageID=160765

leouser
Offline
Joined: 2005-12-12

Well, I can toss it up on the same collab forum thread that Im using for screenshots. How does that sound? You do have access to a *Nix don't you? It actually isn't that much code so far.

Im going to see how far I get with the Windows side of things next. Im getting Cygwin set up and it sounds like you can make JNI stuff and run it without having to refer to Cygwin.

BH

leouser
Offline
Joined: 2005-12-12

Ive tossed the src up here:
https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?...

Ive been using C++ but it should be simple to just use C for this. Also, Ive been using a function I believe is internal to the JVM and not part of the jni interface: jlong_to_ptr.

BH

Joshua Marinacci

swing@javadesktop.org wrote:
>>* Obviously, don't overlap a lightweight component on a heavyweight component
>
>
> It would be nice if it would be acceptable :( This means no menus, not internal frames, no glasspanes.

Why would it mean no menus, internal frames, or glasspanes? Aren't
glasspanes and internal frames lightweight components. The menus will
probably be heavyweight which means they will be in their own top level
windows and thus be outside the shaped window, which seems like the
right behavior.

- Josh

>
> As for my previous post I meant that it would be very hard
> (most likely impossible) to implement real mixing in case of
> translucent lightweigh (if you allow them to overlap heavyweights)
> [Message sent by forum member 'oleg_sukhodolsky' (oleg_sukhodolsky)]
>
> http://forums.java.net/jive/thread.jspa?messageID=160405

oleg_sukhodolsky
Offline
Joined: 2006-02-06

Hi Josh,

I meant that we will have problems with mixing heavyweights and translucent lightweight components.

Thanks, Oleg.

oleg_sukhodolsky
Offline
Joined: 2006-02-06

> * Obviously, don't overlap a lightweight component on a heavyweight component

It would be nice if it would be acceptable :( This means no menus, not internal frames, no glasspanes.

As for my previous post I meant that it would be very hard
(most likely impossible) to implement real mixing in case of
translucent lightweigh (if you allow them to overlap heavyweights)

leouser
Offline
Joined: 2005-12-12

Ive made some progress beyond the triangle madness problem and have successfully created a JWindow/JButton that looks like a snowman.

https://www.dev.java.net/files/forums/2899/1463/1439/jbuttonSnowman.png

maybe Ill do a cat tomorrow. :)
BH

Anthony Petrov

On 10/05/2006 09:16 PM Joshua Marinacci wrote:
> Quite true, but I can't do that now either (at least not without a
> commercial 3rd party library). I think it's a fair tradeoff for now.
> Most apps which would like to use shaped windows don't need heavyweight
> components.
I'm not sure you are quite correct here. The "most apps which would like
to use shaped windows" are media players, aren't they? I could think of
a shaped Java media player using an Active X control embedded, and this
ActiveX control would actually show a movie or play some music, etc. :)

Anyway, shaped *toplevels* do NOT actually bring any problems with
neither translucency nor mixing. So I don't catch your point here.

--
best regards,
Anthony

leouser
Offline
Joined: 2005-12-12

don't forget exciting applications like xeyes and xclock. With shaped windows we will be able to do these highly useful applications in Java.

BH

leouser
Offline
Joined: 2005-12-12

It appears that the Shape based shaping of Windows is now working:
https://www.dev.java.net/files/forums/2899/1463/1442/shapeGPWindow.png

This one was produced by using a Path2D.Float instance.

BH