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
19 package jalview.gui;
\r
22 import java.awt.event.*;
\r
23 import javax.swing.*;
\r
25 import jalview.datamodel.*;
\r
27 public class ScalePanel
\r
30 protected int offy = 4;
\r
32 protected AlignViewport av;
\r
34 boolean stretchingGroup = false;
\r
36 int min, max; //used by mouseDragged to see if user
\r
37 // wants to delete columns
\r
39 public ScalePanel(AlignViewport av, AlignmentPanel ap)
\r
44 addMouseListener(new MouseAdapter()
\r
46 public void mousePressed(MouseEvent evt)
\r
48 doMousePressed(evt);
\r
51 public void mouseReleased(MouseEvent evt)
\r
53 doMouseReleased(evt);
\r
56 addMouseMotionListener(new MouseMotionAdapter()
\r
58 public void mouseDragged(MouseEvent evt)
\r
60 doMouseDragged(evt);
\r
65 public void doMousePressed(MouseEvent evt)
\r
68 int res = (x / av.getCharWidth()) + av.getStartRes();
\r
69 SequenceGroup sg = null;
\r
74 if (av.getColumnSelection().contains(res))
\r
76 av.getColumnSelection().removeElement(res);
\r
77 ap.annotationPanel.removeEditableColumn(res);
\r
81 av.getColumnSelection().addElement(res);
\r
82 sg = new SequenceGroup();
\r
84 for (int i = 0; i < av.alignment.getSequences().size(); i++)
\r
86 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
89 sg.setStartRes(res);
\r
94 av.setSelectionGroup(sg);
\r
98 public void doMouseReleased(MouseEvent evt)
\r
100 int x = evt.getX();
\r
101 int res = (x / av.getCharWidth()) + av.getStartRes();
\r
103 if(av.getColumnSelection()!=null)
\r
105 for(int i=0; i<av.getColumnSelection().size(); i++)
\r
107 ap.annotationPanel.addEditableColumn(
\r
108 av.getColumnSelection().columnAt(i));
\r
112 if (!stretchingGroup)
\r
118 SequenceGroup sg = av.getSelectionGroup();
\r
120 if (res > sg.getStartRes())
\r
124 else if (res < sg.getStartRes())
\r
126 sg.setStartRes(res);
\r
129 stretchingGroup = false;
\r
133 public void doMouseDragged(MouseEvent evt)
\r
135 int x = evt.getX();
\r
136 int res = (x / av.getCharWidth()) + av.getStartRes();
\r
143 SequenceGroup sg = av.getSelectionGroup();
\r
147 stretchingGroup = true;
\r
148 if (!av.getColumnSelection().contains(res))
\r
150 av.getColumnSelection().addElement(res);
\r
154 if (res > sg.getStartRes())
\r
158 else if (res < sg.getStartRes())
\r
160 sg.setStartRes(res);
\r
163 for(int i=min; i<=max; i++)
\r
165 if (i < sg.getStartRes() || i > sg.getEndRes())
\r
167 av.getColumnSelection().removeElement(i);
\r
168 ap.annotationPanel.removeEditableColumn(res);
\r
171 av.getColumnSelection().addElement(i);
\r
177 public void paintComponent(Graphics g)
\r
179 drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight());
\r
182 // scalewidth will normally be screenwidth,
\r
183 public void drawScale(Graphics g, int startx, int endx, int width,
\r
186 Graphics2D gg = (Graphics2D) g;
\r
187 gg.setFont(av.getFont());
\r
188 gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
\r
189 RenderingHints.VALUE_ANTIALIAS_ON);
\r
191 //Fill in the background
\r
192 gg.setColor(Color.white);
\r
193 gg.fillRect(0, 0, width, height);
\r
194 gg.setColor(Color.black);
\r
196 //Fill the selected columns
\r
197 ColumnSelection cs = av.getColumnSelection();
\r
198 gg.setColor(new Color(220, 0, 0));
\r
200 for (int i = 0; i < cs.size(); i++)
\r
202 int sel = cs.columnAt(i);
\r
204 if ( (sel >= startx) && (sel <= endx))
\r
206 gg.fillRect( (sel - startx) * av.charWidth, 0, av.charWidth,
\r
211 // Draw the scale numbers
\r
212 gg.setColor(Color.black);
\r
214 int scalestartx = (startx / 10) * 10;
\r
216 FontMetrics fm = gg.getFontMetrics(av.getFont());
\r
217 int y = av.charHeight - fm.getDescent();
\r
219 if ( (scalestartx % 10) == 0)
\r
224 for (int i = scalestartx; i < endx; i += 5)
\r
226 if ( (i % 10) == 0)
\r
228 gg.drawString(String.valueOf(i),
\r
229 (i - startx - 1) * av.charWidth, y);
\r
230 gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +
\r
231 (av.charWidth / 2)), y + 2,
\r
232 (int) ( ( (i - startx - 1) * av.charWidth) +
\r
233 (av.charWidth / 2)), y + (fm.getDescent() * 2));
\r
237 gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +
\r
238 (av.charWidth / 2)), y + fm.getDescent(),
\r
239 (int) ( ( (i - startx - 1) * av.charWidth) +
\r
240 (av.charWidth / 2)), y + (fm.getDescent() * 2));
\r