1 package fr.orsay.lri.varna.applications.newGUI;
3 import java.awt.datatransfer.DataFlavor;
4 import java.awt.datatransfer.Transferable;
5 import java.awt.datatransfer.UnsupportedFlavorException;
7 import java.io.FileFilter;
8 import java.io.FileNotFoundException;
9 import java.io.FilenameFilter;
10 import java.io.IOException;
11 import java.util.Collection;
12 import java.util.Date;
13 import java.util.regex.Pattern;
15 import fr.orsay.lri.varna.exceptions.ExceptionExportFailed;
16 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
17 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
18 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
19 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
20 import fr.orsay.lri.varna.factories.RNAFactory;
21 import fr.orsay.lri.varna.models.rna.RNA;
23 public class VARNAGUIModel implements Comparable<VARNAGUIModel> {
24 private Date _lastModified;
25 private boolean _outOfSync = false;
26 private RNA _r = null;
27 private String _caption = "";
28 private String _path = "";
29 private String _folder = "";
32 public static Date lastModif(String path)
34 return new Date(new File(path).lastModified()) ;
37 public VARNAGUIModel(String folder, String path)
39 this(folder,path,lastModif(path));
42 public VARNAGUIModel(String folder, String path,Date lastModified)
44 _lastModified = lastModified;
48 String[] s = path.split(Pattern.quote(File.separator));
50 _caption = s[s.length-1];
53 public boolean hasChanged()
58 public boolean checkForModifications()
60 if (!lastModif(_path).equals(_lastModified) && !_outOfSync)
75 } catch (ExceptionUnmatchedClosingParentheses e) {
76 // TODO Auto-generated catch block
78 } catch (ExceptionFileFormatOrSyntax e) {
79 // TODO Auto-generated catch block
81 } catch (FileNotFoundException e) {
82 // TODO Auto-generated catch block
84 } catch (ExceptionExportFailed e) {
85 // TODO Auto-generated catch block
87 } catch (ExceptionPermissionDenied e) {
88 // TODO Auto-generated catch block
90 } catch (ExceptionLoadingFailed e) {
91 // TODO Auto-generated catch block
98 private RNA createRNA() throws ExceptionUnmatchedClosingParentheses, ExceptionFileFormatOrSyntax, FileNotFoundException, ExceptionExportFailed, ExceptionPermissionDenied, ExceptionLoadingFailed
100 Collection<RNA> r = RNAFactory.loadSecStr(_path);
103 _r = r.iterator().next();
108 throw new ExceptionFileFormatOrSyntax("No valid RNA defined in this file.");
113 public String toString()
115 return _caption + (this._outOfSync?"*":"");
118 public String getID()
120 return getRNA().getID();
123 public String getCaption()
128 public String getFolder()
133 public static DataFlavor Flavor = new DataFlavor(VARNAGUIModel.class, "VARNA Object");
136 public int compareTo(VARNAGUIModel o) {
137 return _caption.compareTo(o._caption);