X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FSeqPanel.java;h=ca5d7f7be2a2ba74bf6cddd90cc029cb0aeb28e9;hb=1335a93a7eb656ab1bd08572d4be2b386a9043c9;hp=7d451dad5b6f2d7695a54e443dc4db473307d110;hpb=40ecea964afaaf404465d75873ec915b901117a3;p=jalview.git
diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java
old mode 100755
new mode 100644
index 7d451da..ca5d7f7
--- a/src/jalview/gui/SeqPanel.java
+++ b/src/jalview/gui/SeqPanel.java
@@ -1,20 +1,19 @@
/*
- * 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
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview 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 3 of the License, or (at your option) any later version.
+ *
+ * Jalview 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 Jalview. If not, see .
*/
package jalview.gui;
@@ -22,6 +21,7 @@ import java.util.*;
import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
import jalview.commands.*;
@@ -31,13 +31,13 @@ import jalview.structure.*;
/**
* DOCUMENT ME!
- *
+ *
* @author $author$
- * @version $Revision$
+ * @version $Revision: 1.130 $
*/
-public class SeqPanel
- extends JPanel implements MouseListener,
- MouseMotionListener, MouseWheelListener, SequenceListener
+public class SeqPanel extends JPanel implements MouseListener,
+ MouseMotionListener, MouseWheelListener, SequenceListener,
+ SelectionListener
{
/** DOCUMENT ME!! */
@@ -45,46 +45,63 @@ public class SeqPanel
/** DOCUMENT ME!! */
public AlignmentPanel ap;
+
protected int lastres;
+
protected int startseq;
+
protected AlignViewport av;
ScrollThread scrollThread = null;
+
boolean mouseDragging = false;
+
boolean editingSeqs = false;
+
boolean groupEditing = false;
- //////////////////////////////////////////
- /////Everything below this is for defining the boundary of the rubberband
- //////////////////////////////////////////
+ // ////////////////////////////////////////
+ // ///Everything below this is for defining the boundary of the rubberband
+ // ////////////////////////////////////////
int oldSeq = -1;
+
boolean changeEndSeq = false;
+
boolean changeStartSeq = false;
+
boolean changeEndRes = false;
+
boolean changeStartRes = false;
+
SequenceGroup stretchGroup = null;
+
boolean remove = false;
Point lastMousePress;
+
boolean mouseWheelPressed = false;
+
StringBuffer keyboardNo1;
+
StringBuffer keyboardNo2;
java.net.URL linkImageURL;
StringBuffer tooltipText = new StringBuffer("");
+
String tmpString;
EditCommand editCommand;
StructureSelectionManager ssm;
-
/**
* Creates a new SeqPanel object.
- *
- * @param avp DOCUMENT ME!
- * @param p DOCUMENT ME!
+ *
+ * @param avp
+ * DOCUMENT ME!
+ * @param p
+ * DOCUMENT ME!
*/
public SeqPanel(AlignViewport av, AlignmentPanel ap)
{
@@ -106,13 +123,16 @@ public class SeqPanel
addMouseMotionListener(this);
addMouseListener(this);
addMouseWheelListener(this);
- ssm = StructureSelectionManager.getStructureSelectionManager();
+ ssm = StructureSelectionManager.getStructureSelectionManager(Desktop.instance);
ssm.addStructureViewerListener(this);
+ ssm.addSelectionListener(this);
}
}
int startWrapBlock = -1;
+
int wrappedBlock = -1;
+
int findRes(MouseEvent evt)
{
int res = 0;
@@ -127,8 +147,8 @@ public class SeqPanel
hgap += av.charHeight;
}
- int cHeight = av.getAlignment().getHeight() * av.charHeight
- + hgap + seqCanvas.getAnnotationHeight();
+ int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
+ + seqCanvas.getAnnotationHeight();
int y = evt.getY();
y -= hgap;
@@ -148,6 +168,11 @@ public class SeqPanel
}
else
{
+ if (x>seqCanvas.getWidth()+seqCanvas.getWidth())
+ {
+ // make sure we calculate relative to visible alignment, rather than right-hand gutter
+ x = seqCanvas.getX()+seqCanvas.getWidth();
+ }
res = (x / av.getCharWidth()) + av.getStartRes();
}
@@ -173,18 +198,18 @@ public class SeqPanel
hgap += av.charHeight;
}
- int cHeight = av.getAlignment().getHeight() * av.charHeight
- + hgap + seqCanvas.getAnnotationHeight();
+ int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
+ + seqCanvas.getAnnotationHeight();
y -= hgap;
- seq = Math.min( (y % cHeight) / av.getCharHeight(),
- av.alignment.getHeight() - 1);
+ seq = Math.min((y % cHeight) / av.getCharHeight(),
+ av.alignment.getHeight() - 1);
}
else
{
- seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(),
- av.alignment.getHeight() - 1);
+ seq = Math.min((y / av.getCharHeight()) + av.getStartSeq(),
+ av.alignment.getHeight() - 1);
}
return seq;
@@ -199,20 +224,21 @@ public class SeqPanel
for (int i = 0; i < features.length; i++)
{
if (av.featuresDisplayed == null
- || !av.featuresDisplayed.containsKey(features[i].getType()))
+ || !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())
+ && 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))
+ if ((features[i].getBegin() <= res)
+ && (features[i].getEnd() >= res))
{
tmp.addElement(features[i]);
}
@@ -225,14 +251,13 @@ public class SeqPanel
return features;
}
-
void endEditing()
{
if (editCommand != null && editCommand.getSize() > 0)
{
ap.alignFrame.addHistoryItem(editCommand);
- av.firePropertyChange("alignment", null,
- av.getAlignment().getSequences());
+ av.firePropertyChange("alignment", null, av.getAlignment()
+ .getSequences());
}
startseq = -1;
@@ -272,12 +297,10 @@ public class SeqPanel
void setCursorPosition()
{
- SequenceI sequence =
- (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
+ SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(
+ seqCanvas.cursorY);
- seqCanvas.cursorX = sequence.findIndex(
- getKeyboardNo1() - 1
- );
+ seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1() - 1);
scrollToVisible();
}
@@ -291,14 +314,13 @@ public class SeqPanel
int maxWidth = av.alignment.getWidth();
while (!av.colSel.isVisible(seqCanvas.cursorX)
- && seqCanvas.cursorX < maxWidth
- && seqCanvas.cursorX > 0)
+ && seqCanvas.cursorX < maxWidth && seqCanvas.cursorX > 0)
{
seqCanvas.cursorX += dx;
}
if (seqCanvas.cursorX >= maxWidth
- || !av.colSel.isVisible(seqCanvas.cursorX))
+ || !av.colSel.isVisible(seqCanvas.cursorX))
{
seqCanvas.cursorX = original;
}
@@ -344,14 +366,16 @@ public class SeqPanel
}
if (!av.wrapAlignment)
{
- while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes))
+ while (seqCanvas.cursorX < av.colSel
+ .adjustForHiddenColumns(av.startRes))
{
if (!ap.scrollRight(false))
{
break;
}
}
- while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes))
+ while (seqCanvas.cursorX > av.colSel
+ .adjustForHiddenColumns(av.endRes))
{
if (!ap.scrollRight(true))
{
@@ -361,20 +385,20 @@ public class SeqPanel
}
}
setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
- seqCanvas.cursorX, seqCanvas.cursorY);
+ seqCanvas.cursorX, seqCanvas.cursorY);
seqCanvas.repaint();
}
void setSelectionAreaAtCursor(boolean topLeft)
{
- SequenceI sequence =
- (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
+ SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(
+ seqCanvas.cursorY);
if (av.getSelectionGroup() != null)
{
SequenceGroup sg = av.selectionGroup;
- //Find the top and bottom of this group
+ // Find the top and bottom of this group
int min = av.alignment.getHeight(), max = 0;
for (int i = 0; i < sg.getSize(); i++)
{
@@ -438,6 +462,7 @@ public class SeqPanel
}
ap.paintAlignment(false);
+ av.sendSelection();
}
void insertGapAtCursor(boolean group)
@@ -501,8 +526,9 @@ public class SeqPanel
/**
* DOCUMENT ME!
- *
- * @param evt DOCUMENT ME!
+ *
+ * @param evt
+ * DOCUMENT ME!
*/
public void mouseReleased(MouseEvent evt)
{
@@ -520,8 +546,9 @@ public class SeqPanel
/**
* DOCUMENT ME!
- *
- * @param evt DOCUMENT ME!
+ *
+ * @param evt
+ * DOCUMENT ME!
*/
public void mousePressed(MouseEvent evt)
{
@@ -533,8 +560,7 @@ public class SeqPanel
return;
}
- if (evt.isShiftDown() || evt.isAltDown() ||
- evt.isControlDown())
+ if (evt.isShiftDown() || evt.isAltDown() || evt.isControlDown())
{
if (evt.isAltDown() || evt.isControlDown())
{
@@ -556,8 +582,8 @@ public class SeqPanel
return;
}
- if ( (seq < av.getAlignment().getHeight()) &&
- (res < av.getAlignment().getSequenceAt(seq).getLength()))
+ if ((seq < av.getAlignment().getHeight())
+ && (res < av.getAlignment().getSequenceAt(seq).getLength()))
{
startseq = seq;
lastres = res;
@@ -572,34 +598,42 @@ public class SeqPanel
}
String lastMessage;
+
public void mouseOverSequence(SequenceI sequence, int index, int pos)
{
- String tmp = sequence.hashCode()+" "+index+" "+pos;
-
+ String tmp = sequence.hashCode() + " " + index + " " + pos;
+
if (lastMessage == null || !lastMessage.equals(tmp))
{
// System.err.println("mouseOver Sequence: "+tmp);
- ssm.mouseOverSequence(sequence, index, pos);
+ ssm.mouseOverSequence(sequence, index, pos, av);
}
lastMessage = tmp;
}
-
public void highlightSequence(SearchResults results)
{
- seqCanvas.highlightSearchResults(results);
+ if (av.followHighlight)
+ {
+ if (ap.scrollToPosition(results, false))
+ {
+ seqCanvas.revalidate();
+ }
+ }
+ seqCanvas.highlightSearchResults(results);
}
public void updateColours(SequenceI seq, int index)
{
System.out.println("update the seqPanel colours");
- //repaint();
+ // repaint();
}
/**
* DOCUMENT ME!
- *
- * @param evt DOCUMENT ME!
+ *
+ * @param evt
+ * DOCUMENT ME!
*/
public void mouseMoved(MouseEvent evt)
{
@@ -626,10 +660,9 @@ public class SeqPanel
}
pos = setStatusMessage(sequence, res, seq);
- if (ssm != null && pos>-1)
+ if (ssm != null && pos > -1)
mouseOverSequence(sequence, res, pos);
-
tooltipText.setLength(6); // Cuts the buffer back to
SequenceGroup[] groups = av.alignment.findAllGroups(sequence);
@@ -644,8 +677,8 @@ public class SeqPanel
tooltipText.append("
");
}
- if (!groups[g].getName().startsWith("JTreeGroup") &&
- !groups[g].getName().startsWith("JGroup"))
+ if (!groups[g].getName().startsWith("JTreeGroup")
+ && !groups[g].getName().startsWith("JGroup"))
{
tooltipText.append(groups[g].getName());
}
@@ -661,60 +694,137 @@ public class SeqPanel
// use aa to see if the mouse pointer is on a
if (av.showSequenceFeatures)
{
+ int rpos;
SequenceFeature[] features = findFeaturesAtRes(
- sequence.getDatasetSequence(), sequence.findPosition(res));
+ sequence.getDatasetSequence(),
+ rpos = sequence.findPosition(res));
+ appendFeatures(tooltipText, linkImageURL.toString(), rpos, features,
+ this.ap.seqPanel.seqCanvas.fr.minmax);
+ }
+ if (tooltipText.length() == 6) //
+ {
+ setToolTipText(null);
+ lastTooltip = null;
+ }
+ else
+ {
+ tooltipText.append("");
+ if (lastTooltip == null
+ || !lastTooltip.equals(tooltipText.toString()))
+ {
+ setToolTipText(tooltipText.toString());
+ lastTooltip = tooltipText.toString();
+ }
+
+ }
+
+ }
+
+ private Point lastp = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.swing.JComponent#getToolTipLocation(java.awt.event.MouseEvent)
+ */
+ public Point getToolTipLocation(MouseEvent event)
+ {
+ int x = event.getX(), w = getWidth();
+ int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
+ // close to edge
+ Point p = lastp;
+ if (!event.isShiftDown() || p == null)
+ {
+ p = (tooltipText != null && tooltipText.length() > 6) ? new Point(
+ event.getX() + wdth, event.getY() - 20) : null;
+ }
+ /*
+ * TODO: try to modify position region is not obcured by tooltip
+ */
+ return lastp = p;
+ }
- if (features != null)
+ /**
+ * appends the features at rpos to the given stringbuffer ready for display in
+ * a tooltip
+ *
+ * @param tooltipText2
+ * @param linkImageURL
+ * @param rpos
+ * @param features
+ * TODO refactor to Jalview 'utilities' somehow.
+ */
+ public void appendFeatures(StringBuffer tooltipText2,
+ String linkImageURL, int rpos, SequenceFeature[] features)
+ {
+ appendFeatures(tooltipText2, linkImageURL, rpos, features, null);
+ }
+
+ public void appendFeatures(StringBuffer tooltipText2, String string,
+ int rpos, SequenceFeature[] features, Hashtable minmax)
+ {
+ String tmpString;
+ if (features != null)
+ {
+ for (int i = 0; i < features.length; i++)
{
- for (int i = 0; i < features.length; i++)
+ if (features[i].getType().equals("disulfide bond"))
{
- if (features[i].getType().equals("disulfide bond"))
+ if (features[i].getBegin() == rpos
+ || features[i].getEnd() == rpos)
{
- if (features[i].getBegin() == sequence.findPosition(res)
- || features[i].getEnd() == sequence.findPosition(res))
+ if (tooltipText2.length() > 6)
{
- if (tooltipText.length() > 6)
- {
- tooltipText.append("
");
- }
- tooltipText.append("disulfide bond " + features[i].getBegin() +
- ":" +
- features[i].getEnd());
- if (features[i].links != null)
- {
- tooltipText.append(" ");
- }
+ tooltipText2.append("
");
+ }
+ tooltipText2.append("disulfide bond " + features[i].getBegin()
+ + ":" + features[i].getEnd());
+ if (features[i].links != null)
+ {
+ tooltipText2.append(" ");
}
}
- else
+ }
+ else
+ {
+ if (tooltipText2.length() > 6)
{
- if (tooltipText.length() > 6)
+ tooltipText2.append("
");
+ }
+ // TODO: remove this hack to display link only features
+ boolean linkOnly = features[i].getValue("linkonly") != null;
+ if (!linkOnly)
+ {
+ tooltipText2.append(features[i].getType() + " ");
+ if (rpos != 0)
{
- tooltipText.append("
");
+ // we are marking a positional feature
+ tooltipText2.append(features[i].begin);
}
-
- tooltipText.append(features[i].getType() + " " +
- features[i].begin);
if (features[i].begin != features[i].end)
{
- tooltipText.append(" " + features[i].end);
+ tooltipText2.append(" " + features[i].end);
}
if (features[i].getDescription() != null
- && !features[i].description.equals(features[i].getType()))
+ && !features[i].description.equals(features[i]
+ .getType()))
{
tmpString = features[i].getDescription();
- int startTag = tmpString.toUpperCase().indexOf("");
+ String tmp2up=tmpString.toUpperCase();
+ int startTag = tmp2up.indexOf("");
if (startTag > -1)
{
tmpString = tmpString.substring(startTag + 6);
+ tmp2up = tmp2up.substring(startTag+6);
}
- int endTag = tmpString.toUpperCase().indexOf("");
+ int endTag = tmp2up.indexOf("");
if (endTag > -1)
{
tmpString = tmpString.substring(0, endTag);
+ tmp2up = tmp2up.substring(0, endTag);
}
- endTag = tmpString.toUpperCase().indexOf("");
+ endTag = tmp2up.indexOf("