Example usage for javax.swing JList addListSelectionListener

List of usage examples for javax.swing JList addListSelectionListener

Introduction

In this page you can find the example usage for javax.swing JList addListSelectionListener.

Prototype

public void addListSelectionListener(ListSelectionListener listener) 

Source Link

Document

Adds a listener to the list, to be notified each time a change to the selection occurs; the preferred way of listening for selection state changes.

Usage

From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java

/**
 * /*from  w  w w  . j av a 2  s  .co m*/
 */
private void removeDataset() {
    Institution inst = iPadDBExporter.getCurrentInstitution();
    List<Pair<String, String>> list = iPadCloud.getDatasetList(inst.getGuid());
    if (list != null && list.size() > 0) {
        CellConstraints cc = new CellConstraints();

        final JList<String> dsList = new JList<String>(new DSListModel(list));
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,4px,f:p:g"));
        pb.add(UIHelper.createI18NLabel("Choose a Dataset to remove"), cc.xy(1, 1));
        pb.add(dsList, cc.xy(1, 3));
        pb.setDefaultDialogBorder();
        final CustomDialog dlg = new CustomDialog((Frame) getMostRecentWindow(), "Remove Collection", true,
                pb.getPanel());
        dsList.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    dlg.getOkBtn().setEnabled(!dsList.isSelectionEmpty());
                }
            }
        });
        dlg.setPreferredSize(new Dimension(300, 400));
        dlg.createUI();
        dlg.getOkBtn().setEnabled(false);
        centerAndShow(dlg, 300, 400);
        if (!dlg.isCancelled()) {
            String collectionGUID = list.get(dsList.getSelectedIndex()).first;
            if (StringUtils.isNotEmpty(collectionGUID)) {
                if (iPadCloud.removeDataSet(collectionGUID)) {
                    enableRemoveDatasetBtn();
                    UIRegistry.writeTimedSimpleGlassPaneMsg("The dataset was removed.");
                } else {
                    UIRegistry.writeTimedSimpleGlassPaneMsg("The dataset was not removed.");
                }
            }
        }
        return;
    }
    UIRegistry.showError("You do not have Datasets to remove."); // should not get here
}

From source file:kenh.xscript.elements.Debug.java

