Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
   *
   * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   * Other names may be trademarks of their respective owners.
   *
   * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common
  * Development and Distribution License("CDDL") (collectively, the
  * "License"). You may not use this file except in compliance with the
  * License. You can obtain a copy of the License at
  * http://www.netbeans.org/cddl-gplv2.html
  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  * specific language governing permissions and limitations under the
  * License.  When distributing the software, include this License Header
  * Notice in each file and include the License file at
  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Oracle in the GPL Version 2 section of the License file that
  * accompanied this code. If applicable, add the following below the
  * License Header, with the fields enclosed by brackets [] replaced by
  * your own identifying information:
  * "Portions Copyrighted [year] [name of copyright owner]"
  *
  * If you wish your version of this file to be governed by only the CDDL
  * or only the GPL Version 2, indicate your decision by adding
  * "[Contributor] elects to include this software in this distribution
  * under the [CDDL or GPL Version 2] license." If you do not indicate a
  * single choice of license, a recipient has the option to distribute
  * your version of this file under either the CDDL, the GPL Version 2 or
  * to extend the choice of license to its licensees as provided above.
  * However, if you add GPL Version 2 code and therefore, elected the GPL
  * Version 2 license, then the option applies only if the new code is
  * made subject to such option by the copyright holder.
  *
  * Contributor(s):
  *
  * Portions Copyrighted 2009 Sun Microsystems, Inc.
  */
 package org.netbeans.modules.bugtracking.ui.search;
 

