I'm making a toy hearing test application with Java8 (I'm using JavaFX version 8).
In order to assess if the user can hear the sound he has to click on a UI button with the mouse button which corresponds to the side the sound was coming from.
So, in the click event, I need to distinguish between right and left click buttons, but all JFX seems to be giving me is
PRIMARY
Represents primary (button 1, usually the left) mouse button.
SECONDARY
Represents seconday (button 3, usually the right) mouse button.
which is clearly not good enough: stereo channels aren't going to be inverted only because the user is left-handed.
So, is there any way to tell if PRIMARY is the left or right mouse button?
PS: I can obviously solve the problem by explicitly asking the user to right-click and left-click before starting. I'd like to know if it's possible to avoid that.
I've been browsing through the API and Microsoft docs. The primary and secondary mousebuttons have no unique name - as far as I'm aware of. I can't find a method in Java to find out whether the box "invert mousebuttons" is ticked off or not.
Creating a button "Click left to begin" could function as a "start" and primary mousebutton detection. Maybe there are Java libraries out there which provide a more flexibility using primary/secondary mouse buttons.
Related
I have a graphical editor written with GEF. In this editor it's possible to drag and drop elements around and create connection by dragging and dropping on specific anchor points.
Everything works fine, except that the diagram does not automatically scroll when the user drags stuff around.
I would expect the diagram to scroll automatically when the user reaches the side of it while dragging something.
Is such a feature supported by GEF? Which class/setter should be called to enable it?
If it's not directly supported, how to proceed to achieve it?
It's been a while since I last fiddled with GEF.
Does drag and drop not work at all or just in the direction of negative coordinates?
What Layout are you using?
IIRC, there were different layouts with one of them (FreeForm?) supporting negative coordinates, so if you just have trouble with negative coords, you could try to change the Layout.
Here is an example of a Scrolling Graphical editor (the author says ;)) which might give you a good hint.
And there is a class named org.eclipse.gef.ui.parts.ScrollingGraphicalViewer that might help, too.
Only hints, though, since I don't know your code.
First step is to make your canvas scrollable. This is explained in this book, pages 96 - 101.
Assuming you are already drawing your figures on a FigureCanvas and you're using FreeformFigures and FreeformLayer, you can do the following:
Add a MouseMoveListener on your Figure in its EditPart. Each time a drag is detected, in the mouseDragEvent method, reveal your figure with getViewer().reveal(EditPart.this).
This will cause your Figure to always be constantly revealed when it's being dragged.
I'm using a dynamic graphic library to display data. By clicking with the left button on a node, a window pops out displaying info about it. I would like to use the right button instead, which by now is used to move the node around (without the window popping out). The problem is: the graph listeners I'm using only respond to the left button. So the only solution I can think of is to swap the mouse buttons mapping on the java application. Is there a way to achieve this?
I might be wrong, but can you use MouseListeners for right click, and than use java.awt.Robot to left click that? just a thought. good luck.
Whoops, sorry. I already solved this a long time ago and I forgot to post the answer: The library I'm using is graphstream, and I just needed to set the graph DefaultMouseManagerm (with overriden functions) which takes care of mouse clicks on the graph.
I want to press buttons like it shown on this picture http://i.stack.imgur.com/C1NW3.jpg. That is I want to press buttons by holding finger on the screen and moving it along buttons. For example on this pic buttons 1, 2,5,8,9 will be pressed after this procedure.
Sorry for my bad english, but i cant to describe this in a different way.
How I can do this?
Well, sorry for not providing the very simple answer like "use the function xyz()" for this, but I think there are some general ways to do it:
You can create pictures that look like buttons (or bubbles or anything else appropriate), place them in an order that you need and then, getting each coordinate of the pointer (of the finger) on the screen, just check if this pointer gets into some area (maybe rectangle) inside each button. This logical area should be smaller than shown picture to let user move finger not so careful.
Another "solution" would be to put some "jitter" and send "left click" message on each position update along the way. In this case buttons should have some protection from multiple clicks. I remember on stackoverflow.com some advice how to do this: just disable the button on the click event.
Sorry if Android has some solution "out of the box", which I have no idea about, but the described problem seems to be general, not platform-specific.
Wow, what a stupid question you might say. But is it possible? I have a mouse move event in a Jpanel and it works even when the application is not in focus, now can I have something like that for the clicking event or something similar. And most importantly I don't want other apps (even something like the main menu) to lose focus when i click on my app.
I thought of the system's event queue but i'm not sure where that would lead me to.
Thanks in advance.
[EDIT - the purpose]
I want to create an app that mimics the users interactions with the system in a later time. for example a user takes the mouse and clicks and writes and my app will mimic that in say 2 hours time. ofcourse i would need a system hook for the outer events but i wanted to avoid os-dependant code so i basically capture the screen, take it to my app,for example the user clicks on an icon in the captured picture and then for making that come to life, i translate the coordinates to the real icon and click it (with a Robot) and in this way i can capture the user's events in my own app. the problem occurs when the user clicks on the main menu or right clicks (he's doing that in my app, and my app does that to the system so my app is in between) and ofcourse the real main menu will lose focus when the user tries to click on one of it's items.
sorry for my english.
I'm still not sure I follow what you are trying to do. But the concept of an app getting focus when you click on it is fundamental to the GUI and I suspect rather difficult to get around.
I just found this:
Focusable Windows
To support palette windows and input methods, client code can prevent a Window from becoming the focused Window. By transitivity, this prevents the Window or any of its descendants from becoming the focus owner. Non-focusable Windows may still own Windows that are focusable. By default, every Frame and Dialog is focusable. Every Window which is not a Frame or Dialog, but whose nearest owning Frame or Dialog is showing on the screen, and which has at least one Component in its focus traversal cycle, is also focusable by default. To make a Window non-focusable, use Window.setFocusableWindowState(false).
In this doucment http://java.sun.com/j2se/1.5.0/docs/api/java/awt/doc-files/FocusSpec.html
That sounds like it might do what you want.
Using Java is there anyway to display a custom form/image that behaves similar to TrayIcon.displayMessage() function in that it displays just above the system tray for a while then disappears?
I am also looking for a way to display multiple notifications at the same time by having them display above each other.
If not, how do I find the pixel location for the lower left corner just above the system tray?
I don't think there's a shortcut for drawing frames that act just like the standard TrayIcons (with the x button in the corner) that support stacking akin to the Mac Growl notifications.
you will probably have to implement it yourself.
I've found that stacking messages like that is a complete waste of time as the user will not pay attention to them - the better location for these is in the status area of the application in a simple popup menu.
You can use java.awt.GraphicsEnvironment. getLocalGraphicsEnvironment() to get information about the desktop, which contains 'getMaximumWindowBounds()' which takes care of things like the taskbar position.
You can use a subclass of a javax.swing.JWindow to create a window without a border which can be positioned on the desktop relative to the bottom right corner. This will not always work as the default tray icon, as the location of the icon generator can be somewhere else other than that.
You can add a button that acts like the 'x' button of a standard desktop window - but it's going to be platform dependent.
I use square windows that stack up from the top right corner if I'm using LTR, and it seems to work well.
Go check out Java GNOME. It has Java bindings for GTK, including a status icon for the tray, and notification events.