Debian Codegraph @

src/dr/app/beauti/datapanel/ViewAligmentPanel.java

raw symbols SCIP
1 /*
2 * ViewAligmentPanel.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.beauti.datapanel;
27
28 import javax.swing.*;
29
30 import dr.app.beauti.options.PartitionData;
31 import dr.evolution.util.Taxon;
32
33 import java.awt.*;
34 import java.awt.event.*;
35
36
37 /**
38 * @author Andrew Rambaut
39 * @author Alexei Drummond
40 * @author Walter Xie
41 * @version $Id: ViewAligmentPanel.java,v 1.5 2009/08/11 13:29:34 rambaut Exp$
42 */
43
44 public class ViewAligmentPanel extends JPanel {
45
46 private static final long serialVersionUID = 6129057786946772468L;
47
48 private final PartitionData partitionData;
49 private final static int FONT_SIZE = 14;
50 private final static int GAP = 4;
51 private final static int TAXON_NAME_LEN = 300;
52 private final static int Y_BOADER = FONT_SIZE + 3 * GAP + 20;
53 private int width = TAXON_NAME_LEN;
54 private int height = Y_BOADER;
55
56
57 public ViewAligmentPanel (PartitionData partitionData) {
58 this.partitionData = partitionData;
59
60 getWidthLenth();
61 }
62
63 public void paintComponent(Graphics g) {
64 super.paintComponent(g);
65 setBackground(Color.white);
66
67 // Graphics2D g2d = (Graphics2D) g;
68
69 g.setFont(new Font("SansSerif", Font.PLAIN, FONT_SIZE));
70
71 String sequenceString = partitionData.getAlignment().getAlignedSequenceString(0);
72 for (int i = 0; i < sequenceString.length(); i++) {
73 if (i == 0 || ((i+1)%10) == 0) {
74 if (i == 0) {
75 g.drawString(Integer.toString(i+1), TAXON_NAME_LEN + i * (FONT_SIZE + GAP), Y_BOADER - (FONT_SIZE + 3 * GAP));
76 } else if (i < 100) {
77 g.drawString(Integer.toString(i+1), TAXON_NAME_LEN + i * (FONT_SIZE + GAP) - GAP, Y_BOADER - (FONT_SIZE + 3 * GAP));
78 } else {
79 g.drawString(Integer.toString(i+1), TAXON_NAME_LEN + i * (FONT_SIZE + GAP) - 2 * GAP, Y_BOADER - (FONT_SIZE + 3 * GAP));
80 }
81
82 g.drawLine(TAXON_NAME_LEN + i * (FONT_SIZE + GAP) + GAP, Y_BOADER - (FONT_SIZE + 2 * GAP),
83 TAXON_NAME_LEN + i * (FONT_SIZE + GAP) + GAP, Y_BOADER - (FONT_SIZE + GAP));
84 }
85 }
86
87
88 for (int i = 0; i < partitionData.getAlignment().getTaxonCount(); i++) {
89
90 Taxon taxon = partitionData.getAlignment().getTaxon(i);
91
92 g.drawString(taxon.getId(), 0, Y_BOADER + i * (FONT_SIZE + GAP));
93
94 sequenceString = partitionData.getAlignment().getAlignedSequenceString(i);
95
96 int charSpace = TAXON_NAME_LEN;
97 for (char c : sequenceString.toCharArray()) {
98 g.drawString(Character.toString(c), charSpace, Y_BOADER + i * (FONT_SIZE + GAP));
99 charSpace = charSpace + FONT_SIZE + GAP;
100 }
101
102 }
103
104
105
106 }
107
108 public void setPreferredSize(){
109 super.setPreferredSize(new java.awt.Dimension(width, height));
110 // System.out.println(width + " " + height);
111 }
112
113
114 private void getWidthLenth() {
115 int maxLen = 0;
116
117 String sequenceString = null;
118 for (int i = 0; i < partitionData.getAlignment().getTaxonCount(); i++) {
119
120 sequenceString = partitionData.getAlignment().getAlignedSequenceString(i);
121
122 if (sequenceString.length() > maxLen) maxLen = sequenceString.length();
123
124 height = height + FONT_SIZE + GAP;
125 }
126
127 width = width + maxLen * (FONT_SIZE + GAP);
128 }
129 }