X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqPanel.java;h=5ecc613e009f7d640ad4fa985a1e7ca22ad19f54;hb=d69ea8f1997771890b44e4b332a7ca84fe6f0893;hp=55bc65a8c50b63ac899b06287a7a884eb5e19ee4;hpb=94bc21544b9573fdf177c500bdb981e8076a7e7d;p=jalview.git diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 55bc65a..5ecc613 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -25,6 +25,8 @@ import java.awt.event.*; import jalview.datamodel.*; import jalview.schemes.*; +import java.util.Vector; + public class SeqPanel extends Panel implements MouseMotionListener, MouseListener { @@ -55,6 +57,9 @@ public class SeqPanel StringBuffer keyboardNo1; StringBuffer keyboardNo2; + boolean mouseWheelPressed = false; + Point lastMousePress; + public SeqPanel(AlignViewport avp, AlignmentPanel p) { this.av = avp; @@ -140,26 +145,32 @@ public class SeqPanel endEditing(); - while (seqCanvas.cursorY < av.startSeq) - { - ap.scrollUp(true); - } - while (seqCanvas.cursorY + 1 > av.endSeq) + if (av.wrapAlignment) { - ap.scrollUp(false); + ap.scrollToWrappedVisible(seqCanvas.cursorX); } - while (seqCanvas.cursorX < av.startRes) + else { + while (seqCanvas.cursorY < av.startSeq) + { + ap.scrollUp(true); + } + while (seqCanvas.cursorY + 1 > av.endSeq) + { + ap.scrollUp(false); + } + while (seqCanvas.cursorX < av.startRes) + { - if(!ap.scrollRight(false)) - break; - } - while (seqCanvas.cursorX > av.endRes) - { - if(!ap.scrollRight(true)) - break; + if (!ap.scrollRight(false)) + break; + } + while (seqCanvas.cursorX > av.endRes) + { + if (!ap.scrollRight(true)) + break; + } } - setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY), seqCanvas.cursorX, seqCanvas.cursorY); @@ -176,7 +187,7 @@ public class SeqPanel SequenceGroup sg = av.selectionGroup; //Find the top and bottom of this group int min = av.alignment.getHeight(), max = 0; - for(int i=0; i max) @@ -212,7 +223,7 @@ public class SeqPanel else { // Now add any sequences between min and max - sg.sequences.removeAllElements(); + sg.getSequences(false).removeAllElements(); for (int i = min; i < max; i++) { sg.addSequence(av.alignment.getSequenceAt(i), false); @@ -303,15 +314,28 @@ public class SeqPanel ")"); } } + ap.alignFrame.statusBar.setText(text.toString()); } public void mousePressed(MouseEvent evt) { - if (evt.isShiftDown() || evt.isAltDown() || - evt.isControlDown()) + lastMousePress = evt.getPoint(); + + //For now, ignore the mouseWheel font resizing on Macs + //As the Button2_mask always seems to be true + if ( (evt.getModifiers() & InputEvent.BUTTON2_MASK) == + InputEvent.BUTTON2_MASK && !av.MAC) + { + mouseWheelPressed = true; + return; + } + + if (evt.isShiftDown() + || evt.isControlDown() + || evt.isAltDown()) { - if (evt.isAltDown() || evt.isControlDown()) + if (evt.isControlDown() || evt.isAltDown()) { groupEditing = true; } @@ -354,6 +378,7 @@ public class SeqPanel public void mouseReleased(MouseEvent evt) { mouseDragging = false; + mouseWheelPressed = false; if (!editingSeqs) { @@ -364,7 +389,7 @@ public class SeqPanel editOccurred(); endEditing(); - ap.repaint(); + ap.repaint(); } int startWrapBlock=-1; @@ -390,6 +415,8 @@ public class SeqPanel int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width); + if(cwidth<1) + return 0; wrappedBlock = y / cHeight; wrappedBlock += av.getStartRes() / cwidth; @@ -402,6 +429,9 @@ public class SeqPanel res = (x / av.getCharWidth()) + av.getStartRes(); } + if(av.hasHiddenColumns) + res = av.getColumnSelection().adjustForHiddenColumns(res); + return res; } @@ -423,11 +453,17 @@ public class SeqPanel y -= hgap; - seq = ( (y % cHeight) / av.getCharHeight()); + seq = Math.min( (y % cHeight) / av.getCharHeight(), + av.alignment.getHeight() -1); + if(seq<0) + seq = 0; } else { - seq = (y / av.getCharHeight()) + av.getStartSeq(); + seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(), + av.alignment.getHeight() -1); + if(seq<0) + seq = 0; } return seq; @@ -497,11 +533,9 @@ public class SeqPanel if (obj != null) { - if (obj != "") { - text.append(obj + " (" + - av.getAlignment().getSequenceAt(seq).findPosition(res) + ")"); + text.append(obj + " (" + sequence.findPosition(res) + ")"); } } @@ -510,61 +544,136 @@ public class SeqPanel seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res)); } + ap.alignFrame.statusBar.setText(text.toString()); + // use aa to see if the mouse pointer is on a if (av.showSequenceFeatures && sequence.getSequenceFeatures()!=null && av.featuresDisplayed!=null) { + StringBuffer featureText = new StringBuffer(); + Vector allFeatures = getAllFeaturesAtRes(sequence, sequence.findPosition(res)); + int index = 0; - sequence.getSequenceFeatures(); - boolean first = true; - while (index < sequence.getSequenceFeatures().length) + while (index < allFeatures.size()) { - SequenceFeature sf = sequence.getSequenceFeatures()[index]; - if (sf.getBegin() <= sequence.findPosition(res) && - sf.getEnd() >= sequence.findPosition(res)) + SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(index); + + featureText.append(sf.getType()+" "+sf.begin+":"+sf.end); + + if (sf.getDescription() != null) + featureText.append(" " + sf.getDescription()); + + if (sf.getValue("status") != null ) { - if(!av.featuresDisplayed.containsKey(sf.getType())) - { - index++; - continue; - } + String status = sf.getValue("status").toString(); + if(status.length()>0) + featureText.append(" (" + sf.getValue("status") + ")"); + } + featureText.append("\n"); - if(first) - { - text.append(" Sequence Feature:"); - first = false; - } + index++; + } - text.append(" "+sf.getType()); - if(sf.getDescription()!=null) - text.append(" "+sf.getDescription()); + if (tooltip == null) + tooltip = new Tooltip(featureText.toString(), seqCanvas); + else + tooltip.setTip(featureText.toString()); + + tooltip.repaint(); + + } + } - if (sf.getStatus()!=null && sf.getStatus().length() > 0) + Vector getAllFeaturesAtRes(SequenceI seq, int res) + { + Vector allFeatures = new Vector(); + int index = 0; + if(seq.getSequenceFeatures()!=null) + { + while (index < seq.getSequenceFeatures().length) + { + SequenceFeature sf = seq.getSequenceFeatures()[index]; + if (sf.getBegin() <= res && + sf.getEnd() >= res) + { + if (av.featuresDisplayed.containsKey(sf.getType())) { - text.append(" (" + sf.getStatus() + ")"); + allFeatures.addElement(sf); } - text.append("; "); } - index++; - } } - - ap.alignFrame.statusBar.setText(text.toString()); - + return allFeatures; } + Tooltip tooltip; + public void mouseDragged(MouseEvent evt) { - if (!editingSeqs) -{ - doMouseDraggedDefineMode(evt); - return; -} + if (mouseWheelPressed) + { + int oldWidth = av.charWidth; + + //Which is bigger, left-right or up-down? + if (Math.abs(evt.getY() - lastMousePress.y) + > Math.abs(evt.getX() - lastMousePress.x)) + { + int fontSize = av.font.getSize(); + + if (evt.getY() < lastMousePress.y && av.charHeight > 1) + { + fontSize--; + } + else if (evt.getY() > lastMousePress.y) + { + fontSize++; + } + + + if(fontSize<1) + fontSize = 1; + + av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize)); + av.charWidth = oldWidth; + } + else + { + if (evt.getX() < lastMousePress.x && av.charWidth > 1) + { + av.charWidth--; + } + else if (evt.getX() > lastMousePress.x) + { + av.charWidth++; + } + + if(av.charWidth<1) + { + av.charWidth = 1; + } + } + + ap.fontChanged(); + + FontMetrics fm = getFontMetrics(av.getFont()); + av.validCharWidth = fm.charWidth('M') <= av.charWidth; + + lastMousePress = evt.getPoint(); + + ap.repaint(); + ap.annotationPanel.image = null; + return; + } + + if (!editingSeqs) + { + doMouseDraggedDefineMode(evt); + return; + } int res = findRes(evt); @@ -593,184 +702,221 @@ public class SeqPanel } synchronized void editSequence(boolean insertGap, int startres) - { - int fixedLeft = -1; - int fixedRight = -1; - boolean fixedColumns = false; - SequenceGroup sg = av.getSelectionGroup(); + { + int fixedLeft = -1; + int fixedRight = -1; + boolean fixedColumns = false; + SequenceGroup sg = av.getSelectionGroup(); - if(groupEditing && sg==null) - return; - SequenceI seq = av.alignment.getSequenceAt(startseq); - StringBuffer message = new StringBuffer(); - if (groupEditing) - message.append("Edit group:"); - else - message.append("Edit sequence: "+seq.getName()); + if (!groupEditing && av.hasHiddenRows) + { + if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null) + { + groupEditing = true; + } + } - if(insertGap) - message.append(" insert "); - else - message.append(" delete "); + //No group, but the sequence may represent a group + if (groupEditing + && sg == null + && av.alignment.getSequenceAt(startseq).getHiddenSequences() == null) + { + groupEditing = false; + } + + SequenceI seq = av.alignment.getSequenceAt(startseq); + StringBuffer message = new StringBuffer(); + if (groupEditing) + message.append("Edit group:"); + else + message.append("Edit sequence: "+seq.getName()); + + if(insertGap) + message.append(" insert "); + else + message.append(" delete "); + + message.append(Math.abs(startres-lastres)+" gaps."); + ap.alignFrame.statusBar.setText(message.toString()); - message.append(Math.abs(startres-lastres)+" gaps."); - ap.alignFrame.statusBar.setText(message.toString()); + //Are we editing within a selection group? + if (groupEditing + || (sg != null && sg.getSequences(true).contains(seq))) + { + fixedColumns = true; - //Are we editing within a selection group? - if (groupEditing - || (sg != null && sg.sequences.contains(seq))) + //sg might be null as the user may only see 1 sequence, + //but the sequence represents a group + if (sg == null) { - fixedColumns = true; + sg = new SequenceGroup(null, null, false, false, false, 0, + av.alignment.getWidth()-1); + sg.addSequence(av.alignment.getSequenceAt(startseq), false); + } + + fixedLeft = sg.getStartRes(); + fixedRight = sg.getEndRes(); - fixedLeft = sg.getStartRes(); - fixedRight = sg.getEndRes(); + if ( (startres < fixedLeft && lastres >= fixedLeft) + || (startres >= fixedLeft && lastres < fixedLeft) + || (startres > fixedRight && lastres <=fixedRight) + || (startres <= fixedRight && lastres > fixedRight)) + { + endEditing(); + return; + } - if ( (startres < fixedLeft && lastres >= fixedLeft) - || (startres >= fixedLeft && lastres < fixedLeft) - || (startres > fixedRight && lastres <=fixedRight) - || (startres <= fixedRight && lastres > fixedRight)) + if (fixedLeft > startres) + { + fixedRight = fixedLeft - 1; + fixedLeft = 0; + } + else if (fixedRight < startres) + { + fixedLeft = fixedRight; + fixedRight = -1; + } + } + + + if(av.hasHiddenColumns ) + { + fixedColumns = true; + int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres); + int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres); + + if ( (insertGap && startres > y1 && lastres < y1) + || (!insertGap && startres < y2 && lastres > y2)) { endEditing(); return; } - if (fixedLeft > startres) + //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~"); + //Selection spans a hidden region + if(fixedLefty2 || fixedRight==-1)) { - fixedRight = fixedLeft - 1; - fixedLeft = 0; - } - else if (fixedRight < startres) - { - fixedLeft = fixedRight; - fixedRight = -1; + if(startres>=y2) + { + fixedLeft = y2; + } + else + { + fixedRight = y2 - 1; + } } - } + } - if (groupEditing) + if (groupEditing) + { + // drag to right + if (insertGap) { - // drag to right - if (insertGap) - { - //If the user has selected the whole sequence, and is dragging to - // the right, we can still extend the alignment and selectionGroup - if(sg.getStartRes() == 0 && sg.getEndRes() + 1 == av.alignment.getWidth()) - { - sg.setEndRes(av.alignment.getWidth() + startres - lastres); - fixedRight = sg.getEndRes(); - } + //If the user has selected the whole sequence, and is dragging to + // the right, we can still extend the alignment and selectionGroup + if( sg.getStartRes() == 0 + && sg.getEndRes() == fixedRight + && sg.getEndRes() == av.alignment.getWidth()-1 + ) + { + sg.setEndRes(av.alignment.getWidth() + startres - lastres); + fixedRight = sg.getEndRes(); + } - // Is it valid with fixed columns?? - // Find the next gap before the end - // of the visible region boundary - boolean blank = false; - for (fixedRight = fixedRight; - fixedRight > lastres; - fixedRight--) + // Is it valid with fixed columns?? + // Find the next gap before the end + // of the visible region boundary + boolean blank = false; + for (fixedRight = fixedRight; + fixedRight > lastres; + fixedRight--) + { + blank = true; + for (int s = 0; s < sg.getSize(true); s++) { - blank = true; - for (int s = 0; s < sg.getSize(); s++) + seq = (SequenceI)sg.getSequences(true).elementAt(s); + for (int j = 0; j < startres - lastres; j++) { - seq = sg.getSequenceAt(s); - for (int j = 0; j < startres - lastres; j++) + if (!jalview.util.Comparison.isGap( + seq.getCharAt(fixedRight - j))) { - if (!jalview.util.Comparison.isGap( - seq.getCharAt(fixedRight - j))) - { - blank = false; - break; - } + blank = false; + break; } } - if (blank) - break; } + if (blank) + break; + } - if (!blank) + if (!blank) + { + if(sg.getSize(false) == av.alignment.getHeight() ) { - if(sg.getSize() == av.alignment.getHeight()) - { - //We can still insert gaps if the selectionGroup - //contains all the sequences - sg.setEndRes(sg.getEndRes()+startres-lastres); - fixedRight = av.alignment.getWidth()+startres-lastres; - } - else + if((av.hasHiddenColumns + && startresalWidth) + alWidth = hwidth; } + //We can still insert gaps if the selectionGroup + //contains all the sequences + sg.setEndRes(sg.getEndRes()+startres-lastres); + fixedRight = alWidth+startres-lastres; + } + else + { + endEditing(); + return; } } + } - for (int i = 0; i < sg.getSize(); i++) + // drag to left + else if(!insertGap) + { + /// Are we able to delete? + // ie are all columns blank? + + for (int s = 0; s < sg.getSize(true); s++) { - seq = sg.getSequenceAt(i); + seq = (SequenceI)sg.getSequences(true).elementAt(s); - if (insertGap) + for (int j = startres; j < lastres; j++) { - // dragging to the right - for (int j = lastres; j < startres; j++) + if (seq.getSequence().length() <= j) { - if (fixedColumns && fixedRight != -1) - { - insertChar(j, seq, fixedRight); - } - else - insertChar(j, seq); + continue; } - } - else - { - // dragging to the left - for (int j = lastres; j > startres; j--) + + if (!jalview.util.Comparison.isGap( + seq.getSequence().charAt(j))) { - if (fixedColumns && fixedRight != -1) - { - deleteChar(startres, seq, fixedRight); - } - else - { - deleteChar(startres, seq); - } + // Not a gap, block edit not valid + endEditing(); + return; } } } } - else /////Editing a single sequence/////////// + + + for (int i = 0; i < sg.getSize(true); i++) { + seq = (SequenceI) sg.getSequences(true).elementAt(i); + if (insertGap) { // dragging to the right @@ -778,18 +924,7 @@ public class SeqPanel { if (fixedColumns && fixedRight != -1) { - if (sg.getStartRes() == 0 - && sg.getEndRes() + 1 == av.alignment.getWidth() - && !jalview.util.Comparison.isGap(seq.getCharAt(fixedRight))) - { - //Single sequence edit, whole sequence selected, - //extend the selection group - sg.setEndRes(av.alignment.getWidth() -1 + startres - lastres); - fixedColumns = false; - insertChar(j, seq); - } - else - insertChar(j, seq, fixedRight); + insertChar(j, seq, fixedRight); } else insertChar(j, seq); @@ -811,10 +946,42 @@ public class SeqPanel } } } + } + else /////Editing a single sequence/////////// + { + if (insertGap) + { + // dragging to the right + for (int j = lastres; j < startres; j++) + { + if (fixedColumns && fixedRight != -1) + { + insertChar(j, seq, fixedRight); + } + else + insertChar(j, seq); + } + } + else + { + // dragging to the left + for (int j = lastres; j > startres; j--) + { + if (fixedColumns && fixedRight != -1) + { + deleteChar(startres, seq, fixedRight); + } + else + { + deleteChar(startres, seq); + } + } + } + } - lastres = startres; - seqCanvas.repaint(); - } + lastres = startres; + seqCanvas.repaint(); + } /** @@ -827,7 +994,7 @@ public class SeqPanel { seq.insertCharAt(j, av.getGapCharacter()); seqEditOccurred = true; - } + } void insertChar(int j, SequenceI seq, int fixedColumn) { @@ -869,7 +1036,6 @@ public class SeqPanel "End editing: Tried removing residue " + seq.getCharAt(j)); return; } - seq.deleteCharAt(j); seq.insertCharAt(fixedColumn, av.getGapCharacter()); seqEditOccurred = true; @@ -919,6 +1085,8 @@ public class SeqPanel ////////////////////////////////////////// public void doMousePressedDefineMode(MouseEvent evt) { + + if (scrollThread != null) { scrollThread.running = false; @@ -956,7 +1124,7 @@ public class SeqPanel } } - else if (!stretchGroup.sequences.contains(sequence) + else if (!stretchGroup.getSequences(false).contains(sequence) || stretchGroup.getStartRes() > res || stretchGroup.getEndRes() < res) { @@ -972,57 +1140,76 @@ public class SeqPanel allGroups[i].getEndRes() >= res) { stretchGroup = allGroups[i]; - av.setSelectionGroup(stretchGroup); break; } } } + av.setSelectionGroup(stretchGroup); } - if (stretchGroup == null) - { - // define a new group here - SequenceGroup sg = new SequenceGroup(); - sg.setStartRes(res); - sg.setEndRes(res); - sg.addSequence(sequence, false); - av.setSelectionGroup(sg); - stretchGroup = sg; - - if (av.getConservationSelected()) - { - SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(), - "Background"); - } - if (av.getAbovePIDThreshold()) - { - SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(), - "Background"); - } - - } // DETECT RIGHT MOUSE BUTTON IN AWT - else if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == + if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - APopupMenu popup = new APopupMenu(ap, null, null); + Vector allFeatures = getAllFeaturesAtRes(sequence, + sequence.findPosition(res)); + + Vector links = null; + if(allFeatures!=null) + { + for (int i = 0; i < allFeatures.size(); i++) + { + SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i); + if (sf.links != null) + { + links = new Vector(); + for (int j = 0; j < sf.links.size(); j++) + { + links.addElement(sf.links.elementAt(j)); + } + } + } + } + APopupMenu popup = new APopupMenu(ap, null, links); this.add(popup); popup.show(this, evt.getX(), evt.getY()); + ap.repaint(); + return; } - if (stretchGroup != null && stretchGroup.getEndRes() == res) + if (av.cursorMode) { - // Edit end res position of selected group - changeEndRes = true; + seqCanvas.cursorX = findRes(evt); + seqCanvas.cursorY = findSeq(evt); + seqCanvas.repaint(); + return; } - else if (stretchGroup != null && stretchGroup.getStartRes() == res) - { - // Edit end res position of selected group - changeStartRes = true; - } + //Only if left mouse button do we want to change group sizes + + if (stretchGroup == null) + { + // define a new group here + SequenceGroup sg = new SequenceGroup(); + sg.setStartRes(res); + sg.setEndRes(res); + sg.addSequence(sequence, false); + av.setSelectionGroup(sg); + stretchGroup = sg; + + if (av.getConservationSelected()) + { + SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(), + "Background"); + } + if (av.getAbovePIDThreshold()) + { + SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(), + "Background"); + } + } } public void doMouseReleasedDefineMode(MouseEvent evt) @@ -1036,8 +1223,8 @@ public class SeqPanel { if (stretchGroup.cs instanceof ClustalxColourScheme) { - ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(stretchGroup. - sequences, + ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX( + stretchGroup.getSequences(true), stretchGroup.getWidth()); } @@ -1140,7 +1327,7 @@ public class SeqPanel Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq); - if (stretchGroup.sequences.contains(nextSeq)) + if (stretchGroup.getSequences(false).contains(nextSeq)) { stretchGroup.deleteSequence(seq, false); } @@ -1198,6 +1385,28 @@ public class SeqPanel } } + void scrollCanvas(MouseEvent evt) + { + if(evt==null) + { + if(scrollThread!=null) + { + scrollThread.running = false; + scrollThread = null; + } + mouseDragging = false; + } + else + { + if (scrollThread == null) + scrollThread = new ScrollThread(); + + mouseDragging = true; + scrollThread.setEvent(evt); + } + + } + // this class allows scrolling off the bottom of the visible alignment class ScrollThread extends Thread @@ -1241,12 +1450,12 @@ public class SeqPanel if (mouseDragging && evt.getX() < 0) { - running = ap.scrollRight(true); + running = ap.scrollRight(false); } else if (mouseDragging && evt.getX() >= getSize().width) { - running = ap.scrollRight(false); + running = ap.scrollRight(true); } }