Example usage for javax.swing JTabbedPane removeChangeListener

List of usage examples for javax.swing JTabbedPane removeChangeListener

Introduction

In this page you can find the example usage for javax.swing JTabbedPane removeChangeListener.

Prototype

public void removeChangeListener(ChangeListener l) 

Source Link

Document

Removes a ChangeListener from this tabbedpane.

Usage

From source file:burp.BurpExtender.java

@Override
public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks) {
    // keep a reference to our callbacks object
    this.callbacks = callbacks;

    callbacks.registerContextMenuFactory(new ContextMenuFactory(this, callbacks));

    // set our extension name
    callbacks.setExtensionName("Code Dx");

    for (int i = 0; i < refreshSpinner.length; i++)
        refreshSpinner[i] = new ImageIcon(BurpExtender.class.getResource("/" + i + ".png"));

    // create our UI
    SwingUtilities.invokeLater(new Runnable() {
        @Override//from ww  w  .j  av  a  2 s .  c o m
        public void run() {
            pane = new JScrollPane(createMainPanel());
            refreshAnimation = new ButtonAnimationThread(projectRefresh, refreshSpinner);

            callbacks.customizeUiComponent(pane);

            // add the custom tab to Burp's UI
            callbacks.addSuiteTab(BurpExtender.this);

            // add listener to update projects list when Code Dx tab selected
            Component parent = pane.getParent();
            if (parent instanceof JTabbedPane) {
                final JTabbedPane tabs = (JTabbedPane) parent;
                final ChangeListener tabChangeListener = new ChangeListener() {
                    @Override
                    public void stateChanged(ChangeEvent arg0) {
                        if (pane == tabs.getSelectedComponent() && !updating && !"".equals(serverUrl.getText())
                                && !"".equals(apiKey.getText())) {
                            Thread updateThread = new Thread() {
                                public void run() {
                                    updateTargets();
                                    updateProjects(true);
                                }
                            };
                            updateThread.start();
                        } else if (pane != tabs.getSelectedComponent()) {
                            NameValuePair project = getProject();
                            if (project != null)
                                callbacks.saveExtensionSetting(BurpExtender.PROJECT_KEY, project.getValue());
                        }
                    }

                };
                tabs.addChangeListener(tabChangeListener);
                //Remove the change listener when the extension is unloaded
                callbacks.registerExtensionStateListener(new IExtensionStateListener() {
                    @Override
                    public void extensionUnloaded() {
                        tabs.removeChangeListener(tabChangeListener);
                    }
                });
            }
        }
    });
}