X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqPanel.java;h=3266fabf5631a665138d9e9f7feb574d451a8434;hb=6631ee3334607cc5e0b670191f9df048c157325a;hp=362e7f9b37b2ce24d3625c63d1ce25dae4d1d585;hpb=e2f5868d84779717b0f2835ef009b30c9f6be078;p=jalview.git diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 362e7f9..3266fab 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.api.AlignViewportI; +import jalview.bin.Cache; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.commands.EditCommand.Edit; @@ -42,6 +43,7 @@ import jalview.structure.VamsasSource; import jalview.util.Comparison; import jalview.util.MappingUtils; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; import java.awt.BorderLayout; @@ -54,11 +56,12 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; +import java.util.ArrayList; import java.util.List; -import java.util.Vector; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; /** @@ -509,6 +512,7 @@ public class SeqPanel extends JPanel implements MouseListener, void insertNucAtCursor(boolean group, String nuc) { + // TODO not called - delete? groupEditing = group; startseq = seqCanvas.cursorY; lastres = seqCanvas.cursorX; @@ -579,6 +583,13 @@ public class SeqPanel extends JPanel implements MouseListener, mouseDragging = false; mouseWheelPressed = false; + if (evt.isPopupTrigger()) // Windows: mouseReleased + { + showPopupMenu(evt); + evt.consume(); + return; + } + if (!editingSeqs) { doMouseReleasedDefineMode(evt); @@ -599,19 +610,20 @@ public class SeqPanel extends JPanel implements MouseListener, { lastMousePress = evt.getPoint(); - if (javax.swing.SwingUtilities.isMiddleMouseButton(evt)) + if (SwingUtilities.isMiddleMouseButton(evt)) { mouseWheelPressed = true; return; } - if (evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) + boolean isControlDown = Platform.isControlDown(evt); + if (evt.isShiftDown() || isControlDown) { - if (evt.isAltDown() || evt.isControlDown()) + editingSeqs = true; + if (isControlDown) { groupEditing = true; } - editingSeqs = true; } else { @@ -830,6 +842,13 @@ public class SeqPanel extends JPanel implements MouseListener, private boolean needOverviewUpdate = false; // TODO: refactor to avcontroller /** + * set if av.getSelectionGroup() refers to a group that is defined on the + * alignment view, rather than a transient selection + */ + // private boolean editingDefinedGroup = false; // TODO: refactor to + // avcontroller or viewModel + + /** * Set status message in alignment panel * * @param sequence @@ -848,7 +867,8 @@ public class SeqPanel extends JPanel implements MouseListener, * Sequence number (if known), and sequence name. */ String seqno = seq == -1 ? "" : " " + (seq + 1); - text.append("Sequence" + seqno + " ID: " + sequence.getName()); + text.append("Sequence").append(seqno).append(" ID: ") + .append(sequence.getName()); String residue = null; /* @@ -1179,8 +1199,7 @@ public class SeqPanel extends JPanel implements MouseListener, { for (int j = 0; j < startres - lastres; j++) { - if (!jalview.util.Comparison.isGap(groupSeqs[g] - .getCharAt(fixedRight - j))) + if (!Comparison.isGap(groupSeqs[g].getCharAt(fixedRight - j))) { blank = false; break; @@ -1242,7 +1261,7 @@ public class SeqPanel extends JPanel implements MouseListener, continue; } - if (!jalview.util.Comparison.isGap(groupSeqs[g].getCharAt(j))) + if (!Comparison.isGap(groupSeqs[g].getCharAt(j))) { // Not a gap, block edit not valid endEditing(); @@ -1374,7 +1393,7 @@ public class SeqPanel extends JPanel implements MouseListener, for (blankColumn = fixedColumn; blankColumn > j; blankColumn--) { - if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn))) + if (Comparison.isGap(seq[s].getCharAt(blankColumn))) { // Theres a space, so break and insert the gap break; @@ -1537,9 +1556,10 @@ public class SeqPanel extends JPanel implements MouseListener, */ public void doMousePressedDefineMode(MouseEvent evt) { - int res = findRes(evt); - int seq = findSeq(evt); + final int res = findRes(evt); + final int seq = findSeq(evt); oldSeq = seq; + needOverviewUpdate = false; startWrapBlock = wrappedBlock; @@ -1602,28 +1622,21 @@ public class SeqPanel extends JPanel implements MouseListener, } av.setSelectionGroup(stretchGroup); - } - if (javax.swing.SwingUtilities.isRightMouseButton(evt)) + if (evt.isPopupTrigger()) // Mac: mousePressed { - List allFeatures = ap.getFeatureRenderer() - .findFeaturesAtRes(sequence.getDatasetSequence(), - sequence.findPosition(res)); - Vector links = new Vector(); - for (SequenceFeature sf : allFeatures) - { - if (sf.links != null) - { - for (int j = 0; j < sf.links.size(); j++) - { - links.addElement(sf.links.elementAt(j)); - } - } - } + showPopupMenu(evt); + return; + } - jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(ap, null, links); - pop.show(this, evt.getX(), evt.getY()); + /* + * defer right-mouse click handling to mouseReleased on Windows + * (where isPopupTrigger() will answer true) + * NB isRightMouseButton is also true for Cmd-click on Mac + */ + if (SwingUtilities.isRightMouseButton(evt) && !Platform.isAMac()) + { return; } @@ -1645,7 +1658,6 @@ public class SeqPanel extends JPanel implements MouseListener, sg.setEndRes(res); sg.addSequence(sequence, false); av.setSelectionGroup(sg); - stretchGroup = sg; if (av.getConservationSelected()) @@ -1677,6 +1689,37 @@ public class SeqPanel extends JPanel implements MouseListener, } /** + * Build and show a pop-up menu at the right-click mouse position + * + * @param evt + * @param res + * @param sequence + */ + void showPopupMenu(MouseEvent evt) + { + final int res = findRes(evt); + final int seq = findSeq(evt); + SequenceI sequence = av.getAlignment().getSequenceAt(seq); + List allFeatures = ap.getFeatureRenderer() + .findFeaturesAtRes(sequence.getDatasetSequence(), + sequence.findPosition(res)); + List links = new ArrayList(); + for (SequenceFeature sf : allFeatures) + { + if (sf.links != null) + { + for (String link : sf.links) + { + links.add(link); + } + } + } + + PopupMenu pop = new PopupMenu(ap, null, links); + pop.show(this, evt.getX(), evt.getY()); + } + + /** * DOCUMENT ME! * * @param evt @@ -1688,9 +1731,10 @@ public class SeqPanel extends JPanel implements MouseListener, { return; } - - stretchGroup.recalcConservation(); // always do this - annotation has own - // state + // always do this - annotation has own state + // but defer colourscheme update until hidden sequences are passed in + boolean vischange = stretchGroup.recalcConservation(true); + needOverviewUpdate |= vischange && av.isSelectionDefinedGroup(); if (stretchGroup.cs != null) { stretchGroup.cs.alignmentChanged(stretchGroup, @@ -1709,7 +1753,7 @@ public class SeqPanel extends JPanel implements MouseListener, } PaintRefresher.Refresh(this, av.getSequenceSetId()); ap.paintAlignment(needOverviewUpdate); - + needOverviewUpdate = false; changeEndRes = false; changeStartRes = false; stretchGroup = null; @@ -1763,6 +1807,7 @@ public class SeqPanel extends JPanel implements MouseListener, if (res > (stretchGroup.getStartRes() - 1)) { stretchGroup.setEndRes(res); + needOverviewUpdate |= av.isSelectionDefinedGroup(); } } else if (changeStartRes) @@ -1770,6 +1815,7 @@ public class SeqPanel extends JPanel implements MouseListener, if (res < (stretchGroup.getEndRes() + 1)) { stretchGroup.setStartRes(res); + needOverviewUpdate |= av.isSelectionDefinedGroup(); } } @@ -1803,6 +1849,7 @@ public class SeqPanel extends JPanel implements MouseListener, if (stretchGroup.getSequences(null).contains(nextSeq)) { stretchGroup.deleteSequence(seq, false); + needOverviewUpdate |= av.isSelectionDefinedGroup(); } else { @@ -1812,6 +1859,7 @@ public class SeqPanel extends JPanel implements MouseListener, } stretchGroup.addSequence(nextSeq, false); + needOverviewUpdate |= av.isSelectionDefinedGroup(); } } @@ -1953,28 +2001,28 @@ public class SeqPanel extends JPanel implements MouseListener, // do we want to thread this ? (contention with seqsel and colsel locks, I // suspect) - // rules are: colsel is copied if there is a real intersection between - // sequence selection + /* + * only copy colsel if there is a real intersection between + * sequence selection and this panel's alignment + */ boolean repaint = false; - boolean copycolsel = true; + boolean copycolsel = false; SequenceGroup sgroup = null; if (seqsel != null && seqsel.getSize() > 0) { if (av.getAlignment() == null) { - jalview.bin.Cache.log.warn("alignviewport av SeqSetId=" - + av.getSequenceSetId() + " ViewId=" + av.getViewId() + Cache.log.warn("alignviewport av SeqSetId=" + av.getSequenceSetId() + + " ViewId=" + av.getViewId() + " 's alignment is NULL! returning immediately."); return; } sgroup = seqsel.intersect(av.getAlignment(), (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null); - if ((sgroup == null || sgroup.getSize() == 0) - || (colsel == null || colsel.isEmpty())) + if ((sgroup != null && sgroup.getSize() > 0)) { - // don't copy columns if the region didn't intersect. - copycolsel = false; + copycolsel = true; } } if (sgroup != null && sgroup.getSize() > 0) @@ -2067,7 +2115,6 @@ public class SeqPanel extends JPanel implements MouseListener, ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv, av); av.setColumnSelection(cs); - av.isColSelChanged(true); PaintRefresher.Refresh(this, av.getSequenceSetId());