X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=13b715e9e788a69390194f09522d0c972e6612d3;hb=b057323bd16f49b2636eaf33d7c400ea11409f40;hp=1bd15410041b0757edbe841a0291726760f5963d;hpb=414c54986eb248b78432dc7b99956c6a2f20f018;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 1bd1541..13b715e 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4386,7 +4386,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // Java's Transferable for native dnd evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = evt.getTransferable(); - List files = new ArrayList<>(); + final AlignFrame thisaf = this; + final List files = new ArrayList<>(); List protocols = new ArrayList<>(); try @@ -4398,133 +4399,144 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (files != null) { - try + new Thread(new Runnable() { - // check to see if any of these files have names matching sequences in - // the alignment - SequenceIdMatcher idm = new SequenceIdMatcher( - viewport.getAlignment().getSequencesArray()); - /** - * Object[] { String,SequenceI} - */ - ArrayList filesmatched = new ArrayList<>(); - ArrayList filesnotmatched = new ArrayList<>(); - for (int i = 0; i < files.size(); i++) + @Override + public void run() { - String file = files.get(i).toString(); - String pdbfn = ""; - DataSourceType protocol = FormatAdapter.checkProtocol(file); - if (protocol == DataSourceType.FILE) - { - File fl = new File(file); - pdbfn = fl.getName(); - } - else if (protocol == DataSourceType.URL) - { - URL url = new URL(file); - pdbfn = url.getFile(); - } - if (pdbfn.length() > 0) + try { - // attempt to find a match in the alignment - SequenceI[] mtch = idm.findAllIdMatches(pdbfn); - int l = 0, c = pdbfn.indexOf("."); - while (mtch == null && c != -1) + // check to see if any of these files have names matching sequences + // in + // the alignment + SequenceIdMatcher idm = new SequenceIdMatcher( + viewport.getAlignment().getSequencesArray()); + /** + * Object[] { String,SequenceI} + */ + ArrayList filesmatched = new ArrayList<>(); + ArrayList filesnotmatched = new ArrayList<>(); + for (int i = 0; i < files.size(); i++) { - do + String file = files.get(i).toString(); + String pdbfn = ""; + DataSourceType protocol = FormatAdapter.checkProtocol(file); + if (protocol == DataSourceType.FILE) { - l = c; - } while ((c = pdbfn.indexOf(".", l)) > l); - if (l > -1) - { - pdbfn = pdbfn.substring(0, l); + File fl = new File(file); + pdbfn = fl.getName(); } - mtch = idm.findAllIdMatches(pdbfn); - } - if (mtch != null) - { - FileFormatI type = null; - try + else if (protocol == DataSourceType.URL) { - type = new IdentifyFile().identify(file, protocol); - } catch (Exception ex) - { - type = null; + URL url = new URL(file); + pdbfn = url.getFile(); } - if (type != null && type.isStructureFile()) + if (pdbfn.length() > 0) { - filesmatched.add(new Object[] { file, protocol, mtch }); - continue; + // 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) + { + FileFormatI type = null; + try + { + type = new IdentifyFile().identify(file, protocol); + } catch (Exception ex) + { + type = null; + } + if (type != null && type.isStructureFile()) + { + 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); } } - // 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) - || JvOptionPane.showConfirmDialog(this, - MessageManager.formatMessage( - "label.automatically_associate_structure_files_with_sequences_same_name", - new Object[] - { Integer.valueOf(filesmatched.size()) - .toString() }), - MessageManager.getString( - "label.automatically_associate_structure_files_by_name"), - JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION) - - { - for (Object[] fm : filesmatched) + int assocfiles = 0; + if (filesmatched.size() > 0) { - // 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]) + if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false) + || JvOptionPane.showConfirmDialog(thisaf, + MessageManager.formatMessage( + "label.automatically_associate_structure_files_with_sequences_same_name", + new Object[] + { Integer.valueOf(filesmatched.size()) + .toString() }), + MessageManager.getString( + "label.automatically_associate_structure_files_by_name"), + JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION) + { - PDBEntry pe = new AssociatePdbFileWithSeq() - .associatePdbWithSeq((String) fm[0], - (DataSourceType) fm[1], toassoc, false, - Desktop.instance); - if (pe != null) + for (Object[] fm : filesmatched) { - System.err.println("Associated file : " + ((String) fm[0]) - + " with " + toassoc.getDisplayId(true)); - assocfiles++; + // 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], + (DataSourceType) fm[1], toassoc, false, + Desktop.instance); + if (pe != null) + { + System.err.println("Associated file : " + + ((String) fm[0]) + " with " + + toassoc.getDisplayId(true)); + assocfiles++; + } + } + alignPanel.paintAlignment(true); } } - alignPanel.paintAlignment(true); } - } - } - if (filesnotmatched.size() > 0) - { - if (assocfiles > 0 && (Cache.getDefault( - "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) - || JvOptionPane.showConfirmDialog(this, - "" + MessageManager.formatMessage( - "label.ignore_unmatched_dropped_files_info", - new Object[] - { Integer.valueOf(filesnotmatched.size()) - .toString() }) - + "", - MessageManager.getString( - "label.ignore_unmatched_dropped_files"), - JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION)) - { - return; - } - for (String fn : filesnotmatched) + if (filesnotmatched.size() > 0) + { + if (assocfiles > 0 && (Cache.getDefault( + "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) + || JvOptionPane.showConfirmDialog(thisaf, + "" + MessageManager.formatMessage( + "label.ignore_unmatched_dropped_files_info", + new Object[] + { Integer.valueOf( + filesnotmatched.size()) + .toString() }) + + "", + MessageManager.getString( + "label.ignore_unmatched_dropped_files"), + JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION)) + { + return; + } + for (String fn : filesnotmatched) + { + loadJalviewDataFile(fn, null, null, null); + } + + } + } catch (Exception ex) { - loadJalviewDataFile(fn, null, null, null); + ex.printStackTrace(); } - } - } catch (Exception ex) - { - ex.printStackTrace(); - } + }).start(); } }