X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdPanel.java;h=5db5e2e97ddafb9850dab16236862b62f13c6169;hb=fe5db5e87fc726b1560d21f97f19b0e04963b72c;hp=5e15283e80671d9eb79730adb8ae155a6b782b5a;hpb=491ef50a485fbff6e610c0cd138e5cf89538aa3d;p=jalview.git diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 5e15283..5db5e2e 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,107 +32,214 @@ 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) { - int y = e.getY(); + mouseDragging = true; + int y = e.getY(); + if(av.getWrapAlignment()) + y-=2*av.charHeight; int seq = av.getIndex(y); - if (mouseDown == true) { - if (seq < lastid) { - selectSeqs(lastid-1,seq); - } else if (seq > lastid) { - selectSeqs(lastid+1,seq); - } - lastid = seq; - } + if(seq<0) + return; - return; + if (seq < lastid) + selectSeqs(lastid - 1, seq); + else if (seq > lastid) + selectSeqs(lastid + 1, seq); + + lastid = seq; + 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{ jalview.util.BrowserLauncher.openURL( "http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[swall-id:" + id + "]+-vn+2"); - }catch(Exception ex){ex.printStackTrace();} + }catch(Exception ex){System.err.println( + "Try adding the jalview.browser property to your jalview.properties file:\n" + +"jalview.browser=firefox"); ex.printStackTrace();} + } + + } + 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 mouseEntered(MouseEvent e) { } - public void mouseExited (MouseEvent e) { } + 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; - mouseDown = true; + 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.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(); - } + 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()-1); + 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.repaint(); + } + + void selectSeq(int seq) + { + lastid = seq; + SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq); + av.getSelectionGroup().addOrRemove(pickedSeq); } - public void mouseReleased(MouseEvent e) { - lastid = -1; + void selectSeqs(int start, int end) { - mouseDown = false; - mouseUp = true; + 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) + { + if(scrollThread!=null) + scrollThread.running = false; + + mouseDragging = false; PaintRefresher.Refresh(this); + } + + public void highlightSearchResults( java.util.Vector found ) + { + idCanvas.setHighlighted( found ); + + if(found == null) + return; + int index = av.alignment.findIndex( (SequenceI)found.get(0)); + + // do we need to scroll the panel? + if(av.getStartSeq()>index || av.getEndSeq() lastid) + selectSeqs(lastid + 1, seq); + + lastid = seq; + } + else + running = false; + + alignPanel.repaint(); + try + { + Thread.sleep(100); + } + catch (Exception ex) + {} + } + } +} + }