JAL-1760 JAL-1641 Serialisation of Hidden Seqs and Cols in JSON output. Added ability...
[jalview.git] / src / jalview / io / HtmlFile.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21
22 package jalview.io;
23
24 import java.io.IOException;
25 import java.util.List;
26
27 import org.jsoup.Jsoup;
28 import org.jsoup.nodes.Document;
29 import org.jsoup.nodes.Element;
30
31 import jalview.api.AlignViewControllerGuiI;
32 import jalview.schemes.ColourSchemeI;
33
34 public class HtmlFile extends AlignFile
35 {
36   public static final String FILE_EXT = "html";
37
38   public static final String FILE_DESC = "HTML";
39
40   private ColourSchemeI colourScheme;
41
42   private boolean showSeqFeatures;
43
44   private List<int[]> hiddenColumns;
45
46   public HtmlFile()
47   {
48     super();
49   }
50
51   public HtmlFile(FileParse source) throws IOException
52   {
53     super(source);
54   }
55
56   public HtmlFile(String inFile, String type) throws IOException
57   {
58     super(inFile, type);
59   }
60
61   @Override
62   public void parse() throws IOException
63   {
64     try
65     {
66       StringBuilder htmlData = new StringBuilder();
67       String currentLine;
68       while ((currentLine = nextLine()) != null)
69       {
70         htmlData.append(currentLine);
71       }
72
73       Document doc = Jsoup.parse(htmlData.toString());
74       Element content = doc.getElementById("seqData");
75       String alignmentJsonString = content.val();
76
77       JSONFile jsonFile = new JSONFile().parse(alignmentJsonString);
78       this.seqs = jsonFile.getSeqs();
79       this.seqGroups = jsonFile.getSeqGroups();
80       this.annotations = jsonFile.getAnnotations();
81       this.showSeqFeatures = jsonFile.isShowSeqFeatures();
82       this.colourScheme = jsonFile.getColourScheme();
83       this.hiddenColumns = jsonFile.getHiddenColumns();
84     } catch (Exception e)
85     {
86       e.printStackTrace();
87     }
88   }
89
90   public void applySettingsToAlignmentView(AlignViewControllerGuiI avc)
91   {
92     avc.setShowSeqFeatures(isShowSeqFeatures());
93     avc.changeColour(getColourScheme());
94     avc.setMenusForViewport();
95     avc.hideColumns(hiddenColumns);
96     avc.syncHiddenSequences();
97   }
98
99   @Override
100   public String print()
101   {
102     throw new UnsupportedOperationException(
103             "Print method of HtmlFile is not supported!");
104   }
105
106   public boolean isShowSeqFeatures()
107   {
108     return showSeqFeatures;
109   }
110
111   public void setShowSeqFeatures(boolean showSeqFeatures)
112   {
113     this.showSeqFeatures = showSeqFeatures;
114   }
115
116   public ColourSchemeI getColourScheme()
117   {
118     return colourScheme;
119   }
120
121   public void setColourScheme(ColourSchemeI colourScheme)
122   {
123     this.colourScheme = colourScheme;
124   }
125
126 }