import charite.christo.strap.StrapProtein;
import charite.christo.strap.DrawGappedSequence;
import charite.christo.strap.ResidueAnnotation;
import charite.christo.protein.ShadingAA;
import java.awt.Color;
import java.awt.Point;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/*
java DemoDrawGappedSequence
The method DrawGappedSequence#paintComponent is used to draw the sequence into a JComponent.
*/
public class DemoDrawGappedSequence {
private static StrapProtein p;
public static void main(String[] argv){
/* make a protein with a gapped sequence */
p=new StrapProtein();
p.setGappedSequence("ASDFGH JKLQWERTZUIOyxcvbnmAAAAAAAACCCCCCCCCWWWWWWWWWWWWWWW");
/* Add a green selection to the protein. The selection gets a reference to the protein. */
ResidueAnnotation s=new ResidueAnnotation(p);
p.addResidueSelection(s);
/* The selection spans residues 3 to 5. */
/* For PDB-structures you can give selections in rasmol-syntax. */
s.setSelectedAminoacids("3-5");
s.setColor(Color.GREEN);
/* Display the sequence in a JPanel */
/* It is necessary to overwrite the paintComponent method. */
final JPanel panel=new JPanel(){
final Point origin=new Point(0,0);
/* Overwriting the paint-method */
public void paintComponent(Graphics g) {
super.paintComponent(g);// background
/* ShadingAA.CHEMICAL paints each residue depending on its chemical nature. */
/* If the secondary structure is given in the protein file (PDB-format, DSSP-format) */
/* then the amino acids can also be shaded according to secondary structure (last parameter=true). */
new DrawGappedSequence().draw(this,g,origin,p,ShadingAA.CHEMICAL,DrawGappedSequence.SHADE_SEC_STRU);
}
/* The JScrollPane needs to know the size of its child: */
/* The panel size depends on the font and the horizontal position (max. column) of the last residue. */
@Override public Dimension getPreferredSize() {
final FontMetrics fm=getFontMetrics(getFont());
final int charA=fm.getAscent(),charD=fm.getDescent(),charW=fm.charWidth('X'),charH=charA+charD;
return new Dimension(charW*(p.getMaxColumn()+1),charH);
}
};
panel.setBackground(Color.BLACK);
/* enlarge font */
panel.setFont(new Font("Monospaced",Font.PLAIN,50));
/* display it in a JFrame */
final JFrame f=new JFrame();
f.setSize(300,100);
f.getContentPane().add(new JScrollPane(panel));
f.show();
}
}