JAL-3032 adds Java 8 functionality (2/2)
[jalview.git] / src2 / fr / orsay / lri / varna / models / export / TikzExport.java
1 /*
2  VARNA is a tool for the automated drawing, visualization and annotation of the secondary structure of RNA, designed as a companion software for web servers and databases.
3  Copyright (C) 2008  Kevin Darty, Alain Denise and Yann Ponty.
4  electronic mail : Yann.Ponty@lri.fr
5  paper mail : LRI, bat 490 Université Paris-Sud 91405 Orsay Cedex France
6
7  This file is part of VARNA version 3.1.
8  VARNA version 3.1 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
9  as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10
11  VARNA version 3.1 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  See the GNU General Public License for more details.
14
15  You should have received a copy of the GNU General Public License along with VARNA version 3.1.
16  If not, see http://www.gnu.org/licenses.
17  */
18 package fr.orsay.lri.varna.models.export;
19
20 import java.awt.Color;
21 import java.awt.geom.Point2D;
22 import java.awt.geom.Rectangle2D;
23 import java.awt.geom.Point2D.Double;
24 import java.util.Hashtable;
25
26 import fr.orsay.lri.varna.models.rna.ModeleBP;
27
28 public class TikzExport extends SecStrDrawingProducer {
29
30
31         public TikzExport()
32         {
33                 super();
34                 super.setScale(0.2);
35         }
36         
37
38         private String TikzHeader() {
39                 return   "\\documentclass[tikz,border=10pt]{standalone}\n"
40                                 +"\\usepackage{tikz,relsize}\n"
41                                 +"\\usetikzlibrary{positioning}\n"
42                                 +"\\begin{document}\n"
43                                 +"\\begin{tikzpicture}[inner sep=0, fill=none,draw=none,text=none,font={\\sf}]\n";
44         }
45
46         private String formatPoint(Point2D.Double p)
47         {
48                 return formatPoint(p.x,p.y);
49         }
50
51         private String formatPoint(double x, double y)
52         {
53                 return "("+(super.getScale()*x)+","+(super.getScale()*y)+")";
54         }
55
56         public String drawCircleS(Point2D.Double p, double radius, double thickness) {
57                 return "  \\draw[draw=currColor] "+formatPoint(p)+" circle ("+(radius*super.getScale())+");\n";
58         }
59
60         public String fillCircleS(Point2D.Double p, double radius,
61                         double thickness, Color col) {
62                 return setColorS(col)
63                         +"  \\fill[fill=currColor] "+formatPoint(p)+" circle ("+(radius*super.getScale())+");\n";
64         }
65
66
67         public String drawLineS(Point2D.Double p0, Point2D.Double p1,
68                         double thickness) {
69                 return "  \\draw[draw=currColor] "+formatPoint(p0)+" -- "+formatPoint(p1)+";\n";
70         }
71
72         public String drawRectangleS(Point2D.Double p, Point2D.Double dims,
73                         double thickness) {
74                 return "  \\draw[draw=currColor] "+formatPoint(p)+" -- "+formatPoint(p.x+dims.x,p.y)+" -- "+formatPoint(p.x+dims.x,p.y+dims.y)+" -- "+formatPoint(p.x,p.y+dims.y)+" -- "+formatPoint(p)+";\n";
75         }
76
77         public String drawTextS(Point2D.Double p, String txt) {
78                 return "  \\node[text=currColor] at "+formatPoint(p)+" {"+txt+"};\n";
79         }
80
81         public String setFontS(int font, double size) {
82                 _font = font;
83                 _fontsize = 1.2 * size;
84                 return "";
85         }
86
87         public String setColorS(Color col) {
88                 super.setColorS(col);
89                 return "\\definecolor{currColor}{rgb}{"+(((double)col.getRed())/255.)+","+(((double)col.getGreen())/255.)+","+(((double)col.getBlue())/255.)+"}\n";
90         }
91
92         public String footerS() {
93                 return "\\end{tikzpicture}\n"
94                         +  "\\end{document}";
95         }
96
97         public String headerS(Rectangle2D.Double bb) {
98                 return TikzHeader();
99         }
100
101         @Override
102         public String drawArcS(Point2D.Double origine, double width, double height,
103                         double startAngle, double endAngle) {
104                 return "";
105
106         }
107
108         @Override
109         public String drawPolygonS(Double[] points, double thickness) {
110                 if (points.length > 0) {
111                         String result = "\\draw[draw=currColor] ";
112                         for (int i = 0; i < points.length; i++) {
113                                 result += ""+formatPoint(points[i])+" -- ";
114                         }
115                         result += ""+formatPoint(points[0])+";";
116                         return result;
117                 } else {
118                         return "";
119                 }
120         }
121
122         @Override
123         public String fillPolygonS(Double[] points,  Color col) {
124                 if (points.length > 0) {
125                         String result = "\\fill[fill=currColor] ";
126                         for (int i = 0; i < points.length; i++) {
127                                 result += ""+formatPoint(points[i])+" -- ";
128                         }
129                         result += ""+formatPoint(points[0])+";";
130                         return setColorS(col)
131                                         +result;
132                 } else {
133                         return setColorS(col);
134                 }
135         }
136         
137         @Override
138         public String drawBaseStartS(int index) {
139                 return "";
140         }
141
142         @Override
143         public String drawBaseEndS(int index) {
144                 return "";
145         }
146
147         @Override
148         public String drawBasePairStartS(int i, int j, ModeleBP bps) {
149                 return "";
150         }
151
152         @Override
153         public String drawBasePairEndS(int index) {
154                 return "";
155         }
156
157         @Override
158         public String drawBackboneStartS(int i, int j) {
159                 return "";
160         }
161
162         @Override
163         public String drawBackboneEndS(int index) {
164                 return "";
165         }
166
167
168 }