1 package fr.orsay.lri.varna.components;
3 import java.awt.BasicStroke;
5 import java.awt.Graphics;
6 import java.awt.Graphics2D;
8 import java.awt.Polygon;
9 import java.awt.Rectangle;
10 import java.awt.RenderingHints;
11 import java.awt.event.MouseEvent;
12 import java.awt.event.MouseListener;
13 import java.awt.event.MouseMotionListener;
14 import java.awt.geom.GeneralPath;
15 import java.awt.geom.Point2D;
16 import java.awt.geom.Rectangle2D;
17 import java.awt.geom.Point2D.Double;
18 import java.awt.image.BufferedImage;
19 import java.awt.image.ImageObserver;
21 import javax.swing.JPanel;
23 import fr.orsay.lri.varna.VARNAPanel;
24 import fr.orsay.lri.varna.models.export.SwingGraphics;
25 import fr.orsay.lri.varna.models.export.VueVARNAGraphics;
27 public class ZoomWindow extends JPanel implements ImageObserver, Runnable, MouseMotionListener, MouseListener {
29 VARNAPanel _vp = null;
30 BufferedImage _bi = null;
31 Rectangle2D.Double rnaRect = null;
33 public ZoomWindow(VARNAPanel vp)
36 addMouseMotionListener(this);
37 addMouseListener(this);
41 public synchronized void setPanel(VARNAPanel vp)
48 public synchronized void drawPanel()
50 if (getWidth()>0 && getHeight()>0)
52 _bi= new BufferedImage(getWidth(),getHeight(),BufferedImage.TYPE_4BYTE_ABGR);
53 Graphics2D g2 = _bi.createGraphics();
54 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
55 RenderingHints.VALUE_ANTIALIAS_ON);
56 VueVARNAGraphics g2D = new SwingGraphics(g2);
57 rnaRect =_vp.renderRNA(g2D,new Rectangle2D.Double(0,0,getWidth(),getHeight()),false,true);
59 Point2D.Double p1 = _vp.panelToLogicPoint(new Point2D.Double(0.,0.));
60 Point2D.Double p2 = _vp.panelToLogicPoint(new Point2D.Double(_vp.getWidth(),_vp.getHeight()));
65 Rectangle2D.Double rnaBox = _vp.getRNA().getBBox();
67 double ratiox = w/rnaBox.width;
68 double ratioy = h/rnaBox.height;
70 Rectangle2D.Double rvisible = new Rectangle2D.Double(rnaRect.x+rnaRect.width*(double)(p1.x-rnaBox.x)/(double)rnaBox.width,
71 rnaRect.y+rnaRect.height*(double)(p1.y-rnaBox.y)/(double)rnaBox.height,
73 ratioy*rnaRect.height);
75 //g2D.drawRect(rleft.x,rleft.y,rleft.width,rleft.height);
77 Color shade = new Color(.9f,.9f,.9f,.4f);
79 g2.setStroke(new BasicStroke(1.0f));
83 /*Polygon north = new Polygon(new int[]{0,getWidth(),(int)rvisible.x,
84 (int)(rvisible.x+rvisible.width+1),},new int[]{},1);*/
85 g2.fillRect(0,0,getWidth(),(int)rvisible.y);
86 g2.fillRect(0,(int)rvisible.y,(int)rvisible.x,(int)rvisible.height+1);
87 g2.fillRect((int)(rvisible.x+rvisible.width),(int)rvisible.y,(int)(getHeight()-(rvisible.x+rvisible.width)),(int)(rvisible.height+1));
88 g2.fillRect(0,(int)(rvisible.y+rvisible.height),getWidth(),(int)(getHeight()-(rvisible.y+rvisible.height)));
90 g2.setColor(new Color(.7f,.7f,.7f,.3f));
96 g2D.drawLine(getWidth(),
98 rvisible.x+rvisible.width,
100 g2D.drawLine(getWidth(),
102 rvisible.x+rvisible.width,
103 rvisible.y+rvisible.height);
107 rvisible.y+rvisible.height);
113 public void paintComponent(Graphics g)
115 setBackground(_vp.getBackground());
116 super.paintComponent(g);
120 g.drawImage(_bi,0,0,this);
130 } catch (InterruptedException e) {
138 public void mouseDragged(MouseEvent e) {
139 // TODO Auto-generated method stub
144 public void mouseMoved(MouseEvent e) {
145 // TODO Auto-generated method stub
150 public void mouseClicked(MouseEvent e) {
155 double ratioX = ((double)(x-rnaRect.getMinX())/((double)rnaRect.width));
156 double ratioY = ((double)(y-rnaRect.getMinY())/((double)rnaRect.height));
157 _vp.centerViewOn(ratioX,ratioY );
162 public void mousePressed(MouseEvent e) {
163 // TODO Auto-generated method stub
168 public void mouseReleased(MouseEvent e) {
169 // TODO Auto-generated method stub
174 public void mouseEntered(MouseEvent e) {
175 // TODO Auto-generated method stub
180 public void mouseExited(MouseEvent e) {
181 // TODO Auto-generated method stub