package jalview.gui; import jalview.jbgui.*; import java.util.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ScorePanel extends JPanel { AlignViewport av; public ScorePanel(AlignViewport a) { av = a; setPreferredSize(new Dimension(500,80)); addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent evt) { doMouseMoved(evt); } }); ToolTipManager.sharedInstance().registerComponent(this); } public void doMouseMoved(MouseEvent evt) { Vector freq = av.getConsensus(false); int col = (int)(evt.getX()/av.charWidth) +av.getStartRes(); if(col >= av.getEndRes() || col >= freq.size()) return; Hashtable hash = (Hashtable) freq.elementAt( col ); String characters = hash.get("maxResidue").toString(); if (characters.length()>1) this.setToolTipText(characters); else this.setToolTipText(null); } public void paintComponent(Graphics g) { setPreferredSize(new Dimension( this.getWidth(), 80)); drawScorePanel(g, getWidth(), av.getStartRes(), av.getChunkWidth()); } public void drawScorePanel(Graphics g, int width, int startRes, int length) { g.setColor(Color.white); g.fillRect(0, 0,width, 80); g.setColor(Color.blue); g.setFont(av.getFont()); Vector freq = av.getConsensus(false); int value, charOffset; String characters; char character; int i=0, iSize = length; if(iSize > freq.size()) iSize=freq.size(); for (i = 0; i < iSize; i++) { g.setColor(Color.blue); Hashtable hash = (Hashtable) freq.elementAt(i+startRes); if(hash.containsKey("maxResidue")) characters = hash.get("maxResidue").toString(); else characters="@"; character = characters.charAt(0); value = Integer.parseInt(hash.get("maxCount").toString()); if (characters.length() > 1) character = '+'; charOffset = (int) (av.charWidth - g.getFontMetrics().charWidth(character)) / 2; g.drawString(character + "", charOffset + (int) (i * av.charWidth), 60 + (int) av.charWidth); value = (int) ( (float) value / Float.parseFloat(hash.get("size").toString()) * 55); if ( !jalview.util.Comparison.isGap(character)) g.fillRect( (int) (i * av.charWidth), 60 - value, (int) av.charWidth, value ); } } }