private void initial(Container c) {
    c.setLayout(new BorderLayout());

    // Add variable list

    DefaultListModel<String> model = new DefaultListModel();

    if (this.getEnvironment() != null) {
        java.util.Set<String> keys = this.getEnvironment().getVariables().keySet();
        for (String key : keys) {
            model.addElement(key);//from   w w w .  ja va2s . com
        }
    } else {
        for (int i = 1; i < 10; i++) {
            model.addElement("Variable " + i);
        }
        model.addElement("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }

    JList list = new JList(model);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane listPane = new JScrollPane();
    listPane.setViewportView(list);
    listPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    c.add(listPane, BorderLayout.EAST);

    list.setPreferredSize(new Dimension(150, list.getPreferredSize().height));

    // 

    JTextField quote = new JTextField();
    quote.requestFocus();

    //JButton button = new JButton(">>");

    JPanel quotePanel = new JPanel();
    quotePanel.setLayout(new BorderLayout());
    quotePanel.add(quote, BorderLayout.CENTER);
    //quotePanel.add(button, BorderLayout.EAST);

    JTextArea result = new JTextArea();
    result.setEditable(false);

    JScrollPane resultPane = new JScrollPane();
    resultPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    resultPane.setViewportView(result);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(quotePanel, BorderLayout.NORTH);
    panel.add(resultPane, BorderLayout.CENTER);

    c.add(panel, BorderLayout.CENTER);

    list.addListSelectionListener(this);
    //button.addActionListener(this);
    quote.addKeyListener(this);

    this.result = result;
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * @return/*from   w  w w  .j  a v a2  s  . com*/
 */
private JPanel getStatsPane(final String chartPrefixTitle, final Collection<RegProcEntry> entries,
        final String tableName) {
    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g"));

    final Hashtable<String, String> keyDescPairsHash = rp.getAllDescPairsHash();
    final Hashtable<String, String> desc2KeyPairsHash = new Hashtable<String, String>();
    for (String key : keyDescPairsHash.keySet()) {
        desc2KeyPairsHash.put(keyDescPairsHash.get(key), key);
    }

    Vector<String> keywords = new Vector<String>();
    for (String keyword : getKeyWordsList(entries)) {
        if (keyword.endsWith("_name") || keyword.endsWith("_type") || keyword.endsWith("ISA_Number")
                || keyword.endsWith("reg_isa")) {
            //keywords.add(keyword);

        } else {
            String desc = keyDescPairsHash.get(keyword);
            //System.out.println("["+keyword+"]->["+desc+"]");
            if (desc != null) {
                keywords.add(desc);
            } else {
                System.out.println("Desc for keyword[" + keyword + "] is null.");
            }

        }
    }
    Vector<Object[]> rvList = BasicSQLUtils
            .query("SELECT DISTINCT(Name) FROM registeritem WHERE SUBSTRING(Name, 1, 4) = 'num_'");
    for (Object[] array : rvList) {
        keywords.add((String) array[0]);
    }
    Collections.sort(keywords);

    final JList list = new JList(keywords);
    pb.add(UIHelper.createScrollPane(list), cc.xy(1, 1));

    list.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                String statName = (String) list.getSelectedValue();
                if (desc2KeyPairsHash.get(statName) != null) {
                    statName = desc2KeyPairsHash.get(statName);
                }

                DateType dateType = convertDateType(statName);
                if (dateType == DateType.None) {
                    Vector<Pair<String, Integer>> values;
                    if (statName.startsWith("num_")) {
                        values = getCollNumValuesFromList(statName);
                        Hashtable<String, Boolean> hash = new Hashtable<String, Boolean>();
                        for (Pair<String, Integer> p : values) {
                            if (hash.get(p.first) == null) {
                                hash.put(p.first, true);
                            } else {
                                int i = 0;
                                String name = p.first;
                                while (hash.get(p.first) != null) {
                                    p.first = name + " _" + i;
                                    i++;
                                }
                                hash.put(p.first, true);
                            }
                            //p.first += "(" + p.second.toString() + ")";
                        }

                    } else {
                        values = getCollValuesFromList(statName);
                    }

                    Collections.sort(values, countComparator);
                    Vector<Pair<String, Integer>> top10Values = new Vector<Pair<String, Integer>>();
                    for (int i = 1; i < Math.min(11, values.size()); i++) {
                        top10Values.insertElementAt(values.get(values.size() - i), 0);
                    }
                    createBarChart(chartPrefixTitle + " " + statName, statName, top10Values);

                } else {
                    String desc = getByDateDesc(dateType);
                    Vector<Pair<String, Integer>> values = tableName.equals("track")
                            ? getDateValuesFromListByTable(dateType, tableName)
                            : getDateValuesFromList(dateType);
                    Collections.sort(values, titleComparator);
                    createBarChart(chartPrefixTitle + " " + desc, desc, values);
                }
            }
        }
    });

    return pb.getPanel();
}

From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java

/**
 * Export data //from   w ww . j av a 2 s . co  m
 */
