X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationPanel.java;h=9ae103ea8a50102c5d6ca7c7a6695252322cc35e;hb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;hp=a6c2055230f953ce3687ee212899a59abb4f0e9c;hpb=9257b8510c7354cbd7e43a3fc2817978cc8e4ae9;p=jalview.git diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index a6c2055..9ae103e 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -18,751 +18,841 @@ */ package jalview.gui; -import java.util.*; +import jalview.datamodel.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; + +import java.util.*; + import javax.swing.*; -import jalview.datamodel.*; -public class AnnotationPanel - extends JPanel implements MouseListener, +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class AnnotationPanel extends JPanel implements MouseListener, MouseMotionListener, ActionListener, AdjustmentListener { - static String HELIX = "Helix"; - static String SHEET = "Sheet"; - static String LABEL = "Label"; - static String REMOVE = "Remove Annotation"; - static String COLOUR = "Colour"; - static Color HELIX_COLOUR = Color.red.darker(); - static Color SHEET_COLOUR = Color.green.darker().darker(); - - public static int GRAPH_HEIGHT = 40; - AlignViewport av; - AlignmentPanel ap; - int activeRow = -1; - Vector activeRes; - BufferedImage image; - Graphics2D gg; - FontMetrics fm; - int imgWidth = 0; - boolean fastPaint = false; - - public AnnotationPanel(AlignmentPanel ap) - { - ToolTipManager.sharedInstance().registerComponent(this); - ToolTipManager.sharedInstance().setInitialDelay(0); - ToolTipManager.sharedInstance().setDismissDelay(10000); - this.ap = ap; - av = ap.av; - this.setLayout(null); - addMouseListener(this); - addMouseMotionListener(this); - ap.annotationScroller.getVerticalScrollBar().addAdjustmentListener(this); - } - - public void adjustmentValueChanged(AdjustmentEvent evt) - { - ap.alabels.setScrollOffset( -evt.getValue()); - } - - public void adjustPanelHeight() - { - // setHeight of panels - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - int height = 0; - - if (aa != null) + static String HELIX = "Helix"; + static String SHEET = "Sheet"; + static String LABEL = "Label"; + static String REMOVE = "Remove Annotation"; + static String COLOUR = "Colour"; + static Color HELIX_COLOUR = Color.red.darker(); + static Color SHEET_COLOUR = Color.green.darker().darker(); + + /** DOCUMENT ME!! */ + public static int GRAPH_HEIGHT = 40; + AlignViewport av; + AlignmentPanel ap; + int activeRow = -1; + Vector activeRes; + BufferedImage image; + Graphics2D gg; + FontMetrics fm; + int imgWidth = 0; + boolean fastPaint = false; + + /** + * Creates a new AnnotationPanel object. + * + * @param ap DOCUMENT ME! + */ + public AnnotationPanel(AlignmentPanel ap) { - for (int i = 0; i < aa.length; i++) - { - if (!aa[i].visible) - { - continue; - } + ToolTipManager.sharedInstance().registerComponent(this); + ToolTipManager.sharedInstance().setInitialDelay(0); + ToolTipManager.sharedInstance().setDismissDelay(10000); + this.ap = ap; + av = ap.av; + this.setLayout(null); + addMouseListener(this); + addMouseMotionListener(this); + ap.annotationScroller.getVerticalScrollBar().addAdjustmentListener(this); + } - aa[i].height = 0; + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void adjustmentValueChanged(AdjustmentEvent evt) + { + ap.alabels.setScrollOffset(-evt.getValue()); + } - if (aa[i].hasText) + /** + * DOCUMENT ME! + */ + public void adjustPanelHeight() + { + // setHeight of panels + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + int height = 0; + + if (aa != null) { - aa[i].height += av.charHeight; + for (int i = 0; i < aa.length; i++) + { + if (!aa[i].visible) + { + continue; + } + + aa[i].height = 0; + + if (aa[i].hasText) + { + aa[i].height += av.charHeight; + } + + if (aa[i].hasIcons) + { + aa[i].height += 16; + } + + if (aa[i].isGraph) + { + aa[i].height += GRAPH_HEIGHT; + } + + if (aa[i].height == 0) + { + aa[i].height = 20; + } + + height += aa[i].height; + } } - - if (aa[i].hasIcons) + else { - aa[i].height += 16; + height = 20; } - if (aa[i].isGraph) + this.setPreferredSize(new Dimension(1, height)); + } + + /** + * DOCUMENT ME! + * + * @param col DOCUMENT ME! + */ + public void removeEditableColumn(int col) + { + if (activeRow == -1) { - aa[i].height += GRAPH_HEIGHT; + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + + for (int j = 0; j < aa.length; j++) + { + if (aa[j].editable) + { + activeRow = j; + + break; + } + } } - if (aa[i].height == 0) + if ((activeRes != null) && activeRes.contains(String.valueOf(col))) { - aa[i].height = 20; + activeRes.removeElement(String.valueOf(col)); } - height += aa[i].height; - } + repaint(); } - else + + /** + * DOCUMENT ME! + * + * @param col DOCUMENT ME! + */ + public void addEditableColumn(int col) { - height = 20; - } + if (activeRow == -1) + { + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - this.setPreferredSize(new Dimension(1, height)); - } + for (int j = 0; j < aa.length; j++) + { + if (aa[j].editable) + { + activeRow = j; + break; + } + } + } - public void removeEditableColumn(int col) - { - if (activeRow == -1) - { - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if (activeRes == null) + { + activeRes = new Vector(); + } - for (int j = 0; j < aa.length; j++) - { - if (aa[j].editable) + if (!activeRes.contains(String.valueOf(col))) { - activeRow = j; - break; + activeRes.addElement(String.valueOf(col)); } - } - } - if (activeRes != null && activeRes.contains(String.valueOf(col))) - { - activeRes.removeElement(String.valueOf(col)); + repaint(); } - repaint(); - } - - public void addEditableColumn(int col) - { - if (activeRow == -1) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void actionPerformed(ActionEvent evt) { - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + Annotation[] anot = aa[activeRow].annotations; - for (int j = 0; j < aa.length; j++) - { - if (aa[j].editable) + if (evt.getActionCommand().equals(REMOVE)) { - activeRow = j; - break; + for (int i = 0; i < activeRes.size(); i++) + { + anot[Integer.parseInt(activeRes.get(i).toString())] = null; + anot[Integer.parseInt(activeRes.get(i).toString())] = null; + } } - } - } - - if (activeRes == null) - activeRes = new Vector(); + else if (evt.getActionCommand().equals(LABEL)) + { + String label = JOptionPane.showInputDialog(this, "Enter Label ", + "Enter label", JOptionPane.QUESTION_MESSAGE); - if (!activeRes.contains(String.valueOf(col))) - activeRes.addElement(String.valueOf(col)); + if (label == null) + { + return; + } - repaint(); - } + if ((label.length() > 0) && !aa[activeRow].hasText) + { + aa[activeRow].hasText = true; + } - public void actionPerformed(ActionEvent evt) - { - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - Annotation[] anot = aa[activeRow].annotations; + for (int i = 0; i < activeRes.size(); i++) + { + int index = Integer.parseInt(activeRes.get(i).toString()); - if (evt.getActionCommand().equals(REMOVE)) - { - for (int i = 0; i < activeRes.size(); i++) - { - anot[Integer.parseInt(activeRes.get(i).toString())] = null; - anot[Integer.parseInt(activeRes.get(i).toString())] = null; - } - } - else if (evt.getActionCommand().equals(LABEL)) - { - String label = JOptionPane.showInputDialog(this, "Enter Label ", - "Enter label", - JOptionPane.QUESTION_MESSAGE); + if (anot[index] == null) + { + anot[index] = new Annotation(label, "", ' ', 0); + } - if (label == null) - return; + anot[index].displayCharacter = label; + } + } + else if (evt.getActionCommand().equals(COLOUR)) + { + Color col = JColorChooser.showDialog(this, + "Choose foreground colour", Color.black); - if ( (label.length() > 0) && !aa[activeRow].hasText) - { - aa[activeRow].hasText = true; - } + for (int i = 0; i < activeRes.size(); i++) + { + int index = Integer.parseInt(activeRes.get(i).toString()); - for (int i = 0; i < activeRes.size(); i++) - { - int index = Integer.parseInt(activeRes.get(i).toString()); + if (anot[index] == null) + { + anot[index] = new Annotation("", "", ' ', 0); + } - if (anot[index] == null) - { - anot[index] = new Annotation(label, "", ' ', 0); + anot[index].colour = col; + } } - anot[index].displayCharacter = label; - } - } - else if (evt.getActionCommand().equals(COLOUR)) - { - Color col = JColorChooser.showDialog(this, - "Choose foreground colour", - Color.black); - - for (int i = 0; i < activeRes.size(); i++) - { - int index = Integer.parseInt(activeRes.get(i).toString()); - - if (anot[index] == null) + else // HELIX OR SHEET { - anot[index] = new Annotation("", "", ' ', 0); - } + char type = 0; + String symbol = "\u03B1"; - anot[index].colour = col; - } - } - else // HELIX OR SHEET - { - char type = 0; - String symbol = "\u03B1"; - - if (evt.getActionCommand().equals(HELIX)) - { - type = 'H'; - } - else if (evt.getActionCommand().equals(SHEET)) - { - type = 'E'; - symbol = "\u03B2"; - } - - if (!aa[activeRow].hasIcons) - { - aa[activeRow].hasIcons = true; - } - - String label = JOptionPane.showInputDialog( - "Enter a label for the structure?", - symbol); - - if (label == null) - return; - - if ( (label.length() > 0) && !aa[activeRow].hasText) - { - aa[activeRow].hasText = true; - } + if (evt.getActionCommand().equals(HELIX)) + { + type = 'H'; + } + else if (evt.getActionCommand().equals(SHEET)) + { + type = 'E'; + symbol = "\u03B2"; + } - for (int i = 0; i < activeRes.size(); i++) - { - int index = Integer.parseInt(activeRes.get(i).toString()); + if (!aa[activeRow].hasIcons) + { + aa[activeRow].hasIcons = true; + } - if (anot[index] == null) - { - anot[index] = new Annotation(label, "", type, 0); - } + String label = JOptionPane.showInputDialog("Enter a label for the structure?", + symbol); - anot[index].secondaryStructure = type; - anot[index].displayCharacter = label; - } - } + if (label == null) + { + return; + } - adjustPanelHeight(); - activeRes = null; - repaint(); + if ((label.length() > 0) && !aa[activeRow].hasText) + { + aa[activeRow].hasText = true; + } - return; - } + for (int i = 0; i < activeRes.size(); i++) + { + int index = Integer.parseInt(activeRes.get(i).toString()); - public void mousePressed(MouseEvent evt) - { - int height = 0; - activeRow = -1; - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if (anot[index] == null) + { + anot[index] = new Annotation(label, "", type, 0); + } - for (int i = 0; i < aa.length; i++) - { - height += aa[i].height; + anot[index].secondaryStructure = type; + anot[index].displayCharacter = label; + } + } - if (evt.getY() < height) - { - if (aa[i].editable) - activeRow = i; - else - activeRes = null; + adjustPanelHeight(); + activeRes = null; + repaint(); - break; - } + return; } - - if (SwingUtilities.isRightMouseButton(evt)) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void mousePressed(MouseEvent evt) { - if (activeRes == null) - { - return; - } - - - JPopupMenu pop = new JPopupMenu("Structure type"); - JMenuItem item = new JMenuItem(HELIX); - item.addActionListener(this); - pop.add(item); - item = new JMenuItem(SHEET); - item.addActionListener(this); - pop.add(item); - item = new JMenuItem(LABEL); - item.addActionListener(this); - pop.add(item); - item = new JMenuItem(COLOUR); - item.addActionListener(this); - pop.add(item); - item = new JMenuItem(REMOVE); - item.addActionListener(this); - pop.add(item); - pop.show(this, evt.getX(), evt.getY()); - - return; - } + int height = 0; + activeRow = -1; + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - if (aa == null) - { - return; - } + for (int i = 0; i < aa.length; i++) + { + height += aa[i].height; + if (evt.getY() < height) + { + if (aa[i].editable) + { + activeRow = i; + } + else + { + activeRes = null; + } - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); + break; + } + } - if (evt.isControlDown() || evt.isAltDown()) - { - addEditableColumn(res); - } - else if (evt.isShiftDown()) - { - if (activeRes == null) - { - activeRes = new Vector(); - } - else - { - int start = Integer.parseInt(activeRes.get(activeRes.size() - - 1).toString()); - int end = res; - - if (end < start) + if (SwingUtilities.isRightMouseButton(evt)) { - int temp = end; - end = start; - start = temp; + if (activeRes == null) + { + return; + } + + JPopupMenu pop = new JPopupMenu("Structure type"); + JMenuItem item = new JMenuItem(HELIX); + item.addActionListener(this); + pop.add(item); + item = new JMenuItem(SHEET); + item.addActionListener(this); + pop.add(item); + item = new JMenuItem(LABEL); + item.addActionListener(this); + pop.add(item); + item = new JMenuItem(COLOUR); + item.addActionListener(this); + pop.add(item); + item = new JMenuItem(REMOVE); + item.addActionListener(this); + pop.add(item); + pop.show(this, evt.getX(), evt.getY()); + + return; } - for (int n = start; n <= end; n++) + if (aa == null) { - addEditableColumn(n); + return; } - } - } - else - { - activeRes = new Vector(); - activeRes.addElement(String.valueOf(res)); - } - - repaint(); - } - - public void mouseReleased(MouseEvent evt) - { - } - - public void mouseEntered(MouseEvent evt) - { - } - public void mouseExited(MouseEvent evt) - { - } + int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - public void mouseDragged(MouseEvent evt) - { - } + if (evt.isControlDown() || evt.isAltDown()) + { + addEditableColumn(res); + } + else if (evt.isShiftDown()) + { + if (activeRes == null) + { + activeRes = new Vector(); + } + else + { + int start = Integer.parseInt(activeRes.get(activeRes.size() - + 1).toString()); + int end = res; + + if (end < start) + { + int temp = end; + end = start; + start = temp; + } + + for (int n = start; n <= end; n++) + { + addEditableColumn(n); + } + } + } + else + { + activeRes = new Vector(); + activeRes.addElement(String.valueOf(res)); + } - public void mouseMoved(MouseEvent evt) - { - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + repaint(); + } - if (aa == null) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void mouseReleased(MouseEvent evt) { - return; } - int row = -1; - int height = 0; - - for (int i = 0; i < aa.length; i++) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void mouseEntered(MouseEvent evt) { - if (aa[i].visible) - { - height += aa[i].height; - } - - if (evt.getY() < height) - { - row = i; - - break; - } } - int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - - if ( (row > -1) && (res < aa[row].annotations.length) && - (aa[row].annotations[res] != null)) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void mouseExited(MouseEvent evt) { - this.setToolTipText(aa[row].annotations[res].description); - - StringBuffer text = new StringBuffer("Sequence position " + - (res + 1) + " " + - aa[row].annotations[res].description); - ap.alignFrame.statusBar.setText(text.toString()); } - } - public void mouseClicked(MouseEvent evt) - { - } - - public void paintComponent(Graphics g) - { - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); - - if (fastPaint) + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void mouseDragged(MouseEvent evt) { - g.drawImage(image, 0, 0, this); - fastPaint = false; - - return; } - imgWidth = (av.endRes - av.startRes + 1) * av.charWidth; + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void mouseMoved(MouseEvent evt) + { + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(), - BufferedImage.TYPE_INT_RGB); - gg = (Graphics2D) image.getGraphics(); - gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + if (aa == null) + { + return; + } - gg.setFont(av.getFont()); - fm = gg.getFontMetrics(); + int row = -1; + int height = 0; - drawComponent(gg, av.startRes, av.endRes + 1); - g.drawImage(image, 0, 0, this); - } + for (int i = 0; i < aa.length; i++) + { + if (aa[i].visible) + { + height += aa[i].height; + } - public void fastPaint(int horizontal) - { - if ( (horizontal == 0) || - (av.alignment.getAlignmentAnnotation() == null) || - (av.alignment.getAlignmentAnnotation().length < 1)) - { - repaint(); + if (evt.getY() < height) + { + row = i; - return; - } + break; + } + } - gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0); + int res = (evt.getX() / av.getCharWidth()) + av.getStartRes(); - int sr = av.startRes; - int er = av.endRes + 1; - int transX = 0; + if ((row > -1) && (res < aa[row].annotations.length) && + (aa[row].annotations[res] != null)) + { + this.setToolTipText(aa[row].annotations[res].description); - if (horizontal > 0) // scrollbar pulled right, image to the left - { - transX = (er - sr - horizontal) * av.charWidth; - sr = er - horizontal; + StringBuffer text = new StringBuffer("Sequence position " + + (res + 1) + " " + aa[row].annotations[res].description); + ap.alignFrame.statusBar.setText(text.toString()); + } } - else if (horizontal < 0) + + /** + * DOCUMENT ME! + * + * @param evt DOCUMENT ME! + */ + public void mouseClicked(MouseEvent evt) { - er = sr - horizontal; } - gg.translate(transX, 0); + /** + * DOCUMENT ME! + * + * @param g DOCUMENT ME! + */ + public void paintComponent(Graphics g) + { + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); - drawComponent(gg, sr, er); + if (fastPaint) + { + g.drawImage(image, 0, 0, this); + fastPaint = false; - gg.translate( -transX, 0); + return; + } - fastPaint = true; - repaint(); - } + imgWidth = (av.endRes - av.startRes + 1) * av.charWidth; - public void drawComponent(Graphics2D g, int startRes, int endRes) - { - g.setColor(Color.white); - g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight()); + image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(), + BufferedImage.TYPE_INT_RGB); + gg = (Graphics2D) image.getGraphics(); + gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); - if ( (av.alignment.getAlignmentAnnotation() == null) || - (av.alignment.getAlignmentAnnotation().length < 1)) - { - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); - g.setColor(Color.black); - g.drawString("Alignment has no annotations", 20, 15); + gg.setFont(av.getFont()); - return; + drawComponent(gg, av.startRes, av.endRes + 1); + g.drawImage(image, 0, 0, this); } - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - - int j; - int x = 0; - int y = 0; - char[] lastSS = new char[aa.length]; - int[] lastSSX = new int[aa.length]; - int iconOffset = av.charHeight / 2; - boolean validRes = false; - - //\u03B2 \u03B1 - for (int i = 0; i < aa.length; i++) + /** + * DOCUMENT ME! + * + * @param horizontal DOCUMENT ME! + */ + public void fastPaint(int horizontal) { - AlignmentAnnotation row = aa[i]; + if ((horizontal == 0) || + (av.alignment.getAlignmentAnnotation() == null) || + (av.alignment.getAlignmentAnnotation().length < 1)) + { + repaint(); - if (!row.visible) - { - continue; - } + return; + } - if (row.isGraph) - { - // this is so that we draw the characters below the graph - y += row.height; + gg.copyArea(0, 0, imgWidth, getHeight(), -horizontal * av.charWidth, 0); - if (row.hasText) - { - y -= av.charHeight; - } - } - - if (row.hasText) - { - iconOffset = av.charHeight / 2; - } - else - { - iconOffset = 0; - } - - for (j = startRes; j < endRes; j++) - { - if ( (row.annotations.length <= j) || - (row.annotations[j] == null)) + int sr = av.startRes; + int er = av.endRes + 1; + int transX = 0; + + if (horizontal > 0) // scrollbar pulled right, image to the left { - validRes = false; + transX = (er - sr - horizontal) * av.charWidth; + sr = er - horizontal; } - else + else if (horizontal < 0) { - validRes = true; + er = sr - horizontal; } - x = (j - startRes) * av.charWidth; + gg.translate(transX, 0); - if (activeRow == i) - { - g.setColor(Color.red); + drawComponent(gg, sr, er); - if (activeRes != null) - { - for (int n = 0; n < activeRes.size(); n++) - { - int v = Integer.parseInt(activeRes.get(n).toString()); + gg.translate(-transX, 0); - if (v == j) - { - g.fillRect( (j - startRes) * av.charWidth, y, - av.charWidth, row.height); - } - } - } - } + fastPaint = true; + repaint(); + } - if (validRes && - (row.annotations[j].displayCharacter.length() > 0)) - { - int charOffset = (av.charWidth - - fm.charWidth(row.annotations[j].displayCharacter. - charAt( - 0))) / 2; - g.setColor(row.annotations[j].colour); - - if (j == 0) - { - g.drawString(row.annotations[j].displayCharacter, - x, y + iconOffset + 2); - } - else if ( - ( (row.annotations[j - 1] == null) || - (row.annotations[j].displayCharacter != row.annotations[j - - 1].displayCharacter))) - { - g.drawString(row.annotations[j].displayCharacter, x, - y + iconOffset + 2); - } + /** + * DOCUMENT ME! + * + * @param g DOCUMENT ME! + * @param startRes DOCUMENT ME! + * @param endRes DOCUMENT ME! + */ + public void drawComponent(Graphics2D g, int startRes, int endRes) + { + if(fm==null) + fm = g.getFontMetrics(); - } + g.setColor(Color.white); + g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight()); - if (row.hasIcons) + if ((av.alignment.getAlignmentAnnotation() == null) || + (av.alignment.getAlignmentAnnotation().length < 1)) { - if (!validRes || - (row.annotations[j].secondaryStructure != lastSS[i])) - { - switch (lastSS[i]) - { - case 'H': - g.setColor(HELIX_COLOUR); - g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, - x - lastSSX[i], 7, 8, 8); + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); + g.setColor(Color.black); + g.drawString("Alignment has no annotations", 20, 15); - break; + return; + } - case 'E': - g.setColor(SHEET_COLOUR); - g.fillRect(lastSSX[i], y + 4 + iconOffset, - x - lastSSX[i] - 4, 7); - g.fillPolygon(new int[] - {x - 4, x - 4, x}, - new int[] - { - y + iconOffset, y + 14 + iconOffset, - y + 8 + iconOffset - }, 3); + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - break; + int j; + int x = 0; + int y = 0; + char[] lastSS = new char[aa.length]; + int[] lastSSX = new int[aa.length]; + int iconOffset = av.charHeight / 2; + boolean validRes = false; - case 'C': - break; + //\u03B2 \u03B1 + for (int i = 0; i < aa.length; i++) + { + AlignmentAnnotation row = aa[i]; - default: - g.setColor(Color.gray); - g.fillRect(lastSSX[i], y + 6 + iconOffset, - x - lastSSX[i], 2); + if (!row.visible) + { + continue; + } - break; + if (row.isGraph) + { + // this is so that we draw the characters below the graph + y += row.height; + + if (row.hasText) + { + y -= av.charHeight; + } } - if (validRes) + if (row.hasText) { - lastSS[i] = row.annotations[j].secondaryStructure; + iconOffset = av.charHeight / 2; } else { - lastSS[i] = ' '; + iconOffset = 0; } - lastSSX[i] = x; - } - } - - if (validRes && row.isGraph) - { - g.setColor(new Color(0, 0, 180)); - - int height = (int) ( (row.annotations[j].value / row.graphMax) * - GRAPH_HEIGHT); - - if (row.windowLength > 1) - { - int total = 0; - - for (int i2 = j - (row.windowLength / 2); - i2 < (j + (row.windowLength / 2)); i2++) + for (j = startRes; j < endRes; j++) { - if ( (i2 < 0) || (i2 >= av.alignment.getWidth())) - { - continue; - } + if ((row.annotations.length <= j) || + (row.annotations[j] == null)) + { + validRes = false; + } + else + { + validRes = true; + } + + x = (j - startRes) * av.charWidth; + + if (activeRow == i) + { + g.setColor(Color.red); + + if (activeRes != null) + { + for (int n = 0; n < activeRes.size(); n++) + { + int v = Integer.parseInt(activeRes.get(n).toString()); + + if (v == j) + { + g.fillRect((j - startRes) * av.charWidth, y, + av.charWidth, row.height); + } + } + } + } + + if (validRes && + (row.annotations[j].displayCharacter.length() > 0)) + { + int charOffset = (av.charWidth - + fm.charWidth(row.annotations[j].displayCharacter.charAt( + 0))) / 2; + g.setColor(row.annotations[j].colour); + + if (j == 0) + { + g.drawString(row.annotations[j].displayCharacter, x+charOffset, + y + iconOffset + 2); + } + else if (((row.annotations[j - 1] == null) || + (row.annotations[j].displayCharacter != row.annotations[j - + 1].displayCharacter))) + { + g.drawString(row.annotations[j].displayCharacter, x+charOffset, + y + iconOffset + 2); + } + } + + if (row.hasIcons) + { + if (!validRes || + (row.annotations[j].secondaryStructure != lastSS[i])) + { + switch (lastSS[i]) + { + case 'H': + g.setColor(HELIX_COLOUR); + g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i], 7, 8, 8); - total += row.annotations[i2].value; + break; + + case 'E': + g.setColor(SHEET_COLOUR); + g.fillRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i] - 4, 7); + g.fillPolygon(new int[] { x - 4, x - 4, x }, + new int[] + { + y + iconOffset, y + 14 + iconOffset, + y + 8 + iconOffset + }, 3); + + break; + + case 'C': + break; + + default: + g.setColor(Color.gray); + g.fillRect(lastSSX[i], y + 6 + iconOffset, + x - lastSSX[i], 2); + + break; + } + + if (validRes) + { + lastSS[i] = row.annotations[j].secondaryStructure; + } + else + { + lastSS[i] = ' '; + } + + lastSSX[i] = x; + } + } + + if (validRes && row.isGraph) + { + g.setColor(new Color(0, 0, 180)); + + int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT); + + if (row.windowLength > 1) + { + int total = 0; + + for (int i2 = j - (row.windowLength / 2); + i2 < (j + (row.windowLength / 2)); i2++) + { + if ((i2 < 0) || (i2 >= av.alignment.getWidth())) + { + continue; + } + + total += row.annotations[i2].value; + } + + total /= row.windowLength; + height = (int) ((total / row.graphMax) * GRAPH_HEIGHT); + } + + g.setColor(row.annotations[j].colour); + g.fillRect(x, y - height, av.charWidth, height); + } } - total /= row.windowLength; - height = (int) ( (total / row.graphMax) * GRAPH_HEIGHT); - } + x += av.charWidth; - g.setColor(row.annotations[j].colour); - g.fillRect(x, y - height, av.charWidth, height); - } - } + if (row.hasIcons) + { + switch (lastSS[i]) + { + case 'H': + g.setColor(HELIX_COLOUR); + g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i], 7, 8, 8); + + break; + + case 'E': + g.setColor(SHEET_COLOUR); + g.fillRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i] - 4, 7); + g.fillPolygon(new int[] { x - 4, x - 4, x }, + new int[] + { + y + iconOffset, y + 14 + iconOffset, + y + 7 + iconOffset + }, 3); + + break; + + case 'C': + break; + + default: + g.setColor(Color.gray); + g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2); + + break; + } + } - x += av.charWidth; + if (row.isGraph && row.hasText) + { + y += av.charHeight; + } - if (row.hasIcons) - { - switch (lastSS[i]) - { - case 'H': - g.setColor(HELIX_COLOUR); - g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, - x - lastSSX[i], 7, 8, 8); - - break; - - case 'E': - g.setColor(SHEET_COLOUR); - g.fillRect(lastSSX[i], y + 4 + iconOffset, - x - lastSSX[i] - 4, 7); - g.fillPolygon(new int[] - {x - 4, x - 4, x}, - new int[] - { - y + iconOffset, y + 14 + iconOffset, - y + 7 + iconOffset - }, 3); - - break; - - case 'C': - break; - - default: - g.setColor(Color.gray); - g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2); - - break; + if (!row.isGraph) + { + y += aa[i].height; + } } - } - - if (row.isGraph && row.hasText) - { - y += av.charHeight; - } - - if (!row.isGraph) - { - y += aa[i].height; - } } - } - // used by overview window - public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y) - { - g.setColor(Color.white); - g.fillRect(0, 0, width, y); - g.setColor(new Color(0, 0, 180)); + // used by overview window + public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y) + { + g.setColor(Color.white); + g.fillRect(0, 0, width, y); + g.setColor(new Color(0, 0, 180)); - int x = 0; + int x = 0; - for (int j = 0; j < aa.annotations.length; j++) - { - g.setColor(new Color(0, 0, 180)); + for (int j = 0; j < aa.annotations.length; j++) + { + g.setColor(new Color(0, 0, 180)); - int height = (int) ( (aa.annotations[j].value / aa.graphMax) * - GRAPH_HEIGHT); - g.fillRect(x, y - height, av.charWidth, height); - x += av.charWidth; + int height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); + g.fillRect(x, y - height, av.charWidth, height); + x += av.charWidth; + } } - } }