From 58399507cc82e8c7940a8500af73c3ed1bdd720d Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Thu, 2 Jul 2015 16:37:56 +0100 Subject: [PATCH] JAL-1443 data validation for empty content before loading alignment from file or clipboard --- src/jalview/bin/Jalview.java | 12 +++++++++++- src/jalview/gui/CutAndPasteTransfer.java | 8 +++++++- src/jalview/io/FileLoader.java | 16 ++++++++++++++++ src/jalview/io/IdentifyFile.java | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 00a042d..f4b38d4 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -963,6 +963,16 @@ public class Jalview } return ff; } + + public static boolean isHeadlessMode() + { + String isheadless = System.getProperty("java.awt.headless"); + if (isheadless != null && isheadless.equalsIgnoreCase("true")) + { + return true; + } + return false; + } } /** @@ -1131,4 +1141,4 @@ class FeatureFetcher return queued == 0 && running == 0; } -}; +} diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index e663cf8..979d1aa 100644 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -195,7 +195,13 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer */ public void ok_actionPerformed(ActionEvent e) { - String format = new IdentifyFile().Identify(getText(), "Paste"); + String text = getText(); + if (text.trim().length() < 1) + { + return; + } + + String format = new IdentifyFile().Identify(text, "Paste"); // TODO: identify feature, annotation or tree file and parse appropriately. AlignmentI al = null; diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 18ab642..3aded05 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -22,6 +22,7 @@ package jalview.io; import jalview.api.ComplexAlignFile; import jalview.api.FeaturesDisplayedI; +import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; @@ -257,6 +258,21 @@ public class FileLoader implements Runnable { format = new IdentifyFile().Identify(file, protocol); } + + } + + if (format == null || format.equalsIgnoreCase("EMPTY DATA FILE")) + { + Desktop.instance.stopLoading(); + System.err.println("The input file \"" + file + + "\" has no data content!"); + if (!Jalview.isHeadlessMode()) + { + JOptionPane.showMessageDialog(null, "The input file \"" + + file + "\" has no data content!", "Empty data file", + JOptionPane.ERROR_MESSAGE); + } + return; } // TODO: cache any stream datasources as a temporary file (eg. PDBs // retrieved via URL) diff --git a/src/jalview/io/IdentifyFile.java b/src/jalview/io/IdentifyFile.java index 27f08ae..4c83ac1 100755 --- a/src/jalview/io/IdentifyFile.java +++ b/src/jalview/io/IdentifyFile.java @@ -98,7 +98,7 @@ public class IdentifyFile } while ((data = source.nextLine()) != null) { - length += data.length(); + length += data.trim().length(); if (!lineswereskipped) { for (int i = 0; !isBinary && i < data.length(); i++) -- 1.7.10.2