Author(s):
Jan Stola
 
 class FindBar extends javax.swing.JPanel {
     private static final int MAX_SEARCH_MODEL_SIZE = 5;
     private FindSupport support;
     private boolean initialized;
 
     public FindBar(FindSupport support) {
         this. = support;
         initComponents();
          = new DefaultComboBoxModel();
         .setSelectedItem(""); // NOI18N
          = true;
         addComboEditorListener();
         String closeKey = "close"// NOI18N
         inputMap.put(KeyStroke.getKeyStroke(., 0), closeKey);
         getActionMap().put(closeKeynew AbstractAction() {
             @Override
             public void actionPerformed(ActionEvent e) {
                 FindBar.this..cancel();
             }
         });
     }
 
     private void addComboEditorListener() {
         Component editor = .getEditor().getEditorComponent();
         if (editor instanceof JTextComponent) {
             JTextComponent tcomp = (JTextComponent)editor;
             tcomp.getDocument().addDocumentListener(new DocumentListener() {
                 @Override
                 public void insertUpdate(DocumentEvent e) {
                     changedUpdate(e);
                 }
                 @Override
                 public void removeUpdate(DocumentEvent e) {
                     changedUpdate(e);
                 }
                @Override
                public void changedUpdate(DocumentEvent e) {
                    .updatePattern();
                }
            });
        }
    }
    String getPattern() {
        return .getEditor().getItem().toString();
    }
    boolean getMatchCase() {
        return .isSelected();
    }
    boolean getWholeWords() {
        return .isSelected();
    }
    boolean getRegularExpression() {
        return .isSelected();
    }
    boolean getHighlightResults() {
        return .isSelected();
    }
    @Override
    public boolean requestFocusInWindow() {
        return .requestFocusInWindow();
    }

    
This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
         = new javax.swing.JLabel();
         = new javax.swing.JComboBox();
         = new javax.swing.JCheckBox();
         = new javax.swing.JButton();
         = new javax.swing.JCheckBox();
         = new javax.swing.JCheckBox();
         = new javax.swing.JCheckBox();
         = new javax.swing.JButton();
         = new javax.swing.JButton();
        .setText(org.openide.util.NbBundle.getMessage(FindBar.class"FindBar.findLabel.text")); // NOI18N
        .setEditable(true);
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findComboActionPerformed(evt);
            }
        });
        .setText(org.openide.util.NbBundle.getMessage(FindBar.class"FindBar.machCaseChoice.text")); // NOI18N
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                machCaseChoiceActionPerformed(evt);
            }
        });
        .setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/bugtracking/ui/resources/find_close.png"))); // NOI18N
        .setBorderPainted(false);
        .setContentAreaFilled(false);
        .setFocusable(false);
        .setMargin(new java.awt.Insets(2, 1, 0, 1));
        .setRolloverEnabled(true);
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                closeButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                closeButtonMouseExited(evt);
            }
        });
        .setText(org.openide.util.NbBundle.getMessage(FindBar.class"FindBar.wholeWordsChoice.text")); // NOI18N
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                wholeWordsChoiceActionPerformed(evt);
            }
        });
        .setText(org.openide.util.NbBundle.getMessage(FindBar.class"FindBar.regularExpressionChoice.text")); // NOI18N
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                regularExpressionChoiceActionPerformed(evt);
            }
        });
        .setText(org.openide.util.NbBundle.getMessage(FindBar.class"FindBar.highlightResultsChoice.text")); // NOI18N
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                highlightResultsChoiceActionPerformed(evt);
            }
        });
        .setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/bugtracking/ui/resources/find_previous.png"))); // NOI18N
        .setText(org.openide.util.NbBundle.getMessage(FindBar.class"FindBar.findPreviousButton.text")); // NOI18N
        .setBorderPainted(false);
        .setFocusable(false);
        .setMargin(new java.awt.Insets(2, 1, 0, 1));
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findPreviousButtonActionPerformed(evt);
            }
        });
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                findPreviousButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                findPreviousButtonMouseExited(evt);
            }
        });
        .setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/bugtracking/ui/resources/find_next.png"))); // NOI18N
        .setText(org.openide.util.NbBundle.getMessage(FindBar.class"FindBar.findNextButton.text")); // NOI18N
        .setBorderPainted(false);
        .setContentAreaFilled(false);
        .setFocusable(false);
        .setMargin(new java.awt.Insets(2, 1, 0, 1));
        .setRolloverEnabled(true);
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findNextButtonActionPerformed(evt);
            }
        });
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                findNextButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                findNextButtonMouseExited(evt);
            }
        });
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add()
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add()
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add()
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add()
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add()
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add()
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add()
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, .)
                .add())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add()
                .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add()
                .add()
                .add()
                .add()
                .add()
                .add()
                .add())
        );
    }// </editor-fold>//GEN-END:initComponents
    private void closeButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeButtonMouseEntered
        processMouseEvent(evttrue);
    }//GEN-LAST:event_closeButtonMouseEntered
    private void closeButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeButtonMouseExited
        processMouseEvent(evtfalse);
    }//GEN-LAST:event_closeButtonMouseExited
    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        .cancel();
    }//GEN-LAST:event_closeButtonActionPerformed
    private void findComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findComboActionPerformed
        if ( && isVisible()) {
            updateComboModel();
            .findNext();
        }
    }//GEN-LAST:event_findComboActionPerformed
    private void machCaseChoiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_machCaseChoiceActionPerformed
        .updatePattern();
    }//GEN-LAST:event_machCaseChoiceActionPerformed
    private void wholeWordsChoiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wholeWordsChoiceActionPerformed
        .updatePattern();
    }//GEN-LAST:event_wholeWordsChoiceActionPerformed
    private void regularExpressionChoiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_regularExpressionChoiceActionPerformed
        .updatePattern();
    }//GEN-LAST:event_regularExpressionChoiceActionPerformed
    private void highlightResultsChoiceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_highlightResultsChoiceActionPerformed
    }//GEN-LAST:event_highlightResultsChoiceActionPerformed
    private void findNextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findNextButtonActionPerformed
        updateComboModel();
        .findNext();
    }//GEN-LAST:event_findNextButtonActionPerformed
    private void findPreviousButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findPreviousButtonActionPerformed
        updateComboModel();
        .findPrevious();
    }//GEN-LAST:event_findPreviousButtonActionPerformed
    private void findPreviousButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_findPreviousButtonMouseEntered
        processMouseEvent(evttrue);
    }//GEN-LAST:event_findPreviousButtonMouseEntered
    private void findPreviousButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_findPreviousButtonMouseExited
        processMouseEvent(evtfalse);
    }//GEN-LAST:event_findPreviousButtonMouseExited
    private void findNextButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_findNextButtonMouseEntered
        processMouseEvent(evttrue);
    }//GEN-LAST:event_findNextButtonMouseEntered
    private void findNextButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_findNextButtonMouseExited
        processMouseEvent(evtfalse);
    }//GEN-LAST:event_findNextButtonMouseExited
    private void processMouseEvent(MouseEvent evtboolean over) {
        Object src = evt.getSource();
        if (src instanceof JButton) {
            JButton button = (JButton)src;
            button.setContentAreaFilled(over);
            button.setBorderPainted(over);
        }
    }
    private void updateComboModel() {
        String pattern = getPattern();
        int idx = -1;
        for (int i=0; i<.getSize(); i++) {
            if (pattern.equals(.getElementAt(i))) {
                idx = i;
            }
        }
        if (idx != 0) {
            if (idx != -1) {
                .removeElementAt(idx);
            }
            .insertElementAt(pattern, 0);
            if (.getSize() > ) {
                .removeElementAt();
            }
            .setSelectedItem(pattern);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton closeButton;
    private javax.swing.JComboBox findCombo;
    private javax.swing.JLabel findLabel;
    // End of variables declaration//GEN-END:variables
New to GrepCode? Check out our FAQ X