📄 dnadraw.java
字号:
(ddiameter2 + 10 + widLabel + widREDash) ) - widLabel ); y = (int)( ddiameter2 + (newOrig.getShearY()* (ddiameter2 + 10 + widREDash + (hgt/2.d)) ) + hgt/2.d ); int index = restrictionEnzyme.indexOf(re); reXPositions[index] = x; reYPositions[index] = y; } else { int index = restrictionEnzyme.indexOf(re); x = reXPositions[index]; y = reYPositions[index]; } g2.drawString(reLabel,location.x+x,location.y+y); g2.setTransform(newOrig); g2.setStroke(new BasicStroke(1.f)); int xLine = location.x+(int)(ddiameter); int yLine = location.y+(int)(ddiameter/2.d); g2.drawLine(xLine,yLine,(int)(xLine+widREDash),yLine); g2.setTransform(origin); } } if(majorTicks == null || minorTicks == null) calculateTickPosistions(); //major ticks drawCircularTicks(g2,ddiameter,ddiameter2,diameter,origin, widthPanel,heightPanel,rad,pi,widDash,fm, lineSize,record,majorTicks,false); //minor ticks drawCircularTicks(g2,ddiameter,ddiameter2,diameter,origin, widthPanel,heightPanel,rad,pi,widDash/2,fm, lineSize,record,minorTicks,true); } private void drawCircularTicks(Graphics2D g2, double ddiameter, double ddiameter2, int diameter, AffineTransform origin, double widthPanel,double heightPanel, double rad, double pi, double widDash, FontMetrics fm, int lineSize, boolean record, Vector ticks, boolean smallTicks) { double hgt = fm.getAscent(); g2.setColor(Color.black); if(record) { int nsize = ticks.size(); if(smallTicks) { tickMinorXPositions = new int[nsize]; tickMinorYPositions = new int[nsize]; } else { tickMajorXPositions = new int[nsize]; tickMajorYPositions = new int[nsize]; } } AffineTransform newOrig; Enumeration enumTk = ticks.elements(); while(enumTk.hasMoreElements()) { int tick = ((Integer)enumTk.nextElement()).intValue(); double theta = Math.toRadians(-getAngleFromPosition(tick,rad)); if(theta > pi) theta = theta - pi*2.d; newOrig = (AffineTransform)(origin.clone()); // rotate and add tick mark newOrig.rotate(theta,widthPanel/2.d,heightPanel/2.d); String label = Integer.toString(tick); double wid = fm.stringWidth(label); int x = 0; int y = 0; if(record) { x = (int)( (ddiameter2) + (newOrig.getScaleX()* (widDash+lineSize+3+(diameter+wid)/2.d)) - (wid/2.d)); y = (int)( (ddiameter2) + (newOrig.getShearY()* (widDash+lineSize+3+(diameter+hgt)/2.d)) + (hgt/2.d)); int index = ticks.indexOf(new Integer(tick)); if(smallTicks) { tickMinorXPositions[index] = x; tickMinorYPositions[index] = y; } else { tickMajorXPositions[index] = x; tickMajorYPositions[index] = y; } } else // use stored positions for printing { int index = ticks.indexOf(new Integer(tick)); if(smallTicks) { x = tickMinorXPositions[index]; y = tickMinorYPositions[index]; } { x = tickMajorXPositions[index]; y = tickMajorYPositions[index]; } } if(!smallTicks) // add tick label g2.drawString(label, location.x+x, location.y+y); g2.setTransform(newOrig); g2.setStroke(new BasicStroke(1.f)); int xLine = location.x+(int)(ddiameter); int yLine = location.y+(int)(ddiameter/2.d); g2.drawLine(xLine,yLine,(int)(xLine+lineSize+widDash),yLine);/* System.out.println("THETA "+Math.toDegrees(theta)); System.out.println("m00 "+newOrig.getScaleX()+ " m01 "+newOrig.getShearX()+ " m02 "+newOrig.getTranslateX()); System.out.println("m10 "+newOrig.getScaleY()+ " m12 "+newOrig.getTranslateY());*/ g2.setTransform(origin); } return; } /** * * Calculate the tick marks to be drawn * */ protected void calculateTickPosistions() { minorTicks = new Vector(); majorTicks = new Vector(); int start = getStart(); int end = getEnd(); if(majorTick == 0) return; for(int i=startTick; i<end; i+=majorTick) if(i >= start) majorTicks.add(new Integer(i)); if(minorTick == 0) return; for(int i=startTick; i<end; i+=minorTick) { Integer tk = new Integer(i); if(i >= start && !majorTicks.contains(tk)) minorTicks.add(tk); } } /** * * Return the position tick marks start at * */ protected int getStartTick() { return startTick; } /** * * Set the position tick marks start at * */ protected boolean setStartTick(int startTick) { this.startTick = startTick; if((startTick >= getStart()) && (startTick < getEnd())) return true; return false; } /** * * Return the interval for the tick marks * */ protected int getTickInterval() { return majorTick; } /** * * Set the interval for the tick marks * */ protected boolean setTickInterval(int majorTick) { if(majorTick < (getEnd()-getStart())) { this.majorTick = majorTick; return true; } return false; } /** * * Return the interval for the tick marks * */ protected int getMinorTickInterval() { return minorTick; } /** * * Set the interval for the tick marks * */ protected boolean setMinorTickInterval(int minorTick) { if(minorTick < (getEnd()-getStart())) { this.minorTick = minorTick; return true; } return false; } /** * * Return an angle in degrees * */ protected double getAngleFromPosition(int pos,double rad) { int start = getStart(); int end = getEnd(); return - ((pos-start)*rad)/(end-start); } /** * * The method @print@ must be implemented for @Printable@ interface. * Parameters are supplied by system. * */ public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { Graphics2D g2 = (Graphics2D)g; g2.setColor(Color.black); //set default foreground color to black RepaintManager.currentManager(this).setDoubleBufferingEnabled(false); Dimension d = this.getSize(); //get size of document double panelWidth = d.width; //width in pixels double panelHeight = d.height; //height in pixels double pageHeight = pf.getImageableHeight(); //height of printer page double pageWidth = pf.getImageableWidth(); //width of printer page double scale = pageWidth/panelWidth; int totalNumPages = (int)Math.ceil(scale * panelHeight / pageHeight); // Make sure not print empty pages if(pageIndex >= totalNumPages) return Printable.NO_SUCH_PAGE; // Shift Graphic to line up with beginning of print-imageable region g2.translate(pf.getImageableX(), pf.getImageableY()); // Shift Graphic to line up with beginning of next page to print g2.translate(0f, -pageIndex*pageHeight); // Scale the page so the width fits... g2.scale(scale, scale); drawAll(g2,false); return Printable.PAGE_EXISTS; } public void drawAll(Graphics2D g2, boolean l) { if(((Boolean)lineAttr.get("circular")).booleanValue()) drawCircularPanel(g2,l); //repaint the page for printing else drawLinearPanel(g2); for(int i=0; i<getComponentCount(); i++) { if(getComponent(i) instanceof Block) { System.out.println("Printing block "+i); ((Block)getComponent(i)).draw(g2); } } } public void doPrintActions() { PrinterJob pj=PrinterJob.getPrinterJob(); pj.setPrintable(this); pj.printDialog(); try { pj.print(); } catch (Exception PrintException) {} } protected void setRestrictionEnzyme(Vector restrictionEnzyme) { this.restrictionEnzyme = restrictionEnzyme; } protected void setGeneticMarker(Vector block) { this.block = block; } protected Hashtable getLineAttributes() { return lineAttr; } protected void setLineAttributes(Hashtable lineAttr) { this.lineAttr = lineAttr; } protected void setLineSize(int lineSize) { lineAttr.put("lsize",new Integer(lineSize)); } protected int getLineSize() { return ((Integer)lineAttr.get("lsize")).intValue(); } public void setPlasmidLocation(int x,int y) { location.setLocation(x,y); } public JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar();// file menu JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu); JMenuItem openMenu = new JMenuItem("Open"); openMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { EmbossCirdnaReader dnaRead = new EmbossCirdnaReader(); block = dnaRead.getBlock(); restrictionEnzyme = dnaRead.getRestrictionEnzyme(); lineAttr.put("start",new Integer(dnaRead.getStart())); lineAttr.put("end",new Integer(dnaRead.getEnd()));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -