From: Ben Soares Date: Fri, 13 Sep 2024 14:26:23 +0000 (+0100) Subject: JAL-4461 Adding in a number of properties that control the default save_as format... X-Git-Tag: Release_2_11_4_0~6^2~1^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b2ba3f351c30380ae7a0dd204757d7c3b54dad7f;p=jalview.git JAL-4461 Adding in a number of properties that control the default save_as format. See issue for details. --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 72148f2..d5fb845 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1480,7 +1480,7 @@ action.clustering_matrix_for = Calculating tree for matrix {0} and clustering at action.cluster_matrix_tooltip = Computes an average distance tree for the matrix and displays it label.all_known_alignment_files = All known alignment files label.by_extension = By extension -label.by_extension_tooltip = File will be saved in a format corresponding to the given file extension (if the extension is recognised) +label.by_extension_tooltip = File will be saved in a format corresponding to the given file extension label.command_line_arguments = Command Line Arguments warning.using_old_command_line_arguments = It looks like you are using old command line arguments. These are now deprecated and will be removed in a future release of Jalview.\nFind out about the new command line arguments at\n warning.using_mixed_command_line_arguments = Jalview cannot use both old (-arg) and new (--arg) command line arguments. Please check your command line arguments.\ne.g. {0} and {1} diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 23c6671..b8200fa 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1445,7 +1445,7 @@ prompt.analytics_title = Jalview Estad prompt.analytics = ¿Quiere ayudar a mejorar Jalview habilitando la recopilación de estadísticas de uso con análisis Plausible?\nPuede habilitar o deshabilitar el seguimiento de uso en las preferencias. label.all_known_alignment_files = Todos los archivos de alineación conocidos label.by_extension = Por extensión -label.by_extension_tooltip = El archivo se guardará en un formato correspondiente a la extensión de archivo indicada (si se reconoce la extensión) +label.by_extension_tooltip = El archivo se guardará en un formato correspondiente a la extensión de archivo indicada label.command_line_arguments = Argumentos de línea de comando warning.using_old_command_line_arguments = Parece que estás utilizando argumentos antiguos de línea de comando. Estos ahora están en desuso y se eliminarán en una versión futura de Jalview.\nObtenga más información sobre los nuevos argumentos de la línea de comando en\n warning.using_mixed_command_line_arguments = Jalview no puede utilizar argumentos de línea de comando antiguos (-arg) y nuevos (--arg). Verifique los argumentos de su línea de comando.\ne.g. {0} y {1} diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index ada1cf9..1b42acb 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1184,10 +1184,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void saveAs_actionPerformed() { - String format = currentFileFormat == null ? null - : currentFileFormat.getName(); - JalviewFileChooser chooser = JalviewFileChooser - .forWrite(Cache.getProperty("LAST_DIRECTORY"), format, true); + JalviewFileChooser chooser = JalviewFileChooser.forWrite( + Cache.getProperty("LAST_DIRECTORY"), + currentFileFormat == null ? null : currentFileFormat.getName(), + true); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( @@ -1205,10 +1205,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { // if the autodetect format from extension failed.. JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString( - "label.select_file_format_before_saving"), - MessageManager.getString("label.file_format_not_specified"), - JvOptionPane.WARNING_MESSAGE); + MessageManager + .getString("label.select_file_format_before_saving"), + MessageManager.getString("label.file_format_not_specified"), + JvOptionPane.WARNING_MESSAGE); value = chooser.showSaveDialog(this); if (value != JalviewFileChooser.APPROVE_OPTION) { @@ -1230,6 +1230,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, String lastFilenameSaved; + // globalLastFormatSaved across alignment windows (only for alignments with no + // previous format) + private static FileFormatI globalLastFormatSaved = null; + + public static FileFormatI getLastAlignmentSavedFormat() + { + return globalLastFormatSaved; + } + /** * Raise a dialog or status message for the last call to saveAlignment. * @@ -1290,6 +1299,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, lastFilenameSaved = file; } lastFormatSaved = format; + globalLastFormatSaved = format; if (FileFormat.Jalview.equals(format)) { diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index ffddeb8..00e1647 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -612,11 +612,9 @@ public class Desktop extends jalview.jbgui.GDesktop public void run() { jalview.bin.Console.debug("Filechooser init thread started."); - String fileFormat = FileLoader.getUseDefaultFileFormat() - ? Cache.getProperty("DEFAULT_FILE_FORMAT") - : null; + // default file format now determined by JalviewFileChooser JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"), - fileFormat); + null); jalview.bin.Console.debug("Filechooser init thread finished."); } }).start(); @@ -1216,6 +1214,7 @@ public class Desktop extends jalview.jbgui.GDesktop /** * load all files dropped (2.11.4.0 behaviour) + * * @return false if any file resulted in an error */ public boolean loadDroppedFiles(List files, @@ -1254,7 +1253,7 @@ public class Desktop extends jalview.jbgui.GDesktop "Unexpected Exception when handling " + file.toString(), x); } } - return failed.size()==0; // at least one was loaded. + return failed.size() == 0; // at least one was loaded. } /** @@ -1428,7 +1427,7 @@ public class Desktop extends jalview.jbgui.GDesktop } return failed.size() == 0; // redundant for 2.11.4.0 implementation } - + @Override public void drop(DropTargetDropEvent evt) { @@ -1484,11 +1483,9 @@ public class Desktop extends jalview.jbgui.GDesktop @Override public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport) { - String fileFormat = FileLoader.getUseDefaultFileFormat() - ? Cache.getProperty("DEFAULT_FILE_FORMAT") - : null; + // default file format now determined by JalviewFileChooser JalviewFileChooser chooser = JalviewFileChooser.forRead( - Cache.getProperty("LAST_DIRECTORY"), fileFormat, + Cache.getProperty("LAST_DIRECTORY"), null, BackupFiles.getEnabled()); chooser.setFileView(new JalviewFileView()); @@ -2979,13 +2976,13 @@ public class Desktop extends jalview.jbgui.GDesktop } /** - * Progress bars managed by the IProgressIndicator method. - * TODO - delegate to jalview.gui.ProgressBar + * Progress bars managed by the IProgressIndicator method. TODO - delegate to + * jalview.gui.ProgressBar */ private Hashtable progressBars; private Hashtable progressBarHandlers; - + private Hashtable progressBarMessages; /* @@ -3015,9 +3012,12 @@ public class Desktop extends jalview.jbgui.GDesktop else { progressBars.put(Long.valueOf(id), addProgressPanel(message)); - if (message!=null) { + if (message != null) + { progressBarMessages.put(id, message); - } else { + } + else + { progressBarMessages.remove(id); } } @@ -3080,20 +3080,20 @@ public class Desktop extends jalview.jbgui.GDesktop } } - @Override public String getMessage(long id) { return progressBarMessages.get(id); } - + /** * change the text shown alongside a progress bar + * * @param id * @param message */ @Override - public void setProgressBarMessage(long id,String message) + public void setProgressBarMessage(long id, String message) { Container progBar = progressBars.get(id); if (progBar == null || progBar.getComponentCount() == 0) @@ -3104,12 +3104,13 @@ public class Desktop extends jalview.jbgui.GDesktop { if (component.getClass().equals(JLabel.class)) { - ((JLabel) component).setText(message);; + ((JLabel) component).setText(message); + ; progBar.revalidate(); } } } - + /** * * @return true if any progress bars are still active diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 4fb013f..883d270 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -1106,9 +1106,9 @@ public class Preferences extends GPreferences Cache.disableSessionProperties(); // TODO: JAL-3048 not needed for Jalview-JS - String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + // default file format now determined by JalviewFileChooser JalviewFileChooser chooser = JalviewFileChooser - .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat); + .forRead(Cache.getProperty("LAST_DIRECTORY"), null); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( MessageManager.getString("label.select_startup_file")); diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index 957e47c..de5ad7d 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -59,6 +59,7 @@ import javax.swing.filechooser.FileFilter; import javax.swing.plaf.basic.BasicFileChooserUI; import jalview.bin.Cache; +import jalview.gui.AlignFrame; import jalview.gui.JvOptionPane; import jalview.util.ChannelProperties; import jalview.util.MessageManager; @@ -93,6 +94,20 @@ public class JalviewFileChooser extends JFileChooser protected boolean includeBackupFiles = false; /** + * default file format preference settings + */ + public final static String DEFAULT_FORMAT_PROPERTY = "DEFAULT_FILE_FORMAT"; + + public final static String DEFAULT_SAVE_FORMAT_PROPERTY = "DEFAULT_SAVE_FILE_FORMAT"; + + public final static String USE_LAST_SAVED_FORMAT_VALUE = "USE_LAST_SAVED"; + + // normally an alignment will default to saving as the format it was loaded or + // most recently saved as. Setting this will ignore that and use the + // preference default save format. + public final static String ALWAYS_USE_DEFAULT_SAVED_FORMAT_PROPERTY = "ALWAYS_USE_DEFAULT_SAVE_FORMAT"; + + /** * Factory method to return a file chooser that offers readable alignment file * formats * @@ -120,6 +135,11 @@ public class JalviewFileChooser extends JFileChooser } } + if (selected == null) + { + selected = defaultLoadFileFormat(); + } + return new JalviewFileChooser(directory, extensions.toArray(new String[extensions.size()]), descs.toArray(new String[descs.size()]), selected, true, @@ -135,12 +155,6 @@ public class JalviewFileChooser extends JFileChooser * @return */ public static JalviewFileChooser forWrite(String directory, - String selected) - { - return forWrite(directory, selected, false); - } - - public static JalviewFileChooser forWrite(String directory, String selected, boolean addSelectFormatFromFileExtension) { // TODO in Java 8, forRead and forWrite can be a single method @@ -155,9 +169,11 @@ public class JalviewFileChooser extends JFileChooser descs.add(format.getName()); } } + return new JalviewFileChooser(directory, extensions.toArray(new String[extensions.size()]), - descs.toArray(new String[descs.size()]), selected, false, false, + descs.toArray(new String[descs.size()]), + defaultSaveFileFormat(selected), false, false, addSelectFormatFromFileExtension); } @@ -443,9 +459,9 @@ public class JalviewFileChooser extends JFileChooser MessageManager.getString("label.by_extension_tooltip")); JalviewFileFilter jvf = (JalviewFileFilter) dd.getSelectedItem(); Iterator extensions = jvf.getExtensions(); - if (extensions.hasNext()) + if (extensions.hasNext()) // hasAny() { - sb.append(" (."); + sb.append("\n(."); while (extensions.hasNext()) { sb.append(extensions.next()); @@ -916,4 +932,37 @@ public class JalviewFileChooser extends JFileChooser return dialog; } -} + /** + * return a default file format + */ + public static String defaultLoadFileFormat() + { + return FileLoader.getUseDefaultFileFormat() + ? Cache.getProperty(DEFAULT_FORMAT_PROPERTY) + : null; + } + + public static String defaultSaveFileFormat(String lastUsedFormat) + { + if (!Cache.getDefault(ALWAYS_USE_DEFAULT_SAVED_FORMAT_PROPERTY, false) + && lastUsedFormat != null) + { + return lastUsedFormat; + } + + String pref = Cache.getDefault(DEFAULT_SAVE_FORMAT_PROPERTY, null); + if (USE_LAST_SAVED_FORMAT_VALUE.equals(pref)) + { + FileFormatI globalLastSavedFormat = AlignFrame + .getLastAlignmentSavedFormat(); + if (globalLastSavedFormat != null || lastUsedFormat != null) + { + return globalLastSavedFormat != null + ? globalLastSavedFormat.toString() + : lastUsedFormat; + } + } + return pref == null ? FileFormat.Fasta.getName() : pref; + } + +} \ No newline at end of file