import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FindDialog7 extends KDialog {
    JLabel       findLabel   = new JLabel("Find:");
    JTextField   findText    = stdTextField(20);
    JCheckBox    caseCheck   = new JCheckBox("Match Case");
    JCheckBox    wordCheck   = new JCheckBox("Whole Word");
    JRadioButton topRadio    = new JRadioButton("Start at Top");
    JRadioButton wrapRadio   = new JRadioButton("Wrap Around");
    JButton      findButton  = new JButton("Find");
    JButton      closeButton = new JButton("Close");

    public static void main(String[] args) {
        JDialog dialog = new FindDialog7(new Frame(), "Find Dialog 7", true);
        dialog.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent event) { System.exit(0); }
        });
        dialog.setVisible(true);
        System.exit(0);
    }

    public FindDialog7(Frame owner, String title, boolean modal) {
        super(owner, title, modal);

        closeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                setVisible(false);
            }
        });

        layoutComponents();
        pack();
        setLocationRelativeTo(owner);
    }

    private void layoutComponents() {
        Container content = getContentPane();

        shrinkWrap(new AbstractButton[] { caseCheck, wordCheck,
                                          topRadio, wrapRadio });

        content.add(createVerticalStrut(13), BorderLayout.NORTH);
        content.add(createVerticalStrut(10), BorderLayout.SOUTH);
        content.add(createHorizontalStrut(29), BorderLayout.WEST);    // Additional margin
        content.add(createHorizontalStrut(10), BorderLayout.EAST);
        content.add(createMainBox());
    }
    
    private JPanel createMainBox() {
        JPanel box = new JPanel();
        box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
        box.setBackground(Color.red);

        box.add(createFindTextBox());           
        box.add(createVerticalStrut(11));
        box.add(createCheckRadioBox());
        box.add(createVerticalStrut(17));
        box.add(createActionButtonBox());
        return box;
    }

    private JPanel createFindTextBox() {
        JPanel box = new JPanel();
        box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
        box.setBackground(Color.green);

        box.add(findLabel);
        box.add(createHorizontalStrut(11));
        box.add(findText);
        return box;
    }

    private JPanel createCheckRadioBox() {
        JPanel box = new JPanel();
        box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
        box.setBackground(Color.blue);


        Dimension lblSize;
        lblSize = findLabel.getPreferredSize();
        box.add(createHorizontalStrut(lblSize.width + 11));

        box.add(createCheckButtonBox());
        box.add(createHorizontalStrut(11));           // Space between button groups
        box.add(createRadioButtonBox());
        box.add(Box.createHorizontalGlue());
        return box;
    }

    private JPanel createCheckButtonBox() {
        JPanel box = new JPanel();
        box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
        box.setBackground(Color.cyan);

        box.add(caseCheck);
        box.add(wordCheck);
        return box;
    }

    private JPanel createRadioButtonBox() {
        JPanel box = new JPanel();
        box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
        box.setBackground(Color.yellow);

        box.add(topRadio);
        box.add(wrapRadio);
        return box;
    }
    private JPanel createActionButtonBox() {
        JPanel box = new JPanel();
        box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
        box.setBackground(Color.magenta);

        matchComponentSize(new JComponent[]
                { findButton, closeButton });     
        box.add(Box.createHorizontalGlue());
        box.add(findButton);
        box.add(createHorizontalStrut(5));
        box.add(closeButton);
        return box;
    }

}



