JDK-4241538 : Regression: Wrong isTemporary() status of FocusLost event on Solaris
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.2
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.6
  • CPU: generic
  • Submitted: 1999-05-26
  • Updated: 1999-08-02
  • Resolved: 1999-06-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.2.2 1.2.2Fixed 1.3.0Fixed
Related Reports
Relates :  
Description
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();
    } 

}


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.2.2 kestrel-beta FIXED IN: 1.2.2 kestrel-beta INTEGRATED IN: 1.2.2 kestrel kestrel-beta VERIFIED IN: 1.2.2 kestrel-beta
14-06-2004

SUGGESTED FIX jenny.wang@East 1999-06-07 FOCUS_LOST focus event in Java AWT has two different types: temporary and permanent. The main purpose of the temporary FOCUS_LOST event is to allow a component to receive focus when the focus is restored to its containing window. In general, a component fires a permanent FOCUS_LOST event when it loses the focus to some other component in the same window; a component fires a temporary event when some system operation temporarily takes the focus to do something else, such as open a menu or move cursor outside of the window. Unfortunately the X11 focus model send by X event handler does not make this distinction easy to determine, so we must keep tracking the input focus to determine which FOCUS_LOST focus event should be sent out. ------- canvas.c ------- 68a69,74 > static Widget input_focus = NULL; > > void trackInputFocus (Widget w) { > input_focus = w; > } > 529,530c535 < /* If the event is sent by client or it is caused by a grab < * (i.e. a menu invocation), then this focus-out event is --- > /* If the event is sent by system then focus-out event is 533,536c538,539 < if (fevent->send_event || < (fevent->mode == NotifyGrab || < fevent->mode == NotifyWhileGrabbed)) < temp = TRUE; --- > if (input_focus == w || input_focus == NULL) > temp = TRUE; 1109a1113,1115 > > trackInputFocus(w); > ------- awt_Component.c ------- 1120a1121,1123 > > trackInputFocus(bdata->widget); > 1132a1136 > ------- canvas.h ------- 36a37 > void trackInputFocus (Widget w);
11-06-2004

WORK AROUND [xueming.shen@eng] back out the fix for bug#4124969 and bug#4124119 in canvas.c before we have a complete/correct fix. jenny.wang@East 1999-07-21 I have putback the fix to East Coast Kestral tree at June 7. Go there and get the fix. There is nothing needs to back out!!!!
21-07-1999

EVALUATION See X Suggested Fix field. [xueming.shen@Eng 1999-07-20] Must integrate this fix into kestrel.BETA
20-07-1999