protected void wrapMenuItem_actionPerformed(ActionEvent e)\r
{\r
viewport.setWrapAlignment( wrapMenuItem.isSelected() );\r
- alignPanel.RefreshPanels();\r
+ alignPanel.setWrapAlignment( wrapMenuItem.isSelected() );\r
}\r
\r
\r
\r
public void setWrapAlignment(boolean wrap)\r
{\r
- scalePanelHolder.setVisible(!wrap);\r
- scorePanelHolder.setVisible(!wrap);\r
+ scorePanelHolder.setVisible(!wrap);\r
+ scalePanelHolder.setVisible(!wrap);\r
+ secondaryPanelHolder.setVisible(!wrap);\r
+\r
+ hscroll.setVisible(!wrap);\r
+\r
+ idSpaceFillerPanel.setVisible(!wrap);\r
+ idSpaceFillerPanel1.setVisible(!wrap);\r
+\r
+ RefreshPanels();\r
\r
- hscroll.setVisible(!wrap);\r
- idSpaceFillerPanel.setVisible(!wrap);\r
- idSpaceFillerPanel1.setVisible(!wrap);\r
}\r
\r
\r
seqPanel.seqCanvas.paintFlag = true;\r
idPanel.idCanvas.paintFlag = true;\r
idPanelHolder.setPreferredSize( idPanel.idCanvas.getPreferredSize() );\r
+\r
+ if(av.getWrapAlignment())\r
+ {\r
+ int max = av.alignment.getWidth()/ (seqPanel.seqCanvas.getWidth()/av.charWidth)+1;\r
+\r
+ int h = (av.alignment.getHeight() + 2)*av.charHeight;\r
+ vextent = seqPanel.seqCanvas.getHeight()/h;\r
+ vscroll.setValues(0,vextent,0,max);\r
+ }\r
+ else\r
+\r
setScrollValues(av.getStartRes(), av.getStartSeq());\r
av.getConsensus(true);\r
if(overviewPanel!=null)\r
\r
if (evt.getSource() == vscroll)\r
{\r
- int offy = vscroll.getValue();\r
+ int offy = vscroll.getValue();\r
+ if (av.getWrapAlignment())\r
+ {\r
+ av.setStartRes( vscroll.getValue() * av.getChunkWidth());\r
+ // System.out.println(vscroll.getValue()+" "+ av.getChunkWidth());\r
+ // int resSpan = av.alignment.getWidth()/ (seqPanel.seqCanvas.getWidth()/av.charWidth)+1;\r
+ // int h = (av.alignment.getHeight() + 2)*av.charHeight;\r
+ // vextent = seqPanel.seqCanvas.getHeight()/h;\r
+ // vscroll.setValues(0,vextent,0,max);\r
+\r
+\r
+ // av.setStartSeq( );\r
+ }\r
+ else\r
+ {\r
av.setStartSeq(offy);\r
- av.setEndSeq(offy + seqPanel.seqCanvas.getHeight()/av.getCharHeight());\r
+ av.setEndSeq(offy + seqPanel.seqCanvas.getHeight() / av.getCharHeight());\r
+ }\r
}\r
\r
\r
}\r
\r
\r
+\r
public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException\r
{\r
+ if(av.getWrapAlignment())\r
+ {\r
+ return PrintWrappedAlignment(pg, pf, pi);\r
+ }\r
\r
pg.translate((int)pf.getImageableX(), (int)pf.getImageableY());\r
\r
int pheight = (int)pf.getImageableHeight();\r
int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth();\r
\r
+\r
pg.setColor(Color.white);\r
pg.fillRect(0,0,pwidth, pheight);\r
pg.setFont( av.getFont() );\r
return Printable.PAGE_EXISTS;\r
}\r
\r
+ class VPanel extends javax.swing.JPanel\r
+ {\r
+ Image image;\r
+ public VPanel(Image i)\r
+ {\r
+ image = i;\r
+ repaint();\r
+ }\r
+ public void paintComponent(Graphics g)\r
+ {\r
+ if(image!=null)\r
+ g.drawImage(image,0,0,this);\r
+ }\r
+\r
+ }\r
+\r
+ public int PrintWrappedAlignment(Graphics pg, PageFormat pf, int pi)\r
+ {\r
+ pg.translate((int)pf.getImageableX(), (int)pf.getImageableY());\r
+\r
+ int pwidth = (int)pf.getImageableWidth();\r
+ int pheight = (int)pf.getImageableHeight();\r
+ int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth();\r
+\r
+ if( seqPanel.seqCanvas.getWidth() < pwidth-idWidth)\r
+ pwidth = seqPanel.seqCanvas.getWidth() + idWidth;\r
+\r
+ Image image = createImage(pwidth, pheight);\r
+ pg = image.getGraphics();\r
+\r
+ pg.setColor(Color.white);\r
+ pg.fillRect(0,0,pwidth, pheight);\r
+ pg.setFont( av.getFont() );\r
+\r
+ ////////////////////////////////////\r
+ /// How many sequences and residues can we fit on a printable page?\r
+ AlignmentI da = av.alignment;\r
+ int endy = da.getHeight();\r
+ int chunkHeight = (da.getHeight() + 2)*av.charHeight;\r
+ int chunkWidth = (pwidth-idWidth)/av.charWidth;\r
+\r
+ int noChunksOnPage = pheight / chunkHeight;\r
+ int totalChunks = endy / chunkHeight;\r
+\r
+ if ( pi*noChunksOnPage > totalChunks )\r
+ return Printable.NO_SUCH_PAGE;\r
+\r
+ ////////////////\r
+ // Draw the ids\r
+ pg.setClip(0,0,pwidth, noChunksOnPage*chunkHeight);\r
+\r
+ int row = pi*noChunksOnPage;\r
+ pg.setColor(Color.black);\r
+ for(int ypos=2*av.charHeight;\r
+ ypos <= pheight && row*chunkWidth<da.getWidth();\r
+ ypos += chunkHeight, row++ )\r
+ {\r
+ for (int i = 0; i < endy; i++)\r
+ {\r
+ SequenceI s = da.getSequenceAt(i);\r
+ pg.drawString(s.getDisplayId(), 0,\r
+ AlignmentUtil.getPixelHeight(0, i, av.charHeight) + ypos +\r
+ av.charHeight - (av.charHeight / 5));\r
+ }\r
+ }\r
+\r
+ // draw main sequence panel\r
+ pg.translate(idWidth,0);\r
+ seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth-idWidth, pheight, pi*noChunksOnPage*chunkWidth);\r
+\r
+\r
+ javax.swing.JFrame frame = new javax.swing.JFrame();\r
+ frame.setSize(image.getWidth(null), image.getHeight(null));\r
+ frame.setVisible(true);\r
+ frame.getContentPane().setLayout(new BorderLayout());\r
+ VPanel pan = new VPanel(image);\r
+ frame.getContentPane().add(pan, BorderLayout.CENTER);\r
+ frame.validate();\r
+ return Printable.NO_SUCH_PAGE;//.PAGE_EXISTS;\r
+\r
+ }\r
}\r
\r
\r
\r
//Which ids are we printing\r
int starty = av.getStartSeq();\r
- int endy = av.getEndSeq();\r
+ int endy = da.getHeight();\r
\r
if (av.getWrapAlignment())\r
{\r
- starty = starty%av.getChunkHeight();\r
+ // Draw the rest of the panels\r
+ int chunkHeight = (da.getHeight() + 2)*av.charHeight;\r
+ int row = av.getStartRes() / av.chunkWidth ;\r
+ for(int ypos=2*av.charHeight;\r
+ ypos <= getHeight() && row*av.chunkWidth<da.getWidth();\r
+ ypos += chunkHeight, row++ )\r
+ {\r
+ for (int i = starty; i < endy; i++)\r
+ {\r
+ SequenceI s = da.getSequenceAt(i);\r
+ drawIdString(gg, s, i, 0, ypos);\r
+ }\r
+ }\r
\r
- int ypos = 0;\r
- int rowstart = starty;\r
\r
- if (starty == 0)\r
- ypos = 2*charHeight;\r
- else if (starty == 1)\r
- {\r
- starty = 0;\r
- ypos = charHeight;\r
- }\r
-\r
- endy = starty + da.getHeight();\r
-\r
- if (endy > da.getHeight()) {\r
- endy = da.getHeight();\r
- }\r
-\r
- for (int i = starty; i < endy; i++) {\r
- SequenceI s = da.getSequenceAt(i);\r
- drawIdString(gg,s,i,starty,ypos);\r
- }\r
- if (rowstart == 0) {\r
- ypos = ypos + av.getChunkHeight();\r
- } else if (rowstart == 1) {\r
- ypos = ypos + av.getChunkHeight();\r
- } else {\r
- ypos = ypos + av.getChunkHeight() - rowstart*charHeight;\r
- }\r
-\r
- starty = 0;\r
-\r
- int chunkwidth = av.getChunkWidth();\r
- int startx = (int)(av.getEndSeq()/chunkwidth)*chunkwidth;\r
- int endx = startx + chunkwidth;\r
-\r
-\r
- while (ypos <= getHeight() && endx < da.getWidth()) {\r
-\r
- for (int i = starty; i < endy; i++) {\r
- SequenceI s = da.getSequenceAt(i);\r
- drawIdString(gg,s,i,starty,ypos);\r
- }\r
-\r
- ypos += av.getChunkHeight();\r
- startx += chunkwidth;\r
- endx = startx + chunkwidth;\r
-\r
- if (endx > da.getWidth()) {\r
- endx = da.getWidth();\r
- }\r
-\r
- starty = 0;\r
-\r
- if (endy > da.getHeight()) {\r
- endy = da.getHeight();\r
- }\r
-\r
- }\r
} else\r
{\r
\r
\r
public void mouseDragged(MouseEvent e) {\r
int y = e.getY();\r
+ if(av.getWrapAlignment())\r
+ y-=2*av.charHeight;\r
int seq = av.getIndex(y);\r
\r
if (seq < lastid)\r
{\r
if (e.getClickCount() == 2)\r
{\r
- int seq = av.getIndex(e.getY());\r
+ int y = e.getY();\r
+ if(av.getWrapAlignment())\r
+ y-=2*av.charHeight;\r
+\r
+ int seq = av.getIndex(y);\r
String id = av.getAlignment().getSequenceAt(seq).getName();\r
\r
try{\r
return;\r
\r
int y = e.getY();\r
+ if(av.getWrapAlignment())\r
+ y-=2*av.charHeight;\r
+\r
int seq = av.getIndex(y);\r
\r
if (javax.swing.SwingUtilities.isRightMouseButton(e))\r
\r
}\r
\r
- public void drawScale(int startx, int endx,int charWidth, int charHeight,int ypos) {\r
+ public void drawScale(Graphics g, int startx, int endx,int ypos) {\r
int scalestartx = startx - startx%10 + 10;\r
\r
- gg.setColor(Color.black);\r
+ g.setColor(Color.black);\r
+\r
+ for (int i=scalestartx;i < endx;i+= 10)\r
+ {\r
+ String string = String.valueOf(i);\r
+ g.drawString(string,(i-startx-1)*av.charWidth,ypos - av.charHeight/2);\r
+\r
+ g.drawLine( (i-startx-1)*av.charWidth +av.charWidth/2, ypos+2 - av.charHeight/2,\r
+ (i-startx-1)*av.charWidth +av.charWidth/2, ypos-2 );\r
\r
- for (int i=scalestartx;i < endx;i+= 10) {\r
- String string = String.valueOf(i);\r
- gg.drawString(string,(int)((i-startx-1)*charWidth),ypos+15 - charHeight*(2));\r
}\r
+\r
}\r
\r
\r
* in the adjustment listener in SeqPanel when the scrollbars move.\r
*/\r
\r
- public void paintComponent(Graphics g) {\r
-\r
- AlignmentI da = av.getAlignment();\r
+ public void paintComponent(Graphics g)\r
+ {\r
\r
- if (img == null ||\r
- imgWidth != getWidth() ||\r
- imgHeight != getHeight()\r
- || paintFlag)\r
+ if (img==null || imgWidth!=getWidth() || imgHeight!=getHeight() || paintFlag)\r
{\r
-\r
imgWidth = getWidth();\r
imgHeight = getHeight();\r
-\r
img = createImage(imgWidth,imgHeight);\r
gg = img.getGraphics();\r
-\r
gg.setFont(av.getFont());\r
-\r
paintFlag = false;\r
}\r
\r
+\r
chunkWidth = getWidth()/av.charWidth;\r
- chunkHeight = (da.getHeight() + 2)*av.charHeight;\r
+ chunkHeight = (av.getAlignment().getHeight() + 2)*av.charHeight;\r
\r
av.setChunkHeight(chunkHeight);\r
av.setChunkWidth(chunkWidth);\r
\r
-\r
-\r
fillBackground(gg,Color.WHITE,0,0,imgWidth,imgHeight);\r
\r
- /* if (av.getWrapAlignment()) {\r
- int offy = av.getStartSeq();\r
- startx = (int)(offy/chunkWidth)*chunkWidth;\r
- endx = startx + chunkWidth;\r
- starty = offy%chunkHeight;\r
- endy = starty + da.getHeight();\r
-\r
- int ypos = 0;\r
- int rowstart = starty;\r
-\r
- if (starty == 0) {\r
- ypos = 2*charHeight;\r
- } else if (starty == 1) {\r
- starty = 0;\r
- ypos = charHeight;\r
- }\r
-\r
- if (endy > da.getHeight()) {\r
- endy = da.getHeight();\r
- }\r
-\r
- if (endx > da.getWidth()) {\r
- endx = da.getWidth();\r
- }\r
-\r
- if (rowstart < 2) {\r
- drawScale(startx,endx,charWidth,charHeight,ypos);\r
- }\r
-\r
- drawPanel(gg,startx,endx,starty,endy,startx,starty,ypos);\r
-\r
- if (rowstart == 0) {\r
- ypos = ypos + chunkHeight;\r
- } else if (rowstart == 1) {\r
- ypos = ypos + chunkHeight;\r
- } else {\r
- ypos = ypos + chunkHeight - rowstart*charHeight;\r
- }\r
-\r
- startx += chunkWidth;\r
- endx = startx + chunkWidth;\r
- starty = 0;\r
-\r
- if (endx > da.getWidth()) {\r
- endx = da.getWidth();\r
- }\r
- // Draw the rest of the panels\r
-\r
- while (ypos <= getHeight()) {\r
- drawScale(startx,endx,charWidth,charHeight,ypos);\r
- drawPanel(gg,startx,endx,0,da.getHeight(),startx,starty,ypos);\r
-\r
- ypos += chunkHeight;\r
- startx += chunkWidth;\r
- endx = startx + chunkWidth;\r
-\r
- if (endy > da.getHeight()) {\r
- endy = da.getHeight();\r
- }\r
-\r
- if (endx > da.getWidth()) {\r
- endx = da.getWidth();\r
- }\r
-\r
- }\r
- }\r
- else*/\r
- {\r
- drawPanel(gg,av.startRes,av.endRes,av.startSeq,av.endSeq,av.startRes,av.startSeq,0);\r
- }\r
-\r
+ if (av.getWrapAlignment())\r
+ drawWrappedPanel(gg, getWidth(), getHeight(), av.startRes);\r
+ else\r
+ drawPanel(gg, av.startRes, av.endRes, av.startSeq, av.endSeq, av.startRes, av.startSeq, 0);\r
\r
- /* if ((oldendy -oldstarty) > (getWidth() / av.getCharWidth())) {\r
- System.out.println("LIMITS ERROR LIMITS ERROR");\r
- System.out.println("Corrds " + (oldendy-oldstarty) + " " + (getWidth()/av.getCharWidth()) + " " + getWidth() + " " + av.getCharWidth());\r
- }*/\r
\r
g.drawImage(img,0,0,this);\r
\r
}\r
\r
+ public void drawWrappedPanel(Graphics g, int canvasWidth, int canvasHeight, int startRes)\r
+ {\r
+ AlignmentI da = av.getAlignment();\r
+\r
+ int cWidth = canvasWidth/av.charWidth;\r
+ int cHeight = (av.getAlignment().getHeight() + 2)*av.charHeight;\r
\r
+ int endx = startRes+cWidth-1;\r
+ int ypos = 2*av.charHeight;\r
+\r
+ while (ypos <= canvasHeight)\r
+ {\r
+ drawScale(g, startRes, endx, ypos);\r
+ drawPanel(g, startRes, endx, 0, da.getHeight(), startRes, 0, ypos);\r
+\r
+ ypos += cHeight;\r
+ startRes += cWidth;\r
+ endx = startRes + cWidth - 1;\r
+\r
+ if (endx > da.getWidth())\r
+ endx = da.getWidth();\r
+ }\r
+\r
+ }\r
\r
\r
public void drawPanel(Graphics g,int x1,int x2, int y1, int y2,int startx, int starty,int offset) {\r
addMouseMotionListener( new MouseMotionAdapter()\r
{\r
public void mouseMoved(MouseEvent evt)\r
- { doMouseMoved(evt); }\r
+ {\r
+ if(av.getWrapAlignment())\r
+ return;\r
+ doMouseMoved(evt); }\r
\r
public void mouseDragged(MouseEvent evt)\r
{\r
+ if(av.getWrapAlignment())\r
+ return;\r
if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown())\r
doMouseDragged(evt);\r
else\r
{\r
public void mouseReleased(MouseEvent evt)\r
{\r
+ if(av.getWrapAlignment())\r
+ return;\r
if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown())\r
doMouseReleased(evt);\r
else\r
}\r
public void mousePressed(MouseEvent evt)\r
{\r
+ if(av.getWrapAlignment())\r
+ return;\r
if(evt.isShiftDown() || evt.isAltDown() || evt.isControlDown())\r
doMousePressed(evt);\r
else\r