From 916c1739db3fa90c96cc3c813524d8254ec309e2 Mon Sep 17 00:00:00 2001 From: jrobinso <933148+jrobinso@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:21:24 -0700 Subject: [PATCH] Simplify genome selection dialog * Single select * Remove "download sequence" option --- .../igv/ui/commandbar/GenomeComboBox.java | 41 ++++------- .../ui/commandbar/GenomeSelectionDialog.java | 73 +++++-------------- 2 files changed, 32 insertions(+), 82 deletions(-) diff --git a/src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java b/src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java index 96302500c3..9bb1fedafe 100644 --- a/src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java +++ b/src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java @@ -10,7 +10,6 @@ import org.broad.igv.ui.IGV; import org.broad.igv.ui.UIConstants; import org.broad.igv.ui.util.MessageUtils; -import org.broad.igv.ui.util.ProgressBar; import org.broad.igv.ui.util.UIUtilities; import org.broad.igv.util.LongRunningTask; @@ -223,46 +222,36 @@ public static void loadGenomeFromServer() { Collection inputListItems = GenomeListManager.getInstance().getServerGenomeList(); if (inputListItems == null) { - //Could not reach genome server. Not necessary to display a message, getServerGenomeArchiveList does it already return; } GenomeSelectionDialog dialog = new GenomeSelectionDialog(IGV.getInstance().getMainFrame(), inputListItems); UIUtilities.invokeAndWaitOnEventThread(() -> dialog.setVisible(true)); if (dialog.isCanceled()) { - // Clear the "More..." selection in pulldown IGVEventBus.getInstance().post(new GenomeResetEvent()); } else { - List selectedValueList = dialog.getSelectedValues(); - GenomeListItem firstItem = null; - for (GenomeListItem selectedValue : selectedValueList) { + GenomeListItem selectedValue = dialog.getSelectedValue(); if (selectedValue != null) { - boolean success = GenomeManager.getInstance().downloadGenome(selectedValue, dialog.downloadSequence()); - if (success) { + + try { + GenomeManager.getInstance().loadGenome(selectedValue.getPath()); + GenomeListManager.getInstance().addServerGenomeItem(selectedValue); - firstItem = selectedValue; - } - } - } - if (firstItem != null) { - try { - GenomeManager.getInstance().loadGenome(firstItem.getPath()); - // If the user has previously defined this genome, remove it. - GenomeListManager.getInstance().removeUserDefinedGenome(firstItem.getId()); + GenomeListManager.getInstance().removeUserDefinedGenome(selectedValue.getId()); - // If this is a .json genome, attempt to remove existing .genome files - if(firstItem.getPath().endsWith(".json")) { - removeDotGenomeFile(firstItem.getId()); - } + // If this is a .json genome, attempt to remove existing .genome files + if(selectedValue.getPath().endsWith(".json")) { + removeDotGenomeFile(selectedValue.getId()); + } + } catch (IOException e) { + GenomeListManager.getInstance().removeGenomeListItem(selectedValue); + MessageUtils.showErrorMessage("Error loading genome " + selectedValue.getDisplayableName(), e); + log.error("Error loading genome " + selectedValue.getDisplayableName(), e); + } - } catch (IOException e) { - GenomeListManager.getInstance().removeGenomeListItem(firstItem); - MessageUtils.showErrorMessage("Error loading genome " + firstItem.getDisplayableName(), e); - log.error("Error loading genome " + firstItem.getDisplayableName(), e); } - } } }; diff --git a/src/main/java/org/broad/igv/ui/commandbar/GenomeSelectionDialog.java b/src/main/java/org/broad/igv/ui/commandbar/GenomeSelectionDialog.java index baa3cc6bf0..4b4d9cbdf0 100644 --- a/src/main/java/org/broad/igv/ui/commandbar/GenomeSelectionDialog.java +++ b/src/main/java/org/broad/igv/ui/commandbar/GenomeSelectionDialog.java @@ -47,23 +47,21 @@ * Dialog box for selecting genomes. User can choose from a list, * which is filtered according to text box input */ -public class GenomeSelectionDialog extends org.broad.igv.ui.IGVDialog { +public class GenomeSelectionDialog extends org.broad.igv.ui.IGVDialog { private JPanel dialogPane; private JPanel contentPanel; - private JTextArea textArea1; private JPanel filterPanel; private JLabel label1; private JTextField genomeFilter; private JScrollPane scrollPane1; private JList genomeList; - private JCheckBox downloadSequenceCB; private JPanel buttonBar; private JButton okButton; private JButton cancelButton; private boolean isCanceled = true; - private List selectedValues = null; + private GenomeListItem selectedValue = null; private List allListItems; private DefaultListModel genomeListModel; @@ -74,7 +72,6 @@ public GenomeSelectionDialog(java.awt.Frame parent, Collection i super(parent); initComponents(); initData(inputListItems); - downloadSequenceCB.setVisible(true); } private void initData(Collection inputListItems) { @@ -84,18 +81,12 @@ private void initData(Collection inputListItems) { } /** - * Filter the list of displayed genomes so we only show this - * with the text the user entered. + * Filter the list of displayed genomes with the text the user entered. */ private void rebuildGenomeList(String filterText) { if (genomeListModel == null) { genomeListModel = new DefaultListModel(); - UIUtilities.invokeOnEventThread(new Runnable() { - @Override - public void run() { - genomeList.setModel(genomeListModel); - } - }); + UIUtilities.invokeOnEventThread(() -> genomeList.setModel(genomeListModel)); } genomeListModel.clear(); filterText = filterText.toLowerCase().trim(); @@ -114,14 +105,8 @@ public void run() { * @param e */ private void genomeListMouseClicked(MouseEvent e) { - switch (e.getClickCount()) { - case 1: - List selValues = genomeList.getSelectedValuesList(); - downloadSequenceCB.setEnabled(selValues != null && selValues.size() == 1); - break; - case 2: - okButtonActionPerformed(null); - break; + if (e.getClickCount() == 2) { + okButtonActionPerformed(null); } } @@ -129,12 +114,8 @@ private void genomeEntryKeyReleased(KeyEvent e) { rebuildGenomeList(genomeFilter.getText()); } - public List getSelectedValues() { - return selectedValues; - } - - public boolean downloadSequence(){ - return !isCanceled() && downloadSequenceCB.isEnabled() && downloadSequenceCB.isSelected(); + public GenomeListItem getSelectedValue() { + return selectedValue; } public boolean isCanceled() { @@ -143,14 +124,14 @@ public boolean isCanceled() { private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed isCanceled = true; - selectedValues = null; + selectedValue = null; setVisible(false); dispose(); } private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed isCanceled = false; - selectedValues = genomeList.getSelectedValuesList(); + selectedValue = genomeList.getSelectedValue(); setVisible(false); dispose(); } @@ -159,13 +140,11 @@ private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS private void initComponents() { dialogPane = new JPanel(); contentPanel = new JPanel(); - textArea1 = new JTextArea(); filterPanel = new JPanel(); label1 = new JLabel(); genomeFilter = new JTextField(); scrollPane1 = new JScrollPane(); genomeList = new JList(); - downloadSequenceCB = new JCheckBox(); buttonBar = new JPanel(); okButton = new JButton(); cancelButton = new JButton(); @@ -186,25 +165,15 @@ private void initComponents() { { contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); - //---- textArea1 ---- - textArea1.setText("Selected genomes will be downloaded and added to the genome dropdown list."); - textArea1.setLineWrap(true); - textArea1.setWrapStyleWord(true); - textArea1.setBackground(UIManager.getColor("Button.background")); - textArea1.setRows(2); - textArea1.setMaximumSize(new Dimension(2147483647, 60)); - textArea1.setRequestFocusEnabled(false); - textArea1.setEditable(false); - contentPanel.add(textArea1); //======== filterPanel ======== { filterPanel.setMaximumSize(new Dimension(2147483647, 28)); filterPanel.setLayout(new GridBagLayout()); - ((GridBagLayout)filterPanel.getLayout()).columnWidths = new int[] {0, 0, 0}; - ((GridBagLayout)filterPanel.getLayout()).rowHeights = new int[] {0, 0}; - ((GridBagLayout)filterPanel.getLayout()).columnWeights = new double[] {1.0, 1.0, 1.0E-4}; - ((GridBagLayout)filterPanel.getLayout()).rowWeights = new double[] {1.0, 1.0E-4}; + ((GridBagLayout) filterPanel.getLayout()).columnWidths = new int[]{0, 0, 0}; + ((GridBagLayout) filterPanel.getLayout()).rowHeights = new int[]{0, 0}; + ((GridBagLayout) filterPanel.getLayout()).columnWeights = new double[]{1.0, 1.0, 1.0E-4}; + ((GridBagLayout) filterPanel.getLayout()).rowWeights = new double[]{1.0, 1.0E-4}; //---- label1 ---- label1.setText("Filter:"); @@ -235,7 +204,7 @@ public void keyReleased(KeyEvent e) { { //---- genomeList ---- - //genomeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + genomeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); genomeList.addMouseListener(new IGVMouseInputAdapter() { @Override public void igvMouseClicked(MouseEvent e) { @@ -246,14 +215,6 @@ public void igvMouseClicked(MouseEvent e) { } contentPanel.add(scrollPane1); - //---- downloadSequenceCB ---- - downloadSequenceCB.setText("Download Sequence"); - downloadSequenceCB.setAlignmentX(1.0F); - downloadSequenceCB.setToolTipText("Download the full sequence for this organism. Note that these files can be very large (human is about 3 gigabytes)"); - downloadSequenceCB.setMaximumSize(new Dimension(1000, 23)); - downloadSequenceCB.setPreferredSize(new Dimension(300, 23)); - downloadSequenceCB.setMinimumSize(new Dimension(300, 23)); - contentPanel.add(downloadSequenceCB); } dialogPane.add(contentPanel, BorderLayout.CENTER); @@ -261,8 +222,8 @@ public void igvMouseClicked(MouseEvent e) { { buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); buttonBar.setLayout(new GridBagLayout()); - ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; - ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; + ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[]{0, 85, 80}; + ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[]{1.0, 0.0, 0.0}; //---- okButton ---- okButton.setText("OK");