(String sourceFilename, Texture texture)
| 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 | }); |
no test coverage detected