⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dnadraw.java

📁 emboss的linux版本的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/**********************************************************************  This library is free software; you can redistribute it and/or*  modify it under the terms of the GNU Library General Public*  License as published by the Free Software Foundation; either*  version 2 of the License, or (at your option) any later version.**  This library is distributed in the hope that it will be useful,*  but WITHOUT ANY WARRANTY; without even the implied warranty of*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU*  Library General Public License for more details.**  You should have received a copy of the GNU Library General Public*  License along with this library; if not, write to the*  Free Software Foundation, Inc., 59 Temple Place - Suite 330,*  Boston, MA  02111-1307, USA.**  @author: Copyright (C) Tim Carver*********************************************************************/package org.emboss.jemboss.draw;import javax.swing.*;import java.awt.*;import java.awt.print.*;import java.awt.event.*;import java.awt.geom.AffineTransform;import java.util.*;import java.awt.datatransfer.*;import java.awt.dnd.*;import java.net.URL;import org.emboss.jemboss.gui.ScrollPanel;import org.emboss.jemboss.gui.Browser;public class DNADraw extends ScrollPanel                     implements Printable, DragGestureListener,                     DragSourceListener, DropTargetListener{  public static JScrollPane jsp;  private DNADraw current_dna;  private JFrame mainFrame;  private Point location    = new Point(75,75);  private Dimension border  = new Dimension(150,150);  private Dimension panelSize = new Dimension(600,600);  private Dimension linearPanelSize = new Dimension(800,350);  private Hashtable lineAttr;  private Vector minorTicks;  private Vector majorTicks;  private Vector block;  private Vector restrictionEnzyme;  private int startTick    = 0;  private int minorTick    = 100;  private int majorTick    = 500;//// store the tick positions -- there appears to be// a bug in AffineTransform when it comes to using// elements from the matrix when printing//  private int[] tickMajorXPositions;  private int[] tickMajorYPositions;  private int[] tickMinorXPositions;  private int[] tickMinorYPositions;  private int[] reXPositions;  private int[] reYPositions;  private boolean close = false;  public DNADraw()  {    super(new BorderLayout());     current_dna = this;    setBackground(Color.white);    setPreferredSize(panelSize);    setOpaque(false);    DragSource dragSource = DragSource.getDefaultDragSource();    dragSource.createDefaultDragGestureRecognizer(       this,                             // component where drag originates       DnDConstants.ACTION_COPY_OR_MOVE, // actions       this);          setDropTarget(new DropTarget(this,this));    lineAttr = new Hashtable();    lineAttr.put("start",new Integer(0));    lineAttr.put("end",new Integer(4000));    lineAttr.put("lsize",new Integer(5));    lineAttr.put("circular",new Boolean(true));    MouseListener mouseListener = new MouseAdapter()    {      public void mouseClicked(MouseEvent me)      {        if(me.getClickCount() == 2 &&           !me.isPopupTrigger())        {          for(int i=0; i<getComponentCount(); i++)          {            if(getComponent(i) instanceof Block)            {              final Block drawBlock = (Block)getComponent(i);              if(drawBlock.isOverMe(me.getX(),me.getY()))              {                final JFrame f = new JFrame("Properties");                JButton butt = new JButton("Delete");                butt.addActionListener(new ActionListener()                {                  public void actionPerformed(ActionEvent e)                  {                    remove(drawBlock);                    current_dna.repaint();                     f.setVisible(false);                    f.dispose();                           Enumeration enumBk = block.elements();                    int nelement = 0;                    while(enumBk.hasMoreElements())                    {                      Vector v = (Vector)enumBk.nextElement();                      if(v.contains(drawBlock))                        block.removeElementAt(nelement);                         nelement++;                    }                  }                });                 drawBlock.showProperties(f,DNADraw.this,butt);              }            }          }        }      }    };    this.addMouseListener(mouseListener);  }  public DNADraw(Vector minorTicks, Vector majorTicks,                 Vector block,                 Vector restrictionEnzyme)  {    this();    this.minorTicks = minorTicks;    this.block = block;    this.restrictionEnzyme = restrictionEnzyme;  }  public DNADraw(Vector block, Vector restrictionEnzyme,                 Hashtable lineAttr, int startTick,                 int minorTick, int majorTick)  {    this();    this.block = block;    this.restrictionEnzyme = restrictionEnzyme;    this.lineAttr     = lineAttr;    this.startTick    = startTick;    this.minorTick    = minorTick;    this.majorTick    = majorTick;    if(!isCircular())      setPreferredSize(linearPanelSize);        calculateTickPosistions();  }  /**  *  * Get the width/diameter of the DNA map  *  */  protected double getDiameter()  {    return getWidth()-border.getWidth();  }  protected Point getLocationPoint()  {    return location;  }  protected void zoomIn()  {    int wid = getWidth();    wid     = wid+(int)(wid*0.1);    int hgt = getHeight();    if(isCircular())      hgt = hgt+(int)(hgt*0.1);    zoom(wid,hgt);  }  protected void zoomOut()  {    int wid = getWidth();    wid     = wid-(int)(wid*0.1);    int hgt = getHeight();      if(isCircular())      hgt = hgt-(int)(hgt*0.1);    zoom(wid,hgt);  }    private void zoom(int wid, int hgt)  {    if(isCircular())    {      panelSize = new Dimension(wid,hgt);      setPreferredSize(panelSize);      setSize(panelSize);    }    else    {      linearPanelSize = new Dimension(wid,hgt);      setPreferredSize(linearPanelSize);      setSize(linearPanelSize);    }    repaint();  }    protected void paintComponent(Graphics g)  {    super.paintComponent(g);    Graphics2D g2 = (Graphics2D)g;    if(isCircular())      drawCircularPanel(g2,true);    else      drawLinearPanel(g2);  }  protected boolean isCircular()  {    return ((Boolean)lineAttr.get("circular")).booleanValue();  }  protected void addBlock(Block b)  {    add(b);    validate();  }  protected void drawLinearPanel(Graphics2D g2)  {    FontMetrics fm = g2.getFontMetrics();    double hgt = fm.getAscent();    g2.setColor(Color.black);    double widDash = 4;    int lineSize = 5;    try    {      lineSize = getLineSize();    }    catch(NullPointerException npe)    {      System.out.println("No line size specified using default!");    }    g2.setStroke(new BasicStroke((float)lineSize));    double widthPanel  = getWidth();    double ddiameter  = widthPanel-border.getWidth();    int diameter = (int)ddiameter;    int ymid = getHeight()/2;    g2.setStroke(new BasicStroke((float)lineSize));    g2.drawLine(location.x,ymid,                diameter,ymid);       int start = getStart();    int end   = getEnd();    g2.setColor(Color.black);    g2.setStroke(new BasicStroke(1.f));    if(majorTicks == null || minorTicks == null)      calculateTickPosistions();    Enumeration enumTk = minorTicks.elements();    while(enumTk.hasMoreElements())    {      int tick = ((Integer)enumTk.nextElement()).intValue();      int x = ((diameter-location.x)*(tick-start)/(end-start))+location.x;      int y = ymid+(int)((lineSize+widDash)/2);      g2.drawLine(x,ymid,x,y);    }    enumTk = majorTicks.elements();    while(enumTk.hasMoreElements())    {      int tick = ((Integer)enumTk.nextElement()).intValue();      int x = ((diameter-location.x)*(tick-start)/(end-start))+location.x;      int y = ymid+(lineSize/2)+(int)widDash;      g2.drawLine(x,ymid,x,y);      String label = Integer.toString(tick);      x-=(fm.stringWidth(label)/2);      y+=hgt;      g2.drawString(label,x,y);    }    if(restrictionEnzyme != null)    {      enumTk = restrictionEnzyme.elements();      while(enumTk.hasMoreElements())      {        Vector re = (Vector)enumTk.nextElement();        String reLabel = (String)re.elementAt(0);        int pos = ((Integer)re.elementAt(1)).intValue();        g2.setColor((Color)re.elementAt(2));        int x = ((diameter-location.x)*(pos-start)/(end-start))+location.x;        int y = ymid-(lineSize/2)-(int)widDash;        g2.drawLine(x,ymid,x,y);        x-=(fm.stringWidth(reLabel)/2);        y-=hgt;        g2.drawString(reLabel,x,y);      }    }  }  protected void drawCircularPanel(Graphics2D g2, boolean record)  {    g2.setColor(Color.black);     FontMetrics fm = g2.getFontMetrics();    double hgt = fm.getAscent();    double widthPanel  = getWidth();     double heightPanel = getHeight();    double rad = 360.d;    double pi  = Math.PI;    double widDash = 4;    double ddiameter  = widthPanel-border.getWidth();    double ddiameter2 = ddiameter/2.d;    int diameter = (int)ddiameter;    int lineSize = 5;    try    {      lineSize = getLineSize();    }    catch(NullPointerException npe)    {      System.out.println("No line size specified using default!");    }    g2.setStroke(new BasicStroke((float)lineSize));    g2.drawArc(location.x,location.y,               diameter,diameter,0,360);    AffineTransform origin = g2.getTransform();    AffineTransform newOrig;    if(restrictionEnzyme != null)    {      if(record)      {        int nsize = restrictionEnzyme.size();        reXPositions = new int[nsize];        reYPositions = new int[nsize];      }      Enumeration enumRes = restrictionEnzyme.elements();      while(enumRes.hasMoreElements())      {        Vector re = (Vector)enumRes.nextElement();        String reLabel = (String)re.elementAt(0);        int pos = ((Integer)re.elementAt(1)).intValue();        g2.setColor((Color)re.elementAt(2));        double ang = getAngleFromPosition(pos,rad);        newOrig = (AffineTransform)(origin.clone());        newOrig.rotate(Math.toRadians(-ang),                       widthPanel/2.d,heightPanel/2.d);        int widLabel  = (lineSize+fm.stringWidth(reLabel))/2;        int widREDash = (int)(widDash+widDash+lineSize)+widLabel;        int x = 0;        int y = 0;        if(record)        {          x = (int)( ddiameter2 + (newOrig.getScaleX()*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -