2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
23 import java.awt.event.*;
\r
25 import jalview.datamodel.*;
\r
27 public class ScalePanel
\r
28 extends Panel implements MouseMotionListener, MouseListener
\r
31 protected int offy = 4;
\r
34 protected AlignViewport av;
\r
37 boolean stretchingGroup = false;
\r
38 int min; //used by mouseDragged to see if user
\r
39 int max; //used by mouseDragged to see if user
\r
40 boolean mouseDragging = false;
\r
43 public ScalePanel(AlignViewport av, AlignmentPanel ap)
\r
49 addMouseListener(this);
\r
50 addMouseMotionListener(this);
\r
54 public void mousePressed(MouseEvent evt)
\r
56 int x = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
59 if (av.hasHiddenColumns)
\r
61 res = av.getColumnSelection().adjustForHiddenColumns(x);
\r
70 if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK)
\r
71 == InputEvent.BUTTON3_MASK)
\r
73 PopupMenu pop = new PopupMenu();
\r
76 MenuItem item = new MenuItem("Reveal");
\r
77 item.addActionListener(new ActionListener()
\r
79 public void actionPerformed(ActionEvent e)
\r
81 av.showColumn(reveal[0]);
\r
83 ap.paintAlignment(true);
\r
84 if (ap.overviewPanel != null)
\r
86 ap.overviewPanel.updateOverviewImage();
\r
92 if (av.getColumnSelection().getHiddenColumns().size() > 1)
\r
94 item = new MenuItem("Reveal All");
\r
95 item.addActionListener(new ActionListener()
\r
97 public void actionPerformed(ActionEvent e)
\r
99 av.showAllHiddenColumns();
\r
101 ap.paintAlignment(true);
\r
102 if (ap.overviewPanel != null)
\r
104 ap.overviewPanel.updateOverviewImage();
\r
111 pop.show(this, evt.getX(), evt.getY());
\r
113 else if (av.getColumnSelection().contains(res))
\r
115 MenuItem item = new MenuItem("Hide Columns");
\r
116 item.addActionListener(new ActionListener()
\r
118 public void actionPerformed(ActionEvent e)
\r
120 av.hideColumns(res, res);
\r
121 if (av.getSelectionGroup() != null
\r
123 av.getSelectionGroup().getSize() == av.alignment.getHeight())
\r
125 av.setSelectionGroup(null);
\r
128 ap.paintAlignment(true);
\r
129 if (ap.overviewPanel != null)
\r
131 ap.overviewPanel.updateOverviewImage();
\r
137 pop.show(this, evt.getX(), evt.getY());
\r
140 else // LEFT MOUSE TO SELECT
\r
142 if (!evt.isControlDown() && !evt.isShiftDown())
\r
144 av.getColumnSelection().clear();
\r
147 av.getColumnSelection().addElement(res);
\r
148 SequenceGroup sg = new SequenceGroup();
\r
149 for (int i = 0; i < av.alignment.getSequences().size(); i++)
\r
151 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
154 sg.setStartRes(res);
\r
156 av.setSelectionGroup(sg);
\r
158 if (evt.isShiftDown())
\r
160 int min = Math.min(av.getColumnSelection().getMin(), res);
\r
161 int max = Math.max(av.getColumnSelection().getMax(), res);
\r
162 for (int i = min; i < max; i++)
\r
164 av.getColumnSelection().addElement(i);
\r
166 sg.setStartRes(min);
\r
171 ap.paintAlignment(true);
\r
174 public void mouseReleased(MouseEvent evt)
\r
176 mouseDragging = false;
\r
178 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
180 if (res > av.alignment.getWidth())
\r
182 res = av.alignment.getWidth() - 1;
\r
185 if (av.hasHiddenColumns)
\r
187 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
190 if (!stretchingGroup)
\r
192 ap.paintAlignment(true);
\r
197 SequenceGroup sg = av.getSelectionGroup();
\r
199 if (res > sg.getStartRes())
\r
203 else if (res < sg.getStartRes())
\r
205 sg.setStartRes(res);
\r
208 stretchingGroup = false;
\r
209 ap.paintAlignment(true);
\r
212 public void mouseDragged(MouseEvent evt)
\r
214 mouseDragging = true;
\r
216 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
222 if (av.hasHiddenColumns)
\r
224 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
227 if (res > av.alignment.getWidth())
\r
229 res = av.alignment.getWidth() - 1;
\r
242 SequenceGroup sg = av.getSelectionGroup();
\r
246 stretchingGroup = true;
\r
248 if (!av.getColumnSelection().contains(res))
\r
250 av.getColumnSelection().addElement(res);
\r
253 if (res > sg.getStartRes())
\r
257 if (res < sg.getStartRes())
\r
259 sg.setStartRes(res);
\r
262 for (int i = min; i <= max; i++)
\r
264 if ( (i < sg.getStartRes()) || (i > sg.getEndRes()))
\r
266 av.getColumnSelection().removeElement(i);
\r
270 av.getColumnSelection().addElement(i);
\r
274 ap.paintAlignment(true);
\r
278 public void mouseEntered(MouseEvent evt)
\r
282 ap.seqPanel.scrollCanvas(null);
\r
286 public void mouseExited(MouseEvent evt)
\r
290 ap.seqPanel.scrollCanvas(evt);
\r
294 public void mouseClicked(MouseEvent evt)
\r
299 public void mouseMoved(MouseEvent evt)
\r
301 if (!av.hasHiddenColumns)
\r
306 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
308 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
311 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
\r
313 int[] region = (int[]) av.getColumnSelection().getHiddenColumns().
\r
315 if (res + 1 == region[0] || res - 1 == region[1])
\r
325 public void update(Graphics g)
\r
330 public void paint(Graphics g)
\r
332 drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width,
\r
336 // scalewidth will normally be screenwidth,
\r
337 public void drawScale(Graphics gg, int startx, int endx, int width,
\r
340 gg.setFont(av.getFont());
\r
342 //Fill in the background
\r
343 gg.setColor(Color.white);
\r
344 gg.fillRect(0, 0, width, height);
\r
345 gg.setColor(Color.black);
\r
347 //Fill the selected columns
\r
348 ColumnSelection cs = av.getColumnSelection();
\r
349 gg.setColor(new Color(220, 0, 0));
\r
351 for (int i = 0; i < cs.size(); i++)
\r
353 int sel = cs.columnAt(i);
\r
354 if (av.hasHiddenColumns)
\r
356 sel = av.getColumnSelection().findColumnPosition(sel);
\r
359 if ( (sel >= startx) && (sel <= endx))
\r
361 gg.fillRect( (sel - startx) * av.charWidth, 0, av.charWidth,
\r
366 // Draw the scale numbers
\r
367 gg.setColor(Color.black);
\r
369 int scalestartx = (startx / 10) * 10;
\r
371 FontMetrics fm = gg.getFontMetrics(av.getFont());
\r
372 int y = av.charHeight - fm.getDescent();
\r
374 if ( (scalestartx % 10) == 0)
\r
382 for (int i = scalestartx; i < endx; i += 5)
\r
384 if ( (i % 10) == 0)
\r
386 string = String.valueOf(av.getColumnSelection().adjustForHiddenColumns(
\r
388 if ( (i - startx - 1) * av.charWidth > maxX)
\r
390 gg.drawString(string,
\r
391 (i - startx - 1) * av.charWidth, y);
\r
392 maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string);
\r
395 gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +
\r
396 (av.charWidth / 2)), y + 2,
\r
397 (int) ( ( (i - startx - 1) * av.charWidth) +
\r
398 (av.charWidth / 2)),
\r
399 y + (fm.getDescent() * 2));
\r
404 gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +
\r
405 (av.charWidth / 2)), y + fm.getDescent(),
\r
406 (int) ( ( (i - startx - 1) * av.charWidth) +
\r
407 (av.charWidth / 2)), y + (fm.getDescent() * 2));
\r
411 if (av.hasHiddenColumns)
\r
413 gg.setColor(Color.blue);
\r
415 if (av.getShowHiddenMarkers())
\r
417 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size();
\r
421 res = av.getColumnSelection().findHiddenRegionPosition(i) -
\r
424 if (res < 0 || res > endx - scalestartx)
\r
429 gg.fillPolygon(new int[]
\r
430 {res * av.charWidth - av.charHeight / 4,
\r
431 res * av.charWidth + av.charHeight / 4,
\r
432 res * av.charWidth},
\r
435 y - av.charHeight / 2, y - av.charHeight / 2,
\r
442 if (reveal != null && reveal[0] > startx && reveal[0] < endx)
\r
444 gg.drawString("Reveal Columns", reveal[0] * av.charWidth, 0);
\r