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 (anot[index] == null)
\r
205 anot[index] = new Annotation(label, "", ' ', 0);
\r
208 anot[index].displayCharacter = label;
\r
211 else if (evt.getActionCommand().equals(COLOUR))
\r
213 Color col = JColorChooser.showDialog(this,
\r
214 "Choose foreground colour",
\r
217 for (int i = 0; i < av.getColumnSelection().size(); i++)
\r
219 int index = av.getColumnSelection().columnAt(i);
\r
221 if (anot[index] == null)
\r
223 anot[index] = new Annotation("", "", ' ', 0);
\r
226 anot[index].colour = col;
\r
229 else // HELIX OR SHEET
\r
232 String symbol = "\u03B1";
\r
234 if (evt.getActionCommand().equals(HELIX))
\r
238 else if (evt.getActionCommand().equals(SHEET))
\r
244 if (!aa[activeRow].hasIcons)
\r
246 aa[activeRow].hasIcons = true;
\r
249 String label = JOptionPane.showInputDialog(
\r
250 "Enter a label for the structure?",
\r
258 if ( (label.length() > 0) && !aa[activeRow].hasText)
\r
260 aa[activeRow].hasText = true;
\r
263 for (int i = 0; i < av.getColumnSelection().size(); i++)
\r
265 int index = av.getColumnSelection().columnAt(i);
\r
267 if (anot[index] == null)
\r
269 anot[index] = new Annotation(label, "", type, 0);
\r
272 anot[index].secondaryStructure = type;
\r
273 anot[index].displayCharacter = label;
\r
277 adjustPanelHeight();
\r
286 * @param evt DOCUMENT ME!
\r
288 public void mousePressed(MouseEvent evt)
\r
291 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
300 for (int i = 0; i < aa.length; i++)
\r
304 height += aa[i].height;
\r
307 if (evt.getY() < height)
\r
309 if (aa[i].editable)
\r
313 else if (aa[i].graph > 0)
\r
317 graphStretchY = evt.getY();
\r
324 if (SwingUtilities.isRightMouseButton(evt) && activeRow != -1)
\r
326 if (av.getColumnSelection() == null)
\r
331 JPopupMenu pop = new JPopupMenu("Structure type");
\r
332 JMenuItem item = new JMenuItem(HELIX);
\r
333 item.addActionListener(this);
\r
335 item = new JMenuItem(SHEET);
\r
336 item.addActionListener(this);
\r
338 item = new JMenuItem(LABEL);
\r
339 item.addActionListener(this);
\r
341 item = new JMenuItem(COLOUR);
\r
342 item.addActionListener(this);
\r
344 item = new JMenuItem(REMOVE);
\r
345 item.addActionListener(this);
\r
347 pop.show(this, evt.getX(), evt.getY());
\r
357 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
359 if (av.hasHiddenColumns)
\r
361 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
367 if (av.getColumnSelection().contains(res))
\r
369 av.getColumnSelection().removeElement(res);
\r
373 av.getColumnSelection().addElement(res);
\r
374 SequenceGroup sg = new SequenceGroup();
\r
376 for (int i = 0; i < av.alignment.getSequences().size(); i++)
\r
378 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
381 sg.setStartRes(res);
\r
383 av.setSelectionGroup(sg);
\r
386 ap.paintAlignment(true);
\r
393 * @param evt DOCUMENT ME!
\r
395 public void mouseReleased(MouseEvent evt)
\r
398 graphStretchY = -1;
\r
399 mouseDragging = false;
\r
405 * @param evt DOCUMENT ME!
\r
407 public void mouseEntered(MouseEvent evt)
\r
411 ap.seqPanel.scrollCanvas(null);
\r
418 * @param evt DOCUMENT ME!
\r
420 public void mouseExited(MouseEvent evt)
\r
424 ap.seqPanel.scrollCanvas(evt);
\r
431 * @param evt DOCUMENT ME!
\r
433 public void mouseDragged(MouseEvent evt)
\r
435 if (graphStretch > -1)
\r
437 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight +=
\r
438 graphStretchY - evt.getY();
\r
439 if (av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight < 0)
\r
441 av.alignment.getAlignmentAnnotation()[graphStretch].graphHeight = 0;
\r
443 graphStretchY = evt.getY();
\r
444 adjustPanelHeight();
\r
445 ap.paintAlignment(true);
\r
449 mouseDragging = true;
\r
451 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
453 if (av.hasHiddenColumns)
\r
455 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
458 SequenceGroup sg = av.getSelectionGroup();
\r
472 if (!av.getColumnSelection().contains(res))
\r
474 av.getColumnSelection().addElement(res);
\r
477 if (res > sg.getStartRes())
\r
481 else if (res < sg.getStartRes())
\r
483 sg.setStartRes(res);
\r
486 for (int i = min; i <= max; i++)
\r
488 if ( (i < sg.getStartRes()) || (i > sg.getEndRes()))
\r
490 av.getColumnSelection().removeElement(i);
\r
494 av.getColumnSelection().addElement(i);
\r
498 ap.paintAlignment(true);
\r
507 * @param evt DOCUMENT ME!
\r
509 public void mouseMoved(MouseEvent evt)
\r
511 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
515 this.setToolTipText(null);
\r
522 for (int i = 0; i < aa.length; i++)
\r
526 height += aa[i].height;
\r
529 if (evt.getY() < height)
\r
539 this.setToolTipText(null);
\r
543 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
545 if (av.hasHiddenColumns)
\r
547 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
550 if (aa[row].annotations != null
\r
552 && res < (int) aa[row].annotations.length)
\r
554 if (aa[row].graphGroup > -1)
\r
556 StringBuffer tip = new StringBuffer("<html>");
\r
557 for (int gg = 0; gg < aa.length; gg++)
\r
559 if (aa[gg].graphGroup == aa[row].graphGroup && aa[gg].annotations[res] != null)
\r
561 tip.append(aa[gg].label + " " + aa[gg].annotations[res].description +
\r
565 if (tip.length() != 6)
\r
567 tip.setLength(tip.length() - 4);
\r
568 this.setToolTipText(tip.toString() + "</html>");
\r
571 else if (aa[row].annotations[res] != null
\r
572 && aa[row].annotations[res].description != null)
\r
574 this.setToolTipText(aa[row].annotations[res].description);
\r
577 if (aa[row].annotations[res] != null)
\r
579 StringBuffer text = new StringBuffer("Sequence position " +
\r
582 if (aa[row].annotations[res].description != null)
\r
584 text.append(" " + aa[row].annotations[res].description);
\r
587 ap.alignFrame.statusBar.setText(text.toString());
\r
592 this.setToolTipText(null);
\r
599 * @param evt DOCUMENT ME!
\r
601 public void mouseClicked(MouseEvent evt)
\r
608 * @param g DOCUMENT ME!
\r
610 public void paintComponent(Graphics g)
\r
612 g.setColor(Color.white);
\r
613 g.fillRect(0, 0, getWidth(), getHeight());
\r
618 || (getVisibleRect().width != g.getClipBounds().width)
\r
619 || (getVisibleRect().height != g.getClipBounds().height))
\r
621 g.drawImage(image, 0, 0, this);
\r
626 imgWidth = (av.endRes - av.startRes + 1) * av.charWidth;
\r
628 if (image == null || imgWidth != image.getWidth()
\r
629 || image.getHeight(this) != getHeight())
\r
631 image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(),
\r
632 BufferedImage.TYPE_INT_RGB);
\r
633 gg = (Graphics2D) image.getGraphics();
\r
637 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
638 RenderingHints.VALUE_ANTIALIAS_ON);
\r
641 gg.setFont(av.getFont());
\r
642 fm = gg.getFontMetrics();
\r
643 gg.setColor(Color.white);
\r
644 gg.fillRect(0, 0, imgWidth, image.getHeight());
\r
647 drawComponent(gg, av.startRes, av.endRes + 1);
\r
648 g.drawImage(image, 0, 0, this);
\r
654 * @param horizontal DOCUMENT ME!
\r
656 public void fastPaint(int horizontal)
\r
658 if ( (horizontal == 0)
\r
660 || av.alignment.getAlignmentAnnotation() == null
\r
661 || av.alignment.getAlignmentAnnotation().length < 1
\r
662 || av.updatingConsensus
\r
663 || av.updatingConservation)
\r
669 gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0);
\r
671 int sr = av.startRes;
\r
672 int er = av.endRes + 1;
\r
675 if (horizontal > 0) // scrollbar pulled right, image to the left
\r
677 transX = (er - sr - horizontal) * av.charWidth;
\r
678 sr = er - horizontal;
\r
680 else if (horizontal < 0)
\r
682 er = sr - horizontal;
\r
685 gg.translate(transX, 0);
\r
687 drawComponent(gg, sr, er);
\r
689 gg.translate( -transX, 0);
\r
700 * @param g DOCUMENT ME!
\r
701 * @param startRes DOCUMENT ME!
\r
702 * @param endRes DOCUMENT ME!
\r
704 public void drawComponent(Graphics g, int startRes, int endRes)
\r
706 if (av.updatingConsensus || av.updatingConservation)
\r
712 //We'll keep a record of the old image,
\r
713 //and draw a faded image until the calculation
\r
715 if (fadedImage == null
\r
716 || fadedImage.getWidth() != imgWidth
\r
717 || fadedImage.getHeight() != image.getHeight())
\r
719 fadedImage = new BufferedImage(
\r
720 imgWidth, image.getHeight(),
\r
721 BufferedImage.TYPE_INT_RGB);
\r
723 Graphics2D fadedG = (Graphics2D) fadedImage.getGraphics();
\r
725 fadedG.setColor(Color.white);
\r
726 fadedG.fillRect(0, 0, imgWidth, image.getHeight());
\r
728 fadedG.setComposite(
\r
729 AlphaComposite.getInstance(
\r
730 AlphaComposite.SRC_OVER, .3f));
\r
731 fadedG.drawImage(image, 0, 0, this);
\r
741 g.setColor(Color.white);
\r
742 g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());
\r
744 g.setFont(av.getFont());
\r
747 fm = g.getFontMetrics();
\r
750 if ( (av.alignment.getAlignmentAnnotation() == null) ||
\r
751 (av.alignment.getAlignmentAnnotation().length < 1))
\r
753 g.setColor(Color.white);
\r
754 g.fillRect(0, 0, getWidth(), getHeight());
\r
755 g.setColor(Color.black);
\r
756 if (av.validCharWidth)
\r
758 g.drawString("Alignment has no annotations", 20, 15);
\r
764 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
\r
770 int iconOffset = av.charHeight / 2;
\r
771 boolean validRes = false;
\r
773 boolean[] graphGroupDrawn = new boolean[aa.length];
\r
776 for (int i = 0; i < aa.length; i++)
\r
778 AlignmentAnnotation row = aa[i];
\r
790 if (row.graphGroup > -1 && graphGroupDrawn[row.graphGroup])
\r
795 // this is so that we draw the characters below the graph
\r
800 y -= av.charHeight;
\r
804 if (av.updatingConsensus && aa[i] == av.consensus)
\r
806 y += av.charHeight;
\r
808 g.drawImage(fadedImage,
\r
809 0, y - row.height, imgWidth, y,
\r
810 0, y - row.height, imgWidth, y, this);
\r
811 g.setColor(Color.black);
\r
812 // g.drawString("Calculating Consensus....",20, y-row.height/2);
\r
816 else if (av.updatingConservation && aa[i].label.equals("Conservation"))
\r
819 y += av.charHeight;
\r
820 g.drawImage(fadedImage,
\r
821 0, y - row.height, imgWidth, y,
\r
822 0, y - row.height, imgWidth, y, this);
\r
824 g.setColor(Color.black);
\r
825 // g.drawString("Calculating Conservation.....",20, y-row.height/2);
\r
829 else if (av.updatingConservation && aa[i].label.equals("Quality"))
\r
832 y += av.charHeight;
\r
833 g.drawImage(fadedImage,
\r
834 0, y - row.height, imgWidth, y,
\r
835 0, y - row.height, imgWidth, y, this);
\r
836 g.setColor(Color.black);
\r
837 /// g.drawString("Calculating Quality....",20, y-row.height/2);
\r
844 iconOffset = av.charHeight / 2 + 4;
\r
852 while (x < endRes - startRes)
\r
854 if (av.hasHiddenColumns)
\r
856 column = av.getColumnSelection().adjustForHiddenColumns(startRes + x);
\r
857 if (column > row.annotations.length - 1)
\r
864 column = startRes + x;
\r
867 if ( (row.annotations.length <= column) ||
\r
868 (row.annotations[column] == null))
\r
877 if (activeRow == i)
\r
879 g.setColor(Color.red);
\r
881 if (av.getColumnSelection() != null)
\r
883 for (int n = 0; n < av.getColumnSelection().size(); n++)
\r
885 int v = av.getColumnSelection().columnAt(n);
\r
889 g.fillRect(x * av.charWidth, y,
\r
890 av.charWidth, av.charHeight);
\r
896 if (av.validCharWidth && validRes &&
\r
897 (row.annotations[column].displayCharacter.length() > 0))
\r
900 int charOffset = (av.charWidth -
\r
901 fm.charWidth(row.annotations[column].
\r
902 displayCharacter.charAt(
\r
904 g.setColor(row.annotations[column].colour);
\r
906 if (column == 0 || row.graph > 0)
\r
908 g.drawString(row.annotations[column].displayCharacter,
\r
909 (x * av.charWidth) + charOffset,
\r
913 row.annotations[column - 1] == null
\r
914 || (!row.annotations[column].displayCharacter.equals(
\r
915 row.annotations[column - 1].displayCharacter)
\r
917 (row.annotations[column].displayCharacter.length() < 2 &&
\r
918 row.annotations[column].secondaryStructure == ' ')))
\r
920 g.drawString(row.annotations[column].displayCharacter,
\r
921 x * av.charWidth + charOffset,
\r
929 (row.annotations[column].secondaryStructure != lastSS))
\r
934 g.setColor(HELIX_COLOUR);
\r
937 //Off by 1 offset when drawing rects and ovals
\r
938 //to offscreen image on the MAC
\r
939 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
\r
940 (x * av.charWidth) - lastSSX, 7, 8, 8);
\r
944 int sCol = (lastSSX / av.charWidth) + startRes;
\r
946 int x2 = (x * av.charWidth);
\r
949 row.annotations[sCol - 1] == null ||
\r
950 row.annotations[sCol - 1].secondaryStructure != 'H')
\r
952 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90,
\r
954 x1 += av.charWidth / 2;
\r
957 if (row.annotations[column] == null ||
\r
958 row.annotations[column].secondaryStructure != 'H')
\r
960 g.fillArc( (x * av.charWidth) - av.charWidth,
\r
961 y + 4 + iconOffset, av.charWidth, 8, 270, 180);
\r
962 x2 -= av.charWidth / 2;
\r
965 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
\r
969 g.setColor(SHEET_COLOUR);
\r
970 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
971 (x * av.charWidth) - lastSSX - 4, 7);
\r
972 g.fillPolygon(new int[]
\r
973 { (x * av.charWidth) - 4,
\r
974 (x * av.charWidth) - 4,
\r
975 (x * av.charWidth)},
\r
978 y + iconOffset, y + 14 + iconOffset,
\r
985 g.setColor(Color.gray);
\r
986 g.fillRect(lastSSX, y + 6 + iconOffset,
\r
987 (x * av.charWidth) - lastSSX, 2);
\r
994 lastSS = row.annotations[column].secondaryStructure;
\r
1001 lastSSX = (x * av.charWidth);
\r
1009 if (column >= row.annotations.length)
\r
1011 column = row.annotations.length - 1;
\r
1021 g.setColor(HELIX_COLOUR);
\r
1024 //Off by 1 offset when drawing rects and ovals
\r
1025 //to offscreen image on the MAC
\r
1026 g.fillRoundRect(lastSSX, y + 4 + iconOffset,
\r
1027 (x * av.charWidth) - lastSSX, 7, 8, 8);
\r
1031 int sCol = (lastSSX / av.charWidth) + startRes;
\r
1033 int x2 = (x * av.charWidth);
\r
1036 row.annotations[sCol - 1] == null ||
\r
1037 row.annotations[sCol - 1].secondaryStructure != 'H')
\r
1039 g.fillArc(lastSSX, y + 4 + iconOffset, av.charWidth, 8, 90, 180);
\r
1040 x1 += av.charWidth / 2;
\r
1043 if (row.annotations[column] == null ||
\r
1044 row.annotations[column].secondaryStructure != 'H')
\r
1046 g.fillArc( (x * av.charWidth) - av.charWidth,
\r
1047 y + 4 + iconOffset, av.charWidth, 8, 270,
\r
1049 x2 -= av.charWidth / 2;
\r
1052 g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8);
\r
1057 g.setColor(SHEET_COLOUR);
\r
1059 if (row.annotations[endRes] == null
\r
1060 || row.annotations[endRes].secondaryStructure != 'E')
\r
1062 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
1063 (x * av.charWidth) - lastSSX - 4, 7);
\r
1064 g.fillPolygon(new int[]
\r
1065 { (x * av.charWidth) - 4,
\r
1066 (x * av.charWidth) - 4,
\r
1067 (x * av.charWidth)},
\r
1070 y + iconOffset, y + 14 + iconOffset,
\r
1071 y + 7 + iconOffset
\r
1076 g.fillRect(lastSSX, y + 4 + iconOffset,
\r
1077 (x + 1) * av.charWidth - lastSSX, 7);
\r
1082 g.setColor(Color.gray);
\r
1083 g.fillRect(lastSSX, y + 6 + iconOffset,
\r
1084 (x * av.charWidth) - lastSSX, 2);
\r
1090 if (row.graph > 0 && row.graphHeight > 0)
\r
1092 if (row.graph == AlignmentAnnotation.LINE_GRAPH)
\r
1094 if (row.graphGroup > -1 && !graphGroupDrawn[row.graphGroup])
\r
1096 float groupmax = -999999, groupmin = 9999999;
\r
1097 for (int gg = 0; gg < aa.length; gg++)
\r
1099 if (aa[gg].graphGroup != row.graphGroup)
\r
1104 if (aa[gg] != row)
\r
1106 aa[gg].visible = false;
\r
1109 if (aa[gg].graphMax > groupmax)
\r
1111 groupmax = aa[gg].graphMax;
\r
1113 if (aa[gg].graphMin < groupmin)
\r
1115 groupmin = aa[gg].graphMin;
\r
1119 for (int gg = 0; gg < aa.length; gg++)
\r
1121 if (aa[gg].graphGroup == row.graphGroup)
\r
1123 drawLineGraph(g, aa[gg], startRes, endRes, y,
\r
1124 groupmin, groupmax,
\r
1129 graphGroupDrawn[row.graphGroup] = true;
\r
1133 drawLineGraph(g, row, startRes, endRes,
\r
1134 y, row.graphMin, row.graphMax, row.graphHeight);
\r
1137 else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
\r
1139 drawBarGraph(g, row, startRes, endRes,
\r
1140 row.graphMin, row.graphMax, y);
\r
1144 if (row.graph > 0 && row.hasText)
\r
1146 y += av.charHeight;
\r
1149 if (row.graph == 0)
\r
1151 y += aa[i].height;
\r
1156 public void drawLineGraph(Graphics g, AlignmentAnnotation aa,
\r
1157 int sRes, int eRes,
\r
1159 float min, float max,
\r
1162 if (sRes > aa.annotations.length)
\r
1169 //Adjustment for fastpaint to left
\r
1170 if (eRes < av.endRes)
\r
1175 eRes = Math.min(eRes, aa.annotations.length);
\r
1182 int y1 = y, y2 = y;
\r
1183 float range = max - min;
\r
1188 y2 = y - (int) ( (0 - min / range) * graphHeight);
\r
1191 g.setColor(Color.gray);
\r
1192 g.drawLine(x - av.charWidth, y2, (eRes - sRes + 1) * av.charWidth, y2);
\r
1194 eRes = Math.min(eRes, aa.annotations.length);
\r
1197 int aaMax = aa.annotations.length - 1;
\r
1199 while (x < eRes - sRes)
\r
1201 column = sRes + x;
\r
1202 if (av.hasHiddenColumns)
\r
1204 column = av.getColumnSelection().adjustForHiddenColumns(column);
\r
1207 if (column > aaMax)
\r
1212 if (aa.annotations[column] == null || aa.annotations[column - 1] == null)
\r
1218 g.setColor(aa.annotations[column].colour);
\r
1220 (int) ( ( (aa.annotations[column - 1].value - min) / range) * graphHeight);
\r
1222 (int) ( ( (aa.annotations[column].value - min) / range) * graphHeight);
\r
1224 g.drawLine(x * av.charWidth - av.charWidth / 2, y1,
\r
1225 x * av.charWidth + av.charWidth / 2, y2);
\r
1229 if (aa.threshold != null)
\r
1231 g.setColor(aa.threshold.colour);
\r
1232 Graphics2D g2 = (Graphics2D) g;
\r
1233 g2.setStroke(new BasicStroke(1,
\r
1234 BasicStroke.CAP_SQUARE,
\r
1235 BasicStroke.JOIN_ROUND, 3f,
\r
1239 y2 = (int) (y - ( (aa.threshold.value - min) / range) * graphHeight);
\r
1240 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
\r
1241 g2.setStroke(new BasicStroke());
\r
1245 public void drawBarGraph(Graphics g, AlignmentAnnotation aa,
\r
1246 int sRes, int eRes,
\r
1247 float min, float max,
\r
1250 if (sRes > aa.annotations.length)
\r
1255 eRes = Math.min(eRes, aa.annotations.length);
\r
1257 int x = 0, y1 = y, y2 = y;
\r
1259 float range = max - min;
\r
1263 y2 = y - (int) ( (0 - min / (range)) * aa.graphHeight);
\r
1266 g.setColor(Color.gray);
\r
1268 g.drawLine(x, y2, (eRes - sRes) * av.charWidth, y2);
\r
1271 int aaMax = aa.annotations.length - 1;
\r
1273 while (x < eRes - sRes)
\r
1275 column = sRes + x;
\r
1276 if (av.hasHiddenColumns)
\r
1278 column = av.getColumnSelection().adjustForHiddenColumns(column);
\r
1281 if (column > aaMax)
\r
1286 if (aa.annotations[column] == null)
\r
1292 g.setColor(aa.annotations[column].colour);
\r
1294 (int) ( ( (aa.annotations[column].value - min) / (range)) * aa.graphHeight);
\r
1298 g.fillRect(x * av.charWidth, y2, av.charWidth, y1 - y2);
\r
1302 g.fillRect(x * av.charWidth, y1, av.charWidth, y2 - y1);
\r
1308 if (aa.threshold != null)
\r
1310 g.setColor(aa.threshold.colour);
\r
1311 Graphics2D g2 = (Graphics2D) g;
\r
1312 g2.setStroke(new BasicStroke(1,
\r
1313 BasicStroke.CAP_SQUARE,
\r
1314 BasicStroke.JOIN_ROUND, 3f,
\r
1318 y2 = (int) (y - ( (aa.threshold.value - min) / range) * aa.graphHeight);
\r
1319 g.drawLine(0, y2, (eRes - sRes) * av.charWidth, y2);
\r
1320 g2.setStroke(new BasicStroke());
\r
1324 // used by overview window
\r
1325 public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y,
\r
1326 int sRes, int eRes)
\r
1328 eRes = Math.min(eRes, aa.annotations.length);
\r
1329 g.setColor(Color.white);
\r
1330 g.fillRect(0, 0, width, y);
\r
1331 g.setColor(new Color(0, 0, 180));
\r
1333 int x = 0, height;
\r
1335 for (int j = sRes; j < eRes; j++)
\r
1337 if (aa.annotations[j] != null)
\r
1339 g.setColor(aa.annotations[j].colour);
\r
1341 height = (int) ( (aa.annotations[j].value / aa.graphMax) * y);
\r
1347 g.fillRect(x, y - height, av.charWidth, height);
\r
1349 x += av.charWidth;
\r