import jalview.util.CaseInsensitiveString;
+import java.io.File;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Hashtable;
private static final int PDB_ID_LENGTH = 4;
- private String file;
+ private String fileName;
+
+ private File file;
private String type;
*/
boolean idMatches = id == o.id
|| (id != null && id.equalsIgnoreCase(o.id));
- boolean fileMatches = file == o.file
- || (file != null && file.equals(o.file));
+ boolean fileMatches = fileName == o.fileName
+ || (fileName != null && fileName.equals(o.fileName));
boolean typeMatches = type == o.type
|| (type != null && type.equals(o.type));
if (idMatches && fileMatches && typeMatches)
* @param entryType
* @param filePath
*/
- void init(String pdbId, String chain, PDBEntry.Type entryType,
+ private void init(String pdbId, String chain, PDBEntry.Type entryType,
String filePath)
{
this.id = pdbId;
this.type = entryType == null ? null : entryType.toString();
- this.file = filePath;
+ this.fileName = filePath;
setChainCode(chain);
}
*/
public PDBEntry(PDBEntry entry)
{
- file = entry.file;
+ fileName = entry.fileName;
type = entry.type;
id = entry.id;
if (entry.properties != null)
public void setFile(String f)
{
+ this.fileName = f;
+ }
+
+ public void setFile(File f)
+ {
this.file = f;
}
public String getFile()
{
- return file;
+ return (file != null ? file.getAbsolutePath() : fileName);
+ }
+
+ public File getFileF()
+ {
+ return (file == null ? new File(fileName) : file);
}
public void setType(String t)
{
setFile(newFile);
setType(newType);
+ setFile(newEntry.getFileF());
}
/*
closeViewer(false);
}
});
- initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
+ initJmol(loadStatus, null); // pdbentry, seq, JBPCHECK!
}
@Override
setSize(400, 400); // probably should be a configurable/dynamic default here
initMenus();
addingStructures = false;
- worker = new Thread(this);
- worker.start();
this.addInternalFrameListener(new InternalFrameAdapter()
{
}
});
+ worker = new Thread(this);
+ worker.start();
}
/**
}
- void initJmol(String command)
+ private void initJmol(String command, List<File> files)
{
jmb.setFinishedInit(false);
renderPanel = new RenderPanel();
if (command == null)
{
command = "";
+ } else if (files != null) {
+ jmb.cacheFiles(files);
}
jmb.evalStateCommand(command);
jmb.evalStateCommand("set hoverDelay=0.1");
_started = true;
try
{
- List<String> files = fetchPdbFiles();
+ List<File> files = fetchPdbFiles();
if (files.size() > 0)
{
showFilesInViewer(files);
* @param files
* list of absolute paths to structure files
*/
- void showFilesInViewer(List<String> files)
+ void showFilesInViewer(List<File> files)
{
long lastnotify = jmb.getLoadNotifiesHandled();
StringBuilder fileList = new StringBuilder();
- for (String s : files)
+ for (File f : files)
{
+ String s = f.getAbsolutePath();
fileList.append(SPACE).append(QUOTE)
.append(Platform.escapeString(s)).append(QUOTE);
}
{
try
{
- initJmol("load FILES " + filesString);
+ initJmol("load FILES " + filesString, files);
} catch (OutOfMemoryError oomerror)
{
new OOMWarning("When trying to open the Jmol viewer!", oomerror);
try
{
+ jmb.cacheFiles(files);
jmb.evalStateCommand(command);
} catch (OutOfMemoryError oomerror)
{
*
* @return
*/
- List<String> fetchPdbFiles()
+ List<File> fetchPdbFiles()
{
// todo - record which pdbids were successfully imported.
StringBuilder errormsgs = new StringBuilder();
- List<String> files = new ArrayList<>();
+ List<File> files = new ArrayList<>();
String pdbid = "";
try
{
Pdb pdbclient = new Pdb();
for (int pi = 0; pi < jmb.getPdbCount(); pi++)
{
- String file = jmb.getPdbEntry(pi).getFile();
+ File file = jmb.getPdbEntry(pi).getFileF();
if (file == null)
{
// todo: extract block as method and pull up (also ChimeraViewFrame)
// just transfer the file name from the first sequence's first
// PDBEntry
file = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
- .elementAt(0).getFile()).getAbsolutePath();
+ .elementAt(0).getFile());
jmb.getPdbEntry(pi).setFile(file);
files.add(file);
}
if (filesInViewer != null && filesInViewer.length > 0)
{
addingStructures = true; // already files loaded.
+ String filename = file.getAbsolutePath();
for (int c = 0; c < filesInViewer.length; c++)
{
- if (filesInViewer[c].equals(file))
+ if (filesInViewer[c].equals(filename))
{
file = null;
break;
import jalview.ext.jmol.JalviewJmolBinding;
import jalview.io.DataSourceType;
import jalview.structure.StructureSelectionManager;
+import jalview.util.Platform;
import java.awt.Container;
+import java.io.File;
+import java.util.List;
import java.util.Map;
import org.jmol.api.JmolAppConsoleInterface;
import javajs.util.BS;
+
import org.openscience.jmol.app.jmolpanel.console.AppConsole;
public class AppJmolBinding extends JalviewJmolBinding
return null;
}
+
+ @SuppressWarnings("unused")
+public void cacheFiles(List<File> files) {
+ if (files == null)
+ return;
+ for (File f : files) {
+ String path = f.getAbsolutePath();
+ byte[] data = Platform.getFileBytes(f);
+ if (data != null) {
+ Platform.cacheFileData(path, data);
+ }
+ }
+ }
}