Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-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 2008 Sun Microsystems, Inc.
  */
 
 package org.netbeans.modules.bugtracking.ui.search;
 
 import java.awt.Color;
Quick search toolbar component

Author(s):
Jan Becicka
Tomas Stupka
 
 public class QuickSearchComboBar extends javax.swing.JPanel {
 
     private QuickSearchPopup displayer;
     private Color origForeground;
     private JPanel caller;    
 
     public static final String EVT_ISSUE_CHANGED = "QuickSearchComboBar.issue.changed"// NOI18N
 
     public QuickSearchComboBar(JPanel caller) {
         this. = caller;
         initComponents();
         .setRenderer(new DefaultListCellRenderer() {
             @Override
             public Component getListCellRendererComponent(JList listObject valueint indexboolean isSelectedboolean cellHasFocus) {
                 if(value instanceof Issue) {
                     Issue item = (Issuevalue;
                     value = IssueItem.getIssueDescription(item);
                 }
                 return super.getListCellRendererComponent(listvalueindexisSelectedcellHasFocus);
             }
         });
         .setEditor(new ComboEditor(.getEditor()));
          = new QuickSearchPopup(this);
     }
 
     @Override
     public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
    }
    @Override
    public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
        getChangeSupport().addPropertyChangeListener(listener);
    }
    public Issue getIssue() {
        return (Issue.getEditor().getItem();
    }
    public void setRepository(Repository repo) {
        .setRepository(repo);
        Collection<Issueissues = BugtrackingManager.getInstance().getRecentIssues(repo);
        .setModel(new DefaultComboBoxModel(issues.toArray(new Issue[issues.size()])));
        .setSelectedItem(null);
    }
    void setIssue(Issue issue) {
        if(issue != null) {
            .getEditor().setItem(issue);
            .setVisible(false);
        }
    }

    
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.JComboBox();
        setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        setMaximumSize(new java.awt.Dimension(200, 2147483647));
        setName("Form"); // NOI18N
        setOpaque(false);
        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                formFocusLost(evt);
            }
        });
        .setEditable(true);
        .setName("command"); // NOI18N
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(, 0, 353, .)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents
    private void formFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusLost
        .setVisible(false);
    }//GEN-LAST:event_formFocusLost
    private void returnFocus () {
        .setVisible(false);
        if ( != null) {
            .requestFocus();
        }
    }
    public void enableFields(boolean enable) {
        .setEnabled(enable);
    }

    
Actually invokes action selected in the results list
    public void invokeSelectedItem () {
        JList list = .getList();
        if (list.getModel().getSize() > 0) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JList l = .getList();
                    if (l.getSelectedIndex() == -1) { // Issue 161447
                        l.setSelectedIndex(l.getModel().getSize()-1);
                    }
                    .invoke();
                }
            });
        }
    }
        if( == null) {
             = new PropertyChangeSupport(this);
        }
        return ;
    }
    public void setNoResults (boolean areNoResults) {
        // no op when called too soon
        if ( == null ||  == null) {
            return;
        }
        // don't alter color if showing hint already
            return;
        }
        .setForeground(areNoResults ? . : );
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox command;
    // End of variables declaration//GEN-END:variables
    @Override
    public void requestFocus() {
        super.requestFocus();
        .requestFocus();
    }
    public Component getIssueComponent() {
        return ;
    }
    String getText() {
        return ((JTextField).getEditor().getEditorComponent()).getText();
    }
    static Color getPopupBorderColor () {
        Color shadow = UIManager.getColor("controlShadow"); // NOI18N
        return shadow != null ? shadow : .;
    }
    static Color getTextBackground () {
        Color textB = UIManager.getColor("TextPane.background"); // NOI18N
        return textB != null ? textB : .;
    }
    static Color getResultBackground () {
        return getTextBackground();
    }
    boolean isTextFieldFocusOwner() {
        return .getEditor().getEditorComponent().isFocusOwner();
    }
    private class ComboEditor implements ComboBoxEditor {
        private final JTextField editor;
        private Issue issue;
        private boolean ignoreCommandChanges = false;
        private final ComboBoxEditor delegate;
        public ComboEditor(ComboBoxEditor delegate) {
            this. = delegate;
             = (JTextFielddelegate.getEditorComponent();
            .getDocument().addDocumentListener(new DocumentListener() {
                public void insertUpdate(DocumentEvent arg0) {
                    textChanged();
                }
                public void removeUpdate(DocumentEvent arg0) {
                    textChanged();
                }
                public void changedUpdate(DocumentEvent arg0) {
                    textChanged();
                }
                private void textChanged () {
                    if() {
                        return;
                    }
                    if (isTextFieldFocusOwner()) {
                        if(!.getText().equals("")) {
                            .hidePopup();
                        }
                        .maybeEvaluate(.getText());
                    }
                    setItem(nulltrue);
                }
            });
            .addKeyListener(new java.awt.event.KeyAdapter() {
                @Override
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    commandKeyPressed(evt);
                }
            });
        }
        public Component getEditorComponent() {
            return ;
        }
        private void setItem(Object anObjectboolean keepText) {
            Issue oldIssue = ;
            if(anObject == null) {
                 = null;
                if(!keepText) {
                    .setText("");
                }
            } else if(anObject instanceof Issue) {
                 = (IssueanObject;
                 = true;
                if(!keepText) {
                    .setText(IssueItem.getIssueDescription());
                }
                 = false;
            }
            if(oldIssue != null ||  != null) {
                getChangeSupport().firePropertyChange(oldIssue);
            }
        }
        public void setItem(Object anObject) {
            setItem(anObjectfalse);
        }
        public Object getItem() {
            return ;
        }
        public void selectAll() {
            .selectAll();
        }
        public void addActionListener(ActionListener l) {
            .addActionListener(l);
        }
        public void removeActionListener(ActionListener l) {
            .removeActionListener(l);
        }
        private void commandKeyPressed(java.awt.event.KeyEvent evt) {
            if (evt.getKeyCode()==.) {
                if(.isVisible()) {
                    .selectNext();
                    evt.consume();
                }
            } else if (evt.getKeyCode() == .) {
                if(.isVisible()) {
                    .selectPrev();
                    evt.consume();
                }
            } else if (evt.getKeyCode() == .) {
                if(.isVisible()) {
                    evt.consume();
                    invokeSelectedItem();
                }
            } else if ((evt.getKeyCode()) == .) {
                if(.isVisible()) {
                    returnFocus();
                    .clearModel();
                    evt.consume();
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X