show tooltip using layout coordinates - java

Basically I want to show a javafx.scene.control.Tooltip using screen coordinates.
In a Scene I have a couple of Node instances that each have their own Tooltip instance. A certain event should trigger all nodes to show their tooltips at the same time. (It's a kind of help feature)
But the show methods use screen coordinates. So when I use tooltip.show(node, node.getLayoutX(), node.getLayoutY()) unfortunately all tooltips are off a couple of inches.
Using mouse events, I would have used the mouseEvent.getScreenX() and mouseEvent.getScreenY() methods to show the tooltip. But unfortunately, I'm not using the mouse to trigger this event, this time.
A Node doesn't have getScreenX methods. So, is there a way to convert the layout coordinates to screen coordinates ?
If there is an alternative approach, feel free to share as well.

There is no way to convert directly from layout coordinates to screen coordinates. But there is a method localToScreen which can be used to convert the local coordinates to screen coordinates.
Bounds bounds = node.localToScreen(getBoundsInLocal());
tooltip.show(this, bounds.getMinX(), bounds.getMinY());

Related

Java - Screen Coordinates to Image Coordinates

I am using a Java application to display an image on the screen. I also am using an eye-tracker device which records the absolute pixel X,Y locations where the person is looking on the screen.
However, what I need to do is convert these X,Y coordinates from the screen positions into the X,Y locations of the image. In other words, somehow I need to figure out that (just an example) 482, 458 translates to pixel 1,1 (the upper left pixel) of the image.
How can I determine the image's placement on the screen (not relative to anything)?
I saw a few posts about "getComponentLocation" and some other APIs, but in my experimentation with these, they seem to be giving coordinates relative to the window. I have also had problems with that because the 1,1 coordinate that they give is within the window, and there is actually a bar at the top of the window (that has the title and the close and minimize buttons) whose width I do not know, so I cannot easily translate.
Surely there must be a way to get the absolute pixel location on the screen of a component?
If we are talking about Swing/AWT application than class java.awt.Component has method getLocationOnScreen which seemed to do what you want
And yes as #RealSkeptic mentioned in comments to question:
SwingUtilities.html#convertPointFromScreen
will do all this work for you considering components hierarchy

Java JFreeChart: customize tooltip screen position

I implemented my own JFreeChart XYToolTipGenerator and, as the chart it is used on is almost full screen, sometimes the tooltip position (on screen) hides the point it is related to (e.g. in the bottom right corner, since it seems that tooltip is configured to be positioned South-East of the mouse / data point). This is a problem because the user needs to be able to click on the chart's data points (as it generates a specific action).
Is there a way to either define dynamically the position of the tooltip (e.g. for data points bottom right I would ask the tooltip to be shown North-West) or, alternatively, to define a systematic position (e.g. North-West instead of South-East as it is by default)?
This problem has given me headaches for the last few days - any help or hint is more than welcome.
Many thanks!
Thomas
Here's the answer I posted on the JFreeChart forum:
JFreeChart is using the standard Swing tool tip mechanism. In the ChartPanel class, the getToolTipText(mouseEvent) method is overridden to return the appropriate text for the tooltip, and that's it.
Swing also gives you the option to override the getToolTipLocation(mouseEvent) method, and that's probably what you need here.

Libgdx display text/score as actor on stage

I would like to display multiple texts/scores on my stage. This tutorial suggested SpriteBatch, however, the issue is that these texts won’t fade out (not actor). Certain posts suggested use table, but the issue is that I can’t set texts' position on stage. Is there any other way to display texts as an actor on stage without using table?
Thanks in advance.
Zi
You can create a subclass of actor and draw text as you like in it's overridden draw method.
Just don't forget to set alpha before drawing using setColor method. The value of alpha will be available as a parameter for draw.
You then can fade it the way you want.
Good luck.

Rotate and Perspective on Swing GUI Component (JList/JTable)

I am trying to build a Media Player. I have all the code for music playback. And the GUI is made up of 3 main parts:-
A blue background.
A JList with JScrollPane
A JLayer Shell (with a polygon cut out to reveal the list and blue background beneath it.)
So my question is how can I create a custom list or JTable that is slightly rotated with the base of the component stretched out on both corners (using a perspective filter). Also the JScrollbar attached must be customized also. I guess at least it needs to be rotated. But would like to know how to make one by supplying my own graphics. Is this possible?
Here is a MOCKUP of the design:
http://www.splashportal.net/MOCKUP/iJuk-MOCKUP.swf
Here is a Screenshot of it:
You can transform a view component, as shown here, but mouse interaction is effectively impossible without re-writing the UI delegate. Alternatively, you may be able to adapt the approach shown here that uses an inverse transform to effect mouse control.

Dynamically changing the tooltip of a draw2d figure

We are currently using Eclipse Draw2D/GEF for an information page describing a process in our application. This basically consists of a matrix of large squares, each containing a matrix of smaller squares. We originally had all the squares as GEF objects, but because of the large volume of them being shown, we found that this did not scale very well and the view took a very long time to open. We then changed it so that only the large squares are Figures and we then draw the smaller squares using the graphic in paintFigure.
The problem that we are running into is that we still want the tooltip to change depending on which small square you are hovering over. I tried to do this by adding a mouseMotionListener and setting the tooltip, through setTooltip, depending on where the mouse currently is. The problem is that once the tooltip is displayed, it does not change any more when setTooltip is called.
Does any one know of an alternative way of doing this? Is there a way of getting the viewpart's PopupHelper and using that? Any help would be appreciated.
Thanks
Hmnn.. interesting problem. Since you paint your own Grid within the Figure, I would think that you have two options.
Try posting SWT events to fool Eclipse. I'd try a focus lost followed by a focused gained, to trigger tooltip machinery, at which point you could get the coordinates and display the appropriate contents.
Don't use the Figure#getTooltip strategy at all. Just show your own composite.
To dynamically change the tooltip, you can hold an instance of the tooltip Figure in your parent Figure. In the constructor of the parent Figure, create a new tooltip Figure (e.g. a Label) and use setToolTip() method to set the tooltip Figure to parent Figure.
When data model is changed, the updated tooltip text/icon can be set to the tooltip Figure. Then you just call setToolTip(tooltipFigure) method again.
You can have a method like:
protected Label toolTipLabel;
protected void updateToolTip(String text, Image icon){
toolTipLabel.setText(text);
toolTipLabel.setIcon(icon);
setToolTip(toolTipLabel);
}
The updateToolTip() method can be invoked in parent Figure's conturctor to initialize the tooltip. And this method can be invoked each time after the data model is changed.
I encountered the same problem in my code and solved it with that method. In my code, I invoked the updateToolTip() in the parentFigure.paintFigure() method.

Categories

Resources