2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignmentUtils;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.Annotation;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceGroup;
29 import jalview.datamodel.SequenceI;
30 import jalview.io.FileFormat;
31 import jalview.io.FormatAdapter;
32 import jalview.util.MessageManager;
34 import java.awt.Color;
35 import java.awt.Dimension;
37 import java.awt.FontMetrics;
38 import java.awt.Graphics;
39 import java.awt.Graphics2D;
40 import java.awt.Image;
41 import java.awt.MediaTracker;
42 import java.awt.RenderingHints;
43 import java.awt.Toolkit;
44 import java.awt.datatransfer.StringSelection;
45 import java.awt.event.ActionEvent;
46 import java.awt.event.ActionListener;
47 import java.awt.event.MouseEvent;
48 import java.awt.event.MouseListener;
49 import java.awt.event.MouseMotionListener;
50 import java.awt.geom.AffineTransform;
51 import java.awt.image.BufferedImage;
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.Collections;
55 import java.util.regex.Pattern;
57 import javax.swing.JCheckBoxMenuItem;
58 import javax.swing.JMenuItem;
59 import javax.swing.JPanel;
60 import javax.swing.JPopupMenu;
61 import javax.swing.SwingUtilities;
62 import javax.swing.ToolTipManager;
70 public class AnnotationLabels extends JPanel
71 implements MouseListener, MouseMotionListener, ActionListener
73 private static final Pattern LEFT_ANGLE_BRACKET_PATTERN = Pattern
77 String TOGGLE_LABELSCALE = MessageManager
78 .getString("label.scale_label_to_column");
80 String ADDNEW = MessageManager.getString("label.add_new_row");
82 String EDITNAME = MessageManager
83 .getString("label.edit_label_description");
85 String HIDE = MessageManager.getString("label.hide_row");
87 String DELETE = MessageManager.getString("label.delete_row");
89 String SHOWALL = MessageManager.getString("label.show_all_hidden_rows");
91 String OUTPUT_TEXT = MessageManager.getString("label.export_annotation");
93 String COPYCONS_SEQ = MessageManager
94 .getString("label.copy_consensus_sequence");
96 boolean resizePanel = false;
104 boolean resizing = false;
106 MouseEvent dragEvent;
112 private int scrollOffset = 0;
114 Font font = new Font("Arial", Font.PLAIN, 11);
116 private boolean hasHiddenRows;
119 * Creates a new AnnotationLabels object.
124 public AnnotationLabels(AlignmentPanel ap)
128 ToolTipManager.sharedInstance().registerComponent(this);
130 java.net.URL url = getClass().getResource("/images/idwidth.gif");
135 temp = java.awt.Toolkit.getDefaultToolkit().createImage(url);
140 MediaTracker mt = new MediaTracker(this);
141 mt.addImage(temp, 0);
143 } catch (Exception ex)
147 BufferedImage bi = new BufferedImage(temp.getHeight(this),
148 temp.getWidth(this), BufferedImage.TYPE_INT_RGB);
149 Graphics2D g = (Graphics2D) bi.getGraphics();
150 g.rotate(Math.toRadians(90));
151 g.drawImage(temp, 0, -bi.getWidth(this), this);
154 addMouseListener(this);
155 addMouseMotionListener(this);
156 addMouseWheelListener(ap.getAnnotationPanel());
159 public AnnotationLabels(AlignViewport av)
170 public void setScrollOffset(int y)
177 * sets selectedRow to -2 if no annotation preset, -1 if no visible row is at
181 * coordinate position to search for a row
183 void getSelectedRow(int y)
186 AlignmentAnnotation[] aa = ap.av.getAlignment()
187 .getAlignmentAnnotation();
191 for (int i = 0; i < aa.length; i++)
199 height += aa[i].height;
218 public void actionPerformed(ActionEvent evt)
220 AlignmentAnnotation[] aa = ap.av.getAlignment()
221 .getAlignmentAnnotation();
223 boolean fullRepaint = false;
224 if (evt.getActionCommand().equals(ADDNEW))
226 AlignmentAnnotation newAnnotation = new AlignmentAnnotation(null,
227 null, new Annotation[ap.av.getAlignment().getWidth()]);
229 if (!editLabelDescription(newAnnotation))
234 ap.av.getAlignment().addAnnotation(newAnnotation);
235 ap.av.getAlignment().setAnnotationIndex(newAnnotation, 0);
238 else if (evt.getActionCommand().equals(EDITNAME))
240 String name = aa[selectedRow].label;
241 editLabelDescription(aa[selectedRow]);
242 if (!name.equalsIgnoreCase(aa[selectedRow].label))
247 else if (evt.getActionCommand().equals(HIDE))
249 aa[selectedRow].visible = false;
251 else if (evt.getActionCommand().equals(DELETE))
253 ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
254 ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
257 else if (evt.getActionCommand().equals(SHOWALL))
259 for (int i = 0; i < aa.length; i++)
261 if (!aa[i].visible && aa[i].annotations != null)
263 aa[i].visible = true;
268 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
270 new AnnotationExporter().exportAnnotations(ap,
271 new AlignmentAnnotation[]
272 { aa[selectedRow] });
274 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
276 SequenceI cons = null;
277 if (aa[selectedRow].groupRef != null)
279 cons = aa[selectedRow].groupRef.getConsensusSeq();
283 cons = av.getConsensusSeq();
287 copy_annotseqtoclipboard(cons);
291 else if (evt.getActionCommand().equals(TOGGLE_LABELSCALE))
293 aa[selectedRow].scaleColLabel = !aa[selectedRow].scaleColLabel;
296 ap.refresh(fullRepaint);
306 boolean editLabelDescription(AlignmentAnnotation annotation)
309 EditNameDialog dialog = new EditNameDialog(annotation.label,
310 annotation.description, " Annotation Name ",
311 "Annotation Description ", "Edit Annotation Name/Description",
319 annotation.label = dialog.getName();
321 String text = dialog.getDescription();
322 if (text != null && text.length() == 0)
326 annotation.description = text;
332 public void mousePressed(MouseEvent evt)
334 getSelectedRow(evt.getY() - getScrollOffset());
336 if (evt.isPopupTrigger())
343 * Build and show the Pop-up menu at the right-click mouse position
347 void showPopupMenu(MouseEvent evt)
350 final AlignmentAnnotation[] aa = ap.av.getAlignment()
351 .getAlignmentAnnotation();
353 JPopupMenu pop = new JPopupMenu(
354 MessageManager.getString("label.annotations"));
355 JMenuItem item = new JMenuItem(ADDNEW);
356 item.addActionListener(this);
361 { // let the user make everything visible again
362 item = new JMenuItem(SHOWALL);
363 item.addActionListener(this);
366 pop.show(this, evt.getX(), evt.getY());
369 item = new JMenuItem(EDITNAME);
370 item.addActionListener(this);
372 item = new JMenuItem(HIDE);
373 item.addActionListener(this);
375 // JAL-1264 hide all sequence-specific annotations of this type
376 if (selectedRow < aa.length)
378 if (aa[selectedRow].sequenceRef != null)
380 final String label = aa[selectedRow].label;
381 JMenuItem hideType = new JMenuItem();
382 String text = MessageManager.getString("label.hide_all") + " "
384 hideType.setText(text);
385 hideType.addActionListener(new ActionListener()
388 public void actionPerformed(ActionEvent e)
390 AlignmentUtils.showOrHideSequenceAnnotations(
391 ap.av.getAlignment(), Collections.singleton(label),
393 // for (AlignmentAnnotation ann : ap.av.getAlignment()
394 // .getAlignmentAnnotation())
396 // if (ann.sequenceRef != null && ann.label != null
397 // && ann.label.equals(label))
399 // ann.visible = false;
408 item = new JMenuItem(DELETE);
409 item.addActionListener(this);
413 item = new JMenuItem(SHOWALL);
414 item.addActionListener(this);
417 item = new JMenuItem(OUTPUT_TEXT);
418 item.addActionListener(this);
420 // TODO: annotation object should be typed for autocalculated/derived
422 if (selectedRow < aa.length)
424 final String label = aa[selectedRow].label;
425 if (!(aa[selectedRow].autoCalculated)
426 && !("HMM".equals(aa[selectedRow].getCalcId())))
428 if (aa[selectedRow].graph == AlignmentAnnotation.NO_GRAPH)
430 // display formatting settings for this row.
432 // av and sequencegroup need to implement same interface for
433 item = new JCheckBoxMenuItem(TOGGLE_LABELSCALE,
434 aa[selectedRow].scaleColLabel);
435 item.addActionListener(this);
439 else if (label.indexOf("Consensus") > -1)
444 // av and sequencegroup need to implement same interface for
446 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
447 MessageManager.getString("label.ignore_gaps_consensus"),
448 (aa[selectedRow].groupRef != null)
449 ? aa[selectedRow].groupRef.getIgnoreGapsConsensus()
450 : ap.av.isIgnoreGapsConsensus());
451 final AlignmentAnnotation aaa = aa[selectedRow];
452 cbmi.addActionListener(new ActionListener()
455 public void actionPerformed(ActionEvent e)
457 if (aaa.groupRef != null)
459 // TODO: pass on reference to ap so the view can be updated.
460 aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState());
461 ap.getAnnotationPanel()
462 .paint(ap.getAnnotationPanel().getGraphics());
466 ap.av.setIgnoreGapsConsensus(cbmi.getState(), ap);
468 ap.alignmentChanged();
472 // av and sequencegroup need to implement same interface for
473 if (aaa.groupRef != null)
475 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
476 MessageManager.getString("label.show_group_histogram"),
477 aa[selectedRow].groupRef.isShowConsensusHistogram());
478 chist.addActionListener(new ActionListener()
481 public void actionPerformed(ActionEvent e)
483 // TODO: pass on reference
489 aaa.groupRef.setShowConsensusHistogram(chist.getState());
491 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
495 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
496 MessageManager.getString("label.show_group_logo"),
497 aa[selectedRow].groupRef.isShowSequenceLogo());
498 cprofl.addActionListener(new ActionListener()
501 public void actionPerformed(ActionEvent e)
503 // TODO: pass on reference
509 aaa.groupRef.setshowSequenceLogo(cprofl.getState());
511 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
515 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
516 MessageManager.getString("label.normalise_group_logo"),
517 aa[selectedRow].groupRef.isNormaliseSequenceLogo());
518 cproflnorm.addActionListener(new ActionListener()
521 public void actionPerformed(ActionEvent e)
524 // TODO: pass on reference
530 aaa.groupRef.setNormaliseSequenceLogo(cproflnorm.getState());
531 // automatically enable logo display if we're clicked
532 aaa.groupRef.setshowSequenceLogo(true);
534 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
541 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
542 MessageManager.getString("label.show_histogram"),
543 av.isShowConsensusHistogram());
544 chist.addActionListener(new ActionListener()
547 public void actionPerformed(ActionEvent e)
549 // TODO: pass on reference
555 av.setShowConsensusHistogram(chist.getState());
557 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
561 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
562 MessageManager.getString("label.show_logo"),
563 av.isShowSequenceLogo());
564 cprof.addActionListener(new ActionListener()
567 public void actionPerformed(ActionEvent e)
569 // TODO: pass on reference
575 av.setShowSequenceLogo(cprof.getState());
577 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
581 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
582 MessageManager.getString("label.normalise_logo"),
583 av.isNormaliseSequenceLogo());
584 cprofnorm.addActionListener(new ActionListener()
587 public void actionPerformed(ActionEvent e)
589 // TODO: pass on reference
595 av.setShowSequenceLogo(true);
596 av.setNormaliseSequenceLogo(cprofnorm.getState());
598 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
603 final JMenuItem consclipbrd = new JMenuItem(COPYCONS_SEQ);
604 consclipbrd.addActionListener(this);
605 pop.add(consclipbrd);
607 else if ("HMM".equals(aa[selectedRow].getCalcId())) // TODO create labels
608 // in message resource
612 final AlignmentAnnotation aaa = aa[selectedRow];
614 final JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem(
615 MessageManager.getString(
616 "label.ignore_below_background_frequency"),
617 (aa[selectedRow].groupRef != null)
618 ? aa[selectedRow].groupRef
619 .getIgnoreBelowBackground()
620 : ap.av.isIgnoreBelowBackground());
622 cbmi.addActionListener(new ActionListener()
625 public void actionPerformed(ActionEvent e)
627 if (aaa.groupRef != null)
629 // TODO: pass on reference to ap so the view can be updated.
630 aaa.groupRef.setIgnoreBelowBackground(cbmi.getState());
631 ap.getAnnotationPanel()
632 .paint(ap.getAnnotationPanel().getGraphics());
636 ap.av.setIgnoreBelowBackground(cbmi.getState(), ap);
638 ap.alignmentChanged();
642 if (aaa.groupRef != null)
644 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
645 MessageManager.getString("label.show_group_histogram"),
646 aa[selectedRow].groupRef.isShowInformationHistogram());
647 chist.addActionListener(new ActionListener()
650 public void actionPerformed(ActionEvent e)
652 // TODO: pass on reference
658 aaa.groupRef.setShowInformationHistogram(chist.getState());
660 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
664 final JCheckBoxMenuItem cprofl = new JCheckBoxMenuItem(
665 MessageManager.getString("label.show_group_logo"),
666 aa[selectedRow].groupRef.isShowHMMSequenceLogo());
667 cprofl.addActionListener(new ActionListener()
670 public void actionPerformed(ActionEvent e)
672 // TODO: pass on reference
678 aaa.groupRef.setshowHMMSequenceLogo(cprofl.getState());
680 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
684 final JCheckBoxMenuItem cproflnorm = new JCheckBoxMenuItem(
685 MessageManager.getString("label.normalise_group_logo"),
686 aa[selectedRow].groupRef.isNormaliseHMMSequenceLogo());
687 cproflnorm.addActionListener(new ActionListener()
690 public void actionPerformed(ActionEvent e)
693 // TODO: pass on reference
700 .setNormaliseHMMSequenceLogo(cproflnorm.getState());
701 // automatically enable logo display if we're clicked
702 aaa.groupRef.setshowHMMSequenceLogo(true);
704 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
711 final JCheckBoxMenuItem chist = new JCheckBoxMenuItem(
712 MessageManager.getString("label.show_histogram"),
713 av.isShowInformationHistogram());
714 chist.addActionListener(new ActionListener()
717 public void actionPerformed(ActionEvent e)
719 // TODO: pass on reference
725 av.setShowInformationHistogram(chist.getState());
727 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
731 final JCheckBoxMenuItem cprof = new JCheckBoxMenuItem(
732 MessageManager.getString("label.show_logo"),
733 av.isShowHMMSequenceLogo());
734 cprof.addActionListener(new ActionListener()
737 public void actionPerformed(ActionEvent e)
739 // TODO: pass on reference
745 av.updateInformation(ap);
746 av.setShowHMMSequenceLogo(cprof.getState());
748 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
752 final JCheckBoxMenuItem cprofnorm = new JCheckBoxMenuItem(
753 MessageManager.getString("label.normalise_logo"),
754 av.isNormaliseHMMSequenceLogo());
755 cprofnorm.addActionListener(new ActionListener()
758 public void actionPerformed(ActionEvent e)
760 // TODO: pass on reference
766 av.setShowHMMSequenceLogo(true);
767 av.setNormaliseHMMSequenceLogo(cprofnorm.getState());
769 // ap.annotationPanel.paint(ap.annotationPanel.getGraphics());
776 pop.show(this, evt.getX(), evt.getY());
786 public void mouseReleased(MouseEvent evt)
788 if (evt.isPopupTrigger())
794 int start = selectedRow;
795 getSelectedRow(evt.getY() - getScrollOffset());
796 int end = selectedRow;
800 // Swap these annotations
801 AlignmentAnnotation startAA = ap.av.getAlignment()
802 .getAlignmentAnnotation()[start];
805 end = ap.av.getAlignment().getAlignmentAnnotation().length - 1;
807 AlignmentAnnotation endAA = ap.av.getAlignment()
808 .getAlignmentAnnotation()[end];
810 ap.av.getAlignment().getAlignmentAnnotation()[end] = startAA;
811 ap.av.getAlignment().getAlignmentAnnotation()[start] = endAA;
817 ap.getAnnotationPanel().repaint();
827 public void mouseEntered(MouseEvent evt)
843 public void mouseExited(MouseEvent evt)
845 if (dragEvent == null)
859 public void mouseDragged(MouseEvent evt)
865 Dimension d = ap.annotationScroller.getPreferredSize();
866 int dif = evt.getY() - oldY;
868 dif /= ap.av.getCharHeight();
869 dif *= ap.av.getCharHeight();
871 if ((d.height - dif) > 20)
873 ap.annotationScroller
874 .setPreferredSize(new Dimension(d.width, d.height - dif));
875 d = ap.annotationSpaceFillerHolder.getPreferredSize();
876 ap.annotationSpaceFillerHolder
877 .setPreferredSize(new Dimension(d.width, d.height - dif));
878 ap.paintAlignment(true);
896 public void mouseMoved(MouseEvent evt)
898 resizePanel = evt.getY() < 10;
900 getSelectedRow(evt.getY() - getScrollOffset());
902 if (selectedRow > -1 && ap.av.getAlignment()
903 .getAlignmentAnnotation().length > selectedRow)
905 AlignmentAnnotation aa = ap.av.getAlignment()
906 .getAlignmentAnnotation()[selectedRow];
908 StringBuffer desc = new StringBuffer();
909 if (aa.description != null
910 && !aa.description.equals("New description"))
912 // TODO: we could refactor and merge this code with the code in
913 // jalview.gui.SeqPanel.mouseMoved(..) that formats sequence feature
915 desc.append(aa.getDescription(true).trim());
916 // check to see if the description is an html fragment.
917 if (desc.length() < 6 || (desc.substring(0, 6).toLowerCase()
918 .indexOf("<html>") < 0))
920 // clean the description ready for embedding in html
921 desc = new StringBuffer(LEFT_ANGLE_BRACKET_PATTERN.matcher(desc)
922 .replaceAll("<"));
923 desc.insert(0, "<html>");
927 // remove terminating html if any
928 int i = desc.substring(desc.length() - 7).toLowerCase()
929 .lastIndexOf("</html>");
932 desc.setLength(desc.length() - 7 + i);
937 desc.append("<br/>");
939 // if (aa.hasProperties())
941 // desc.append("<table>");
942 // for (String prop : aa.getProperties())
944 // desc.append("<tr><td>" + prop + "</td><td>"
945 // + aa.getProperty(prop) + "</td><tr>");
947 // desc.append("</table>");
952 // begin the tooltip's html fragment
953 desc.append("<html>");
956 // TODO: limit precision of score to avoid noise from imprecise
958 // (64.7 becomes 64.7+/some tiny value).
959 desc.append(" Score: " + aa.score);
962 if (desc.length() > 6)
964 desc.append("</html>");
965 this.setToolTipText(desc.toString());
969 this.setToolTipText(null);
975 public void mouseClicked(MouseEvent evt)
977 final AlignmentAnnotation[] aa = ap.av.getAlignment()
978 .getAlignmentAnnotation();
979 if (!evt.isPopupTrigger() && SwingUtilities.isLeftMouseButton(evt))
981 if (selectedRow > -1 && selectedRow < aa.length)
983 if (aa[selectedRow].groupRef != null)
985 if (evt.getClickCount() >= 2)
987 // todo: make the ap scroll to the selection - not necessary, first
988 // click highlights/scrolls, second selects
989 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
991 SequenceGroup sg = ap.av.getSelectionGroup();
992 if (sg == null || sg == aa[selectedRow].groupRef
993 || !(jalview.util.Platform.isControlDown(evt)
994 || evt.isShiftDown()))
996 if (jalview.util.Platform.isControlDown(evt)
997 || evt.isShiftDown())
999 // clone a new selection group from the associated group
1000 ap.av.setSelectionGroup(
1001 new SequenceGroup(aa[selectedRow].groupRef));
1005 // set selection to the associated group so it can be edited
1006 ap.av.setSelectionGroup(aa[selectedRow].groupRef);
1011 // modify current selection with associated group
1012 int remainToAdd = aa[selectedRow].groupRef.getSize();
1013 for (SequenceI sgs : aa[selectedRow].groupRef.getSequences())
1015 if (jalview.util.Platform.isControlDown(evt))
1017 sg.addOrRemove(sgs, --remainToAdd == 0);
1021 // notionally, we should also add intermediate sequences from
1022 // last added sequence ?
1023 sg.addSequence(sgs, --remainToAdd == 0);
1028 ap.paintAlignment(false);
1029 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1030 ap.av.sendSelection();
1034 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(
1035 aa[selectedRow].groupRef.getSequences(null));
1039 else if (aa[selectedRow].sequenceRef != null)
1041 if (evt.getClickCount() == 1)
1043 ap.getSeqPanel().ap.getIdPanel()
1044 .highlightSearchResults(Arrays.asList(new SequenceI[]
1045 { aa[selectedRow].sequenceRef }));
1047 else if (evt.getClickCount() >= 2)
1049 ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null);
1050 SequenceGroup sg = ap.av.getSelectionGroup();
1053 // we make a copy rather than edit the current selection if no
1054 // modifiers pressed
1055 // see Enhancement JAL-1557
1056 if (!(jalview.util.Platform.isControlDown(evt)
1057 || evt.isShiftDown()))
1059 sg = new SequenceGroup(sg);
1061 sg.addSequence(aa[selectedRow].sequenceRef, false);
1065 if (jalview.util.Platform.isControlDown(evt))
1067 sg.addOrRemove(aa[selectedRow].sequenceRef, true);
1071 // notionally, we should also add intermediate sequences from
1072 // last added sequence ?
1073 sg.addSequence(aa[selectedRow].sequenceRef, true);
1079 sg = new SequenceGroup();
1081 sg.setEndRes(ap.av.getAlignment().getWidth() - 1);
1082 sg.addSequence(aa[selectedRow].sequenceRef, false);
1084 ap.av.setSelectionGroup(sg);
1085 ap.paintAlignment(false);
1086 PaintRefresher.Refresh(ap, ap.av.getSequenceSetId());
1087 ap.av.sendSelection();
1097 * do a single sequence copy to jalview and the system clipboard
1100 * sequence to be copied to clipboard
1102 protected void copy_annotseqtoclipboard(SequenceI sq)
1104 SequenceI[] seqs = new SequenceI[] { sq };
1105 String[] omitHidden = null;
1106 SequenceI[] dseqs = new SequenceI[] { sq.getDatasetSequence() };
1107 if (dseqs[0] == null)
1109 dseqs[0] = new Sequence(sq);
1110 dseqs[0].setSequence(jalview.analysis.AlignSeq.extractGaps(
1111 jalview.util.Comparison.GapChars, sq.getSequenceAsString()));
1113 sq.setDatasetSequence(dseqs[0]);
1115 Alignment ds = new Alignment(dseqs);
1116 if (av.hasHiddenColumns())
1118 omitHidden = av.getAlignment().getHiddenColumns()
1119 .getVisibleSequenceStrings(0, sq.getLength(), seqs);
1122 int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
1123 if (av.hasHiddenColumns())
1125 alignmentStartEnd = av.getAlignment().getHiddenColumns()
1126 .getVisibleStartAndEndIndex(av.getAlignment().getWidth());
1129 String output = new FormatAdapter().formatSequences(FileFormat.Fasta,
1130 seqs, omitHidden, alignmentStartEnd);
1132 Toolkit.getDefaultToolkit().getSystemClipboard()
1133 .setContents(new StringSelection(output), Desktop.instance);
1135 ArrayList<int[]> hiddenColumns = null;
1137 if (av.hasHiddenColumns())
1140 hiddenColumns = av.getAlignment().getHiddenColumns()
1141 .getHiddenColumnsCopy();
1145 Desktop.jalviewClipboard = new Object[] { seqs, ds, // what is the dataset
1147 // sequence ? need to
1149 // sequence as special.
1160 public void paintComponent(Graphics g)
1163 int width = getWidth();
1166 width = ap.calculateIdWidth().width + 4;
1169 Graphics2D g2 = (Graphics2D) g;
1172 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
1173 RenderingHints.VALUE_ANTIALIAS_ON);
1176 drawComponent(g2, true, width);
1181 * Draw the full set of annotation Labels for the alignment at the given
1185 * Graphics2D instance (needed for font scaling)
1187 * Width for scaling labels
1190 public void drawComponent(Graphics g, int width)
1192 drawComponent(g, false, width);
1195 private final boolean debugRedraw = false;
1198 * Draw the full set of annotation Labels for the alignment at the given
1202 * Graphics2D instance (needed for font scaling)
1204 * - true indicates that only current visible area needs to be
1207 * Width for scaling labels
1209 public void drawComponent(Graphics g, boolean clip, int width)
1211 if (av.getFont().getSize() < 10)
1217 g.setFont(av.getFont());
1220 FontMetrics fm = g.getFontMetrics(g.getFont());
1221 g.setColor(Color.white);
1222 g.fillRect(0, 0, getWidth(), getHeight());
1224 g.translate(0, getScrollOffset());
1225 g.setColor(Color.black);
1227 AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation();
1228 int fontHeight = g.getFont().getSize();
1231 int graphExtras = 0;
1233 Font baseFont = g.getFont();
1234 FontMetrics baseMetrics = fm;
1235 int ofontH = fontHeight;
1238 int[] visr = (ap != null && ap.getAnnotationPanel() != null)
1239 ? ap.getAnnotationPanel().getVisibleVRange()
1241 if (clip && visr != null)
1244 visHeight = visr[1];
1246 boolean visible = true, before = false, after = false;
1249 hasHiddenRows = false;
1251 for (int i = 0; i < aa.length; i++)
1256 hasHiddenRows = true;
1269 System.out.println("before vis: " + i);
1273 // don't draw what isn't visible
1276 if (olY > visHeight)
1284 "Scroll offset: " + sOffset + " after vis: " + i);
1288 // don't draw what isn't visible
1292 g.setColor(Color.black);
1294 offset = -aa[i].height / 2;
1298 offset += fm.getHeight() / 2;
1299 offset -= fm.getDescent();
1303 offset += fm.getDescent();
1306 x = width - fm.stringWidth(aa[i].label) - 3;
1308 if (aa[i].graphGroup > -1)
1311 // TODO: JAL-1291 revise rendering model so the graphGroup map is
1312 // computed efficiently for all visible labels
1313 for (int gg = 0; gg < aa.length; gg++)
1315 if (aa[gg].graphGroup == aa[i].graphGroup)
1320 if (groupSize * (fontHeight + 8) < aa[i].height)
1322 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1327 // scale font to fit
1328 float h = aa[i].height / (float) groupSize, s;
1335 fontHeight = -8 + (int) h;
1336 s = ((float) fontHeight) / (float) ofontH;
1338 .deriveFont(AffineTransform.getScaleInstance(s, s));
1340 fm = g.getFontMetrics();
1341 graphExtras = (aa[i].height - (groupSize * (fontHeight + 8)))
1347 for (int gg = 0; gg < aa.length; gg++)
1349 if (aa[gg].graphGroup == aa[i].graphGroup)
1351 x = width - fm.stringWidth(aa[gg].label) - 3;
1352 g.drawString(aa[gg].label, x, y - graphExtras);
1354 if (aa[gg]._linecolour != null)
1357 g.setColor(aa[gg]._linecolour);
1358 g.drawLine(x, y - graphExtras + 3,
1359 x + fm.stringWidth(aa[gg].label),
1360 y - graphExtras + 3);
1363 g.setColor(Color.black);
1364 graphExtras += fontHeight + 8;
1368 g.setFont(baseFont);
1370 fontHeight = ofontH;
1374 g.drawString(aa[i].label, x, y + offset);
1381 g.drawImage(image, 2, 0 - getScrollOffset(), this);
1383 else if (dragEvent != null && aa != null)
1385 g.setColor(Color.lightGray);
1386 g.drawString(aa[selectedRow].label, dragEvent.getX(),
1387 dragEvent.getY() - getScrollOffset());
1390 if (!av.getWrapAlignment() && ((aa == null) || (aa.length < 1)))
1392 g.drawString(MessageManager.getString("label.right_click"), 2, 8);
1393 g.drawString(MessageManager.getString("label.to_add_annotation"), 2,
1398 public int getScrollOffset()
1400 return scrollOffset;