Debian Codegraph @

src/dr/app/beauti/alignmentviewer/PlotPane.java

raw symbols SCIP
1 /*
2 * PlotPane.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.alignmentviewer;
27
28 import javax.swing.*;
29 import java.awt.*;
30
31 /**
32 * @author Andrew Rambaut
33 * @version $Id: RulerPane.java,v 1.1 2005/11/01 23:52:04 rambaut Exp $
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 }