X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FScalePanel.java;h=194066e172d04d5beece1443aed9bf40437ff74a;hb=6e2c975d1b0b32b54da3e2854a75dae607a4bfd3;hp=bc5ec3dcb997cd42d72635f56906c32e1af70101;hpb=25aaaa87042b3f507ad4348120df7dd073182759;p=jalview.git diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index bc5ec3d..194066e 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1) - * 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. * @@ -39,7 +39,6 @@ import java.awt.event.MouseMotionListener; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; -import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; /** @@ -84,6 +83,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, * @param evt * DOCUMENT ME! */ + @Override public void mousePressed(MouseEvent evt) { int x = (evt.getX() / av.getCharWidth()) + av.getStartRes(); @@ -106,111 +106,138 @@ public class ScalePanel extends JPanel implements MouseMotionListener, min = res; max = res; - if (SwingUtilities.isRightMouseButton(evt)) + if (evt.isPopupTrigger()) { - JPopupMenu pop = new JPopupMenu(); - if (reveal != null) + rightMouseButtonPressed(evt, res); + } + else + { + leftMouseButtonPressed(evt, res); + } + } + + /** + * 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) + { + JPopupMenu pop = new JPopupMenu(); + if (reveal != null) + { + JMenuItem item = new JMenuItem( + MessageManager.getString("label.reveal")); + item.addActionListener(new ActionListener() { - JMenuItem item = new JMenuItem( - MessageManager.getString("label.reveal")); - item.addActionListener(new ActionListener() + @Override + public void actionPerformed(ActionEvent e) { - public void actionPerformed(ActionEvent e) + av.showColumn(reveal[0]); + reveal = null; + ap.paintAlignment(true); + if (ap.overviewPanel != null) { - av.showColumn(reveal[0]); - reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } + ap.overviewPanel.updateOverviewImage(); } - }); - pop.add(item); - - if (av.getColumnSelection().hasHiddenColumns()) - { - item = new JMenuItem( - MessageManager.getString("action.reveal_all")); - item.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - av.showAllHiddenColumns(); - reveal = null; - ap.paintAlignment(true); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } - } - }); - pop.add(item); + av.sendSelection(); } - pop.show(this, evt.getX(), evt.getY()); - } - else if (av.getColumnSelection().contains(res)) + }); + pop.add(item); + + if (av.getColumnSelection().hasHiddenColumns()) { - JMenuItem item = new JMenuItem( - MessageManager.getString("label.hide_columns")); + item = new JMenuItem(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); - pop.show(this, evt.getX(), evt.getY()); } + pop.show(this, evt.getX(), evt.getY()); } - else - // LEFT MOUSE TO SELECT + else if (av.getColumnSelection().contains(res)) { - if (!evt.isControlDown() && !evt.isShiftDown()) + JMenuItem item = new JMenuItem( + MessageManager.getString("label.hide_columns")); + item.addActionListener(new ActionListener() { - av.getColumnSelection().clear(); - } + @Override + public void actionPerformed(ActionEvent e) + { + av.hideColumns(res, res); + if (av.getSelectionGroup() != null + && av.getSelectionGroup().getSize() == av.getAlignment() + .getHeight()) + { + av.setSelectionGroup(null); + } - av.getColumnSelection().addElement(res); - SequenceGroup sg = new SequenceGroup(); - // try to be as quick as possible - SequenceI[] iVec = av.getAlignment().getSequencesArray(); - for (int i = 0; i < iVec.length; i++) - { - sg.addSequence(iVec[i], false); - iVec[i] = null; - } - iVec = null; - sg.setStartRes(res); - sg.setEndRes(res); + ap.paintAlignment(true); + if (ap.overviewPanel != null) + { + ap.overviewPanel.updateOverviewImage(); + } + av.sendSelection(); + } + }); + pop.add(item); + pop.show(this, evt.getX(), evt.getY()); + } + } - if (evt.isShiftDown()) + /** + * Handles left mouse button press + * + * @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(); + // try to be as quick as possible + SequenceI[] iVec = av.getAlignment().getSequencesArray(); + for (int i = 0; i < iVec.length; i++) + { + sg.addSequence(iVec[i], false); + iVec[i] = null; + } + iVec = null; + sg.setStartRes(res); + sg.setEndRes(res); + + 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++) { - int min = Math.min(av.getColumnSelection().getMin(), res); - int max = Math.max(av.getColumnSelection().getMax(), res); - for (int i = min; i < max; i++) - { - av.getColumnSelection().addElement(i); - } - sg.setStartRes(min); - sg.setEndRes(max); + av.getColumnSelection().addElement(i); } - av.setSelectionGroup(sg); + sg.setStartRes(min); + sg.setEndRes(max); } - + av.setSelectionGroup(sg); ap.paintAlignment(false); av.sendSelection(); } @@ -221,6 +248,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseReleased(MouseEvent evt) { mouseDragging = false; @@ -268,6 +296,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseDragged(MouseEvent evt) { mouseDragging = true; @@ -337,6 +366,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } } + @Override public void mouseEntered(MouseEvent evt) { if (mouseDragging) @@ -345,6 +375,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } } + @Override public void mouseExited(MouseEvent evt) { if (mouseDragging) @@ -353,10 +384,12 @@ public class ScalePanel extends JPanel implements MouseMotionListener, } } + @Override public void mouseClicked(MouseEvent evt) { } + @Override public void mouseMoved(MouseEvent evt) { if (!av.hasHiddenColumns()) @@ -398,6 +431,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, * @param g * DOCUMENT ME! */ + @Override public void paintComponent(Graphics g) { drawScale(g, av.getStartRes(), av.getEndRes(), getWidth(), getHeight()); @@ -423,14 +457,18 @@ public class ScalePanel extends JPanel implements MouseMotionListener, // Fill the selected columns ColumnSelection cs = av.getColumnSelection(); + int avCharWidth = av.getCharWidth(), avCharHeight = av.getCharHeight(); + int s; if (cs != null) { gg.setColor(new Color(220, 0, 0)); - for (int i = 0; i < cs.size(); i++) + 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()) { if (cs.isVisible(sel)) @@ -445,7 +483,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, if ((sel >= startx) && (sel <= endx)) { - gg.fillRect((sel - startx) * av.charWidth, 0, av.charWidth, + gg.fillRect((sel - startx) * avCharWidth, 0, avCharWidth, getHeight()); } } @@ -455,43 +493,82 @@ public class ScalePanel extends JPanel implements MouseMotionListener, int scalestartx = (startx / 10) * 10; + SequenceI refSeq = av.getAlignment().getSeqrep(); + int refSp = 0, refEp = -1, refStart = 0, refEnd = -1, refStartI = 0, refEndI = -1; + if (refSeq != null) + { + // find bounds and set origin appopriately + // locate first visible position for this sequence + int[] refbounds = av.getColumnSelection() + .locateVisibleBoundsOfSequence(refSeq); + + refSp = refbounds[0]; + refEp = refbounds[1]; + refStart = refbounds[2]; + refEnd = refbounds[3]; + refStartI = refbounds[4]; + refEndI = refbounds[5]; + scalestartx = refSp + ((scalestartx - refSp) / 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) + if (refSeq == null && scalestartx % 10 == 0) { scalestartx += 5; } String string; - int maxX = 0; - + int maxX = 0, refN, iadj; + // todo: add a 'reference origin column' to set column number relative to for (int i = scalestartx; i < endx; i += 5) { - if ((i % 10) == 0) + if (((i - refSp) % 10) == 0) { - string = String.valueOf(av.getColumnSelection() - .adjustForHiddenColumns(i)); - if ((i - startx - 1) * av.charWidth > maxX) + iadj = av.getColumnSelection().adjustForHiddenColumns(i - 1); + if (refSeq == null) + { + string = String.valueOf(iadj); + } + else + { + refN = refSeq.findPosition(iadj); + // TODO show bounds if position is a gap + // - ie L--R -> "1L|2R" for + // marker + if (iadj < refStartI) + { + string = String.valueOf(iadj - refStartI); + } + else if (iadj > refEndI) + { + string = "+" + String.valueOf(iadj - refEndI); + } + else + { + string = String.valueOf(refN) + refSeq.getCharAt(iadj); + } + } + 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)); } } @@ -505,21 +582,18 @@ public class ScalePanel extends JPanel implements MouseMotionListener, for (int i = 0; i < av.getColumnSelection().getHiddenColumns() .size(); i++) { - 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); } } @@ -527,7 +601,7 @@ public class ScalePanel extends JPanel 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); } }