MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / installReloadWatch

Method installReloadWatch

src/main/java/field/graphics/Texture.java:69–103  ·  view source on GitHub ↗
(String sourceFilename, Texture texture)

Source from the content-addressed store, hash-verified

67 this.specification = specification;
68 if (this.specification.forceSingleBuffered) setIsDoubleBuffered(false);
69
70 if (specification.source != null) {
71 installReloadWatch(specification.source, this);
72 }
73 }
74
75 private void installReloadWatch(String sourceFilename, Texture texture) {
76
77 if (ws == null) {
78 ws = new FileAlterationMonitor(2000);
79 try {
80 ws.start();
81 } catch (Exception e) {
82 e.printStackTrace();
83 }
84 }
85
86
87 synchronized (ws) {
88
89 String name = new File(sourceFilename).getName();
90
91 FileAlterationObserver o = new FileAlterationObserver(new File(sourceFilename).getParentFile(),
92 new NameFileFilter(name));
93 try {
94 o.initialize();
95 } catch (Exception e) {
96 e.printStackTrace();
97 }
98 o.addListener(new FileAlterationListenerAdaptor() {
99 @Override
100 public void onFileChange(File file) {
101 if (file.getName().equals(name)) {
102 System.out.println(" automatic reload for texture :" + file);
103 texture.reloadFrom(file.getAbsolutePath());
104 }
105 }
106 });

Callers 1

TextureMethod · 0.95

Calls 3

startMethod · 0.45
getNameMethod · 0.45
initializeMethod · 0.45

Tested by

no test coverage detected