class SearchPanel
{
    private final Action nextAction;
    private final Action previousAction;
    private JCheckBox caseSensitive;
    private JTextField searchField;
    private JLabel counterLabel;
    private JPanel panel;
    
    private final Action closeAction = new AbstractAction()
    {
        @Override
        public void actionPerformed(ActionEvent actionEvent)
        {
            panel.setVisible(false);
            closeAction.setEnabled(false);
            panel.getParent().transferFocus();
        }
    };
    
    private final Action findAction = new AbstractAction()
    {
        @Override
        public void actionPerformed(ActionEvent actionEvent)
        {
            if (!panel.isVisible())
            {
                panel.setVisible(true);
                panel.getParent().validate();
                return;
            }
            reFocus();
        }
    };

    /**
     * Constructor.
     * @param documentListener DocumentListener instance.
     * @param changeListener ChangeListener instance.
     * @param compListener ComponentListener instance.
     * @param nextAction Action instance for next find.
     * @param previousAction Action instance for previous find.
     */
    SearchPanel(DocumentListener documentListener, ChangeListener changeListener,
                ComponentListener compListener, Action nextAction, Action previousAction)
    {
        this.nextAction = nextAction;
        this.previousAction = previousAction;
        initUI(documentListener, changeListener, compListener);
    }

    private void initUI(DocumentListener documentListener, ChangeListener changeListener,
                        ComponentListener compListener)
    {<FILL_FUNCTION_BODY>}

    boolean isCaseSensitive()
    {
        return caseSensitive.isSelected();
    }

    String getSearchWord()
    {
        return searchField.getText();
    }

    void reset()
    {
        counterLabel.setVisible(false);
    }

    void updateCounterLabel(int now, int total)
    {
        if (!counterLabel.isVisible())
        {
            counterLabel.setVisible(true);
        }
        if (total == 0)
        {
            counterLabel.setText(" No match found ");
            nextAction.setEnabled(false);
            return;
        }
        counterLabel.setText(" " + now + " of " + total + " ");
    }

    JPanel getPanel()
    {
        return panel;
    }

    public void reFocus()
    {
        searchField.requestFocus();
        String searchKey = searchField.getText();
        searchField.setText(searchKey);
        searchField.setSelectionStart(0);
        searchField.setSelectionEnd(searchField.getText().length());

        closeAction.setEnabled(true);
    }

    public void addMenuListeners(PDFDebugger frame)
    {
        frame.getFindMenu().setEnabled(true);
        frame.getFindMenuItem().addActionListener(findAction);
        frame.getFindNextMenuItem().addActionListener(nextAction);
        frame.getFindPreviousMenuItem().addActionListener(previousAction);
    }

    public void removeMenuListeners(PDFDebugger frame)
    {
        frame.getFindMenu().setEnabled(false);
        frame.getFindMenuItem().removeActionListener(findAction);
        frame.getFindNextMenuItem().removeActionListener(nextAction);
        frame.getFindPreviousMenuItem().removeActionListener(previousAction);
    }
}

        searchField = new JTextField();
        searchField.getDocument().addDocumentListener(documentListener);

        counterLabel = new JLabel();
        counterLabel.setVisible(false);

        JButton nextButton = new JButton();
        nextButton.setAction(nextAction);
        nextButton.setText("Next");

        JButton previousButton = new JButton();
        previousButton.setAction(previousAction);
        previousButton.setText("Previous");

        caseSensitive = new JCheckBox("Match case");
        caseSensitive.setSelected(false);
        caseSensitive.addChangeListener(changeListener);
        caseSensitive.setToolTipText("Check for case sensitive search");

        JButton crossButton = new JButton();
        crossButton.setAction(closeAction);
        crossButton.setText("Done");
        closeAction.setEnabled(false);
        
        panel = new JPanel();
        panel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
        panel.setBackground(new Color(230, 230, 230));
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

        panel.add(Box.createHorizontalGlue());
        panel.add(searchField);
        panel.add(counterLabel);
        panel.add(previousButton);
        panel.add(nextButton);
        panel.add(caseSensitive);
        panel.add(Box.createRigidArea(new Dimension(5, 0)));
        panel.add(crossButton);

        panel.addComponentListener(compListener);

        searchField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), closeAction);
    
<no_super_class>