Package org.netbeans.modules.php.drupaldevel.ui.searchbar

Source Code of org.netbeans.modules.php.drupaldevel.ui.searchbar.DrupalSearchUI

/*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
package org.netbeans.modules.php.drupaldevel.ui.searchbar;

import java.net.URL;
import java.net.URLEncoder;
import javax.swing.JOptionPane;
import org.netbeans.api.project.Project;
import org.netbeans.modules.php.drupaldevel.DrupalDevelPreferences;
import org.netbeans.modules.php.drupaldevel.Util;
import org.netbeans.modules.php.drupaldevel.ui.searchbar.autocomplete.AutoCompleteEvent;
import org.netbeans.modules.php.drupaldevel.ui.searchbar.autocomplete.AutoCompleteEventListener;
import org.openide.awt.HtmlBrowser;

/**
*
* @author Jamie Holly <jamie@hollyit.net>
*/
public class DrupalSearchUI extends javax.swing.JPanel {

    /**
     * Creates new form DrupalSearchUI
     */
    private String activeVersion = "";

    public DrupalSearchUI() {
        initComponents();
        setAutoComplete();

        autoComplete1.addAutoCompleteListener(new AutoCompleteEventListener() {

            @Override
            public void enterPressedEvent(AutoCompleteEvent evt) {
                try {
                    String url = "http://api.drupal.org/api/search/" + activeVersion + "/" + URLEncoder.encode(autoComplete1.getText(), "UTF-8");
                    HtmlBrowser.URLDisplayer.getDefault().showURL(new URL(url));
                } catch (Exception eee) {
                    return;//nothing much to do
                }
            }
        });

    }

    private void setAutoComplete() {

        Project proj = Util.getActiveProject();
        String version = DrupalDevelPreferences.getDefaultDrupalVersion();
        if (proj != null) {
            version = DrupalDevelPreferences.getDrupalVersion(proj);
        }
        if (activeVersion.equals(version) || version.equals("")) {
            return;
        }
        activeVersion = version;
        jLabel1.setText("Drupal " + version);
       
        autoComplete1.setWordFile(DrupalDevelPreferences.libraryInstallPath() + "/search/" + version + ".txt");

    }

    /** 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() {

        autoComplete1 = new org.netbeans.modules.php.drupaldevel.ui.searchbar.autocomplete.AutoComplete();
        jLabel1 = new javax.swing.JLabel();

        autoComplete1.setText(org.openide.util.NbBundle.getMessage(DrupalSearchUI.class, "DrupalSearchUI.autoComplete1.text")); // NOI18N
        autoComplete1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                autoComplete1FocusGained(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/php/drupaldevel/drupal.png"))); // NOI18N
        jLabel1.setText(org.openide.util.NbBundle.getMessage(DrupalSearchUI.class, "DrupalSearchUI.jLabel1.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 10, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(autoComplete1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(autoComplete1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel1))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void autoComplete1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_autoComplete1FocusGained
        setAutoComplete();
    }//GEN-LAST:event_autoComplete1FocusGained
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.netbeans.modules.php.drupaldevel.ui.searchbar.autocomplete.AutoComplete autoComplete1;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of org.netbeans.modules.php.drupaldevel.ui.searchbar.DrupalSearchUI

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.