X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=e45dc5d679b47eec46eb8e6c227d7ce2d5f162d6;hb=833b0e8d60b46c17dad52d31f4896363f29499bc;hp=e08fce5e9740dea7efb1592b338f001915c4fd36;hpb=948bd3bcbacc509da0cefaae3eedd97300a6ccce;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index e08fce5..e45dc5d 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -88,6 +88,7 @@ import jalview.schemes.ColourSchemes; import jalview.schemes.ResidueColourScheme; import jalview.schemes.TCoffeeColourScheme; import jalview.util.MessageManager; +import jalview.util.dialogrunner.RunResponse; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; import jalview.ws.DBRefFetcher; @@ -122,6 +123,7 @@ import java.awt.event.MouseEvent; import java.awt.print.PageFormat; import java.awt.print.PrinterJob; import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; @@ -136,6 +138,7 @@ import java.util.Vector; import javax.swing.JCheckBoxMenuItem; import javax.swing.JEditorPane; +import javax.swing.JFileChooser; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; import javax.swing.JMenu; @@ -150,7 +153,8 @@ import javax.swing.SwingUtilities; * @version $Revision$ */ public class AlignFrame extends GAlignFrame implements DropTargetListener, - IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener + IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener, + PropertyChangeListener { public static final int DEFAULT_WIDTH = 700; @@ -324,6 +328,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, init(); } + @Override + public void propertyChange(PropertyChangeEvent evt) + { + Desktop.getDesktop().propertyChange(evt); + } + /** * initalise the alignframe from the underlying viewport data and the * configurations @@ -378,7 +388,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (Desktop.desktop != null) { this.setDropTarget(new java.awt.dnd.DropTarget(this, this)); + /** + * BH 2018 ignore service listeners + * + * @j2sNative + * + */ + { addServiceListeners(); + } setGUINucleotide(); } @@ -1101,43 +1119,45 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void saveAs_actionPerformed(ActionEvent e) { + // TODO: JAL-3048 JalviewFileChooser - Save option + String format = currentFileFormat == null ? null : currentFileFormat.getName(); - JalviewFileChooser chooser = JalviewFileChooser + final JalviewFileChooser chooser = JalviewFileChooser .forWrite(Cache.getProperty("LAST_DIRECTORY"), format); - + final AlignFrame us = this; chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( MessageManager.getString("label.save_alignment_to_file")); chooser.setToolTipText(MessageManager.getString("action.save")); - int value = chooser.showSaveDialog(this); - - if (value == JalviewFileChooser.APPROVE_OPTION) + chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION) { - currentFileFormat = chooser.getSelectedFormat(); - while (currentFileFormat == null) - { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString( - "label.select_file_format_before_saving"), - MessageManager.getString("label.file_format_not_specified"), - JvOptionPane.WARNING_MESSAGE); + @Override + public void run() + { currentFileFormat = chooser.getSelectedFormat(); - value = chooser.showSaveDialog(this); - if (value != JalviewFileChooser.APPROVE_OPTION) + while (currentFileFormat == null) { - return; + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString( + "label.select_file_format_before_saving"), + MessageManager + .getString("label.file_format_not_specified"), + JvOptionPane.WARNING_MESSAGE); + currentFileFormat = chooser.getSelectedFormat(); + chooser.showSaveDialog(us); } - } - fileName = chooser.getSelectedFile().getPath(); + fileName = chooser.getSelectedFile().getPath(); - Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName()); + Cache.setProperty("DEFAULT_FILE_FORMAT", + currentFileFormat.getName()); - Cache.setProperty("LAST_DIRECTORY", fileName); - saveAlignment(fileName, currentFileFormat); - } + Cache.setProperty("LAST_DIRECTORY", fileName); + saveAlignment(fileName, currentFileFormat); + } + }).showSaveDialog(this); } public boolean saveAlignment(String file, FileFormatI format) @@ -1404,7 +1424,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void associatedData_actionPerformed(ActionEvent e) { - // Pick the tree file JalviewFileChooser chooser = new JalviewFileChooser( jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); @@ -1413,14 +1432,30 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, chooser.setToolTipText( MessageManager.getString("label.load_jalview_annotations")); - int value = chooser.showOpenDialog(null); + Desktop.getDesktop().dialogData = new Object[] { "SelectedFile", + new Runnable() + { + + @Override + public void run() + { + Object[] data = Desktop.getDesktop().dialogData; + int value = ((Integer) data[0]).intValue(); + + if (value == JFileChooser.APPROVE_OPTION) + { + JalviewFileChooser chooser = (JalviewFileChooser) data[2]; + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + loadJalviewDataFile(choice, null, null, null); + } + } + + }, chooser }; + + chooser.showOpenDialog(null); + - if (value == JalviewFileChooser.APPROVE_OPTION) - { - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - loadJalviewDataFile(choice, null, null, null); - } } @@ -1828,7 +1863,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void copy_actionPerformed(ActionEvent e) { - System.gc(); if (viewport.getSelectionGroup() == null) { return; @@ -3261,6 +3295,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.setOverviewPanel(null); }; }); + if (getKeyListeners().length > 0) + { + frame.addKeyListener(getKeyListeners()[0]); + } alignPanel.setOverviewPanel(overview); } @@ -3867,6 +3905,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void loadTreeMenuItem_actionPerformed(ActionEvent e) { + // TODO: JAL-3048 JalviewFileChooser // Pick the tree file JalviewFileChooser chooser = new JalviewFileChooser( jalview.bin.Cache.getProperty("LAST_DIRECTORY")); @@ -3876,33 +3915,40 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, chooser.setToolTipText( MessageManager.getString("label.load_tree_file")); - int value = chooser.showOpenDialog(null); - - if (value == JalviewFileChooser.APPROVE_OPTION) - { - String filePath = chooser.getSelectedFile().getPath(); - Cache.setProperty("LAST_DIRECTORY", filePath); - NewickFile fin = null; - try - { - fin = new NewickFile(filePath, DataSourceType.FILE); - viewport.setCurrentTree(showNewickTree(fin, filePath).getTree()); - } catch (Exception ex) - { - JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(), - MessageManager.getString("label.problem_reading_tree_file"), - JvOptionPane.WARNING_MESSAGE); - ex.printStackTrace(); - } - if (fin != null && fin.hasWarningMessage()) - { - JvOptionPane.showMessageDialog(Desktop.desktop, - fin.getWarningMessage(), - MessageManager - .getString("label.possible_problem_with_tree_file"), - JvOptionPane.WARNING_MESSAGE); - } - } + chooser.response( + new jalview.util.dialogrunner.RunResponse(JalviewFileChooser.APPROVE_OPTION) + { + @Override + public void run() + { + String filePath = chooser.getSelectedFile().getPath(); + Cache.setProperty("LAST_DIRECTORY", filePath); + NewickFile fin = null; + try + { + fin = new NewickFile(new FileParse( + chooser.getSelectedFile(), DataSourceType.FILE)); + viewport.setCurrentTree( + showNewickTree(fin, filePath).getTree()); + } catch (Exception ex) + { + JvOptionPane.showMessageDialog(Desktop.desktop, + ex.getMessage(), + MessageManager.getString( + "label.problem_reading_tree_file"), + JvOptionPane.WARNING_MESSAGE); + ex.printStackTrace(); + } + if (fin != null && fin.hasWarningMessage()) + { + JvOptionPane.showMessageDialog(Desktop.desktop, + fin.getWarningMessage(), + MessageManager.getString( + "label.possible_problem_with_tree_file"), + JvOptionPane.WARNING_MESSAGE); + } + } + }).openDialog(this); } public TreePanel showNewickTree(NewickFile nf, String treeTitle) @@ -4322,13 +4368,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Try to load a features file onto the alignment. * * @param file - * contents or path to retrieve file + * contents or path to retrieve file or a File object * @param sourceType * access mode of file (see jalview.io.AlignFile) * @return true if features file was parsed correctly. */ - public boolean parseFeaturesFile(String file, DataSourceType sourceType) + public boolean parseFeaturesFile(Object file, DataSourceType sourceType) { + // BH 2018 return avc.parseFeaturesFile(file, sourceType, Cache.getDefault("RELAXEDSEQIDMATCHING", false)); @@ -4375,8 +4422,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // Java's Transferable for native dnd evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = evt.getTransferable(); + + final AlignFrame thisaf = this; - final List files = new ArrayList<>(); + final List files = new ArrayList<>(); List protocols = new ArrayList<>(); try @@ -4404,20 +4453,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Object[] { String,SequenceI} */ ArrayList filesmatched = new ArrayList<>(); - ArrayList filesnotmatched = new ArrayList<>(); + ArrayList filesnotmatched = new ArrayList<>(); for (int i = 0; i < files.size(); i++) { - String file = files.get(i).toString(); + // BH 2018 + Object file = files.get(i); + String fileName = file.toString(); String pdbfn = ""; - DataSourceType protocol = FormatAdapter.checkProtocol(file); + DataSourceType protocol = (file instanceof File ? DataSourceType.FILE : FormatAdapter.checkProtocol(fileName)); if (protocol == DataSourceType.FILE) { - File fl = new File(file); + File fl = (file instanceof File ? (File) file : new File(fileName)); pdbfn = fl.getName(); } else if (protocol == DataSourceType.URL) { - URL url = new URL(file); + URL url = new URL(fileName); pdbfn = url.getFile(); } if (pdbfn.length() > 0) @@ -4439,7 +4490,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (mtch != null) { - FileFormatI type = null; + FileFormatI type; try { type = new IdentifyFile().identify(file, protocol); @@ -4461,17 +4512,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, int assocfiles = 0; if (filesmatched.size() > 0) { - if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false) - || JvOptionPane.showConfirmDialog(thisaf, - MessageManager.formatMessage( - "label.automatically_associate_structure_files_with_sequences_same_name", - new Object[] - { Integer.valueOf(filesmatched.size()) - .toString() }), - MessageManager.getString( - "label.automatically_associate_structure_files_by_name"), - JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION) - + boolean autoAssociate = Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false); + if (!autoAssociate) + { + String msg = MessageManager.formatMessage( + "label.automatically_associate_structure_files_with_sequences_same_name", + new Object[] + { Integer.valueOf(filesmatched.size()) + .toString() }); + String ttl = MessageManager.getString( + "label.automatically_associate_structure_files_by_name"); + int choice = JvOptionPane.showConfirmDialog(thisaf, msg, + ttl, JvOptionPane.YES_NO_OPTION); + autoAssociate = choice == JvOptionPane.YES_OPTION; + } + if (autoAssociate) { for (Object[] fm : filesmatched) { @@ -4497,6 +4552,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.paintAlignment(true, false); } } + else + { + /* + * add declined structures as sequences + */ + for (Object[] o : filesmatched) + { + filesnotmatched.add(o[0]); + } + } } if (filesnotmatched.size() > 0) { @@ -4516,7 +4581,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { return; } - for (String fn : filesnotmatched) + for (Object fn : filesnotmatched) { loadJalviewDataFile(fn, null, null, null); } @@ -4543,9 +4608,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param file * either a filename or a URL string. */ - public void loadJalviewDataFile(String file, DataSourceType sourceType, + public void loadJalviewDataFile(Object file, DataSourceType sourceType, FileFormatI format, SequenceI assocSeq) { + // BH 2018 was String file try { if (sourceType == null) @@ -5576,6 +5642,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void loadVcf_actionPerformed() { + // TODO: JAL-3048 - No VCF support in JsJalview JalviewFileChooser chooser = new JalviewFileChooser( Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); @@ -5593,6 +5660,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } + } class PrintThread extends Thread