2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
22 import jalview.datamodel.*;
\r
24 import java.awt.event.*;
\r
26 public class ScalePanel extends Panel
\r
29 protected int offy = 4;
\r
32 protected AlignViewport av;
\r
35 boolean stretchingGroup = false;
\r
37 public ScalePanel(AlignViewport av, AlignmentPanel ap)
\r
43 addMouseListener(new MouseAdapter()
\r
45 public void mousePressed(MouseEvent evt)
\r
47 doMousePressed(evt);
\r
49 public void mouseReleased(MouseEvent evt)
\r
51 doMouseReleased(evt);
\r
55 addMouseMotionListener(new MouseMotionAdapter()
\r
57 public void mouseDragged(MouseEvent evt)
\r
59 doMouseDragged(evt);
\r
66 public void doMousePressed(MouseEvent evt) {
\r
68 int res = x/av.getCharWidth() + av.getStartRes();
\r
69 SequenceGroup sg = null;
\r
71 if (av.getColumnSelection().contains(res))
\r
72 av.getColumnSelection().removeElement(res);
\r
75 av.getColumnSelection().addElement(res);
\r
77 sg = new SequenceGroup();
\r
78 for (int i = 0; i < av.alignment.getSequences().size(); i++)
\r
79 sg.addSequence(av.alignment.getSequenceAt(i));
\r
81 sg.setStartRes(res);
\r
84 ap.annotationPanel.addEditableColumn(res);
\r
86 av.setSelectionGroup(sg);
\r
90 public void doMouseReleased(MouseEvent evt)
\r
92 if(!stretchingGroup)
\r
96 int res = x/av.getCharWidth() + av.getStartRes();
\r
98 if (! av.getColumnSelection().contains(res))
\r
99 av.getColumnSelection().addElement(res);
\r
101 SequenceGroup sg = av.getSelectionGroup();
\r
103 if(res>sg.getStartRes())
\r
105 else if(res<sg.getStartRes())
\r
106 sg.setStartRes(res);
\r
108 stretchingGroup = false;
\r
112 public void doMouseDragged(MouseEvent evt)
\r
114 int x = evt.getX();
\r
115 int res = x/av.getCharWidth() + av.getStartRes();
\r
117 SequenceGroup sg = av.getSelectionGroup();
\r
120 stretchingGroup = true;
\r
121 if (res > sg.getStartRes())
\r
123 else if (res < sg.getStartRes())
\r
124 sg.setStartRes(res);
\r
126 ap.annotationPanel.addEditableColumn(res);
\r
131 public void update(Graphics g)
\r
136 public void paint(Graphics g)
\r
138 drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width, getSize().height);
\r
141 // scalewidth will normally be screenwidth,
\r
142 public void drawScale(Graphics gg, int startx, int endx, int width, int height)
\r
144 gg.setFont(av.getFont());
\r
146 //Fill in the background
\r
147 gg.setColor(Color.white);
\r
148 gg.fillRect(0,0,width, height);
\r
149 gg.setColor(Color.black);
\r
152 //Fill the selected columns
\r
153 ColumnSelection cs = av.getColumnSelection();
\r
154 gg.setColor(new Color(220,0,0));
\r
155 for (int i=0; i<cs.size(); i++)
\r
157 int sel = cs.columnAt(i);
\r
158 if ( sel >= startx && sel <= endx)
\r
159 gg.fillRect((sel-startx)*av.charWidth,0,av.charWidth, getSize().height);
\r
163 // Draw the scale numbers
\r
164 gg.setColor(Color.black);
\r
165 int scalestartx = (startx/10) * 10;
\r
167 FontMetrics fm = gg.getFontMetrics(av.getFont());
\r
168 int y = av.charHeight -fm.getDescent();
\r
170 if(scalestartx%10==0)
\r
173 for (int i=scalestartx;i < endx; i+= 5)
\r
177 gg.drawString(String.valueOf(i), (i - startx - 1) * av.charWidth, y);
\r
178 gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
\r
180 (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
\r
181 y+fm.getDescent()*2);
\r
184 gg.drawLine( (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
\r
186 (int) ( (i - startx - 1) * av.charWidth + av.charWidth / 2),
\r
187 y+fm.getDescent()*2);
\r