| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 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 |
|
| 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 |
|
| 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 |
} |