protected void exportSingleLocale() {
    statusBar.setText(getResourceString("SchemaLocalizerFrame.EXPORTING")); //$NON-NLS-1$
    statusBar.paintImmediately(statusBar.getBounds());

    schemaLocPanel.getAllDataFromUI();

    if (localizableIO.hasChanged()) {
        if (UIRegistry.askYesNoLocalized("SAVE", "CANCEL",
                UIRegistry.getResourceString("SchemaLocalizerFrame.NEEDS_SAVING"),
                "SAVE") == JOptionPane.YES_NO_OPTION) {
            localizableIO.save();
        } else {
            return;
        }
    }

    Vector<Locale> stdLocales = SchemaI18NService.getInstance().getStdLocaleList(false);
    final JList list = new JList(stdLocales);
    list.setCellRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                setText(((Locale) value).getDisplayName());
            }
            return this;
        }
    });

    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g"));
    pb.add(UIHelper.createScrollPane(list), (new CellConstraints()).xy(1, 1));
    pb.setDefaultDialogBorder();

    final CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(),
            getResourceString("SchemaLocalizerFrame.CHOOSE_LOCALE"), true, pb.getPanel());
    list.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                dlg.getOkBtn().setEnabled(list.getSelectedValue() != null);
            }
        }
    });
    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);

    UIHelper.centerAndShow(dlg);
    if (!dlg.isCancelled()) {
        Locale locale = (Locale) list.getSelectedValue();
        if (locale != null) {
            FileDialog fileDlg = new FileDialog((Frame) UIRegistry.getTopWindow(),
                    getResourceString("SchemaLocalizerFrame.SVFILENAME"), FileDialog.SAVE);
            fileDlg.setVisible(true);
            String fileName = fileDlg.getFile();
            if (StringUtils.isNotEmpty(fileName)) {
                File outFile = new File(fileDlg.getDirectory() + File.separator + fileName);
                boolean savedOK = localizableIO.exportSingleLanguageToDirectory(outFile, locale);
                if (savedOK) {
                    String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTEDTO",
                            locale.getDisplayName(), outFile.getAbsolutePath());
                    UIRegistry.displayInfoMsgDlg(msg);
                } else {
                    String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTING_ERR",
                            outFile.getAbsolutePath());
                    UIRegistry.showError(msg);
                }

            }
        }
    }
}

From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java

@SuppressWarnings("unchecked")
private void addRenderers() {
    try {/*from w  w  w .  ja  v  a  2s .  c o  m*/
        setDefaultRenderer(Class.forName("java.lang.Object"), new JBDefaultTableCellRenderer());
        setDefaultRenderer(Class.forName("java.util.Collection"), new CollectionRenderer());

        final JList<Object> list = new JList<Object>();
        list.setVisibleRowCount(3);
        list.setOpaque(true);
        list.setCellRenderer(new ListDefaultRenderer());

        list.addListSelectionListener(new ListSelectionListener() {
            @SuppressWarnings({ "static-access", "unused" })
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    Object obj = list.getSelectedValue();
                    obj = RegistryObjectsTable.this.convertValue(obj);

                    if (obj instanceof URL) {
                        HyperLinker.displayURL(obj.toString());
                    } else if (obj instanceof String) {
                        //Check if URL is valid
                        URL _url = null;

                        try {
                            _url = new URL(obj.toString());
                            HyperLinker.displayURL(obj.toString());
                        } catch (MalformedURLException exc) {
                            //No need to do anything. It is normal for text to not be a URL
                            _url = null;
                        }
                    }
                }
            }
        });

        JScrollPane listPane = new JScrollPane(list);
        setDefaultEditor(Class.forName("java.util.Collection"), new JBDefaultCellEditor(listPane));

        HyperLinkLabel hyperLinkLabel = new HyperLinkLabel();
        hyperLinkLabel.setHorizontalAlignment(SwingConstants.TRAILING);
        setDefaultEditor(Class.forName("java.lang.Object"), new JBDefaultCellEditor(hyperLinkLabel));
    } catch (ClassNotFoundException e) {
        return;
    }
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * //from w  ww. jav  a  2s .c o m
 */
