X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=a8bc815a62a6bbf3c668159bf337095c3ba86922;hb=cd669a0e8c7b91b379bca8fe6e702cf0fcbd1ce0;hp=092d7e7504b3e6868d3338e23658ba14b128b4ea;hpb=cb8e52fbbc5f725e3f7f48c672cdddb0690bd978;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 092d7e7..a8bc815 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -20,6 +20,18 @@ */ package jalview.gui; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Rectangle; +import java.io.File; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import javax.swing.JInternalFrame; + import jalview.analysis.AlignmentUtils; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.api.AlignViewportI; @@ -35,11 +47,19 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.ContactMatrixI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; +import jalview.io.FileFormatException; +import jalview.io.FileFormatI; +import jalview.io.FileFormats; +import jalview.io.FileLoader; +import jalview.io.IdentifyFile; import jalview.renderer.ResidueShader; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; @@ -53,17 +73,6 @@ import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; import jalview.ws.params.AutoCalcSetting; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; - -import javax.swing.JInternalFrame; - /** * DOCUMENT ME! * @@ -291,8 +300,8 @@ public class AlignViewport extends AlignmentViewport schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR, ResidueColourScheme.NONE); } - ColourSchemeI colourScheme = ColourSchemeProperty - .getColourScheme(this, alignment, schemeName); + ColourSchemeI colourScheme = ColourSchemeProperty.getColourScheme(this, + alignment, schemeName); residueShading = new ResidueShader(colourScheme); if (colourScheme instanceof UserColourScheme) @@ -719,12 +728,62 @@ public class AlignViewport extends AlignmentViewport al.addSequence(seq); } } - + for (ContactMatrixI cm : toAdd.getContactMaps()) + { + al.addContactList(cm); + } ranges.setEndSeq(getAlignment().getHeight() - 1); // BH 2019.04.18 firePropertyChange("alignment", null, getAlignment().getSequences()); } /** + * Load a File into this AlignViewport attempting to detect format if not + * given or given as null. + * + * @param file + * @param format + */ + public void addFile(File file, FileFormatI format) + { + addFile(file, format, true); + } + + public void addFile(File file, FileFormatI format, boolean async) + { + DataSourceType protocol = AppletFormatAdapter.checkProtocol(file); + + if (format == null) + { + try + { + format = new IdentifyFile().identify(file, protocol); + } catch (FileFormatException e1) + { + jalview.bin.Console.error("Unknown file format for '" + file + "'"); + } + } + else if (FileFormats.getInstance().isIdentifiable(format)) + { + try + { + format = new IdentifyFile().identify(file, protocol); + } catch (FileFormatException e) + { + jalview.bin.Console.error("Unknown file format for '" + file + "'", + e); + } + } + + new FileLoader().LoadFile(this, file, DataSourceType.FILE, format, + async); + } + + public void addFile(File file) + { + addFile(file, null); + } + + /** * Show a dialog with the option to open and link (cDNA <-> protein) as a new * alignment, either as a standalone alignment or in a split frame. Returns * true if the new alignment was opened, false if not, because the user @@ -741,36 +800,21 @@ public class AlignViewport extends AlignmentViewport final String question = JvSwingUtils.wrapTooltip(true, MessageManager.getString("label.open_split_window?")); final AlignViewport us = this; - + /* * options No, Split Window, New Window correspond to * dialog responses 0, 1, 2 (even though JOptionPane shows them * in reverse order) */ JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop) - .setResponseHandler(0, new Runnable() - { - @Override - public void run() - { - addDataToAlignment(al); - } - }).setResponseHandler(1, new Runnable() - { - @Override - public void run() - { - us.openLinkedAlignmentAs(al, title, true); - } - }).setResponseHandler(2, new Runnable() - { - @Override - public void run() - { - us.openLinkedAlignmentAs(al, title, false); - } + .setResponseHandler(0, () -> { + addDataToAlignment(al); + }).setResponseHandler(1, () -> { + us.openLinkedAlignmentAs(al, title, true); + }).setResponseHandler(2, () -> { + us.openLinkedAlignmentAs(al, title, false); }); - dialog.showDialog(question, + dialog.showDialog(question, MessageManager.getString("label.open_split_window"), JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null, options, options[0]); @@ -778,7 +822,7 @@ public class AlignViewport extends AlignmentViewport protected void openLinkedAlignmentAs(AlignmentI al, String title, boolean newWindowOrSplitPane) - { + { /* * Identify protein and dna alignments. Make a copy of this one if opening * in a new split pane. @@ -824,8 +868,7 @@ public class AlignViewport extends AlignmentViewport try { - newAlignFrame.setMaximum( - Cache.getDefault("SHOW_FULLSCREEN", false)); + newAlignFrame.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false)); } catch (java.beans.PropertyVetoException ex) { } @@ -954,7 +997,7 @@ public class AlignViewport extends AlignmentViewport */ protected boolean noReferencesTo(AlignedCodonFrame acf) { - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); if (frames == null) { return true; @@ -991,10 +1034,10 @@ public class AlignViewport extends AlignmentViewport } /** - * Applies the supplied feature settings descriptor to currently known features. - * This supports an 'initial configuration' of feature colouring based on a - * preset or user favourite. This may then be modified in the usual way using - * the Feature Settings dialogue. + * Applies the supplied feature settings descriptor to currently known + * features. This supports an 'initial configuration' of feature colouring + * based on a preset or user favourite. This may then be modified in the usual + * way using the Feature Settings dialogue. * * @param featureSettings */ @@ -1007,8 +1050,8 @@ public class AlignViewport extends AlignmentViewport /** * when mergeOnly is set, then group and feature visibility or feature colours * are not modified for features and groups already known to the feature - * renderer. Feature ordering is always adjusted, and transparency is always set - * regardless. + * renderer. Feature ordering is always adjusted, and transparency is always + * set regardless. * * @param featureSettings * @param mergeOnly @@ -1020,12 +1063,13 @@ public class AlignViewport extends AlignmentViewport { return; } - + FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas .getFeatureRenderer(); List origRenderOrder = new ArrayList<>(); List origGroups = new ArrayList<>(); - // preserve original render order - allows differentiation between user configured colours and autogenerated ones + // preserve original render order - allows differentiation between user + // configured colours and autogenerated ones origRenderOrder.addAll(fr.getRenderOrder()); origGroups.addAll(fr.getFeatureGroups()); @@ -1057,7 +1101,8 @@ public class AlignViewport extends AlignmentViewport && origColour.getColour().equals( ColorUtils.createColourFromName(type))))) { - // if we are merging, only update if there wasn't already a colour defined for + // if we are merging, only update if there wasn't already a colour + // defined for // this type if (preferredColour != null) { @@ -1081,7 +1126,8 @@ public class AlignViewport extends AlignmentViewport { if (!mergeOnly || !origGroups.contains(group)) { - // when merging, display groups only if the aren't already marked as not visible + // when merging, display groups only if the aren't already marked as not + // visible fr.setGroupVisibility(group, featureSettings.isGroupDisplayed(group)); } @@ -1112,4 +1158,5 @@ public class AlignViewport extends AlignmentViewport { this.viewName = viewName; } + }