+ String file = files.get(i).toString();
+ String pdbfn = "";
+ String protocol = FormatAdapter.checkProtocol(file);
+ if (protocol == jalview.io.FormatAdapter.FILE)
+ {
+ File fl = new File(file);
+ pdbfn = fl.getName();
+ }
+ else if (protocol == jalview.io.FormatAdapter.URL)
+ {
+ URL url = new URL(file);
+ pdbfn = url.getFile();
+ }
+ if (pdbfn.length() > 0)
+ {
+ // attempt to find a match in the alignment
+ SequenceI[] mtch = idm.findAllIdMatches(pdbfn);
+ int l = 0, c = pdbfn.indexOf(".");
+ while (mtch == null && c != -1)
+ {
+ do
+ {
+ l = c;
+ } while ((c = pdbfn.indexOf(".", l)) > l);
+ if (l > -1)
+ {
+ pdbfn = pdbfn.substring(0, l);
+ }
+ mtch = idm.findAllIdMatches(pdbfn);
+ }
+ if (mtch != null)
+ {
+ String type = null;
+ try
+ {
+ type = new IdentifyFile().Identify(file, protocol);
+ } catch (Exception ex)
+ {
+ type = null;
+ }
+ if (type != null)
+ {
+ if (type.equalsIgnoreCase("PDB"))
+ {
+ filesmatched.add(new Object[]
+ { file, protocol, mtch });
+ continue;
+ }
+ }
+ }
+ // File wasn't named like one of the sequences or wasn't a PDB file.
+ filesnotmatched.add(file);
+ }
+ }
+ int assocfiles = 0;
+ if (filesmatched.size() > 0)
+ {
+ if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false)
+ || JOptionPane
+ .showConfirmDialog(
+ this,
+ "Do you want to automatically associate the "
+ + filesmatched.size()
+ + " PDB files with sequences in the alignment that have the same name ?",
+ "Automatically Associate PDB files by name",
+ JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
+
+ {
+ for (Object[] fm : filesmatched)
+ {
+ // try and associate
+ // TODO: may want to set a standard ID naming formalism for
+ // associating PDB files which have no IDs.
+ for (SequenceI toassoc: (SequenceI[])fm[2]) {
+ PDBEntry pe = new AssociatePdbFileWithSeq()
+ .associatePdbWithSeq((String) fm[0], (String) fm[1],
+ toassoc, false);
+ if (pe != null)
+ {
+ System.err
+ .println("Associated file : " + ((String) fm[0])
+ + " with "
+ + toassoc.getDisplayId(true));
+ assocfiles++;
+ }
+ }
+ alignPanel.paintAlignment(true);
+ }
+ }
+ }
+ if (filesnotmatched.size() > 0)
+ {
+ if (assocfiles > 0
+ && (Cache.getDefault(
+ "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JOptionPane
+ .showConfirmDialog(
+ this,
+ "<html>Do you want to <em>ignore</em> the "
+ + filesnotmatched.size()
+ + " files whose names did not match any sequence IDs ?</html>",
+ "Ignore unmatched dropped files ?",
+ JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION))
+ {
+ return;
+ }
+ for (String fn : filesnotmatched)
+ {
+ loadJalviewDataFile(fn, null, null, null);
+ }
+