Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4241538

Regression: Wrong isTemporary() status of FocusLost event on Solaris

XMLWordPrintable

    • 1.2.2
    • generic
    • solaris_2.6
    • Verified

        Fix for bug#4124969 & bug#4124199 in canvas.c is not complete&correct
        which causes the isTemporary() method of FocusOut event returns wrong
        status, this regression makes the inputmethod functionality does not
        work correctly (both on 1.2.2 and 1.3)

        The following sample showes the problem, click the "cyan" area to make
        one of the lightweight components obtain the focus, then click to
        switch focus owner between lightweight components, you will find the
        isTemporary() of the FocusLost event is "permanent" which is correct, but
        if you change the focus owner from a lightweight component to the perred
        TextField component, the FocusLost's isTemporary() returns "temporary".


        import java.applet.*;
        import java.awt.*;
        import java.awt.event.*;

        public class lwfocus extends Panel
        {

          PassiveClient pc1 = new PassiveClient("LW_1");
          PassiveClient pc2 = new PassiveClient("LW_2");
          TextField tx = new TextField("textfield");

          public lwfocus(String title) {
            super();
            setLayout(new GridLayout(3, 1, 10, 10));
            add(pc1);
            add(pc2);
            add(tx);
          }

          public void start() {
          }
            
          public void stop() {
          }

          public static void main(String argv[]) {
            Frame frame = new Frame("lightweight focus");
            lwfocus test = new lwfocus("hello");

            test.setSize(400,400);

            test.start();

            frame.add("Center", test);
            frame.setSize(400, 400);

            WindowListener listener = new WindowAdapter() {
              public void windowClosing(WindowEvent e) {
        e.getWindow().dispose();
        System.exit(0);
              };
            };


            frame.addWindowListener(listener);
            frame.validate();
            frame.setVisible(true);
          }

        }
        class PassiveClient extends Container implements FocusListener {
            boolean haveFocus = false;
            String name;
            Window w;

            PassiveClient(String name) {
                super();
                this.name = name;
        setSize(400, 100);
        setBackground(Color.cyan);
        setVisible(true);
        setEnabled(true);
        addMouseListener(new MouseFocusListener(this));
        addFocusListener(this);
                w = null;
            }

            Window GetWindow() {
                Container w = this;
                while(!(w instanceof Window)) {
                    w = w.getParent();
                }
                return (Window)w;
            }

            public void paint(Graphics g) {
        g.setColor(getBackground());
        Dimension size = getSize();
        g.fillRect(0, 0, size.width, size.height);
        if (haveFocus) {
        g.setColor(Color.black);
        g.drawRect(0, 0, size.width - 1, size.height - 1);
        g.drawRect(1, 1, size.width - 3, size.height - 3);
        }
        g.setColor(getForeground());
            }
            
            public void focusGained(FocusEvent event) {
                haveFocus = true;
        paint(getGraphics());
        System.out.println();
                if (w == null)
        w = GetWindow();
        System.out.println("--------------------------------");
        System.out.println("GAIN<" + name + ":" + event + "> ");
            }
            
            public void focusLost(FocusEvent event) {
                haveFocus = false;
        paint(getGraphics());
        System.out.println();
        System.out.println("--------------------------------");
        System.out.println("LOST<" + name + ":" + event + ">");
            }
        }
        class MouseFocusListener extends MouseAdapter {

            private Component target;
            
            MouseFocusListener(Component target) {
                this.target = target;
            }

            public void mouseClicked(MouseEvent e) {
                target.requestFocus();
            }

        }

              duke J. Duke
              sherman Xueming Shen
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: