You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Jumbo <p_...@yahoo.com> on 2013/02/15 11:35:02 UTC

RE: Dialog opened from menu loses focus

Hi Roger,

Is it possible for you to share how you have resolved this issue by
sub-classing the menu and disabling the transition animations?

Thanks.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Dialog-opened-from-menu-loses-focus-tp4022067p4022441.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: Dialog opened from menu loses focus

Posted by Jumbo <p_...@yahoo.com>.
Thanks a lot Oliver for sharing your solution.



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Dialog-opened-from-menu-loses-focus-tp4022067p4022449.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: Dialog opened from menu loses focus

Posted by Oliver Oyston <Ol...@actian.com>.
I worked around the problem using a custom skin - perhaps not the most
elegant solution but it works...

The custom skin is registered at an appropriate place (application
startup / constructor / etc).

// Use a customized skin for menu items
theme.set(Menu.Item.class, CustomMenuItemSkin.class);

Our main class exposes the mainWindow like this:

/**
 * The main application window (top-level Pivot object).
 */
@BXML public static Window mainWindow;

I renamed our main class to "MainClass" in the snippet below - you will
need to implement this as appropriate for your application or alter the
skin to make it more generic

package your.package.name.here;

import org.apache.pivot.util.Vote;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Container;
import org.apache.pivot.wtk.Menu;
import org.apache.pivot.wtk.MenuPopup;
import org.apache.pivot.wtk.MenuPopupStateListener;
import org.apache.pivot.wtk.Mouse;
import org.apache.pivot.wtk.skin.terra.TerraMenuItemSkin;

/**
 * Custom skin to ensure that the transition effects of the context menu
does not cause the stealing of focus from dialogs.
 */
public class CustomMenuItemSkin extends TerraMenuItemSkin {

    @Override
    public boolean mouseUp(Component component, Mouse.Button button, int
x, int y) {
        boolean consumed = super.mouseDown(component, button, x, y);

        Menu.Item menuItem = (Menu.Item)getComponent();

        if (menuItem.isActive()) {

            MenuPopup popup;

            // Find the first MenuPopup container for the component.
            Container container = component.getParent();

            do {
                if (container.getClass() == MenuPopup.class){

                    // We found a menu popup
                    popup = (MenuPopup)container;

                    // Disable the main window.
                    MainClass.mainWindow.setEnabled(false);

                    popup.getMenuPopupStateListeners().add(new
MenuPopupStateListener() {
                        @Override
                        public Vote previewMenuPopupClose(MenuPopup
components, boolean b) {
                            return Vote.APPROVE;
                        }

                        @Override
                        public void menuPopupCloseVetoed(MenuPopup
components, Vote vote) {

                        }

                        @Override
                        public void menuPopupClosed(MenuPopup
components) {
                            // Enable the main window.
                            MainClass.mainWindow.setEnabled(true);

                            // Remove listener.
 
components.getMenuPopupStateListeners().remove(this);
                        }
                    });

                    // Break out of the loop.
                    break;
                }
            }
            while ((container = container.getParent()) != null);

            // Execute the menu press
            menuItem.press();
        }

        return consumed;
    }
}

Hope this helps.

Oli

-----Original Message-----
From: Jumbo [mailto:p_kowshik@yahoo.com] 
Sent: Friday, February 15, 2013 2:35 AM
To: user@pivot.apache.org
Subject: RE: Dialog opened from menu loses focus

Hi Roger,

Is it possible for you to share how you have resolved this issue by
sub-classing the menu and disabling the transition animations?

Thanks.



--
View this message in context:
http://apache-pivot-users.399431.n3.nabble.com/Dialog-opened-from-menu-l
oses-focus-tp4022067p4022441.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.