Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * RulerPane.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 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 }