import jalview.gui.JalviewColourChooser.ColourChooserListener;
import jalview.renderer.AnnotationRenderer;
import jalview.renderer.AwtRenderPanelI;
-import jalview.schemes.FeatureColour;
import jalview.schemes.ResidueProperties;
import jalview.util.Comparison;
import jalview.util.MessageManager;
import java.util.Collections;
import java.util.List;
-import javax.swing.JColorChooser;
-import javax.swing.JDialog;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
}
/**
- * DOCUMENT ME!
+ * On leaving the panel, calls ScalePanel.mouseExited to deal with scrolling
+ * with column selection on a mouse drag
*
* @param evt
- * DOCUMENT ME!
*/
@Override
public void mouseExited(MouseEvent evt)
*/
package jalview.gui;
+import jalview.bin.Jalview;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import jalview.viewmodel.ViewportRanges;
import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
+import javax.swing.Timer;
import javax.swing.ToolTipManager;
/**
}
/**
- * DOCUMENT ME!
+ * On (re-)entering the panel, stop any scrolling
*
* @param e
- * DOCUMENT ME!
*/
@Override
public void mouseEntered(MouseEvent e)
{
+ stopScrolling();
+ }
+
+ /**
+ * Interrupts the scroll thread if one is running
+ */
+ void stopScrolling()
+ {
if (scrollThread != null)
{
scrollThread.stopScrolling();
return;
}
- if (mouseDragging && (e.getY() < 0)
- && (av.getRanges().getStartSeq() > 0))
+ if (mouseDragging)
{
- scrollThread = new ScrollThread(true);
+ /*
+ * on mouse drag above or below the panel, start
+ * scrolling if there are more sequences to show
+ */
+ ViewportRanges ranges = av.getRanges();
+ if (e.getY() < 0 && ranges.getStartSeq() > 0)
+ {
+ startScrolling(true);
+ }
+ else if (e.getY() >= getHeight()
+ && ranges.getEndSeq() <= av.getAlignment().getHeight())
+ {
+ startScrolling(false);
+ }
}
+ }
- if (mouseDragging && (e.getY() >= getHeight())
- && (av.getAlignment().getHeight() > av.getRanges().getEndSeq()))
+ /**
+ * Starts scrolling either up or down
+ *
+ * @param up
+ */
+ void startScrolling(boolean up)
+ {
+ scrollThread = new ScrollThread(up);
+ if (!Jalview.isJS())
{
- scrollThread = new ScrollThread(false);
+ /*
+ * Java - run in a new thread
+ */
+ scrollThread.start();
+ }
+ else
+ {
+ /*
+ * for JalviewJS using Swing Timer
+ */
+ Timer t = new Timer(20, new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (scrollThread != null)
+ {
+ // if (!scrollOnce() {t.stop();}) gives compiler error :-(
+ scrollThread.scrollOnce();
+ }
+ }
+ });
+ t.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (scrollThread == null)
+ {
+ // finished and nulled itself
+ t.stop();
+ }
+ }
+ });
+ t.start();
}
}
@Override
public void mouseReleased(MouseEvent e)
{
- if (scrollThread != null)
- {
- scrollThread.stopScrolling();
- }
+ stopScrolling();
mouseDragging = false;
PaintRefresher.Refresh(this, av.getSequenceSetId());
* Scrolls the alignment either up or down, one row at a time, adding newly
* visible sequences to the current selection. Speed is limited to a maximum
* of ten rows per second. The thread exits when the end of the alignment is
- * reached or a flag is set to stop it.
+ * reached or a flag is set to stop it by a call to stopScrolling.
*/
@Override
public void run()
while (running)
{
- ViewportRanges ranges = IdPanel.this.av.getRanges();
- if (ranges.scrollUp(up))
- {
- int toSeq = up ? ranges.getStartSeq() : ranges.getEndSeq();
- int fromSeq = toSeq < lastid ? lastid - 1 : lastid + 1;
- IdPanel.this.selectSeqs(fromSeq, toSeq);
-
- lastid = toSeq;
- }
- else
- {
- /*
- * scroll did nothing - reached limit of visible alignment
- */
- running = false;
- }
-
- alignPanel.paintAlignment(false, false);
-
+ running = scrollOnce();
try
{
Thread.sleep(100);
{
}
}
+ IdPanel.this.scrollThread = null;
+ }
+
+ /**
+ * Scrolls one row up or down. Answers true if a scroll could be done, false
+ * if not (top or bottom of alignment reached).
+ */
+ boolean scrollOnce()
+ {
+ ViewportRanges ranges = IdPanel.this.av.getRanges();
+ if (ranges.scrollUp(up))
+ {
+ int toSeq = up ? ranges.getStartSeq() : ranges.getEndSeq();
+ int fromSeq = toSeq < lastid ? lastid - 1 : lastid + 1;
+ IdPanel.this.selectSeqs(fromSeq, toSeq);
+ lastid = toSeq;
+ alignPanel.paintAlignment(false, false);
+ return true;
+ }
+
+ return false;
}
}
}