@SuppressWarnings("unchecked")
protected void doSetVersion() {
    CellConstraints cc = new CellConstraints();

    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,2px,f:p:g"));

    Vector<String> versionsList = new Vector<String>();
    Hashtable<String, String> verToDateHash = new Hashtable<String, String>();
    try {
        SimpleDateFormat mmddyyyy = new SimpleDateFormat("MM/dd/yyyy");
        SimpleDateFormat yyyymmdd = new SimpleDateFormat("yyyy/MM/dd");
        List<String> lines = FileUtils.readLines(rp.getDataFromWeb(
                UIRegistry.getResourceString("CGI_BASE_URL") + "/specifydownloads/specify6/alpha/versions.txt",
                false));
        for (String line : lines) {
            String[] toks = line.split(",");
            if (toks.length > 2) {
                String ver = StringUtils.remove(toks[1].trim(), "Alpha ");

                versionsList.insertElementAt(ver, 0);

                String dateStr = toks[2].trim();
                dateStr = StringUtils.replace(dateStr, ".", "/");
                try {
                    Date date = mmddyyyy.parse(dateStr);
                    verToDateHash.put(ver, yyyymmdd.format(date));

                } catch (Exception ex) {
                }
            }
        }
        versionsList.insertElementAt("Clear", 0);

    } catch (IOException ex) {
        ex.printStackTrace();
    }

    final JList list = new JList(versionsList);
    final CustomDialog dlg = new CustomDialog(null, "Set Version", true, pb.getPanel());

    pb.add(UIHelper.createLabel("Versions", SwingConstants.CENTER), cc.xy(1, 1));
    pb.add(UIHelper.createScrollPane(list), cc.xy(1, 3));

    list.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                dlg.getOkBtn().setEnabled(list.getSelectedIndex() > -1);
            }
        }
    });
    list.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            if (e.getClickCount() == 2) {
                dlg.getOkBtn().doClick();
            }
        }

    });

    pb.setDefaultDialogBorder();

    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);

    dlg.setVisible(true);
    if (!dlg.isCancelled()) {
        int inx = list.getSelectedIndex();
        String version = (String) list.getSelectedValue();

        if (version.equals("Clear")) {
            rp.setVersionDates(null, null, null);
            frame.setTitle(title);
        } else {
            String prevVersion = inx == list.getModel().getSize() - 1 ? null
                    : (String) list.getModel().getElementAt(inx + 1);
            rp.setVersionDates(version, prevVersion, verToDateHash);
            frame.setTitle(title + " for " + version);
        }

        /*try
        {
        rp.process(doLocal ? new File("reg.dat") : rp.getDataFromWeb("SpReg.REGISTER_URL", true));
        rp.processTracks(doLocal ? new File("track.dat") : rp.getDataFromWeb("StatsTrackerTask.URL", true));
        rp.mergeStats();
                
        } catch (IOException ex)
        {
        ex.printStackTrace();
        }*/

    }
}

From source file:org.gumtree.vis.awt.AbstractPlotEditor.java

private JPanel createHelpPanel() {
    JPanel wrap = new JPanel(new GridLayout(1, 1));

    JPanel helpPanel = new JPanel(new GridLayout(1, 1));
    helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    //       helpPanel.setBorder(BorderFactory.createTitledBorder(
    //            BorderFactory.createEtchedBorder(), "Help Topics"));

    SpringLayout spring = new SpringLayout();
    JPanel inner = new JPanel(spring);
    inner.setBorder(BorderFactory.createEmptyBorder());

    final IHelpProvider provider = plot.getHelpProvider();
    final JList list = new JList(provider.getHelpMap().keySet().toArray());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      list.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane listPane1 = new JScrollPane(list);
    inner.add(listPane1);//ww  w .j  av  a 2  s  . com
    listPane1.setMaximumSize(new Dimension(140, 0));
    listPane1.setMinimumSize(new Dimension(70, 0));
    //      JPanel contentPanel = new JPanel(new GridLayout(2, 1));
    //      inner.add(list);
    final JTextField keyField = new JTextField();
    keyField.setMaximumSize(new Dimension(400, 20));
    keyField.setEditable(false);
    //      keyField.setMaximumSize();
    //      keyArea.setLineWrap(true);
    //      keyArea.setWrapStyleWord(true);
    //      keyArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(keyField);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    final JTextArea helpArea = new JTextArea();
    JScrollPane areaPane = new JScrollPane(helpArea);
    helpArea.setEditable(false);
    helpArea.setLineWrap(true);
    helpArea.setWrapStyleWord(true);
    //      helpArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(areaPane);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    //      inner.add(contentPanel);
    spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner);
    spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField);
    spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField);
    spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner);
    spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane);
    spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner);

    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Object[] selected = list.getSelectedValues();
            if (selected.length >= 0) {
                HelpObject help = provider.getHelpMap().get(selected[0]);
                if (help != null) {
                    keyField.setText(help.getKey());
                    helpArea.setText(help.getDiscription());
                }
            }
        }
    });

    helpPanel.add(inner, BorderLayout.NORTH);
    wrap.setName("Help");

    wrap.add(helpPanel, BorderLayout.NORTH);
    return wrap;
}

From source file:org.gumtree.vis.hist2d.Hist2DChartEditor.java

