X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdPanel.java;h=07a3c55b87f3c05911def8c3968c649d21eece81;hb=a07bf6f3bf11bddbed2c40e76a0e9cf062123d98;hp=26d419924fd04b940946ebb7152a6783036807ed;hpb=1ecf6419aba86993b3c223bf5ec0fa79427baf85;p=jalview.git diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 26d4199..07a3c55 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -12,15 +12,12 @@ public class IdPanel extends JPanel implements MouseListener, MouseMotionListene protected IdCanvas idCanvas; protected AlignViewport av; protected AlignmentPanel alignPanel; + ScrollThread scrollThread = null; - protected int offy; - public int width; - public int lastid; - - - - boolean mouseDown; - boolean mouseUp; + int offy; + int width; + int lastid = -1; + boolean mouseDragging = false; public IdPanel(AlignViewport av, AlignmentPanel parent) { @@ -35,92 +32,199 @@ public class IdPanel extends JPanel implements MouseListener, MouseMotionListene public void mouseMoved(MouseEvent e) {} - public void selectSeqs(int start, int end) { - if (end < start) { - int tmp = start; - start = end; - end = tmp; - } - for (int i = start; i <= end; i++) { - SequenceI pickedSeq = av.getAlignment().getSequenceAt(i); + public void mouseDragged(MouseEvent e) { + mouseDragging = true; - if (av.getSelection().contains(pickedSeq)) { - av.getSelection().removeElement(pickedSeq); - } else { - av.getSelection().addElement(pickedSeq); - } - } + int y = e.getY(); + if(av.getWrapAlignment()) + y-=2*av.charHeight; + int seq = av.getIndex(y); - repaint(); + if(seq<0) + return; - } + if (seq < lastid) + selectSeqs(lastid - 1, seq); + else if (seq > lastid) + selectSeqs(lastid + 1, seq); - public void mouseDragged(MouseEvent e) { - int y = e.getY(); + lastid = seq; + alignPanel.repaint(); + } - int seq = av.getIndex(y); + public void mouseClicked(MouseEvent e) + { + if (e.getClickCount() == 2) + { + int y = e.getY(); + if(av.getWrapAlignment()) + y-=2*av.charHeight; + + int seq = av.getIndex(y); + String id = av.getAlignment().getSequenceAt(seq).getName(); + + try{ + jalview.util.BrowserLauncher.openURL( + "http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[swall-id:" + id + + "]+-vn+2"); + }catch(Exception ex){ex.printStackTrace();} + } - if (mouseDown == true) { - if (seq < lastid) { - selectSeqs(lastid-1,seq); - } else if (seq > lastid) { - selectSeqs(lastid+1,seq); - } - lastid = seq; + } + public void mouseEntered(MouseEvent e) + { + if(scrollThread!=null) + scrollThread.running = false; + } + + public void mouseExited (MouseEvent e) + { + if(av.getWrapAlignment()) + return; + + if(mouseDragging && e.getY()<0 && av.getStartSeq()>0) + { + scrollThread = new ScrollThread(true); } - return; + if(mouseDragging && e.getY()>=getHeight() && av.alignment.getHeight()>av.getEndSeq()) + { + scrollThread = new ScrollThread(false); + } } - public void mouseClicked(MouseEvent e) { } - public void mouseEntered(MouseEvent e) { } - public void mouseExited (MouseEvent e) { } public void mousePressed(MouseEvent e) { - int x = e.getX(); + if (e.getClickCount() == 2) + return; + int y = e.getY(); + if(av.getWrapAlignment()) + y-=2*av.charHeight; int seq = av.getIndex(y); + if (seq == -1) + return; + + if (javax.swing.SwingUtilities.isRightMouseButton(e)) + { + jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel, + (Sequence)av.getAlignment().getSequenceAt(seq)); + pop.show(this, e.getX(), y); + return; + } - mouseDown = true; + if(!e.isControlDown() && !e.isShiftDown() && av.alignment.findGroup( av.alignment.getSequenceAt(seq))!=null) + { - if( javax.swing.SwingUtilities.isRightMouseButton(e)) - { - String id = av.getAlignment().getSequenceAt(seq).getName(); - String s = (String)JOptionPane.showInputDialog( - this, - "Edit sequence name", - "Edit sequence name", - JOptionPane.PLAIN_MESSAGE, - null, - null, - id); - - if(s!=null) - { - av.getAlignment().getSequenceAt(seq).setName(s); - alignPanel.RefreshPanels(); - } + SequenceGroup selection = new SequenceGroup(); + SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(seq)); + selection.setStartRes(0); + selection.setEndRes(av.alignment.getWidth()); + for (int i =0; i< sg.getSize(); i++) + selection.addSequence(sg.getSequenceAt(i)); - } - else - { - if (seq != -1) - selectSeqs(seq,seq); + av.setSelectionGroup(selection); + return; + } - lastid = seq; - } - return; + if(av.getSelectionGroup()==null || ( !e.isControlDown() && av.getSelectionGroup()!=null)) + av.setSelectionGroup(new SequenceGroup()); + + av.getSelectionGroup().setStartRes(0); + av.getSelectionGroup().setEndRes(av.alignment.getWidth()-1); + + if(e.isShiftDown() && lastid!=-1) + selectSeqs(lastid, seq); + else + selectSeq(seq); + + alignPanel.repaint(); + repaint(); } - public void mouseReleased(MouseEvent e) { - lastid = -1; + void selectSeq(int seq) + { + lastid = seq; + SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq); + av.getSelectionGroup().addOrRemove(pickedSeq); + } - mouseDown = false; - mouseUp = true; + void selectSeqs(int start, int end) { + + lastid = start; + if (end < start) + { + int tmp = start; + start = end; + end = tmp; + lastid = end; + } + + for (int i = start; i <= end; i++) + av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i)); + + } - PaintRefresher.Refresh(this); + public void mouseReleased(MouseEvent e) + { + if(scrollThread!=null) + scrollThread.running = false; + + mouseDragging = false; + PaintRefresher.Refresh(this); } + + // this class allows scrolling off the bottom of the visible alignment + class ScrollThread + extends Thread + { + boolean running = false; + boolean up = true; + public ScrollThread(boolean up) + { + this.up = up; + start(); + } + + public void stopScrolling() + { + running = false; + } + + public void run() + { + running = true; + while (running) + { + if(alignPanel.scrollUp(up)) + { + // scroll was ok, so add new sequence to selection + int seq = av.getStartSeq(); + if(!up) + seq = av.getEndSeq(); + + if (seq < lastid) + selectSeqs(lastid - 1, seq); + else if (seq > lastid) + selectSeqs(lastid + 1, seq); + + lastid = seq; + } + else + running = false; + + alignPanel.repaint(); + try + { + Thread.sleep(100); + } + catch (Exception ex) + {} + } + } +} + }