protected void saveAs_actionPerformed(ActionEvent e)\r
{\r
JFileChooser chooser = new JFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"));\r
+ chooser.setFileView(new JalviewFileView());\r
chooser.setDialogTitle("Save Alignment to file - "+e.getActionCommand() +" format.");\r
chooser.setToolTipText("Save");\r
int value = chooser.showSaveDialog(this);\r
\r
public void moveSelectedSequences(boolean up)\r
{\r
- SequenceGroup sg = viewport.getRubberbandGroup();\r
+ SequenceGroup sg = viewport.getSelectionGroup();\r
if (sg == null)\r
return;\r
\r
\r
protected void copy_actionPerformed(ActionEvent e)\r
{\r
- if(viewport.getRubberbandGroup()==null)\r
+ if(viewport.getSelectionGroup()==null)\r
return;\r
\r
- SequenceGroup sg = viewport.getRubberbandGroup();\r
+ SequenceGroup sg = viewport.getSelectionGroup();\r
\r
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();\r
StringBuffer buffer= new StringBuffer();\r
protected void delete_actionPerformed(ActionEvent e)\r
{\r
addHistoryItem("Delete");\r
- if (viewport.getRubberbandGroup() == null)\r
+ if (viewport.getSelectionGroup() == null)\r
return;\r
\r
- SequenceGroup sg = viewport.getRubberbandGroup();\r
+ SequenceGroup sg = viewport.getSelectionGroup();\r
for (int i=0;i < sg.sequences.size(); i++)\r
{\r
SequenceI seq = sg.getSequenceAt(i);\r
viewport.getAlignment().getSequences().setElementAt(seq, index);\r
}\r
\r
- viewport.setRubberbandGroup(null);\r
+ viewport.setSelectionGroup(null);\r
viewport.alignment.deleteGroup(sg);\r
viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight());\r
if(viewport.getAlignment().getHeight()<1)\r
protected void deleteGroups_actionPerformed(ActionEvent e)\r
{\r
viewport.alignment.deleteAllGroups();\r
- viewport.getSelection().clear();\r
+ viewport.setSelectionGroup(null);\r
\r
alignPanel.RefreshPanels();\r
}\r
\r
public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e)\r
{\r
- Selection sel = viewport.getSelection();\r
+ SequenceGroup sg = new SequenceGroup();\r
for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)\r
- sel.addElement( viewport.getAlignment().getSequenceAt(i));\r
+ sg.addSequence( viewport.getAlignment().getSequenceAt(i));\r
+ sg.setEndRes(viewport.alignment.getWidth());\r
+ viewport.setSelectionGroup(sg);\r
PaintRefresher.Refresh(null);\r
}\r
\r
public void deselectAllSequenceMenuItem_actionPerformed(ActionEvent e)\r
{\r
- viewport.setRubberbandGroup(null);\r
- viewport.getSelection().clear();\r
+ viewport.setSelectionGroup(null);\r
PaintRefresher.Refresh(null);\r
}\r
\r
public void invertSequenceMenuItem_actionPerformed(ActionEvent e)\r
{\r
- Selection sel = viewport.getSelection();\r
+ SequenceGroup sg = viewport.getSelectionGroup();\r
for (int i=0; i<viewport.getAlignment().getSequences().size(); i++)\r
- {\r
- if (sel.contains(viewport.getAlignment().getSequenceAt(i)))\r
- sel.removeElement(viewport.getAlignment().getSequenceAt(i));\r
- else\r
- sel.addElement(viewport.getAlignment().getSequenceAt(i));\r
- }\r
+ sg.addOrRemove (viewport.getAlignment().getSequenceAt(i));\r
+\r
PaintRefresher.Refresh(null);\r
}\r
\r
\r
public void pairwiseAlignmentMenuItem_actionPerformed(ActionEvent e)\r
{\r
- if(viewport.getSelection().size()<2)\r
+ if(viewport.getSelectionGroup().getSize()<2)\r
JOptionPane.showInternalMessageDialog(this, "You must select at least 2 sequences.", "Invalid Selection", JOptionPane.WARNING_MESSAGE);\r
else\r
{\r
\r
public void PCAMenuItem_actionPerformed(ActionEvent e)\r
{\r
- if( (viewport.getSelection().size()<4 && viewport.getSelection().size()>0)\r
+\r
+ if( (viewport.getSelectionGroup()!=null && viewport.getSelectionGroup().getSize()<4 && viewport.getSelectionGroup().getSize()>0)\r
|| viewport.getAlignment().getHeight()<4)\r
{\r
JOptionPane.showInternalMessageDialog(this, "Principal component analysis must take\n"\r
}\r
\r
TreePanel tp=null;\r
- if (viewport.getSelection() != null && viewport.getSelection().size() > 3)\r
+ if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize() > 3)\r
{\r
- tp = new TreePanel(viewport, viewport.getSelection().asVector(),type, pwType,\r
+ tp = new TreePanel(viewport, viewport.getSelectionGroup().sequences,type, pwType,\r
0, viewport.alignment.getWidth());\r
}\r
else\r
boolean conservationColourSelected = false;\r
boolean abovePIDThreshold = false;\r
\r
- SequenceGroup rubberbandGroup = null;\r
+ SequenceGroup selectionGroup = new SequenceGroup();\r
\r
RendererI renderer = new SequenceRenderer(this);\r
\r
Font font = new Font("SansSerif",Font.PLAIN,10);\r
AlignmentI alignment;\r
\r
- Selection sel = new Selection(this);\r
ColumnSelection colSel = new ColumnSelection();\r
\r
String visibleConsensus;\r
return consensus;\r
}\r
\r
- public SequenceGroup getRubberbandGroup()\r
+ public SequenceGroup getSelectionGroup()\r
{\r
- return rubberbandGroup;\r
+ return selectionGroup;\r
}\r
\r
- public void setRubberbandGroup(SequenceGroup sg)\r
+ public void setSelectionGroup(SequenceGroup sg)\r
{\r
- rubberbandGroup = sg;\r
+ selectionGroup = sg;\r
}\r
\r
+\r
public boolean getConservationSelected()\r
{\r
return conservationColourSelected;\r
}\r
return -1;\r
}\r
- public Selection getSelection() {\r
- return sel;\r
- }\r
+\r
public ColumnSelection getColumnSelection() {\r
return colSel;\r
}\r
});\r
\r
\r
- hscroll.setFocusable(false);\r
- vscroll.setFocusable(false);\r
+ // hscroll.setFocusable(false);\r
+ // vscroll.setFocusable(false);\r
setFocusable(true);\r
\r
addKeyListener(new KeyAdapter()\r
switch(evt.getKeyCode())\r
{\r
case 27: // escape key\r
- av.setRubberbandGroup(null);\r
- av.getSelection().clear();\r
+ av.setSelectionGroup(null);\r
RefreshPanels();\r
break;\r
case KeyEvent.VK_X:\r
\r
public void RefreshPanels()\r
{\r
- requestFocus();\r
- invalidate();\r
- idPanelHolder.setPreferredSize( idPanel.idCanvas.getPreferredSize() );\r
- idSpaceFillerPanel1.setPreferredSize(new Dimension(500, av.charHeight/2 +12));\r
- scalePanelHolder.setPreferredSize(new Dimension(500, av.charHeight/2 +12));\r
- if(av.getWrapAlignment())\r
- {\r
- int max = av.alignment.getWidth()/ (seqPanel.seqCanvas.getWidth()/av.charWidth)+1;\r
+ javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+ {\r
+ public void run()\r
+ {\r
+\r
+ requestFocus();\r
+ invalidate();\r
+ idPanelHolder.setPreferredSize(idPanel.idCanvas.getPreferredSize());\r
+ hscrollFillerPanel.setPreferredSize(new Dimension(idPanel.idCanvas.\r
+ getPreferredSize().width, 12));\r
+ idSpaceFillerPanel1.setPreferredSize(new Dimension(500,\r
+ av.charHeight / 2 + 12));\r
+ scalePanelHolder.setPreferredSize(new Dimension(500,\r
+ av.charHeight / 2 + 12));\r
+ if (av.getWrapAlignment())\r
+ {\r
+ int max = av.alignment.getWidth() /\r
+ (seqPanel.seqCanvas.getWidth() / av.charWidth) + 1;\r
+\r
+ int h = (av.alignment.getHeight() + 2) * av.charHeight;\r
+ vextent = seqPanel.seqCanvas.getHeight() / h;\r
+ vscroll.setValues(0, vextent, 0, max);\r
+ }\r
+ else\r
+\r
+ setScrollValues(av.getStartRes(), av.getStartSeq());\r
+ av.getConsensus(true);\r
+ if (overviewPanel != null)\r
+ overviewPanel.updateOverviewImage();\r
+\r
+ }\r
+ });\r
+\r
+ validate();\r
+ repaint();\r
+ }\r
+ int hextent = 0;\r
+ int vextent = 0;\r
+\r
\r
- int h = (av.alignment.getHeight() + 2)*av.charHeight;\r
- vextent = seqPanel.seqCanvas.getHeight()/h;\r
- vscroll.setValues(0,vextent,0,max);\r
+ // return value is true if the scroll is valid\r
+ public boolean scrollUp(boolean up)\r
+ {\r
+ if(up)\r
+ {\r
+ if(vscroll.getValue()<1)\r
+ return false;\r
+ vscroll.setValue(vscroll.getValue() - 1);\r
}\r
else\r
+ {\r
+ if(vextent+vscroll.getValue() >= av.getAlignment().getHeight())\r
+ return false;\r
+ vscroll.setValue(vscroll.getValue() + 1);\r
+ }\r
\r
- setScrollValues(av.getStartRes(), av.getStartSeq());\r
- av.getConsensus(true);\r
- if(overviewPanel!=null)\r
- overviewPanel.updateOverviewImage();\r
+ return true;\r
+ }\r
\r
- validate();\r
- repaint();\r
+ public boolean scrollRight(boolean right)\r
+ {\r
+ if(right)\r
+ {\r
+ if(hscroll.getValue()<1)\r
+ return false;\r
+ hscroll.setValue(hscroll.getValue() - 1);\r
+ }\r
+ else\r
+ {\r
+ if(hextent+hscroll.getValue() >= av.getAlignment().getWidth())\r
+ return false;\r
+ hscroll.setValue(hscroll.getValue() + 1);\r
+ }\r
\r
- }\r
+ return true;\r
+ }\r
\r
- int hextent = 0;\r
- int vextent = 0;\r
\r
public void setScrollValues(int x, int y)\r
{\r
Color currentTextColor=null;\r
for(int i=startSeq; i<endSeq; i++)\r
{\r
- if (av.getSelection().contains(av.getAlignment().getSequenceAt(i)))\r
+ if (av.alignment.findGroup(av.getAlignment().getSequenceAt(i))==null)\r
{\r
currentColor = Color.gray;\r
currentTextColor = Color.black;\r
\r
javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(jalview.bin.Cache.getProperty(\r
"LAST_DIRECTORY"));\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
chooser.setDialogTitle("Create JPG image from alignment");\r
chooser.setToolTipText("Save");\r
\r
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);\r
\r
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();\r
- int width = 1200, height = 800;\r
+ int width = 900, height = 650;\r
if(screenSize.getWidth()<width)\r
width = screenSize.width;\r
if(screenSize.getHeight()<height)\r
public void inputLocalFileMenuItem_actionPerformed(ActionEvent e)\r
{\r
JFileChooser chooser = new JFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"));\r
+ chooser.setFileView(new JalviewFileView());\r
chooser.setDialogTitle("Open local file");\r
chooser.setToolTipText("Open");\r
int value = chooser.showOpenDialog(this);\r
int res = Integer.parseInt(searchString);\r
found = true;\r
\r
- if(av.getSelection().size()>0)\r
- seq = (Sequence)(av.getSelection().sequenceAt(0));\r
+ if(av.getSelectionGroup().getSize()>0)\r
+ seq = (Sequence)(av.getSelectionGroup().getSequenceAt(0));\r
else\r
seq = (Sequence)av.getAlignment().getSequenceAt(0);\r
\r
int end = av.alignment.getHeight();\r
\r
\r
- SequenceGroup rubberband = av.getRubberbandGroup();\r
+ SequenceGroup rubberband = av.getSelectionGroup();\r
if(rubberband!=null)\r
end = rubberband.getEndRes();\r
\r
{\r
seq = (Sequence)av.getAlignment().getSequenceAt(seqIndex);\r
\r
- if( av.getSelection().size()>0 && !av.getSelection().contains(seq)\r
+ if( av.getSelectionGroup().getSize()>0 && !av.getSelectionGroup().sequences.contains(seq)\r
|| (rubberband!=null && !rubberband.sequences.contains(seq)) )\r
{\r
// if a selection has been made, only search within that selection\r
return;\r
\r
SequenceGroup sg = (SequenceGroup)groups.elementAt(selectedGroupIndex);\r
- Selection sel = av.getSelection();\r
- for(int i=0; i<sel.size(); i++)\r
+\r
+ for(int i=0; i<av.getSelectionGroup().getSize(); i++)\r
{\r
- int index = unassignedVector.indexOf( sel.sequenceAt(i).getDisplayId() );\r
+ int index = unassignedVector.indexOf( av.getSelectionGroup().getSequenceAt(i).getDisplayId() );\r
if(index!=-1)\r
{\r
sg.addSequence( (SequenceI) sequenceHash.get( unassignedVector.elementAt(index) ));\r
\r
unassignedVector.addElement(assignedVector.elementAt(indices[i]-i));\r
SequenceI removeSequence = (SequenceI)sequenceHash.get( assignedVector.elementAt(indices[i]-i) );\r
- av.getSelection().removeElement( removeSequence );\r
+ av.getSelectionGroup().deleteSequence( removeSequence );\r
sg.deleteSequence( removeSequence );\r
assignedVector.removeElementAt(indices[i]-i);\r
\r
String id = (String)enum.nextElement();\r
unassignedVector.addElement( id );\r
SequenceI removeSequence = (SequenceI)sequenceHash.get( id );\r
- av.getSelection().removeElement( removeSequence );\r
+ av.getSelectionGroup().deleteSequence( removeSequence );\r
sg.deleteSequence( removeSequence );\r
}\r
\r
{\r
protected AlignViewport av;\r
\r
- public boolean paintFlag = false;\r
protected boolean showScores = true;\r
\r
protected int maxIdLength = -1;\r
PaintRefresher.Register(this);\r
}\r
\r
- public void drawIdString(Graphics gg,SequenceI ds,int i, int starty, int ypos) {\r
+ public void drawIdString(Graphics gg,SequenceI s,int i, int starty, int ypos) {\r
int charHeight = av.getCharHeight();\r
\r
- if (av.getSelection().contains(ds)) {\r
+\r
+ if (av.getSelectionGroup()!=null && av.getSelectionGroup().sequences.contains(s)) {\r
gg.setColor(Color.lightGray);\r
gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);\r
gg.setColor(Color.white);\r
} else {\r
- gg.setColor(ds.getColor());\r
+ gg.setColor(s.getColor());\r
gg.fillRect(0,AlignmentUtil.getPixelHeight(starty,i,charHeight)+ ypos,getWidth(),charHeight);\r
gg.setColor(Color.black);\r
}\r
\r
- String string = ds.getName() + "/" + ds.getStart() + "-" + ds.getEnd();\r
+ String string = s.getName() + "/" + s.getStart() + "-" + s.getEnd();\r
\r
gg.drawString(string,0,AlignmentUtil.getPixelHeight(starty,i,charHeight) + ypos + charHeight- (charHeight/5));\r
\r
}\r
\r
public void paintComponent(Graphics gg) {\r
- AlignmentI da = av.getAlignment();\r
- int charHeight = av.getCharHeight();\r
+ AlignmentI al = av.alignment;\r
+ int charHeight = av.charHeight;\r
gg.setFont(av.getFont());\r
\r
//Fill in the background\r
if (av.getWrapAlignment())\r
{\r
// Draw the rest of the panels\r
- int chunkHeight = (da.getHeight() + 2)*av.charHeight;\r
+ int chunkHeight = (al.getHeight() + 2)*av.charHeight;\r
int row = av.getStartRes() / av.chunkWidth ;\r
for(int ypos=2*av.charHeight;\r
- ypos <= getHeight() && row*av.chunkWidth<da.getWidth();\r
+ ypos <= getHeight() && row*av.chunkWidth<al.getWidth();\r
ypos += chunkHeight, row++ )\r
{\r
for (int i = starty; i < av.alignment.getHeight(); i++)\r
{\r
- SequenceI s = da.getSequenceAt(i);\r
+ SequenceI s = al.getSequenceAt(i);\r
drawIdString(gg, s, i, 0, ypos);\r
}\r
}\r
for (int i = starty; i < endy; i++)\r
{\r
// Selected sequence colours\r
- if (av.getSelection().contains(da.getSequenceAt(i)))\r
+\r
+ if (av.getSelectionGroup()!= null && av.getSelectionGroup().sequences.contains(al.getSequenceAt(i)))\r
{\r
+ // if(av.alignment.findGroup(al.getSequenceAt(i)).getEndRes()==\r
currentColor = Color.lightGray;\r
currentTextColor = Color.black;\r
}\r
else\r
{\r
- currentColor = da.getSequenceAt(i).getColor();\r
+ currentColor = al.getSequenceAt(i).getColor();\r
currentTextColor = Color.black;\r
}\r
\r
charHeight);\r
\r
gg.setColor(currentTextColor);\r
- String string = da.getSequenceAt(i).getDisplayId();\r
+ String string = al.getSequenceAt(i).getDisplayId();\r
gg.drawString(string, 0,\r
AlignmentUtil.getPixelHeight(starty, i, charHeight) +\r
charHeight - (charHeight / 5));\r
protected IdCanvas idCanvas;\r
protected AlignViewport av;\r
protected AlignmentPanel alignPanel;\r
+ ScrollThread scrollThread = null;\r
\r
- protected int offy;\r
- public int width;\r
- public int lastid;\r
-\r
- SequenceGroup selectedSequenceGroup;\r
+ int offy;\r
+ int width;\r
+ int lastid = -1;\r
+ boolean mouseDragging = false;\r
\r
public IdPanel(AlignViewport av, AlignmentPanel parent)\r
{\r
\r
public void mouseMoved(MouseEvent e) {}\r
\r
- public void selectSeqs(int start, int end) {\r
- if (end < start)\r
- {\r
- int tmp = start;\r
- start = end;\r
- end = tmp;\r
- }\r
-\r
- for (int i = start; i <= end; i++)\r
- {\r
- SequenceI pickedSeq = av.getAlignment().getSequenceAt(i);\r
- if (av.getSelection().contains(pickedSeq))\r
- {\r
- av.getSelection().removeElement(pickedSeq);\r
- selectedSequenceGroup.deleteSequence(pickedSeq);\r
- }\r
- else\r
- {\r
- av.getSelection().addElement(pickedSeq);\r
- if(selectedSequenceGroup==null)\r
- {\r
- selectedSequenceGroup = new SequenceGroup();\r
- av.setRubberbandGroup( selectedSequenceGroup );\r
- // av.alignment.addGroup( selectedSequenceGroup );\r
- selectedSequenceGroup.setStartRes(0);\r
- selectedSequenceGroup.setEndRes( pickedSeq.getSequence().length());\r
- }\r
-\r
- selectedSequenceGroup.addSequence( pickedSeq );\r
- }\r
-\r
- }\r
-\r
- alignPanel.seqPanel.seqCanvas.paintFlag=true;\r
- alignPanel.repaint();\r
- repaint();\r
-\r
- }\r
\r
public void mouseDragged(MouseEvent e) {\r
+ mouseDragging = true;\r
+\r
int y = e.getY();\r
if(av.getWrapAlignment())\r
y-=2*av.charHeight;\r
int seq = av.getIndex(y);\r
\r
+ if(seq<0)\r
+ return;\r
+\r
if (seq < lastid)\r
selectSeqs(lastid - 1, seq);\r
else if (seq > lastid)\r
selectSeqs(lastid + 1, seq);\r
\r
lastid = seq;\r
-\r
- return;\r
+ alignPanel.repaint();\r
}\r
\r
public void mouseClicked(MouseEvent e)\r
}\r
\r
}\r
- public void mouseEntered(MouseEvent e) { }\r
- public void mouseExited (MouseEvent e) { }\r
+ public void mouseEntered(MouseEvent e)\r
+ {\r
+ if(scrollThread!=null)\r
+ scrollThread.running = false;\r
+ }\r
+\r
+ public void mouseExited (MouseEvent e)\r
+ {\r
+ if(av.getWrapAlignment())\r
+ return;\r
+\r
+ if(mouseDragging && e.getY()<0 && av.getStartSeq()>0)\r
+ {\r
+ scrollThread = new ScrollThread(true);\r
+ }\r
+\r
+ if(mouseDragging && e.getY()>=getHeight() && av.alignment.getHeight()>av.getEndSeq())\r
+ {\r
+ scrollThread = new ScrollThread(false);\r
+ }\r
+ }\r
+\r
\r
public void mousePressed(MouseEvent e) {\r
if (e.getClickCount() == 2)\r
y-=2*av.charHeight;\r
\r
int seq = av.getIndex(y);\r
+ if (seq == -1)\r
+ return;\r
\r
if (javax.swing.SwingUtilities.isRightMouseButton(e))\r
{\r
return;\r
}\r
\r
+ if(!e.isControlDown() && !e.isShiftDown() && av.alignment.findGroup( av.alignment.getSequenceAt(seq))!=null)\r
+ {\r
\r
+ SequenceGroup selection = new SequenceGroup();\r
+ SequenceGroup sg = av.alignment.findGroup(av.alignment.getSequenceAt(seq));\r
+ selection.setStartRes(0);\r
+ selection.setEndRes(av.alignment.getWidth());\r
+ for (int i =0; i< sg.getSize(); i++)\r
+ selection.addSequence(sg.getSequenceAt(i));\r
\r
- if(av.getRubberbandGroup()!=null && (av.getRubberbandGroup().getSize() == av.getSelection().size()))\r
- selectedSequenceGroup = av.getRubberbandGroup();\r
-\r
- if (selectedSequenceGroup == null)\r
- {\r
- selectedSequenceGroup = new SequenceGroup();\r
- av.setRubberbandGroup(selectedSequenceGroup);\r
- av.getSelection().clear();\r
+ av.setSelectionGroup(selection);\r
+ return;\r
}\r
\r
- selectedSequenceGroup.setStartRes(0);\r
- selectedSequenceGroup.setEndRes(av.getAlignment().getWidth() - 1);\r
+ if(av.getSelectionGroup()==null || ( !e.isControlDown() && av.getSelectionGroup()!=null))\r
+ av.setSelectionGroup(new SequenceGroup());\r
\r
- if (seq != -1)\r
- selectSeqs(seq, seq);\r
+ av.getSelectionGroup().setStartRes(0);\r
+ av.getSelectionGroup().setEndRes(av.alignment.getWidth());\r
\r
- lastid = seq;\r
+ if(e.isShiftDown() && lastid!=-1)\r
+ selectSeqs(lastid, seq);\r
+ else\r
+ selectSeq(seq);\r
\r
+ alignPanel.seqPanel.seqCanvas.paintFlag=true;\r
+ alignPanel.repaint();\r
+ repaint();\r
+ }\r
\r
- return;\r
+ void selectSeq(int seq)\r
+ {\r
+ lastid = seq;\r
+ SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq);\r
+ av.getSelectionGroup().addOrRemove(pickedSeq);\r
}\r
\r
+ void selectSeqs(int start, int end) {\r
+\r
+ lastid = start;\r
+ if (end < start)\r
+ {\r
+ int tmp = start;\r
+ start = end;\r
+ end = tmp;\r
+ lastid = end;\r
+ }\r
+\r
+ for (int i = start; i <= end; i++)\r
+ av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i));\r
+\r
+ }\r
+\r
+\r
public void mouseReleased(MouseEvent e)\r
{\r
- lastid = -1;\r
+ if(scrollThread!=null)\r
+ scrollThread.running = false;\r
+\r
+ mouseDragging = false;\r
PaintRefresher.Refresh(this);\r
- selectedSequenceGroup = null;\r
}\r
+\r
+ // this class allows scrolling off the bottom of the visible alignment\r
+ class ScrollThread\r
+ extends Thread\r
+ {\r
+ boolean running = false;\r
+ boolean up = true;\r
+ public ScrollThread(boolean up)\r
+ {\r
+ this.up = up;\r
+ start();\r
+ }\r
+\r
+ public void stopScrolling()\r
+ {\r
+ running = false;\r
+ }\r
+\r
+ public void run()\r
+ {\r
+ running = true;\r
+ while (running)\r
+ {\r
+ if(alignPanel.scrollUp(up))\r
+ {\r
+ // scroll was ok, so add new sequence to selection\r
+ int seq = av.getStartSeq();\r
+ if(!up)\r
+ seq = av.getEndSeq();\r
+\r
+ if (seq < lastid)\r
+ selectSeqs(lastid - 1, seq);\r
+ else if (seq > lastid)\r
+ selectSeqs(lastid + 1, seq);\r
+\r
+ lastid = seq;\r
+ }\r
+ else\r
+ running = false;\r
+\r
+ alignPanel.repaint();\r
+ try\r
+ {\r
+ Thread.sleep(100);\r
+ }\r
+ catch (Exception ex)\r
+ {}\r
+ }\r
+ }\r
+}\r
+\r
}\r
public PCAPanel(AlignViewport av, SequenceI[] s) {\r
\r
this.av = av;\r
- if(av.getSelection().size()>3)\r
+ if(av.getSelectionGroup().getSize()>3)\r
{\r
- s = new Sequence[av.getSelection().size()];\r
+ s = new Sequence[av.getSelectionGroup().getSize()];\r
for(int i=0; i<s.length; i++)\r
- s[i] = av.getSelection().sequenceAt(i);\r
+ s[i] = av.getSelectionGroup().getSequenceAt(i);\r
}\r
\r
\r
this.av = av;\r
float scores[][] = new float[av.getAlignment().getHeight()][av.getAlignment().getHeight()];\r
double totscore = 0;\r
- int count = av.getSelection().size();\r
+ int count = av.getSelectionGroup().getSize();\r
\r
int acount = 0;\r
for (int i = 1; i < count; i++)\r
for (int j = 0; j < i; j++)\r
{\r
acount++;\r
- AlignSeq as = new AlignSeq(av.getSelection().sequenceAt(i),av.getSelection().sequenceAt(j),"pep");\r
+ AlignSeq as = new AlignSeq(av.getSelectionGroup().getSequenceAt(i),\r
+ av.getSelectionGroup().getSequenceAt(j),"pep");\r
\r
as.calcScoreMatrix();\r
as.traceAlignment();\r
catch(Exception e)\r
{ e.printStackTrace(); }\r
\r
- SequenceGroup sg = ap.av.getRubberbandGroup();\r
+ SequenceGroup sg = ap.av.getSelectionGroup();\r
if(sg!=null)\r
{\r
groupName.setText(sg.getName());\r
if( superG !=null)\r
superG.setSuperGroupProperties( sg );\r
\r
-\r
- //once group is defined, remove selection rubberband\r
- ap.av.setRubberbandGroup(null);\r
-\r
ap.seqPanel.seqCanvas.paintFlag=true;\r
ap.seqPanel.repaint();\r
}\r
\r
SequenceGroup getGroup()\r
{\r
- SequenceGroup sg = ap.av.getRubberbandGroup();\r
+ SequenceGroup sg = ap.av.getSelectionGroup();\r
\r
// this method won't add a new group if it already exists\r
ap.av.alignment.addGroup(sg);\r
\r
void unGroupMenuItem_actionPerformed(ActionEvent e)\r
{\r
- SequenceGroup sg = ap.av.getRubberbandGroup();\r
+ SequenceGroup sg = ap.av.getSelectionGroup();\r
ap.av.alignment.deleteGroup(sg);\r
- ap.av.setRubberbandGroup(null);\r
+ ap.av.setSelectionGroup(null);\r
ap.RefreshPanels();\r
}\r
\r
\r
undoButton.setEnabled(true);\r
\r
- if (ap.av.sel != null && ap.av.sel.size() > 1)\r
+ SequenceGroup sg = ap.av.getSelectionGroup();\r
+ if (sg != null && sg.getSize() > 1)\r
{\r
\r
- del = ap.av.alignment.removeRedundancy(threshold, ap.av.sel.asVector());\r
+ del = ap.av.alignment.removeRedundancy(threshold, sg.sequences);\r
for (int i = 0; i < del.size(); i++)\r
- if (ap.av.sel.contains( (SequenceI) del.elementAt(i)))\r
- ap.av.sel.removeElement( (SequenceI) del.elementAt(i));\r
+ if (sg.sequences.contains( (SequenceI) del.elementAt(i)))\r
+ sg.deleteSequence( (SequenceI) del.elementAt(i));\r
\r
}\r
else\r
del = ap.av.alignment.removeRedundancy(threshold,s);\r
for (int j=0; j < del.size(); j++)\r
{\r
- if (ap.av.sel.contains((SequenceI)del.elementAt(j)))\r
- ap.av.sel.removeElement((SequenceI)del.elementAt(j));\r
+ if (sg.sequences.contains((SequenceI)del.elementAt(j)))\r
+ sg.deleteSequence((SequenceI)del.elementAt(j));\r
\r
}\r
}\r
g.setColor(sp.sequence.getColor());\r
\r
\r
- if (av != null)\r
+ if (av.getSelectionGroup() != null)\r
{\r
- if (av.getSelection().contains(((SequencePoint)points.elementAt(i)).sequence))\r
+ if (av.getSelectionGroup().sequences.contains(((SequencePoint)points.elementAt(i)).sequence))\r
g.setColor(Color.gray);\r
}\r
if (z < 0)\r
\r
SequenceI found = findPoint(x,y);\r
\r
- if (found != null) {\r
- if (av != null) {\r
-\r
- if (av.getSelection().contains(found)) {\r
- av.getSelection().removeElement(found);\r
- } else {\r
- av.getSelection().addElement(found);\r
- }\r
+ if (found != null)\r
+ {\r
+ if (av.getSelectionGroup() != null)\r
+ {\r
+ av.getSelectionGroup().addOrRemove(found);\r
PaintRefresher.Refresh(this);\r
}\r
+ else\r
+ {\r
+ av.setSelectionGroup(new SequenceGroup());\r
+ av.getSelectionGroup().addOrRemove(found);\r
+ av.getSelectionGroup().setEndRes(av.alignment.getWidth());\r
+\r
+ }\r
}\r
repaint();\r
}\r
\r
if (tmp1 > x1 && tmp1 < x2 && tmp2 > y1 && tmp2 < y2) {\r
if (av != null) {\r
- if (!av.getSelection().contains(sp.sequence)) {\r
+ if (!av.getSelectionGroup().sequences.contains(sp.sequence))\r
+ {\r
changedSel = true;\r
- av.getSelection().addElement(sp.sequence);\r
+ av.getSelectionGroup().addSequence(sp.sequence);\r
}\r
}\r
}\r
sg.setStartRes(res);\r
sg.setEndRes(res);\r
}\r
- av.setRubberbandGroup(sg);\r
+ av.setSelectionGroup(sg);\r
ap.RefreshPanels();\r
}\r
\r
if (! av.getColumnSelection().contains(res))\r
av.getColumnSelection().addElement(res);\r
\r
- SequenceGroup sg = av.getRubberbandGroup();\r
+ SequenceGroup sg = av.getSelectionGroup();\r
\r
if(res>sg.getStartRes())\r
sg.setEndRes(res);\r
int x = evt.getX();\r
int res = x/av.getCharWidth() + av.getStartRes();\r
\r
- SequenceGroup sg = av.getRubberbandGroup();\r
+ SequenceGroup sg = av.getSelectionGroup();\r
if(sg!=null)\r
{\r
stretchingGroup = true;\r
+++ /dev/null
-package jalview.gui;\r
-\r
-import jalview.datamodel.*;\r
-\r
-import java.util.*;\r
-\r
-public class Selection\r
-{\r
-\r
- Vector selected = new Vector();\r
- AlignViewport av;\r
-\r
- public Selection(AlignViewport av)\r
- {\r
- this.av = av;\r
- }\r
-\r
- public void addElement(SequenceI seq) {\r
- selected.addElement(seq);\r
- SequenceGroup sg = av.getRubberbandGroup();\r
- if(sg==null)\r
- {\r
- sg = new SequenceGroup();\r
- sg.setEndRes(av.alignment.getWidth()-1);\r
- av.setRubberbandGroup(sg);\r
- }\r
-\r
- sg.addSequence(seq);\r
-\r
- }\r
-\r
- public void clear() {\r
- selected.removeAllElements();\r
- }\r
-\r
- public void removeElement(SequenceI seq) {\r
- if (selected.contains(seq))\r
- selected.removeElement(seq);\r
- else\r
- System.err.println("WARNING: Tried to remove SequenceI NOT in Selection");\r
-\r
- SequenceGroup sg = av.getRubberbandGroup();\r
- if (sg != null)\r
- sg.deleteSequence(seq);\r
-\r
-\r
- }\r
-\r
- public boolean contains(SequenceI seq) {\r
- return selected.contains(seq);\r
- }\r
-\r
- public SequenceI sequenceAt(int i) {\r
- return (SequenceI)selected.elementAt(i);\r
- }\r
-\r
- public int size() {\r
- return selected.size();\r
- }\r
-\r
- public Vector asVector() {\r
- return selected;\r
- }\r
-\r
- public void selectAll(AlignmentI align) {\r
- for (int i=0;i<align.getSequences().size();i++) {\r
- SequenceI seq = align.getSequenceAt(i);\r
- if (!contains(seq)) {\r
- addElement(seq);\r
- }\r
- }\r
- }\r
-}\r
else\r
inGroup = false;\r
\r
- group = av.getRubberbandGroup();\r
+ group = av.getSelectionGroup();\r
if( group != null && group.sequences.contains(nextSeq) )\r
{\r
g.setColor(Color.RED.brighter());\r
// if character is inserted or deleted, we will need to recalculate the conservation\r
int seqEditOccurred = -1;\r
\r
+ ScrollThread scrollThread = null;\r
+ boolean mouseDragging = false;\r
+\r
+\r
public SeqPanel(AlignViewport avp, AlignmentPanel p) {\r
this.av = avp;\r
\r
else\r
doMousePressedDefineMode(evt);\r
}\r
+ public void mouseExited(MouseEvent evt)\r
+ {\r
+ if (av.getWrapAlignment() || evt.isShiftDown() || evt.isAltDown() ||\r
+ evt.isControlDown())\r
+ return;\r
+ doMouseExitedDefineMode(evt);\r
+\r
+ }\r
+ public void mouseEntered(MouseEvent evt)\r
+ {\r
+ if (av.getWrapAlignment() || evt.isShiftDown() || evt.isAltDown() ||\r
+ evt.isControlDown())\r
+ return;\r
+ doMouseEnteredDefineMode(evt);\r
+ }\r
\r
});\r
repaint();\r
if(res>sequence.getLength())\r
return;\r
\r
- stretchGroup = av.getRubberbandGroup();\r
+ stretchGroup = av.getSelectionGroup();\r
\r
if(stretchGroup == null)\r
{\r
stretchGroup = av.alignment.findGroup( sequence );\r
- av.setRubberbandGroup( stretchGroup );\r
+ av.setSelectionGroup( stretchGroup );\r
}\r
\r
else if(!stretchGroup.sequences.contains(sequence)\r
allGroups[i].getEndRes() >= res)\r
{\r
stretchGroup = allGroups[i];\r
- av.setRubberbandGroup(stretchGroup);\r
+ av.setSelectionGroup(stretchGroup);\r
break;\r
}\r
}\r
sg.setStartRes(res);\r
sg.setEndRes(res);\r
sg.addSequence( sequence );\r
- av.setRubberbandGroup( sg );\r
+ av.setSelectionGroup( sg );\r
stretchGroup = sg;\r
\r
if(av.getConservationSelected())\r
\r
public void doMouseReleasedDefineMode(MouseEvent evt)\r
{\r
+ mouseDragging = false;\r
+\r
if(stretchGroup==null)\r
return;\r
\r
changeEndRes = false;\r
changeStartRes = false;\r
stretchGroup = null;\r
+ ap.idPanel.repaint();\r
}\r
\r
\r
stretchGroup.setStartRes( res );\r
}\r
\r
-\r
int dragDirection = 0;\r
if (y > oldSeq)\r
dragDirection = 1;\r
else if (y < oldSeq)\r
dragDirection = -1;\r
\r
- while (y != oldSeq)\r
+ while (y != oldSeq && oldSeq>0)\r
{\r
// This routine ensures we don't skip any sequences, as the\r
// selection is quite slow.\r
}\r
}\r
oldSeq = y;\r
+ mouseDragging = true;\r
+ if(scrollThread!=null)\r
+ scrollThread.setEvent(evt);\r
\r
seqCanvas.paintFlag = true;\r
repaint();\r
}\r
\r
+ public void doMouseEnteredDefineMode(MouseEvent e)\r
+ {\r
+ if (scrollThread != null)\r
+ scrollThread.running = false;\r
+ }\r
+\r
+ public void doMouseExitedDefineMode(MouseEvent e)\r
+ {\r
+ if (av.getWrapAlignment())\r
+ return;\r
+\r
+ if(mouseDragging)\r
+ scrollThread = new ScrollThread();\r
+\r
+ }\r
+ // this class allows scrolling off the bottom of the visible alignment\r
+ class ScrollThread extends Thread\r
+ {\r
+ MouseEvent evt;\r
+ boolean running = false;\r
+ public ScrollThread()\r
+ {\r
+ start();\r
+ }\r
+\r
+ public void setEvent(MouseEvent e)\r
+ {\r
+ evt = e;\r
+ }\r
+\r
+ public void stopScrolling()\r
+ {\r
+ running = false;\r
+ }\r
+\r
+ public void run()\r
+ {\r
+ running = true;\r
+ while (running)\r
+ {\r
+ if(evt!=null)\r
+ {\r
+\r
+ if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0)\r
+ running = ap.scrollUp(true);\r
+\r
+ if (mouseDragging && evt.getY() >= getHeight() &&\r
+ av.alignment.getHeight() > av.getEndSeq())\r
+ running = ap.scrollUp(false);\r
+\r
+ if (mouseDragging && evt.getX() < 0)\r
+ running = ap.scrollRight(true);\r
+\r
+ else if (mouseDragging && evt.getX() >= getWidth())\r
+ running = ap.scrollRight(false);\r
+ }\r
+\r
+ ap.repaint();\r
+ try\r
+ {\r
+ Thread.sleep(75);\r
+ }\r
+ catch (Exception ex)\r
+ {}\r
+ }\r
+ }\r
+}\r
+\r
+\r
\r
}\r
\r
if(av.getColourText())\r
{\r
getBoxColour(av.getGlobalColourScheme(), seq, i);\r
- graphics.setColor(resBoxColour.darker());\r
+ if(av.getShowBoxes())\r
+ graphics.setColor(resBoxColour.darker());\r
+ else\r
+ graphics.setColor(resBoxColour);\r
}\r
}\r
\r
\r
while( visible )\r
{\r
- if( System.currentTimeMillis()/1000 - startTime > 8)\r
+ if( System.currentTimeMillis()/1000 - startTime > 5)\r
visible = false;\r
\r
try{\r
\r
//RubberbandRectangle rubberband;\r
\r
- Selection selected;\r
Vector listeners;\r
\r
Hashtable nameHash = new Hashtable();\r
{\r
this.av = av;\r
this.tree = tree;\r
- selected = av.getSelection();\r
scrollPane = scroller;\r
addMouseListener(this);\r
tree.findHeight(tree.getTopNode());\r
}\r
public void TreeSelectionChanged(Sequence sequence)\r
{\r
- selected = av.getSelection();\r
+ SequenceGroup selected = av.getSelectionGroup();\r
+ if(selected == null)\r
+ {\r
+ selected = new SequenceGroup();\r
+ av.setSelectionGroup(selected);\r
+ }\r
+\r
+ selected.setEndRes(av.alignment.getWidth());\r
+ selected.addOrRemove(sequence);\r
\r
- if (selected.contains(sequence))\r
- selected.removeElement(sequence);\r
- else\r
- selected.addElement(sequence);\r
\r
- setSelected(selected);\r
PaintRefresher.Refresh(this);\r
repaint();\r
}\r
\r
\r
- public void setSelected(Selection selected)\r
- {\r
- this.selected = selected;\r
- }\r
\r
public void setTree(NJTree tree) {\r
this.tree = tree;\r
\r
nameHash.put((SequenceI)node.element(),rect);\r
\r
- if (selected.contains((SequenceI)node.element())) {\r
+ SequenceGroup selected = av.getSelectionGroup();\r
+ if (selected!=null && selected.sequences.contains((SequenceI)node.element())) {\r
g.setColor(Color.gray);\r
\r
g.fillRect(xend + 10, ypos - charHeight + 3,charWidth,charHeight);\r
\r
}\r
\r
- public void pickNodes(Rectangle pickBox, Selection sel) {\r
+ public void pickNodes(Rectangle pickBox) {\r
int width = getWidth();\r
int height = getHeight();\r
\r
}\r
float chunk = (float)(height-offy*2)/top.count;\r
\r
- pickNode(pickBox,sel,top,chunk,wscale,width,offx,offy);\r
+ pickNode(pickBox,top,chunk,wscale,width,offx,offy);\r
}\r
\r
- public void pickNode(Rectangle pickBox, Selection sel, SequenceNode node, float chunk, float scale, int width,int offx, int offy) {\r
+ public void pickNode(Rectangle pickBox, SequenceNode node, float chunk, float scale, int width,int offx, int offy) {\r
if (node == null) {\r
return;\r
}\r
if (pickBox.contains(new Point(xend,ypos))) {\r
if (node.element() instanceof SequenceI) {\r
SequenceI seq = (SequenceI)node.element();\r
- if (sel.contains(seq)) {\r
- sel.removeElement(seq);\r
- } else {\r
- sel.addElement(seq);\r
- }\r
+ SequenceGroup sg = av.getSelectionGroup();\r
+ if(sg!=null)\r
+ sg.addOrRemove(seq);\r
}\r
}\r
} else {\r
- pickNode(pickBox,sel,(SequenceNode)node.left(), chunk,scale,width,offx,offy);\r
- pickNode(pickBox,sel,(SequenceNode)node.right(),chunk,scale,width,offx,offy);\r
+ pickNode(pickBox,(SequenceNode)node.left(), chunk,scale,width,offx,offy);\r
+ pickNode(pickBox,(SequenceNode)node.right(),chunk,scale,width,offx,offy);\r
}\r
}\r
\r
\r
public void paintComponent(Graphics g)\r
{\r
+\r
font = new Font("Verdana",Font.PLAIN,fontSize);\r
g.setFont(font);\r
\r
tree.groupNodes(tree.getTopNode(),fthreshold);\r
setColor(tree.getTopNode(),Color.black);\r
\r
- av.sel.clear();\r
+ av.setSelectionGroup(null);\r
av.alignment.deleteAllGroups();\r
\r
for (int i=0; i < tree.getGroups().size(); i++)\r
{\r
SequenceNode sn = (SequenceNode) l.elementAt(j);\r
if(sg==null)\r
- sg = new SequenceGroup("TreeGroup", av.getGlobalColourScheme(), true, true,false,0,av.alignment.getWidth());\r
+ sg = new SequenceGroup("TreeGroup", av.getGlobalColourScheme(), true, true,false,0,av.alignment.getWidth());\r
\r
sg.addSequence( (Sequence) sn.element());\r
}\r
protected void loadbutton_actionPerformed(ActionEvent e)\r
{\r
JFileChooser chooser = new JFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"));\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
chooser.setDialogTitle("Load colour scheme");\r
chooser.setToolTipText("Load");\r
int value = chooser.showOpenDialog(this);\r
protected void savebutton_actionPerformed(ActionEvent e)\r
{\r
JFileChooser chooser = new JFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"));\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
chooser.setDialogTitle("Save colour scheme");\r
chooser.setToolTipText("Save");\r
int value = chooser.showSaveDialog(this);\r