Hi Les,

In ULC, temporary focus events (FocusEvent#isTemporary()) are not forwarded
to the server.

You will need to extend the component for which you want to capture all
focus events. Please see the snippet at the end of this mail.

ULC does not provide an API for menu listeners. If you wish you could extend
ULCMenu to handle this event. Please see the
ULC Extension Guide for implementing events.

Thanks and regards,

Janak

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Les Thomas
Sent: Tuesday, October 17, 2006 9:18 PM
To: [EMAIL PROTECTED]
Cc: 'Les Thomas'
Subject: [ULC-developer] Focus Lost Bug



I believe I have discovered a bug with focus lost events for a text field.
I have a text field with a focus event listener and a menu.  If I click into
the text field, the text field correctly receives the focus gained event.
However, if I click on the menu item, the text field never receives a focus
lost event.  This is different behavior than Swing.

Can you provide any workarounds?  I am trying to implement a solution where
menu items become enabled or disabled based upon whether a text field has
focus.

Also, Swing's JMenu can have menu listeners that will receive menu selected,
menu deselected and menu cancelled events.  Is there an equivalent in ULC?
If I can get the menu select event, then I could assume that the text field
no longer has focus.

Finally, is there any equivalent Swing UndoManager functionality in ULC?  Do
you have any built in support for implementing undo functionality in ULC?

I have provided a test case for ULC and Swing to demonstrate the focus bug.

ULC Version: 6.1.1
JVM: Java 5 (1.5.0_06)

Kind regards,

Les

-----------------------

import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ClientContext;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCMenu;
import com.ulcjava.base.application.ULCMenuBar;
import com.ulcjava.base.application.ULCMenuItem;
import com.ulcjava.base.application.ULCTextField;
import com.ulcjava.base.application.event.FocusEvent;
import com.ulcjava.base.application.event.IFocusListener;
import com.ulcjava.base.application.util.Color;
import com.ulcjava.base.client.UITextField;
import com.ulcjava.base.development.DevelopmentRunner;
import com.ulcjava.base.shared.UlcEventCategories;
import com.ulcjava.base.shared.UlcEventConstants;

public class TestULCFocusExtension extends AbstractApplication {
        private ULCMyTextField textField = null;

        public void start() {

                textField = new ULCMyTextField(20);
                textField.addFocusListener(new IFocusListener() {
                        public void focusGained(FocusEvent event) {
                                textField.setBackground(Color.gray);
                                System.out.println("textfield Gained");
                        }

                        public void focusLost(FocusEvent event) {
                                textField.setBackground(Color.white);
                                System.out.println("textfield Lost");
                        }
                });

                 ClientContext.setEventDeliveryMode(textField,
                 UlcEventCategories.FOCUS_EVENT_CATEGORY,
                 UlcEventConstants.ASYNCHRONOUS_MODE);

                ULCBoxPane content = new ULCBoxPane();
                content.add(ULCBoxPane.BOX_EXPAND_CENTER, textField);

                ULCFrame frame = new ULCFrame("Test Focus Lost");

                ULCMenuBar menuBar = new ULCMenuBar();
                final ULCMenu editMenu = new ULCMenu("Edit");

                ULCMenuItem cut = new ULCMenuItem("Cut");
                ULCMenuItem copy = new ULCMenuItem("Copy");
                ULCMenuItem paste = new ULCMenuItem("Paste");

                editMenu.add(cut);
                editMenu.add(copy);
                editMenu.add(paste);
                menuBar.add(editMenu);

                frame.setMenuBar(menuBar);

                frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
                frame.add(content);
                frame.setVisible(true);
        }

        public static void main(String[] args) {
                
DevelopmentRunner.setApplicationClass(TestULCFocusExtension.class);
                DevelopmentRunner.main(args);
        }

        public static class ULCMyTextField extends ULCTextField {

                public ULCMyTextField(int i) {
                        super(i);
                }

                protected String typeString() {
                        return UIMyTextField.class.getName();
                }

        }

        public static class UIMyTextField extends UITextField {

                public void focusGained(java.awt.event.FocusEvent event) {
                        super.focusGained(event);
                        if (event.isTemporary()) {
                                fireFocusGainedULC();
                        }
                }

                public void focusLost(java.awt.event.FocusEvent event) {
                        super.focusLost(event);
                        if (event.isTemporary()) {
                                fireFocusLostULC();
                        }
                }
        }
}

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to