X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fappletgui%2FAlignFrame.java;h=604da7b405a585062b0fcd0e0d8621d96d102202;hb=22b7f97726482cb0ee32389811126e62aaead61d;hp=d1b2da99185f0add4f6f9999011ebd774f18a772;hpb=8f599b2d8da5ad8ccfcd42139e1b6f170bc3ad0f;p=jalview.git diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index d1b2da9..604da7b 100755 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,6 +23,7 @@ import jalview.schemes.*; import jalview.datamodel.*; import jalview.analysis.*; import jalview.io.*; +import jalview.commands.*; import java.awt.*; import java.awt.event.*; import java.util.*; @@ -36,9 +37,8 @@ public class AlignFrame extends Frame implements ActionListener, { public AlignmentPanel alignPanel; public AlignViewport viewport; - int NEW_WINDOW_WIDTH = 700; - int NEW_WINDOW_HEIGHT = 500; - jalview.bin.JalviewLite applet; + int DEFAULT_WIDTH = 700; + int DEFAULT_HEIGHT = 500; String jalviewServletURL; @@ -58,10 +58,12 @@ public class AlignFrame extends Frame implements ActionListener, ex.printStackTrace(); } - this.applet = applet; viewport = new AlignViewport(al, applet); alignPanel = new AlignmentPanel(this, viewport); + viewport.updateConservation(alignPanel); + viewport.updateConsensus(alignPanel); + annotationPanelMenuItem.setState(viewport.showAnnotation); seqLimits.setState(viewport.showJVSuffix); @@ -93,13 +95,13 @@ public class AlignFrame extends Frame implements ActionListener, if (param != null) { int width = Integer.parseInt(param); - NEW_WINDOW_WIDTH = width; + DEFAULT_WIDTH = width; } param = applet.getParameter("windowHeight"); if (param != null) { int height = Integer.parseInt(param); - NEW_WINDOW_HEIGHT = height; + DEFAULT_HEIGHT = height; } } catch (Exception ex) @@ -112,17 +114,8 @@ public class AlignFrame extends Frame implements ActionListener, this.addKeyListener(this); alignPanel.seqPanel.seqCanvas.addKeyListener(this); alignPanel.idPanel.idCanvas.addKeyListener(this); - - viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener() - { - public void propertyChange(java.beans.PropertyChangeEvent evt) - { - if (evt.getPropertyName().equals("alignment")) - { - alignmentChanged(); - } - } - }); + alignPanel.scalePanel.addKeyListener(this); + alignPanel.annotationPanel.addKeyListener(this); if(embedded) @@ -132,8 +125,8 @@ public class AlignFrame extends Frame implements ActionListener, else { add(alignPanel, BorderLayout.CENTER); - jalview.bin.JalviewLite.addFrame(this, title, NEW_WINDOW_WIDTH, - NEW_WINDOW_HEIGHT); + jalview.bin.JalviewLite.addFrame(this, title, DEFAULT_WIDTH, + DEFAULT_HEIGHT); } alignPanel.validate(); alignPanel.repaint(); @@ -215,9 +208,9 @@ public class AlignFrame extends Frame implements ActionListener, } break; case KeyEvent.VK_V: - if (evt.isControlDown() || evt.isMetaDown()) + if (evt.isControlDown()) { - paste(true); + paste(evt.isShiftDown()); } break; case KeyEvent.VK_A: @@ -260,7 +253,10 @@ public class AlignFrame extends Frame implements ActionListener, case KeyEvent.VK_SPACE: if(viewport.cursorMode) { - alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()); + alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown() + || evt.isShiftDown() + || evt.isAltDown() + ); } break; @@ -268,7 +264,9 @@ public class AlignFrame extends Frame implements ActionListener, case KeyEvent.VK_BACK_SPACE: if(viewport.cursorMode) { - alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()); + alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown() + || evt.isShiftDown() + || evt.isAltDown()); } else { @@ -320,7 +318,6 @@ public class AlignFrame extends Frame implements ActionListener, alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes; alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq; } - alignPanel.seqPanel.seqCanvas.repaint(); break; case KeyEvent.VK_F: @@ -329,7 +326,114 @@ public class AlignFrame extends Frame implements ActionListener, findMenuItem_actionPerformed(); } break; - } + + case KeyEvent.VK_H: + { + boolean toggleSeqs = !evt.isControlDown(); + boolean toggleCols = !evt.isShiftDown(); + boolean hide = false; + SequenceGroup sg = viewport.getSelectionGroup(); + + if(toggleSeqs) + { + if (sg != null && sg.getSize(false) != viewport.alignment.getHeight()) + { + hide = true; + viewport.hideAllSelectedSeqs(); + } + else if (!(toggleCols && viewport.colSel.getSelected().size() > 0)) + viewport.showAllHiddenSeqs(); + } + + if(toggleCols) + { + if (viewport.colSel.getSelected().size() > 0) + { + viewport.hideSelectedColumns(); + if(!toggleSeqs) + viewport.selectionGroup = sg; + } + else if (!hide) + viewport.showAllHiddenColumns(); + } + break; + } + + case KeyEvent.VK_PAGE_UP: + if (viewport.wrapAlignment) + alignPanel.scrollUp(true); + else + alignPanel.setScrollValues(viewport.startRes, + viewport.startSeq + - viewport.endSeq + viewport.startSeq); + break; + + case KeyEvent.VK_PAGE_DOWN: + if (viewport.wrapAlignment) + alignPanel.scrollUp(false); + else + alignPanel.setScrollValues(viewport.startRes, + viewport.startSeq + + viewport.endSeq - viewport.startSeq); + break; + + case KeyEvent.VK_Z: + if (evt.isControlDown()) + { + undoMenuItem_actionPerformed(); + } + break; + + case KeyEvent.VK_Y: + if (evt.isControlDown()) + { + redoMenuItem_actionPerformed(); + } + break; + + case KeyEvent.VK_L: + if (evt.isControlDown()) + { + trimAlignment(true); + } + break; + + case KeyEvent.VK_R: + if (evt.isControlDown()) + { + trimAlignment(false); + } + break; + + case KeyEvent.VK_E: + if (evt.isControlDown()) + { + if (evt.isShiftDown()) + this.removeAllGapsMenuItem_actionPerformed(); + else + removeGappedColumnMenuItem_actionPerformed(); + } + break; + case KeyEvent.VK_I: + if (evt.isControlDown()) + { + if (evt.isAltDown()) + viewport.invertColumnSelection(); + else + this.invertSequenceMenuItem_actionPerformed(); + } + break; + + case KeyEvent.VK_U: + if (evt.isControlDown()) + { + this.deleteGroups_actionPerformed(); + } + break; + + + } + alignPanel.repaint(); } public void keyReleased(KeyEvent evt) {} @@ -374,117 +478,137 @@ public void itemStateChanged(ItemEvent evt) } public void actionPerformed(ActionEvent evt) { - if(evt.getSource()==inputText) + Object source = evt.getSource(); + + if(source==inputText) inputText_actionPerformed(); - else if(evt.getSource()==loadTree) + else if(source==loadTree) loadTree_actionPerformed(); - else if(evt.getSource()==loadApplication) + else if(source==loadApplication) launchFullApplication(); - else if(evt.getSource()==closeMenuItem) + else if(source==closeMenuItem) closeMenuItem_actionPerformed(); - else if(evt.getSource()==copy) + else if(source==copy) copy_actionPerformed(); - else if(evt.getSource()==undoMenuItem) + else if(source==undoMenuItem) undoMenuItem_actionPerformed(); - else if(evt.getSource()==redoMenuItem) + else if(source==redoMenuItem) redoMenuItem_actionPerformed(); - else if(evt.getSource()==inputText) + else if(source==inputText) inputText_actionPerformed(); - else if(evt.getSource()==closeMenuItem) + else if(source==closeMenuItem) closeMenuItem_actionPerformed(); - else if(evt.getSource()==undoMenuItem) + else if(source==undoMenuItem) undoMenuItem_actionPerformed(); - else if(evt.getSource()==redoMenuItem) + else if(source==redoMenuItem) redoMenuItem_actionPerformed(); - else if(evt.getSource()==copy) + else if(source==copy) copy_actionPerformed(); - else if(evt.getSource()==pasteNew) + else if(source==pasteNew) pasteNew_actionPerformed(); - else if(evt.getSource()==pasteThis) + else if(source==pasteThis) pasteThis_actionPerformed(); - else if(evt.getSource()==cut) + else if(source==cut) cut_actionPerformed(); - else if(evt.getSource()==delete) + else if(source==delete) delete_actionPerformed(); - else if(evt.getSource()==deleteGroups) + else if(source==deleteGroups) deleteGroups_actionPerformed(); - else if(evt.getSource()==selectAllSequenceMenuItem) + else if(source==selectAllSequenceMenuItem) selectAllSequenceMenuItem_actionPerformed(); - else if(evt.getSource()==deselectAllSequenceMenuItem) + else if(source==deselectAllSequenceMenuItem) deselectAllSequenceMenuItem_actionPerformed(); - else if(evt.getSource()==invertSequenceMenuItem) + else if(source==invertSequenceMenuItem) invertSequenceMenuItem_actionPerformed(); - else if(evt.getSource()==remove2LeftMenuItem) - remove2LeftMenuItem_actionPerformed(); - else if(evt.getSource()==remove2RightMenuItem) - remove2RightMenuItem_actionPerformed(); - else if(evt.getSource()==removeGappedColumnMenuItem) + else if(source==invertColSel) + { viewport.invertColumnSelection(); alignPanel.repaint(); } + else if(source==remove2LeftMenuItem) + trimAlignment(true); + else if(source==remove2RightMenuItem) + trimAlignment(false); + else if(source==removeGappedColumnMenuItem) removeGappedColumnMenuItem_actionPerformed(); - else if(evt.getSource()==removeAllGapsMenuItem) + else if(source==removeAllGapsMenuItem) removeAllGapsMenuItem_actionPerformed(); - else if(evt.getSource()==findMenuItem) + else if(source==findMenuItem) findMenuItem_actionPerformed(); - else if(evt.getSource()==font) + else if(source==font) font_actionPerformed(); - else if(evt.getSource()==featureSettings) + else if(source==showColumns) + { + viewport.showAllHiddenColumns(); alignPanel.repaint(); + } + else if(source==showSeqs) + { + viewport.showAllHiddenSeqs(); + } + else if(source == hideColumns) + { + viewport.hideSelectedColumns(); alignPanel.repaint(); + } + else if(source == hideSequences && viewport.getSelectionGroup()!=null) + { + viewport.hideAllSelectedSeqs(); + } + else if(source==featureSettings) featureSettings_actionPerformed(); - else if(evt.getSource()==overviewMenuItem) + else if(source==overviewMenuItem) overviewMenuItem_actionPerformed(); - else if(evt.getSource()==noColourmenuItem) + else if(source==noColourmenuItem) noColourmenuItem_actionPerformed(); - else if(evt.getSource()==clustalColour) + else if(source==clustalColour) clustalColour_actionPerformed(); - else if(evt.getSource()==zappoColour) + else if(source==zappoColour) zappoColour_actionPerformed(); - else if(evt.getSource()==taylorColour) + else if(source==taylorColour) taylorColour_actionPerformed(); - else if(evt.getSource()==hydrophobicityColour) + else if(source==hydrophobicityColour) hydrophobicityColour_actionPerformed(); - else if(evt.getSource()==helixColour) + else if(source==helixColour) helixColour_actionPerformed(); - else if(evt.getSource()==strandColour) + else if(source==strandColour) strandColour_actionPerformed(); - else if(evt.getSource()==turnColour) + else if(source==turnColour) turnColour_actionPerformed(); - else if(evt.getSource()==buriedColour) + else if(source==buriedColour) buriedColour_actionPerformed(); - else if(evt.getSource()==nucleotideColour) + else if(source==nucleotideColour) nucleotideColour_actionPerformed(); - else if(evt.getSource()==modifyPID) + else if(source==modifyPID) modifyPID_actionPerformed(); - else if(evt.getSource()==modifyConservation) + else if(source==modifyConservation) modifyConservation_actionPerformed(); - else if(evt.getSource()==userDefinedColour) + else if(source==userDefinedColour) userDefinedColour_actionPerformed(); - else if(evt.getSource()==PIDColour) + else if(source==PIDColour) PIDColour_actionPerformed(); - else if(evt.getSource()==BLOSUM62Colour) + else if(source==BLOSUM62Colour) BLOSUM62Colour_actionPerformed(); - else if(evt.getSource()==annotationColour) + else if(source==annotationColour) new AnnotationColourChooser(viewport, alignPanel); - else if(evt.getSource()==sortPairwiseMenuItem) + else if(source==sortPairwiseMenuItem) sortPairwiseMenuItem_actionPerformed(); - else if(evt.getSource()==sortIDMenuItem) + else if(source==sortIDMenuItem) sortIDMenuItem_actionPerformed(); - else if(evt.getSource()==sortGroupMenuItem) + else if(source==sortGroupMenuItem) sortGroupMenuItem_actionPerformed(); - else if(evt.getSource()==removeRedundancyMenuItem) + else if(source==removeRedundancyMenuItem) removeRedundancyMenuItem_actionPerformed(); - else if(evt.getSource()==pairwiseAlignmentMenuItem) + else if(source==pairwiseAlignmentMenuItem) pairwiseAlignmentMenuItem_actionPerformed(); - else if(evt.getSource()==PCAMenuItem) + else if(source==PCAMenuItem) PCAMenuItem_actionPerformed(); - else if(evt.getSource()==averageDistanceTreeMenuItem) + else if(source==averageDistanceTreeMenuItem) averageDistanceTreeMenuItem_actionPerformed(); - else if(evt.getSource()==neighbourTreeMenuItem) + else if(source==neighbourTreeMenuItem) neighbourTreeMenuItem_actionPerformed(); - else if(evt.getSource()==njTreeBlosumMenuItem) + else if(source==njTreeBlosumMenuItem) njTreeBlosumMenuItem_actionPerformed(); - else if(evt.getSource()==avDistanceTreeBlosumMenuItem) + else if(source==avDistanceTreeBlosumMenuItem) avTreeBlosumMenuItem_actionPerformed(); - else if(evt.getSource()==documentation) + else if(source==documentation) documentation_actionPerformed(); - else if(evt.getSource()==about) + else if(source==about) about_actionPerformed(); } @@ -499,7 +623,7 @@ public void itemStateChanged(ItemEvent evt) protected void outputText_actionPerformed(ActionEvent e) { - CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this); + CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this); Frame frame = new Frame(); frame.add(cap); jalview.bin.JalviewLite.addFrame(frame, @@ -515,25 +639,37 @@ public void itemStateChanged(ItemEvent evt) StringBuffer url = new StringBuffer(jalviewServletURL); url.append("?open="+ - appendProtocol( applet.getParameter("file") ) ); + appendProtocol( viewport.applet.getParameter("file") ) ); - if(applet.getParameter("features")!=null) + if(viewport.applet.getParameter("features")!=null) { url.append( "&features=" ); - url.append( appendProtocol( applet.getParameter("features") ) ); + url.append( appendProtocol( viewport.applet.getParameter("features") ) ); + } + + if(viewport.applet.getParameter("annotations")!=null) + { + url.append( "&annotations=" ); + url.append( appendProtocol( viewport.applet.getParameter("annotations") ) ); + } + + if(viewport.applet.getParameter("jnetfile")!=null) + { + url.append( "&annotations=" ); + url.append( appendProtocol( viewport.applet.getParameter("jnetfile") ) ); } - if(applet.getParameter("defaultColour")!=null) + if(viewport.applet.getParameter("defaultColour")!=null) { url.append("&colour=" + - removeWhiteSpace(applet.getParameter("defaultColour")) + removeWhiteSpace(viewport.applet.getParameter("defaultColour")) ); } - if(applet.getParameter("userDefinedColour")!=null) + if(viewport.applet.getParameter("userDefinedColour")!=null) { url.append( "&colour=" + - removeWhiteSpace( applet.getParameter("userDefinedColour") ) + removeWhiteSpace( viewport.applet.getParameter("userDefinedColour") ) ); } @@ -562,7 +698,7 @@ public void itemStateChanged(ItemEvent evt) new URL(url); }catch(java.net.MalformedURLException ex) { - url = applet.getCodeBase()+url; + url = viewport.applet.getCodeBase()+url; } return url; } @@ -570,22 +706,24 @@ public void itemStateChanged(ItemEvent evt) public void closeMenuItem_actionPerformed() { PaintRefresher.components.remove(viewport.alignment); - if(PaintRefresher.components.size()==0 && applet==null) + if(PaintRefresher.components.size()==0 && viewport.applet==null) System.exit(0); this.dispose(); } - Stack historyList = new Stack(); - Stack redoList = new Stack(); + /** + * DOCUMENT ME! + */ void updateEditMenuBar() { - if (historyList.size() > 0) + + if (viewport.historyList.size() > 0) { undoMenuItem.setEnabled(true); - HistoryItem hi = (HistoryItem) historyList.peek(); - undoMenuItem.setLabel("Undo " + hi.getDescription()); + CommandI command = (CommandI) viewport.historyList.peek(); + undoMenuItem.setLabel("Undo " + command.getDescription()); } else { @@ -593,11 +731,12 @@ public void itemStateChanged(ItemEvent evt) undoMenuItem.setLabel("Undo"); } - if (redoList.size() > 0) + if (viewport.redoList.size() > 0) { redoMenuItem.setEnabled(true); - HistoryItem hi = (HistoryItem) redoList.peek(); - redoMenuItem.setLabel("Redo " + hi.getDescription()); + + CommandI command = (CommandI) viewport.redoList.peek(); + redoMenuItem.setLabel("Redo " + command.getDescription()); } else { @@ -606,37 +745,81 @@ public void itemStateChanged(ItemEvent evt) } } - public void addHistoryItem(HistoryItem hi) + public void addHistoryItem(CommandI command) { - historyList.push(hi); - updateEditMenuBar(); + if(command.getSize()>0) + { + viewport.historyList.push(command); + viewport.redoList.removeAllElements(); + updateEditMenuBar(); + viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null; + } } + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ protected void undoMenuItem_actionPerformed() { - HistoryItem hi = (HistoryItem) historyList.pop(); - redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment, - HistoryItem.HIDE)); - restoreHistoryItem(hi); - viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); - } + if(viewport.historyList.size()<1) + return; - protected void redoMenuItem_actionPerformed() - { - HistoryItem hi = (HistoryItem) redoList.pop(); - restoreHistoryItem(hi); + CommandI command = (CommandI)viewport.historyList.pop(); + viewport.redoList.push(command); + command.undoCommand(); + + AlignViewport originalSource = getOriginatingSource(command); + + originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null; updateEditMenuBar(); - viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); + originalSource.firePropertyChange("alignment", null,null); } - // used by undo and redo - void restoreHistoryItem(HistoryItem hi) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void redoMenuItem_actionPerformed() { - hi.restore(); + CommandI command = (CommandI) viewport.redoList.pop(); + viewport.historyList.push(command); + command.doCommand(); + + AlignViewport originalSource = getOriginatingSource(command); + originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns()!=null; updateEditMenuBar(); + originalSource.firePropertyChange("alignment", null, null); + } - viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); + AlignViewport getOriginatingSource(CommandI command) + { + AlignViewport originalSource = viewport; + //For sequence removal and addition, we need to fire + //the property change event FROM the viewport where the + //original alignment was altered + if (command instanceof EditCommand) + { + EditCommand editCommand = (EditCommand) command; + AlignmentI al = editCommand.getAlignment(); + Vector comps = (Vector) PaintRefresher.components + .get(viewport.getSequenceSetId()); + for (int i = 0; i < comps.size(); i++) + { + if (comps.elementAt(i) instanceof AlignmentPanel) + { + if (al == ( (AlignmentPanel) comps.elementAt(i)).av.alignment) + { + originalSource = ( (AlignmentPanel) comps.elementAt(i)).av; + break; + } + } + } + } + return originalSource; } public void moveSelectedSequences(boolean up) @@ -691,7 +874,8 @@ public void itemStateChanged(ItemEvent evt) alignPanel.repaint(); } - StringBuffer copiedSequences; + static StringBuffer copiedSequences; + static Vector copiedHiddenColumns; protected void copy_actionPerformed() { if (viewport.getSelectionGroup() == null) @@ -712,6 +896,25 @@ public void itemStateChanged(ItemEvent evt) int index = 0, startRes, endRes; char ch; + if (viewport.hasHiddenColumns && viewport.getSelectionGroup() != null) + { + copiedHiddenColumns = new Vector(); + int hiddenOffset = viewport.getSelectionGroup().getStartRes(); + for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns().size(); + i++) + { + int[] region = (int[]) + viewport.getColumnSelection().getHiddenColumns().elementAt(i); + + copiedHiddenColumns.addElement(new int[] + {region[0] - hiddenOffset, + region[1] - hiddenOffset}); + } + } + else + copiedHiddenColumns = null; + + for (int i = 0; i < sg.getSize(false); i++) { SequenceI seq = null; @@ -769,8 +972,6 @@ public void itemStateChanged(ItemEvent evt) protected void pasteThis_actionPerformed() { - addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment, - HistoryItem.PASTE)); paste(false); } @@ -778,6 +979,7 @@ public void itemStateChanged(ItemEvent evt) { try { + if (copiedSequences == null) { return; @@ -790,26 +992,16 @@ public void itemStateChanged(ItemEvent evt) String name = st.nextToken(); int start = Integer.parseInt(st.nextToken()); int end = Integer.parseInt(st.nextToken()); - Sequence sequence = new Sequence(name, st.nextToken(), start, end); - - if (!newAlignment) - { - viewport.alignment.addSequence(sequence); - } - else - { - seqs.addElement(sequence); - } + seqs.addElement(new Sequence(name, st.nextToken(), start, end)); + } + SequenceI[] newSeqs = new SequenceI[seqs.size()]; + for (int i = 0; i < seqs.size(); i++) + { + newSeqs[i] = (SequenceI) seqs.elementAt(i); } if (newAlignment) { - SequenceI[] newSeqs = new SequenceI[seqs.size()]; - for (int i = 0; i < seqs.size(); i++) - { - newSeqs[i] = (SequenceI) seqs.elementAt(i); - } - String newtitle = new String("Copied sequences"); if (getTitle().startsWith("Copied sequences")) { @@ -820,18 +1012,42 @@ public void itemStateChanged(ItemEvent evt) newtitle = newtitle.concat("- from " + getTitle()); } AlignFrame af = new AlignFrame(new Alignment(newSeqs), - applet, + viewport.applet, newtitle, false); + if (copiedHiddenColumns != null) + { + for (int i = 0; i < copiedHiddenColumns.size(); i++) + { + int[] region = (int[]) copiedHiddenColumns.elementAt(i); + af.viewport.hideColumns(region[0], region[1]); + } + } - jalview.bin.JalviewLite.addFrame(af, newtitle, NEW_WINDOW_WIDTH, - NEW_WINDOW_HEIGHT); + + jalview.bin.JalviewLite.addFrame(af, newtitle, DEFAULT_WIDTH, + DEFAULT_HEIGHT); } else { + for (int i = 0; i < newSeqs.length; i++) + { + viewport.alignment.addSequence(newSeqs[i]); + } + + //!newAlignment + addHistoryItem(new EditCommand( + "Add sequences", + EditCommand.PASTE, + newSeqs, + 0, + viewport.alignment.getWidth(), + viewport.alignment) + ); + viewport.setEndSeq(viewport.alignment.getHeight()); viewport.alignment.getWidth(); - viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); + viewport.firePropertyChange("alignment", null, null); } } @@ -848,62 +1064,62 @@ public void itemStateChanged(ItemEvent evt) protected void delete_actionPerformed() { - addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment, - HistoryItem.HIDE)); - if (viewport.getSelectionGroup() == null) + + SequenceGroup sg = viewport.getSelectionGroup(); + if (sg == null) { return; } - - SequenceGroup sg = viewport.getSelectionGroup(); - boolean allSequences = false; - if(sg.getSize(false)==viewport.alignment.getHeight()) - allSequences = true; - + Vector seqs = new Vector(); + SequenceI seq; for (int i = 0; i < sg.getSize(false); i++) { - SequenceI seq = sg.getSequenceAt(i); - int index = viewport.getAlignment().findIndex(seq); - seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1); + seq = sg.getSequenceAt(i); + seqs.addElement(seq); + } - // If the cut affects all sequences, remove highlighted columns - if (allSequences) - { - viewport.getColumnSelection().removeElements(sg.getStartRes(), - sg.getEndRes() + 1); - } + // If the cut affects all sequences, remove highlighted columns + if (sg.getSize(false) == viewport.alignment.getHeight()) + { + viewport.getColumnSelection().removeElements(sg.getStartRes(), + sg.getEndRes() + 1); + } + + + SequenceI [] cut = new SequenceI[seqs.size()]; + for(int i=0; i 0) { - addHistoryItem(new HistoryItem("Remove Left", viewport.alignment, - HistoryItem.HIDE)); - int min = colSel.getMin(); - viewport.getAlignment().trimLeft(min); - colSel.compensateForEdit(0, min); + if(trimLeft) + column = colSel.getMin(); + else + column = colSel.getMax(); - if (viewport.getSelectionGroup() != null) - { - viewport.getSelectionGroup().adjustForRemoveLeft(min); - } + SequenceI [] seqs; + if(viewport.getSelectionGroup()!=null) + seqs = viewport.getSelectionGroup().getSequencesAsArray(true); + else + seqs = viewport.alignment.getSequencesArray(); - Vector groups = viewport.alignment.getGroups(); - for (int i = 0; i < groups.size(); i++) - { - SequenceGroup sg = (SequenceGroup) groups.elementAt(i); - if (!sg.adjustForRemoveLeft(min)) - { - viewport.alignment.deleteGroup(sg); - } - } - viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); - } - } - public void remove2RightMenuItem_actionPerformed() - { - ColumnSelection colSel = viewport.getColumnSelection(); - if (colSel.size() > 0) - { - addHistoryItem(new HistoryItem("Remove Right", viewport.alignment, - HistoryItem.HIDE)); - int max = colSel.getMax(); - viewport.getAlignment().trimRight(max); - if (viewport.getSelectionGroup() != null) + TrimRegionCommand trimRegion; + if(trimLeft) { - viewport.getSelectionGroup().adjustForRemoveRight(max); + trimRegion = new TrimRegionCommand("Remove Left", + TrimRegionCommand.TRIM_LEFT, + seqs, + column, + viewport.alignment, + viewport.colSel, + viewport.selectionGroup); + viewport.setStartRes(0); } + else + { + trimRegion = new TrimRegionCommand("Remove Right", + TrimRegionCommand.TRIM_RIGHT, + seqs, + column, + viewport.alignment, + viewport.colSel, + viewport.selectionGroup); + } + + statusBar.setText("Removed "+trimRegion.getSize()+" columns."); + + + addHistoryItem(trimRegion); Vector groups = viewport.alignment.getGroups(); + for (int i = 0; i < groups.size(); i++) { SequenceGroup sg = (SequenceGroup) groups.elementAt(i); - if (!sg.adjustForRemoveRight(max)) + + if ( (trimLeft && !sg.adjustForRemoveLeft(column)) + || (!trimLeft && !sg.adjustForRemoveRight(column))) { viewport.alignment.deleteGroup(sg); } } - viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); - } + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + } } + public void removeGappedColumnMenuItem_actionPerformed() { - addHistoryItem(new HistoryItem("Remove Gapped Columns", - viewport.alignment, - HistoryItem.HIDE)); + int start = 0, end = viewport.alignment.getWidth()-1; - //This is to maintain viewport position on first residue - //of first sequence - SequenceI seq = viewport.alignment.getSequenceAt(0); - int startRes = seq.findPosition(viewport.startRes); + SequenceI[] seqs; + if (viewport.getSelectionGroup() != null) + { + seqs = viewport.getSelectionGroup().getSequencesAsArray(true); + start = viewport.getSelectionGroup().getStartRes(); + end = viewport.getSelectionGroup().getEndRes(); + } + else + seqs = viewport.alignment.getSequencesArray(); - viewport.getAlignment().removeGaps(); - viewport.setStartRes(seq.findIndex(startRes)-1); + RemoveGapColCommand removeGapCols = + new RemoveGapColCommand("Remove Gapped Columns", + seqs, + start, end, + viewport.getGapCharacter()); - viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); - } + addHistoryItem(removeGapCols); - public void removeAllGapsMenuItem_actionPerformed() - { - addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment, - HistoryItem.HIDE)); + statusBar.setText("Removed "+removeGapCols.getSize()+" empty columns."); //This is to maintain viewport position on first residue //of first sequence SequenceI seq = viewport.alignment.getSequenceAt(0); int startRes = seq.findPosition(viewport.startRes); + // ShiftList shifts; + // viewport.getAlignment().removeGaps(shifts=new ShiftList()); + // edit.alColumnChanges=shifts.getInverse(); + // if (viewport.hasHiddenColumns) + // viewport.getColumnSelection().compensateForEdits(shifts); + viewport.setStartRes(seq.findIndex(startRes)-1); + viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); - SequenceI current; - int jSize; - - Vector seqs=null; + } - int start=0, end = viewport.alignment.getWidth(); + public void removeAllGapsMenuItem_actionPerformed() + { + int start = 0, end = viewport.alignment.getWidth()-1; - if (viewport.getSelectionGroup() != null - && viewport.getSelectionGroup().getSequences(false) != null - && viewport.getSelectionGroup().getSize(false)>0) + SequenceI[] seqs; + if (viewport.getSelectionGroup() != null) { - seqs = viewport.getSelectionGroup().getSequences(true); + seqs = viewport.getSelectionGroup().getSequencesAsArray(true); start = viewport.getSelectionGroup().getStartRes(); - end = viewport.getSelectionGroup().getEndRes()+1; + end = viewport.getSelectionGroup().getEndRes(); } else - seqs = viewport.alignment.getSequences(); + seqs = viewport.alignment.getSequencesArray(); - for (int i = 0; i < seqs.size(); i++) - { - current = (SequenceI) seqs.elementAt(i); - jSize = current.getLength(); + //This is to maintain viewport position on first residue + //of first sequence + SequenceI seq = viewport.alignment.getSequenceAt(0); + int startRes = seq.findPosition(viewport.startRes); - // Removing a range is much quicker than removing gaps - // one by one for long sequences - int j = start; - int rangeStart=-1, rangeEnd=-1; + addHistoryItem(new RemoveGapsCommand("Remove Gaps", + seqs, + start, end, + viewport.getGapCharacter())); - do - { - if (jalview.util.Comparison.isGap(current.getCharAt(j))) - { - if(rangeStart==-1) - { - rangeStart = j; - rangeEnd = j+1; - } - else - { - rangeEnd++; - } - j++; - } - else - { - if(rangeStart>-1) - { - current.deleteChars(rangeStart, rangeEnd); - j-=rangeEnd-rangeStart; - jSize-=rangeEnd-rangeStart; - rangeStart = -1; - rangeEnd = -1; - } - else - j++; - } - } - while (j < end && j < jSize); - if(rangeStart>-1) - { - current.deleteChars(rangeStart, rangeEnd); - } - } viewport.setStartRes(seq.findIndex(startRes)-1); - viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); - } - - public void alignmentChanged() - { - viewport.alignment.padGaps(); - if(viewport.autocalculateConsensus) - { - viewport.updateConsensus(); - viewport.updateConservation(); - } - - resetAllColourSchemes(); - if(alignPanel.overviewPanel!=null) - alignPanel.overviewPanel.updateOverviewImage(); - - viewport.alignment.adjustSequenceAnnotations(); - alignPanel.repaint(); - } - - void resetAllColourSchemes() - { - ColourSchemeI cs = viewport.globalColourScheme; - if(cs!=null) - { - if (cs instanceof ClustalxColourScheme) - { - ( (ClustalxColourScheme) viewport.getGlobalColourScheme()). - resetClustalX(viewport.alignment.getSequences(), - viewport.alignment.getWidth()); - } - cs.setConsensus(viewport.vconsensus); - if (cs.conservationApplied()) - { - Alignment al = (Alignment) viewport.alignment; - Conservation c = new Conservation("All", - ResidueProperties.propHash, 3, - al.getSequences(), 0, - al.getWidth() - 1); - c.calculate(); - c.verdict(false, viewport.ConsPercGaps); - - cs.setConservation(c); - } - } + viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences()); - int s, sSize = viewport.alignment.getGroups().size(); - for(s=0; s 1) + if (viewport.getSelectionGroup()!=null + && viewport.getSelectionGroup().getSize(false) > 1) { Frame frame = new Frame(); frame.add(new PairwiseAlignPanel(alignPanel)); @@ -1624,25 +1766,19 @@ public void itemStateChanged(ItemEvent evt) } - final TreePanel tp; - if (viewport.getSelectionGroup() != null && - viewport.getSelectionGroup().getSize(false) > 3) - { - tp = new TreePanel(viewport, - viewport.getSelectionGroup().getSequences(false), - type, - pwType, - 0, viewport.alignment.getWidth()); - } - else + if ( (viewport.getSelectionGroup() != null && + viewport.getSelectionGroup().getSize(false) > 1) + || (viewport.getSelectionGroup() == null + && viewport.alignment.getHeight() > 1)) { - tp = new TreePanel(viewport, viewport.getAlignment().getSequences(), - type, pwType, 0, viewport.alignment.getWidth()); - } + final TreePanel tp = new TreePanel(viewport, + type, + pwType); - addTreeMenuItem(tp, title); + addTreeMenuItem(tp, title); - jalview.bin.JalviewLite.addFrame(tp, title, 600, 500); + jalview.bin.JalviewLite.addFrame(tp, title, 600, 500); + } } void loadTree_actionPerformed() @@ -1658,8 +1794,9 @@ public void itemStateChanged(ItemEvent evt) public void loadTree(jalview.io.NewickFile tree, String treeFile) { TreePanel tp = new TreePanel(viewport, - viewport.getAlignment().getSequences(), - tree, "From File - ", treeFile); + treeFile, + "From File - ", + tree); jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500); addTreeMenuItem(tp, treeFile); } @@ -1672,8 +1809,8 @@ public void itemStateChanged(ItemEvent evt) { public void actionPerformed(ActionEvent evt) { - addHistoryItem(new HistoryItem("Sort", viewport.alignment, - HistoryItem.SORT)); + // addHistoryItem(new HistoryItem("Sort", viewport.alignment, + // HistoryItem.SORT)); AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree()); alignPanel.repaint(); } @@ -1760,7 +1897,7 @@ public void itemStateChanged(ItemEvent evt) public void showURL(String url, String target) { - if (applet == null) + if (viewport.applet == null) { System.out.println("Not running as applet - no browser available."); } @@ -1769,7 +1906,7 @@ public void itemStateChanged(ItemEvent evt) try { System.out.println("Show url: "+url); - applet.getAppletContext().showDocument(new java.net.URL(url), + viewport.applet.getAppletContext().showDocument(new java.net.URL(url), target); } catch (Exception ex) @@ -1835,8 +1972,7 @@ public void itemStateChanged(ItemEvent evt) protected CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem(); protected CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem(); MenuItem findMenuItem = new MenuItem(); - Menu searchMenu = new Menu(); - protected CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem(); + protected CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem(); protected MenuItem nucleotideColour = new MenuItem(); MenuItem deleteGroups = new MenuItem(); MenuItem delete = new MenuItem(); @@ -1864,8 +2000,9 @@ public void itemStateChanged(ItemEvent evt) protected CheckboxMenuItem seqLimits = new CheckboxMenuItem(); Panel embeddedMenu; Label embeddedEdit; - Label embeddedSearch; + Label embeddedSelect; Label embeddedView; + Label embeddedFormat; Label embeddedColour; Label embeddedFile; Label embeddedHelp; @@ -1879,12 +2016,11 @@ public void itemStateChanged(ItemEvent evt) MenuItem item; // dynamically fill save as menu with available formats - for (int i = 0; i < jalview.io.AppletFormatAdapter.formats.size(); i++) + for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++) { - item = new MenuItem( (String) jalview.io.AppletFormatAdapter.formats. - elementAt( - i)); + item = new MenuItem( jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]); + item.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) @@ -1989,9 +2125,7 @@ public void itemStateChanged(ItemEvent evt) renderGapsMenuItem.addItemListener(this); findMenuItem.setLabel("Find..."); findMenuItem.addActionListener(this); - searchMenu.setLabel("Search"); - - abovePIDThreshold.setLabel("Above Identity Threshold"); + abovePIDThreshold.setLabel("Above Identity Threshold"); abovePIDThreshold.addItemListener(this); nucleotideColour.setLabel("Nucleotide"); nucleotideColour.addActionListener(this); @@ -2052,12 +2186,27 @@ public void itemStateChanged(ItemEvent evt) sequenceFeatures.setState(false); annotationColour.setLabel("by Annotation..."); annotationColour.addActionListener(this); - + invertSequenceMenuItem.setLabel("Invert Sequence Selection"); + invertColSel.setLabel("Invert Column Selection"); + menu1.setLabel("Show"); + showColumns.setLabel("All Columns "); + showSeqs.setLabel("All Sequences"); + menu2.setLabel("Hide"); + hideColumns.setLabel("Selected Columns"); + hideSequences.setLabel("Selected Sequences"); + invertColSel.addActionListener(this); + showColumns.addActionListener(this); + showSeqs.addActionListener(this); + hideColumns.addActionListener(this); + hideSequences.addActionListener(this); + formatMenu.setLabel("Format"); + selectMenu.setLabel("Select"); alignFrameMenuBar.add(fileMenu); alignFrameMenuBar.add(editMenu); - alignFrameMenuBar.add(searchMenu); - alignFrameMenuBar.add(viewMenu); - alignFrameMenuBar.add(colourMenu); + alignFrameMenuBar.add(selectMenu); + alignFrameMenuBar.add(viewMenu); + alignFrameMenuBar.add(formatMenu); + alignFrameMenuBar.add(colourMenu); alignFrameMenuBar.add(calculateMenu); alignFrameMenuBar.add(helpMenu); fileMenu.add(inputText); @@ -2073,32 +2222,16 @@ public void itemStateChanged(ItemEvent evt) editMenu.add(copy); editMenu.add(pasteMenu); editMenu.add(delete); - editMenu.addSeparator(); - editMenu.add(selectAllSequenceMenuItem); - editMenu.add(deselectAllSequenceMenuItem); - editMenu.add(invertSequenceMenuItem); - editMenu.add(deleteGroups); - editMenu.addSeparator(); + editMenu.addSeparator(); editMenu.add(remove2LeftMenuItem); editMenu.add(remove2RightMenuItem); editMenu.add(removeGappedColumnMenuItem); editMenu.add(removeAllGapsMenuItem); editMenu.add(removeRedundancyMenuItem); - searchMenu.add(findMenuItem); - viewMenu.add(font); - viewMenu.addSeparator(); - viewMenu.add(seqLimits); - viewMenu.addSeparator(); - viewMenu.add(wrapMenuItem); - viewMenu.add(scaleAbove); - viewMenu.add(scaleLeft); - viewMenu.add(scaleRight); - viewMenu.addSeparator(); - viewMenu.add(viewBoxesMenuItem); - viewMenu.add(viewTextMenuItem); - viewMenu.add(colourTextMenuItem); - viewMenu.add(renderGapsMenuItem); - viewMenu.add(annotationPanelMenuItem); + viewMenu.add(menu1); + viewMenu.add(menu2); + viewMenu.addSeparator(); + viewMenu.add(annotationPanelMenuItem); viewMenu.addSeparator(); viewMenu.add(sequenceFeatures); viewMenu.add(featureSettings); @@ -2144,40 +2277,57 @@ public void itemStateChanged(ItemEvent evt) calculate.add(njTreeBlosumMenuItem); helpMenu.add(documentation); helpMenu.add(about); + menu1.add(showColumns); + menu1.add(showSeqs); + menu2.add(hideColumns); + menu2.add(hideSequences); + formatMenu.add(font); + formatMenu.add(seqLimits); + formatMenu.add(wrapMenuItem); + formatMenu.add(scaleAbove); + formatMenu.add(scaleLeft); + formatMenu.add(scaleRight); + formatMenu.add(viewBoxesMenuItem); + formatMenu.add(viewTextMenuItem); + formatMenu.add(colourTextMenuItem); + formatMenu.add(renderGapsMenuItem); + selectMenu.add(findMenuItem); + selectMenu.addSeparator(); + selectMenu.add(selectAllSequenceMenuItem); + selectMenu.add(deselectAllSequenceMenuItem); + selectMenu.add(invertSequenceMenuItem); + selectMenu.add(invertColSel); + selectMenu.add(deleteGroups); } public void setEmbedded() { embeddedMenu = new Panel(); - embeddedEdit = new Label(); - embeddedSearch = new Label(); - embeddedView = new Label(); - embeddedColour = new Label(); - embeddedFile = new Label(); - embeddedHelp = new Label(); - embeddedCalculate = new Label(); + embeddedEdit = new Label("Edit"); + embeddedSelect = new Label("Select"); + embeddedView = new Label("View"); + embeddedFormat = new Label("Format"); + embeddedColour = new Label("Colour"); + embeddedFile = new Label("File"); + embeddedHelp = new Label("Help"); + embeddedCalculate = new Label("Calculate"); flowLayout1 = new FlowLayout(); embeddedMenu.setBackground(Color.lightGray); embeddedMenu.setLayout(flowLayout1); - embeddedEdit.setText("Edit"); embeddedEdit.setFont(new java.awt.Font("Arial", Font.PLAIN, 10)); - embeddedSearch.setText("Search"); - embeddedSearch.setFont(new java.awt.Font("Arial", Font.PLAIN, 10)); - embeddedView.setText("View"); + embeddedSelect.setFont(new java.awt.Font("Arial", Font.PLAIN, 10)); embeddedView.setFont(new java.awt.Font("Arial", Font.PLAIN, 10)); - embeddedColour.setText("Colour"); + embeddedFormat.setFont(new java.awt.Font("Arial", Font.PLAIN, 10)); embeddedColour.setFont(new java.awt.Font("Arial", Font.PLAIN, 10)); embeddedFile.setFont(new java.awt.Font("Arial", Font.PLAIN, 10)); - embeddedFile.setText("File"); embeddedHelp.setFont(new java.awt.Font("Arial", Font.PLAIN, 10)); - embeddedHelp.setText("Help"); embeddedCalculate.setFont(new java.awt.Font("Arial", Font.PLAIN, 10)); - embeddedCalculate.setText("Calculate"); embeddedMenu.add(embeddedFile); embeddedMenu.add(embeddedEdit); - embeddedMenu.add(embeddedSearch); + embeddedMenu.add(embeddedSelect); embeddedMenu.add(embeddedView); + embeddedMenu.add(embeddedFormat); embeddedMenu.add(embeddedColour); embeddedMenu.add(embeddedCalculate); embeddedMenu.add(embeddedHelp); @@ -2186,8 +2336,9 @@ public void itemStateChanged(ItemEvent evt) flowLayout1.setVgap(0); embeddedFile.addMouseListener(this); embeddedEdit.addMouseListener(this); - embeddedSearch.addMouseListener(this); + embeddedSelect.addMouseListener(this); embeddedView.addMouseListener(this); + embeddedFormat.addMouseListener(this); embeddedColour.addMouseListener(this); embeddedCalculate.addMouseListener(this); embeddedHelp.addMouseListener(this); @@ -2196,26 +2347,35 @@ public void itemStateChanged(ItemEvent evt) fileMenu.remove(closeMenuItem); fileMenu.remove(3); // Seperator - applet.setLayout(new BorderLayout()); - applet.add(embeddedMenu, BorderLayout.NORTH); - applet.add(statusBar, BorderLayout.SOUTH); - // applet.validate(); + viewport.applet.setLayout(new BorderLayout()); + viewport.applet.add(embeddedMenu, BorderLayout.NORTH); + viewport.applet.add(statusBar, BorderLayout.SOUTH); + // viewport.applet.validate(); - alignPanel.setSize(applet.size().width, applet.size().height + alignPanel.setSize(viewport.applet.size().width, viewport.applet.size().height - embeddedMenu.HEIGHT - statusBar.HEIGHT); - applet.add(alignPanel, BorderLayout.CENTER); - applet.validate(); + viewport.applet.add(alignPanel, BorderLayout.CENTER); + viewport.applet.validate(); } PopupMenu filePopup, editPopup, searchPopup, - viewPopup, colourPopup, calculatePopup, helpPopup; + viewPopup, formatPopup, colourPopup, calculatePopup, helpPopup; MenuItem featureSettings = new MenuItem(); CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem(); MenuItem annotationColour = new MenuItem(); + MenuItem invertColSel = new MenuItem(); + Menu menu1 = new Menu(); + MenuItem showColumns = new MenuItem(); + MenuItem showSeqs = new MenuItem(); + Menu menu2 = new Menu(); + MenuItem hideColumns = new MenuItem(); + MenuItem hideSequences = new MenuItem(); + Menu formatMenu = new Menu(); + Menu selectMenu = new Menu(); public void mousePressed(MouseEvent evt) { @@ -2229,14 +2389,18 @@ public void itemStateChanged(ItemEvent evt) { popup = editPopup = genPopupMenu(editPopup, editMenu); } - else if(source==embeddedSearch) + else if(source==embeddedSelect) { - popup = searchPopup = genPopupMenu(searchPopup, searchMenu); + popup = searchPopup = genPopupMenu(searchPopup, selectMenu); } else if(source==embeddedView) { popup = viewPopup = genPopupMenu(viewPopup, viewMenu); } + else if (source ==embeddedFormat) + { + popup = formatPopup = genPopupMenu(formatPopup, formatMenu); + } else if(source==embeddedColour) { popup = colourPopup = genPopupMenu(colourPopup, colourMenu);