X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=293948ae0403cf9680d2beb46f20f097b31c6ecc;hb=a10a465359de7b8c0baff4925d4b267a28eb0071;hp=d8459a9f23ca210891454010aed83619e5de69fd;hpb=239ea1f6501b7a04d4e80149690c16e81560c00f;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index d8459a9..293948a 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1) - * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5.1) + * Copyright (C) 2010 J Procter, AM Waterhouse, 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 - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * This file is part of Jalview. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Jalview. If not, see . */ package jalview.gui; @@ -406,39 +405,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { boolean toggleSeqs = !evt.isControlDown(); boolean toggleCols = !evt.isShiftDown(); - - boolean hide = false; - - SequenceGroup sg = viewport.getSelectionGroup(); - if (toggleSeqs) - { - if (sg != null - && sg.getSize() != viewport.alignment.getHeight()) - { - hideSelSequences_actionPerformed(null); - hide = true; - } - else if (!(toggleCols && viewport.colSel.getSelected().size() > 0)) - { - showAllSeqs_actionPerformed(null); - } - } - - if (toggleCols) - { - if (viewport.colSel.getSelected().size() > 0) - { - hideSelColumns_actionPerformed(null); - if (!toggleSeqs) - { - viewport.selectionGroup = sg; - } - } - else if (!hide) - { - showAllColumns_actionPerformed(null); - } - } + toggleHiddenRegions(toggleSeqs, toggleCols); break; } case KeyEvent.VK_PAGE_UP: @@ -579,7 +546,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, showTranslation.setVisible(nucleotide); conservationMenuItem.setEnabled(!nucleotide); modifyConservation.setEnabled(!nucleotide); - + showGroupConservation.setEnabled(!nucleotide); // Remember AlignFrame always starts as protein if (!nucleotide) { @@ -621,7 +588,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, annotationPanelMenuItem.setState(av.showAnnotation); viewBoxesMenuItem.setSelected(av.showBoxes); viewTextMenuItem.setSelected(av.showText); - showUnconservedMenuItem.setSelected(av.showUnconserved); + showNonconservedMenuItem.setSelected(av.showUnconserved); + showGroupConsensus.setSelected(av.showGroupConsensus); + showGroupConservation.setSelected(av.showGroupConservation); + showConsensusHistogram.setSelected(av.showConsensusHistogram); + showSequenceLogo.setSelected(av.showSequenceLogo); setColourSelected(ColourSchemeProperty.getColourName(av .getGlobalColourScheme())); @@ -652,20 +623,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } JPanel progressPanel; + Long lId = new Long(id); GridLayout layout = (GridLayout) statusPanel.getLayout(); - if (progressBars.get(new Long(id)) != null) + if (progressBars.get(lId) != null) { progressPanel = (JPanel) progressBars.get(new Long(id)); statusPanel.remove(progressPanel); - progressBars.remove(progressPanel); + progressBars.remove(lId); progressPanel = null; if (message != null) { statusBar.setText(message); } - if (progressBarHandlers.contains(new Long(id))) + if (progressBarHandlers.contains(lId)) { - progressBarHandlers.remove(new Long(id)); + progressBarHandlers.remove(lId); } layout.setRows(layout.getRows() - 1); } @@ -682,7 +654,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, layout.setRows(layout.getRows() + 1); statusPanel.add(progressPanel); - progressBars.put(new Long(id), progressPanel); + progressBars.put(lId, progressPanel); } // update GUI setMenusForViewport(); @@ -757,6 +729,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (fileName != null) { + // TODO: work out how to recover feature settings for correct view(s) when + // file is reloaded. if (currentFileFormat.equals("Jalview")) { JInternalFrame[] frames = Desktop.desktop.getAllFrames(); @@ -791,7 +765,23 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protocol, currentFileFormat); newframe.setBounds(bounds); - + if (featureSettings != null && featureSettings.isShowing()) + { + final Rectangle fspos = featureSettings.frame.getBounds(); + // TODO: need a 'show feature settings' function that takes bounds - + // need to refactor Desktop.addFrame + newframe.featureSettings_actionPerformed(null); + final FeatureSettings nfs = newframe.featureSettings; + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + nfs.frame.setBounds(fspos); + } + }); + this.featureSettings.close(); + this.featureSettings = null; + } this.closeMenuItem_actionPerformed(true); } } @@ -893,12 +883,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true)) { - // JBPNote need to have a raise_gui flag here - JOptionPane.showInternalMessageDialog(this, "Cannot save file " - + fileName + " using format " + format, - "Alignment output format not supported", - JOptionPane.WARNING_MESSAGE); + warningMessage("Cannot save file " + fileName + " using format " + + format, "Alignment output format not supported"); saveAs_actionPerformed(null); + // JBPNote need to have a raise_gui flag here return false; } @@ -959,6 +947,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return success; } + private void warningMessage(String warning, String title) + { + if (new jalview.util.Platform().isHeadless()) + { + System.err.println("Warning: " + title + "\nWarning: " + warning); + + } + else + { + JOptionPane.showInternalMessageDialog(this, warning, title, + JOptionPane.WARNING_MESSAGE); + } + return; + } + /** * DOCUMENT ME! * @@ -1203,7 +1206,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.historyList.push(command); viewport.redoList.clear(); updateEditMenuBar(); - viewport.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null; + viewport.hasHiddenColumns = (viewport.colSel != null + && viewport.colSel.getHiddenColumns() != null && viewport.colSel + .getHiddenColumns().size() > 0); } } @@ -1250,7 +1255,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (originalSource != null) { - originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null; + originalSource.hasHiddenColumns = (viewport.colSel != null + && viewport.colSel.getHiddenColumns() != null && viewport.colSel + .getHiddenColumns().size() > 0); originalSource.firePropertyChange("alignment", null, originalSource.alignment.getSequences()); } @@ -1278,7 +1285,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (originalSource != null) { - originalSource.hasHiddenColumns = viewport.colSel.getHiddenColumns() != null; + originalSource.hasHiddenColumns = (viewport.colSel != null + && viewport.colSel.getHiddenColumns() != null && viewport.colSel + .getHiddenColumns().size() > 0); originalSource.firePropertyChange("alignment", null, originalSource.alignment.getSequences()); } @@ -1521,15 +1530,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (viewport.hasHiddenColumns) { hiddenColumns = new Vector(); - int hiddenOffset = viewport.getSelectionGroup().getStartRes(); + int hiddenOffset = viewport.getSelectionGroup().getStartRes(),hiddenCutoff=viewport.getSelectionGroup().getEndRes(); for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns() .size(); i++) { int[] region = (int[]) viewport.getColumnSelection() .getHiddenColumns().elementAt(i); - - hiddenColumns.addElement(new int[] + if (region[0]>=hiddenOffset && region[1]<=hiddenCutoff) + { + hiddenColumns.addElement(new int[] { region[0] - hiddenOffset, region[1] - hiddenOffset }); + } } } @@ -1913,6 +1924,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.sequenceColours = null; viewport.setSelectionGroup(null); PaintRefresher.Refresh(this, viewport.getSequenceSetId()); + alignPanel.updateAnnotation(); alignPanel.paintAlignment(true); } @@ -2354,6 +2366,116 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.paintAlignment(true); } + /** + * called by key handler and the hide all/show all menu items + * + * @param toggleSeqs + * @param toggleCols + */ + private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols) + { + + boolean hide = false; + SequenceGroup sg = viewport.getSelectionGroup(); + if (!toggleSeqs && !toggleCols) + { + // Hide everything by the current selection - this is a hack - we do the + // invert and then hide + // first check that there will be visible columns after the invert. + if ((viewport.colSel != null && viewport.colSel.getSelected() != null && viewport.colSel + .getSelected().size() > 0) + || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg + .getEndRes())) + { + // now invert the sequence set, if required - empty selection implies + // that no hiding is required. + if (sg != null) + { + invertSequenceMenuItem_actionPerformed(null); + sg = viewport.getSelectionGroup(); + toggleSeqs = true; + + } + viewport.expandColSelection(sg, true); + // finally invert the column selection and get the new sequence + // selection. + invertColSel_actionPerformed(null); + toggleCols = true; + } + } + + if (toggleSeqs) + { + if (sg != null && sg.getSize() != viewport.alignment.getHeight()) + { + hideSelSequences_actionPerformed(null); + hide = true; + } + else if (!(toggleCols && viewport.colSel.getSelected().size() > 0)) + { + showAllSeqs_actionPerformed(null); + } + } + + if (toggleCols) + { + if (viewport.colSel.getSelected().size() > 0) + { + hideSelColumns_actionPerformed(null); + if (!toggleSeqs) + { + viewport.selectionGroup = sg; + } + } + else if (!hide) + { + showAllColumns_actionPerformed(null); + } + } + } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#hideAllButSelection_actionPerformed(java.awt. + * event.ActionEvent) + */ + public void hideAllButSelection_actionPerformed(ActionEvent e) + { + toggleHiddenRegions(false, false); + } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#hideAllSelection_actionPerformed(java.awt.event + * .ActionEvent) + */ + public void hideAllSelection_actionPerformed(ActionEvent e) + { + SequenceGroup sg = viewport.getSelectionGroup(); + viewport.expandColSelection(sg, false); + viewport.hideAllSelectedSeqs(); + viewport.hideSelectedColumns(); + alignPanel.paintAlignment(true); + } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#showAllhidden_actionPerformed(java.awt.event. + * ActionEvent) + */ + public void showAllhidden_actionPerformed(ActionEvent e) + { + viewport.showAllHiddenColumns(); + viewport.showAllHiddenSeqs(); + alignPanel.paintAlignment(true); + } + public void hideSelColumns_actionPerformed(ActionEvent e) { viewport.hideSelectedColumns(); @@ -2447,6 +2569,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, featureSettings.close(); featureSettings = null; } + if (!showSeqFeatures.isSelected()) + { + // make sure features are actually displayed + showSeqFeatures.setSelected(true); + showSeqFeatures_actionPerformed(null); + } featureSettings = new FeatureSettings(this); } @@ -3267,8 +3395,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { - // are the sequences aligned? - if (!viewport.alignment.isAligned()) + // are the visible sequences aligned? + if (!viewport.alignment.isAligned(false)) { JOptionPane .showMessageDialog( @@ -3537,10 +3665,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // jobs // TODO: viewport.alignment.isAligned is a global state - the local // selection may well be aligned - we preserve 2.0.8 behaviour for moment. - if (!viewport.alignment.isAligned()) + if (!viewport.alignment.isAligned(false)) { seqs.setSequences(new SeqCigar[] { seqs.getSequences()[0] }); + // TODO: if seqs.getSequences().length>1 then should really have warned + // user! + } return seqs; } @@ -3720,9 +3851,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .getServiceClient(sh); impl.attachWSMenuEntry(seqsrchmenu, this); } - // finally, add the whole shebang onto the webservices menu wsmenu.add(seqsrchmenu); } + // finally, add the whole shebang onto the webservices menu resetWebServiceMenu(); for (int i = 0, j = wsmenu.size(); i < j; i++) { @@ -3745,6 +3876,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { webService.removeAll(); build_fetchdbmenu(webService); + build_urlServiceMenu(webService); + } + + /** + * construct any groupURL type service menu entries. + * + * @param webService + */ + private void build_urlServiceMenu(JMenu webService) + { + jalview.ws.EnfinEnvision2OneWay.getInstance().attachWSMenuEntry( + webService, this); } /* @@ -4032,6 +4175,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // update the min/max ranges where necessary alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true); } + if (featureSettings != null) + { + featureSettings.setTableData(); + } alignPanel.paintAlignment(true); } @@ -4087,8 +4234,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } java.net.URI uri = new java.net.URI(s); - java.io.File file = new java.io.File(uri); - files.add(file); + // check to see if we can handle this kind of URI + if (uri.getScheme().toLowerCase().startsWith("http")) + { + files.add(uri.toString()); + } + else + { + // otherwise preserve old behaviour: catch all for file objects + java.io.File file = new java.io.File(uri); + files.add(file.toString()); + } } } } catch (Exception e) @@ -4112,9 +4268,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * Attempt to load a "dropped" file: First by testing whether it's and - * Annotation file, then a JNet file, and finally a features file. If all are - * false then the user may have dropped an alignment file onto this + * Attempt to load a "dropped" file or URL string: First by testing whether + * it's and Annotation file, then a JNet file, and finally a features file. If + * all are false then the user may have dropped an alignment file onto this * AlignFrame. * * @param file @@ -4124,11 +4280,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { try { - String protocol = "File"; - - if (file.indexOf("http:") > -1 || file.indexOf("file:") > -1) + String protocol = jalview.io.FormatAdapter.FILE; + String f = file.toLowerCase(); + if (f.indexOf("http:") == 0 || f.indexOf("https:") == 0 + || f.indexOf("file:") == 0) { - protocol = "URL"; + protocol = jalview.io.FormatAdapter.URL; } boolean isAnnotation = new AnnotationFile().readAnnotationFile( @@ -4400,9 +4557,105 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ protected void showUnconservedMenuItem_actionPerformed(ActionEvent e) { - viewport.setShowUnconserved(showUnconservedMenuItem.getState()); + viewport.setShowUnconserved(showNonconservedMenuItem.getState()); alignPanel.paintAlignment(true); } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event + * .ActionEvent) + */ + protected void showGroupConsensus_actionPerformed(ActionEvent e) + { + viewport.setShowGroupConsensus(showGroupConsensus.getState()); + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); + + } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt + * .event.ActionEvent) + */ + protected void showGroupConservation_actionPerformed(ActionEvent e) + { + viewport.setShowGroupConservation(showGroupConservation.getState()); + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); + } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt + * .event.ActionEvent) + */ + protected void showConsensusHistogram_actionPerformed(ActionEvent e) + { + viewport.setShowConsensusHistogram(showConsensusHistogram.getState()); + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); + } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt + * .event.ActionEvent) + */ + protected void showSequenceLogo_actionPerformed(ActionEvent e) + { + viewport.setShowSequenceLogo(showSequenceLogo.getState()); + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); + } + + protected void applyAutoAnnotationSettings_actionPerformed(ActionEvent e) + { + alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState()); + } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt + * .event.ActionEvent) + */ + protected void makeGrpsFromSelection_actionPerformed(ActionEvent e) + { + if (viewport.getSelectionGroup() != null) + { + SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom( + viewport.getSequenceSelection(), viewport.getAlignmentView( + true).getSequenceStrings(viewport.getGapCharacter()), + viewport.alignment.getGroups()); + viewport.alignment.deleteAllGroups(); + viewport.sequenceColours = null; + viewport.setSelectionGroup(null); + // set view properties for each group + for (int g = 0; g < gps.length; g++) + { + gps[g].setShowNonconserved(viewport.getShowUnconserved()); + gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo()); + viewport.alignment.addGroup(gps[g]); + Color col = new Color((int) (Math.random() * 255), (int) (Math + .random() * 255), (int) (Math.random() * 255)); + col = col.brighter(); + for (Enumeration sq = gps[g].getSequences(null).elements(); sq + .hasMoreElements(); viewport.setSequenceColour( + (SequenceI) sq.nextElement(), col)) + ; + } + PaintRefresher.Refresh(this, viewport.getSequenceSetId()); + alignPanel.updateAnnotation(); + alignPanel.paintAlignment(true); + } + } } class PrintThread extends Thread