3 * Jalview - A Sequence Alignment Editor and Viewer
\r
4 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
11 * This program is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program; if not, write to the Free Software
\r
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
21 package jalview.appletgui;
\r
23 import java.awt.event.*;
\r
25 import jalview.datamodel.*;
\r
27 public class AnnotationLabels extends Panel implements ActionListener
\r
29 boolean active = false;
\r
31 boolean resizing = false;
\r
33 static String ADDNEW = "Add new row";
\r
34 static String HIDE = "Hide this row";
\r
35 static String DELETE = "Delete this row";
\r
36 static String SHOWALL="Show all hidden rows";
\r
37 static String OUTPUT_TEXT="Show Values In Textbox";
\r
38 int selectedRow = 0;
\r
39 int scrollOffset = 0;
\r
41 public AnnotationLabels(AlignmentPanel ap)
\r
45 addMouseListener(new MouseAdapter()
\r
46 {public void mousePressed(MouseEvent evt)
\r
48 doMousePressed(evt);
\r
53 public void setScrollOffset(int y)
\r
59 public void actionPerformed(ActionEvent evt)
\r
61 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
63 if(evt.getActionCommand().equals(HIDE))
\r
65 aa[selectedRow].visible = false;
\r
67 else if(evt.getActionCommand().equals(SHOWALL))
\r
69 for(int i=0; i<aa.length; i++)
\r
70 aa[i].visible = true;
\r
72 else if (evt.getActionCommand().equals(OUTPUT_TEXT))
\r
74 CutAndPasteTransfer cap = new CutAndPasteTransfer(false);
\r
75 Frame frame = new Frame();
\r
77 jalview.bin.JalviewLite.addFrame(frame,
\r
78 ap.alignFrame.getTitle() + " - " +
\r
79 aa[selectedRow].label, 500, 100);
\r
80 cap.setText(aa[selectedRow].toString());
\r
83 ap.annotationPanel.adjustPanelHeight();
\r
84 setSize(getSize().width,ap.annotationPanel.getSize().height);
\r
89 public void doMousePressed(MouseEvent evt)
\r
91 int y = evt.getY() - scrollOffset;
\r
92 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
94 for (int i = 0; i < aa.length; i++)
\r
99 height += aa[i].height;
\r
107 PopupMenu pop = new PopupMenu("Annotations");
\r
108 MenuItem item = new MenuItem(HIDE);
\r
109 item.addActionListener(this);
\r
111 item = new MenuItem(SHOWALL);
\r
112 item.addActionListener(this);
\r
115 item = new MenuItem(OUTPUT_TEXT);
\r
116 item.addActionListener(this);
\r
118 pop.show(this, evt.getX(), evt.getY());
\r
122 public void paint(Graphics g)
\r
127 public void drawComponent(Graphics g)
\r
129 FontMetrics fm = g.getFontMetrics(g.getFont());
\r
130 g.setColor(Color.white);
\r
131 g.fillRect(0,0, getSize().width, getSize().height);
\r
133 g.translate(0, scrollOffset);
\r
134 g.setColor(Color.black);
\r
136 AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();
\r
137 int y = g.getFont().getSize();
\r
141 for(int i=0; i<aa.length; i++)
\r
146 x = getSize().width - fm.stringWidth(aa[i].label)-3;
\r
149 y+=(aa[i].height/3);
\r
151 g.drawString(aa[i].label, x, y);
\r
154 y+=(2*aa[i].height/3);
\r