Package org.gephi.desktop.spigot

Source Code of org.gephi.desktop.spigot.SpigotVisualPanel1

/*
Copyright 2008-2010 Gephi
Authors : Yi Du <duyi001@gmail.com>
Website : http://www.gephi.org

This file is part of Gephi.

Gephi is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Gephi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Gephi.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.gephi.desktop.spigot;

import javax.swing.DefaultListModel;
import javax.swing.JPanel;
import javax.swing.ListModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.gephi.io.importer.spi.ImporterWizardUI;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;

public final class SpigotVisualPanel1 extends JPanel implements ChangeListener {

    private DefaultListModel subTypeModel = new DefaultListModel();

    public SpigotVisualPanel1() {
        initComponents();
        reloadDescription();
    }

    @Override
    public String getName() {
        return NbBundle.getMessage(SpigotVisualPanel1.class, "SpigotVisualPanel1.title");
    }

    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelCategory = new javax.swing.JLabel();
        labelSpigot = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        categoryList = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        spigotList = new javax.swing.JList();
        labelDescription = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        descriptionArea = new javax.swing.JTextArea();

        setMaximumSize(new java.awt.Dimension(500, 360));
        setMinimumSize(new java.awt.Dimension(500, 360));
        setPreferredSize(new java.awt.Dimension(500, 360));

        org.openide.awt.Mnemonics.setLocalizedText(labelCategory, org.openide.util.NbBundle.getMessage(SpigotVisualPanel1.class, "SpigotVisualPanel1.labelCategory.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(labelSpigot, org.openide.util.NbBundle.getMessage(SpigotVisualPanel1.class, "SpigotVisualPanel1.labelSpigot.text")); // NOI18N

        categoryList.setModel(getCategoryListModel());
        categoryList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        categoryList.setSelectedIndex(0);
        categoryList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                categoryListValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(categoryList);

        spigotList.setModel(reloadSubType());
        spigotList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        spigotList.setSelectedIndex(0);
        spigotList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                spigotListValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(spigotList);

        org.openide.awt.Mnemonics.setLocalizedText(labelDescription, org.openide.util.NbBundle.getMessage(SpigotVisualPanel1.class, "SpigotVisualPanel1.labelDescription.text")); // NOI18N

        descriptionArea.setColumns(20);
        descriptionArea.setRows(5);
        jScrollPane3.setViewportView(descriptionArea);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelCategory, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(55, 55, 55)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(labelSpigot)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 175, Short.MAX_VALUE))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)))
                    .addComponent(labelDescription))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelCategory)
                    .addComponent(labelSpigot))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelDescription)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void categoryListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_categoryListValueChanged
        reloadSubType();
        if (spigotList.getSelectedValue() == null) {
            descriptionArea.setText("");
        }
        spigotList.setSelectedIndex(0);
    }//GEN-LAST:event_categoryListValueChanged

    private void spigotListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_spigotListValueChanged
        reloadDescription();
    }//GEN-LAST:event_spigotListValueChanged
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList categoryList;
    private javax.swing.JTextArea descriptionArea;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel labelCategory;
    private javax.swing.JLabel labelDescription;
    private javax.swing.JLabel labelSpigot;
    private javax.swing.JList spigotList;
    // End of variables declaration//GEN-END:variables

    public String getCurrentCategory() {
        return categoryList.getSelectedValue().toString();
    }

    public String getCurrentSpigot() {
        return spigotList.getSelectedValue().toString();
    }

    private ListModel getCategoryListModel() {
        DefaultListModel model = new DefaultListModel();
        for (ImporterWizardUI wizardUi : Lookup.getDefault().lookupAll(ImporterWizardUI.class)) {
            if (!model.contains(wizardUi.getCategory())) {
                model.addElement(wizardUi.getCategory());
            }
        }
        return model;
    }

    private ListModel reloadSubType() {
        subTypeModel.clear();
        if (categoryList.getSelectedValue() == null) {
            return subTypeModel;
        }
        String category = categoryList.getSelectedValue().toString();

        for (ImporterWizardUI wizardUi : Lookup.getDefault().lookupAll(ImporterWizardUI.class)) {
            if (category.equals(wizardUi.getCategory())) {
                subTypeModel.addElement(wizardUi.getDisplayName());
                descriptionArea.setText(wizardUi.getDescription());
            }
        }
        return subTypeModel;
    }

    private void reloadDescription() {
        if (emptyList()) {
            return;
        }
        String category = categoryList.getSelectedValue().toString();
        String spigot = spigotList.getSelectedValue().toString();

        for (ImporterWizardUI wizardUi : Lookup.getDefault().lookupAll(ImporterWizardUI.class)) {
            if (category.equals(wizardUi.getCategory()) && spigot.equals(wizardUi.getDisplayName())) {
                descriptionArea.setText(wizardUi.getDescription());
            }
        }
    }

    boolean emptyList() {
        if (categoryList.getSelectedValue() == null
                || spigotList.getSelectedValue() == null) {
            return true;
        } else {
            return false;
        }
    }

    public void stateChanged(ChangeEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
TOP

Related Classes of org.gephi.desktop.spigot.SpigotVisualPanel1

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.