private JPanel createHelpPanel(JFreeChart chart) {
    JPanel wrap = new JPanel(new GridLayout(1, 1));

    JPanel helpPanel = new JPanel(new GridLayout(1, 1));
    helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    //       helpPanel.setBorder(BorderFactory.createTitledBorder(
    //            BorderFactory.createEtchedBorder(), "Help Topics"));

    SpringLayout spring = new SpringLayout();
    JPanel inner = new JPanel(spring);
    inner.setBorder(BorderFactory.createEmptyBorder());

    final IHelpProvider provider = new Hist2DHelpProvider();
    final JList list = new JList(provider.getHelpMap().keySet().toArray());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      list.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane listPane1 = new JScrollPane(list);
    inner.add(listPane1);//from  w w w. j  a  v a  2s .c  o m
    listPane1.setMaximumSize(new Dimension(140, 0));
    listPane1.setMinimumSize(new Dimension(70, 0));
    //      JPanel contentPanel = new JPanel(new GridLayout(2, 1));
    //      inner.add(list);
    final JTextField keyField = new JTextField();
    keyField.setMaximumSize(new Dimension(400, 20));
    keyField.setEditable(false);
    //      keyField.setMaximumSize();
    //      keyArea.setLineWrap(true);
    //      keyArea.setWrapStyleWord(true);
    //      keyArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(keyField);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    final JTextArea helpArea = new JTextArea();
    JScrollPane areaPane = new JScrollPane(helpArea);
    helpArea.setEditable(false);
    helpArea.setLineWrap(true);
    helpArea.setWrapStyleWord(true);
    //      helpArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(areaPane);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    //      inner.add(contentPanel);
    spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner);
    spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField);
    spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField);
    spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner);
    spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane);
    spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner);

    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Object[] selected = list.getSelectedValues();
            if (selected.length >= 0) {
                HelpObject help = provider.getHelpMap().get(selected[0]);
                if (help != null) {
                    keyField.setText(help.getKey());
                    helpArea.setText(help.getDiscription());
                }
            }
        }
    });

    helpPanel.add(inner, BorderLayout.NORTH);
    wrap.setName("Help");

    wrap.add(helpPanel, BorderLayout.NORTH);
    return wrap;

}

From source file:edu.ku.brc.specify.conversion.SpecifyDBConverter.java

/**
 * @return//  ww w.  j a  va2 s.c o  m
 * @throws SQLException
 */
