X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FScalePanel.java;h=71ecb132efb31103312dfa939c98e5390d7b7ec2;hb=9cf7cc96d9e7b582e2c1b1b5fd85924ba3117c42;hp=2b6f37abfea64e1f59205a9418be997a89329d69;hpb=f58113903c158201e64b3db50cc6cd57a8db6ae6;p=jalview.git diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 2b6f37a..71ecb13 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -70,6 +70,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, } + @Override public void mousePressed(MouseEvent evt) { int x = (evt.getX() / av.getCharWidth()) + av.getStartRes(); @@ -88,111 +89,140 @@ public class ScalePanel extends Panel implements MouseMotionListener, max = res; if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - PopupMenu pop = new PopupMenu(); - if (reveal != null) + rightMouseButtonPressed(evt, res); + } + else + { + leftMouseButtonPressed(evt, res); + } + } + + /** + * Handles left mouse button pressed (selection / clear selections) + * + * @param evt + * @param res + */ + protected void leftMouseButtonPressed(MouseEvent evt, final int res) + { + if (!evt.isControlDown() && !evt.isShiftDown()) + { + av.getColumnSelection().clear(); + } + + av.getColumnSelection().addElement(res); + SequenceGroup sg = new SequenceGroup(); + for (int i = 0; i < av.getAlignment().getSequences().size(); i++) + { + sg.addSequence(av.getAlignment().getSequenceAt(i), false); + } + + sg.setStartRes(res); + sg.setEndRes(res); + av.setSelectionGroup(sg); + + if (evt.isShiftDown()) + { + int min = Math.min(av.getColumnSelection().getMin(), res); + int max = Math.max(av.getColumnSelection().getMax(), res); + for (int i = min; i < max; i++) { - MenuItem item = new MenuItem( - MessageManager.getString("label.reveal")); - item.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - av.showColumn(reveal[0]); - reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } - } - }); - pop.add(item); + av.getColumnSelection().addElement(i); + } + sg.setStartRes(min); + sg.setEndRes(max); + } + ap.paintAlignment(true); + av.sendSelection(); + } - if (av.getColumnSelection().hasManyHiddenColumns()) + /** + * Handles right mouse button press. If pressed in a selected column, opens + * context menu for 'Hide Columns'. If pressed on a hidden columns marker, + * opens context menu for 'Reveal / Reveal All'. Else does nothing. + * + * @param evt + * @param res + */ + protected void rightMouseButtonPressed(MouseEvent evt, final int res) + { + PopupMenu pop = new PopupMenu(); + if (reveal != null) + { + MenuItem item = new MenuItem( + MessageManager.getString("label.reveal")); + item.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) { - item = new MenuItem(MessageManager.getString("action.reveal_all")); - item.addActionListener(new ActionListener() + av.showColumn(reveal[0]); + reveal = null; + ap.paintAlignment(true); + if (ap.overviewPanel != null) { - public void actionPerformed(ActionEvent e) - { - av.showAllHiddenColumns(); - reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } - } - }); - pop.add(item); + ap.overviewPanel.updateOverviewImage(); + } + av.sendSelection(); } - this.add(pop); - pop.show(this, evt.getX(), evt.getY()); - } - else if (av.getColumnSelection().contains(res)) + }); + pop.add(item); + + if (av.getColumnSelection().hasManyHiddenColumns()) { - MenuItem item = new MenuItem( - MessageManager.getString("label.hide_columns")); + item = new MenuItem(MessageManager.getString("action.reveal_all")); item.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - av.hideColumns(res, res); - if (av.getSelectionGroup() != null - && av.getSelectionGroup().getSize() == av - .getAlignment().getHeight()) - { - av.setSelectionGroup(null); - } - + av.showAllHiddenColumns(); + reveal = null; ap.paintAlignment(true); if (ap.overviewPanel != null) { ap.overviewPanel.updateOverviewImage(); } + av.sendSelection(); } }); pop.add(item); - this.add(pop); - pop.show(this, evt.getX(), evt.getY()); } + this.add(pop); + pop.show(this, evt.getX(), evt.getY()); } - else - // LEFT MOUSE TO SELECT + else if (av.getColumnSelection().contains(res)) { - if (!evt.isControlDown() && !evt.isShiftDown()) + MenuItem item = new MenuItem( + MessageManager.getString("label.hide_columns")); + item.addActionListener(new ActionListener() { - av.getColumnSelection().clear(); - } - - av.getColumnSelection().addElement(res); - SequenceGroup sg = new SequenceGroup(); - for (int i = 0; i < av.getAlignment().getSequences().size(); i++) - { - sg.addSequence(av.getAlignment().getSequenceAt(i), false); - } - - sg.setStartRes(res); - sg.setEndRes(res); - av.setSelectionGroup(sg); - - if (evt.isShiftDown()) - { - int min = Math.min(av.getColumnSelection().getMin(), res); - int max = Math.max(av.getColumnSelection().getMax(), res); - for (int i = min; i < max; i++) + @Override + public void actionPerformed(ActionEvent e) { - av.getColumnSelection().addElement(i); + av.hideColumns(res, res); + if (av.getSelectionGroup() != null + && av.getSelectionGroup().getSize() == av + .getAlignment().getHeight()) + { + av.setSelectionGroup(null); + } + + ap.paintAlignment(true); + if (ap.overviewPanel != null) + { + ap.overviewPanel.updateOverviewImage(); + } + av.sendSelection(); } - sg.setStartRes(min); - sg.setEndRes(max); - } + }); + pop.add(item); + this.add(pop); + pop.show(this, evt.getX(), evt.getY()); } - - ap.paintAlignment(true); - av.sendSelection(); } + @Override public void mouseReleased(MouseEvent evt) { mouseDragging = false; @@ -232,6 +262,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, av.sendSelection(); } + @Override public void mouseDragged(MouseEvent evt) { mouseDragging = true; @@ -301,6 +332,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, } } + @Override public void mouseEntered(MouseEvent evt) { if (mouseDragging) @@ -309,6 +341,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, } } + @Override public void mouseExited(MouseEvent evt) { if (mouseDragging) @@ -317,11 +350,13 @@ public class ScalePanel extends Panel implements MouseMotionListener, } } + @Override public void mouseClicked(MouseEvent evt) { } + @Override public void mouseMoved(MouseEvent evt) { if (!av.hasHiddenColumns()) @@ -346,11 +381,13 @@ public class ScalePanel extends Panel implements MouseMotionListener, repaint(); } + @Override public void update(Graphics g) { paint(g); } + @Override public void paint(Graphics g) { drawScale(g, av.getStartRes(), av.getEndRes(), getSize().width, @@ -362,7 +399,6 @@ public class ScalePanel extends Panel implements MouseMotionListener, int height) { gg.setFont(av.getFont()); - // Fill in the background gg.setColor(Color.white); gg.fillRect(0, 0, width, height); @@ -371,10 +407,11 @@ public class ScalePanel extends Panel implements MouseMotionListener, // Fill the selected columns ColumnSelection cs = av.getColumnSelection(); gg.setColor(new Color(220, 0, 0)); - - for (int i = 0; i < cs.size(); i++) + int avcharWidth = av.getCharWidth(), avcharHeight = av.getCharHeight(); + for (int sel : cs.getSelected()) { - int sel = cs.columnAt(i); + // TODO: JAL-2001 - provide a fast method to list visible selected in a + // given range if (av.hasHiddenColumns()) { sel = av.getColumnSelection().findColumnPosition(sel); @@ -382,7 +419,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, if ((sel >= startx) && (sel <= endx)) { - gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth, + gg.fillRect((sel - startx) * avcharWidth, 0, avcharWidth, getSize().height); } } @@ -391,9 +428,10 @@ public class ScalePanel extends Panel implements MouseMotionListener, gg.setColor(Color.black); int scalestartx = (startx / 10) * 10; + int widthx = 1 + endx - startx; FontMetrics fm = gg.getFontMetrics(av.getFont()); - int y = av.charHeight - fm.getDescent(); + int y = avcharHeight - fm.getDescent(); if ((scalestartx % 10) == 0) { @@ -409,26 +447,23 @@ public class ScalePanel extends Panel implements MouseMotionListener, { string = String.valueOf(av.getColumnSelection() .adjustForHiddenColumns(i)); - if ((i - startx - 1) * av.charWidth > maxX) + if ((i - startx - 1) * avcharWidth > maxX) { - gg.drawString(string, (i - startx - 1) * av.charWidth, y); - maxX = (i - startx + 1) * av.charWidth + fm.stringWidth(string); + gg.drawString(string, (i - startx - 1) * avcharWidth, y); + maxX = (i - startx + 1) * avcharWidth + fm.stringWidth(string); } - gg.drawLine( - ((i - startx - 1) * av.charWidth) + (av.charWidth / 2), + gg.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2), y + 2, - ((i - startx - 1) * av.charWidth) + (av.charWidth / 2), - y + (fm.getDescent() * 2)); + ((i - startx - 1) * avcharWidth) + (avcharWidth / 2), y + + (fm.getDescent() * 2)); } else { - gg.drawLine( - ((i - startx - 1) * av.charWidth) + (av.charWidth / 2), - y + fm.getDescent(), - ((i - startx - 1) * av.charWidth) + (av.charWidth / 2), - y + (fm.getDescent() * 2)); + gg.drawLine(((i - startx - 1) * avcharWidth) + (avcharWidth / 2), y + + fm.getDescent(), ((i - startx - 1) * avcharWidth) + + (avcharWidth / 2), y + (fm.getDescent() * 2)); } } @@ -445,17 +480,15 @@ public class ScalePanel extends Panel implements MouseMotionListener, res = av.getColumnSelection().findHiddenRegionPosition(i) - startx; - if (res < 0 || res > endx - scalestartx) + if (res < 0 || res > widthx) { continue; } - gg.fillPolygon(new int[] - { res * av.charWidth - av.charHeight / 4, - res * av.charWidth + av.charHeight / 4, res * av.charWidth }, - new int[] - { y - av.charHeight / 2, y - av.charHeight / 2, y + 8 }, - 3); + gg.fillPolygon(new int[] { res * avcharWidth - avcharHeight / 4, + res * avcharWidth + avcharHeight / 4, res * avcharWidth }, + new int[] { y - avcharHeight / 2, y - avcharHeight / 2, + y + 8 }, 3); } } @@ -463,7 +496,7 @@ public class ScalePanel extends Panel implements MouseMotionListener, if (reveal != null && reveal[0] > startx && reveal[0] < endx) { gg.drawString(MessageManager.getString("label.reveal_columns"), - reveal[0] * av.charWidth, 0); + reveal[0] * avcharWidth, 0); } }