d507362c8cc5188a35eb805977099ee81f3da351
[jalview.git] / src / jalview / io / HtmlFile.java
1 package jalview.io;
2
3 import jalview.gui.AlignFrame;
4 import jalview.schemes.ColourSchemeI;
5
6 import java.io.IOException;
7
8 import org.jsoup.Jsoup;
9 import org.jsoup.nodes.Document;
10 import org.jsoup.nodes.Element;
11
12 public class HtmlFile extends AlignFile
13 {
14   public static final String FILE_EXT = "html";
15
16   public static final String FILE_DESC = "HTML";
17
18   private ColourSchemeI colourScheme;
19
20   private boolean showSeqFeatures;
21
22   public HtmlFile()
23   {
24     super();
25   }
26
27   public HtmlFile(FileParse source) throws IOException
28   {
29     super(source);
30   }
31
32   public HtmlFile(String inFile, String type) throws IOException
33   {
34     super(inFile, type);
35   }
36
37   @Override
38   public void parse() throws IOException
39   {
40     try
41     {
42       StringBuilder htmlData = new StringBuilder();
43       String currentLine;
44       while ((currentLine = nextLine()) != null)
45       {
46         htmlData.append(currentLine);
47       }
48
49       Document doc = Jsoup.parse(htmlData.toString());
50       Element content = doc.getElementById("seqData");
51       String alignmentJsonString = content.val();
52
53       JSONFile jsonFile = new JSONFile().parse(alignmentJsonString);
54       seqs = jsonFile.seqs;
55       seqGroups = jsonFile.seqGroups;
56       annotations = jsonFile.annotations;
57       showSeqFeatures = jsonFile.isShowSeqFeatures();
58       colourScheme = jsonFile.getColourScheme();
59     } catch (Exception e)
60     {
61       e.printStackTrace();
62     }
63   }
64
65   public void applySettingsToAlignFrame(AlignFrame af)
66   {
67     af.setShowSeqFeatures(isShowSeqFeatures());
68     af.changeColour(getColourScheme());
69     af.setMenusForViewport();
70   }
71
72
73   @Override
74   public String print()
75   {
76     throw new UnsupportedOperationException(
77             "Print method of HtmlFile is not supported!");
78   }
79
80   public boolean isShowSeqFeatures()
81   {
82     return showSeqFeatures;
83   }
84
85   public void setShowSeqFeatures(boolean showSeqFeatures)
86   {
87     this.showSeqFeatures = showSeqFeatures;
88   }
89
90   public ColourSchemeI getColourScheme()
91   {
92     return colourScheme;
93   }
94
95   public void setColourScheme(ColourSchemeI colourScheme)
96   {
97     this.colourScheme = colourScheme;
98   }
99
100 }