public Pair<String, String> chooseTable(final String title, final String subTitle, final boolean doSp5DBs)
        throws SQLException {
    MySQLDMBSUserMgr mgr = new MySQLDMBSUserMgr();

    Vector<DBNamePair> availPairs = new Vector<DBNamePair>();

    if (mgr.connectToDBMS(itUsrPwd.first, itUsrPwd.second, hostName)) {
        BasicSQLUtils.setSkipTrackExceptions(true);

        //String sql = String.format("SELECT DISTINCT `COLUMNS`.TABLE_SCHEMA FROM `COLUMNS` WHERE `COLUMNS`.TABLE_NAME = '%s'", doSp5DBs ? "collectionobjectcatalog" : "taxon");
        Connection conn = mgr.getConnection();
        Vector<Object[]> dbNames = BasicSQLUtils.query(conn, "show databases");
        for (Object[] row : dbNames) {
            String dbName = row[0].toString();

            //System.out.print("Database Found ["+dbName+"]  ");
            conn.setCatalog(dbName);

            boolean isSp5DB = false;
            Vector<Object[]> tables = BasicSQLUtils.query(conn, "show tables");
            for (Object[] tblRow : tables) {
                String tableName = tblRow[0].toString();
                if (tableName.equalsIgnoreCase("usysversion")) {
                    isSp5DB = true;
                    break;
                }
            }

            if ((!isSp5DB && doSp5DBs) || (isSp5DB && !doSp5DBs)) {
                continue;
            }

            // make all table names lowercase
            try {
                Integer count = BasicSQLUtils.getCount(conn, "select COUNT(*) FROM collection");
                if (count == null) {
                    for (Object[] tblRow : tables) {
                        String tableName = tblRow[0].toString();
                        if (!tableName.equals(tableName.toLowerCase())) {
                            BasicSQLUtils.update(conn,
                                    "RENAME TABLE " + tableName + " TO " + tableName.toLowerCase());
                        }
                    }
                }

            } catch (Exception ex) {
                ex.printStackTrace();
            }

            Vector<Object> tableDesc = BasicSQLUtils.querySingleCol(conn,
                    "select CollectionName FROM collection");
            if (tableDesc.size() > 0) {
                String collName = tableDesc.get(0).toString();
                availPairs.add(new DBNamePair(collName, row[0].toString()));
            }
        }

        Collections.sort(availPairs, new Comparator<Pair<String, String>>() {
            @Override
            public int compare(Pair<String, String> o1, Pair<String, String> o2) {
                return o1.second.compareTo(o2.second);
            }
        });

        mgr.close();
        BasicSQLUtils.setSkipTrackExceptions(false);

        final JList list = new JList(availPairs);
        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,4px,f:p:g"));
        pb.add(UIHelper.createLabel(subTitle), cc.xy(1, 1));
        pb.add(UIHelper.createScrollPane(list, true), cc.xy(1, 3));
        pb.setDefaultDialogBorder();

        final CustomDialog dlg = new CustomDialog(null, title, true, pb.getPanel());
        list.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    dlg.getOkBtn().setEnabled(list.getSelectedIndex() > -1);
                }
            }
        });

        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    dlg.getOkBtn().setEnabled(list.getSelectedIndex() > -1);
                    dlg.getOkBtn().doClick();
                }
            }
        });

        dlg.createUI();
        dlg.pack();
        Dimension d = dlg.getPreferredSize();
        d.height = 700;
        dlg.setSize(d);
        UIHelper.centerAndShow(dlg);

        if (dlg.isCancelled()) {
            return null;
        }

        return namePairToConvert = (DBNamePair) list.getSelectedValue();
    }

    return null;
}

From source file:org.gumtree.vis.plot1d.Plot1DChartEditor.java

private JPanel createHelpPanel(JFreeChart chart) {
    JPanel wrap = new JPanel(new GridLayout(1, 1));

    JPanel helpPanel = new JPanel(new GridLayout(1, 1));
    helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    //       helpPanel.setBorder(BorderFactory.createTitledBorder(
    //            BorderFactory.createEtchedBorder(), "Help Topics"));

    SpringLayout spring = new SpringLayout();
    JPanel inner = new JPanel(spring);
    inner.setBorder(BorderFactory.createEmptyBorder());

    final IHelpProvider provider = new Plot1DHelpProvider();
    final JList list = new JList(provider.getHelpMap().keySet().toArray());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      list.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane listPane1 = new JScrollPane(list);
    inner.add(listPane1);//from w  w w.ja  v a  2 s.c  om
    listPane1.setMaximumSize(new Dimension(140, 0));
    listPane1.setMinimumSize(new Dimension(70, 0));
    //      JPanel contentPanel = new JPanel(new GridLayout(2, 1));
    //      inner.add(list);
    final JTextField keyField = new JTextField();
    keyField.setMaximumSize(new Dimension(400, 20));
    keyField.setEditable(false);
    //      keyField.setMaximumSize();
    //      keyArea.setLineWrap(true);
    //      keyArea.setWrapStyleWord(true);
    //      keyArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(keyField);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    final JTextArea helpArea = new JTextArea();
    JScrollPane areaPane = new JScrollPane(helpArea);
    helpArea.setEditable(false);
    helpArea.setLineWrap(true);
    helpArea.setWrapStyleWord(true);
    //      helpArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(areaPane);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    //      inner.add(contentPanel);
    spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner);
    spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField);
    spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField);
    spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner);
    spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane);
    spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner);

    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Object[] selected = list.getSelectedValues();
            if (selected.length >= 0) {
                HelpObject help = provider.getHelpMap().get(selected[0]);
                if (help != null) {
                    keyField.setText(help.getKey());
                    helpArea.setText(help.getDiscription());
                }
            }
        }
    });

    helpPanel.add(inner, BorderLayout.NORTH);
    wrap.setName("Help");

    wrap.add(helpPanel, BorderLayout.NORTH);
    return wrap;

}