Hi Christophe,

Thanks for pointing out this bug. I have opened an issue:
https://www.canoo.com/jira/browse/UBA-7172.

I will try to provide a work around.

Thanks and regards,

Janak

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
[EMAIL PROTECTED]
Sent: Monday, February 26, 2007 4:52 PM
To: [email protected]
Subject: [ULC-developer] ULCCombobox - IKeySelectionManager



I have a different behavior wenn I use a IKeySelectionManager with Swing or
ULC.

With Swing, the 'not-matching' KeyEvent (in this case PF10) is forwarded the
the container of the combobox.
With ULC, the KeyEvent ist consumed.

See the code snipets:

1. I register a keyboardAction for keyEvent F10 with
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT on a container.
2. I put tow comboboxes on this container. the second combobox have a
IKeySelectionManager.
3. When the second combobox has the focus,  the keyEvent F10 shoul be
forwarded.

Regards,
Christophe Perret

mailto:[EMAIL PROTECTED]


ULC:

public class TestULC extends AbstractApplication{

        /**
         * @param args
         */
        public static void main(String[] args) {

                DevelopmentRunner.setApplicationClass(TestULC.class);
                DevelopmentRunner.main(args);

        }

        /* (non-Javadoc)
         * @see com.ulcjava.base.application.IApplication#start()
         */
        public void start() {

                final ULCFrame frame = new ULCFrame("Test KeyboardListener
ULC");
                frame.addWindowListener(new IWindowListener() {

                        public void windowClosing(WindowEvent event) {
                                ApplicationContext.terminate();
                        }
                });

                frame.setSize(500, 300);

                ULCBoxPane pane = new ULCBoxPane(true);
                pane.add(getCombobox());
                pane.add(getComboBoxWithSelectionManager());
                pane.add(getText());
                pane.add(getTextWithKeyListeners());


                pane.registerKeyboardAction(new IActionListener() {

                        public void actionPerformed(ActionEvent event) {

                                new ULCAlert(" ", "F10 pressed",
"ok").show();

                        }}, KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0),
ULCComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

                frame.add(pane);
                frame.setVisible(true);

        }


        /**
         * @return
         */
        private ULCComponent getComboBoxWithSelectionManager() {

                ULCComboBox combo = getCombobox();
                combo.setKeySelectionManager(new IKeySelectionManager(){

                        public int selectionForKey(char keyChar,
IComboBoxModel model) {
                                // do some  stuff here
                                return -1;
                        }});

                return combo;
        }


        /**
         * @return
         */
        private static ULCComboBox getCombobox() {

                return new ULCComboBox(new String[]{"one", "two", "three"});
        }

        /**
         * @return
         */
        private static ULCTextField getText() {

                return new ULCTextField("very simple ULCTextField");
        }

        /**
         * @return
         */
        private static ULCTextField getTextWithKeyListeners() {

                ULCTextField txt = new ULCTextField("ULCTextField with
KeyListeners");

                txt.addKeyListener(new IKeyListener() {

                        public void keyTyped(KeyEvent event) {

                                new ULCAlert( " ", "any key pressed on
TextField", "ok").show();

                        }});

                txt.registerKeyboardAction(new IActionListener(){

                        public void actionPerformed(ActionEvent event) {

                                new ULCAlert( " ", "F11 pressed on
TextField", "ok").show();

                        }}, KeyStroke.getKeyStroke(KeyEvent.VK_F11,
0),ULCComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
                return txt;
        }
}

Swing:

public class TestSwing {

        /**
         * @param args
         */
        public static void main(String[] args) {


                final JFrame frame = new JFrame("Test KeyboardListener
Swing");


                frame.setSize(500, 300);

                final JPanel pane = new JPanel();
                pane.add(getCombobox());
                pane.add(getComboBoxWithSelectionManager());
                pane.add(getText());
                pane.add(getTextWithKeyListeners());


                pane.registerKeyboardAction(new ActionListener(){

                        public void actionPerformed(ActionEvent e) {

                                JOptionPane.showMessageDialog(pane, "F10
pressed on pane.");

                        }}, KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

                frame.add(pane);

                frame.setVisible(true);


        }



        /**
         * @return
         */
        private static JComponent getComboBoxWithSelectionManager() {

                JComboBox combo = getCombobox();
                combo.setKeySelectionManager(new
JComboBox.KeySelectionManager(){

                        public int selectionForKey(char aKey, ComboBoxModel
aModel) {

                                // do some stuff here

                                return -1;
                        }});

                return combo;
        }


        /**
         * @return
         */
        private static JComboBox getCombobox() {

                return new JComboBox(new String[]{"one", "two", "three"});
        }

        /**
         * @return
         */
        private static JTextField getText() {

                return new JTextField("very simple ULCTextField");
        }

        /**
         * @return
         */
        private static JTextField getTextWithKeyListeners() {

                final JTextField txt = new JTextField("ULCTextField with
KeyListeners");

                txt.addKeyListener(new KeyListener() {

                        public void keyTyped(KeyEvent e) {

                                JOptionPane.showMessageDialog(txt, "keyTyped
on JTextField.");

                        }

                        public void keyPressed(KeyEvent e) {

                                JOptionPane.showMessageDialog(txt,
"keyPressed on JTextField.");

                        }

                        public void keyReleased(KeyEvent e) {

                                JOptionPane.showMessageDialog(txt,
"keyReleased on JTextField.");

                        }});

                txt.registerKeyboardAction(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {

                                JOptionPane.showMessageDialog(txt, "F11
pressed on JTextField.");

                        }}, KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );

                return txt;
        }
}

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

Reply via email to