From 40ecea964afaaf404465d75873ec915b901117a3 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 13 Jul 2007 15:09:14 +0000 Subject: [PATCH] pickmanager on sequence and alignment position, vamsas pick broadcast and refactor for new DBRef management and generalised source and entry retrieval mechanism for references and cross references --- src/jalview/appletgui/SeqPanel.java | 3388 ++++++++++---------- src/jalview/gui/AlignFrame.java | 135 +- src/jalview/gui/AppJmol.java | 1 + src/jalview/gui/DasSourceBrowser.java | 4 +- src/jalview/gui/FeatureSettings.java | 4 +- src/jalview/gui/PopupMenu.java | 2974 ++++++++--------- src/jalview/gui/SeqPanel.java | 8 +- src/jalview/gui/SequenceFetcher.java | 1185 +++---- src/jalview/gui/TreeCanvas.java | 2 +- src/jalview/jbgui/GAlignFrame.java | 19 +- src/jalview/structure/SequenceListener.java | 60 +- .../structure/StructureSelectionManager.java | 24 +- 12 files changed, 3991 insertions(+), 3813 deletions(-) diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 24a934c..a010364 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -1,1694 +1,1694 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 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 - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -package jalview.appletgui; - -import java.util.*; - -import java.awt.*; -import java.awt.event.*; - -import jalview.commands.*; -import jalview.datamodel.*; -import jalview.schemes.*; -import jalview.structure.SequenceListener; -import jalview.structure.StructureSelectionManager; - -public class SeqPanel - extends Panel implements MouseMotionListener, MouseListener, SequenceListener -{ - - public SeqCanvas seqCanvas; - public AlignmentPanel ap; - - protected int lastres; - protected int startseq; - - protected AlignViewport av; - - // if character is inserted or deleted, we will need to recalculate the conservation - boolean seqEditOccurred = false; - - ScrollThread scrollThread = null; - boolean mouseDragging = false; - boolean editingSeqs = false; - boolean groupEditing = false; - - int oldSeq = -1; - boolean changeEndSeq = false; - boolean changeStartSeq = false; - boolean changeEndRes = false; - boolean changeStartRes = false; - SequenceGroup stretchGroup = null; - - StringBuffer keyboardNo1; - StringBuffer keyboardNo2; - - boolean mouseWheelPressed = false; - Point lastMousePress; - - EditCommand editCommand; - - StructureSelectionManager ssm; - - - public SeqPanel(AlignViewport avp, AlignmentPanel p) - { - this.av = avp; - - seqCanvas = new SeqCanvas(avp); - setLayout(new BorderLayout()); - add(seqCanvas); - - ap = p; - - seqCanvas.addMouseMotionListener(this); - seqCanvas.addMouseListener(this); - ssm = StructureSelectionManager.getStructureSelectionManager(); - ssm.addStructureViewerListener(this); - - seqCanvas.repaint(); - } - - void endEditing() - { - if (editCommand != null && editCommand.getSize() > 0) - { - ap.alignFrame.addHistoryItem(editCommand); - av.firePropertyChange("alignment", null, - av.getAlignment().getSequences()); - } - - startseq = -1; - lastres = -1; - editingSeqs = false; - groupEditing = false; - keyboardNo1 = null; - keyboardNo2 = null; - editCommand = null; - } - - void setCursorRow() - { - seqCanvas.cursorY = getKeyboardNo1() - 1; - scrollToVisible(); - } - - void setCursorColumn() - { - seqCanvas.cursorX = getKeyboardNo1() - 1; - scrollToVisible(); - } - - void setCursorRowAndColumn() - { - if (keyboardNo2 == null) - { - keyboardNo2 = new StringBuffer(); - } - else - { - seqCanvas.cursorX = getKeyboardNo1() - 1; - seqCanvas.cursorY = getKeyboardNo2() - 1; - scrollToVisible(); - } - } - - void setCursorPosition() - { - SequenceI sequence = - (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY); - - seqCanvas.cursorX = sequence.findIndex( - getKeyboardNo1() - 1 - ); - scrollToVisible(); - } - - void moveCursor(int dx, int dy) - { - seqCanvas.cursorX += dx; - seqCanvas.cursorY += dy; - if (av.hasHiddenColumns && !av.colSel.isVisible(seqCanvas.cursorX)) - { - int original = seqCanvas.cursorX - dx; - int maxWidth = av.alignment.getWidth(); - - while (!av.colSel.isVisible(seqCanvas.cursorX) - && seqCanvas.cursorX < maxWidth - && seqCanvas.cursorX > 0) - { - seqCanvas.cursorX += dx; - } - - if (seqCanvas.cursorX >= maxWidth - || !av.colSel.isVisible(seqCanvas.cursorX)) - { - seqCanvas.cursorX = original; - } - } - scrollToVisible(); - } - - void scrollToVisible() - { - if (seqCanvas.cursorX < 0) - { - seqCanvas.cursorX = 0; - } - else if (seqCanvas.cursorX > av.alignment.getWidth() - 1) - { - seqCanvas.cursorX = av.alignment.getWidth() - 1; - } - - if (seqCanvas.cursorY < 0) - { - seqCanvas.cursorY = 0; - } - else if (seqCanvas.cursorY > av.alignment.getHeight() - 1) - { - seqCanvas.cursorY = av.alignment.getHeight() - 1; - } - - endEditing(); - if (av.wrapAlignment) - { - ap.scrollToWrappedVisible(seqCanvas.cursorX); - } - else - { - while (seqCanvas.cursorY < av.startSeq) - { - ap.scrollUp(true); - } - while (seqCanvas.cursorY + 1 > av.endSeq) - { - ap.scrollUp(false); - } - while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes)) - { - - if (!ap.scrollRight(false)) - { - break; - } - } - while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes)) - { - if (!ap.scrollRight(true)) - { - break; - } - } - } - setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY), - seqCanvas.cursorX, seqCanvas.cursorY); - - seqCanvas.repaint(); - } - - void setSelectionAreaAtCursor(boolean topLeft) - { - SequenceI sequence = - (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY); - - if (av.getSelectionGroup() != null) - { - SequenceGroup sg = av.selectionGroup; - //Find the top and bottom of this group - int min = av.alignment.getHeight(), max = 0; - for (int i = 0; i < sg.getSize(); i++) - { - int index = av.alignment.findIndex(sg.getSequenceAt(i)); - if (index > max) - { - max = index; - } - if (index < min) - { - min = index; - } - } - - max++; - - if (topLeft) - { - sg.setStartRes(seqCanvas.cursorX); - if (sg.getEndRes() < seqCanvas.cursorX) - { - sg.setEndRes(seqCanvas.cursorX); - } - - min = seqCanvas.cursorY; - } - else - { - sg.setEndRes(seqCanvas.cursorX); - if (sg.getStartRes() > seqCanvas.cursorX) - { - sg.setStartRes(seqCanvas.cursorX); - } - - max = seqCanvas.cursorY + 1; - } - - if (min > max) - { - // Only the user can do this - av.setSelectionGroup(null); - } - else - { - // Now add any sequences between min and max - sg.getSequences(null).removeAllElements(); - for (int i = min; i < max; i++) - { - sg.addSequence(av.alignment.getSequenceAt(i), false); - } - } - } - - if (av.getSelectionGroup() == null) - { - SequenceGroup sg = new SequenceGroup(); - sg.setStartRes(seqCanvas.cursorX); - sg.setEndRes(seqCanvas.cursorX); - sg.addSequence(sequence, false); - av.setSelectionGroup(sg); - } - - ap.paintAlignment(false); - } - - void insertGapAtCursor(boolean group) - { - groupEditing = group; - startseq = seqCanvas.cursorY; - lastres = seqCanvas.cursorX; - editSequence(true, seqCanvas.cursorX + getKeyboardNo1()); - endEditing(); - } - - void deleteGapAtCursor(boolean group) - { - groupEditing = group; - startseq = seqCanvas.cursorY; - lastres = seqCanvas.cursorX + getKeyboardNo1(); - editSequence(false, seqCanvas.cursorX); - endEditing(); - } - - void numberPressed(char value) - { - if (keyboardNo1 == null) - { - keyboardNo1 = new StringBuffer(); - } - - if (keyboardNo2 != null) - { - keyboardNo2.append(value); - } - else - { - keyboardNo1.append(value); - } - } - - int getKeyboardNo1() - { - if (keyboardNo1 == null) - return 1; - else - { - int value = Integer.parseInt(keyboardNo1.toString()); - keyboardNo1 = null; - return value; - } - } - - int getKeyboardNo2() - { - if (keyboardNo2 == null) - return 1; - else - { - int value = Integer.parseInt(keyboardNo2.toString()); - keyboardNo2 = null; - return value; - } - } - - - void setStatusMessage(SequenceI sequence, int res, int seq) - { - StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " + - sequence.getName()); - - Object obj = null; - if (av.alignment.isNucleotide()) - { - obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) + - ""); - if (obj != null) - { - text.append(" Nucleotide: "); - } - } - else - { - obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + ""); - if (obj != null) - { - text.append(" Residue: "); - } - } - - if (obj != null) - { - - if (obj != "") - { - text.append(obj + " (" + sequence.findPosition(res) + - ")"); - } - } - - ap.alignFrame.statusBar.setText(text.toString()); - - } - - public void mousePressed(MouseEvent evt) - { - 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.isControlDown() || evt.isAltDown()) - { - groupEditing = true; - } - editingSeqs = true; - } - else - { - doMousePressedDefineMode(evt); - return; - } - - int seq = findSeq(evt); - int res = findRes(evt); - - if (seq < 0 || res < 0) - { - return; - } - - if ( (seq < av.getAlignment().getHeight()) && - (res < av.getAlignment().getSequenceAt(seq).getLength())) - { - startseq = seq; - lastres = res; - } - else - { - startseq = -1; - lastres = -1; - } - - return; - } - - public void mouseClicked(MouseEvent evt) - { - SequenceI sequence = av.alignment.getSequenceAt(findSeq(evt)); - if (evt.getClickCount() > 1) - { - if (av.getSelectionGroup().getSize() == 1 - && av.getSelectionGroup().getEndRes() - - av.getSelectionGroup().getStartRes() < 2) - { - av.setSelectionGroup(null); - } - - SequenceFeature[] features = findFeaturesAtRes( - sequence, - sequence.findPosition(findRes(evt)) - ); - - if (features != null && features.length > 0) - { - SearchResults highlight = new SearchResults(); - highlight.addResult(sequence, - features[0].getBegin(), - features[0].getEnd()); - seqCanvas.highlightSearchResults(highlight); - } - if (features != null && features.length > 0) - { - seqCanvas.getFeatureRenderer().amendFeatures( - new SequenceI[] - {sequence}, features, false, ap); - - seqCanvas.highlightSearchResults(null); - } - } - } - - public void mouseReleased(MouseEvent evt) - { - mouseDragging = false; - mouseWheelPressed = false; - ap.paintAlignment(true); - - if (!editingSeqs) - { - doMouseReleasedDefineMode(evt); - return; - } - - endEditing(); - - } - - int startWrapBlock = -1; - int wrappedBlock = -1; - int findRes(MouseEvent evt) - { - int res = 0; - int x = evt.getX(); - - if (av.wrapAlignment) - { - - int hgap = av.charHeight; - if (av.scaleAboveWrapped) - { - hgap += av.charHeight; - } - - int cHeight = av.getAlignment().getHeight() * av.charHeight - + hgap + seqCanvas.getAnnotationHeight(); - - int y = evt.getY(); - y -= hgap; - x -= seqCanvas.LABEL_WEST; - - int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width); - if (cwidth < 1) - { - return 0; - } - - wrappedBlock = y / cHeight; - wrappedBlock += av.getStartRes() / cwidth; - - res = wrappedBlock * cwidth + x / av.getCharWidth(); - - } - else - { - res = (x / av.getCharWidth()) + av.getStartRes(); - } - - if (av.hasHiddenColumns) - { - res = av.getColumnSelection().adjustForHiddenColumns(res); - } - - return res; - - } - - int findSeq(MouseEvent evt) - { - - int seq = 0; - int y = evt.getY(); - - if (av.wrapAlignment) - { - int hgap = av.charHeight; - if (av.scaleAboveWrapped) - { - hgap += av.charHeight; - } - - int cHeight = av.getAlignment().getHeight() * av.charHeight - + hgap + seqCanvas.getAnnotationHeight(); - - y -= hgap; - - seq = Math.min( (y % cHeight) / av.getCharHeight(), - av.alignment.getHeight() - 1); - if (seq < 0) - { - seq = 0; - } - } - else - { - seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(), - av.alignment.getHeight() - 1); - if (seq < 0) - { - seq = 0; - } - } - - return seq; - } - - - - public void doMousePressed(MouseEvent evt) - { - - int seq = findSeq(evt); - int res = findRes(evt); - - if (seq < av.getAlignment().getHeight() && - res < av.getAlignment().getSequenceAt(seq).getLength()) - { - //char resstr = align.getSequenceAt(seq).getSequence().charAt(res); - // Find the residue's position in the sequence (res is the position - // in the alignment - - startseq = seq; - lastres = res; - } - else - { - startseq = -1; - lastres = -1; - } - - return; - } - - - String lastMessage; - public void mouseOverSequence(SequenceI sequence, int index) - { - String tmp = sequence.hashCode()+index+""; - if (lastMessage == null || !lastMessage.equals(tmp)) - ssm.mouseOverSequence(sequence, index); - - lastMessage = tmp; - } - - - public void highlightSequence(SearchResults results) - { - seqCanvas.highlightSearchResults(results); - } - - public void updateColours(SequenceI seq, int index) - { - System.out.println("update the seqPanel colours"); - //repaint(); - } - - public void mouseMoved(MouseEvent evt) - { - int res = findRes(evt); - int seq = findSeq(evt); - - if (seq >= av.getAlignment().getHeight() || seq < 0 || res < 0) - { - if (tooltip != null) - { - tooltip.setTip(""); - } - return; - } - - SequenceI sequence = av.getAlignment().getSequenceAt(seq); - if (res > sequence.getLength()) - { - if (tooltip != null) - { - tooltip.setTip(""); - } - return; - } - - - if (ssm != null) - mouseOverSequence(sequence, sequence.findPosition(res)); - - - StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " + - sequence.getName()); - - Object obj = null; - if (av.alignment.isNucleotide()) - { - obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) + - ""); - if (obj != null) - { - text.append(" Nucleotide: "); - } - } - else - { - obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + ""); - if (obj != null) - { - text.append(" Residue: "); - } - } - - if (obj != null) - { - if (obj != "") - { - text.append(obj + " (" + sequence.findPosition(res) + ")"); - } - } - - ap.alignFrame.statusBar.setText(text.toString()); - - StringBuffer tooltipText = new StringBuffer(); - SequenceGroup[] groups = av.alignment.findAllGroups(sequence); - if (groups != null) - { - for (int g = 0; g < groups.length; g++) - { - if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res) - { - if (!groups[g].getName().startsWith("JTreeGroup") && - !groups[g].getName().startsWith("JGroup")) - { - tooltipText.append(groups[g].getName() + " "); - } - if (groups[g].getDescription() != null) - { - tooltipText.append(groups[g].getDescription()); - } - tooltipText.append("\n"); - } - } - } - - // use aa to see if the mouse pointer is on a - SequenceFeature [] allFeatures = findFeaturesAtRes(sequence, - sequence.findPosition(res)); - - int index = 0; - while (index < allFeatures.length) - { - SequenceFeature sf = allFeatures[index]; - - tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end); - - if (sf.getDescription() != null) - { - tooltipText.append(" " + sf.getDescription()); - } - - if (sf.getValue("status") != null) - { - String status = sf.getValue("status").toString(); - if (status.length() > 0) - { - tooltipText.append(" (" + sf.getValue("status") + ")"); - } - } - tooltipText.append("\n"); - - index++; - } - - if (tooltip == null) - { - tooltip = new Tooltip(tooltipText.toString(), seqCanvas); - } - else - { - tooltip.setTip(tooltipText.toString()); - } - } - - SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res) - { - Vector tmp = new Vector(); - SequenceFeature[] features = sequence.getSequenceFeatures(); - if (features != null) - { - for (int i = 0; i < features.length; i++) - { - if (av.featuresDisplayed == null - || !av.featuresDisplayed.containsKey(features[i].getType())) - { - continue; - } - - - - if (features[i].featureGroup != null - && seqCanvas.fr.featureGroups!=null - && seqCanvas.fr.featureGroups.containsKey(features[i].featureGroup) - && !((Boolean)seqCanvas.fr.featureGroups.get(features[i].featureGroup)).booleanValue()) - continue; - - - if ( (features[i].getBegin() <= res) && - (features[i].getEnd() >= res)) - { - tmp.addElement(features[i]); - } - } - } - - features = new SequenceFeature[tmp.size()]; - tmp.copyInto(features); - - return features; - } - - - Tooltip tooltip; - - public void mouseDragged(MouseEvent evt) - { - 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.paintAlignment(false); - ap.annotationPanel.image = null; - return; - } - - if (!editingSeqs) - { - doMouseDraggedDefineMode(evt); - return; - } - - int res = findRes(evt); - - if (res < 0) - { - res = 0; - } - - if ( (lastres == -1) || (lastres == res)) - { - return; - } - - if ( (res < av.getAlignment().getWidth()) && (res < lastres)) - { - // dragLeft, delete gap - editSequence(false, res); - } - else - { - editSequence(true, res); - } - - mouseDragging = true; - if (scrollThread != null) - { - scrollThread.setEvent(evt); - } - - } - - synchronized void editSequence(boolean insertGap, int startres) - { - int fixedLeft = -1; - int fixedRight = -1; - boolean fixedColumns = false; - SequenceGroup sg = av.getSelectionGroup(); - - SequenceI seq = av.alignment.getSequenceAt(startseq); - - if (!groupEditing && av.hasHiddenRows) - { - if (av.hiddenRepSequences != null - && av.hiddenRepSequences.containsKey(seq)) - { - sg = (SequenceGroup) av.hiddenRepSequences.get(seq); - groupEditing = true; - } - } - - StringBuffer message = new StringBuffer(); - if (groupEditing) - { - message.append("Edit group:"); - if (editCommand == null) - { - editCommand = new EditCommand("Edit Group"); - } - } - else - { - message.append("Edit sequence: " + seq.getName()); - String label = seq.getName(); - if (label.length() > 10) - { - label = label.substring(0, 10); - } - if (editCommand == null) - { - editCommand = new EditCommand("Edit " + label); - } - } - - if (insertGap) - { - message.append(" insert "); - } - else - { - message.append(" delete "); - } - - 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(av.hiddenRepSequences).contains(seq))) - { - fixedColumns = true; - - //sg might be null as the user may only see 1 sequence, - //but the sequence represents a group - if (sg == null) - { - if (av.hiddenRepSequences == null - || !av.hiddenRepSequences.containsKey(seq)) - { - endEditing(); - return; - } - - sg = (SequenceGroup) av.hiddenRepSequences.get(seq); - } - - 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 (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; - } - - //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~"); - //Selection spans a hidden region - if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1)) - { - if (startres >= y2) - { - fixedLeft = y2; - } - else - { - fixedRight = y2 - 1; - } - } - } - - if (groupEditing) - { - Vector vseqs = sg.getSequences(av.hiddenRepSequences); - int g, groupSize = vseqs.size(); - SequenceI[] groupSeqs = new SequenceI[groupSize]; - for (g = 0; g < groupSeqs.length; g++) - { - groupSeqs[g] = (SequenceI) vseqs.elementAt(g); - } - - // 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() == 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--) - { - blank = true; - - for (g = 0; g < groupSize; g++) - { - for (int j = 0; j < startres - lastres; j++) - { - if (!jalview.util.Comparison.isGap( - groupSeqs[g].getCharAt(fixedRight - j))) - { - blank = false; - break; - } - } - } - if (blank) - { - break; - } - } - - if (!blank) - { - if (sg.getSize() == av.alignment.getHeight()) - { - if ( (av.hasHiddenColumns - && - startres < av.getColumnSelection().getHiddenBoundaryRight(startres))) - { - endEditing(); - return; - } - - int alWidth = av.alignment.getWidth(); - if (av.hasHiddenRows) - { - int hwidth = av.alignment.getHiddenSequences().getWidth(); - if (hwidth > alWidth) - { - 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; - } - } - } - - // drag to left - else if (!insertGap) - { - /// Are we able to delete? - // ie are all columns blank? - - for (g = 0; g < groupSize; g++) - { - for (int j = startres; j < lastres; j++) - { - if (groupSeqs[g].getLength() <= j) - { - continue; - } - - if (!jalview.util.Comparison.isGap( - groupSeqs[g].getCharAt(j))) - { - // Not a gap, block edit not valid - endEditing(); - return; - } - } - } - } - - if (insertGap) - { - // dragging to the right - if (fixedColumns && fixedRight != -1) - { - for (int j = lastres; j < startres; j++) - { - insertChar(j, groupSeqs, fixedRight); - } - } - else - { - editCommand.appendEdit(EditCommand.INSERT_GAP, - groupSeqs, - startres, startres - lastres, - av.alignment, - true); - } - } - else - { - // dragging to the left - if (fixedColumns && fixedRight != -1) - { - for (int j = lastres; j > startres; j--) - { - deleteChar(startres, groupSeqs, fixedRight); - } - } - else - { - editCommand.appendEdit(EditCommand.DELETE_GAP, - groupSeqs, - startres, lastres - startres, - av.alignment, - true); - } - - } - } - else /////Editing a single sequence/////////// - { - if (insertGap) - { - // dragging to the right - if (fixedColumns && fixedRight != -1) - { - for (int j = lastres; j < startres; j++) - { - insertChar(j, new SequenceI[] - {seq}, fixedRight); - } - } - else - { - editCommand.appendEdit(EditCommand.INSERT_GAP, - new SequenceI[] - {seq}, - lastres, startres - lastres, - av.alignment, - true); - } - } - else - { - // dragging to the left - if (fixedColumns && fixedRight != -1) - { - for (int j = lastres; j > startres; j--) - { - if (!jalview.util.Comparison.isGap(seq.getCharAt(startres))) - { - endEditing(); - break; - } - deleteChar(startres, new SequenceI[] - {seq}, fixedRight); - } - } - else - { - //could be a keyboard edit trying to delete none gaps - int max = 0; - for (int m = startres; m < lastres; m++) - { - if (!jalview.util.Comparison.isGap(seq.getCharAt(m))) - { - break; - } - max++; - } - - if (max > 0) - { - editCommand.appendEdit(EditCommand.DELETE_GAP, - new SequenceI[] - {seq}, - startres, max, - av.alignment, - true); - } - } - } - } - - lastres = startres; - seqCanvas.repaint(); - } - - void insertChar(int j, SequenceI[] seq, int fixedColumn) - { - int blankColumn = fixedColumn; - for (int s = 0; s < seq.length; s++) - { - //Find the next gap before the end of the visible region boundary - //If lastCol > j, theres a boundary after the gap insertion - - for (blankColumn = fixedColumn; blankColumn > j; blankColumn--) - { - if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn))) - { - //Theres a space, so break and insert the gap - break; - } - } - - if (blankColumn <= j) - { - blankColumn = fixedColumn; - endEditing(); - return; - } - } - - editCommand.appendEdit(EditCommand.DELETE_GAP, - seq, - blankColumn, 1, av.alignment, true); - - editCommand.appendEdit(EditCommand.INSERT_GAP, - seq, - j, 1, av.alignment, - true); - - } - - void deleteChar(int j, SequenceI[] seq, int fixedColumn) - { - - editCommand.appendEdit(EditCommand.DELETE_GAP, - seq, - j, 1, av.alignment, true); - - editCommand.appendEdit(EditCommand.INSERT_GAP, - seq, - fixedColumn, 1, av.alignment, true); - } - -////////////////////////////////////////// -/////Everything below this is for defining the boundary of the rubberband -////////////////////////////////////////// - public void doMousePressedDefineMode(MouseEvent evt) - { - if (scrollThread != null) - { - scrollThread.running = false; - scrollThread = null; - } - - int res = findRes(evt); - int seq = findSeq(evt); - oldSeq = seq; - startWrapBlock = wrappedBlock; - - if (seq == -1) - { - return; - } - - SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq); - - if (sequence == null || res > sequence.getLength()) - { - return; - } - - stretchGroup = av.getSelectionGroup(); - - if (stretchGroup == null) - { - stretchGroup = av.alignment.findGroup(sequence); - if (stretchGroup != null && res > stretchGroup.getStartRes() && - res < stretchGroup.getEndRes()) - { - av.setSelectionGroup(stretchGroup); - } - else - { - stretchGroup = null; - } - } - - else if (!stretchGroup.getSequences(null).contains(sequence) - || stretchGroup.getStartRes() > res - || stretchGroup.getEndRes() < res) - { - stretchGroup = null; - - SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence); - - if (allGroups != null) - { - for (int i = 0; i < allGroups.length; i++) - { - if (allGroups[i].getStartRes() <= res && - allGroups[i].getEndRes() >= res) - { - stretchGroup = allGroups[i]; - break; - } - } - } - av.setSelectionGroup(stretchGroup); - } - - // DETECT RIGHT MOUSE BUTTON IN AWT - if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == - InputEvent.BUTTON3_MASK) - { - SequenceFeature [] allFeatures = findFeaturesAtRes(sequence, - sequence.findPosition(res)); - - Vector links = null; - if (allFeatures != null) - { - for (int i = 0; i < allFeatures.length; i++) - { - if (allFeatures[i].links != null) - { - links = new Vector(); - for (int j = 0; j < allFeatures[i].links.size(); j++) - { - links.addElement(allFeatures[i].links.elementAt(j)); - } - } - } - } - APopupMenu popup = new APopupMenu(ap, null, links); - this.add(popup); - popup.show(this, evt.getX(), evt.getY()); - return; - } - - if (av.cursorMode) - { - seqCanvas.cursorX = findRes(evt); - seqCanvas.cursorY = findSeq(evt); - seqCanvas.repaint(); - return; - } - - //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) - { - if (stretchGroup == null) - { - return; - } - - if (stretchGroup.cs != null) - { - if (stretchGroup.cs instanceof ClustalxColourScheme) - { - ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX( - stretchGroup.getSequences(av.hiddenRepSequences), - stretchGroup.getWidth()); - } - - if (stretchGroup.cs instanceof Blosum62ColourScheme - || stretchGroup.cs instanceof PIDColourScheme - || stretchGroup.cs.conservationApplied() - || stretchGroup.cs.getThreshold() > 0) - { - stretchGroup.recalcConservation(); - } - - if (stretchGroup.cs.conservationApplied()) - { - SliderPanel.setConservationSlider(ap, stretchGroup.cs, - stretchGroup.getName()); - stretchGroup.recalcConservation(); - } - else - { - SliderPanel.setPIDSliderSource(ap, stretchGroup.cs, - stretchGroup.getName()); - } - } - changeEndRes = false; - changeStartRes = false; - stretchGroup = null; - PaintRefresher.Refresh(ap, av.getSequenceSetId()); - ap.paintAlignment(true); - } - - public void doMouseDraggedDefineMode(MouseEvent evt) - { - int res = findRes(evt); - int y = findSeq(evt); - - if (wrappedBlock != startWrapBlock) - { - return; - } - - if (stretchGroup == null) - { - return; - } - - mouseDragging = true; - - if (y > av.alignment.getHeight()) - { - y = av.alignment.getHeight() - 1; - } - - if (res >= av.alignment.getWidth()) - { - res = av.alignment.getWidth() - 1; - } - - if (stretchGroup.getEndRes() == res) - { - // Edit end res position of selected group - changeEndRes = true; - } - else if (stretchGroup.getStartRes() == res) - { - // Edit start res position of selected group - changeStartRes = true; - } - - if (res < 0) - { - res = 0; - } - - if (changeEndRes) - { - if (res > (stretchGroup.getStartRes() - 1)) - { - stretchGroup.setEndRes(res); - } - } - else if (changeStartRes) - { - if (res < (stretchGroup.getEndRes() + 1)) - { - stretchGroup.setStartRes(res); - } - } - - int dragDirection = 0; - - if (y > oldSeq) - { - dragDirection = 1; - } - else if (y < oldSeq) - { - dragDirection = -1; - } - - while ( (y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight())) - { - // This routine ensures we don't skip any sequences, as the - // selection is quite slow. - Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq); - - oldSeq += dragDirection; - - if (oldSeq < 0) - { - break; - } - - Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq); - - if (stretchGroup.getSequences(null).contains(nextSeq)) - { - stretchGroup.deleteSequence(seq, false); - } - else - { - if (seq != null) - { - stretchGroup.addSequence(seq, false); - } - - stretchGroup.addSequence(nextSeq, false); - } - } - - if (oldSeq < 0) - { - oldSeq = -1; - } - - if (res > av.endRes || res < av.startRes - || y < av.startSeq || y > av.endSeq) - { - mouseExited(evt); - } - - if (scrollThread != null) - { - scrollThread.setEvent(evt); - } - - seqCanvas.repaint(); - } - - public void mouseEntered(MouseEvent e) - { - if (oldSeq < 0) - { - oldSeq = 0; - } - - if (scrollThread != null) - { - scrollThread.running = false; - scrollThread = null; - } - } - - public void mouseExited(MouseEvent e) - { - if (av.getWrapAlignment()) - { - return; - } - - if (mouseDragging && scrollThread == null) - { - scrollThread = new ScrollThread(); - } - } - - 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 - { - MouseEvent evt; - boolean running = false; - public ScrollThread() - { - start(); - } - - public void setEvent(MouseEvent e) - { - evt = e; - } - - public void stopScrolling() - { - running = false; - } - - public void run() - { - running = true; - while (running) - { - - if (evt != null) - { - - if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0) - { - running = ap.scrollUp(true); - } - - if (mouseDragging && evt.getY() >= getSize().height && - av.alignment.getHeight() > av.getEndSeq()) - { - running = ap.scrollUp(false); - } - - if (mouseDragging && evt.getX() < 0) - { - running = ap.scrollRight(false); - } - - else if (mouseDragging && evt.getX() >= getSize().width) - { - running = ap.scrollRight(true); - } - } - - try - { - Thread.sleep(75); - } - catch (Exception ex) - {} - } - } - } - -} +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +package jalview.appletgui; + +import java.util.*; + +import java.awt.*; +import java.awt.event.*; + +import jalview.commands.*; +import jalview.datamodel.*; +import jalview.schemes.*; +import jalview.structure.SequenceListener; +import jalview.structure.StructureSelectionManager; + +public class SeqPanel + extends Panel implements MouseMotionListener, MouseListener, SequenceListener +{ + + public SeqCanvas seqCanvas; + public AlignmentPanel ap; + + protected int lastres; + protected int startseq; + + protected AlignViewport av; + + // if character is inserted or deleted, we will need to recalculate the conservation + boolean seqEditOccurred = false; + + ScrollThread scrollThread = null; + boolean mouseDragging = false; + boolean editingSeqs = false; + boolean groupEditing = false; + + int oldSeq = -1; + boolean changeEndSeq = false; + boolean changeStartSeq = false; + boolean changeEndRes = false; + boolean changeStartRes = false; + SequenceGroup stretchGroup = null; + + StringBuffer keyboardNo1; + StringBuffer keyboardNo2; + + boolean mouseWheelPressed = false; + Point lastMousePress; + + EditCommand editCommand; + + StructureSelectionManager ssm; + + + public SeqPanel(AlignViewport avp, AlignmentPanel p) + { + this.av = avp; + + seqCanvas = new SeqCanvas(avp); + setLayout(new BorderLayout()); + add(seqCanvas); + + ap = p; + + seqCanvas.addMouseMotionListener(this); + seqCanvas.addMouseListener(this); + ssm = StructureSelectionManager.getStructureSelectionManager(); + ssm.addStructureViewerListener(this); + + seqCanvas.repaint(); + } + + void endEditing() + { + if (editCommand != null && editCommand.getSize() > 0) + { + ap.alignFrame.addHistoryItem(editCommand); + av.firePropertyChange("alignment", null, + av.getAlignment().getSequences()); + } + + startseq = -1; + lastres = -1; + editingSeqs = false; + groupEditing = false; + keyboardNo1 = null; + keyboardNo2 = null; + editCommand = null; + } + + void setCursorRow() + { + seqCanvas.cursorY = getKeyboardNo1() - 1; + scrollToVisible(); + } + + void setCursorColumn() + { + seqCanvas.cursorX = getKeyboardNo1() - 1; + scrollToVisible(); + } + + void setCursorRowAndColumn() + { + if (keyboardNo2 == null) + { + keyboardNo2 = new StringBuffer(); + } + else + { + seqCanvas.cursorX = getKeyboardNo1() - 1; + seqCanvas.cursorY = getKeyboardNo2() - 1; + scrollToVisible(); + } + } + + void setCursorPosition() + { + SequenceI sequence = + (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY); + + seqCanvas.cursorX = sequence.findIndex( + getKeyboardNo1() - 1 + ); + scrollToVisible(); + } + + void moveCursor(int dx, int dy) + { + seqCanvas.cursorX += dx; + seqCanvas.cursorY += dy; + if (av.hasHiddenColumns && !av.colSel.isVisible(seqCanvas.cursorX)) + { + int original = seqCanvas.cursorX - dx; + int maxWidth = av.alignment.getWidth(); + + while (!av.colSel.isVisible(seqCanvas.cursorX) + && seqCanvas.cursorX < maxWidth + && seqCanvas.cursorX > 0) + { + seqCanvas.cursorX += dx; + } + + if (seqCanvas.cursorX >= maxWidth + || !av.colSel.isVisible(seqCanvas.cursorX)) + { + seqCanvas.cursorX = original; + } + } + scrollToVisible(); + } + + void scrollToVisible() + { + if (seqCanvas.cursorX < 0) + { + seqCanvas.cursorX = 0; + } + else if (seqCanvas.cursorX > av.alignment.getWidth() - 1) + { + seqCanvas.cursorX = av.alignment.getWidth() - 1; + } + + if (seqCanvas.cursorY < 0) + { + seqCanvas.cursorY = 0; + } + else if (seqCanvas.cursorY > av.alignment.getHeight() - 1) + { + seqCanvas.cursorY = av.alignment.getHeight() - 1; + } + + endEditing(); + if (av.wrapAlignment) + { + ap.scrollToWrappedVisible(seqCanvas.cursorX); + } + else + { + while (seqCanvas.cursorY < av.startSeq) + { + ap.scrollUp(true); + } + while (seqCanvas.cursorY + 1 > av.endSeq) + { + ap.scrollUp(false); + } + while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes)) + { + + if (!ap.scrollRight(false)) + { + break; + } + } + while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes)) + { + if (!ap.scrollRight(true)) + { + break; + } + } + } + setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY), + seqCanvas.cursorX, seqCanvas.cursorY); + + seqCanvas.repaint(); + } + + void setSelectionAreaAtCursor(boolean topLeft) + { + SequenceI sequence = + (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY); + + if (av.getSelectionGroup() != null) + { + SequenceGroup sg = av.selectionGroup; + //Find the top and bottom of this group + int min = av.alignment.getHeight(), max = 0; + for (int i = 0; i < sg.getSize(); i++) + { + int index = av.alignment.findIndex(sg.getSequenceAt(i)); + if (index > max) + { + max = index; + } + if (index < min) + { + min = index; + } + } + + max++; + + if (topLeft) + { + sg.setStartRes(seqCanvas.cursorX); + if (sg.getEndRes() < seqCanvas.cursorX) + { + sg.setEndRes(seqCanvas.cursorX); + } + + min = seqCanvas.cursorY; + } + else + { + sg.setEndRes(seqCanvas.cursorX); + if (sg.getStartRes() > seqCanvas.cursorX) + { + sg.setStartRes(seqCanvas.cursorX); + } + + max = seqCanvas.cursorY + 1; + } + + if (min > max) + { + // Only the user can do this + av.setSelectionGroup(null); + } + else + { + // Now add any sequences between min and max + sg.getSequences(null).removeAllElements(); + for (int i = min; i < max; i++) + { + sg.addSequence(av.alignment.getSequenceAt(i), false); + } + } + } + + if (av.getSelectionGroup() == null) + { + SequenceGroup sg = new SequenceGroup(); + sg.setStartRes(seqCanvas.cursorX); + sg.setEndRes(seqCanvas.cursorX); + sg.addSequence(sequence, false); + av.setSelectionGroup(sg); + } + + ap.paintAlignment(false); + } + + void insertGapAtCursor(boolean group) + { + groupEditing = group; + startseq = seqCanvas.cursorY; + lastres = seqCanvas.cursorX; + editSequence(true, seqCanvas.cursorX + getKeyboardNo1()); + endEditing(); + } + + void deleteGapAtCursor(boolean group) + { + groupEditing = group; + startseq = seqCanvas.cursorY; + lastres = seqCanvas.cursorX + getKeyboardNo1(); + editSequence(false, seqCanvas.cursorX); + endEditing(); + } + + void numberPressed(char value) + { + if (keyboardNo1 == null) + { + keyboardNo1 = new StringBuffer(); + } + + if (keyboardNo2 != null) + { + keyboardNo2.append(value); + } + else + { + keyboardNo1.append(value); + } + } + + int getKeyboardNo1() + { + if (keyboardNo1 == null) + return 1; + else + { + int value = Integer.parseInt(keyboardNo1.toString()); + keyboardNo1 = null; + return value; + } + } + + int getKeyboardNo2() + { + if (keyboardNo2 == null) + return 1; + else + { + int value = Integer.parseInt(keyboardNo2.toString()); + keyboardNo2 = null; + return value; + } + } + + + void setStatusMessage(SequenceI sequence, int res, int seq) + { + StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " + + sequence.getName()); + + Object obj = null; + if (av.alignment.isNucleotide()) + { + obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) + + ""); + if (obj != null) + { + text.append(" Nucleotide: "); + } + } + else + { + obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + ""); + if (obj != null) + { + text.append(" Residue: "); + } + } + + if (obj != null) + { + + if (obj != "") + { + text.append(obj + " (" + sequence.findPosition(res) + + ")"); + } + } + + ap.alignFrame.statusBar.setText(text.toString()); + + } + + public void mousePressed(MouseEvent evt) + { + 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.isControlDown() || evt.isAltDown()) + { + groupEditing = true; + } + editingSeqs = true; + } + else + { + doMousePressedDefineMode(evt); + return; + } + + int seq = findSeq(evt); + int res = findRes(evt); + + if (seq < 0 || res < 0) + { + return; + } + + if ( (seq < av.getAlignment().getHeight()) && + (res < av.getAlignment().getSequenceAt(seq).getLength())) + { + startseq = seq; + lastres = res; + } + else + { + startseq = -1; + lastres = -1; + } + + return; + } + + public void mouseClicked(MouseEvent evt) + { + SequenceI sequence = av.alignment.getSequenceAt(findSeq(evt)); + if (evt.getClickCount() > 1) + { + if (av.getSelectionGroup().getSize() == 1 + && av.getSelectionGroup().getEndRes() + - av.getSelectionGroup().getStartRes() < 2) + { + av.setSelectionGroup(null); + } + + SequenceFeature[] features = findFeaturesAtRes( + sequence, + sequence.findPosition(findRes(evt)) + ); + + if (features != null && features.length > 0) + { + SearchResults highlight = new SearchResults(); + highlight.addResult(sequence, + features[0].getBegin(), + features[0].getEnd()); + seqCanvas.highlightSearchResults(highlight); + } + if (features != null && features.length > 0) + { + seqCanvas.getFeatureRenderer().amendFeatures( + new SequenceI[] + {sequence}, features, false, ap); + + seqCanvas.highlightSearchResults(null); + } + } + } + + public void mouseReleased(MouseEvent evt) + { + mouseDragging = false; + mouseWheelPressed = false; + ap.paintAlignment(true); + + if (!editingSeqs) + { + doMouseReleasedDefineMode(evt); + return; + } + + endEditing(); + + } + + int startWrapBlock = -1; + int wrappedBlock = -1; + int findRes(MouseEvent evt) + { + int res = 0; + int x = evt.getX(); + + if (av.wrapAlignment) + { + + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + { + hgap += av.charHeight; + } + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + seqCanvas.getAnnotationHeight(); + + int y = evt.getY(); + y -= hgap; + x -= seqCanvas.LABEL_WEST; + + int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width); + if (cwidth < 1) + { + return 0; + } + + wrappedBlock = y / cHeight; + wrappedBlock += av.getStartRes() / cwidth; + + res = wrappedBlock * cwidth + x / av.getCharWidth(); + + } + else + { + res = (x / av.getCharWidth()) + av.getStartRes(); + } + + if (av.hasHiddenColumns) + { + res = av.getColumnSelection().adjustForHiddenColumns(res); + } + + return res; + + } + + int findSeq(MouseEvent evt) + { + + int seq = 0; + int y = evt.getY(); + + if (av.wrapAlignment) + { + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + { + hgap += av.charHeight; + } + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + seqCanvas.getAnnotationHeight(); + + y -= hgap; + + seq = Math.min( (y % cHeight) / av.getCharHeight(), + av.alignment.getHeight() - 1); + if (seq < 0) + { + seq = 0; + } + } + else + { + seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(), + av.alignment.getHeight() - 1); + if (seq < 0) + { + seq = 0; + } + } + + return seq; + } + + + + public void doMousePressed(MouseEvent evt) + { + + int seq = findSeq(evt); + int res = findRes(evt); + + if (seq < av.getAlignment().getHeight() && + res < av.getAlignment().getSequenceAt(seq).getLength()) + { + //char resstr = align.getSequenceAt(seq).getSequence().charAt(res); + // Find the residue's position in the sequence (res is the position + // in the alignment + + startseq = seq; + lastres = res; + } + else + { + startseq = -1; + lastres = -1; + } + + return; + } + + + String lastMessage; + public void mouseOverSequence(SequenceI sequence, int index, int pos) + { + String tmp = sequence.hashCode()+index+""; + if (lastMessage == null || !lastMessage.equals(tmp)) + ssm.mouseOverSequence(sequence, index, pos); + + lastMessage = tmp; + } + + + public void highlightSequence(SearchResults results) + { + seqCanvas.highlightSearchResults(results); + } + + public void updateColours(SequenceI seq, int index) + { + System.out.println("update the seqPanel colours"); + //repaint(); + } + + public void mouseMoved(MouseEvent evt) + { + int res = findRes(evt); + int seq = findSeq(evt); + + if (seq >= av.getAlignment().getHeight() || seq < 0 || res < 0) + { + if (tooltip != null) + { + tooltip.setTip(""); + } + return; + } + + SequenceI sequence = av.getAlignment().getSequenceAt(seq); + if (res > sequence.getLength()) + { + if (tooltip != null) + { + tooltip.setTip(""); + } + return; + } + + int respos = sequence.findPosition(res); + if (ssm != null) + mouseOverSequence(sequence, res, respos); + + + StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " + + sequence.getName()); + + Object obj = null; + if (av.alignment.isNucleotide()) + { + obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) + + ""); + if (obj != null) + { + text.append(" Nucleotide: "); + } + } + else + { + obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + ""); + if (obj != null) + { + text.append(" Residue: "); + } + } + + if (obj != null) + { + if (obj != "") + { + text.append(obj + " (" + respos + ")"); + } + } + + ap.alignFrame.statusBar.setText(text.toString()); + + StringBuffer tooltipText = new StringBuffer(); + SequenceGroup[] groups = av.alignment.findAllGroups(sequence); + if (groups != null) + { + for (int g = 0; g < groups.length; g++) + { + if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res) + { + if (!groups[g].getName().startsWith("JTreeGroup") && + !groups[g].getName().startsWith("JGroup")) + { + tooltipText.append(groups[g].getName() + " "); + } + if (groups[g].getDescription() != null) + { + tooltipText.append(groups[g].getDescription()); + } + tooltipText.append("\n"); + } + } + } + + // use aa to see if the mouse pointer is on a + SequenceFeature [] allFeatures = findFeaturesAtRes(sequence, + sequence.findPosition(res)); + + int index = 0; + while (index < allFeatures.length) + { + SequenceFeature sf = allFeatures[index]; + + tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end); + + if (sf.getDescription() != null) + { + tooltipText.append(" " + sf.getDescription()); + } + + if (sf.getValue("status") != null) + { + String status = sf.getValue("status").toString(); + if (status.length() > 0) + { + tooltipText.append(" (" + sf.getValue("status") + ")"); + } + } + tooltipText.append("\n"); + + index++; + } + + if (tooltip == null) + { + tooltip = new Tooltip(tooltipText.toString(), seqCanvas); + } + else + { + tooltip.setTip(tooltipText.toString()); + } + } + + SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res) + { + Vector tmp = new Vector(); + SequenceFeature[] features = sequence.getSequenceFeatures(); + if (features != null) + { + for (int i = 0; i < features.length; i++) + { + if (av.featuresDisplayed == null + || !av.featuresDisplayed.containsKey(features[i].getType())) + { + continue; + } + + + + if (features[i].featureGroup != null + && seqCanvas.fr.featureGroups!=null + && seqCanvas.fr.featureGroups.containsKey(features[i].featureGroup) + && !((Boolean)seqCanvas.fr.featureGroups.get(features[i].featureGroup)).booleanValue()) + continue; + + + if ( (features[i].getBegin() <= res) && + (features[i].getEnd() >= res)) + { + tmp.addElement(features[i]); + } + } + } + + features = new SequenceFeature[tmp.size()]; + tmp.copyInto(features); + + return features; + } + + + Tooltip tooltip; + + public void mouseDragged(MouseEvent evt) + { + 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.paintAlignment(false); + ap.annotationPanel.image = null; + return; + } + + if (!editingSeqs) + { + doMouseDraggedDefineMode(evt); + return; + } + + int res = findRes(evt); + + if (res < 0) + { + res = 0; + } + + if ( (lastres == -1) || (lastres == res)) + { + return; + } + + if ( (res < av.getAlignment().getWidth()) && (res < lastres)) + { + // dragLeft, delete gap + editSequence(false, res); + } + else + { + editSequence(true, res); + } + + mouseDragging = true; + if (scrollThread != null) + { + scrollThread.setEvent(evt); + } + + } + + synchronized void editSequence(boolean insertGap, int startres) + { + int fixedLeft = -1; + int fixedRight = -1; + boolean fixedColumns = false; + SequenceGroup sg = av.getSelectionGroup(); + + SequenceI seq = av.alignment.getSequenceAt(startseq); + + if (!groupEditing && av.hasHiddenRows) + { + if (av.hiddenRepSequences != null + && av.hiddenRepSequences.containsKey(seq)) + { + sg = (SequenceGroup) av.hiddenRepSequences.get(seq); + groupEditing = true; + } + } + + StringBuffer message = new StringBuffer(); + if (groupEditing) + { + message.append("Edit group:"); + if (editCommand == null) + { + editCommand = new EditCommand("Edit Group"); + } + } + else + { + message.append("Edit sequence: " + seq.getName()); + String label = seq.getName(); + if (label.length() > 10) + { + label = label.substring(0, 10); + } + if (editCommand == null) + { + editCommand = new EditCommand("Edit " + label); + } + } + + if (insertGap) + { + message.append(" insert "); + } + else + { + message.append(" delete "); + } + + 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(av.hiddenRepSequences).contains(seq))) + { + fixedColumns = true; + + //sg might be null as the user may only see 1 sequence, + //but the sequence represents a group + if (sg == null) + { + if (av.hiddenRepSequences == null + || !av.hiddenRepSequences.containsKey(seq)) + { + endEditing(); + return; + } + + sg = (SequenceGroup) av.hiddenRepSequences.get(seq); + } + + 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 (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; + } + + //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~"); + //Selection spans a hidden region + if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1)) + { + if (startres >= y2) + { + fixedLeft = y2; + } + else + { + fixedRight = y2 - 1; + } + } + } + + if (groupEditing) + { + Vector vseqs = sg.getSequences(av.hiddenRepSequences); + int g, groupSize = vseqs.size(); + SequenceI[] groupSeqs = new SequenceI[groupSize]; + for (g = 0; g < groupSeqs.length; g++) + { + groupSeqs[g] = (SequenceI) vseqs.elementAt(g); + } + + // 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() == 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--) + { + blank = true; + + for (g = 0; g < groupSize; g++) + { + for (int j = 0; j < startres - lastres; j++) + { + if (!jalview.util.Comparison.isGap( + groupSeqs[g].getCharAt(fixedRight - j))) + { + blank = false; + break; + } + } + } + if (blank) + { + break; + } + } + + if (!blank) + { + if (sg.getSize() == av.alignment.getHeight()) + { + if ( (av.hasHiddenColumns + && + startres < av.getColumnSelection().getHiddenBoundaryRight(startres))) + { + endEditing(); + return; + } + + int alWidth = av.alignment.getWidth(); + if (av.hasHiddenRows) + { + int hwidth = av.alignment.getHiddenSequences().getWidth(); + if (hwidth > alWidth) + { + 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; + } + } + } + + // drag to left + else if (!insertGap) + { + /// Are we able to delete? + // ie are all columns blank? + + for (g = 0; g < groupSize; g++) + { + for (int j = startres; j < lastres; j++) + { + if (groupSeqs[g].getLength() <= j) + { + continue; + } + + if (!jalview.util.Comparison.isGap( + groupSeqs[g].getCharAt(j))) + { + // Not a gap, block edit not valid + endEditing(); + return; + } + } + } + } + + if (insertGap) + { + // dragging to the right + if (fixedColumns && fixedRight != -1) + { + for (int j = lastres; j < startres; j++) + { + insertChar(j, groupSeqs, fixedRight); + } + } + else + { + editCommand.appendEdit(EditCommand.INSERT_GAP, + groupSeqs, + startres, startres - lastres, + av.alignment, + true); + } + } + else + { + // dragging to the left + if (fixedColumns && fixedRight != -1) + { + for (int j = lastres; j > startres; j--) + { + deleteChar(startres, groupSeqs, fixedRight); + } + } + else + { + editCommand.appendEdit(EditCommand.DELETE_GAP, + groupSeqs, + startres, lastres - startres, + av.alignment, + true); + } + + } + } + else /////Editing a single sequence/////////// + { + if (insertGap) + { + // dragging to the right + if (fixedColumns && fixedRight != -1) + { + for (int j = lastres; j < startres; j++) + { + insertChar(j, new SequenceI[] + {seq}, fixedRight); + } + } + else + { + editCommand.appendEdit(EditCommand.INSERT_GAP, + new SequenceI[] + {seq}, + lastres, startres - lastres, + av.alignment, + true); + } + } + else + { + // dragging to the left + if (fixedColumns && fixedRight != -1) + { + for (int j = lastres; j > startres; j--) + { + if (!jalview.util.Comparison.isGap(seq.getCharAt(startres))) + { + endEditing(); + break; + } + deleteChar(startres, new SequenceI[] + {seq}, fixedRight); + } + } + else + { + //could be a keyboard edit trying to delete none gaps + int max = 0; + for (int m = startres; m < lastres; m++) + { + if (!jalview.util.Comparison.isGap(seq.getCharAt(m))) + { + break; + } + max++; + } + + if (max > 0) + { + editCommand.appendEdit(EditCommand.DELETE_GAP, + new SequenceI[] + {seq}, + startres, max, + av.alignment, + true); + } + } + } + } + + lastres = startres; + seqCanvas.repaint(); + } + + void insertChar(int j, SequenceI[] seq, int fixedColumn) + { + int blankColumn = fixedColumn; + for (int s = 0; s < seq.length; s++) + { + //Find the next gap before the end of the visible region boundary + //If lastCol > j, theres a boundary after the gap insertion + + for (blankColumn = fixedColumn; blankColumn > j; blankColumn--) + { + if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn))) + { + //Theres a space, so break and insert the gap + break; + } + } + + if (blankColumn <= j) + { + blankColumn = fixedColumn; + endEditing(); + return; + } + } + + editCommand.appendEdit(EditCommand.DELETE_GAP, + seq, + blankColumn, 1, av.alignment, true); + + editCommand.appendEdit(EditCommand.INSERT_GAP, + seq, + j, 1, av.alignment, + true); + + } + + void deleteChar(int j, SequenceI[] seq, int fixedColumn) + { + + editCommand.appendEdit(EditCommand.DELETE_GAP, + seq, + j, 1, av.alignment, true); + + editCommand.appendEdit(EditCommand.INSERT_GAP, + seq, + fixedColumn, 1, av.alignment, true); + } + +////////////////////////////////////////// +/////Everything below this is for defining the boundary of the rubberband +////////////////////////////////////////// + public void doMousePressedDefineMode(MouseEvent evt) + { + if (scrollThread != null) + { + scrollThread.running = false; + scrollThread = null; + } + + int res = findRes(evt); + int seq = findSeq(evt); + oldSeq = seq; + startWrapBlock = wrappedBlock; + + if (seq == -1) + { + return; + } + + SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq); + + if (sequence == null || res > sequence.getLength()) + { + return; + } + + stretchGroup = av.getSelectionGroup(); + + if (stretchGroup == null) + { + stretchGroup = av.alignment.findGroup(sequence); + if (stretchGroup != null && res > stretchGroup.getStartRes() && + res < stretchGroup.getEndRes()) + { + av.setSelectionGroup(stretchGroup); + } + else + { + stretchGroup = null; + } + } + + else if (!stretchGroup.getSequences(null).contains(sequence) + || stretchGroup.getStartRes() > res + || stretchGroup.getEndRes() < res) + { + stretchGroup = null; + + SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence); + + if (allGroups != null) + { + for (int i = 0; i < allGroups.length; i++) + { + if (allGroups[i].getStartRes() <= res && + allGroups[i].getEndRes() >= res) + { + stretchGroup = allGroups[i]; + break; + } + } + } + av.setSelectionGroup(stretchGroup); + } + + // DETECT RIGHT MOUSE BUTTON IN AWT + if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == + InputEvent.BUTTON3_MASK) + { + SequenceFeature [] allFeatures = findFeaturesAtRes(sequence, + sequence.findPosition(res)); + + Vector links = null; + if (allFeatures != null) + { + for (int i = 0; i < allFeatures.length; i++) + { + if (allFeatures[i].links != null) + { + links = new Vector(); + for (int j = 0; j < allFeatures[i].links.size(); j++) + { + links.addElement(allFeatures[i].links.elementAt(j)); + } + } + } + } + APopupMenu popup = new APopupMenu(ap, null, links); + this.add(popup); + popup.show(this, evt.getX(), evt.getY()); + return; + } + + if (av.cursorMode) + { + seqCanvas.cursorX = findRes(evt); + seqCanvas.cursorY = findSeq(evt); + seqCanvas.repaint(); + return; + } + + //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) + { + if (stretchGroup == null) + { + return; + } + + if (stretchGroup.cs != null) + { + if (stretchGroup.cs instanceof ClustalxColourScheme) + { + ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX( + stretchGroup.getSequences(av.hiddenRepSequences), + stretchGroup.getWidth()); + } + + if (stretchGroup.cs instanceof Blosum62ColourScheme + || stretchGroup.cs instanceof PIDColourScheme + || stretchGroup.cs.conservationApplied() + || stretchGroup.cs.getThreshold() > 0) + { + stretchGroup.recalcConservation(); + } + + if (stretchGroup.cs.conservationApplied()) + { + SliderPanel.setConservationSlider(ap, stretchGroup.cs, + stretchGroup.getName()); + stretchGroup.recalcConservation(); + } + else + { + SliderPanel.setPIDSliderSource(ap, stretchGroup.cs, + stretchGroup.getName()); + } + } + changeEndRes = false; + changeStartRes = false; + stretchGroup = null; + PaintRefresher.Refresh(ap, av.getSequenceSetId()); + ap.paintAlignment(true); + } + + public void doMouseDraggedDefineMode(MouseEvent evt) + { + int res = findRes(evt); + int y = findSeq(evt); + + if (wrappedBlock != startWrapBlock) + { + return; + } + + if (stretchGroup == null) + { + return; + } + + mouseDragging = true; + + if (y > av.alignment.getHeight()) + { + y = av.alignment.getHeight() - 1; + } + + if (res >= av.alignment.getWidth()) + { + res = av.alignment.getWidth() - 1; + } + + if (stretchGroup.getEndRes() == res) + { + // Edit end res position of selected group + changeEndRes = true; + } + else if (stretchGroup.getStartRes() == res) + { + // Edit start res position of selected group + changeStartRes = true; + } + + if (res < 0) + { + res = 0; + } + + if (changeEndRes) + { + if (res > (stretchGroup.getStartRes() - 1)) + { + stretchGroup.setEndRes(res); + } + } + else if (changeStartRes) + { + if (res < (stretchGroup.getEndRes() + 1)) + { + stretchGroup.setStartRes(res); + } + } + + int dragDirection = 0; + + if (y > oldSeq) + { + dragDirection = 1; + } + else if (y < oldSeq) + { + dragDirection = -1; + } + + while ( (y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight())) + { + // This routine ensures we don't skip any sequences, as the + // selection is quite slow. + Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq); + + oldSeq += dragDirection; + + if (oldSeq < 0) + { + break; + } + + Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq); + + if (stretchGroup.getSequences(null).contains(nextSeq)) + { + stretchGroup.deleteSequence(seq, false); + } + else + { + if (seq != null) + { + stretchGroup.addSequence(seq, false); + } + + stretchGroup.addSequence(nextSeq, false); + } + } + + if (oldSeq < 0) + { + oldSeq = -1; + } + + if (res > av.endRes || res < av.startRes + || y < av.startSeq || y > av.endSeq) + { + mouseExited(evt); + } + + if (scrollThread != null) + { + scrollThread.setEvent(evt); + } + + seqCanvas.repaint(); + } + + public void mouseEntered(MouseEvent e) + { + if (oldSeq < 0) + { + oldSeq = 0; + } + + if (scrollThread != null) + { + scrollThread.running = false; + scrollThread = null; + } + } + + public void mouseExited(MouseEvent e) + { + if (av.getWrapAlignment()) + { + return; + } + + if (mouseDragging && scrollThread == null) + { + scrollThread = new ScrollThread(); + } + } + + 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 + { + MouseEvent evt; + boolean running = false; + public ScrollThread() + { + start(); + } + + public void setEvent(MouseEvent e) + { + evt = e; + } + + public void stopScrolling() + { + running = false; + } + + public void run() + { + running = true; + while (running) + { + + if (evt != null) + { + + if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0) + { + running = ap.scrollUp(true); + } + + if (mouseDragging && evt.getY() >= getSize().height && + av.alignment.getHeight() > av.getEndSeq()) + { + running = ap.scrollUp(false); + } + + if (mouseDragging && evt.getX() < 0) + { + running = ap.scrollRight(false); + } + + else if (mouseDragging && evt.getX() >= getSize().width) + { + running = ap.scrollRight(true); + } + } + + try + { + Thread.sleep(75); + } + catch (Exception ex) + {} + } + } + } + +} diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index c7887da..a8cd23a 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -498,14 +498,17 @@ public class AlignFrame showTranslation.setVisible( nucleotide ); conservationMenuItem.setEnabled( !nucleotide ); modifyConservation.setEnabled( !nucleotide ); - + //Remember AlignFrame always starts as protein if(!nucleotide) { calculateMenu.remove(calculateMenu.getItemCount()-2); } + setShowProductsEnabled(); } + + /** * Need to call this method when tabs are selected for multiple views, * or when loading from Jalview2XML.java @@ -3527,7 +3530,7 @@ public class AlignFrame public void actionPerformed(ActionEvent e) { - new jalview.io.DBRefFetcher( + new jalview.ws.DBRefFetcher( alignPanel.av.getSequenceSelection(), alignPanel.alignFrame).fetchDBRefs(false); } @@ -3553,8 +3556,134 @@ public class AlignFrame vs.storeJalview( chooser.getSelectedFile().getAbsolutePath(), this); } }*/ + /** + * prototype of an automatically enabled/disabled analysis function + * + */ + protected void setShowProductsEnabled() + { + SequenceI [] selection = viewport.getSequenceSelection(); + if (canShowProducts(selection, viewport.getSelectionGroup()!=null, viewport.getAlignment().getDataset())) + { + showProducts.setEnabled(true); + + } else { + showProducts.setEnabled(false); + } + } + /** + * search selection for sequence xRef products and build the + * show products menu. + * @param selection + * @param dataset + * @return true if showProducts menu should be enabled. + */ + public boolean canShowProducts(SequenceI[] selection, boolean isRegionSelection, Alignment dataset) + { + boolean showp=false; + try { + showProducts.removeAll(); + final boolean dna = viewport.getAlignment().isNucleotide(); + String[] ptypes = CrossRef.findSequenceXrefTypes(dna, selection, dataset); + //Object[] prods = CrossRef.buildXProductsList(viewport.getAlignment().isNucleotide(), selection, dataset, true); + final SequenceI[] sel = selection; + for (int t=0; ptypes!=null && t0) - { - java.util.Enumeration e = seq.getDatasetSequence().getPDBId(). - elements(); - - while (e.hasMoreElements()) - { - final PDBEntry pdb = (PDBEntry) e.nextElement(); - - menuItem = new JMenuItem(); - menuItem.setText(pdb.getId()); - menuItem.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - Vector seqs = new Vector(); - for (int i = 0; i < ap.av.alignment.getHeight(); i++) - { - Vector pdbs = ap.av.alignment.getSequenceAt(i).getDatasetSequence().getPDBId(); - if(pdbs==null) - continue; - - for(int p=0; p 1) - { - menuItem = new JMenuItem("Represent Group with " + seq.getName()); - menuItem.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - hideSequences(true); - } - }); - sequenceMenu.add(menuItem); - } - - if (ap.av.hasHiddenRows) - { - final int index = ap.av.alignment.findIndex(seq); - - if (ap.av.adjustForHiddenSeqs(index) - - ap.av.adjustForHiddenSeqs(index - 1) > 1) - { - menuItem = new JMenuItem("Reveal Sequences"); - menuItem.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - ap.av.showSequence(index); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } - } - }); - add(menuItem); - } - - menuItem = new JMenuItem("Reveal All"); - menuItem.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - ap.av.showAllHiddenSeqs(); - if (ap.overviewPanel != null) - { - ap.overviewPanel.updateOverviewImage(); - } - } - }); - - add(menuItem); - } - - } - - SequenceGroup sg = ap.av.getSelectionGroup(); - - if (sg != null) - { - groupName.setText(sg.getName()); - - if (sg.cs instanceof ZappoColourScheme) - { - zappoColour.setSelected(true); - } - else if (sg.cs instanceof TaylorColourScheme) - { - taylorColour.setSelected(true); - } - else if (sg.cs instanceof PIDColourScheme) - { - PIDColour.setSelected(true); - } - else if (sg.cs instanceof Blosum62ColourScheme) - { - BLOSUM62Colour.setSelected(true); - } - else if (sg.cs instanceof UserColourScheme) - { - userDefinedColour.setSelected(true); - } - else if (sg.cs instanceof HydrophobicColourScheme) - { - hydrophobicityColour.setSelected(true); - } - else if (sg.cs instanceof HelixColourScheme) - { - helixColour.setSelected(true); - } - else if (sg.cs instanceof StrandColourScheme) - { - strandColour.setSelected(true); - } - else if (sg.cs instanceof TurnColourScheme) - { - turnColour.setSelected(true); - } - else if (sg.cs instanceof BuriedColourScheme) - { - buriedColour.setSelected(true); - } - else if (sg.cs instanceof ClustalxColourScheme) - { - clustalColour.setSelected(true); - } - else - { - noColourmenuItem.setSelected(true); - } - - if (sg.cs != null && sg.cs.conservationApplied()) - { - conservationMenuItem.setSelected(true); - } - - showText.setSelected(sg.getDisplayText()); - showColourText.setSelected(sg.getColourText()); - showBoxes.setSelected(sg.getDisplayBoxes()); - } - else - { - groupMenu.setVisible(false); - editMenu.setVisible(false); - } - - if (!ap.av.alignment.getGroups().contains(sg)) - { - unGroupMenuItem.setVisible(false); - } - - if (seq == null) - { - sequenceMenu.setVisible(false); - structureMenu.setVisible(false); - } - - if (links != null && links.size() > 0) - { - JMenu linkMenu = new JMenu("Link"); - JMenuItem item; - for (int i = 0; i < links.size(); i++) - { - String link = links.elementAt(i).toString(); - final String label = link.substring(0, link.indexOf("|")); - item = new JMenuItem(label); - final String url; - - if (link.indexOf("$SEQUENCE_ID$") > -1) - { - String id = seq.getName(); - if (id.indexOf("|") > -1) - { - id = id.substring(id.lastIndexOf("|") + 1); - } - - url = link.substring(link.indexOf("|") + 1, - link.indexOf("$SEQUENCE_ID$")) - + id + - link.substring(link.indexOf("$SEQUENCE_ID$") + 13); - } - else - { - url = link.substring(link.lastIndexOf("|") + 1); - } - - item.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - showLink(url); - } - }); - - linkMenu.add(item); - } - if (sequence != null) - { - sequenceMenu.add(linkMenu); - } - else - { - add(linkMenu); - } - } - } - - /** - * DOCUMENT ME! - * - * @throws Exception DOCUMENT ME! - */ - private void jbInit() - throws Exception - { - groupMenu.setText("Group"); - groupMenu.setText("Selection"); - groupName.setText("Name"); - groupName.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - groupName_actionPerformed(); - } - }); - sequenceMenu.setText("Sequence"); - sequenceName.setText("Edit Name/Description"); - sequenceName.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - sequenceName_actionPerformed(); - } - }); - PIDColour.setFocusPainted(false); - unGroupMenuItem.setText("Remove Group"); - unGroupMenuItem.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - unGroupMenuItem_actionPerformed(); - } - }); - - outline.setText("Border colour"); - outline.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - outline_actionPerformed(); - } - }); - nucleotideMenuItem.setText("Nucleotide"); - nucleotideMenuItem.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - nucleotideMenuItem_actionPerformed(); - } - }); - colourMenu.setText("Group Colour"); - showBoxes.setText("Boxes"); - showBoxes.setState(true); - showBoxes.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - showBoxes_actionPerformed(); - } - }); - showText.setText("Text"); - showText.setState(true); - showText.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - showText_actionPerformed(); - } - }); - showColourText.setText("Colour Text"); - showColourText.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - showColourText_actionPerformed(); - } - }); - editMenu.setText("Edit"); - cut.setText("Cut"); - cut.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - cut_actionPerformed(); - } - }); - upperCase.setText("To Upper Case"); - upperCase.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - changeCase(e); - } - }); - copy.setText("Copy"); - copy.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - copy_actionPerformed(); - } - }); - lowerCase.setText("To Lower Case"); - lowerCase.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - changeCase(e); - } - }); - toggle.setText("Toggle Case"); - toggle.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - changeCase(e); - } - }); - pdbMenu.setText("Associate Structure with Sequence"); - pdbFromFile.setText("From File"); - pdbFromFile.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - pdbFromFile_actionPerformed(); - } - }); - enterPDB.setText("Enter PDB Id"); - enterPDB.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - enterPDB_actionPerformed(); - } - }); - discoverPDB.setText("Discover PDB ids"); - discoverPDB.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - discoverPDB_actionPerformed(); - } - }); - outputMenu.setText("Output to Textbox..."); - sequenceFeature.setText("Create Sequence Feature"); - sequenceFeature.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - sequenceFeature_actionPerformed(); - } - }); - textColour.setText("Text Colour"); - textColour.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - textColour_actionPerformed(); - } - }); - jMenu1.setText("Group"); - structureMenu.setText("Structure"); - viewStructureMenu.setText("View Structure"); - // colStructureMenu.setText("Colour By Structure"); - editSequence.setText("Edit Sequence..."); - editSequence.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent actionEvent) - { - editSequence_actionPerformed(actionEvent); - } - }); - /* annotationMenuItem.setText("By Annotation"); - annotationMenuItem.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent actionEvent) - { - annotationMenuItem_actionPerformed(actionEvent); - } - });*/ - - add(groupMenu); - - add(sequenceMenu); - this.add(structureMenu); - groupMenu.add(editMenu); - groupMenu.add(outputMenu); - groupMenu.add(sequenceFeature); - groupMenu.add(jMenu1); - sequenceMenu.add(sequenceName); - colourMenu.add(textColour); - colourMenu.add(noColourmenuItem); - colourMenu.add(clustalColour); - colourMenu.add(BLOSUM62Colour); - colourMenu.add(PIDColour); - colourMenu.add(zappoColour); - colourMenu.add(taylorColour); - colourMenu.add(hydrophobicityColour); - colourMenu.add(helixColour); - colourMenu.add(strandColour); - colourMenu.add(turnColour); - colourMenu.add(buriedColour); - colourMenu.add(nucleotideMenuItem); - colourMenu.add(userDefinedColour); - - if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null) - { - java.util.Enumeration userColours = jalview.gui.UserDefinedColours. - getUserColourSchemes().keys(); - - while (userColours.hasMoreElements()) - { - JMenuItem item = new JMenuItem(userColours. - nextElement().toString()); - item.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - userDefinedColour_actionPerformed(evt); - } - }); - colourMenu.add(item); - } - } - - colourMenu.addSeparator(); - colourMenu.add(abovePIDColour); - colourMenu.add(conservationMenuItem); - //colourMenu.add(annotationMenuItem); - editMenu.add(copy); - editMenu.add(cut); - editMenu.add(editSequence); - editMenu.add(upperCase); - editMenu.add(lowerCase); - editMenu.add(toggle); - pdbMenu.add(pdbFromFile); - pdbMenu.add(enterPDB); - pdbMenu.add(discoverPDB); - jMenu1.add(groupName); - jMenu1.add(unGroupMenuItem); - jMenu1.add(colourMenu); - jMenu1.add(showBoxes); - jMenu1.add(showText); - jMenu1.add(showColourText); - jMenu1.add(outline); - structureMenu.add(pdbMenu); - structureMenu.add(viewStructureMenu); - // structureMenu.add(colStructureMenu); - noColourmenuItem.setText("None"); - noColourmenuItem.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - noColourmenuItem_actionPerformed(); - } - }); - - clustalColour.setText("Clustalx colours"); - clustalColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - clustalColour_actionPerformed(); - } - }); - zappoColour.setText("Zappo"); - zappoColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - zappoColour_actionPerformed(); - } - }); - taylorColour.setText("Taylor"); - taylorColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - taylorColour_actionPerformed(); - } - }); - hydrophobicityColour.setText("Hydrophobicity"); - hydrophobicityColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - hydrophobicityColour_actionPerformed(); - } - }); - helixColour.setText("Helix propensity"); - helixColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - helixColour_actionPerformed(); - } - }); - strandColour.setText("Strand propensity"); - strandColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - strandColour_actionPerformed(); - } - }); - turnColour.setText("Turn propensity"); - turnColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - turnColour_actionPerformed(); - } - }); - buriedColour.setText("Buried Index"); - buriedColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - buriedColour_actionPerformed(); - } - }); - abovePIDColour.setText("Above % Identity"); - abovePIDColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - abovePIDColour_actionPerformed(); - } - }); - userDefinedColour.setText("User Defined..."); - userDefinedColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - userDefinedColour_actionPerformed(e); - } - }); - PIDColour.setText("Percentage Identity"); - PIDColour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - PIDColour_actionPerformed(); - } - }); - BLOSUM62Colour.setText("BLOSUM62"); - BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - BLOSUM62Colour_actionPerformed(); - } - }); - conservationMenuItem.setText("Conservation"); - conservationMenuItem.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(ActionEvent e) - { - conservationMenuItem_actionPerformed(); - } - }); - } - - /** - * DOCUMENT ME! - */ - void refresh() - { - ap.paintAlignment(true); - - PaintRefresher.Refresh(this, ap.av.getSequenceSetId()); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void clustalColour_actionPerformed() - { - SequenceGroup sg = getGroup(); - sg.cs = new ClustalxColourScheme(sg.getSequences(ap.av.hiddenRepSequences), - ap.av.alignment.getWidth()); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void zappoColour_actionPerformed() - { - getGroup().cs = new ZappoColourScheme(); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void taylorColour_actionPerformed() - { - getGroup().cs = new TaylorColourScheme(); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void hydrophobicityColour_actionPerformed() - { - getGroup().cs = new HydrophobicColourScheme(); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void helixColour_actionPerformed() - { - getGroup().cs = new HelixColourScheme(); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void strandColour_actionPerformed() - { - getGroup().cs = new StrandColourScheme(); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void turnColour_actionPerformed() - { - getGroup().cs = new TurnColourScheme(); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void buriedColour_actionPerformed() - { - getGroup().cs = new BuriedColourScheme(); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void nucleotideMenuItem_actionPerformed() - { - getGroup().cs = new NucleotideColourScheme(); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void abovePIDColour_actionPerformed() - { - SequenceGroup sg = getGroup(); - if (sg.cs == null) - { - return; - } - - if (abovePIDColour.isSelected()) - { - sg.cs.setConsensus(AAFrequency.calculate( - sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), - sg.getEndRes() + 1)); - - int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, - getGroup().getName()); - - sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus()); - - SliderPanel.showPIDSlider(); - } - else // remove PIDColouring - { - sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus()); - } - - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void userDefinedColour_actionPerformed(ActionEvent e) - { - SequenceGroup sg = getGroup(); - - if (e.getActionCommand().equals("User Defined...")) - { - new UserDefinedColours(ap, sg); - } - else - { - UserColourScheme udc = (UserColourScheme) UserDefinedColours. - getUserColourSchemes().get(e.getActionCommand()); - - sg.cs = udc; - } - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void PIDColour_actionPerformed() - { - SequenceGroup sg = getGroup(); - sg.cs = new PIDColourScheme(); - sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av. - hiddenRepSequences), - sg.getStartRes(), - sg.getEndRes() + 1)); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void BLOSUM62Colour_actionPerformed() - { - SequenceGroup sg = getGroup(); - - sg.cs = new Blosum62ColourScheme(); - - sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av. - hiddenRepSequences), - sg.getStartRes(), - sg.getEndRes() + 1)); - - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void noColourmenuItem_actionPerformed() - { - getGroup().cs = null; - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void conservationMenuItem_actionPerformed() - { - SequenceGroup sg = getGroup(); - if (sg.cs == null) - { - return; - } - - if (conservationMenuItem.isSelected()) - { - Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, - sg.getSequences(ap.av. - hiddenRepSequences), - sg.getStartRes(), - sg.getEndRes() + 1); - - c.calculate(); - c.verdict(false, ap.av.ConsPercGaps); - - sg.cs.setConservation(c); - - SliderPanel.setConservationSlider(ap, sg.cs, sg.getName()); - SliderPanel.showConservationSlider(); - } - else // remove ConservationColouring - { - sg.cs.setConservation(null); - } - - refresh(); - } - - public void annotationMenuItem_actionPerformed(ActionEvent actionEvent) - { - SequenceGroup sg = getGroup(); - if (sg == null) - { - return; - } - - AnnotationColourGradient acg = new AnnotationColourGradient( - sequence.getAnnotation()[0], null, AnnotationColourGradient.NO_THRESHOLD); - - acg.predefinedColours = true; - sg.cs = acg; - - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void groupName_actionPerformed() - { - - SequenceGroup sg = getGroup(); - EditNameDialog dialog = new EditNameDialog(sg.getName(), - sg.getDescription(), - " Group Name ", - "Group Description ", - "Edit Group Name/Description"); - - if (!dialog.accept) - { - return; - } - - sg.setName(dialog.getName()); - sg.setDescription(dialog.getDescription()); - } - - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - SequenceGroup getGroup() - { - SequenceGroup sg = ap.av.getSelectionGroup(); - // this method won't add a new group if it already exists - if (sg != null) - { - ap.av.alignment.addGroup(sg); - } - - return sg; - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - void sequenceName_actionPerformed() - { - EditNameDialog dialog = new EditNameDialog(sequence.getName(), - sequence.getDescription(), - " Sequence Name ", - "Sequence Description ", - "Edit Sequence Name/Description"); - - if (!dialog.accept) - { - return; - } - - if (dialog.getName() != null) - { - if (dialog.getName().indexOf(" ") > -1) - { - JOptionPane.showMessageDialog(ap, - "Spaces have been converted to \"_\"", - "No spaces allowed in Sequence Name", - JOptionPane.WARNING_MESSAGE); - } - - sequence.setName(dialog.getName().replace(' ', '_')); - ap.paintAlignment(false); - } - - sequence.setDescription(dialog.getDescription()); - - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); - - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - void unGroupMenuItem_actionPerformed() - { - SequenceGroup sg = ap.av.getSelectionGroup(); - ap.av.alignment.deleteGroup(sg); - ap.av.setSelectionGroup(null); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - protected void outline_actionPerformed() - { - SequenceGroup sg = getGroup(); - Color col = JColorChooser.showDialog(this, "Select Outline Colour", - Color.BLUE); - - if (col != null) - { - sg.setOutlineColour(col); - } - - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void showBoxes_actionPerformed() - { - getGroup().setDisplayBoxes(showBoxes.isSelected()); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void showText_actionPerformed() - { - getGroup().setDisplayText(showText.isSelected()); - refresh(); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void showColourText_actionPerformed() - { - getGroup().setColourText(showColourText.isSelected()); - refresh(); - } - - public void showLink(String url) - { - try - { - jalview.util.BrowserLauncher.openURL(url); - } - catch (Exception ex) - { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Unixers: Couldn't find default web browser." - + - "\nAdd the full path to your browser in Preferences.", - "Web browser not found", - JOptionPane.WARNING_MESSAGE); - - ex.printStackTrace(); - } - } - - void hideSequences(boolean representGroup) - { - SequenceGroup sg = ap.av.getSelectionGroup(); - if (sg == null || sg.getSize() < 1) - { - ap.av.hideSequence(new SequenceI[] - {sequence}); - return; - } - - ap.av.setSelectionGroup(null); - - if (representGroup) - { - ap.av.hideRepSequences(sequence, sg); - - return; - } - - int gsize = sg.getSize(); - SequenceI[] hseqs; - - hseqs = new SequenceI[gsize]; - - int index = 0; - for (int i = 0; i < gsize; i++) - { - hseqs[index++] = sg.getSequenceAt(i); - } - - ap.av.hideSequence(hseqs); - } - - public void copy_actionPerformed() - { - ap.alignFrame.copy_actionPerformed(null); - } - - public void cut_actionPerformed() - { - ap.alignFrame.cut_actionPerformed(null); - } - - void changeCase(ActionEvent e) - { - Object source = e.getSource(); - SequenceGroup sg = ap.av.getSelectionGroup(); - - if (sg != null) - { - int[][] startEnd = ap.av.getVisibleRegionBoundaries( - sg.getStartRes(), sg.getEndRes() + 1); - - String description; - int caseChange; - - if (source == toggle) - { - description = "Toggle Case"; - caseChange = ChangeCaseCommand.TOGGLE_CASE; - } - else if (source == upperCase) - { - description = "To Upper Case"; - caseChange = ChangeCaseCommand.TO_UPPER; - } - else - { - description = "To Lower Case"; - caseChange = ChangeCaseCommand.TO_LOWER; - } - - ChangeCaseCommand caseCommand = new ChangeCaseCommand( - description, sg.getSequencesAsArray(ap.av.hiddenRepSequences), - startEnd, caseChange - ); - - ap.alignFrame.addHistoryItem(caseCommand); - - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); - - } - } - - public void outputText_actionPerformed(ActionEvent e) - { - CutAndPasteTransfer cap = new CutAndPasteTransfer(); - cap.setForInput(null); - Desktop.addInternalFrame(cap, - "Alignment output - " + e.getActionCommand(), 600, - 500); - - String[] omitHidden = null; - - if (ap.av.hasHiddenColumns) - { - System.out.println("PROMPT USER HERE"); - omitHidden = ap.av.getViewAsString(true); - } - - cap.setText(new FormatAdapter().formatSequences( - e.getActionCommand(), - ap.av.getSelectionAsNewSequence(), - omitHidden)); - } - - public void pdbFromFile_actionPerformed() - { - jalview.io.JalviewFileChooser chooser - = new jalview.io.JalviewFileChooser(jalview.bin.Cache. - getProperty( - "LAST_DIRECTORY")); - chooser.setFileView(new jalview.io.JalviewFileView()); - chooser.setDialogTitle("Select a PDB file"); - chooser.setToolTipText("Load a PDB file"); - - int value = chooser.showOpenDialog(null); - - if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) - { - PDBEntry entry = new PDBEntry(); - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - try - { - MCview.PDBfile pdbfile = new MCview.PDBfile(choice, - jalview.io.AppletFormatAdapter.FILE); - - if (pdbfile.id == null) - { - String reply = JOptionPane.showInternalInputDialog( - Desktop.desktop, - "Couldn't find a PDB id in the file supplied." - + "Please enter an Id to identify this structure.", - "No PDB Id in File", JOptionPane.QUESTION_MESSAGE); - if (reply == null) - { - return; - } - - entry.setId(reply); - } - else - { - entry.setId(pdbfile.id); - } - } - catch (java.io.IOException ex) - { - ex.printStackTrace(); - } - - entry.setFile(choice); - sequence.getDatasetSequence().addPDBId(entry); - } - - } - - public void enterPDB_actionPerformed() - { - String id = JOptionPane.showInternalInputDialog(Desktop.desktop, - "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE); - - if (id != null && id.length() > 0) - { - PDBEntry entry = new PDBEntry(); - entry.setId(id.toUpperCase()); - sequence.getDatasetSequence() - .addPDBId(entry); - } - } - - public void discoverPDB_actionPerformed() - { - SequenceI[] sequences = - ap.av.selectionGroup == null ? - new Sequence[]{sequence} - : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment); - - new jalview.io.DBRefFetcher(sequences, - ap.alignFrame).fetchDBRefs(false); - } - - public void sequenceFeature_actionPerformed() - { - SequenceGroup sg = ap.av.getSelectionGroup(); - if (sg == null) - { - return; - } - - int gSize = sg.getSize(); - SequenceI[] seqs = new SequenceI[gSize]; - SequenceFeature[] features = new SequenceFeature[gSize]; - - for (int i = 0; i < gSize; i++) - { - seqs[i] = sg.getSequenceAt(i).getDatasetSequence(); - int start = sg.getSequenceAt(i).findPosition(sg.getStartRes()); - int end = sg.findEndRes(sg.getSequenceAt(i)); - features[i] = new SequenceFeature(null, null, null, start, end, "Jalview"); - } - - if (ap.seqPanel.seqCanvas.getFeatureRenderer() - .amendFeatures(seqs, features, true, ap)) - { - ap.alignFrame.showSeqFeatures.setSelected(true); - ap.av.setShowSequenceFeatures(true); - ap.highlightSearchResults(null); - } - } - - public void textColour_actionPerformed() - { - SequenceGroup sg = getGroup(); - if (sg != null) - { - new TextColourChooser().chooseColour(ap, sg); - } - } - - public void colourByStructure(String pdbid) - { - Annotation [] anots = jalview.structure.StructureSelectionManager.getStructureSelectionManager() - .colourSequenceFromStructure(sequence, pdbid); - - AlignmentAnnotation an = new AlignmentAnnotation( - "Structure", "Coloured by "+pdbid, anots); - - ap.av.alignment.addAnnotation(an); - an.createSequenceMapping(sequence, 0, true); - //an.adjustForAlignment(); - ap.av.alignment.setAnnotationIndex(an,0); - - ap.adjustAnnotationHeight(); - - sequence.addAlignmentAnnotation(an); - - } - - public void editSequence_actionPerformed(ActionEvent actionEvent) - { - SequenceGroup sg = ap.av.getSelectionGroup(); - - if(sg!=null) - { - if (sequence == null) - sequence = (Sequence) sg.getSequenceAt(0); - - EditNameDialog dialog = new EditNameDialog( - sequence.getSequenceAsString( - sg.getStartRes(), - sg.getEndRes() + 1), - null, - "Edit Sequence ", - null, - "Edit Sequence"); - - if (dialog.accept) - { - EditCommand editCommand = new EditCommand( - "Edit Sequences", EditCommand.REPLACE, - dialog.getName().replace(' ', ap.av.getGapCharacter()), - sg.getSequencesAsArray(ap.av.hiddenRepSequences), - sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment - ); - - ap.alignFrame.addHistoryItem(editCommand); - - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); - } - } - } - - -} +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +package jalview.gui; + +import java.util.*; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import MCview.*; +import jalview.analysis.*; +import jalview.commands.*; +import jalview.datamodel.*; +import jalview.io.*; +import jalview.schemes.*; + +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class PopupMenu + extends JPopupMenu +{ + JMenu groupMenu = new JMenu(); + JMenuItem groupName = new JMenuItem(); + protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem hydrophobicityColour = new + JRadioButtonMenuItem(); + protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem(); + protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem(); + protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem(); + protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem(); + JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem(); + protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem(); + AlignmentPanel ap; + JMenu sequenceMenu = new JMenu(); + JMenuItem sequenceName = new JMenuItem(); + Sequence sequence; + JMenuItem unGroupMenuItem = new JMenuItem(); + JMenuItem outline = new JMenuItem(); + JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem(); + JMenu colourMenu = new JMenu(); + JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem(); + JCheckBoxMenuItem showText = new JCheckBoxMenuItem(); + JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem(); + JMenu editMenu = new JMenu(); + JMenuItem cut = new JMenuItem(); + JMenuItem copy = new JMenuItem(); + JMenuItem upperCase = new JMenuItem(); + JMenuItem lowerCase = new JMenuItem(); + JMenuItem toggle = new JMenuItem(); + JMenu pdbMenu = new JMenu(); + JMenuItem pdbFromFile = new JMenuItem(); + JMenuItem enterPDB = new JMenuItem(); + JMenuItem discoverPDB = new JMenuItem(); + JMenu outputMenu = new JMenu(); + JMenuItem sequenceFeature = new JMenuItem(); + JMenuItem textColour = new JMenuItem(); + JMenu jMenu1 = new JMenu(); + JMenu structureMenu = new JMenu(); + JMenu viewStructureMenu = new JMenu(); + // JMenu colStructureMenu = new JMenu(); + JMenuItem editSequence = new JMenuItem(); + // JMenuItem annotationMenuItem = new JMenuItem(); + + /** + * Creates a new PopupMenu object. + * + * @param ap DOCUMENT ME! + * @param seq DOCUMENT ME! + */ + public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links) + { + /////////////////////////////////////////////////////////// + // If this is activated from the sequence panel, the user may want to + // edit or annotate a particular residue. Therefore display the residue menu + // + // If from the IDPanel, we must display the sequence menu + ////////////////////////////////////////////////////////// + this.ap = ap; + sequence = seq; + + ButtonGroup colours = new ButtonGroup(); + colours.add(noColourmenuItem); + colours.add(clustalColour); + colours.add(zappoColour); + colours.add(taylorColour); + colours.add(hydrophobicityColour); + colours.add(helixColour); + colours.add(strandColour); + colours.add(turnColour); + colours.add(buriedColour); + colours.add(abovePIDColour); + colours.add(userDefinedColour); + colours.add(PIDColour); + colours.add(BLOSUM62Colour); + + for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++) + { + JMenuItem item = new JMenuItem(jalview.io.FormatAdapter.WRITEABLE_FORMATS[ + i]); + + item.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + outputText_actionPerformed(e); + } + }); + + outputMenu.add(item); + } + + try + { + jbInit(); + } + catch (Exception e) + { + e.printStackTrace(); + } + + if (seq != null) + { + sequenceMenu.setText(sequence.getName()); + + JMenuItem menuItem; + if (seq.getDatasetSequence().getPDBId() != null + && seq.getDatasetSequence().getPDBId().size()>0) + { + java.util.Enumeration e = seq.getDatasetSequence().getPDBId(). + elements(); + + while (e.hasMoreElements()) + { + final PDBEntry pdb = (PDBEntry) e.nextElement(); + + menuItem = new JMenuItem(); + menuItem.setText(pdb.getId()); + menuItem.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + Vector seqs = new Vector(); + for (int i = 0; i < ap.av.alignment.getHeight(); i++) + { + Vector pdbs = ap.av.alignment.getSequenceAt(i).getDatasetSequence().getPDBId(); + if(pdbs==null) + continue; + + for(int p=0; p 1) + { + menuItem = new JMenuItem("Represent Group with " + seq.getName()); + menuItem.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + hideSequences(true); + } + }); + sequenceMenu.add(menuItem); + } + + if (ap.av.hasHiddenRows) + { + final int index = ap.av.alignment.findIndex(seq); + + if (ap.av.adjustForHiddenSeqs(index) - + ap.av.adjustForHiddenSeqs(index - 1) > 1) + { + menuItem = new JMenuItem("Reveal Sequences"); + menuItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ap.av.showSequence(index); + if (ap.overviewPanel != null) + { + ap.overviewPanel.updateOverviewImage(); + } + } + }); + add(menuItem); + } + + menuItem = new JMenuItem("Reveal All"); + menuItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ap.av.showAllHiddenSeqs(); + if (ap.overviewPanel != null) + { + ap.overviewPanel.updateOverviewImage(); + } + } + }); + + add(menuItem); + } + + } + + SequenceGroup sg = ap.av.getSelectionGroup(); + + if (sg != null) + { + groupName.setText(sg.getName()); + + if (sg.cs instanceof ZappoColourScheme) + { + zappoColour.setSelected(true); + } + else if (sg.cs instanceof TaylorColourScheme) + { + taylorColour.setSelected(true); + } + else if (sg.cs instanceof PIDColourScheme) + { + PIDColour.setSelected(true); + } + else if (sg.cs instanceof Blosum62ColourScheme) + { + BLOSUM62Colour.setSelected(true); + } + else if (sg.cs instanceof UserColourScheme) + { + userDefinedColour.setSelected(true); + } + else if (sg.cs instanceof HydrophobicColourScheme) + { + hydrophobicityColour.setSelected(true); + } + else if (sg.cs instanceof HelixColourScheme) + { + helixColour.setSelected(true); + } + else if (sg.cs instanceof StrandColourScheme) + { + strandColour.setSelected(true); + } + else if (sg.cs instanceof TurnColourScheme) + { + turnColour.setSelected(true); + } + else if (sg.cs instanceof BuriedColourScheme) + { + buriedColour.setSelected(true); + } + else if (sg.cs instanceof ClustalxColourScheme) + { + clustalColour.setSelected(true); + } + else + { + noColourmenuItem.setSelected(true); + } + + if (sg.cs != null && sg.cs.conservationApplied()) + { + conservationMenuItem.setSelected(true); + } + + showText.setSelected(sg.getDisplayText()); + showColourText.setSelected(sg.getColourText()); + showBoxes.setSelected(sg.getDisplayBoxes()); + } + else + { + groupMenu.setVisible(false); + editMenu.setVisible(false); + } + + if (!ap.av.alignment.getGroups().contains(sg)) + { + unGroupMenuItem.setVisible(false); + } + + if (seq == null) + { + sequenceMenu.setVisible(false); + structureMenu.setVisible(false); + } + + if (links != null && links.size() > 0) + { + JMenu linkMenu = new JMenu("Link"); + JMenuItem item; + for (int i = 0; i < links.size(); i++) + { + String link = links.elementAt(i).toString(); + final String label = link.substring(0, link.indexOf("|")); + item = new JMenuItem(label); + final String url; + + if (link.indexOf("$SEQUENCE_ID$") > -1) + { + String id = seq.getName(); + if (id.indexOf("|") > -1) + { + id = id.substring(id.lastIndexOf("|") + 1); + } + + url = link.substring(link.indexOf("|") + 1, + link.indexOf("$SEQUENCE_ID$")) + + id + + link.substring(link.indexOf("$SEQUENCE_ID$") + 13); + } + else + { + url = link.substring(link.lastIndexOf("|") + 1); + } + + item.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + showLink(url); + } + }); + + linkMenu.add(item); + } + if (sequence != null) + { + sequenceMenu.add(linkMenu); + } + else + { + add(linkMenu); + } + } + } + + /** + * DOCUMENT ME! + * + * @throws Exception DOCUMENT ME! + */ + private void jbInit() + throws Exception + { + groupMenu.setText("Group"); + groupMenu.setText("Selection"); + groupName.setText("Name"); + groupName.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + groupName_actionPerformed(); + } + }); + sequenceMenu.setText("Sequence"); + sequenceName.setText("Edit Name/Description"); + sequenceName.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + sequenceName_actionPerformed(); + } + }); + PIDColour.setFocusPainted(false); + unGroupMenuItem.setText("Remove Group"); + unGroupMenuItem.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + unGroupMenuItem_actionPerformed(); + } + }); + + outline.setText("Border colour"); + outline.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + outline_actionPerformed(); + } + }); + nucleotideMenuItem.setText("Nucleotide"); + nucleotideMenuItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + nucleotideMenuItem_actionPerformed(); + } + }); + colourMenu.setText("Group Colour"); + showBoxes.setText("Boxes"); + showBoxes.setState(true); + showBoxes.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + showBoxes_actionPerformed(); + } + }); + showText.setText("Text"); + showText.setState(true); + showText.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + showText_actionPerformed(); + } + }); + showColourText.setText("Colour Text"); + showColourText.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + showColourText_actionPerformed(); + } + }); + editMenu.setText("Edit"); + cut.setText("Cut"); + cut.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cut_actionPerformed(); + } + }); + upperCase.setText("To Upper Case"); + upperCase.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + changeCase(e); + } + }); + copy.setText("Copy"); + copy.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + copy_actionPerformed(); + } + }); + lowerCase.setText("To Lower Case"); + lowerCase.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + changeCase(e); + } + }); + toggle.setText("Toggle Case"); + toggle.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + changeCase(e); + } + }); + pdbMenu.setText("Associate Structure with Sequence"); + pdbFromFile.setText("From File"); + pdbFromFile.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + pdbFromFile_actionPerformed(); + } + }); + enterPDB.setText("Enter PDB Id"); + enterPDB.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + enterPDB_actionPerformed(); + } + }); + discoverPDB.setText("Discover PDB ids"); + discoverPDB.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + discoverPDB_actionPerformed(); + } + }); + outputMenu.setText("Output to Textbox..."); + sequenceFeature.setText("Create Sequence Feature"); + sequenceFeature.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + sequenceFeature_actionPerformed(); + } + }); + textColour.setText("Text Colour"); + textColour.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + textColour_actionPerformed(); + } + }); + jMenu1.setText("Group"); + structureMenu.setText("Structure"); + viewStructureMenu.setText("View Structure"); + // colStructureMenu.setText("Colour By Structure"); + editSequence.setText("Edit Sequence..."); + editSequence.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent actionEvent) + { + editSequence_actionPerformed(actionEvent); + } + }); + /* annotationMenuItem.setText("By Annotation"); + annotationMenuItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent actionEvent) + { + annotationMenuItem_actionPerformed(actionEvent); + } + });*/ + + add(groupMenu); + + add(sequenceMenu); + this.add(structureMenu); + groupMenu.add(editMenu); + groupMenu.add(outputMenu); + groupMenu.add(sequenceFeature); + groupMenu.add(jMenu1); + sequenceMenu.add(sequenceName); + colourMenu.add(textColour); + colourMenu.add(noColourmenuItem); + colourMenu.add(clustalColour); + colourMenu.add(BLOSUM62Colour); + colourMenu.add(PIDColour); + colourMenu.add(zappoColour); + colourMenu.add(taylorColour); + colourMenu.add(hydrophobicityColour); + colourMenu.add(helixColour); + colourMenu.add(strandColour); + colourMenu.add(turnColour); + colourMenu.add(buriedColour); + colourMenu.add(nucleotideMenuItem); + colourMenu.add(userDefinedColour); + + if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null) + { + java.util.Enumeration userColours = jalview.gui.UserDefinedColours. + getUserColourSchemes().keys(); + + while (userColours.hasMoreElements()) + { + JMenuItem item = new JMenuItem(userColours. + nextElement().toString()); + item.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + userDefinedColour_actionPerformed(evt); + } + }); + colourMenu.add(item); + } + } + + colourMenu.addSeparator(); + colourMenu.add(abovePIDColour); + colourMenu.add(conservationMenuItem); + //colourMenu.add(annotationMenuItem); + editMenu.add(copy); + editMenu.add(cut); + editMenu.add(editSequence); + editMenu.add(upperCase); + editMenu.add(lowerCase); + editMenu.add(toggle); + pdbMenu.add(pdbFromFile); + pdbMenu.add(enterPDB); + pdbMenu.add(discoverPDB); + jMenu1.add(groupName); + jMenu1.add(unGroupMenuItem); + jMenu1.add(colourMenu); + jMenu1.add(showBoxes); + jMenu1.add(showText); + jMenu1.add(showColourText); + jMenu1.add(outline); + structureMenu.add(pdbMenu); + structureMenu.add(viewStructureMenu); + // structureMenu.add(colStructureMenu); + noColourmenuItem.setText("None"); + noColourmenuItem.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + noColourmenuItem_actionPerformed(); + } + }); + + clustalColour.setText("Clustalx colours"); + clustalColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + clustalColour_actionPerformed(); + } + }); + zappoColour.setText("Zappo"); + zappoColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + zappoColour_actionPerformed(); + } + }); + taylorColour.setText("Taylor"); + taylorColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + taylorColour_actionPerformed(); + } + }); + hydrophobicityColour.setText("Hydrophobicity"); + hydrophobicityColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + hydrophobicityColour_actionPerformed(); + } + }); + helixColour.setText("Helix propensity"); + helixColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + helixColour_actionPerformed(); + } + }); + strandColour.setText("Strand propensity"); + strandColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + strandColour_actionPerformed(); + } + }); + turnColour.setText("Turn propensity"); + turnColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + turnColour_actionPerformed(); + } + }); + buriedColour.setText("Buried Index"); + buriedColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + buriedColour_actionPerformed(); + } + }); + abovePIDColour.setText("Above % Identity"); + abovePIDColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + abovePIDColour_actionPerformed(); + } + }); + userDefinedColour.setText("User Defined..."); + userDefinedColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + userDefinedColour_actionPerformed(e); + } + }); + PIDColour.setText("Percentage Identity"); + PIDColour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + PIDColour_actionPerformed(); + } + }); + BLOSUM62Colour.setText("BLOSUM62"); + BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + BLOSUM62Colour_actionPerformed(); + } + }); + conservationMenuItem.setText("Conservation"); + conservationMenuItem.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + conservationMenuItem_actionPerformed(); + } + }); + } + + /** + * DOCUMENT ME! + */ + void refresh() + { + ap.paintAlignment(true); + + PaintRefresher.Refresh(this, ap.av.getSequenceSetId()); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void clustalColour_actionPerformed() + { + SequenceGroup sg = getGroup(); + sg.cs = new ClustalxColourScheme(sg.getSequences(ap.av.hiddenRepSequences), + ap.av.alignment.getWidth()); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void zappoColour_actionPerformed() + { + getGroup().cs = new ZappoColourScheme(); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void taylorColour_actionPerformed() + { + getGroup().cs = new TaylorColourScheme(); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void hydrophobicityColour_actionPerformed() + { + getGroup().cs = new HydrophobicColourScheme(); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void helixColour_actionPerformed() + { + getGroup().cs = new HelixColourScheme(); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void strandColour_actionPerformed() + { + getGroup().cs = new StrandColourScheme(); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void turnColour_actionPerformed() + { + getGroup().cs = new TurnColourScheme(); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void buriedColour_actionPerformed() + { + getGroup().cs = new BuriedColourScheme(); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void nucleotideMenuItem_actionPerformed() + { + getGroup().cs = new NucleotideColourScheme(); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void abovePIDColour_actionPerformed() + { + SequenceGroup sg = getGroup(); + if (sg.cs == null) + { + return; + } + + if (abovePIDColour.isSelected()) + { + sg.cs.setConsensus(AAFrequency.calculate( + sg.getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), + sg.getEndRes() + 1)); + + int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, + getGroup().getName()); + + sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus()); + + SliderPanel.showPIDSlider(); + } + else // remove PIDColouring + { + sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus()); + } + + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void userDefinedColour_actionPerformed(ActionEvent e) + { + SequenceGroup sg = getGroup(); + + if (e.getActionCommand().equals("User Defined...")) + { + new UserDefinedColours(ap, sg); + } + else + { + UserColourScheme udc = (UserColourScheme) UserDefinedColours. + getUserColourSchemes().get(e.getActionCommand()); + + sg.cs = udc; + } + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void PIDColour_actionPerformed() + { + SequenceGroup sg = getGroup(); + sg.cs = new PIDColourScheme(); + sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av. + hiddenRepSequences), + sg.getStartRes(), + sg.getEndRes() + 1)); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void BLOSUM62Colour_actionPerformed() + { + SequenceGroup sg = getGroup(); + + sg.cs = new Blosum62ColourScheme(); + + sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av. + hiddenRepSequences), + sg.getStartRes(), + sg.getEndRes() + 1)); + + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void noColourmenuItem_actionPerformed() + { + getGroup().cs = null; + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void conservationMenuItem_actionPerformed() + { + SequenceGroup sg = getGroup(); + if (sg.cs == null) + { + return; + } + + if (conservationMenuItem.isSelected()) + { + Conservation c = new Conservation("Group", + ResidueProperties.propHash, 3, + sg.getSequences(ap.av. + hiddenRepSequences), + sg.getStartRes(), + sg.getEndRes() + 1); + + c.calculate(); + c.verdict(false, ap.av.ConsPercGaps); + + sg.cs.setConservation(c); + + SliderPanel.setConservationSlider(ap, sg.cs, sg.getName()); + SliderPanel.showConservationSlider(); + } + else // remove ConservationColouring + { + sg.cs.setConservation(null); + } + + refresh(); + } + + public void annotationMenuItem_actionPerformed(ActionEvent actionEvent) + { + SequenceGroup sg = getGroup(); + if (sg == null) + { + return; + } + + AnnotationColourGradient acg = new AnnotationColourGradient( + sequence.getAnnotation()[0], null, AnnotationColourGradient.NO_THRESHOLD); + + acg.predefinedColours = true; + sg.cs = acg; + + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void groupName_actionPerformed() + { + + SequenceGroup sg = getGroup(); + EditNameDialog dialog = new EditNameDialog(sg.getName(), + sg.getDescription(), + " Group Name ", + "Group Description ", + "Edit Group Name/Description"); + + if (!dialog.accept) + { + return; + } + + sg.setName(dialog.getName()); + sg.setDescription(dialog.getDescription()); + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + SequenceGroup getGroup() + { + SequenceGroup sg = ap.av.getSelectionGroup(); + // this method won't add a new group if it already exists + if (sg != null) + { + ap.av.alignment.addGroup(sg); + } + + return sg; + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + void sequenceName_actionPerformed() + { + EditNameDialog dialog = new EditNameDialog(sequence.getName(), + sequence.getDescription(), + " Sequence Name ", + "Sequence Description ", + "Edit Sequence Name/Description"); + + if (!dialog.accept) + { + return; + } + + if (dialog.getName() != null) + { + if (dialog.getName().indexOf(" ") > -1) + { + JOptionPane.showMessageDialog(ap, + "Spaces have been converted to \"_\"", + "No spaces allowed in Sequence Name", + JOptionPane.WARNING_MESSAGE); + } + + sequence.setName(dialog.getName().replace(' ', '_')); + ap.paintAlignment(false); + } + + sequence.setDescription(dialog.getDescription()); + + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); + + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + void unGroupMenuItem_actionPerformed() + { + SequenceGroup sg = ap.av.getSelectionGroup(); + ap.av.alignment.deleteGroup(sg); + ap.av.setSelectionGroup(null); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void outline_actionPerformed() + { + SequenceGroup sg = getGroup(); + Color col = JColorChooser.showDialog(this, "Select Outline Colour", + Color.BLUE); + + if (col != null) + { + sg.setOutlineColour(col); + } + + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void showBoxes_actionPerformed() + { + getGroup().setDisplayBoxes(showBoxes.isSelected()); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void showText_actionPerformed() + { + getGroup().setDisplayText(showText.isSelected()); + refresh(); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void showColourText_actionPerformed() + { + getGroup().setColourText(showColourText.isSelected()); + refresh(); + } + + public void showLink(String url) + { + try + { + jalview.util.BrowserLauncher.openURL(url); + } + catch (Exception ex) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + "Unixers: Couldn't find default web browser." + + + "\nAdd the full path to your browser in Preferences.", + "Web browser not found", + JOptionPane.WARNING_MESSAGE); + + ex.printStackTrace(); + } + } + + void hideSequences(boolean representGroup) + { + SequenceGroup sg = ap.av.getSelectionGroup(); + if (sg == null || sg.getSize() < 1) + { + ap.av.hideSequence(new SequenceI[] + {sequence}); + return; + } + + ap.av.setSelectionGroup(null); + + if (representGroup) + { + ap.av.hideRepSequences(sequence, sg); + + return; + } + + int gsize = sg.getSize(); + SequenceI[] hseqs; + + hseqs = new SequenceI[gsize]; + + int index = 0; + for (int i = 0; i < gsize; i++) + { + hseqs[index++] = sg.getSequenceAt(i); + } + + ap.av.hideSequence(hseqs); + } + + public void copy_actionPerformed() + { + ap.alignFrame.copy_actionPerformed(null); + } + + public void cut_actionPerformed() + { + ap.alignFrame.cut_actionPerformed(null); + } + + void changeCase(ActionEvent e) + { + Object source = e.getSource(); + SequenceGroup sg = ap.av.getSelectionGroup(); + + if (sg != null) + { + int[][] startEnd = ap.av.getVisibleRegionBoundaries( + sg.getStartRes(), sg.getEndRes() + 1); + + String description; + int caseChange; + + if (source == toggle) + { + description = "Toggle Case"; + caseChange = ChangeCaseCommand.TOGGLE_CASE; + } + else if (source == upperCase) + { + description = "To Upper Case"; + caseChange = ChangeCaseCommand.TO_UPPER; + } + else + { + description = "To Lower Case"; + caseChange = ChangeCaseCommand.TO_LOWER; + } + + ChangeCaseCommand caseCommand = new ChangeCaseCommand( + description, sg.getSequencesAsArray(ap.av.hiddenRepSequences), + startEnd, caseChange + ); + + ap.alignFrame.addHistoryItem(caseCommand); + + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); + + } + } + + public void outputText_actionPerformed(ActionEvent e) + { + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + cap.setForInput(null); + Desktop.addInternalFrame(cap, + "Alignment output - " + e.getActionCommand(), 600, + 500); + + String[] omitHidden = null; + + if (ap.av.hasHiddenColumns) + { + System.out.println("PROMPT USER HERE"); + omitHidden = ap.av.getViewAsString(true); + } + + cap.setText(new FormatAdapter().formatSequences( + e.getActionCommand(), + ap.av.getSelectionAsNewSequence(), + omitHidden)); + } + + public void pdbFromFile_actionPerformed() + { + jalview.io.JalviewFileChooser chooser + = new jalview.io.JalviewFileChooser(jalview.bin.Cache. + getProperty( + "LAST_DIRECTORY")); + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle("Select a PDB file"); + chooser.setToolTipText("Load a PDB file"); + + int value = chooser.showOpenDialog(null); + + if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) + { + PDBEntry entry = new PDBEntry(); + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + try + { + MCview.PDBfile pdbfile = new MCview.PDBfile(choice, + jalview.io.AppletFormatAdapter.FILE); + + if (pdbfile.id == null) + { + String reply = JOptionPane.showInternalInputDialog( + Desktop.desktop, + "Couldn't find a PDB id in the file supplied." + + "Please enter an Id to identify this structure.", + "No PDB Id in File", JOptionPane.QUESTION_MESSAGE); + if (reply == null) + { + return; + } + + entry.setId(reply); + } + else + { + entry.setId(pdbfile.id); + } + } + catch (java.io.IOException ex) + { + ex.printStackTrace(); + } + + entry.setFile(choice); + sequence.getDatasetSequence().addPDBId(entry); + } + + } + + public void enterPDB_actionPerformed() + { + String id = JOptionPane.showInternalInputDialog(Desktop.desktop, + "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE); + + if (id != null && id.length() > 0) + { + PDBEntry entry = new PDBEntry(); + entry.setId(id.toUpperCase()); + sequence.getDatasetSequence() + .addPDBId(entry); + } + } + + public void discoverPDB_actionPerformed() + { + SequenceI[] sequences = + ap.av.selectionGroup == null ? + new Sequence[]{sequence} + : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment); + + new jalview.ws.DBRefFetcher(sequences, + ap.alignFrame).fetchDBRefs(false); + } + + public void sequenceFeature_actionPerformed() + { + SequenceGroup sg = ap.av.getSelectionGroup(); + if (sg == null) + { + return; + } + + int gSize = sg.getSize(); + SequenceI[] seqs = new SequenceI[gSize]; + SequenceFeature[] features = new SequenceFeature[gSize]; + + for (int i = 0; i < gSize; i++) + { + seqs[i] = sg.getSequenceAt(i).getDatasetSequence(); + int start = sg.getSequenceAt(i).findPosition(sg.getStartRes()); + int end = sg.findEndRes(sg.getSequenceAt(i)); + features[i] = new SequenceFeature(null, null, null, start, end, "Jalview"); + } + + if (ap.seqPanel.seqCanvas.getFeatureRenderer() + .amendFeatures(seqs, features, true, ap)) + { + ap.alignFrame.showSeqFeatures.setSelected(true); + ap.av.setShowSequenceFeatures(true); + ap.highlightSearchResults(null); + } + } + + public void textColour_actionPerformed() + { + SequenceGroup sg = getGroup(); + if (sg != null) + { + new TextColourChooser().chooseColour(ap, sg); + } + } + + public void colourByStructure(String pdbid) + { + Annotation [] anots = jalview.structure.StructureSelectionManager.getStructureSelectionManager() + .colourSequenceFromStructure(sequence, pdbid); + + AlignmentAnnotation an = new AlignmentAnnotation( + "Structure", "Coloured by "+pdbid, anots); + + ap.av.alignment.addAnnotation(an); + an.createSequenceMapping(sequence, 0, true); + //an.adjustForAlignment(); + ap.av.alignment.setAnnotationIndex(an,0); + + ap.adjustAnnotationHeight(); + + sequence.addAlignmentAnnotation(an); + + } + + public void editSequence_actionPerformed(ActionEvent actionEvent) + { + SequenceGroup sg = ap.av.getSelectionGroup(); + + if(sg!=null) + { + if (sequence == null) + sequence = (Sequence) sg.getSequenceAt(0); + + EditNameDialog dialog = new EditNameDialog( + sequence.getSequenceAsString( + sg.getStartRes(), + sg.getEndRes() + 1), + null, + "Edit Sequence ", + null, + "Edit Sequence"); + + if (dialog.accept) + { + EditCommand editCommand = new EditCommand( + "Edit Sequences", EditCommand.REPLACE, + dialog.getName().replace(' ', ap.av.getGapCharacter()), + sg.getSequencesAsArray(ap.av.hiddenRepSequences), + sg.getStartRes(), sg.getEndRes() + 1, ap.av.alignment + ); + + ap.alignFrame.addHistoryItem(editCommand); + + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); + } + } + } + + +} diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index dc326de..7d451da 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -572,14 +572,14 @@ public class SeqPanel } String lastMessage; - public void mouseOverSequence(SequenceI sequence, int index) + public void mouseOverSequence(SequenceI sequence, int index, int pos) { - String tmp = sequence.hashCode()+" "+index+""; + String tmp = sequence.hashCode()+" "+index+" "+pos; if (lastMessage == null || !lastMessage.equals(tmp)) { // System.err.println("mouseOver Sequence: "+tmp); - ssm.mouseOverSequence(sequence, index); + ssm.mouseOverSequence(sequence, index, pos); } lastMessage = tmp; } @@ -627,7 +627,7 @@ public class SeqPanel pos = setStatusMessage(sequence, res, seq); if (ssm != null && pos>-1) - mouseOverSequence(sequence, pos); + mouseOverSequence(sequence, res, pos); tooltipText.setLength(6); // Cuts the buffer back to diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 989227b..10e1b59 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -1,581 +1,604 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 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 - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ -package jalview.gui; - -import java.io.*; -import java.util.*; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; - -import MCview.*; -import jalview.datamodel.*; -import jalview.datamodel.xdb.embl.*; -import java.io.File; -import jalview.io.*; -import java.awt.Rectangle; -import java.awt.BorderLayout; -import java.awt.Dimension; - -public class SequenceFetcher -extends JPanel implements Runnable -{ - JInternalFrame frame; - AlignFrame alignFrame; - StringBuffer result; - final String noDbSelected = "-- Select Database --"; - public SequenceFetcher(AlignFrame af) - { - alignFrame = af; - database.addItem(noDbSelected); - database.addItem("Uniprot"); - database.addItem("EMBL"); - database.addItem("EMBLCDS"); - database.addItem("PDB"); - database.addItem("PFAM"); - - try - { - jbInit(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - - frame = new JInternalFrame(); - frame.setContentPane(this); - if (System.getProperty("os.name").startsWith("Mac")) - { - Desktop.addInternalFrame(frame, getFrameTitle(), 400, 140); - } - else - { - Desktop.addInternalFrame(frame, getFrameTitle(), 400, 125); - } - } - - private String getFrameTitle() - { - return ( (alignFrame == null) ? "New " : "Additional ") + - "Sequence Fetcher"; - } - - private void jbInit() - throws Exception - { - this.setLayout(borderLayout2); - - database.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - jLabel1.setFont(new java.awt.Font("Verdana", Font.ITALIC, 11)); - jLabel1.setHorizontalAlignment(SwingConstants.CENTER); - jLabel1.setText( - "Separate multiple accession ids with semi colon \";\""); - ok.setText("OK"); - ok.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - ok_actionPerformed(); - } - }); - close.setText("Close"); - close.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - close_actionPerformed(e); - } - }); - textArea.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - textArea.setLineWrap(true); - textArea.addKeyListener(new KeyAdapter() - { - public void keyPressed(KeyEvent e) - { - if(e.getKeyCode()==KeyEvent.VK_ENTER) - ok_actionPerformed(); - } - }); - jPanel3.setLayout(borderLayout1); - borderLayout1.setVgap(5); - jPanel1.add(ok); - jPanel1.add(close); - jPanel3.add(jPanel2, java.awt.BorderLayout.WEST); - jPanel2.add(database); - jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER); - jPanel3.add(jLabel1, java.awt.BorderLayout.NORTH); - this.add(jPanel1, java.awt.BorderLayout.SOUTH); - this.add(jPanel3, java.awt.BorderLayout.CENTER); - jScrollPane1.getViewport().add(textArea); - - } - - JComboBox database = new JComboBox(); - JLabel jLabel1 = new JLabel(); - JButton ok = new JButton(); - JButton close = new JButton(); - JPanel jPanel1 = new JPanel(); - JTextArea textArea = new JTextArea(); - JScrollPane jScrollPane1 = new JScrollPane(); - JPanel jPanel2 = new JPanel(); - JPanel jPanel3 = new JPanel(); - BorderLayout borderLayout1 = new BorderLayout(); - BorderLayout borderLayout2 = new BorderLayout(); - public void close_actionPerformed(ActionEvent e) - { - try - { - frame.setClosed(true); - } - catch (Exception ex) - {} - } - - public void ok_actionPerformed() - { - database.setEnabled(false); - textArea.setEnabled(false); - ok.setEnabled(false); - close.setEnabled(false); - - Thread worker = new Thread(this); - worker.start(); - } - - private void resetDialog() - { - database.setEnabled(true); - textArea.setEnabled(true); - ok.setEnabled(true); - close.setEnabled(true); - } - - public void run() - { - String error = ""; - if (database.getSelectedItem().equals(noDbSelected)) - { - error += "Please select the source database\n"; - } - com.stevesoft.pat.Regex empty = new com.stevesoft.pat.Regex("\\s+", ""); - textArea.setText(empty.replaceAll(textArea.getText())); - if (textArea.getText().length() == 0) - { - error += "Please enter a (semi-colon separated list of) database id(s)"; - } - if (error.length() > 0) - { - showErrorMessage(error); - resetDialog(); - return; - } - - result = new StringBuffer(); - if (database.getSelectedItem().equals("Uniprot")) - { - getUniprotFile(textArea.getText()); - } - else if (database.getSelectedItem().equals("EMBL") - || database.getSelectedItem().equals("EMBLCDS")) - { - String DBRefSource = database.getSelectedItem().equals("EMBLCDS") - ? jalview.datamodel.DBRefSource.EMBLCDS - : jalview.datamodel.DBRefSource.EMBL; - - StringTokenizer st = new StringTokenizer(textArea.getText(), ";"); - SequenceI[] seqs = null; - while(st.hasMoreTokens()) - { - EBIFetchClient dbFetch = new EBIFetchClient(); - - File reply = dbFetch.fetchDataAsFile( - database.getSelectedItem().toString().toLowerCase( - ) + ":" + st.nextToken(), - "emblxml",null); - - jalview.datamodel.xdb.embl.EmblFile efile=null; - if (reply != null && reply.exists()) - { - efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply); - } - if (efile!=null) { - for (Iterator i=efile.getEntries().iterator(); i.hasNext(); ) { - EmblEntry entry = (EmblEntry) i.next(); - SequenceI[] seqparts = entry.getSequences(false,true, DBRefSource); - if (seqparts!=null) { - SequenceI[] newseqs = null; - int si=0; - if (seqs==null) { - newseqs = new SequenceI[seqparts.length]; - } else { - newseqs = new SequenceI[seqs.length+seqparts.length]; - - for (;si0) { - if (parseResult(new Alignment(seqs), null, null)!=null) - result.append("# Successfully parsed the "+database.getSelectedItem()+" Queries into an Alignment"); - } - } - else if (database.getSelectedItem().equals("PDB")) - { - StringTokenizer qset = new StringTokenizer(textArea.getText(), ";"); - String query; - SequenceI[] seqs = null; - while (qset.hasMoreTokens() && ((query = qset.nextToken())!=null)) - { - SequenceI[] seqparts = getPDBFile(query.toUpperCase()); - if (seqparts != null) - { - if (seqs == null) - { - seqs = seqparts; - } - else - { - SequenceI[] newseqs = new SequenceI[seqs.length+seqparts.length]; - int i=0; - for (; i < seqs.length; i++) - { - newseqs[i] = seqs[i]; - seqs[i] = null; - } - for (int j=0;j 0) - { - if (parseResult(new Alignment(seqs), null, null)!=null) - { - result.append( - "# Successfully parsed the PDB File Queries into an Alignment"); - } - } - } - else if( database.getSelectedItem().equals("PFAM")) - { - try - { - result.append(new FastaFile( - "http://www.sanger.ac.uk/cgi-bin/Pfam/getalignment.pl?format=fal&acc=" - + textArea.getText().toUpperCase(), "URL").print() - ); - - if(result.length()>0) - { - parseResult( result.toString(), textArea.getText().toUpperCase() ); - } - - } - catch (java.io.IOException ex) - { - result = null; - } - } - - if (result == null || result.length() == 0) - { - showErrorMessage("Error retrieving " + textArea.getText() - + " from " + database.getSelectedItem()); - } - - resetDialog(); - return; - } - - void getUniprotFile(String id) - { - EBIFetchClient ebi = new EBIFetchClient(); - File file = ebi.fetchDataAsFile("uniprot:" + id, "xml", null); - - DBRefFetcher dbref = new DBRefFetcher(); - Vector entries = dbref.getUniprotEntries(file); - - if (entries != null) - { - //First, make the new sequences - Enumeration en = entries.elements(); - while (en.hasMoreElements()) - { - UniprotEntry entry = (UniprotEntry) en.nextElement(); - - StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot"); - Enumeration en2 = entry.getAccession().elements(); - while (en2.hasMoreElements()) - { - name.append("|"); - name.append(en2.nextElement()); - } - en2 = entry.getName().elements(); - while (en2.hasMoreElements()) - { - name.append("|"); - name.append(en2.nextElement()); - } - - if (entry.getProtein() != null) - { - name.append(" " + entry.getProtein().getName().elementAt(0)); - } - - result.append(name + "\n" + entry.getUniprotSequence().getContent() + - "\n"); - - } - - //Then read in the features and apply them to the dataset - Alignment al = parseResult(result.toString(), null); - for (int i = 0; i < entries.size(); i++) - { - UniprotEntry entry = (UniprotEntry) entries.elementAt(i); - Enumeration e = entry.getDbReference().elements(); - Vector onlyPdbEntries = new Vector(); - while (e.hasMoreElements()) - { - PDBEntry pdb = (PDBEntry) e.nextElement(); - if (!pdb.getType().equals("PDB")) - { - continue; - } - - onlyPdbEntries.addElement(pdb); - } - - Enumeration en2 = entry.getAccession().elements(); - while (en2.hasMoreElements()) - { - al.getSequenceAt(i).getDatasetSequence().addDBRef(new DBRefEntry( - DBRefSource.UNIPROT, - "0", - en2.nextElement().toString())); - } - - - - - al.getSequenceAt(i).getDatasetSequence().setPDBId(onlyPdbEntries); - if (entry.getFeature() != null) - { - e = entry.getFeature().elements(); - while (e.hasMoreElements()) - { - SequenceFeature sf = (SequenceFeature) e.nextElement(); - sf.setFeatureGroup("Uniprot"); - al.getSequenceAt(i).getDatasetSequence().addSequenceFeature( sf ); - } - } - } - } - } - - SequenceI[] getPDBFile(String id) - { - Vector result = new Vector(); - String chain = null; - if (id.indexOf(":") > -1) - { - chain = id.substring(id.indexOf(":") + 1); - id = id.substring(0, id.indexOf(":")); - } - - EBIFetchClient ebi = new EBIFetchClient(); - String file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw"). - getAbsolutePath(); - if (file == null) - { - return null; - } - try - { - PDBfile pdbfile = new PDBfile(file, jalview.io.AppletFormatAdapter.FILE); - for (int i = 0; i < pdbfile.chains.size(); i++) - { - if (chain == null || - ( (PDBChain) pdbfile.chains.elementAt(i)).id. - toUpperCase().equals(chain)) - { - PDBChain pdbchain = (PDBChain) pdbfile.chains.elementAt(i); - // Get the Chain's Sequence - who's dataset includes any special features added from the PDB file - SequenceI sq = pdbchain.sequence; - // Specially formatted name for the PDB chain sequences retrieved from the PDB - sq.setName("PDB|"+id+"|"+sq.getName()); - // Might need to add more metadata to the PDBEntry object - // like below - /* - * PDBEntry entry = new PDBEntry(); - // Construct the PDBEntry - entry.setId(id); - if (entry.getProperty() == null) - entry.setProperty(new Hashtable()); - entry.getProperty().put("chains", - pdbchain.id - + "=" + sq.getStart() - + "-" + sq.getEnd()); - sq.getDatasetSequence().addPDBId(entry); - */ - // Add PDB DB Refs - // We make a DBRefEtntry because we have obtained the PDB file from a verifiable source - // JBPNote - PDB DBRefEntry should also carry the chain and mapping information - DBRefEntry dbentry = new DBRefEntry(jalview.datamodel.DBRefSource.PDB, - "0", id + pdbchain.id); - sq.addDBRef(dbentry); - // and add seuqence to the retrieved set - result.addElement(sq.deriveSequence()); - } - } - - if (result.size() < 1) - { - throw new Exception("WsDBFetch for PDB id resulted in zero result size"); - } - } - catch (Exception ex) // Problem parsing PDB file - { - jalview.bin.Cache.log.warn("Exception when retrieving " + - textArea.getText() + " from " + - database.getSelectedItem(), ex); - return null; - } - - - SequenceI[] results = new SequenceI[result.size()]; - for (int i = 0, j = result.size(); i < j; i++) - { - results[i] = (SequenceI) result.elementAt(i); - result.setElementAt(null,i); - } - return results; - } - Alignment parseResult(String result, String title) - { - String format = new IdentifyFile().Identify(result, "Paste"); - Alignment sequences = null; - if (FormatAdapter.isValidFormat(format)) - { - sequences = null; - try - { - sequences = new FormatAdapter().readFile(result.toString(), "Paste", - format); - } - catch (Exception ex) - {} - - if (sequences!=null) - { - return parseResult(sequences, title, format); - } - } - else - { - showErrorMessage("Error retrieving " + textArea.getText() - + " from " + database.getSelectedItem()); - } - - return null; - } - - Alignment parseResult(Alignment al, String title, String currentFileFormat) - { - - if (al != null && al.getHeight() > 0) - { - if (alignFrame == null) - { - AlignFrame af = new AlignFrame(al, - AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT); - if (currentFileFormat!=null) - { - af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT FORMAT FOR NON-FormatAdapter Sourced Alignments? - } - - if(title==null) - { - title = "Retrieved from " + database.getSelectedItem(); - } - - Desktop.addInternalFrame(af, - title, - AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT); - - af.statusBar.setText("Successfully pasted alignment file"); - - try - { - af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); - } - catch (Exception ex) - {} - } - else - { - for (int i = 0; i < al.getHeight(); i++) - { - alignFrame.viewport.alignment.addSequence(al.getSequenceAt(i)); // this also creates dataset sequence entries - } - alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment. - getHeight()); - alignFrame.viewport.alignment.getWidth(); - alignFrame.viewport.firePropertyChange("alignment", null, - alignFrame.viewport. - getAlignment().getSequences()); - } - } - return al; - } - - void showErrorMessage(final String error) - { - resetDialog(); - javax.swing.SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - error, "Error Retrieving Data", - JOptionPane.WARNING_MESSAGE); - } - }); - } -} - +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +package jalview.gui; + +import java.io.*; +import java.util.*; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import MCview.*; +import jalview.datamodel.*; +import jalview.datamodel.xdb.embl.*; +import java.io.File; +import jalview.io.*; +import jalview.ws.DBRefFetcher; +import jalview.ws.EBIFetchClient; + +import java.awt.Rectangle; +import java.awt.BorderLayout; +import java.awt.Dimension; + +public class SequenceFetcher +extends JPanel implements Runnable +{ + jalview.ws.SequenceFetcher sfetch; + JInternalFrame frame; + AlignFrame alignFrame; + StringBuffer result; + final String noDbSelected = "-- Select Database --"; + public SequenceFetcher(AlignFrame af) + { + alignFrame = af; + sfetch = new jalview.ws.SequenceFetcher(); + database.addItem(noDbSelected); + /* + * Dynamically generated database list + * will need a translation function from + * internal source to externally distinct names. + * UNIPROT and UP_NAME are identical DB sources, + * and should be collapsed. + * + + String dbs[] = sfetch.getSupportedDb(); + for (int i=0; i 0) + { + showErrorMessage(error); + resetDialog(); + return; + } + + result = new StringBuffer(); + if (database.getSelectedItem().equals("Uniprot")) + { + getUniprotFile(textArea.getText()); + } + else if (database.getSelectedItem().equals("EMBL") + || database.getSelectedItem().equals("EMBLCDS")) + { + String DBRefSource = database.getSelectedItem().equals("EMBLCDS") + ? jalview.datamodel.DBRefSource.EMBLCDS + : jalview.datamodel.DBRefSource.EMBL; + + StringTokenizer st = new StringTokenizer(textArea.getText(), ";"); + SequenceI[] seqs = null; + while(st.hasMoreTokens()) + { + EBIFetchClient dbFetch = new EBIFetchClient(); + + File reply = dbFetch.fetchDataAsFile( + database.getSelectedItem().toString().toLowerCase( + ) + ":" + st.nextToken(), + "emblxml",null); + + jalview.datamodel.xdb.embl.EmblFile efile=null; + if (reply != null && reply.exists()) + { + efile = jalview.datamodel.xdb.embl.EmblFile.getEmblFile(reply); + } + if (efile!=null) { + for (Iterator i=efile.getEntries().iterator(); i.hasNext(); ) { + EmblEntry entry = (EmblEntry) i.next(); + SequenceI[] seqparts = entry.getSequences(false,true, DBRefSource); + if (seqparts!=null) { + SequenceI[] newseqs = null; + int si=0; + if (seqs==null) { + newseqs = new SequenceI[seqparts.length]; + } else { + newseqs = new SequenceI[seqs.length+seqparts.length]; + + for (;si0) { + if (parseResult(new Alignment(seqs), null, null)!=null) + result.append("# Successfully parsed the "+database.getSelectedItem()+" Queries into an Alignment"); + } + } + else if (database.getSelectedItem().equals("PDB")) + { + StringTokenizer qset = new StringTokenizer(textArea.getText(), ";"); + String query; + SequenceI[] seqs = null; + while (qset.hasMoreTokens() && ((query = qset.nextToken())!=null)) + { + SequenceI[] seqparts = getPDBFile(query.toUpperCase()); + if (seqparts != null) + { + if (seqs == null) + { + seqs = seqparts; + } + else + { + SequenceI[] newseqs = new SequenceI[seqs.length+seqparts.length]; + int i=0; + for (; i < seqs.length; i++) + { + newseqs[i] = seqs[i]; + seqs[i] = null; + } + for (int j=0;j 0) + { + if (parseResult(new Alignment(seqs), null, null)!=null) + { + result.append( + "# Successfully parsed the PDB File Queries into an Alignment"); + } + } + } + else if( database.getSelectedItem().equals("PFAM")) + { + try + { + result.append(new FastaFile( + "http://www.sanger.ac.uk/cgi-bin/Pfam/getalignment.pl?format=fal&acc=" + + textArea.getText().toUpperCase(), "URL").print() + ); + + if(result.length()>0) + { + parseResult( result.toString(), textArea.getText().toUpperCase() ); + } + + } + catch (java.io.IOException ex) + { + result = null; + } + } + + if (result == null || result.length() == 0) + { + showErrorMessage("Error retrieving " + textArea.getText() + + " from " + database.getSelectedItem()); + } + + resetDialog(); + return; + } + + void getUniprotFile(String id) + { + EBIFetchClient ebi = new EBIFetchClient(); + File file = ebi.fetchDataAsFile("uniprot:" + id, "xml", null); + + DBRefFetcher dbref = new DBRefFetcher(); + Vector entries = dbref.getUniprotEntries(file); + + if (entries != null) + { + //First, make the new sequences + Enumeration en = entries.elements(); + while (en.hasMoreElements()) + { + UniprotEntry entry = (UniprotEntry) en.nextElement(); + + StringBuffer name = new StringBuffer(">UniProt/Swiss-Prot"); + Enumeration en2 = entry.getAccession().elements(); + while (en2.hasMoreElements()) + { + name.append("|"); + name.append(en2.nextElement()); + } + en2 = entry.getName().elements(); + while (en2.hasMoreElements()) + { + name.append("|"); + name.append(en2.nextElement()); + } + + if (entry.getProtein() != null) + { + name.append(" " + entry.getProtein().getName().elementAt(0)); + } + + result.append(name + "\n" + entry.getUniprotSequence().getContent() + + "\n"); + + } + + //Then read in the features and apply them to the dataset + Alignment al = parseResult(result.toString(), null); + for (int i = 0; i < entries.size(); i++) + { + UniprotEntry entry = (UniprotEntry) entries.elementAt(i); + Enumeration e = entry.getDbReference().elements(); + Vector onlyPdbEntries = new Vector(); + while (e.hasMoreElements()) + { + PDBEntry pdb = (PDBEntry) e.nextElement(); + if (!pdb.getType().equals("PDB")) + { + continue; + } + + onlyPdbEntries.addElement(pdb); + } + + Enumeration en2 = entry.getAccession().elements(); + while (en2.hasMoreElements()) + { + al.getSequenceAt(i).getDatasetSequence().addDBRef(new DBRefEntry( + DBRefSource.UNIPROT, + "0", + en2.nextElement().toString())); + } + + + + + al.getSequenceAt(i).getDatasetSequence().setPDBId(onlyPdbEntries); + if (entry.getFeature() != null) + { + e = entry.getFeature().elements(); + while (e.hasMoreElements()) + { + SequenceFeature sf = (SequenceFeature) e.nextElement(); + sf.setFeatureGroup("Uniprot"); + al.getSequenceAt(i).getDatasetSequence().addSequenceFeature( sf ); + } + } + } + } + } + + SequenceI[] getPDBFile(String id) + { + Vector result = new Vector(); + String chain = null; + if (id.indexOf(":") > -1) + { + chain = id.substring(id.indexOf(":") + 1); + id = id.substring(0, id.indexOf(":")); + } + + EBIFetchClient ebi = new EBIFetchClient(); + String file = ebi.fetchDataAsFile("pdb:" + id, "pdb", "raw"). + getAbsolutePath(); + if (file == null) + { + return null; + } + try + { + PDBfile pdbfile = new PDBfile(file, jalview.io.AppletFormatAdapter.FILE); + for (int i = 0; i < pdbfile.chains.size(); i++) + { + if (chain == null || + ( (PDBChain) pdbfile.chains.elementAt(i)).id. + toUpperCase().equals(chain)) + { + PDBChain pdbchain = (PDBChain) pdbfile.chains.elementAt(i); + // Get the Chain's Sequence - who's dataset includes any special features added from the PDB file + SequenceI sq = pdbchain.sequence; + // Specially formatted name for the PDB chain sequences retrieved from the PDB + sq.setName("PDB|"+id+"|"+sq.getName()); + // Might need to add more metadata to the PDBEntry object + // like below + /* + * PDBEntry entry = new PDBEntry(); + // Construct the PDBEntry + entry.setId(id); + if (entry.getProperty() == null) + entry.setProperty(new Hashtable()); + entry.getProperty().put("chains", + pdbchain.id + + "=" + sq.getStart() + + "-" + sq.getEnd()); + sq.getDatasetSequence().addPDBId(entry); + */ + // Add PDB DB Refs + // We make a DBRefEtntry because we have obtained the PDB file from a verifiable source + // JBPNote - PDB DBRefEntry should also carry the chain and mapping information + DBRefEntry dbentry = new DBRefEntry(jalview.datamodel.DBRefSource.PDB, + "0", id + pdbchain.id); + sq.addDBRef(dbentry); + // and add seuqence to the retrieved set + result.addElement(sq.deriveSequence()); + } + } + + if (result.size() < 1) + { + throw new Exception("WsDBFetch for PDB id resulted in zero result size"); + } + } + catch (Exception ex) // Problem parsing PDB file + { + jalview.bin.Cache.log.warn("Exception when retrieving " + + textArea.getText() + " from " + + database.getSelectedItem(), ex); + return null; + } + + + SequenceI[] results = new SequenceI[result.size()]; + for (int i = 0, j = result.size(); i < j; i++) + { + results[i] = (SequenceI) result.elementAt(i); + result.setElementAt(null,i); + } + return results; + } + Alignment parseResult(String result, String title) + { + String format = new IdentifyFile().Identify(result, "Paste"); + Alignment sequences = null; + if (FormatAdapter.isValidFormat(format)) + { + sequences = null; + try + { + sequences = new FormatAdapter().readFile(result.toString(), "Paste", + format); + } + catch (Exception ex) + {} + + if (sequences!=null) + { + return parseResult(sequences, title, format); + } + } + else + { + showErrorMessage("Error retrieving " + textArea.getText() + + " from " + database.getSelectedItem()); + } + + return null; + } + + Alignment parseResult(Alignment al, String title, String currentFileFormat) + { + + if (al != null && al.getHeight() > 0) + { + if (alignFrame == null) + { + AlignFrame af = new AlignFrame(al, + AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + if (currentFileFormat!=null) + { + af.currentFileFormat = currentFileFormat; // WHAT IS THE DEFAULT FORMAT FOR NON-FormatAdapter Sourced Alignments? + } + + if(title==null) + { + title = "Retrieved from " + database.getSelectedItem(); + } + + Desktop.addInternalFrame(af, + title, + AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + + af.statusBar.setText("Successfully pasted alignment file"); + + try + { + af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); + } + catch (Exception ex) + {} + } + else + { + for (int i = 0; i < al.getHeight(); i++) + { + alignFrame.viewport.alignment.addSequence(al.getSequenceAt(i)); // this also creates dataset sequence entries + } + alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment. + getHeight()); + alignFrame.viewport.alignment.getWidth(); + alignFrame.viewport.firePropertyChange("alignment", null, + alignFrame.viewport. + getAlignment().getSequences()); + } + } + return al; + } + + void showErrorMessage(final String error) + { + resetDialog(); + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + error, "Error Retrieving Data", + JOptionPane.WARNING_MESSAGE); + } + }); + } +} + diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 58ca6f6..ea2ef4d 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -423,7 +423,7 @@ public class TreeCanvas return; } - if ( (node.left() == null) && (node.right() == null)) + if ( (node.left() == null) && (node.right() == null)) // TODO: internal node { node.color = c; diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index b37e4c1..36378d4 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -116,6 +116,7 @@ public class GAlignFrame JMenuItem vamsasStore = new JMenuItem(); protected JMenuItem showTranslation = new JMenuItem(); protected JMenuItem extractScores = new JMenuItem(); + protected JMenu showProducts = new JMenu(); public JMenuItem featureSettings = new JMenuItem(); JMenuItem fetchSequence = new JMenuItem(); JMenuItem annotationColour = new JMenuItem(); @@ -1026,7 +1027,16 @@ public class GAlignFrame extractScores_actionPerformed(e); } }); - extractScores.setVisible(false); // JBPNote: TODO: make gui for regex based score extraction + extractScores.setVisible(true); // JBPNote: TODO: make gui for regex based score extraction + showProducts.setText("Get Cross References"); + /*showProducts.addActionListener(new ActionListener() + { + + public void actionPerformed(ActionEvent e) + { + showProducts_actionPerformed(e); + } + });*/ featureSettings.setText("Feature Settings..."); featureSettings.addActionListener(new ActionListener() { @@ -1362,6 +1372,7 @@ public class GAlignFrame calculateMenu.add(PCAMenuItem); calculateMenu.addSeparator(); calculateMenu.add(showTranslation); + calculateMenu.add(showProducts); calculateMenu.add(autoCalculate); calculateMenu.addSeparator(); calculateMenu.add(extractScores); @@ -1412,6 +1423,12 @@ public class GAlignFrame selectMenu.add(deleteGroups); } + protected void showProducts_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + protected void buildSortByAnnotationScoresMenu() { } diff --git a/src/jalview/structure/SequenceListener.java b/src/jalview/structure/SequenceListener.java index bda215e..5370e12 100644 --- a/src/jalview/structure/SequenceListener.java +++ b/src/jalview/structure/SequenceListener.java @@ -1,30 +1,30 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2007 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 - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ -package jalview.structure; - -import jalview.datamodel.*; - -public interface SequenceListener -{ - public void mouseOverSequence(SequenceI sequence, int index); - - public void highlightSequence(jalview.datamodel.SearchResults results); - - public void updateColours(SequenceI sequence, int index); -} +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +package jalview.structure; + +import jalview.datamodel.*; + +public interface SequenceListener +{ + public void mouseOverSequence(SequenceI sequence, int index, int pos); + + public void highlightSequence(jalview.datamodel.SearchResults results); + + public void updateColours(SequenceI sequence, int index); +} diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index b07b7a4..d36d009 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -293,10 +293,12 @@ public class StructureSelectionManager // pairs - public void mouseOverSequence(SequenceI seq, int index) + public void mouseOverSequence(SequenceI seq, int indexpos, int index) { boolean hasSequenceListeners = handlingVamsasMo || seqmappings != null; SearchResults results = null; + if (index==-1) + index=seq.findPosition(indexpos); StructureListener sl; int atomNo = 0; for (int i = 0; i < listeners.size(); i++) @@ -307,7 +309,7 @@ public class StructureSelectionManager for (int j = 0; j < mappings.length; j++) { - if (mappings[j].sequence == seq) + if (mappings[j].sequence == seq || mappings[j].sequence==seq.getDatasetSequence()) { atomNo = mappings[j].getAtomNum(index); @@ -348,6 +350,7 @@ public class StructureSelectionManager // hasSequenceListeners = results.getSize() > 0; if (handlingVamsasMo) { + // maybe have to resolve seq to a dataset seqeunce... // add in additional direct sequence and/or dataset sequence // highlighting results.addResult(seq, index, index); @@ -366,8 +369,8 @@ public class StructureSelectionManager // DEBUG //System.err.println("Vamsas from Seq " + seq.getDisplayId(false) + " " + // index); - // pass the mouse over onto the VamsasListener(s) - ((VamsasListener) listeners.elementAt(i)).mouseOver(seq, index); + // pass the mouse over and absolute position onto the VamsasListener(s) + ((VamsasListener) listeners.elementAt(i)).mouseOver(seq, indexpos); } } } @@ -378,18 +381,23 @@ public class StructureSelectionManager * handled */ boolean handlingVamsasMo = false; - + long lastmsg=0; /** * as mouseOverSequence but only route event to SequenceListeners * * @param sequenceI - * @param position + * @param position in an alignment sequence */ public void mouseOverVamsasSequence(SequenceI sequenceI, int position) { handlingVamsasMo = true; - mouseOverSequence(sequenceI, position); - handlingVamsasMo = false; + long msg = sequenceI.hashCode()*(1+position); + if (lastmsg!=msg) + { + lastmsg = msg; + mouseOverSequence(sequenceI, position, -1); + } + handlingVamsasMo = false; } public Annotation[] colourSequenceFromStructure(SequenceI seq, -- 1.7.10.2