2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
22 import java.awt.event.*;
\r
23 import java.awt.image.*;
\r
24 import javax.swing.*;
\r
26 import jalview.datamodel.*;
\r
32 * @version $Revision$
\r
34 public class AnnotationPanel
\r
35 extends JPanel implements MouseListener,
\r
36 MouseMotionListener, ActionListener, AdjustmentListener
\r
38 final String HELIX = "Helix";
\r
39 final String SHEET = "Sheet";
\r
40 final String LABEL = "Label";
\r
41 final String REMOVE = "Remove Annotation";
\r
42 final String COLOUR = "Colour";
\r
43 final Color HELIX_COLOUR = Color.red.darker();
\r
44 final Color SHEET_COLOUR = Color.green.darker().darker();
\r
46 /** DOCUMENT ME!! */
\r
50 BufferedImage image;
\r
51 BufferedImage fadedImage;
\r
55 boolean fastPaint = false;
\r
57 //Used For mouse Dragging and resizing graphs
\r
58 int graphStretch = -1;
\r
59 int graphStretchY = -1;
\r
60 int min; //used by mouseDragged to see if user
\r
61 int max; //used by mouseDragged to see if user
\r
62 boolean mouseDragging = false;
\r
64 boolean MAC = false;
\r
67 * Creates a new AnnotationPanel object.
\r
69 * @param ap DOCUMENT ME!
\r
71 public AnnotationPanel(AlignmentPanel ap)
\r
74 if (System.getProperty("os.name").startsWith("Mac"))
\r
79 ToolTipManager.sharedInstance().registerComponent(this);
\r
80 ToolTipManager.sharedInstance().setInitialDelay(0);
\r
81 ToolTipManager.sharedInstance().setDismissDelay(10000);
\r
84 this.setLayout(null);
\r
85 addMouseListener(this);
\r
86 addMouseMotionListener(this);
\r
87 ap.annotationScroller.getVerticalScrollBar().addAdjustmentListener(this);
\r
90 public AnnotationPanel(AlignViewport av)
\r
98 * @param evt DOCUMENT ME!
\r
100 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
102 ap.alabels.setScrollOffset( -evt.getValue());
\r
108 public int adjustPanelHeight()
\r
110 // setHeight of panels
\r
111 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
116 for (int i = 0; i < aa.length; i++)
\r
118 if (!aa[i].visible)
\r
127 aa[i].height += av.charHeight;
\r
130 if (aa[i].hasIcons)
\r
132 aa[i].height += 16;
\r
135 if (aa[i].graph > 0)
\r
137 aa[i].height += aa[i].graphHeight;
\r
140 if (aa[i].height == 0)
\r
145 height += aa[i].height;
\r
153 this.setPreferredSize(new Dimension(1, height));
\r
161 * @param evt DOCUMENT ME!
\r
163 public void actionPerformed(ActionEvent evt)
\r
165 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
166 Annotation[] anot = aa[activeRow].annotations;
\r
168 if (anot.length < av.getColumnSelection().getMax())
\r
170 Annotation[] temp = new Annotation[av.getColumnSelection().getMax() + 2];
\r
171 System.arraycopy(anot, 0, temp, 0, anot.length);
\r
173 aa[activeRow].annotations = anot;
\r
176 if (evt.getActionCommand().equals(REMOVE))
\r
178 for (int i = 0; i < av.getColumnSelection().size(); i++)
\r
180 anot[av.getColumnSelection().columnAt(i)] = null;
\r
183 else if (evt.getActionCommand().equals(LABEL))
\r
185 String label = JOptionPane.showInputDialog(this, "Enter Label ",
\r
187 JOptionPane.QUESTION_MESSAGE);
\r
194 if ( (label.length() > 0) && !aa[activeRow].hasText)
\r
196 aa[activeRow].hasText = true;
\r
199 for (int i = 0; i < av.getColumnSelection().size(); i++)
\r
201 int index = av.getColumnSelection().columnAt(i);
\r
203 if(!av.colSel.isVisible(index))
\r
206 if (anot[index] == null)
\r
208 anot[index] = new Annotation(label, "", ' ', 0);
\r
211 anot[index].displayCharacter = label;
\r
214 else if (evt.getActionCommand().equals(COLOUR))
\r
216 Color col = JColorChooser.showDialog(this,
\r
217 "Choose foreground colour",
\r
220 for (int i = 0; i < av.getColumnSelection().size(); i++)
\r
222 int index = av.getColumnSelection().columnAt(i);
\r
224 if(!av.colSel.isVisible(index))
\r
227 if (anot[index] == null)
\r
229 anot[index] = new Annotation("", "", ' ', 0);
\r
232 anot[index].colour = col;
\r
235 else // HELIX OR SHEET
\r
238 String symbol = "\u03B1";
\r
240 if (evt.getActionCommand().equals(HELIX))
\r
244 else if (evt.getActionCommand().equals(SHEET))
\r
250 if (!aa[activeRow].hasIcons)
\r
252 aa[activeRow].hasIcons = true;
\r
255 String label = JOptionPane.showInputDialog(
\r
256 "Enter a label for the structure?",
\r
264 if ( (label.length() > 0) && !aa[activeRow].hasText)
\r
266 aa[activeRow].hasText = true;
\r
269 for (int i = 0; i < av.getColumnSelection().size(); i++)
\r
271 int index = av.getColumnSelection().columnAt(i);
\r
273 if(!av.colSel.isVisible(index))
\r
276 if (anot[index] == null)
\r
278 anot[index] = new Annotation(label, "", type, 0);
\r
281 anot[index].secondaryStructure = type;
\r
282 anot[index].displayCharacter = label;
\r
286 adjustPanelHeight();
\r
295 * @param evt DOCUMENT ME!
\r
297 public void mousePressed(MouseEvent evt)
\r
300 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
309 for (int i = 0; i < aa.length; i++)
\r
313 height += aa[i].height;
\r
316 if (evt.getY() < height)
\r
318 if (aa[i].editable)
\r
322 else if (aa[i].graph > 0)
\r
326 graphStretchY = evt.getY();
\r
333 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
\r
335 if (av.getColumnSelection() == null)
\r
340 JPopupMenu pop = new JPopupMenu("Structure type");
\r
341 JMenuItem item = new JMenuItem(HELIX);
\r
342 item.addActionListener(this);
\r
344 item = new JMenuItem(SHEET);
\r
345 item.addActionListener(this);
\r
347 item = new JMenuItem(LABEL);
\r
348 item.addActionListener(this);
\r
350 item = new JMenuItem(COLOUR);
\r
351 item.addActionListener(this);
\r
353 item = new JMenuItem(REMOVE);
\r
354 item.addActionListener(this);
\r
356 pop.show(this, evt.getX(), evt.getY());
\r
366 ap.scalePanel.mousePressed(evt);
\r
373 * @param evt DOCUMENT ME!
\r
375 public void mouseReleased(MouseEvent evt)
\r
378 graphStretchY = -1;
\r
379 mouseDragging = false;
\r
380 ap.scalePanel.mouseReleased(evt);
\r
386 * @param evt DOCUMENT ME!
\r
388 public void mouseEntered(MouseEvent evt)
\r
390 ap.scalePanel.mouseEntered(evt);
\r
396 * @param evt DOCUMENT ME!
\r
398 public void mouseExited(MouseEvent evt)
\r
400 ap.scalePanel.mouseExited(evt);
\r
406 * @param evt DOCUMENT ME!
\r
408 public void mouseDragged(MouseEvent evt)
\r
410 if (graphStretch > -1)
\r
412 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight +=
\r
413 graphStretchY - evt.getY();
\r
414 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
\r
416 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
\r
418 graphStretchY = evt.getY();
\r
419 adjustPanelHeight();
\r
420 ap.paintAlignment(true);
\r
424 ap.scalePanel.mouseDragged(evt);
\r
431 * @param evt DOCUMENT ME!
\r
433 public void mouseMoved(MouseEvent evt)
\r
435 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
439 this.setToolTipText(null);
\r
446 for (int i = 0; i < aa.length; i++)
\r
450 height += aa[i].height;
\r
453 if (evt.getY() < height)
\r
463 this.setToolTipText(null);
\r
467 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
469 if (av.hasHiddenColumns)
\r
471 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
474 if (aa[row].annotations != null
\r
476 && res < (int) aa[row].annotations.length)
\r
478 if (aa[row].graphGroup > -1)
\r
480 StringBuffer tip = new StringBuffer("<html>");
\r
481 for (int gg = 0; gg < aa.length; gg++)
\r
483 if (aa[gg].graphGroup == aa[row].graphGroup && aa[gg].annotations[res] != null)
\r
485 tip.append(aa[gg].label + " " + aa[gg].annotations[res].description +
\r
489 if (tip.length() != 6)
\r
491 tip.setLength(tip.length() - 4);
\r
492 this.setToolTipText(tip.toString() + "</html>");
\r
495 else if (aa[row].annotations[res] != null
\r
496 && aa[row].annotations[res].description != null)
\r
498 this.setToolTipText(aa[row].annotations[res].description);
\r
501 if (aa[row].annotations[res] != null)
\r
503 StringBuffer text = new StringBuffer("Sequence position " +
\r
506 if (aa[row].annotations[res].description != null)
\r
508 text.append(" " + aa[row].annotations[res].description);
\r
511 ap.alignFrame.statusBar.setText(text.toString());
\r
516 this.setToolTipText(null);
\r
523 * @param evt DOCUMENT ME!
\r
525 public void mouseClicked(MouseEvent evt)
\r
532 * @param g DOCUMENT ME!
\r
534 public void paintComponent(Graphics g)
\r
536 g.setColor(Color.white);
\r
537 g.fillRect(0, 0, getWidth(), getHeight());
\r
542 || (getVisibleRect().width != g.getClipBounds().width)
\r
543 || (getVisibleRect().height != g.getClipBounds().height))
\r
545 g.drawImage(image, 0, 0, this);
\r
550 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
\r
552 if (image == null || imgWidth != image.getWidth()
\r
553 || image.getHeight(this) != getHeight())
\r
555 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
\r
556 BufferedImage.TYPE_INT_RGB);
\r
557 gg = (Graphics2D) image.getGraphics();
\r
561 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
562 RenderingHints.VALUE_ANTIALIAS_ON);
\r
565 gg.setFont(av.getFont());
\r
566 fm = gg.getFontMetrics();
\r
567 gg.setColor(Color.white);
\r
568 gg.fillRect(0, 0, imgWidth, image.getHeight());
\r
571 drawComponent(gg, av.startRes, av.endRes + 1);
\r
572 g.drawImage(image, 0, 0, this);
\r
578 * @param horizontal DOCUMENT ME!
\r
580 public void fastPaint(int horizontal)
\r
582 if ( (horizontal == 0)
\r
584 || av.alignment.getAlignmentAnnotation() == null
\r
585 || av.alignment.getAlignmentAnnotation().length < 1
\r
586 || av.updatingConsensus
\r
587 || av.updatingConservation)
\r
593 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
\r
595 int sr = av.startRes;
\r
596 int er = av.endRes + 1;
\r
599 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
601 transX = (er - sr - horizontal) * av.charWidth;
\r
602 sr = er - horizontal;
\r
604 else if (horizontal < 0)
\r
606 er = sr - horizontal;
\r
609 gg.translate(transX, 0);
\r
611 drawComponent(gg, sr, er);
\r
613 gg.translate( -transX, 0);
\r
624 * @param g DOCUMENT ME!
\r
625 * @param startRes DOCUMENT ME!
\r
626 * @param endRes DOCUMENT ME!
\r
628 public void drawComponent(Graphics g, int startRes, int endRes)
\r
630 if (av.updatingConsensus || av.updatingConservation)
\r
636 //We'll keep a record of the old image,
\r
637 //and draw a faded image until the calculation
\r
639 if (fadedImage == null
\r
640 || fadedImage.getWidth() != imgWidth
\r
641 || fadedImage.getHeight() != image.getHeight())
\r
643 fadedImage = new BufferedImage(
\r
644 imgWidth, image.getHeight(),
\r
645 BufferedImage.TYPE_INT_RGB);
\r
647 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
\r
649 fadedG.setColor(Color.white);
\r
650 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
\r
652 fadedG.setComposite(
\r
653 AlphaComposite.getInstance(
\r
654 AlphaComposite.SRC_OVER, .3f));
\r
655 fadedG.drawImage(image, 0, 0, this);
\r
665 g.setColor(Color.white);
\r
666 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
\r
668 g.setFont(av.getFont());
\r
671 fm = g.getFontMetrics();
\r
674 if ( (av.alignment.getAlignmentAnnotation() == null) ||
\r
675 (av.alignment.getAlignmentAnnotation().length < 1))
\r
677 g.setColor(Color.white);
\r
678 g.fillRect(0, 0, getWidth(), getHeight());
\r
679 g.setColor(Color.black);
\r
680 if (av.validCharWidth)
\r
682 g.drawString("Alignment has no annotations", 20, 15);
\r
688 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
694 int iconOffset = 0;
\r
695 boolean validRes = false;
\r
697 boolean[] graphGroupDrawn = new boolean[aa.length];
\r
700 for (int i = 0; i < aa.length; i++)
\r
702 AlignmentAnnotation row = aa[i];
\r
714 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
\r
719 // this is so that we draw the characters below the graph
\r
724 iconOffset = av.charHeight / 2 + 4;
\r
725 y -= av.charHeight;
\r
728 else if (row.hasText)
\r
730 iconOffset = av.charHeight -fm.getDescent();
\r
739 if (av.updatingConsensus && aa[i] == av.consensus)
\r
741 y += av.charHeight;
\r
743 g.drawImage(fadedImage,
\r
744 0, y - row.height, imgWidth, y,
\r
745 0, y - row.height, imgWidth, y, this);
\r
746 g.setColor(Color.black);
\r
747 // g.drawString("Calculating Consensus....",20, y-row.height/2);
\r
751 else if (av.updatingConservation && aa[i].label.equals("Conservation"))
\r
754 y += av.charHeight;
\r
755 g.drawImage(fadedImage,
\r
756 0, y - row.height, imgWidth, y,
\r
757 0, y - row.height, imgWidth, y, this);
\r
759 g.setColor(Color.black);
\r
760 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
\r
764 else if (av.updatingConservation && aa[i].label.equals("Quality"))
\r
767 y += av.charHeight;
\r
768 g.drawImage(fadedImage,
\r
769 0, y - row.height, imgWidth, y,
\r
770 0, y - row.height, imgWidth, y, this);
\r
771 g.setColor(Color.black);
\r
772 /// g.drawString("Calculating Quality....",20, y-row.height/2);
\r
780 while (x < endRes - startRes)
\r
782 if (av.hasHiddenColumns)
\r
784 column = av.getColumnSelection().adjustForHiddenColumns(startRes + x);
\r
785 if (column > row.annotations.length - 1)
\r
792 column = startRes + x;
\r
795 if ( (row.annotations.length <= column) ||
\r
796 (row.annotations[column] == null))
\r
805 if (activeRow == i)
\r
807 g.setColor(Color.red);
\r
809 if (av.getColumnSelection() != null)
\r
811 for (int n = 0; n < av.getColumnSelection().size(); n++)
\r
813 int v = av.getColumnSelection().columnAt(n);
\r
817 g.fillRect(x * av.charWidth, y,
\r
818 av.charWidth, av.charHeight);
\r
824 if (av.validCharWidth && validRes
\r
825 && row.annotations[column].displayCharacter != null
\r
826 && (row.annotations[column].displayCharacter.length() > 0))
\r
829 int charOffset = (av.charWidth -
\r
830 fm.charWidth(row.annotations[column].
\r
831 displayCharacter.charAt(
\r
834 if (row.annotations[column].colour == null)
\r
835 g.setColor(Color.black);
\r
837 g.setColor(row.annotations[column].colour);
\r
839 if (column == 0 || row.graph > 0)
\r
841 g.drawString(row.annotations[column].displayCharacter,
\r
842 (x * av.charWidth) + charOffset,
\r
846 row.annotations[column - 1] == null
\r
847 || (!row.annotations[column].displayCharacter.equals(
\r
848 row.annotations[column - 1].displayCharacter)
\r
850 (row.annotations[column].displayCharacter.length() < 2 &&
\r
851 row.annotations[column].secondaryStructure == ' ')))
\r
853 g.drawString(row.annotations[column].displayCharacter,
\r
854 x * av.charWidth + charOffset,
\r
862 (row.annotations[column].secondaryStructure != lastSS))
\r
867 g.setColor(HELIX_COLOUR);
\r
870 //Off by 1 offset when drawing rects and ovals
\r
871 //to offscreen image on the MAC
\r
872 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
\r
873 (x * av.charWidth) - lastSSX, 7, 8, 8);
\r
877 int sCol = (lastSSX / av.charWidth) + startRes;
\r
879 int x2 = (x * av.charWidth);
\r
882 row.annotations[sCol - 1] == null ||
\r
883 row.annotations[sCol - 1].secondaryStructure != 'H')
\r
885 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
\r
887 x1 += av.charWidth / 2;
\r
890 if (row.annotations[column] == null ||
\r
891 row.annotations[column].secondaryStructure != 'H')
\r
893 g.fillArc( (x * av.charWidth) - av.charWidth,
\r
894 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
\r
895 x2 -= av.charWidth / 2;
\r
898 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
\r
902 g.setColor(SHEET_COLOUR);
\r
903 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
904 (x * av.charWidth) - lastSSX - 4, 7);
\r
905 g.fillPolygon(new int[]
\r
906 { (x * av.charWidth) - 4,
\r
907 (x * av.charWidth) - 4,
\r
908 (x * av.charWidth)},
\r
911 y + iconOffset, y + 14 + iconOffset,
\r
918 g.setColor(Color.gray);
\r
919 g.fillRect(lastSSX, y + 6 + iconOffset,
\r
920 (x * av.charWidth) - lastSSX, 2);
\r
927 lastSS = row.annotations[column].secondaryStructure;
\r
934 lastSSX = (x * av.charWidth);
\r
942 if (column >= row.annotations.length)
\r
944 column = row.annotations.length - 1;
\r
954 g.setColor(HELIX_COLOUR);
\r
957 //Off by 1 offset when drawing rects and ovals
\r
958 //to offscreen image on the MAC
\r
959 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
\r
960 (x * av.charWidth) - lastSSX, 7, 8, 8);
\r
964 int sCol = (lastSSX / av.charWidth) + startRes;
\r
966 int x2 = (x * av.charWidth);
\r
969 row.annotations[sCol - 1] == null ||
\r
970 row.annotations[sCol - 1].secondaryStructure != 'H')
\r
972 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
\r
973 x1 += av.charWidth / 2;
\r
976 if (row.annotations[column] == null ||
\r
977 row.annotations[column].secondaryStructure != 'H')
\r
979 g.fillArc( (x * av.charWidth) - av.charWidth,
\r
980 y + 4 + iconOffset, av.charWidth, 8, 270,
\r
982 x2 -= av.charWidth / 2;
\r
985 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
\r
990 g.setColor(SHEET_COLOUR);
\r
992 if (row.annotations[endRes] == null
\r
993 || row.annotations[endRes].secondaryStructure != 'E')
\r
995 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
996 (x * av.charWidth) - lastSSX - 4, 7);
\r
997 g.fillPolygon(new int[]
\r
998 { (x * av.charWidth) - 4,
\r
999 (x * av.charWidth) - 4,
\r
1000 (x * av.charWidth)},
\r
1003 y + iconOffset, y + 14 + iconOffset,
\r
1004 y + 7 + iconOffset
\r
1009 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
1010 (x + 1) * av.charWidth - lastSSX, 7);
\r
1015 g.setColor(Color.gray);
\r
1016 g.fillRect(lastSSX, y + 6 + iconOffset,
\r
1017 (x * av.charWidth) - lastSSX, 2);
\r
1023 if (row.graph > 0 && row.graphHeight > 0)
\r
1025 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
\r
1027 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
\r
1029 float groupmax = -999999, groupmin = 9999999;
\r
1030 for (int gg = 0; gg < aa.length; gg++)
\r
1032 if (aa[gg].graphGroup != row.graphGroup)
\r
1037 if (aa[gg] != row)
\r
1039 aa[gg].visible = false;
\r
1042 if (aa[gg].graphMax > groupmax)
\r
1044 groupmax = aa[gg].graphMax;
\r
1046 if (aa[gg].graphMin < groupmin)
\r
1048 groupmin = aa[gg].graphMin;
\r
1052 for (int gg = 0; gg < aa.length; gg++)
\r
1054 if (aa[gg].graphGroup == row.graphGroup)
\r
1056 drawLineGraph(g, aa[gg], startRes, endRes, y,
\r
1057 groupmin, groupmax,
\r
1062 graphGroupDrawn[row.graphGroup] = true;
\r
1066 drawLineGraph(g, row, startRes, endRes,
\r
1067 y, row.graphMin, row.graphMax, row.graphHeight);
\r
1070 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
\r
1072 drawBarGraph(g, row, startRes, endRes,
\r
1073 row.graphMin, row.graphMax, y);
\r
1077 if (row.graph > 0 && row.hasText)
\r
1079 y += av.charHeight;
\r
1082 if (row.graph == 0)
\r
1084 y += aa[i].height;
\r
1089 public void drawLineGraph(Graphics g, AlignmentAnnotation aa,
\r
1090 int sRes, int eRes,
\r
1092 float min, float max,
\r
1095 if (sRes > aa.annotations.length)
\r
1102 //Adjustment for fastpaint to left
\r
1103 if (eRes < av.endRes)
\r
1108 eRes = Math.min(eRes, aa.annotations.length);
\r
1115 int y1 = y, y2 = y;
\r
1116 float range = max - min;
\r
1121 y2 = y - (int) ( (0 - min / range) * graphHeight);
\r
1124 g.setColor(Color.gray);
\r
1125 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
\r
1127 eRes = Math.min(eRes, aa.annotations.length);
\r
1130 int aaMax = aa.annotations.length - 1;
\r
1132 while (x < eRes - sRes)
\r
1134 column = sRes + x;
\r
1135 if (av.hasHiddenColumns)
\r
1137 column = av.getColumnSelection().adjustForHiddenColumns(column);
\r
1140 if (column > aaMax)
\r
1145 if (aa.annotations[column] == null || aa.annotations[column - 1] == null)
\r
1151 if (aa.annotations[column].colour == null)
\r
1152 g.setColor(Color.black);
\r
1154 g.setColor(aa.annotations[column].colour);
\r
1157 (int) ( ( (aa.annotations[column - 1].value - min) / range) * graphHeight);
\r
1159 (int) ( ( (aa.annotations[column].value - min) / range) * graphHeight);
\r
1161 g.drawLine(x * av.charWidth - av.charWidth / 2, y1,
\r
1162 x * av.charWidth + av.charWidth / 2, y2);
\r
1166 if (aa.threshold != null)
\r
1168 g.setColor(aa.threshold.colour);
\r
1169 Graphics2D g2 = (Graphics2D) g;
\r
1170 g2.setStroke(new BasicStroke(1,
\r
1171 BasicStroke.CAP_SQUARE,
\r
1172 BasicStroke.JOIN_ROUND, 3f,
\r
1176 y2 = (int) (y - ( (aa.threshold.value - min) / range) * graphHeight);
\r
1177 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
\r
1178 g2.setStroke(new BasicStroke());
\r
1182 public void drawBarGraph(Graphics g, AlignmentAnnotation aa,
\r
1183 int sRes, int eRes,
\r
1184 float min, float max,
\r
1187 if (sRes > aa.annotations.length)
\r
1192 eRes = Math.min(eRes, aa.annotations.length);
\r
1194 int x = 0, y1 = y, y2 = y;
\r
1196 float range = max - min;
\r
1200 y2 = y - (int) ( (0 - min / (range)) * aa.graphHeight);
\r
1203 g.setColor(Color.gray);
\r
1205 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
\r
1208 int aaMax = aa.annotations.length - 1;
\r
1210 while (x < eRes - sRes)
\r
1212 column = sRes + x;
\r
1213 if (av.hasHiddenColumns)
\r
1215 column = av.getColumnSelection().adjustForHiddenColumns(column);
\r
1218 if (column > aaMax)
\r
1223 if (aa.annotations[column] == null)
\r
1229 if (aa.annotations[column].colour == null)
\r
1230 g.setColor(Color.black);
\r
1232 g.setColor(aa.annotations[column].colour);
\r
1235 (int) ( ( (aa.annotations[column].value - min) / (range)) * aa.graphHeight);
\r
1239 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
\r
1243 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
\r
1249 if (aa.threshold != null)
\r
1251 g.setColor(aa.threshold.colour);
\r
1252 Graphics2D g2 = (Graphics2D) g;
\r
1253 g2.setStroke(new BasicStroke(1,
\r
1254 BasicStroke.CAP_SQUARE,
\r
1255 BasicStroke.JOIN_ROUND, 3f,
\r
1259 y2 = (int) (y - ( (aa.threshold.value - min) / range) * aa.graphHeight);
\r
1260 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
\r
1261 g2.setStroke(new BasicStroke());
\r
1265 // used by overview window
\r
1266 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y,
\r
1267 int sRes, int eRes)
\r
1269 eRes = Math.min(eRes, aa.annotations.length);
\r
1270 g.setColor(Color.white);
\r
1271 g.fillRect(0, 0, width, y);
\r
1272 g.setColor(new Color(0, 0, 180));
\r
1274 int x = 0, height;
\r
1276 for (int j = sRes; j < eRes; j++)
\r
1278 if (aa.annotations[j] != null)
\r
1280 if (aa.annotations[j].colour == null)
\r
1281 g.setColor(Color.black);
\r
1283 g.setColor(aa.annotations[j].colour);
\r
1285 height = (int) ( (aa.annotations[j].value / aa.graphMax) * y);
\r
1291 g.fillRect(x, y - height, av.charWidth, height);
\r
1293 x += av.charWidth;
\r