| 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.alignmentviewer; |
| 27 |
|
| 28 |
import javax.swing.*; |
| 29 |
import java.awt.*; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class RulerPane extends JComponent { |
| 36 |
private AlignmentBuffer alignment = null; |
| 37 |
private ColumnDecorator columnDecorator = null; |
| 38 |
private int columnCount = 0; |
| 39 |
|
| 40 |
private int colWidth = 0; |
| 41 |
private int ascent = 0; |
| 42 |
|
| 43 |
public int getColumnWidth() { |
| 44 |
|
| 45 |
return colWidth; |
| 46 |
} |
| 47 |
|
| 48 |
public int getColumnCount() { |
| 49 |
return columnCount; |
| 50 |
} |
| 51 |
|
| 52 |
public RulerPane() { |
| 53 |
setFont( new Font("sansserif", Font.PLAIN, 10)); |
| 54 |
} |
| 55 |
|
| 56 |
public void setAlignmentBuffer(AlignmentBuffer alignment) { |
| 57 |
this.alignment = alignment; |
| 58 |
|
| 59 |
if (alignment != null) { |
| 60 |
columnCount = alignment.getSiteCount(); |
| 61 |
} else { |
| 62 |
columnCount = 0; |
| 63 |
} |
| 64 |
|
| 65 |
FontMetrics fm = getFontMetrics(getFont()); |
| 66 |
ascent = fm.getAscent(); |
| 67 |
|
| 68 |
setup(); |
| 69 |
} |
| 70 |
|
| 71 |
public void setColumnWidth(int columnWidth) { |
| 72 |
this.colWidth = columnWidth; |
| 73 |
setup(); |
| 74 |
} |
| 75 |
|
| 76 |
public void setColumnDecorator(ColumnDecorator columnDecorator) { |
| 77 |
this.columnDecorator = columnDecorator; |
| 78 |
} |
| 79 |
|
| 80 |
private void setup() { |
| 81 |
setPreferredSize(new Dimension(colWidth * columnCount, 16)); |
| 82 |
invalidate(); |
| 83 |
} |
| 84 |
|
| 85 |
public void paint(Graphics graphics) { |
| 86 |
if (alignment == null) return; |
| 87 |
|
| 88 |
Graphics2D g2 = (Graphics2D)graphics; |
| 89 |
|
| 90 |
int col1 = 0; |
| 91 |
int col2 = columnCount - 1; |
| 92 |
|
| 93 |
int y1 = 0; |
| 94 |
int y2 = getHeight(); |
| 95 |
|
| 96 |
int y = ascent; |
| 97 |
|
| 98 |
if (columnDecorator != null) { |
| 99 |
int x = 0; |
| 100 |
for (int col = col1; col <= col2; col++) { |
| 101 |
Paint columnBackground = columnDecorator.getColumnBackground(col); |
| 102 |
if (columnBackground != null) { |
| 103 |
g2.setPaint(columnBackground); |
| 104 |
g2.fillRect(x, y1, colWidth, y2); |
| 105 |
} |
| 106 |
x += colWidth; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
g2.setPaint(Color.BLACK); |
| 111 |
|
| 112 |
int x = 0; |
| 113 |
if (col1 == 0) { |
| 114 |
g2.drawString("1", x, y); |
| 115 |
g2.drawLine(x, y2, x, y + 1); |
| 116 |
x += colWidth; |
| 117 |
col1++; |
| 118 |
} |
| 119 |
|
| 120 |
for (int col = col1; col <= col2; col++) { |
| 121 |
if ((col + 1) % 5 == 0) { |
| 122 |
g2.drawString(Integer.toString(col + 1), x, y); |
| 123 |
g2.drawLine(x, y2, x, y + 1); |
| 124 |
} else { |
| 125 |
g2.drawLine(x, y2, x, y + 4); |
| 126 |
} |
| 127 |
x += colWidth; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
} |