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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
/**
* Title: ProAlign<p>
* Description: sequence alignment comparison program<p>
* Copyright: Copyright (c) Ari Loytynoja<p>
* License: GNU GENERAL PUBLIC LICENSE<p>
* @see http://www.gnu.org/copyleft/gpl.html
* Company: ULB<p>
* @author Ari Loytynoja
* @version 1.0
*/
package proalign;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
// Print a curve on a JPanel.
//
public class PrintMinimumCurve extends JPanel {
double[] minProb;
String[] nodes;
int height = 100;
int xScale = 2; // scale: pixels per column.
PrintMinimumCurve pc;
MinimumProbWindow qw;
PrintMinimumCurve(MinimumProbWindow qw, double[] minProb, String[] nodes) {
pc = this;
this.qw = qw;
this.minProb = minProb;
this.nodes = nodes;
setBackground(Color.white);
setForeground(Color.black);
setPreferredSize(new Dimension(xScale*minProb.length, height));
addMouseListener(new MiceListener());
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
super.paintComponent(g2); //clears the background
height = pc.qw.getVisibleHeight();
pc.setPreferredSize(new Dimension(xScale*minProb.length, height));
for(int i=0; i<minProb.length-1; i++) {
int y1 = (int) (Math.exp(minProb[i])*height);
int y2 = (int) (Math.exp(minProb[i+1])*height);
if(y1>0 && y2>0) {
g2.drawLine(i*xScale,height-y1,(i+1)*xScale,height-y2);
}
}
}
// Listens mouse click: focus alignment, update messageText.
//
class MiceListener extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
int x = e.getX();
int y = e.getY();
qw.rw.focusAlignment(x/xScale);
qw.rw.messageText.setText(" Minimum posterior probability "+
(""+Math.exp(minProb[x/xScale])+" ").substring(0,5)+
" at "+nodes[x/xScale]+".");
}
}
}
|