Skip to content

Commit

Permalink
Simplify genome selection dialog
Browse files Browse the repository at this point in the history
* Single select
* Remove "download sequence" option
  • Loading branch information
jrobinso committed Aug 20, 2024
1 parent 4a739bf commit 916c173
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 82 deletions.
41 changes: 15 additions & 26 deletions src/main/java/org/broad/igv/ui/commandbar/GenomeComboBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -223,46 +222,36 @@ public static void loadGenomeFromServer() {

Collection<GenomeListItem> 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<GenomeListItem> 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);
}
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenomeListItem> genomeList;
private JCheckBox downloadSequenceCB;
private JPanel buttonBar;
private JButton okButton;
private JButton cancelButton;
private boolean isCanceled = true;

private List<GenomeListItem> selectedValues = null;
private GenomeListItem selectedValue = null;
private List<GenomeListItem> allListItems;
private DefaultListModel genomeListModel;

Expand All @@ -74,7 +72,6 @@ public GenomeSelectionDialog(java.awt.Frame parent, Collection<GenomeListItem> i
super(parent);
initComponents();
initData(inputListItems);
downloadSequenceCB.setVisible(true);
}

private void initData(Collection<GenomeListItem> inputListItems) {
Expand All @@ -84,18 +81,12 @@ private void initData(Collection<GenomeListItem> 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();
Expand All @@ -114,27 +105,17 @@ public void run() {
* @param e
*/
private void genomeListMouseClicked(MouseEvent e) {
switch (e.getClickCount()) {
case 1:
List<GenomeListItem> selValues = genomeList.getSelectedValuesList();
downloadSequenceCB.setEnabled(selValues != null && selValues.size() == 1);
break;
case 2:
okButtonActionPerformed(null);
break;
if (e.getClickCount() == 2) {
okButtonActionPerformed(null);
}
}

private void genomeEntryKeyReleased(KeyEvent e) {
rebuildGenomeList(genomeFilter.getText());
}

public List<GenomeListItem> getSelectedValues() {
return selectedValues;
}

public boolean downloadSequence(){
return !isCanceled() && downloadSequenceCB.isEnabled() && downloadSequenceCB.isSelected();
public GenomeListItem getSelectedValue() {
return selectedValue;
}

public boolean isCanceled() {
Expand All @@ -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();
}
Expand All @@ -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();
Expand All @@ -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:");
Expand Down Expand Up @@ -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) {
Expand All @@ -246,23 +215,15 @@ 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);

//======== buttonBar ========
{
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");
Expand Down

0 comments on commit 916c173

Please sign in to comment.