2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
28 public class AnnotationLabels extends Panel implements ActionListener,
29 MouseListener, MouseMotionListener
33 boolean active = false;
39 boolean resizing = false;
43 static String ADDNEW = "Add New Row";
45 static String EDITNAME = "Edit Label/Description";
47 static String HIDE = "Hide This Row";
49 static String SHOWALL = "Show All Hidden Rows";
51 static String OUTPUT_TEXT = "Show Values In Textbox";
53 static String COPYCONS_SEQ = "Copy Consensus Sequence";
61 public AnnotationLabels(AlignmentPanel ap)
66 addMouseListener(this);
67 addMouseMotionListener(this);
70 public AnnotationLabels(AlignViewport av)
75 public void setScrollOffset(int y)
81 int getSelectedRow(int y)
84 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
92 for (int i = 0; i < aa.length; i++)
99 height += aa[i].height;
110 public void actionPerformed(ActionEvent evt)
112 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
114 if (evt.getActionCommand().equals(ADDNEW))
116 AlignmentAnnotation newAnnotation = new AlignmentAnnotation("", null,
117 new Annotation[ap.av.alignment.getWidth()]);
119 if (!editLabelDescription(newAnnotation))
124 ap.av.alignment.addAnnotation(newAnnotation);
125 ap.av.alignment.setAnnotationIndex(newAnnotation, 0);
127 else if (evt.getActionCommand().equals(EDITNAME))
129 editLabelDescription(aa[selectedRow]);
131 else if (evt.getActionCommand().equals(HIDE))
133 aa[selectedRow].visible = false;
135 else if (evt.getActionCommand().equals(SHOWALL))
137 for (int i = 0; i < aa.length; i++)
139 aa[i].visible = (aa[i].annotations == null) ? false : true;
142 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
144 CutAndPasteTransfer cap = new CutAndPasteTransfer(false,
146 Frame frame = new Frame();
148 jalview.bin.JalviewLite.addFrame(frame, ap.alignFrame.getTitle()
149 + " - " + aa[selectedRow].label, 500, 100);
150 cap.setText(aa[selectedRow].toString());
152 else if (evt.getActionCommand().equals(COPYCONS_SEQ))
154 SequenceI cons = av.getConsensusSeq();
157 copy_annotseqtoclipboard(cons);
161 ap.annotationPanel.adjustPanelHeight();
162 setSize(getSize().width, ap.annotationPanel.getSize().height);
164 ap.paintAlignment(true);
167 boolean editLabelDescription(AlignmentAnnotation annotation)
169 Checkbox padGaps = new Checkbox("Fill Empty Gaps With \""
170 + ap.av.getGapCharacter() + "\"", annotation.padGaps);
172 EditNameDialog dialog = new EditNameDialog(annotation.label,
173 annotation.description, " Annotation Label",
174 "Annotation Description", ap.alignFrame,
175 "Edit Annotation Name / Description", 500, 180, false);
177 Panel empty = new Panel(new FlowLayout());
182 dialog.setVisible(true);
186 annotation.label = dialog.getName();
187 annotation.description = dialog.getDescription();
188 annotation.setPadGaps(padGaps.getState(), av.getGapCharacter());
197 public void mouseMoved(MouseEvent evt)
199 int row = getSelectedRow(evt.getY() - scrollOffset);
205 tooltip = new Tooltip(ap.av.alignment.getAlignmentAnnotation()[row]
206 .getDescription(true), this);
210 tooltip.setTip(ap.av.alignment.getAlignmentAnnotation()[row]
211 .getDescription(true));
214 else if (tooltip != null)
221 public void mouseDragged(MouseEvent evt)
225 public void mouseClicked(MouseEvent evt)
229 public void mouseReleased(MouseEvent evt)
233 public void mouseEntered(MouseEvent evt)
237 public void mouseExited(MouseEvent evt)
241 public void mousePressed(MouseEvent evt)
243 selectedRow = getSelectedRow(evt.getY() - scrollOffset);
245 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
247 PopupMenu popup = new PopupMenu("Annotations");
249 MenuItem item = new MenuItem(ADDNEW);
250 item.addActionListener(this);
252 item = new MenuItem(EDITNAME);
253 item.addActionListener(this);
255 item = new MenuItem(HIDE);
256 item.addActionListener(this);
258 item = new MenuItem(SHOWALL);
259 item.addActionListener(this);
262 item = new MenuItem(OUTPUT_TEXT);
263 item.addActionListener(this);
266 if (aa[selectedRow] == ap.av.consensus)
268 popup.addSeparator();
269 final CheckboxMenuItem cbmi = new CheckboxMenuItem(
270 "Ignore Gaps In Consensus", ap.av.getIgnoreGapsConsensus());
272 cbmi.addItemListener(new ItemListener()
274 public void itemStateChanged(ItemEvent e)
276 ap.av.setIgnoreGapsConsensus(cbmi.getState());
277 ap.paintAlignment(true);
281 item = new MenuItem(COPYCONS_SEQ);
282 item.addActionListener(this);
286 popup.show(this, evt.getX(), evt.getY());
296 protected void copy_annotseqtoclipboard(SequenceI sq)
298 if (sq == null || sq.getLength() < 1)
302 jalview.appletgui.AlignFrame.copiedSequences = new StringBuffer();
303 jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t"
304 + sq.getStart() + "\t" + sq.getEnd() + "\t"
305 + sq.getSequenceAsString() + "\n");
306 if (av.hasHiddenColumns)
308 jalview.appletgui.AlignFrame.copiedHiddenColumns = new Vector();
309 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
311 int[] region = (int[]) av.getColumnSelection().getHiddenColumns()
314 jalview.appletgui.AlignFrame.copiedHiddenColumns
315 .addElement(new int[]
316 { region[0], region[1] });
321 public void update(Graphics g)
326 public void paint(Graphics g)
328 int w = getSize().width;
329 if (image == null || w != image.getWidth(this))
331 image = createImage(w, ap.annotationPanel.getSize().height);
334 drawComponent(image.getGraphics(), w);
335 g.drawImage(image, 0, 0, this);
338 public void drawComponent(Graphics g, int width)
340 g.setFont(av.getFont());
341 FontMetrics fm = g.getFontMetrics(av.getFont());
342 g.setColor(Color.white);
343 g.fillRect(0, 0, getSize().width, getSize().height);
345 g.translate(0, scrollOffset);
346 g.setColor(Color.black);
348 AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();
349 int y = g.getFont().getSize();
354 for (int i = 0; i < aa.length; i++)
361 x = width - fm.stringWidth(aa[i].label) - 3;
365 y += (aa[i].height / 3);
368 g.drawString(aa[i].label, x, y);
372 y += (2 * aa[i].height / 3);