X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqPanel.java;h=6869964d91f826c82e935dea85be8bc32a5d76e1;hb=9c1232ed2d632dd4968e407a6c9aa3e2beb6bacf;hp=987b0b801eabdde8b7657d0e735bf1108e7468b5;hpb=25e0e98d70d32d81c952a5927e847deeee76b810;p=jalview.git diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 987b0b8..6869964 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -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; @@ -182,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) @@ -218,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); @@ -309,11 +314,21 @@ public class SeqPanel ")"); } } + ap.alignFrame.statusBar.setText(text.toString()); } public void mousePressed(MouseEvent evt) { + lastMousePress = evt.getPoint(); + + if ( (evt.getModifiers() & InputEvent.BUTTON2_MASK) == + InputEvent.BUTTON2_MASK) + { + mouseWheelPressed = true; + return; + } + if (evt.isShiftDown() || evt.isAltDown() || evt.isControlDown()) { @@ -360,6 +375,7 @@ public class SeqPanel public void mouseReleased(MouseEvent evt) { mouseDragging = false; + mouseWheelPressed = false; if (!editingSeqs) { @@ -370,7 +386,7 @@ public class SeqPanel editOccurred(); endEditing(); - ap.repaint(); + ap.repaint(); } int startWrapBlock=-1; @@ -522,55 +538,133 @@ public class SeqPanel && 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)) - { - if(!av.featuresDisplayed.containsKey(sf.getType())) - { - index++; - continue; - } - - if(first) - { - text.append(" Sequence Feature:"); - first = false; - } + SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(index); - text.append(" "+sf.getType()); + featureText.append(sf.getType()+" "+sf.begin+":"+sf.end); - if(sf.getDescription()!=null) - text.append(" "+sf.getDescription()); + if (sf.getDescription() != null) + featureText.append(" " + sf.getDescription()); - if (sf.getStatus()!=null && sf.getStatus().length() > 0) - { - text.append(" (" + sf.getStatus() + ")"); - } - text.append("; "); + if (sf.getValue("status") != null ) + { + featureText.append(" (" + sf.getValue("status") + ")"); } + featureText.append("\n"); index++; - } + + + if (tooltip == null) + tooltip = new Tooltip(featureText.toString(), seqCanvas); + else + tooltip.setTip(featureText.toString()); + + tooltip.repaint(); + + // text.append(" Sequence Feature:"); + // text.append(featureText); + } + ap.alignFrame.statusBar.setText(text.toString()); } + 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())) + { + allFeatures.addElement(sf); + } + } + index++; + } + } + 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); @@ -626,7 +720,7 @@ public class SeqPanel //Are we editing within a selection group? if (groupEditing - || (sg != null && sg.sequences.contains(seq))) + || (sg != null && sg.getSequences(false).contains(seq))) { fixedColumns = true; @@ -677,7 +771,7 @@ public class SeqPanel fixedRight--) { blank = true; - for (int s = 0; s < sg.getSize(); s++) + for (int s = 0; s < sg.getSize(false); s++) { seq = sg.getSequenceAt(s); for (int j = 0; j < startres - lastres; j++) @@ -696,7 +790,7 @@ public class SeqPanel if (!blank) { - if(sg.getSize() == av.alignment.getHeight()) + if(sg.getSize(false) == av.alignment.getHeight()) { //We can still insert gaps if the selectionGroup //contains all the sequences @@ -718,7 +812,7 @@ public class SeqPanel /// Are we able to delete? // ie are all columns blank? - for (int s = 0; s < sg.getSize(); s++) + for (int s = 0; s < sg.getSize(false); s++) { seq = sg.getSequenceAt(s); @@ -741,7 +835,7 @@ public class SeqPanel } - for (int i = 0; i < sg.getSize(); i++) + for (int i = 0; i < sg.getSize(false); i++) { seq = sg.getSequenceAt(i); @@ -925,6 +1019,8 @@ public class SeqPanel ////////////////////////////////////////// public void doMousePressedDefineMode(MouseEvent evt) { + + if (scrollThread != null) { scrollThread.running = false; @@ -962,7 +1058,7 @@ public class SeqPanel } } - else if (!stretchGroup.sequences.contains(sequence) + else if (!stretchGroup.getSequences(false).contains(sequence) || stretchGroup.getStartRes() > res || stretchGroup.getEndRes() < res) { @@ -978,57 +1074,90 @@ public class SeqPanel allGroups[i].getEndRes() >= res) { stretchGroup = allGroups[i]; - av.setSelectionGroup(stretchGroup); break; } } } + av.setSelectionGroup(stretchGroup); } - if (stretchGroup == null) + if (av.cursorMode) { - // 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"); - } - + seqCanvas.cursorX = findRes(evt); + seqCanvas.cursorY = findSeq(evt); + seqCanvas.repaint(); + return; } + + // 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(); } - - if (stretchGroup != null && stretchGroup.getEndRes() == res) + else { - // Edit end res position of selected group - changeEndRes = true; - } + //Only if left mouse button do we want to change group sizes - else if (stretchGroup != null && stretchGroup.getStartRes() == res) - { - // Edit end res position of selected group - changeStartRes = true; - } + 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"); + } + + } + + if (stretchGroup != null && stretchGroup.getEndRes() == res) + { + // Edit end res position of selected group + changeEndRes = true; + } + else if (stretchGroup != null && stretchGroup.getStartRes() == res) + { + // Edit end res position of selected group + changeStartRes = true; + } + } } public void doMouseReleasedDefineMode(MouseEvent evt) @@ -1042,8 +1171,8 @@ public class SeqPanel { if (stretchGroup.cs instanceof ClustalxColourScheme) { - ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(stretchGroup. - sequences, + ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX( + stretchGroup.getSequences(true), stretchGroup.getWidth()); } @@ -1146,7 +1275,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); }