X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;fp=src%2Fjalview%2Fgui%2FDesktop.java;h=2e8644e8c958ef803c836e024a568af971fd5c70;hp=28606f105e4b7f332244979075aa893357be4b32;hb=7d67fb613ec026dc9a265e351e7fab542e3f1d61;hpb=3e29fb36af9c48e07837e32b7e99c081b2461b2f diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 28606f1..2e8644e 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -27,8 +27,11 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.bin.Jalview; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatException; +import jalview.io.FileFormatI; import jalview.io.FileLoader; -import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; @@ -461,11 +464,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements public void run() { Cache.log.debug("Filechooser init thread started."); - new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS, - jalview.io.AppletFormatAdapter.READABLE_FNAMES, - jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT")); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"), + // jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS, + // jalview.io.AppletFormatAdapter.READABLE_FNAMES, + fileFormat, true); Cache.log.debug("Filechooser init thread finished."); } }).start(); @@ -685,10 +688,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements String file = (String) contents .getTransferData(DataFlavor.stringFlavor); - String format = new IdentifyFile().identify(file, - FormatAdapter.PASTE); + FileFormatI format = new IdentifyFile().identify(file, + DataSourceType.PASTE); - new FileLoader().LoadFile(file, FormatAdapter.PASTE, format); + new FileLoader().LoadFile(file, DataSourceType.PASTE, format); } } catch (Exception ex) @@ -954,8 +957,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements // Java's Transferable for native dnd evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = evt.getTransferable(); - java.util.List files = new ArrayList(); - java.util.List protocols = new ArrayList(); + List files = new ArrayList(); + List protocols = new ArrayList(); try { @@ -973,13 +976,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements for (int i = 0; i < files.size(); i++) { String file = files.get(i).toString(); - String protocol = (protocols == null) ? FormatAdapter.FILE - : (String) protocols.get(i); - String format = null; + DataSourceType protocol = (protocols == null) ? DataSourceType.FILE + : protocols.get(i); + FileFormatI format = null; if (file.endsWith(".jar")) { - format = "Jalview"; + format = FileFormat.Jalview; } else @@ -1008,11 +1011,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements @Override public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport) { - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS, - jalview.io.AppletFormatAdapter.READABLE_FNAMES, - jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT")); + String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT"); + JalviewFileChooser chooser = JalviewFileChooser.forRead( + Cache.getProperty("LAST_DIRECTORY"), + // AppletFormatAdapter.READABLE_EXTENSIONS, + // AppletFormatAdapter.READABLE_FNAMES, + fileFormat, true); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager @@ -1024,28 +1028,34 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (value == JalviewFileChooser.APPROVE_OPTION) { String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser + Cache.setProperty("LAST_DIRECTORY", chooser .getSelectedFile().getParent()); - String format = null; - if (chooser.getSelectedFormat() != null - && chooser.getSelectedFormat().equals("Jalview")) + FileFormatI format = null; + FileFormatI selectedFormat = chooser.getSelectedFormat(); + if (FileFormat.Jalview.equals(selectedFormat)) { - format = "Jalview"; + format = FileFormat.Jalview; } else { - format = new IdentifyFile().identify(choice, FormatAdapter.FILE); + try + { + format = new IdentifyFile().identify(choice, DataSourceType.FILE); + } catch (FileFormatException e) + { + // format is null + } } if (viewport != null) { - new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, + new FileLoader().LoadFile(viewport, choice, DataSourceType.FILE, format); } else { - new FileLoader().LoadFile(choice, FormatAdapter.FILE, format); + new FileLoader().LoadFile(choice, DataSourceType.FILE, format); } } } @@ -1101,19 +1111,28 @@ public class Desktop extends jalview.jbgui.GDesktop implements { if (viewport != null) { - new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, - "Jalview"); + new FileLoader().LoadFile(viewport, url, DataSourceType.URL, + FileFormat.Jalview); } else { - new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview"); + new FileLoader().LoadFile(url, DataSourceType.URL, + FileFormat.Jalview); } } else { - String format = new IdentifyFile().identify(url, FormatAdapter.URL); + FileFormatI format = null; + try + { + format = new IdentifyFile().identify(url, DataSourceType.URL); + } catch (FileFormatException e) + { + // TODO revise error handling, distinguish between + // URL not found and response not valid + } - if (format.equals("URL NOT FOUND")) + if (format == null) { JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager.formatMessage("label.couldnt_locate", @@ -1126,11 +1145,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (viewport != null) { - new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format); + new FileLoader() + .LoadFile(viewport, url, DataSourceType.URL, format); } else { - new FileLoader().LoadFile(url, FormatAdapter.URL, format); + new FileLoader().LoadFile(url, DataSourceType.URL, format); } } } @@ -1516,8 +1536,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements public void saveState_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), - new String[] { "jvp" }, new String[] { "Jalview Project" }, + Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project", "Jalview Project"); chooser.setFileView(new JalviewFileView()); @@ -1588,7 +1607,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements public void loadState_actionPerformed(ActionEvent e) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] { + Cache.getProperty("LAST_DIRECTORY"), new String[] { "jvp", "jar" }, new String[] { "Jalview Project", "Jalview Project (old)" }, "Jalview Project"); chooser.setFileView(new JalviewFileView()); @@ -1601,7 +1620,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements final File selectedFile = chooser.getSelectedFile(); setProjectFile(selectedFile); final String choice = selectedFile.getAbsolutePath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", + Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent()); new Thread(new Runnable() { @@ -2172,9 +2191,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (v_client != null) { JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] - { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ - new String[] { "Vamsas Document" }, "Vamsas Document"); + Cache.getProperty("LAST_DIRECTORY"), "vdj",// TODO: VAMSAS DOCUMENT EXTENSION is VDJ + "Vamsas Document", "Vamsas Document"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager @@ -2188,7 +2206,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements JPanel progpanel = addProgressPanel(MessageManager.formatMessage( "label.saving_vamsas_doc", new Object[] { choice.getName() })); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent()); + Cache.setProperty("LAST_DIRECTORY", choice.getParent()); String warnmsg = null; String warnttl = null; try @@ -2230,7 +2248,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ public void setVamsasUpdate(boolean b) { - jalview.bin.Cache.log.debug("Setting gui for Vamsas update " + Cache.log.debug("Setting gui for Vamsas update " + (b ? "in progress" : "finished")); if (vamUpdate != null) @@ -3260,7 +3278,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements } public static void transferFromDropTarget(List files, - List protocols, DropTargetDropEvent evt, Transferable t) + List protocols, DropTargetDropEvent evt, + Transferable t) throws Exception { @@ -3274,7 +3293,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements .getTransferData(DataFlavor.javaFileListFlavor)) { files.add(((File) file).toString()); - protocols.add(FormatAdapter.FILE); + protocols.add(DataSourceType.FILE); } } else @@ -3304,7 +3323,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { Cache.log.debug("Adding missing FILE protocol for " + files.get(protocols.size())); - protocols.add(FormatAdapter.FILE); + protocols.add(DataSourceType.FILE); } for (java.util.StringTokenizer st = new java.util.StringTokenizer( data, "\r\n"); st.hasMoreTokens();) @@ -3319,14 +3338,14 @@ public class Desktop extends jalview.jbgui.GDesktop implements java.net.URI uri = new java.net.URI(s); if (uri.getScheme().toLowerCase().startsWith("http")) { - protocols.add(FormatAdapter.URL); + protocols.add(DataSourceType.URL); files.add(uri.toString()); } else { // otherwise preserve old behaviour: catch all for file objects java.io.File file = new java.io.File(uri); - protocols.add(FormatAdapter.FILE); + protocols.add(DataSourceType.FILE); files.add(file.toString()); } }