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
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.
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.
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.
18 package fr.orsay.lri.varna.models.export;
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;
26 import fr.orsay.lri.varna.models.rna.ModeleBP;
28 public class XFIGExport extends SecStrDrawingProducer {
30 private int _font = SecStrDrawingProducer.FONT_TIMES_ROMAN;
31 @SuppressWarnings("unused")
32 private StringBuffer buf = new StringBuffer();
34 private Hashtable<Color, Integer> _definedCols = new Hashtable<Color, Integer>();
36 // From XFig 3.2 file format, indexed RGB colors are in the range [32,543]
37 private int _nextColCode = 32;
38 private final static int UPPER_BOUND_COLOR_CODE = 543;
47 private String ensureColorDefinition(Color col) {
48 if (!_definedCols.containsKey(col)) {
49 if (_nextColCode < UPPER_BOUND_COLOR_CODE) {
50 int curColorCode = _nextColCode;
51 _definedCols.put(col, curColorCode);
54 String RGBR = Integer.toHexString(col.getRed());
55 if (RGBR.length() < 2) {
58 String RGBG = Integer.toHexString(col.getGreen());
59 if (RGBG.length() < 2) {
62 String RGBB = Integer.toHexString(col.getBlue());
63 if (RGBB.length() < 2) {
66 String RGBHex = "#" + RGBR + RGBG + RGBB;
67 RGBHex = RGBHex.toUpperCase();
68 return "0 " + curColorCode + " " + RGBHex + "\n";
74 private int getColorCode(Color col) {
75 if (_definedCols.containsKey(col)) {
76 return _definedCols.get(col);
81 private int getCurColorCode() {
82 if (_definedCols.containsKey(_curColor)) {
83 return _definedCols.get(_curColor);
88 private String XFIGHeader() {
89 return "#FIG 3.2\n" + "Landscape\n" + "Center\n" + "Inches\n"
90 + "Letter \n" + "100.00\n" + "Single\n" + "-2\n" + "1200 2\n";
93 public String drawCircleS(Point2D.Double p, double radius, double thickness) {
94 return ("1 3 0 " + (long) thickness + " " + getCurColorCode()
95 + " 7 50 -1 -1 0.000 1 0.0000 " + (long) p.x + " "
96 + (long) -p.y + " " + (long) radius + " " + (long) radius + " 1 1 1 1\n");
99 public String drawLineS(Point2D.Double p0, Point2D.Double p1,
101 return ("2 1 0 " + (long) thickness + " " + getCurColorCode()
102 + " 7 60 -1 -1 0.000 0 0 -1 0 0 2\n" + " " + (long) p0.x + " "
103 + (long) -p0.y + " " + (long) p1.x + " " + (long) -p1.y + "\n");
106 public String drawRectangleS(Point2D.Double p, Point2D.Double dims,
108 return ("2 2 0 " + (long) thickness + " " + getCurColorCode()
109 + " 7 50 -1 -1 0.000 0 0 -1 0 0 5\n" + "\t " + (long) (p.x)
110 + " " + (long) (-p.y) + " " + (long) (p.x + dims.x) + " "
111 + (long) (-p.y) + " " + (long) (p.x + dims.x) + " "
112 + (long) -(p.y + dims.y) + " " + (long) (p.x) + " "
113 + (long) -(p.y + dims.y) + " " + (long) (p.x) + " "
114 + (long) -(p.y) + "\n");
117 public String drawTextS(Point2D.Double p, String txt) {
118 return ("4 1 " + getCurColorCode() + " 40 -1 " + _font + " "
119 + (long) _fontsize + " 0.0000 6 " + (long) 4 * _fontsize + " "
120 + (long) (2 * _fontsize) + " " + (long) (p.x) + " "
121 + (long) -(p.y - 6 * _fontsize) + " " + txt + "\\001\n");
124 public String fillCircleS(Point2D.Double p, double radius,
125 double thickness, Color col) {
126 String coldef = ensureColorDefinition(col);
127 return (coldef + "1 3 0 " + (long) thickness + " 0 "
128 + getColorCode(col) + " 50 0 20 0.000 1 0.0000 " + (long) p.x
129 + " " + (long) -p.y + " " + (long) radius + " " + (long) radius + " 1 1 1 1\n");
132 public String setFontS(int font, double size) {
134 _fontsize = 1.2 * size;
138 public String setColorS(Color col) {
139 super.setColorS(col);
140 return (ensureColorDefinition(col));
143 public String footerS() {
147 public String headerS(Rectangle2D.Double bb) {
152 public String drawArcS(Point2D.Double origine, double width, double height,
153 double startAngle, double endAngle) {
154 double p1x = origine.x;
155 double p1y = -origine.y;
156 double p2x = origine.x + width / 2.0;
157 double p2y = -origine.y - height / 2.0;
158 double p3x = origine.x + width;
160 double cx = (p1x + p3x) / 2.0;
161 double cy = p3y + height / 2.0;
162 return ("5 1 0 1 " + getCurColorCode() + " 7 50 0 -1 4.000 0 0 0 0 "
163 + cx + " " + cy + " " + (int) p1x + " " + (int) p1y + " "
164 + (int) p2x + " " + (int) p2y + " " + (int) p3x + " "
170 public String drawPolygonS(Double[] points, double thickness) {
171 if (points.length > 0) {
172 String result = "2 3 0 1 " + getCurColorCode()
173 + " 7 40 0 -1 4.000 0 0 0 0 0 " + (points.length + 1)
175 for (int i = 0; i < points.length; i++) {
176 result += (int) Math.round(points[i].x) + " "
177 + (int) Math.round(-points[i].y) + " ";
179 result += (int) Math.round(points[0].x) + " "
180 + (int) Math.round(-points[0].y) + " ";
189 public String fillPolygonS(Double[] points, Color col) {
190 if (points.length > 0) {
191 String coldef = ensureColorDefinition(col);
192 String result = "2 3 0 1 0 " + getColorCode(col)
193 + " 35 0 0 4.000 0 0 0 0 0 " + (points.length + 1) + "\n";
194 for (int i = 0; i < points.length; i++) {
195 result += (int) Math.round(points[i].x) + " "
196 + (int) Math.round(-points[i].y) + " ";
198 result += (int) Math.round(points[0].x) + " "
199 + (int) Math.round(-points[0].y) + " ";
201 return coldef + result;
208 public String drawBaseStartS(int index) {
213 public String drawBaseEndS(int index) {
218 public String drawBasePairStartS(int i, int j, ModeleBP bps) {
223 public String drawBasePairEndS(int index) {
228 public String drawBackboneStartS(int i, int j) {
233 public String drawBackboneEndS(int index) {