From 57c323c357199f78a812adb4d63290a3347f4097 Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Fri, 17 Nov 2017 17:57:31 +0000 Subject: [PATCH] JAL-281 option pane with error handling for selecting an URL --- resources/lang/Messages.properties | 4 +- src/jalview/ext/archaeopteryx/AptxInit.java | 3 +- src/jalview/ext/archaeopteryx/AptxTreeBuilder.java | 5 ++- .../ext/archaeopteryx/LoadedTreeAssociation.java | 6 +-- src/jalview/ext/forester/io/TreeParser.java | 3 +- .../ext/treeviewer/ExternalTreeBuilderI.java | 26 ----------- .../ext/treeviewer/ExternalTreeParserI.java | 11 ++--- src/jalview/gui/AlignFrame.java | 46 ++++++++++++++++++-- src/jalview/gui/Desktop.java | 5 ++- src/jalview/jbgui/GAlignFrame.java | 8 ++-- src/jalview/util/MappingUtils.java | 19 ++++++++ 11 files changed, 87 insertions(+), 49 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 7a7bfbf..3c69dcd 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -388,6 +388,8 @@ label.selected_region_to_tree_may_only_contain_residues_or_gaps = The selected label.sequences_selection_not_aligned = Sequences in selection are not aligned label.problem_reading_tree_file = Problem reading tree file label.possible_problem_with_tree_file = Possible problem with tree file +label.tree_url_example = Please enter a complete URL, \"for example http://purl.org/phylo/treebase/phylows/study/TB2:S15480?format=nexus\" +label.load_tree_url = Tree from URL label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation = Please select at least three bases in at least one sequence in order to perform a cDNA translation. label.translation_failed = Translation Failed label.error_when_translating_sequences_submit_bug_report = Unfortunately, something went wrong when translating your sequences.\nPlease take a look in the Jalview java console\nand submit a bug report including the stacktrace. @@ -417,7 +419,7 @@ label.input_alignment_from_url = Input Alignment From URL label.input_alignment = Input Alignment label.couldnt_import_as_vamsas_session = Couldn't import {0} as a new vamsas session. label.vamsas_document_import_failed = Vamsas Document Import Failed -label.couldnt_locate = Couldn't locate {0} +label.couldnt_locate = Could not locate {0} label.url_not_found = URL not found label.new_sequence_url_link = New sequence URL link label.cannot_edit_annotations_in_wrapped_view = Cannot edit annotations in wrapped view diff --git a/src/jalview/ext/archaeopteryx/AptxInit.java b/src/jalview/ext/archaeopteryx/AptxInit.java index 817fef3..107aeca 100644 --- a/src/jalview/ext/archaeopteryx/AptxInit.java +++ b/src/jalview/ext/archaeopteryx/AptxInit.java @@ -8,6 +8,7 @@ import jalview.gui.Desktop; import jalview.viewmodel.AlignmentViewport; import java.awt.Dimension; +import java.net.URL; import java.util.Map; import org.forester.archaeopteryx.Archaeopteryx; @@ -93,7 +94,7 @@ public final class AptxInit return bindFrameToJalview(aptxApp); } - public static MainFrame createInstanceFromUrl() + public static MainFrame createInstanceFromUrl(URL url) { return null; diff --git a/src/jalview/ext/archaeopteryx/AptxTreeBuilder.java b/src/jalview/ext/archaeopteryx/AptxTreeBuilder.java index 7b03d5c..74d89d2 100644 --- a/src/jalview/ext/archaeopteryx/AptxTreeBuilder.java +++ b/src/jalview/ext/archaeopteryx/AptxTreeBuilder.java @@ -5,6 +5,7 @@ import jalview.datamodel.SequenceI; import jalview.ext.forester.DataConversions; import jalview.ext.forester.ForesterMatrix; import jalview.ext.treeviewer.ExternalTreeBuilderI; +import jalview.util.MappingUtils; import jalview.util.MessageManager; import java.util.HashMap; @@ -91,9 +92,9 @@ public class AptxTreeBuilder NodeData nodeData = sequenceNode.getNodeData(); nodeData.setSequence(seq); - ExternalTreeBuilderI.putWithDuplicationCheck(nodesWithAlignment, + MappingUtils.putWithDuplicationCheck(nodesWithAlignment, sequenceNode, sequence); - ExternalTreeBuilderI.putWithDuplicationCheck(alignmentWithNodes, + MappingUtils.putWithDuplicationCheck(alignmentWithNodes, sequence, sequenceNode); rootNode.addAsChild(sequenceNode); } diff --git a/src/jalview/ext/archaeopteryx/LoadedTreeAssociation.java b/src/jalview/ext/archaeopteryx/LoadedTreeAssociation.java index adea693..c869cd5 100644 --- a/src/jalview/ext/archaeopteryx/LoadedTreeAssociation.java +++ b/src/jalview/ext/archaeopteryx/LoadedTreeAssociation.java @@ -4,7 +4,7 @@ import jalview.analysis.SequenceIdMatcher; import jalview.datamodel.SequenceI; import jalview.ext.forester.DataConversions; import jalview.ext.treeviewer.ExternalLoadedTreeAssociationI; -import jalview.ext.treeviewer.ExternalTreeBuilderI; +import jalview.util.MappingUtils; import java.util.HashMap; import java.util.List; @@ -67,9 +67,9 @@ public class LoadedTreeAssociation .createForesterSequence(nodeSequence, true); treeNode.getNodeData().setSequence(foresterNodeSeq); - ExternalTreeBuilderI.putWithDuplicationCheck(alignmentWithNodes, + MappingUtils.putWithDuplicationCheck(alignmentWithNodes, nodeSequence, treeNode); - ExternalTreeBuilderI.putWithDuplicationCheck(nodesWithAlignment, + MappingUtils.putWithDuplicationCheck(nodesWithAlignment, treeNode, nodeSequence); diff --git a/src/jalview/ext/forester/io/TreeParser.java b/src/jalview/ext/forester/io/TreeParser.java index 96b5770..43fd1fa 100644 --- a/src/jalview/ext/forester/io/TreeParser.java +++ b/src/jalview/ext/forester/io/TreeParser.java @@ -52,7 +52,7 @@ public class TreeParser // implements ExternalTreeParserI public void loadTree(AlignViewport viewport) { - NewickFile fin = null; + NewickFile fin = null; // old tree try { AptxInit.createInstanceFromFile(filePath, viewport); @@ -60,6 +60,7 @@ public class TreeParser // implements ExternalTreeParserI fin = new NewickFile(filePath, DataSourceType.FILE); viewport.setCurrentTree(viewport.getAlignPanel().alignFrame .showNewickTree(fin, filePath).getTree()); + } catch (Exception ex) { JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(), diff --git a/src/jalview/ext/treeviewer/ExternalTreeBuilderI.java b/src/jalview/ext/treeviewer/ExternalTreeBuilderI.java index 27659d7..8fd1d1d 100644 --- a/src/jalview/ext/treeviewer/ExternalTreeBuilderI.java +++ b/src/jalview/ext/treeviewer/ExternalTreeBuilderI.java @@ -28,30 +28,4 @@ public interface ExternalTreeBuilderI public String generateTreeName(); - /** - * probably move - * - * @param map - * @param key - * @param value - * @return - */ - static Map putWithDuplicationCheck(Map map, K key, - V value) - { - if (!map.containsKey(key)) - { - map.put(key, value); - } - else - { - jalview.bin.Cache.log.warn( - "Attempt to add duplicate entry detected for map with key: " - + key.toString() + " and value: " + value.toString()); - } - - return map; - - } - } diff --git a/src/jalview/ext/treeviewer/ExternalTreeParserI.java b/src/jalview/ext/treeviewer/ExternalTreeParserI.java index fb7227f..47960f9 100644 --- a/src/jalview/ext/treeviewer/ExternalTreeParserI.java +++ b/src/jalview/ext/treeviewer/ExternalTreeParserI.java @@ -2,20 +2,17 @@ // // import jalview.viewmodel.AlignmentViewport; // -// import javax.swing.JInternalFrame; -// /// ** +// * // * Interface for loading in existing trees to an external tree viewer. // * // * @author kjvanderheide // * -// * @param -// * Frame of the tree viewer. // */ -// public interface ExternalTreeParserI +// public interface ExternalTreeParserI // { -// public void loadTreeFile(AlignmentViewport viewport); +// public ExternalTreeI loadTreeFile(AlignmentViewport viewport); // -// public void loadTreeUrl(AlignmentViewport viewport); +// public ExternalTreeI loadTreeUrl(AlignmentViewport viewport); // // } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 4bd20fc..3d9e0bb 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -127,6 +127,7 @@ import java.beans.PropertyChangeEvent; import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; +import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -3879,7 +3880,7 @@ public void chooseTreeFile() { chooser.setDialogTitle( MessageManager.getString("label.select_newick_like_tree_file")); // modify chooser.setToolTipText( - MessageManager.getString("label.load_tree_file")); + MessageManager.getString("label.load_tree_for_sequence_set")); for (SupportedTreeFileFilter treeFormat : SupportedTreeFileFilter .values()) { @@ -3899,6 +3900,46 @@ public void chooseTreeFile() { } } + public void chooseTreeUrl() + { + URL treeUrl; + + String urlString = JvOptionPane.showInputDialog(this, + MessageManager.getString("label.tree_url_example"), + MessageManager.getString("label.load_tree_url"), + JvOptionPane.QUESTION_MESSAGE); + if ((urlString != null) && (!urlString.isEmpty())) + { + try + { + treeUrl = new URL(urlString); + AptxInit.createInstanceFromUrl(treeUrl); + + } catch (MalformedURLException e) + { + JvOptionPane.showMessageDialog(this, + MessageManager.formatMessage( + "exception.failed_to_read_data_from_source", + new String[] + { urlString }), + MessageManager.getString("label.url_not_found") + , JvOptionPane.ERROR_MESSAGE); + } + + } + + + // final String url_string = JOptionPane + // .showInputDialog( this, + // message, + // "Use URL/webservice to obtain a phylogeny", + // JOptionPane.QUESTION_MESSAGE ); + // boolean nhx_or_nexus = false; + // if ( ( url_string != null ) && ( url_string.length() > 0 ) ) { + // try { + // url = new URL( url_string ); + } + /** * DOCUMENT ME! * @@ -3914,8 +3955,7 @@ public void chooseTreeFile() { @Override protected void loadTreeUrlItem_actionPerformed(ActionEvent e) { - AptxInit.createInstanceFromUrl(); - + chooseTreeUrl(); } @Override diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index f90752b..ca82d90 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -1161,8 +1161,9 @@ public class Desktop extends jalview.jbgui.GDesktop if (format == null) { JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.formatMessage("label.couldnt_locate", - new Object[] + MessageManager.formatMessage( + "label.couldnt_locate", + new String[] { url }), MessageManager.getString("label.url_not_found"), JvOptionPane.WARNING_MESSAGE); diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 4073fcc..954721e 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -1079,8 +1079,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem loadTreeFile = new JMenuItem( MessageManager.getString("label.from_file")); - // loadTreeMenuItem.setActionCommand( - // MessageManager.getString()); + loadTreeFile.addActionListener(new ActionListener() { @Override @@ -1707,7 +1706,8 @@ public class GAlignFrame extends JInternalFrame MessageManager.getString("label.export_image")); JMenu loadTreeMenu = new JMenu( MessageManager.getString("label.load_associated_tree")); - loadTreeMenu.setActionCommand("label.load_tree_for_sequence_set"); + // loadTreeMenu.setToolTipText( + // MessageManager.getString("label.load_tree_for_sequence_set")); JMenu fileMenu = new JMenu(MessageManager.getString("action.file")); @@ -1884,6 +1884,8 @@ public class GAlignFrame extends JInternalFrame // JAL-574 // selectMenu.addSeparator(); // selectMenu.add(listenToViewSelections); + + } /** diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 9c5c109..78a833e 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -990,4 +990,23 @@ public final class MappingUtils } } } + + + public static Map putWithDuplicationCheck(Map map, K key, + V value) + { + if (!map.containsKey(key)) + { + map.put(key, value); + } + else + { + jalview.bin.Cache.log.warn( + "Attempt to add duplicate entry detected for map with key: " + + key.toString() + " and value: " + value.toString()); + } + + return map; + + } } -- 1.7.10.2