+ AlignViewport av;\r
+ OverviewPanel overviewPanel;\r
+ SeqPanel seqPanel;\r
+ IdPanel idPanel;\r
+ IdwidthAdjuster idwidthAdjuster;\r
+\r
+ /** DOCUMENT ME!! */\r
+ public AlignFrame alignFrame;\r
+ ScalePanel scalePanel;\r
+ AnnotationPanel annotationPanel;\r
+ AnnotationLabels alabels;\r
+\r
+ // this value is set false when selection area being dragged\r
+ boolean fastPaint = true;\r
+ int hextent = 0;\r
+ int vextent = 0;\r
+\r
+ /**\r
+ * Creates a new AlignmentPanel object.\r
+ *\r
+ * @param af DOCUMENT ME!\r
+ * @param av DOCUMENT ME!\r
+ */\r
+ public AlignmentPanel(AlignFrame af, final AlignViewport av)\r
+ {\r
+ alignFrame = af;\r
+ this.av = av;\r
+ seqPanel = new SeqPanel(av, this);\r
+ idPanel = new IdPanel(av, this);\r
+\r
+ scalePanel = new ScalePanel(av, this);\r
+\r
+ idPanelHolder.add(idPanel, BorderLayout.CENTER);\r
+ idwidthAdjuster = new IdwidthAdjuster(this);\r
+ idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);\r
+\r
+ annotationPanel = new AnnotationPanel(this);\r
+ alabels = new AnnotationLabels(this);\r
+\r
+ annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize());\r
+ annotationScroller.setPreferredSize(annotationPanel.getPreferredSize());\r
+ annotationScroller.setViewportView(annotationPanel);\r
+ annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);\r
+\r
+ fontChanged();\r
+\r
+ scalePanelHolder.add(scalePanel, BorderLayout.CENTER);\r
+ seqPanelHolder.add(seqPanel, BorderLayout.CENTER);\r
+\r
+ setScrollValues(0, 0);\r
+\r
+ hscroll.addAdjustmentListener(this);\r
+ vscroll.addAdjustmentListener(this);\r
+\r
+ setFocusable(true);\r
+ addKeyListener(new KeyAdapter()\r
+ {\r
+ public void keyPressed(KeyEvent evt)\r
+ {\r
+ switch (evt.getKeyCode())\r
+ {\r
+ case 27: // escape key\r
+ av.setSelectionGroup(null);\r
+ repaint();\r
+\r
+ break;\r
+\r
+ case KeyEvent.VK_DOWN:\r
+ alignFrame.moveSelectedSequences(false);\r
+\r
+ break;\r
+\r
+ case KeyEvent.VK_UP:\r
+ alignFrame.moveSelectedSequences(true);\r
+\r
+ break;\r
+\r
+ case KeyEvent.VK_BACK_SPACE:\r
+ case KeyEvent.VK_DELETE:\r
+ alignFrame.cut_actionPerformed(null);\r
+ break;\r
+ }\r
+\r
+ }\r
+ });\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ */\r
+ public void fontChanged()\r
+ {\r
+ // set idCanvas bufferedImage to null\r
+ // to prevent drawing old image\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
+\r
+ scalePanelHolder.setPreferredSize(new Dimension(10,\r
+ av.charHeight + fm.getDescent()));\r
+ idSpaceFillerPanel1.setPreferredSize(new Dimension(10,\r
+ av.charHeight + fm.getDescent()));\r
+\r
+ idPanel.idCanvas.gg = null;\r
+ seqPanel.seqCanvas.img = null;\r
+ annotationPanel.adjustPanelHeight();\r
+\r
+ Dimension d = calculateIdWidth();\r
+ d.setSize(d.width + 4, d.height);\r
+ idPanel.idCanvas.setPreferredSize(d);\r
+ hscrollFillerPanel.setPreferredSize(d);\r
+\r
+ if (av.getWrapAlignment())\r
+ {\r
+ int max = av.alignment.getWidth() /\r
+ seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());\r
+ vscroll.setMaximum(max);\r
+ vscroll.setUnitIncrement(1);\r
+ vscroll.setVisibleAmount(1);\r
+ }\r
+ else\r
+ {\r
+ setScrollValues(av.getStartRes(), av.getStartSeq());\r
+ }\r
+\r
+ if(overviewPanel!=null)\r
+ overviewPanel.setBoxPosition();\r
+\r
+ repaint();\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public Dimension calculateIdWidth()\r
+ {\r
+ Container c = new Container();\r
+\r
+ FontMetrics fm = c.getFontMetrics(av.font);\r
+ AlignmentI al = av.getAlignment();\r
+\r
+ int i = 0;\r
+ int idWidth = 0;\r
+ String id;\r
+\r
+ while ((i < al.getHeight()) && (al.getSequenceAt(i) != null))\r
+ {\r
+ SequenceI s = al.getSequenceAt(i);\r
+\r
+ if (av.getShowFullId())\r
+ {\r
+ id = s.getDisplayId();\r
+ }\r
+ else\r
+ {\r
+ id = s.getName();\r
+ }\r
+\r
+ if (fm.stringWidth(id) > idWidth)\r
+ {\r
+ idWidth = fm.stringWidth(id);\r
+ }\r
+\r
+ i++;\r
+ }\r
+\r
+ // Also check annotation label widths\r
+ i = 0;\r
+\r
+ if (al.getAlignmentAnnotation() != null)\r
+ {\r
+ fm = c.getFontMetrics(alabels.getFont());\r
+\r
+ while (i < al.getAlignmentAnnotation().length)\r
+ {\r
+ String label = al.getAlignmentAnnotation()[i].label;\r
+\r
+ if (fm.stringWidth(label) > idWidth)\r
+ {\r
+ idWidth = fm.stringWidth(label);\r
+ }\r
+\r
+ i++;\r
+ }\r
+ }\r
+\r
+ return new Dimension(idWidth, 12);\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param results DOCUMENT ME!\r
+ */\r
+ public void highlightSearchResults(int[] results)\r
+ {\r
+ seqPanel.seqCanvas.highlightSearchResults(results);\r
+\r
+ // do we need to scroll the panel?\r
+ if (results != null)\r
+ {\r
+ SequenceI seq = av.alignment.getSequenceAt(results[0]);\r
+ int start = seq.findIndex(results[1]) - 1;\r
+ int end = seq.findIndex(results[2]) - 1;\r
+\r
+ if ((av.getStartRes() > start) || (av.getEndRes() < end) ||\r
+ ((av.getStartSeq() > results[0]) ||\r
+ (av.getEndSeq() < results[0])))\r
+ {\r
+ setScrollValues(start, results[0]);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public OverviewPanel getOverviewPanel()\r
+ {\r
+ return overviewPanel;\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param op DOCUMENT ME!\r
+ */\r
+ public void setOverviewPanel(OverviewPanel op)\r
+ {\r
+ overviewPanel = op;\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param b DOCUMENT ME!\r
+ */\r
+ public void setAnnotationVisible(boolean b)\r
+ {\r
+ annotationSpaceFillerHolder.setVisible(b);\r
+ annotationScroller.setVisible(b);\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param wrap DOCUMENT ME!\r
+ */\r
+ public void setWrapAlignment(boolean wrap)\r
+ {\r
+ av.startSeq = 0;\r
+ scalePanelHolder.setVisible(!wrap);\r
+ hscroll.setVisible(!wrap);\r
+ idwidthAdjuster.setVisible(!wrap);\r
+\r
+ if(wrap)\r
+ {\r
+ annotationScroller.setVisible(false);\r
+ annotationSpaceFillerHolder.setVisible(false);\r
+ }\r
+ else if(av.showAnnotation)\r
+ {\r
+ annotationScroller.setVisible(true);\r
+ annotationSpaceFillerHolder.setVisible(true);\r
+ }\r
+\r
+ idSpaceFillerPanel1.setVisible(!wrap);\r
+\r
+ repaint();\r
+ }\r
+\r
+\r
+ // return value is true if the scroll is valid\r
+ public boolean scrollUp(boolean up)\r
+ {\r
+ if (up)\r
+ {\r
+ if (vscroll.getValue() < 1)\r
+ {\r
+ return false;\r
+ }\r
+\r
+ fastPaint = false;\r
+ vscroll.setValue(vscroll.getValue() - 1);\r
+ }\r
+ else\r
+ {\r
+ if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight())\r
+ {\r
+ return false;\r
+ }\r
+\r
+ fastPaint = false;\r
+ vscroll.setValue(vscroll.getValue() + 1);\r
+ }\r
+\r
+ fastPaint = true;\r
+\r
+ return true;\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param right DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public boolean scrollRight(boolean right)\r
+ {\r
+ if (right)\r
+ {\r
+ if (hscroll.getValue() < 1)\r
+ {\r
+ return false;\r
+ }\r
+\r
+ fastPaint = false;\r
+ hscroll.setValue(hscroll.getValue() - 1);\r
+ }\r
+ else\r
+ {\r
+ if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth())\r
+ {\r
+ return false;\r
+ }\r
+\r
+ fastPaint = false;\r
+ hscroll.setValue(hscroll.getValue() + 1);\r
+ }\r
+\r
+ fastPaint = true;\r