1 45 46 package edu.rice.cs.util.swing; 47 48 import java.io.File ; 49 50 54 public class FileDisplay { 55 56 private File _file; 57 private String _rep; 58 private boolean _repIsDifferent; private boolean _isNew; 60 61 protected FileDisplayManager _fdm; 62 63 FileDisplay(File f, FileDisplayManager fdm) { 64 this(fdm); 65 _file = f; 66 _rep = formatRep(f); 67 } 68 69 FileDisplay(File parent, String child, FileDisplayManager fdm) { 70 this(fdm); 71 if (child == null || child.equals("")) { 72 _file = new File (parent, "."); 73 } 74 else { 75 _file = new File (parent, child); 76 } 77 _rep = formatRep(_file); 78 } 79 80 private FileDisplay(FileDisplayManager fdm) { 81 _fdm = fdm; 82 } 83 84 public static FileDisplay newFile(File parent, FileDisplayManager fdm) { 85 FileDisplay fd = new FileDisplay(parent, "", fdm); 86 fd._isNew = true; 87 fd._rep = getDefaultNewFileRep(); 88 return fd; 89 } 90 91 public File getParentFile() { return _file.getParentFile(); } 92 93 public File getFile() { return _file; } 94 95 103 public boolean isEditable() { return (_isNew || (_file.canWrite() && _rep.equals(_file.getName()))); } 104 105 public boolean isNew() { return _isNew; } 106 107 public String getRepresentation() { return _rep; } 108 109 public final String toString() { return _rep; } 110 111 protected String formatRep(File file) { 112 return _fdm.getName(file); 113 } 114 115 protected static String getDefaultNewFileRep() { 116 return "New Folder"; 117 } 118 119 120 } | Popular Tags |