Example usage for javax.swing JList isSelectionEmpty

List of usage examples for javax.swing JList isSelectionEmpty

Introduction

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

Prototype

@BeanProperty(bound = false)
public boolean isSelectionEmpty() 

Source Link

Document

Returns true if nothing is selected, else false .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);

    boolean anySelected = !list.isSelectionEmpty();

}

From source file:SplitPaneDemo2.java

public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting())
        return;/*ww  w .j  a va 2s .  c  o  m*/

    JList theList = (JList) e.getSource();
    if (theList.isSelectionEmpty()) {
        label.setText("Nothing selected.");
    } else {
        int index = theList.getSelectedIndex();
        label.setText("Selected image number " + index);
    }
}

From source file:SplitPaneDemo2.java

public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting())
        return;//from w w w  .  j a  v  a2s .  c  o  m

    JList theList = (JList) e.getSource();
    if (theList.isSelectionEmpty()) {
        picture.setIcon(null);
        picture.setText(null);
    } else {
        int index = theList.getSelectedIndex();
        ImageIcon newImage = createImageIcon("images/" + (String) imageNames.elementAt(index));
        picture.setIcon(newImage);
        if (newImage != null) {
            picture.setText(null);
        } else {
            picture.setText("Image not found: " + (String) imageNames.elementAt(index));
        }
    }
}

From source file:latexstudio.editor.DbxFileActions.java

/**
 * Shows a .tex files list from user's dropbox and opens the selected one
 *
 * @return List, that contatins user's .tex files from his dropbox; can be
 * empty/*  w  w  w .j  ava2s.  com*/
 */
public void openFromDropbox(DropboxRevisionsTopComponent drtc, RevisionDisplayTopComponent revtc) {
    List<DbxEntryDto> dbxEntries = getDbxTexEntries(DbxUtil.getDbxClient());

    if (!dbxEntries.isEmpty()) {
        JList<DbxEntryDto> list = new JList(dbxEntries.toArray());
        list.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
        int option = JOptionPane.showConfirmDialog(null, list, "Open file from Dropbox",
                JOptionPane.OK_CANCEL_OPTION);

        if (option == JOptionPane.OK_OPTION && !list.isSelectionEmpty()) {
            DbxEntryDto entry = list.getSelectedValue();
            String localPath = ApplicationUtils.getAppDirectory() + File.separator + entry.getName();
            File outputFile = DbxUtil.downloadRemoteFile(entry, localPath);

            revtc.close();

            drtc.updateRevisionsList(entry.getPath());
            drtc.open();
            drtc.requestActive();

            String content = FileService.readFromFile(outputFile.getAbsolutePath());
            etc.setEditorContent(content);
            etc.setCurrentFile(outputFile);
            etc.setDbxState(new DbxState(entry.getPath(), entry.getRevision()));
            etc.setModified(false);
            etc.setPreviewDisplayed(false);
        }
    } else {
        JOptionPane.showMessageDialog(etc, "No .tex files found!", "Error", JOptionPane.ERROR_MESSAGE);
    }
}

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

/**
 * /*from www  .j a  v  a2  s . c o  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:edu.ku.brc.specify.config.ResourceImportExportDlg.java

/**
 * Enables the Import / Export and Revert Buttons
 *///from  w ww.  jav  a 2 s .c  o m
protected void enableUI() {
    int currentTabIndex = tabbedPane.getModel().getSelectedIndex();

    if (currentTabIndex == 0) // Views
    {
        boolean enable = !viewSetsList.isSelectionEmpty();

        importBtn.setEnabled(enable && levelCBX.getSelectedIndex() < 5);
        exportBtn.setEnabled(enable && viewSetsModel.size() > 0);

        if (viewSetsList.getSelectedValue() instanceof SpViewSetObj) {
            SpViewSetObj vso = (SpViewSetObj) viewSetsList.getSelectedValue();
            revertBtn.setEnabled(vso != null && vso.getId() != null);
        } else {
            revertBtn.setEnabled(false);
        }

    } else if (currentTabIndex != -1) {

        JList activeList = tabbedPane.getSelectedComponent() == resPanel ? resList : repList;
        if (activeList.getSelectedValue() instanceof String) {
            importBtn.setEnabled(true);
            exportBtn.setEnabled(false);
            revertBtn.setEnabled(false);

        } else {
            boolean hasOthersTab = tabbedPane.getTabCount() > 2;
            boolean enable = !activeList.isSelectionEmpty();
            int numItems = ((DefaultListModel) activeList.getModel()).size();

            importBtn.setEnabled(enable && (levelCBX.getSelectedIndex() < 2 || (numItems > 1 && hasOthersTab)));
            exportBtn.setEnabled(enable && numItems > 1);

            SpAppResource appRes = (SpAppResource) activeList.getSelectedValue();
            enable = false;
            if (appRes != null && appRes.getId() != null) {
                if (appRes.getMimeType() != null && (appRes.getMimeType().equals(ReportsBaseTask.REPORTS_MIME)
                        || appRes.getMimeType().equals(ReportsBaseTask.LABELS_MIME))) {
                    //if (!isSpReportResource((SpAppResource )appRes))
                    {
                        //XXX what if appres is imported report with no config file???
                        enable = true;

                        //revert not currently working
                    }

                } else {
                    enable = true;
                }
            }
            revertBtn.setEnabled(enable);
        }
    }

}