3 import javax.swing.*;
\r
4 import java.awt.event.*;
\r
5 import java.awt.image.*;
\r
8 public class OverviewPanel extends JPanel
\r
10 BufferedImage miniMe;
\r
16 int sequencesWidth, sequencesHeight;
\r
18 int boxX=-1, boxY=-1, boxWidth=-1, boxHeight=-1;
\r
20 public OverviewPanel(AlignmentPanel ap, AlignViewport av)
\r
25 // scale the initial size of overviewpanel to shape of alignment
\r
27 float initialScale = (float)av.getAlignment().getWidth()/(float)av.getAlignment().getHeight();
\r
28 if(av.getAlignment().getWidth() > av.getAlignment().getHeight())
\r
31 sequencesWidth = 400;
\r
32 sequencesHeight = (int)(400f/initialScale);
\r
37 sequencesWidth = (int)(400f*initialScale);
\r
38 sequencesHeight = 300;
\r
43 setSize(sequencesWidth, sequencesHeight+graphHeight);
\r
46 updateOverviewImage();
\r
48 addComponentListener(new ComponentAdapter()
\r
51 public void componentResized(ComponentEvent evt)
\r
53 if( getWidth()!=sequencesWidth || getHeight()!=sequencesHeight+graphHeight)
\r
54 updateOverviewImage();
\r
59 addMouseMotionListener(new MouseMotionAdapter()
\r
61 public void mouseDragged(MouseEvent evt)
\r
62 { doMouseDragged(evt);}
\r
65 addMouseListener(new MouseAdapter()
\r
67 public void mousePressed(MouseEvent evt)
\r
68 { doMousePressed(evt);}
\r
69 public void mouseReleased(MouseEvent evt)
\r
70 { doMouseReleased(evt);}
\r
75 public void doMousePressed(MouseEvent evt)
\r
77 checkValid(evt.getX(), evt.getY());
\r
81 public void doMouseReleased(MouseEvent evt)
\r
86 ap.setScrollValues( (int)(x/scalew/av.getCharWidth()), (int)(y/scaleh/av.getCharHeight()) );
\r
89 public void doMouseDragged(MouseEvent evt)
\r
94 ap.setScrollValues( (int)(x/scalew/av.getCharWidth()), (int)(y/scaleh/av.getCharHeight()) );
\r
98 void checkValid(int x, int y)
\r
103 if (y > sequencesHeight - boxHeight)
\r
104 y = sequencesHeight- boxHeight;
\r
110 if (x > sequencesWidth - boxWidth)
\r
111 x = sequencesWidth - boxWidth;
\r
117 public void updateOverviewImage()
\r
120 boolean oldRenderGaps = av.renderGaps;
\r
121 av.setRenderGaps(false);
\r
123 setPreferredSize (new Dimension(sequencesWidth, sequencesHeight+graphHeight));
\r
124 sequencesWidth=getWidth();
\r
125 sequencesHeight=this.getHeight()-graphHeight;
\r
128 int fullsizeWidth = av.getAlignment().getWidth() * av.getCharWidth();
\r
129 int fullsizeHeight = av.getAlignment().getHeight()* av.getCharHeight();
\r
132 BufferedImage fullSize = new BufferedImage(fullsizeWidth,
\r
134 BufferedImage.TYPE_INT_RGB);
\r
136 BufferedImage consensus = new BufferedImage(fullsizeWidth,
\r
138 BufferedImage.TYPE_INT_RGB);
\r
141 Graphics g = fullSize.getGraphics();
\r
142 ap.seqPanel.seqCanvas.drawPanel(g,0,av.getAlignment().getWidth(),0,av.getAlignment().getHeight(),0,0,0);
\r
144 g = consensus.getGraphics();
\r
145 ap.scorePanel.drawScorePanel(g, fullsizeWidth, 0, av.getAlignment().getWidth());
\r
148 miniMe = new BufferedImage(sequencesWidth, sequencesHeight + graphHeight,
\r
149 BufferedImage.TYPE_INT_RGB);
\r
150 Graphics mg = miniMe.getGraphics();
\r
152 mg.drawImage(fullSize, 0, 0, sequencesWidth, sequencesHeight, 0, 0,
\r
153 fullsizeWidth, fullsizeHeight, this);
\r
154 mg.drawImage(consensus, 0, sequencesHeight, sequencesWidth,
\r
155 sequencesHeight + graphHeight, 0, 0, fullsizeWidth, 60, this);
\r
157 scalew = (float) sequencesWidth / (float) fullsizeWidth;
\r
158 scaleh = (float) sequencesHeight / (float) fullsizeHeight;
\r
161 }catch(Exception ex)
\r
162 {// most likely the frame size is zero
\r
166 av.setRenderGaps(oldRenderGaps);
\r
170 public void setBoxPosition()
\r
172 boxX = (int) (av.getStartRes() * av.getCharWidth() * scalew);
\r
173 boxY = (int) (av.getStartSeq() * av.getCharHeight() * scaleh);
\r
174 boxWidth = (int) (av.getEndRes() * av.getCharWidth() * scalew) - boxX;
\r
175 boxHeight = (int) (av.getEndSeq() * av.getCharHeight() * scaleh) - boxY;
\r
181 public void paintComponent(Graphics g)
\r
183 g.setColor(Color.white);
\r
184 g.fillRect(0,0,getWidth(),getHeight());
\r
186 g.drawImage(miniMe, 0,0,this);
\r
188 g.setColor(Color.red);
\r
190 g.drawRect(boxX, boxY, boxWidth, boxHeight);
\r
191 g.drawRect(boxX+1, boxY+1, boxWidth-2, boxHeight-2);
\r