1 33 34 package edu.rice.cs.drjava.model; 35 36 import java.util.HashMap ; 37 import java.io.File ; 38 import java.io.IOException ; 39 import javax.swing.text.BadLocationException ; 40 41 import edu.rice.cs.util.UnexpectedException; 42 import edu.rice.cs.drjava.model.definitions.DefinitionsDocument; 43 44 45 public class TestDocGetter extends DummyGlobalModel { 46 47 48 HashMap <File , OpenDefinitionsDocument> docs; 49 50 51 public TestDocGetter() { this(new File [0], new String [0]); } 52 53 57 public TestDocGetter(File [] files, String [] texts) { 58 if (files.length != texts.length) { 59 throw new IllegalArgumentException ("Argument arrays must match in size."); 60 } 61 62 docs = new HashMap <File , OpenDefinitionsDocument>(texts.length * 2); 63 64 GlobalEventNotifier en = new GlobalEventNotifier(); 65 for (int i = 0; i < texts.length; i++) { 66 DefinitionsDocument doc = new DefinitionsDocument(en); 67 OpenDefinitionsDocument odoc = new TestOpenDoc(doc); 68 odoc.setFile(files[i]); 69 try { doc.insertString(0, texts[i], null); } 70 catch (BadLocationException e) { throw new UnexpectedException(e); } 71 docs.put(files[i], odoc); 72 } 73 } 74 75 public OpenDefinitionsDocument getDocumentForFile(File file) 76 throws IOException { 77 if (docs.containsKey(file)) return docs.get(file); 79 else throw new IllegalStateException ("TestDocGetter can't open new files!"); 80 } 81 82 83 private static class TestOpenDoc extends DummyOpenDefDoc { 84 DefinitionsDocument _doc; 85 File _file; 86 TestOpenDoc(DefinitionsDocument d) { 87 _doc = d; 88 _defDoc = d; 89 _file = null; 90 } 91 92 93 protected DefinitionsDocument getDocument() { return _doc; } 94 95 96 public File getFile() throws FileMovedException { return _file; } 97 98 public void setFile(File f) { _file = f; } 99 } 100 } 101 | Popular Tags |