<commit_before>package example;
//-*- mode:java; encoding:utf8n; coding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class MainPanel extends JPanel{
    private static final String dummy = "Hello";
    private final JTextArea textArea = new JTextArea();
    private final JTextField textField1 = new JTextField(dummy);
    private final JTextField textField2 = new JTextField(dummy);
    private final JTextField textField3 = new JTextField(dummy);
    private final JTextField textField4 = new JTextField(dummy);
    public MainPanel(final JFrame frame) {
        super(new BorderLayout());
        textField3.addHierarchyListener(new HierarchyListener() {
            @Override public void hierarchyChanged(HierarchyEvent e) {
                if((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED)!=0 && textField3.isShowing()) {
                    EventQueue.invokeLater(new Runnable(){
                        @Override public void run() {
                            textField3.requestFocusInWindow();
                        }
                    });
                }
            }
        });
        //http://forums.sun.com/thread.jspa?threadID=777887
        textField4.addAncestorListener(new AncestorListener() {
            @Override public void ancestorAdded(AncestorEvent event) {
                textField4.requestFocusInWindow();
            }
            @Override public void ancestorMoved(AncestorEvent event) {}
            @Override public void ancestorRemoved(AncestorEvent event) {}
        });

        JPanel p = new JPanel(new GridLayout(2,2,5,5));
        p.add(makePanel("Default",           frame, textField1));
        p.add(makePanel2("WindowListener",   frame, textField2));
        p.add(makePanel("HierarchyListener", frame, textField3));
        p.add(makePanel("AncestorListener",  frame, textField4));
        add(p, BorderLayout.NORTH);
        add(new JScrollPane(textArea));
        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        setPreferredSize(new Dimension(320, 180));
    }
    private JPanel makePanel(String title, final JFrame frame, final JTextField textField) {
        JPanel p = new JPanel(new BorderLayout());
        p.setBorder(BorderFactory.createTitledBorder(title));
        p.add(new JButton(new AbstractAction("show") {
            @Override public void actionPerformed(ActionEvent e) {
                int result = JOptionPane.showConfirmDialog(frame, textField, "Input Text", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
                if(result==JOptionPane.OK_OPTION) textArea.setText(textField.getText());
            }
        }));
        return p;
    }
    private JPanel makePanel2(String title, final JFrame frame, final JTextField textField) {
        JPanel p = new JPanel(new BorderLayout());
        p.setBorder(BorderFactory.createTitledBorder(title));
        p.add(new JButton(new AbstractAction("show") {
            @Override public void actionPerformed(ActionEvent e) {
                JOptionPane pane = new JOptionPane(textField, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);<commit_msg>use AncestorEvent#getComponent()<commit_after>package example;
//-*- mode:java; encoding:utf8n; coding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class MainPanel extends JPanel{
    private static final String dummy = "Hello";
    private final JTextArea textArea = new JTextArea();
    private final JTextField textField1 = new JTextField(dummy);
    private final JTextField textField2 = new JTextField(dummy);
    private final JTextField textField3 = new JTextField(dummy);
    private final JTextField textField4 = new JTextField(dummy);
    public MainPanel(final JFrame frame) {
        super(new BorderLayout());
        textField3.addHierarchyListener(new HierarchyListener() {
            @Override public void hierarchyChanged(HierarchyEvent e) {
                final JComponent c = (JComponent)e.getComponent();
                if((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED)!=0 && c.isShowing()) {
                    EventQueue.invokeLater(new Runnable(){
                        @Override public void run() {
                            c.requestFocusInWindow();
                            //or textField3.requestFocusInWindow();
                        }
                    });
                }
            }
        });
        //http://forums.sun.com/thread.jspa?threadID=777887
        textField4.addAncestorListener(new AncestorListener() {
            @Override public void ancestorAdded(AncestorEvent e) {
                e.getComponent().requestFocusInWindow();
                //or textField4.requestFocusInWindow();
            }
            @Override public void ancestorMoved(AncestorEvent e) {}
            @Override public void ancestorRemoved(AncestorEvent e) {}
        });

        JPanel p = new JPanel(new GridLayout(2,2,5,5));
        p.add(makePanel("Default",           frame, textField1));
        p.add(makePanel2("WindowListener",   frame, textField2));
        p.add(makePanel("HierarchyListener", frame, textField3));
        p.add(makePanel("AncestorListener",  frame, textField4));
        add(p, BorderLayout.NORTH);
        add(new JScrollPane(textArea));
        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        setPreferredSize(new Dimension(320, 180));
    }
    private JPanel makePanel(String title, final JFrame frame, final JTextField textField) {
        JPanel p = new JPanel(new BorderLayout());
        p.setBorder(BorderFactory.createTitledBorder(title));
        p.add(new JButton(new AbstractAction("show") {
            @Override public void actionPerformed(ActionEvent e) {
                int result = JOptionPane.showConfirmDialog(frame, textField, "Input Text", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
                if(result==JOptionPane.OK_OPTION) textArea.setText(textField.getText());
            }
        }));
        return p;
    }
    private JPanel makePanel2(String title, final JFrame frame, final JTextField textField) {
        JPanel p = new JPanel(new BorderLayout());
        p.setBorder(BorderFactory.createTitledBorder(title));
        p.add(new JButton(new AbstractAction("show") {
            @Override public void actionPerformed(ActionEvent e) {
                JOptionPane pane = new JOptionPane(textField, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
{'fraction_non_alphanumeric': 0.10656474820143885, 'fraction_numerical': 0.011540767386091126, 'mean_word_length': 2.7300167691447736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '931779', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1830, 'n_words': 394}