JAL-2805 loads of file reorganizing, interfaces expanded
[jalview.git] / src / jalview / ext / forester / io / TreeParser.java
1 package jalview.ext.forester.io;
2
3 import jalview.ext.archaeopteryx.JalviewBinding;
4 import jalview.ext.archaeopteryx.LoadedTreeAssociation;
5 import jalview.ext.archaeopteryx.ArchaeopteryxInit;
6 import jalview.ext.treeviewer.ExternalTreeParserI;
7 import jalview.gui.Desktop;
8 import jalview.gui.JvOptionPane;
9 import jalview.util.MessageManager;
10 import jalview.viewmodel.AlignmentViewport;
11
12 import java.io.File;
13 import java.io.IOException;
14
15 import org.forester.archaeopteryx.Archaeopteryx;
16 import org.forester.archaeopteryx.MainFrame;
17 import org.forester.util.ForesterUtil;
18
19 public class TreeParser implements ExternalTreeParserI<MainFrame>
20 {
21   private final String filePath;
22
23   private final File file;
24
25   public TreeParser(final String treeFilePath)
26   {
27     final String possibleError = ForesterUtil.isReadableFile(treeFilePath);
28     if (possibleError != null)
29     {
30       JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
31               MessageManager.getString("label.problem_reading_tree_file"),
32               JvOptionPane.WARNING_MESSAGE);
33
34     }
35     filePath = treeFilePath;
36     file = new File(filePath);
37
38
39   }
40
41   public TreeParser(final File treeFile) throws IOException
42   {
43     final String possibleError = ForesterUtil.isReadableFile(treeFile);
44     if (possibleError != null)
45     {
46       JvOptionPane.showMessageDialog(Desktop.desktop, possibleError,
47               MessageManager.getString("label.problem_reading_tree_file"),
48               JvOptionPane.WARNING_MESSAGE);
49
50     }
51     file = treeFile;
52     filePath = file.getCanonicalPath();
53   }
54
55   @Override
56   public MainFrame loadTree(AlignmentViewport viewport)
57   {
58     String[] AptxArgs = new String[] { "-c",
59         "_aptx_jalview_configuration_file", filePath };
60     MainFrame aptx = Archaeopteryx.main(AptxArgs);
61
62     LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
63             viewport.getAlignment().getSequencesArray(),
64             aptx.getMainPanel().getCurrentTreePanel().getPhylogeny());
65
66     bindAptxNodes.associateLeavesToSequences();
67     new JalviewBinding(aptx, viewport, bindAptxNodes.getAlignmentWithNodes(),
68             bindAptxNodes.getNodesWithAlignment());
69
70     ArchaeopteryxInit.bindFrameToJalview(aptx);
71
72     return aptx;
73
74
75   }
76
77 }
78
79
80
81
82
83