* @return true if parsing resulted in something being imported to the view or
* dataset
*/
- public boolean parseFeaturesFile(String file, DataSourceType sourceType,
+ public boolean parseFeaturesFile(Object file, DataSourceType sourceType,
boolean relaxedIdMatching);
/**
}
@Override
- public boolean parseFeaturesFile(String file, DataSourceType protocol,
+ public boolean parseFeaturesFile(Object file, DataSourceType protocol,
boolean relaxedIdMatching)
{
boolean featuresAdded = false;
{
Viewer viewer = null;
- public JmolParser(boolean immediate, String inFile,
+ public JmolParser(boolean immediate, Object inFile,
DataSourceType sourceType) throws IOException
{
+ // BH 2018 File or String for filename
super(immediate, inFile, sourceType);
}
- public JmolParser(String inFile, DataSourceType sourceType)
+ public JmolParser(Object inFile, DataSourceType sourceType)
throws IOException
{
super(inFile, sourceType);
* params -o (output to sysout) -n (nodisplay) -x (exit when finished)
* see http://wiki.jmol.org/index.php/Jmol_Application
*/
+
viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
null, "-x -o -n", this);
// ensure the 'new' (DSSP) not 'old' (Ramachandran) SS method is used
* 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));
// Java's Transferable for native dnd
evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
Transferable t = evt.getTransferable();
+
+
final AlignFrame thisaf = this;
- final List<String> files = new ArrayList<>();
+ final List<Object> files = new ArrayList<>();
List<DataSourceType> protocols = new ArrayList<>();
try
* Object[] { String,SequenceI}
*/
ArrayList<Object[]> filesmatched = new ArrayList<>();
- ArrayList<String> filesnotmatched = new ArrayList<>();
+ ArrayList<Object> 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)
}
if (mtch != null)
{
- FileFormatI type = null;
+ FileFormatI type;
try
{
type = new IdentifyFile().identify(file, protocol);
{
return;
}
- for (String fn : filesnotmatched)
+ for (Object fn : filesnotmatched)
{
loadJalviewDataFile(fn, null, null, null);
}
* @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)
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
+import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.event.HyperlinkEvent;
checkURLLinks();
- this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
// Spawn a thread that shows the splashscreen
SwingUtilities.invokeLater(new Runnable()
} // end BH 2018 ignore
+ this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
+
this.addWindowListener(new WindowAdapter()
{
@Override
// Java's Transferable for native dnd
evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
Transferable t = evt.getTransferable();
- List<String> files = new ArrayList<>();
+ List<Object> files = new ArrayList<>();
List<DataSourceType> protocols = new ArrayList<>();
try
{
for (int i = 0; i < files.size(); i++)
{
- String file = files.get(i).toString();
+ // BH 2018 File or String
+ Object file = files.get(i);
+ String fileName = file.toString();
DataSourceType protocol = (protocols == null)
? DataSourceType.FILE
: protocols.get(i);
FileFormatI format = null;
- if (file.endsWith(".jar"))
+ if (fileName.endsWith(".jar"))
{
format = FileFormat.Jalview;
format = new IdentifyFile().identify(file, protocol);
}
- new FileLoader().LoadFile(file, protocol, format);
+ new FileLoader().LoadFile(null, file, protocol, format);
}
} catch (Exception ex)
ArrayList<JPanel> fileLoadingPanels = new ArrayList<>();
- public void startLoading(final String fileName)
+ public void startLoading(final Object fileName)
{
if (fileLoadingCount == 0)
{
* - the payload from the drop event
* @throws Exception
*/
- public static void transferFromDropTarget(List<String> files,
+ public static void transferFromDropTarget(List<Object> files,
List<DataSourceType> protocols, DropTargetDropEvent evt,
Transferable t) throws Exception
{
+
+ // BH 2018 changed List<String> to List<Object> to allow for File from SwingJS
+
+// DataFlavor[] flavors = t.getTransferDataFlavors();
+// for (int i = 0; i < flavors.length; i++) {
+// if (flavors[i].isFlavorJavaFileListType()) {
+// evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
+// List<File> list = (List<File>) t.getTransferData(flavors[i]);
+// for (int j = 0; j < list.size(); j++) {
+// File file = (File) list.get(j);
+// byte[] data = getDroppedFileBytes(file);
+// fileName.setText(file.getName() + " - " + data.length + " " + evt.getLocation());
+// JTextArea target = (JTextArea) ((DropTarget) evt.getSource()).getComponent();
+// target.setText(new String(data));
+// }
+// dtde.dropComplete(true);
+// return;
+// }
+//
DataFlavor uriListFlavor = new DataFlavor(
"text/uri-list;class=java.lang.String"), urlFlavour = null;
for (Object file : (List) t
.getTransferData(DataFlavor.javaFileListFlavor))
{
- files.add(((File) file).toString());
+ files.add(file);
protocols.add(DataSourceType.FILE);
}
}
// resolve any .lnk files in the file drop
for (int f = 0; f < files.size(); f++)
{
- String source = files.get(f).toLowerCase();
+ String source = files.get(f).toString().toLowerCase();
if (protocols.get(f).equals(DataSourceType.FILE)
&& (source.endsWith(".lnk") || source.endsWith(".url")
|| source.endsWith(".site")))
{
try {
- File lf = new File(files.get(f));
+ Object obj = files.get(f);
+ File lf = (obj instanceof File ? (File) obj : new File((String) obj));
// process link file to get a URL
Cache.log.debug("Found potential link file: " + lf);
WindowsShortcut wscfile = new WindowsShortcut(lf);
* @param sourceType
* What type of file to read from (File, URL, Pasted String)
*/
- public AlignFile(String dataObject, DataSourceType sourceType)
+ public AlignFile(Object dataObject, DataSourceType sourceType)
throws IOException
{
this(true, dataObject, sourceType);
* What type of file to read from (File, URL)
* @throws IOException
*/
- public AlignFile(boolean parseImmediately, String dataObject,
+ public AlignFile(boolean parseImmediately, Object dataObject,
DataSourceType sourceType) throws IOException
{
+ // BH allows File or String
super(dataObject, sourceType);
initData();
if (parseImmediately)
String refSeqId = null;
- public boolean annotateAlignmentView(AlignViewportI viewport, String file,
+ public boolean annotateAlignmentView(AlignViewportI viewport, Object file,
DataSourceType protocol)
{
ColumnSelection colSel = viewport.getColumnSelection();
}
public boolean readAnnotationFile(AlignmentI al, HiddenColumns hidden,
- String file, DataSourceType sourceType)
+ Object file, DataSourceType sourceType)
{
BufferedReader in = null;
try
{
if (sourceType == DataSourceType.FILE)
{
- in = new BufferedReader(new FileReader(file));
+ in = FileLoader.getBuffereReader(file);
}
else if (sourceType == DataSourceType.URL)
{
- URL url = new URL(file);
+ URL url = new URL(file.toString());
in = new BufferedReader(new InputStreamReader(url.openStream()));
}
else if (sourceType == DataSourceType.PASTE)
{
- in = new BufferedReader(new StringReader(file));
+ in = new BufferedReader(new StringReader(file.toString()));
}
else if (sourceType == DataSourceType.CLASSLOADER)
{
if (isParseWithJMOL)
{
// needs a File option
- alignFile = new JmolParser(inFile, sourceType);
+ alignFile = new JmolParser(selectedFile == null ? inFile : selectedFile, sourceType);
}
else
{
return null;
}
+
/**
* Determines the protocol (i.e DataSourceType.{FILE|PASTE|URL}) for the input
* data
+ *
+ * BH 2018 allows File or String, and can return RELATIVE_URL
*
- * @param data
+ * @param dataObject File or String
* @return the protocol for the input data
*/
- public static DataSourceType checkProtocol(String data)
+ public static DataSourceType checkProtocol(Object dataObject)
{
+ if(dataObject instanceof File)
+ return DataSourceType.FILE;
+
+ String data = dataObject.toString();
DataSourceType protocol = DataSourceType.PASTE;
String ft = data.toLowerCase().trim();
if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0
/**
* Constructor which does not parse the file immediately
*
- * @param file
+ * @param file File or String filename
* @param paste
* @throws IOException
*/
- public FeaturesFile(String file, DataSourceType paste)
+ public FeaturesFile(Object file, DataSourceType paste)
throws IOException
{
super(false, file, paste);
* @param type
* @throws IOException
*/
- public FeaturesFile(boolean parseImmediately, String file,
+ public FeaturesFile(boolean parseImmediately, Object file,
DataSourceType type) throws IOException
{
super(parseImmediately, file, type);
import jalview.util.MessageManager;
import jalview.ws.utils.UrlDownloadClient;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Vector;
this.raiseGUI = raiseGUI;
}
- public void LoadFile(AlignViewport viewport, String file,
+ public void LoadFile(AlignViewport viewport, Object file,
DataSourceType protocol, FileFormatI format)
{
this.viewport = viewport;
- LoadFile(file, protocol, format);
- }
-
- public void LoadFile(AlignViewport viewport, File selectedFile,
- DataSourceType protocol, FileFormatI format)
- {
- this.viewport = viewport;
- this.selectedFile = selectedFile;
- LoadFile(selectedFile.getPath(), protocol, format);
+ if (file instanceof File) {
+ this.selectedFile = (File) file;
+ file = selectedFile.getPath();
+ }
+ LoadFile(file.toString(), protocol, format);
}
public void LoadFile(String file, DataSourceType protocol,
return tempStructFile.toString();
}
+ /**
+ *
+ * @param file a File, or a String which is a name of a file
+ * @return
+ * @throws FileNotFoundException
+ */
+ @SuppressWarnings("unused")
+ public static BufferedReader getBuffereReader(Object file) throws FileNotFoundException {
+ if (file instanceof String)
+ return new BufferedReader(new FileReader((String) file));
+
+ byte[] bytes = /** @j2sNative file._bytes || */ null;
+ if (bytes != null)
+ return new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes)));
+ return new BufferedReader(new FileReader((File) file));
+ }
+
}
import java.net.URL;
import java.util.zip.GZIPInputStream;
-import javajs.util.Rdr;
-
/**
* implements a random access wrapper around a particular datasource, for
* passing to identifyFile and AlignFile objects.
public File inFile = null;
- public byte[] bytes; // from JavaScript
+ private byte[] bytes; // from JavaScript
+ public byte[] getBytes()
+ {
+ return bytes;
+ }
/**
* a viewport associated with the current file operation. May be null. May
* move to different object.
* Create a datasource for input to Jalview. See AppletFormatAdapter for the
* types of sources that are handled.
*
- * @param fileStr
- * - datasource locator/content
+ * @param file
+ * - datasource locator/content as File or String
* @param sourceType
* - protocol of source
* @throws MalformedURLException
* @throws IOException
*/
- public FileParse(String fileStr, DataSourceType sourceType)
- throws MalformedURLException, IOException
- {
-
- this(null, fileStr, sourceType, false);
- }
-
- public FileParse(File file, DataSourceType sourceType)
+ public FileParse(Object file, DataSourceType sourceType)
throws MalformedURLException, IOException
{
-
- this(file, file.getPath(), sourceType, true);
+ if (file instanceof File)
+ {
+ parse((File) file, ((File) file).getPath(), sourceType, true);
+ }
+ else
+ {
+ parse(null, file.toString(), sourceType, false);
+ }
}
- private FileParse(File file, String fileStr, DataSourceType sourceType,
+ private void parse(File file, String fileStr, DataSourceType sourceType,
boolean isFileObject) throws MalformedURLException, IOException
{
-
/**
* @j2sNative
*
{
// this will be from JavaScript
inFile = file;
- dataIn = new BufferedReader(new java.io.InputStreamReader(new ByteArrayInputStream(bytes)));
+ dataIn = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes)));
dataName = fileStr;
}
else if (checkFileSource(fileStr))
}
else if (sourceType == DataSourceType.RELATIVE_URL)
{
- String data = null;
/**
* BH 2018 hack for no support for access-origin
*
* @j2sNative
*
- * data = $.ajax({url:fileStr, async:false}).responseText;
+ * this.bytes = swingjs.JSToolkit.getFileAsBytes(fileStr);
*
*/
- dataIn = Rdr.getBR(data);
-
+ dataIn = new BufferedReader(new java.io.InputStreamReader(new ByteArrayInputStream(bytes)));
dataName = fileStr;
}
*/
public class IdentifyFile
{
+
+ public FileFormatI identify(Object file, DataSourceType protocol) throws FileFormatException
+ {
+ // BH 2018
+ return (file instanceof File ? identify((File) file, protocol) : identify((String) file, protocol));
+
+ }
+
public FileFormatI identify(File file, DataSourceType sourceType)
throws FileFormatException
{
+ // BH 2018
String emessage = "UNIDENTIFIED FILE PARSING ERROR";
FileParse parser = null;
try
}
}
+
}
/**
* Creates a new JPredFile object.
*
+ * BH allows File or String
+ *
* @param inFile
* DOCUMENT ME!
* @param sourceType
* @throws IOException
* DOCUMENT ME!
*/
- public JPredFile(String inFile, DataSourceType sourceType)
+ public JPredFile(Object inFile, DataSourceType sourceType)
throws IOException
{
super(inFile, sourceType);
private boolean pdbIdAvailable;
- public StructureFile(String inFile, DataSourceType sourceType)
+ public StructureFile(Object inFile, DataSourceType sourceType)
throws IOException
{
super(inFile, sourceType);
}
- public StructureFile(boolean parseImmediately, String dataObject,
+ public StructureFile(boolean parseImmediately, Object dataObject,
DataSourceType sourceType) throws IOException
{
super(parseImmediately, dataObject, sourceType);
Integer fWidth;
- public TCoffeeScoreFile(String inFile, DataSourceType fileSourceType)
+ public TCoffeeScoreFile(Object inFile, DataSourceType fileSourceType)
throws IOException
{
+ // BH 2018 allows File or String
super(inFile, fileSourceType);
}
*/
public GDesktop()
{
+ super();
try
{
jbInit();