*/
package jalview.gui;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DropTargetDragEvent;
+import java.awt.dnd.DropTargetDropEvent;
+import java.awt.dnd.DropTargetEvent;
+import java.awt.dnd.DropTargetListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusAdapter;
+import java.awt.event.FocusEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.print.PageFormat;
+import java.awt.print.PrinterJob;
+import java.beans.PropertyChangeEvent;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JEditorPane;
+import javax.swing.JInternalFrame;
+import javax.swing.JLayeredPane;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
+
import jalview.analysis.AlignmentSorter;
import jalview.analysis.AlignmentUtils;
import jalview.analysis.CrossRef;
import jalview.schemes.ResidueColourScheme;
import jalview.schemes.TCoffeeColourScheme;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
import jalview.ws.jws2.jabaws2.Jws2Instance;
import jalview.ws.seqfetcher.DbSourceProxy;
-import java.awt.BorderLayout;
-import java.awt.Component;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.StringSelection;
-import java.awt.datatransfer.Transferable;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DropTargetDragEvent;
-import java.awt.dnd.DropTargetDropEvent;
-import java.awt.dnd.DropTargetEvent;
-import java.awt.dnd.DropTargetListener;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.FocusAdapter;
-import java.awt.event.FocusEvent;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.print.PageFormat;
-import java.awt.print.PrinterJob;
-import java.beans.PropertyChangeEvent;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.PrintWriter;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Deque;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Vector;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JEditorPane;
-import javax.swing.JInternalFrame;
-import javax.swing.JLayeredPane;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JScrollPane;
-import javax.swing.SwingUtilities;
-
/**
* DOCUMENT ME!
*
else
{
// create backupfiles object and get new temp filename destination
+ Cache.log.debug("ALIGNFRAME making backupfiles object for " + file);
BackupFiles backupfiles = new BackupFiles(file);
try
{
+ Cache.log.debug("ALIGNFRAME setting PrintWriter");
PrintWriter out = new PrintWriter(
new FileWriter(backupfiles.getTempFilePath()));
+ Cache.log.debug("ALIGNFRAME using temp file "
+ + backupfiles.getTempFilePath());
+
out.print(output);
+ Cache.log.debug("ALIGNFRAME about to close file");
out.close();
+ Cache.log.debug("ALIGNFRAME closed file");
this.setTitle(file);
statusBar.setText(MessageManager.formatMessage(
"label.successfully_saved_to_file_in_format", new Object[]
{ fileName, format.getName() }));
+ } catch (IOException e)
+ {
+ success = false;
+ Cache.log.error(
+ "ALIGNFRAME Something happened writing the temp file");
+ Cache.log.error(e.getMessage());
+ Cache.log.debug(e.getStackTrace());
+
} catch (Exception ex)
{
success = false;
- ex.printStackTrace();
+ Cache.log.error(
+ "ALIGNFRAME Something else happened writing the temp file");
+ Cache.log.error(ex.getMessage());
+ Cache.log.debug(ex.getStackTrace());
}
backupfiles.setWriteSuccess(success);
+ Cache.log.debug("ALIGNFRAME writing temp file was "
+ + (success ? "" : "not ") + "successful");
// do the backup file roll and rename the temp file to actual file
+ Cache.log.debug("ALIGNFRAME about to rollBackupsAndRenameTempFile");
success = backupfiles.rollBackupsAndRenameTempFile();
+ Cache.log.debug("ALIGNFRAME performed rollBackupsAndRenameTempFile "
+ + (success ? "" : "un") + "successfully");
}
}
if (!success)
{
- JvOptionPane.showInternalMessageDialog(this, MessageManager
- .formatMessage("label.couldnt_save_file", new Object[]
- { fileName }),
- MessageManager.getString("label.error_saving_file"),
- JvOptionPane.WARNING_MESSAGE);
+ if (!Platform.isHeadless())
+ {
+ JvOptionPane.showInternalMessageDialog(this, MessageManager
+ .formatMessage("label.couldnt_save_file", new Object[]
+ { fileName }),
+ MessageManager.getString("label.error_saving_file"),
+ JvOptionPane.WARNING_MESSAGE);
+ }
}
return success;
if (viewport.getViewName() == null)
{
- viewport.setViewName(MessageManager
- .getString("label.view_name_original"));
+ viewport.setViewName(
+ MessageManager.getString("label.view_name_original"));
}
/*
* otherwise set the chosen colour scheme (or null for 'None')
*/
ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name,
- viewport,
- viewport.getAlignment(), viewport.getHiddenRepSequences());
+ viewport, viewport.getAlignment(),
+ viewport.getHiddenRepSequences());
changeColour(cs);
}
}
private Rectangle lastFeatureSettingsBounds = null;
+
@Override
public void setFeatureSettingsGeometry(Rectangle bounds)
{
{
String tempfilename = file.getName();
File tempdir = file.getParentFile();
+ Cache.log.debug(
+ "BACKUPFILES [file!=null] attempting to create temp file "
+ + tempfilename + " in dir " + tempdir);
temp = File.createTempFile(tempfilename,
TEMP_FILE_EXT + newTempFileSuffix, tempdir);
}
else
{
+ Cache.log.debug(
+ "BACKUPFILES [file==null] attempting to create default temp file "
+ + DEFAULT_TEMP_FILE + " with extension "
+ + TEMP_FILE_EXT);
temp = File.createTempFile(DEFAULT_TEMP_FILE, TEMP_FILE_EXT);
}
} catch (IOException e)
{
- Cache.log.error(
- "Could not create temp file to save into (IOException)");
+ Cache.log
+ .error("Could not create temp file to save to (IOException)");
+ Cache.log.error(e.getMessage());
+ Cache.log.debug(e.getStackTrace());
} catch (Exception e)
{
Cache.log.error("Exception ctreating temp file for saving");
+ Cache.log.debug(e.getStackTrace());
}
this.setTempFile(temp);
}
public static void classInit()
{
+ Cache.log.debug("BACKUPFILES classInit");
setEnabled(Cache.getDefault(ENABLED, true));
BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
.getSavedBackupEntry();
Cache.log.error(
"IOException when getting Canonical Path of temp file '"
+ this.getTempFile().getName() + "'");
+ Cache.log.debug(e.getStackTrace());
}
return path;
}
return true;
}
+ Cache.log.debug("BACKUPFILES rollBackupFiles starting");
+
String dir = "";
File dirFile;
try
{
dirFile = file.getParentFile();
dir = dirFile.getCanonicalPath();
- Cache.log.debug("BACKUPFILES: dir: " + dir);
+ Cache.log.debug("BACKUPFILES dir: " + dir);
} catch (Exception e)
{
Cache.log.error(
"Could not get canonical path for file '" + file + "'");
+ Cache.log.error(e.getMessage());
+ Cache.log.debug(e.getStackTrace());
return false;
}
String filename = file.getName();
String basename = filename;
+ Cache.log.debug("BACKUPFILES filename is " + filename);
boolean ret = true;
// Create/move backups up one
if (backupFiles.length == 0)
{
// No other backup files. Just need to move existing file to backupfile_1
+ Cache.log.debug(
+ "BACKUPFILES no existing backup files, setting index to 1");
nextIndexNum = 1;
}
else
if (reverseOrder)
{
// backup style numbering
+ Cache.log.debug("BACKUPFILES rolling files in reverse order");
int tempMax = noMax ? -1 : max;
// noMax == true means no limits
// no "oldest" file to delete
previousFile = backupfile_n;
fileToBeDeleted = null;
+ Cache.log.debug("BACKUPFILES No oldest file to delete");
continue;
}
File replacementFile = backupfile_n;
long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
long replacementFileLMT = replacementFile.lastModified();
+ Cache.log.debug("BACKUPFILES fileToBeDeleted is "
+ + fileToBeDeleted.getAbsolutePath());
+ Cache.log.debug("BACKUPFILES replacementFile is "
+ + backupfile_n.getAbsolutePath());
try
{
boolean delete = confirmNewerDeleteFile(fileToBeDeleted,
replacementFile, true);
+ Cache.log.debug("BACKUPFILES "
+ + (delete ? "confirmed" : "not") + " deleting file "
+ + fileToBeDeleted.getAbsolutePath()
+ + " which is newer than "
+ + replacementFile.getAbsolutePath());
if (delete)
{
}
else
{
+ Cache.log.debug("BACKUPFILES moving "
+ + fileToBeDeleted.getAbsolutePath() + " to "
+ + oldestTempFile.getAbsolutePath());
moveFileToFile(fileToBeDeleted, oldestTempFile);
}
}
else
{
+ Cache.log.debug("BACKUPFILES going to move "
+ + fileToBeDeleted.getAbsolutePath() + " to "
+ + oldestTempFile.getAbsolutePath());
moveFileToFile(fileToBeDeleted, oldestTempFile);
addDeleteFile(oldestTempFile);
}
if (delete)
{
addDeleteFile(fileToBeDeleted);
- Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDelted): "
+ Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): "
+ fileToBeDeleted);
}
int pos = deleteFiles.indexOf(fileToBeDeleted);
if (pos > -1)
{
+ Cache.log.debug("BACKUPFILES not adding file "
+ + fileToBeDeleted.getAbsolutePath()
+ + " to the delete list (already at index" + pos + ")");
return true;
}
else
{
+ Cache.log.debug("BACKUPFILES adding file "
+ + fileToBeDeleted.getAbsolutePath() + " to the delete list");
deleteFiles.add(fileToBeDeleted);
}
return ret;
try
{
// delete destination file - not usually necessary but Just In Case...
+ Cache.log.debug("BACKUPFILES deleting " + newFile.getAbsolutePath());
newFile.delete();
+ Cache.log.debug("BACKUPFILES moving " + oldFile.getAbsolutePath()
+ + " to " + newFile.getAbsolutePath());
Files.move(oldPath, newPath, StandardCopyOption.REPLACE_EXISTING);
ret = true;
+ Cache.log.debug("BACKUPFILES move seemse to have succeeded");
} catch (IOException e)
{
Cache.log.warn("Could not move file '" + oldPath.toString() + "' to '"
+ newPath.toString() + "'");
- Cache.log.error(e.getStackTrace());
+ Cache.log.error(e.getMessage());
+ Cache.log.debug(e.getStackTrace());
ret = false;
} catch (Exception e)
{
Cache.log.error(e.getMessage());
- Cache.log.error(e.getStackTrace());
+ Cache.log.debug(e.getStackTrace());
ret = false;
}
return ret;