JAL-2797 the big switch, all GUI method calls now go via the AptxFrame
[jalview.git] / forester / java / src / org / forester / archaeopteryx / UrlTreeReader.java
index cb1d118..e3c81f9 100644 (file)
@@ -30,13 +30,11 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 
-import javax.net.ssl.HttpsURLConnection;
 import javax.swing.JOptionPane;
 
 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
 import org.forester.archaeopteryx.webservices.WebserviceUtil;
 import org.forester.archaeopteryx.webservices.WebservicesManager;
-import org.forester.archaeopteryx.webservices.WebservicesManager.WsPhylogenyFormat;
 import org.forester.io.parsers.PhylogenyParser;
 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
 import org.forester.io.parsers.nhx.NHXParser;
@@ -46,10 +44,7 @@ import org.forester.io.parsers.tol.TolParser;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
 import org.forester.phylogeny.data.Identifier;
-import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
-import org.forester.phylogeny.factories.PhylogenyFactory;
 import org.forester.util.ForesterUtil;
-import org.forester.util.TrustManager;
 
 public class UrlTreeReader implements Runnable {
 
@@ -72,7 +67,7 @@ public class UrlTreeReader implements Runnable {
         final WebservicesManager webservices_manager = WebservicesManager.getInstance();
         final PhylogeniesWebserviceClient client = webservices_manager
                 .getAvailablePhylogeniesWebserviceClient( _webservice_client_index );
-        String identifier = JOptionPane.showInputDialog( _main_frame, client.getInstructions() + "\n(Reference: "
+        String identifier = JOptionPane.showInputDialog( _main_frame.getThisFrame(), client.getInstructions() + "\n(Reference: "
                 + client.getReference() + ")", client.getDescription(), JOptionPane.QUESTION_MESSAGE );
         if ( ( identifier != null ) && ( identifier.trim().length() > 0 ) ) {
             identifier = identifier.trim();
@@ -86,7 +81,7 @@ public class UrlTreeReader implements Runnable {
                     id = -1;
                 }
                 if ( id < 1 ) {
-                    JOptionPane.showMessageDialog( _main_frame,
+                    JOptionPane.showMessageDialog( _main_frame.getThisFrame(),
                                                    "Identifier is expected to be a number",
                                                    "Can not open URL",
                                                    JOptionPane.ERROR_MESSAGE );
@@ -155,35 +150,25 @@ public class UrlTreeReader implements Runnable {
                 else {
                     _main_frame.getMainPanel().setWaitCursor();
                 }
-                final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
-                
-                if (client.getReturnFormat()== WebservicesManager.WsPhylogenyFormat.TREEBASE_TREE
-                    || client.getReturnFormat()== WebservicesManager.WsPhylogenyFormat.TREEBASE_STUDY) {
-                    
-                    final HttpsURLConnection con = TrustManager.makeHttpsURLConnection( url );
-                    trees = factory.create( con.getInputStream(), parser );
-                }
-                else {
-                    trees = factory.create( url.openStream(), parser );
-                }
+                trees = ForesterUtil.readPhylogeniesFromUrl( url, parser );
             }
             catch ( final MalformedURLException e ) {
                 exception = true;
-                JOptionPane.showMessageDialog( _main_frame,
+                JOptionPane.showMessageDialog( _main_frame.getThisFrame(),
                                                "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
                                                "Malformed URL",
                                                JOptionPane.ERROR_MESSAGE );
             }
             catch ( final IOException e ) {
                 exception = true;
-                JOptionPane.showMessageDialog( _main_frame,
+                JOptionPane.showMessageDialog( _main_frame.getThisFrame(),
                                                "Could not read from " + url + "\n" + e.getLocalizedMessage(),
                                                "Failed to read tree from " + client.getName() + " for " + identifier,
                                                JOptionPane.ERROR_MESSAGE );
             }
             catch ( final NumberFormatException e ) {
                 exception = true;
-                JOptionPane.showMessageDialog( _main_frame,
+                JOptionPane.showMessageDialog( _main_frame.getThisFrame(),
                                                "Could not read from " + url + "\n" + e.getLocalizedMessage(),
                                                "Failed to read tree from " + client.getName() + " for " + identifier,
                                                JOptionPane.ERROR_MESSAGE );
@@ -191,7 +176,7 @@ public class UrlTreeReader implements Runnable {
             catch ( final Exception e ) {
                 exception = true;
                 e.printStackTrace();
-                JOptionPane.showMessageDialog( _main_frame,
+                JOptionPane.showMessageDialog( _main_frame.getThisFrame(),
                                                e.getLocalizedMessage(),
                                                "Unexpected Exception",
                                                JOptionPane.ERROR_MESSAGE );
@@ -216,7 +201,7 @@ public class UrlTreeReader implements Runnable {
                                 WebserviceUtil.processInstructions( client, phylogeny );
                             }
                             catch ( final PhyloXmlDataFormatException e ) {
-                                JOptionPane.showMessageDialog( _main_frame,
+                                JOptionPane.showMessageDialog( _main_frame.getThisFrame(),
                                                                "Error:\n" + e.getLocalizedMessage(),
                                                                "Error",
                                                                JOptionPane.ERROR_MESSAGE );
@@ -227,7 +212,7 @@ public class UrlTreeReader implements Runnable {
                                 PhylogenyMethods.transferNodeNameToField( phylogeny, client.getNodeField(), false );
                             }
                             catch ( final PhyloXmlDataFormatException e ) {
-                                JOptionPane.showMessageDialog( _main_frame,
+                                JOptionPane.showMessageDialog( _main_frame.getThisFrame(),
                                                                "Error:\n" + e.getLocalizedMessage(),
                                                                "Error",
                                                                JOptionPane.ERROR_MESSAGE );