How to consume JavaFX TouchEvent correctly? - user-interface

I have a GUI with several menus.
The current menu is the child of a StackPane which in turn is a child of a RootLayout (GridPane) and there is only one menu active at a time which means that the StackPane has only one child at a time.
The menu switches by replacing all children in the StackPane with the new page.
(theStackpane.getChildren().setAll(newMenu);)
The active menu may have a button that changes the menu, so a click on the button replaces all children in the StackPane (the one with the button you just clicked as well).
The problem is, when there is a button that changes the menu and there is a button at the same location in the new menu, both buttons get clicked, although you just clicked the first button (which changes the menu).
The structure is like this:
RootLayout
.theStackPane
..activeMenu
...oneButton
A click on oneButton (that changes the menu) leads to:
RootLayout
.theStackPane
..newMenu
...twoButton
The StackPane stays the same, just all children of theStackPane get exchanged by new ones.
Now if oneButton is at the same location of twoButton, oneButton gets activated, changes the menu by replacing all children, newMenu is shown, twoButton gets activated and does whatever it does - stop.
Although I'd like to have it like this:
If oneButton is at the same location of twoButton, oneButton gets activated, changes the menu by replacing all children, newMenu is shown - stop.
How do I prevent the current behaviour?

buttonOne & buttonOnNewPage are inside the same stackPane, right? Then that happens because in the event capturing phase the stackPane propagates the event to both buttons so when the handler tries to consume it, it has already been propagated.
So, instead of using a handler in buttonOne lets try using a filter, and inside it consuming the event. Try something like this:
EventHandler filter = new EventHandler(<TouchEvent>() {
public void handle(TouchEvent event) {
theStackPane.getChildren().setAll(newPage);
event.consume();
}
}
buttonOne.addEventFilter(TouchEvent.TOUCH_PRESSED, filter);

I finally got to a solution:
I got it to work as expected when I switched setOnTouchPressed to setOnAction.
I don't event need to consume the ActionEvent when I touch oneButton.
So instead of
oneButton.setOnTouchPressed(e -> {
theStackPane.setAll(newPage);
});
I am now using
oneButton.setOnAction(e -> {
theStackPane.setAll(newPage);
});

Related

how to make a macOS app have two main menu

I know some mac application has two main menu.
main menu means top left menu in macOS screen.
When a windowA show, the main menuA show.
As I click some window (name it windowB) in the application
and another menuB is replaced menuA.
And as I click windowA, the main menuA reappear.
Does someone know how to implement this behavior?
You have to associate a menu to each window. For this, you can copy the MainMenu of the Application and paste it into the appropriate Window Controller Scene. Then select the connections of the window in the scene and link the item "menu" to the new menu of the scene. Repeat this for all your window controllers/windows.
Then you need to add some code. Create a new Window class:
class Window : NSWindow {
override func becomeKey() {
NSLog("become2")
NSApplication.shared().mainMenu = self.menu
super.becomeKey()
}
}
and then set the class property of each window to this Window class.
You can then edit menus accordingly to your needs. Be aware that you need to reconnect each menu item to the appropriate first responder action...
I'm not sure it is the best solution, but it works well for me. In fact I don't really understand why I need to subclass NSWindow this way...

Unity UI Button has insane transition state behaviour - it remains highlighted after being clicked

It took me a while to figure out the problem with Unity UI Button Transition:
Problem:
I hover on the button object, it goes to highlighted state, that's Fine. If I press mouse on button and it goes to pressed state then I move mouse outside of button so its no longer over button. The button goes to highlighted state instead of normal state. I need to click in empty space to get the normal state of button.
TLDR:
To retain keyboard automatic navigation, you probably want to inherit from IPointerExitHandler and deselect on exit:
public void OnPointerExit(PointerEventData data)
{
EventSystem.current.SetSelectedGameObject(null);
}
You could add checks to only deselect gameObject if already selected.
This is the default behaviour for a Button element in Unity - it retains focus after the initial interaction, causing it to show the Highlighted Color. Clicking away clears the focus, so it no longer becomes highlighted then.
To change this behaviour, you can switch the Navigation setting.
Currently, it's set to Automatic. According to the documentation, the option you want to use instead is None, which results in:
No keyboard navigation. Also ensures that it does not receive focus from clicking/tapping on it.
Hope this helps! Let me know if you have any questions.
If you want to use keyboard navigation and also get rid of this problem you can add this function to update:
void Update()
{
if (Input.GetMouseButtonUp(0))
{
EventSystem.current.SetSelectedGameObject(null);
}
}

Kendo UI Toolbar and Grid - strange save behavior when triggered from Toolbar control

I have some pages where I have a kendo ui grid (wired up to full CRUD services), but use a separate Kendo UI Toolbar control (as opposed to the toolbar configuration in the grid itself). I have a number of different buttons/menus on the toolbar, but am seeing a strange behavior when calling saveChanges() on the grid. If a cell is being edited when the save button is clicked, the grid is saved, but the edited value is lost (it reverts back to where it was). The following details what I see in different situations:
When using a save button configured in the grid (command: "save"), any changes in a cell being edited are committed with the save.
When using a plain html button that calls the saveChanges() method of the grid, any changes in a cell being edited are committed with the save.
When using a save button configured in a toolbar control, the changes in a cell being edited are LOST when saveChanges() is called.
The following jsbin shows the behavior of all three:
http://jsbin.com/jazobexatu/2/edit?html,js,output
I have tried calling the save from the toolbar button a number of different ways (even trying to trigger the click event of the external button), but nothing seems to correct the behavior. I also tried calling closeCell() on the grid (to try to force the value back into the data, but that doesn't work either). I haven't been able to debug the javascript enough to figure out what is different. I'm hoping someone with a deeper understanding of these controls can help me out.
For some reason, the mouse down event on the toolbar button doesn't cause a blur on the editor.
You can try it yourself by clicking in the cell to edit it, then click and hold the mouse button down on the "normal" button. The editor closes on mouse down, causing a blur of the editor, and persists the change.
If you do the same thing, click and hold mouse down, on the toolbar button, the editor stays open.
I've been poking through the source, but haven't figured out exactly why this happens. My best guess would be that the mousedown handler on the toolbar prevents the event from bubbling or running its default action and the editor doesn't blur.
Additional detail: On mousedown on the grid header button and the normal button, the focused element changes (which is what causes the editor blur). But on mousedown of the toolbar button, the editor input element still has the focus.
Shifting the focus on mousedown of the toolbar might be a workaround.
Sort of a weird hack, but this works in Chrome (any should in any browser that supports activeElement
click: function (e) {
$(document.activeElement).blur();
$("#grid").data("kendoGrid").saveChanges();
}

jQuery how do i select multiple elements

I am new to jQuery and i want to figure out how to select multiple elements for my navigation bar i'm trying to create. I want to have it check if the users mouse is over the item in the navigation bar or over the drop down menu (otherwise the drop down menu would disappear). I have tried to use:
$('#nav_item_1').mouseenter(function(){
//make the drop down menu visible and change nav_item background here
}); `
$('#nav_item_1,#dropdown').mouseleave({
//revert everything back to normal
});
but then when i try to move my mouse from the item in the navigation bar to the drop down menu it reverts everything back to normal.
The issue that you're having is because when you leave the navigation bar item .mouseleave is being triggered instantly hiding the #dropdown with it.
What I would do here is set a slight time out on the mouseleave event of the nav_item about half a second or less to hide the dropdown. This will allow the user the amount of seconds set outside of the navigation bar so that they can hover over the dropdown. After the user is on the #dropdown I would clear the timeout preventing the normal behavior of the dropdown hiding.
How would you do this with code?
$('#nav_item_1').mouseleave(function() {
/* set your time out here to return everything to normal. Because we want to allow the dropdown to stay visible for a fraction of time required to move the cursor to the dropdown.*/
});
And then,
$('#dropdown').mouseenter(function() {
// clear the timer to prevent normal behavior (keeping the dropdown visible).
});
Check out this link: http://www.w3schools.com/js/js_timing.asp
Regarding your original question about selecting multiple items. You are doing it corrently. But as I explained above your code is not reaching the mouseleave event of the #dropdown.
The second piece of code makes it so that when you leave #nav_item_1 OR #dropdown, everything will be reverted. So when you leave the #nav_item_1 to go to the #dropdown, the event will fire.
You could check every mouse move if the current mouse target contains the dropdown or nav_item:
$("#nav_item_1").mouseenter(function () {
// make menu visible etc
}
$(document).mousemove(function (e) { // note the e parameter
if ($(e.target).has("#dropdown,#nav_item_1").length !== 0) {
// revert
}
}
This requires the two elements to be very close to each other in order for it to work properly though.

How to require explicit dismissal of a yui popup menu?

I have a page with a couple of widgets on it, each of which, when clicked, brings up a yui popup menu: If I click on widget 1, its menu comes up. If I now click on widget 2, widget 1's menu gets a hide event, and widget 2's menu gets a show event and comes up. I'd like to change this so that, when widget 1's menu is up, it must be explicitly dismissed by a click on the page background (and/or, perhaps, another click on the widget or the escape key) before the menu attached to widget 2 is allowed to appear.
I've set up some beforeShowEvent and beforeHideEvent handlers on the menus, hoping to be able to use some method (a global variable? ick) of keeping track of when a menu is present and showing or hiding accordingly, but it's not working -- these handlers can't tell the difference between a click on the page background and a click on widget 2 (at least, not as I've done it so far). Is there any way to do what I'm trying to do? Thanks!
I think that a combination of clicktohide: false
Boolean indicating if the Menu will automatically be hidden if the user clicks outside of it. This property is only applied when the "position" configuration property is set to dynamic and is automatically applied to all submenus.
and keepopen: true
Boolean indicating if the menu should remain open when clicked.
will take care of this.
http://developer.yahoo.com/yui/menu/#configref

Resources