X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdPanel.java;h=8903ce3f7d3dcf55c3dd8bed87a57ae58ea52bb9;hb=e74b22a8fe7beaaa54bb46c452cbb57766e90bbd;hp=4509ab3391b31325ab1dbf74e70c8cf67be84c2a;hpb=c5898a03d9b066d4ccc2e22d3cb72a8ca3cc656e;p=jalview.git diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 4509ab3..8903ce3 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -12,11 +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; - + int offy; + int width; + int lastid = -1; + boolean mouseDragging = false; public IdPanel(AlignViewport av, AlignmentPanel parent) { @@ -31,34 +32,17 @@ 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); - - if (av.getSelection().contains(pickedSeq)) - av.getSelection().removeElement(pickedSeq); - else - av.getSelection().addElement(pickedSeq); - - } - - repaint(); - - } public void mouseDragged(MouseEvent e) { + mouseDragging = true; + int y = e.getY(); + if(av.getWrapAlignment()) + y-=2*av.charHeight; int seq = av.getIndex(y); - - + if(seq<0) + return; if (seq < lastid) selectSeqs(lastid - 1, seq); @@ -66,15 +50,18 @@ public class IdPanel extends JPanel implements MouseListener, MouseMotionListene selectSeqs(lastid + 1, seq); lastid = seq; - - return; + alignPanel.repaint(); } public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { - int seq = av.getIndex(e.getY()); + int y = e.getY(); + if(av.getWrapAlignment()) + y-=2*av.charHeight; + + int seq = av.getIndex(y); String id = av.getAlignment().getSequenceAt(seq).getName(); try{ @@ -85,49 +72,160 @@ public class IdPanel extends JPanel implements MouseListener, MouseMotionListene } } - public void mouseEntered(MouseEvent e) { } - public void mouseExited (MouseEvent e) { } + 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); + } + + if(mouseDragging && e.getY()>=getHeight() && av.alignment.getHeight()>av.getEndSeq()) + { + scrollThread = new ScrollThread(false); + } + } + public void mousePressed(MouseEvent e) { 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; + } - if( javax.swing.SwingUtilities.isRightMouseButton(e)) - { - String id = av.getAlignment().getSequenceAt(seq).getName(); - String s = (String)JOptionPane.showInternalInputDialog( - this, - "Edit sequence name", - "Edit sequence name", - JOptionPane.PLAIN_MESSAGE, - null, - null, - id); - - if(s!=null) - { - av.getAlignment().getSequenceAt(seq).setName(s); - alignPanel.RefreshPanels(); - } + if(!e.isControlDown() && !e.isShiftDown() && av.alignment.findGroup( av.alignment.getSequenceAt(seq))!=null) + { - } - else - { - if (seq != -1) - selectSeqs(seq,seq); + 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)); - lastid = seq; - } - return; + av.setSelectionGroup(selection); + 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.seqPanel.seqCanvas.paintFlag=true; + alignPanel.repaint(); + repaint(); } + void selectSeq(int seq) + { + lastid = seq; + SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq); + av.getSelectionGroup().addOrRemove(pickedSeq); + } + + 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)); + + } + + public void mouseReleased(MouseEvent e) { - lastid = -1; + 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) + {} + } + } +} + }