Lines 25-30
Link Here
|
25 |
import java.io.IOException; |
25 |
import java.io.IOException; |
26 |
import java.io.OutputStream; |
26 |
import java.io.OutputStream; |
27 |
import java.lang.reflect.Method; |
27 |
import java.lang.reflect.Method; |
|
|
28 |
import java.nio.charset.Charset; |
28 |
import java.util.Collections; |
29 |
import java.util.Collections; |
29 |
import java.util.HashSet; |
30 |
import java.util.HashSet; |
30 |
import java.util.Set; |
31 |
import java.util.Set; |
Lines 38-43
Link Here
|
38 |
|
39 |
|
39 |
import org.netbeans.junit.NbTestCase; |
40 |
import org.netbeans.junit.NbTestCase; |
40 |
import org.netbeans.junit.NbTestSuite; |
41 |
import org.netbeans.junit.NbTestSuite; |
|
|
42 |
import org.netbeans.spi.queries.FileEncodingQueryImplementation; |
41 |
import org.openide.actions.*; |
43 |
import org.openide.actions.*; |
42 |
import org.openide.cookies.CloseCookie; |
44 |
import org.openide.cookies.CloseCookie; |
43 |
import org.openide.cookies.EditCookie; |
45 |
import org.openide.cookies.EditCookie; |
Lines 228-233
Link Here
|
228 |
env.fileLock.releaseLock(); |
230 |
env.fileLock.releaseLock(); |
229 |
} |
231 |
} |
230 |
|
232 |
|
|
|
233 |
public void testFileEncodingQuery () throws Exception { |
234 |
DES des = support(); |
235 |
FileEncodingQueryImpl.getDefault().reset(); |
236 |
StyledDocument doc = des.openDocument(); |
237 |
assertEquals(des.getDataObject().getPrimaryFile(),FileEncodingQueryImpl.getDefault().getFile()); |
238 |
FileEncodingQueryImpl.getDefault().reset(); |
239 |
doc.insertString(doc.getLength(), " Added text.", null); |
240 |
des.saveDocument(); |
241 |
assertEquals(des.getDataObject().getPrimaryFile(),FileEncodingQueryImpl.getDefault().getFile()); |
242 |
} |
243 |
|
231 |
/** File object that let us know what is happening and delegates to certain |
244 |
/** File object that let us know what is happening and delegates to certain |
232 |
* instance variables of the test. |
245 |
* instance variables of the test. |
233 |
*/ |
246 |
*/ |
Lines 392-397
Link Here
|
392 |
} |
405 |
} |
393 |
|
406 |
|
394 |
} |
407 |
} |
|
|
408 |
|
409 |
private static final class FileEncodingQueryImpl extends FileEncodingQueryImplementation { |
410 |
|
411 |
private static FileEncodingQueryImpl instance; |
412 |
|
413 |
private FileObject file; |
414 |
|
415 |
private FileEncodingQueryImpl () { |
416 |
|
417 |
} |
418 |
|
419 |
public Charset getEncoding(FileObject file) { |
420 |
this.file = file; |
421 |
return Charset.defaultCharset(); |
422 |
} |
423 |
|
424 |
public void reset () { |
425 |
this.file = null; |
426 |
} |
427 |
|
428 |
public FileObject getFile () { |
429 |
return this.file; |
430 |
} |
431 |
|
432 |
public synchronized static FileEncodingQueryImpl getDefault () { |
433 |
if (instance == null) { |
434 |
instance = new FileEncodingQueryImpl (); |
435 |
} |
436 |
return instance; |
437 |
} |
438 |
} |
395 |
|
439 |
|
396 |
public static final class Lkp extends org.openide.util.lookup.AbstractLookup { |
440 |
public static final class Lkp extends org.openide.util.lookup.AbstractLookup { |
397 |
public Lkp () { |
441 |
public Lkp () { |
Lines 402-407
Link Here
|
402 |
super (ic); |
446 |
super (ic); |
403 |
|
447 |
|
404 |
ic.add (new Pool ()); |
448 |
ic.add (new Pool ()); |
|
|
449 |
ic.add (FileEncodingQueryImpl.getDefault()); |
405 |
} |
450 |
} |
406 |
|
451 |
|
407 |
} // end of Lkp |
452 |
} // end of Lkp |