2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
27 public class AnnotationLabels extends Panel implements ActionListener,
28 MouseListener, MouseMotionListener
32 boolean active = false;
38 boolean resizing = false;
42 static String ADDNEW = "Add New Row";
44 static String EDITNAME = "Edit Label/Description";
46 static String HIDE = "Hide This Row";
48 static String SHOWALL = "Show All Hidden Rows";
50 static String OUTPUT_TEXT = "Show Values In Textbox";
52 static String COPYCONS_SEQ = "Copy Consensus Sequence";
60 public AnnotationLabels(AlignmentPanel ap)
65 addMouseListener(this);
66 addMouseMotionListener(this);
69 public AnnotationLabels(AlignViewport av)
74 public void setScrollOffset(int y)
80 int getSelectedRow(int y)
83 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
91 for (int i = 0; i < aa.length; i++)
98 height += aa[i].height;
109 public void actionPerformed(ActionEvent evt)
111 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
113 if (evt.getActionCommand().equals(ADDNEW))
115 AlignmentAnnotation newAnnotation = new AlignmentAnnotation("", null,
116 new Annotation[ap.av.alignment.getWidth()]);
118 if (!editLabelDescription(newAnnotation))
123 ap.av.alignment.addAnnotation(newAnnotation);
124 ap.av.alignment.setAnnotationIndex(newAnnotation, 0);
126 else if (evt.getActionCommand().equals(EDITNAME))
128 editLabelDescription(aa[selectedRow]);
130 else if (evt.getActionCommand().equals(HIDE))
132 aa[selectedRow].visible = false;
134 else if (evt.getActionCommand().equals(SHOWALL))
136 for (int i = 0; i < aa.length; i++)
138 aa[i].visible = (aa[i].annotations == null) ? false : true;
141 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
143 CutAndPasteTransfer cap = new CutAndPasteTransfer(false,
145 Frame frame = new Frame();
147 jalview.bin.JalviewLite.addFrame(frame, ap.alignFrame.getTitle()
148 + " - " + aa[selectedRow].label, 500, 100);
149 cap.setText(aa[selectedRow].toString());
151 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
153 SequenceI cons = av.getConsensusSeq();
156 copy_annotseqtoclipboard(cons);
160 ap.annotationPanel.adjustPanelHeight();
161 setSize(getSize().width, ap.annotationPanel.getSize().height);
163 ap.paintAlignment(true);
166 boolean editLabelDescription(AlignmentAnnotation annotation)
168 Checkbox padGaps = new Checkbox("Fill Empty Gaps With \""
169 + ap.av.getGapCharacter() + "\"", annotation.padGaps);
171 EditNameDialog dialog = new EditNameDialog(annotation.label,
172 annotation.description, " Annotation Label",
173 "Annotation Description", ap.alignFrame,
174 "Edit Annotation Name / Description", 500, 180, false);
176 Panel empty = new Panel(new FlowLayout());
181 dialog.setVisible(true);
185 annotation.label = dialog.getName();
186 annotation.description = dialog.getDescription();
187 annotation.setPadGaps(padGaps.getState(), av.getGapCharacter());
196 public void mouseMoved(MouseEvent evt)
198 int row = getSelectedRow(evt.getY() - scrollOffset);
204 tooltip = new Tooltip(ap.av.alignment.getAlignmentAnnotation()[row]
205 .getDescription(true), this);
209 tooltip.setTip(ap.av.alignment.getAlignmentAnnotation()[row]
210 .getDescription(true));
213 else if (tooltip != null)
220 public void mouseDragged(MouseEvent evt)
224 public void mouseClicked(MouseEvent evt)
228 public void mouseReleased(MouseEvent evt)
232 public void mouseEntered(MouseEvent evt)
236 public void mouseExited(MouseEvent evt)
240 public void mousePressed(MouseEvent evt)
242 selectedRow = getSelectedRow(evt.getY() - scrollOffset);
244 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
246 PopupMenu popup = new PopupMenu("Annotations");
248 MenuItem item = new MenuItem(ADDNEW);
249 item.addActionListener(this);
254 popup.show(this, evt.getX(), evt.getY());
257 // add the rest if there are actually rows to show
258 item = new MenuItem(EDITNAME);
259 item.addActionListener(this);
261 item = new MenuItem(HIDE);
262 item.addActionListener(this);
264 item = new MenuItem(SHOWALL);
265 item.addActionListener(this);
268 item = new MenuItem(OUTPUT_TEXT);
269 item.addActionListener(this);
272 if (aa[selectedRow] == ap.av.consensus)
274 popup.addSeparator();
275 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
276 "Ignore Gaps In Consensus", ap.av.getIgnoreGapsConsensus());
278 cbmi.addItemListener(new ItemListener()
280 public void itemStateChanged(ItemEvent e)
282 ap.av.setIgnoreGapsConsensus(cbmi.getState());
283 ap.paintAlignment(true);
287 item = new MenuItem(COPYCONS_SEQ);
288 item.addActionListener(this);
292 popup.show(this, evt.getX(), evt.getY());
302 protected void copy_annotseqtoclipboard(SequenceI sq)
304 if (sq == null || sq.getLength() < 1)
308 jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
309 jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t"
310 + sq.getStart() + "\t" + sq.getEnd() + "\t"
311 + sq.getSequenceAsString() + "\n");
312 if (av.hasHiddenColumns)
314 jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector();
315 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
317 int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
320 jalview.appletgui.AlignFrame.copiedHiddenColumns
321 .addElement(new int[]
322 { region[0], region[1] });
327 public void update(Graphics g)
332 public void paint(Graphics g)
334 int w = getSize().width;
335 if (image == null || w != image.getWidth(this))
337 image = createImage(w, ap.annotationPanel.getSize().height);
340 drawComponent(image.getGraphics(), w);
341 g.drawImage(image, 0, 0, this);
344 public void drawComponent(Graphics g, int width)
346 g.setFont(av.getFont());
347 FontMetrics fm = g.getFontMetrics(av.getFont());
348 g.setColor(Color.white);
349 g.fillRect(0, 0, getSize().width, getSize().height);
351 g.translate(0, scrollOffset);
352 g.setColor(Color.black);
354 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
355 int y = g.getFont().getSize();
360 for (int i = 0; i < aa.length; i++)
367 x = width - fm.stringWidth(aa[i].label) - 3;
371 y += (aa[i].height / 3);
374 g.drawString(aa[i].label, x, y);
378 y += (2 * aa[i].height / 3);