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
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
60 res = av.getColumnSelection().adjustForHiddenColumns(x);
\r
66 if ((evt.getModifiers() & InputEvent.BUTTON3_MASK)
\r
67 == InputEvent.BUTTON3_MASK)
\r
69 PopupMenu pop = new PopupMenu();
\r
72 MenuItem item = new MenuItem("Reveal");
\r
73 item.addActionListener(new ActionListener()
\r
75 public void actionPerformed(ActionEvent e)
\r
77 av.showColumn(reveal[0]);
\r
80 if (ap.overviewPanel != null)
\r
81 ap.overviewPanel.updateOverviewImage();
\r
86 if (av.getColumnSelection().getHiddenColumns().size() > 1)
\r
88 item = new MenuItem("Reveal All");
\r
89 item.addActionListener(new ActionListener()
\r
91 public void actionPerformed(ActionEvent e)
\r
93 av.showAllHiddenColumns();
\r
96 if (ap.overviewPanel != null)
\r
97 ap.overviewPanel.updateOverviewImage();
\r
103 pop.show(this, evt.getX(), evt.getY());
\r
105 else if (av.getColumnSelection().contains(res))
\r
107 MenuItem item = new MenuItem("Hide Columns");
\r
108 item.addActionListener(new ActionListener()
\r
110 public void actionPerformed(ActionEvent e)
\r
112 av.hideColumns(res, res);
\r
114 if (ap.overviewPanel != null)
\r
115 ap.overviewPanel.updateOverviewImage();
\r
120 pop.show(this, evt.getX(), evt.getY());
\r
123 else // LEFT MOUSE TO SELECT
\r
125 if (!evt.isControlDown() && !evt.isShiftDown())
\r
127 av.getColumnSelection().clear();
\r
130 av.getColumnSelection().addElement(res);
\r
131 SequenceGroup sg = new SequenceGroup();
\r
132 for (int i = 0; i < av.alignment.getSequences().size(); i++)
\r
134 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
137 sg.setStartRes(res);
\r
139 av.setSelectionGroup(sg);
\r
141 if(evt.isShiftDown())
\r
143 int min = Math.min(av.getColumnSelection().getMin(), res);
\r
144 int max = Math.max(av.getColumnSelection().getMax(), res);
\r
145 for (int i = min; i<max; i++)
\r
147 av.getColumnSelection().addElement(i);
\r
149 sg.setStartRes(min);
\r
157 public void mouseReleased(MouseEvent evt)
\r
159 mouseDragging = false;
\r
161 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
163 if(res> av.alignment.getWidth())
\r
165 res = av.alignment.getWidth()-1;
\r
168 if(av.hasHiddenColumns)
\r
169 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
171 if (!stretchingGroup)
\r
178 SequenceGroup sg = av.getSelectionGroup();
\r
180 if (res > sg.getStartRes())
\r
184 else if (res < sg.getStartRes())
\r
186 sg.setStartRes(res);
\r
189 stretchingGroup = false;
\r
193 public void mouseDragged(MouseEvent evt)
\r
195 mouseDragging = true;
\r
197 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
201 if (av.hasHiddenColumns)
\r
202 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
204 if (res > av.alignment.getWidth())
\r
206 res = av.alignment.getWidth() - 1;
\r
219 SequenceGroup sg = av.getSelectionGroup();
\r
223 stretchingGroup = true;
\r
225 if (!av.getColumnSelection().contains(res))
\r
227 av.getColumnSelection().addElement(res);
\r
230 if (res > sg.getStartRes())
\r
234 if (res < sg.getStartRes())
\r
236 sg.setStartRes(res);
\r
239 for (int i = min; i <= max; i++)
\r
241 if ( (i < sg.getStartRes()) || (i > sg.getEndRes()))
\r
243 av.getColumnSelection().removeElement(i);
\r
247 av.getColumnSelection().addElement(i);
\r
256 public void mouseEntered(MouseEvent evt)
\r
259 ap.seqPanel.scrollCanvas(null);
\r
262 public void mouseExited(MouseEvent evt)
\r
265 ap.seqPanel.scrollCanvas(evt);
\r
268 public void mouseClicked(MouseEvent evt)
\r
273 public void mouseMoved(MouseEvent evt)
\r
275 if (!av.hasHiddenColumns)
\r
278 int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
\r
280 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
283 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size(); i++)
\r
285 int[] region = (int[]) av.getColumnSelection().getHiddenColumns().
\r
287 if (res + 1 == region[0] || res - 1 == region[1])
\r
297 public void update(Graphics g)
\r
302 public void paint(Graphics g)
\r
304 drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width,
\r
308 // scalewidth will normally be screenwidth,
\r
309 public void drawScale(Graphics gg, int startx, int endx, int width,
\r
312 gg.setFont(av.getFont());
\r
315 //Fill in the background
\r
316 gg.setColor(Color.white);
\r
317 gg.fillRect(0, 0, width, height);
\r
318 gg.setColor(Color.black);
\r
320 //Fill the selected columns
\r
321 ColumnSelection cs = av.getColumnSelection();
\r
322 gg.setColor(new Color(220, 0, 0));
\r
324 for (int i = 0; i < cs.size(); i++)
\r
326 int sel = cs.columnAt(i);
\r
327 if(av.hasHiddenColumns)
\r
328 sel = av.getColumnSelection().findColumnPosition(sel);
\r
331 if ((sel >= startx) && (sel <= endx))
\r
333 gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth,
\r
338 // Draw the scale numbers
\r
339 gg.setColor(Color.black);
\r
341 int scalestartx = (startx / 10) * 10;
\r
343 FontMetrics fm = gg.getFontMetrics(av.getFont());
\r
344 int y = av.charHeight - fm.getDescent();
\r
346 if ((scalestartx % 10) == 0)
\r
354 for (int i = scalestartx; i < endx; i += 5)
\r
358 string = String.valueOf(av.getColumnSelection().adjustForHiddenColumns(i));
\r
359 if ( (i - startx - 1) * av.charWidth > maxX)
\r
361 gg.drawString(string,
\r
362 (i - startx - 1) * av.charWidth, y);
\r
363 maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string);
\r
366 gg.drawLine( (int) ( ( (i - startx - 1) * av.charWidth) +
\r
367 (av.charWidth / 2)), y + 2,
\r
368 (int) ( ( (i - startx - 1) * av.charWidth) +
\r
369 (av.charWidth / 2)),
\r
370 y + (fm.getDescent() * 2));
\r
375 gg.drawLine((int) (((i - startx - 1) * av.charWidth) +
\r
376 (av.charWidth / 2)), y + fm.getDescent(),
\r
377 (int) (((i - startx - 1) * av.charWidth) +
\r
378 (av.charWidth / 2)), y + (fm.getDescent() * 2));
\r
382 if (av.hasHiddenColumns)
\r
384 gg.setColor(Color.blue);
\r
386 if(av.getShowHiddenMarkers())
\r
388 for (int i = 0; i < av.getColumnSelection().getHiddenColumns().size();
\r
392 res = av.getColumnSelection().findHiddenRegionPosition(i) -
\r
395 if(res < 0 || res > endx-scalestartx)
\r
398 gg.fillPolygon(new int[]
\r
399 {res * av.charWidth - av.charHeight / 4,
\r
400 res * av.charWidth + av.charHeight / 4,
\r
401 res * av.charWidth},
\r
404 y - av.charHeight / 2, y - av.charHeight / 2,
\r
411 if (reveal != null && reveal[0] > startx && reveal[0] < endx)
\r
413 gg.drawString("Reveal Columns", reveal[0] * av.charWidth, 0);
\r