| 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 abstract class PlotPane extends JComponent { |
| 36 |
private AlignmentBuffer alignment = null; |
| 37 |
private ColumnDecorator columnDecorator = null; |
| 38 |
private int columnCount = 0; |
| 39 |
|
| 40 |
private int colWidth = 0; |
| 41 |
|
| 42 |
public int getColumnWidth() { |
| 43 |
|
| 44 |
return colWidth; |
| 45 |
} |
| 46 |
|
| 47 |
public int getColumnCount() { |
| 48 |
return columnCount; |
| 49 |
} |
| 50 |
|
| 51 |
public PlotPane() { |
| 52 |
setFont( new Font("sansserif", Font.PLAIN, 10)); |
| 53 |
} |
| 54 |
|
| 55 |
public void setAlignmentBuffer(AlignmentBuffer alignment) { |
| 56 |
this.alignment = alignment; |
| 57 |
|
| 58 |
if (alignment != null) { |
| 59 |
columnCount = alignment.getSiteCount(); |
| 60 |
} else { |
| 61 |
columnCount = 0; |
| 62 |
} |
| 63 |
|
| 64 |
setup(); |
| 65 |
} |
| 66 |
|
| 67 |
public void setColumnWidth(int columnWidth) { |
| 68 |
this.colWidth = columnWidth; |
| 69 |
setup(); |
| 70 |
} |
| 71 |
|
| 72 |
public void setColumnDecorator(ColumnDecorator columnDecorator) { |
| 73 |
this.columnDecorator = columnDecorator; |
| 74 |
} |
| 75 |
|
| 76 |
private void setup() { |
| 77 |
setPreferredSize(new Dimension(colWidth * columnCount, 16)); |
| 78 |
invalidate(); |
| 79 |
} |
| 80 |
|
| 81 |
public void paint(Graphics graphics) { |
| 82 |
if (alignment == null) return; |
| 83 |
|
| 84 |
Graphics2D g2 = (Graphics2D)graphics; |
| 85 |
|
| 86 |
int col1 = 0; |
| 87 |
int col2 = columnCount - 1; |
| 88 |
|
| 89 |
int y1 = 0; |
| 90 |
int y2 = getHeight(); |
| 91 |
|
| 92 |
if (columnDecorator != null) { |
| 93 |
int x = 0; |
| 94 |
for (int col = col1; col <= col2; col++) { |
| 95 |
Paint columnBackground = columnDecorator.getColumnBackground(col); |
| 96 |
if (columnBackground != null) { |
| 97 |
g2.setPaint(columnBackground); |
| 98 |
g2.fillRect(x, y1, colWidth, y2); |
| 99 |
} |
| 100 |
x += colWidth; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
paintPlot(g2); |
| 105 |
} |
| 106 |
|
| 107 |
public abstract void paintPlot(Graphics2D g2); |
| 108 |
|
| 109 |
} |