Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TomasMikula/LiveDirsFX
Directory tree model for JavaFX that watches the filesystem for changes.
https://github.com/TomasMikula/LiveDirsFX
Last synced: 25 days ago
JSON representation
Directory tree model for JavaFX that watches the filesystem for changes.
- Host: GitHub
- URL: https://github.com/TomasMikula/LiveDirsFX
- Owner: TomasMikula
- License: bsd-2-clause
- Created: 2014-04-06T14:06:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-09-21T22:47:59.000Z (about 4 years ago)
- Last Synced: 2024-05-02T05:24:20.796Z (7 months ago)
- Language: Java
- Size: 91.8 KB
- Stars: 47
- Watchers: 10
- Forks: 9
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- AwesomeJavaFX - LiveDirsFX - Directory tree model for JavaFX that watches the filesystem for changes. (Libraries, Tools and Projects)
README
LiveDirsFX
==========LiveDirsFX is a combination of a directory watcher, a directory-tree model (for [TreeView](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TreeView.html)) and a simple asynchronous file I/O facility. The extra benefits of this combination are:
1. Automatic synchronization of the directory model with the filesystem.
2. Ability to distinguish directory and file modifications made by the application (through the I/O facility) from external modifications.Example
-------```java
enum ChangeSource {
INTERNAL, // indicates a change made by this application
EXTERNAL, // indicates an external change
}// create LiveDirs to watch a directory
LiveDirs liveDirs = new LiveDirs<>(EXTERNAL);
Path dir = Paths.get("/path/to/watched/directory/");
liveDirs.addTopLevelDirectory(dir);// use LiveDirs as a TreeView model
TreeView treeView = new TreeView<>(liveDirs.model().getRoot());
treeView.setShowRoot(false);// handle external changes
liveDirs.model().modifications().subscribe(m -> {
if(m.getInitiator() == EXTERNAL) {
// handle external modification, e.g. reload the modified file
reload(m.getPath());
} else {
// modification done by this application, no extra action needed
}
});// Use LiveDirs's I/O facility to write to the filesystem,
// in order to be able to distinguish between internal and external changes.
Path file = dir.resolve("some/file.txt");
liveDirs.io().saveUTF8File(file, "Hello text file!", INTERNAL);// clean up
liveDirs.dispose();
```Use LiveDirsFX in your project
------------------------------### Method 1: as a managed dependency (recommended)
Snapshot releases are deployed to Sonatype snapshot repository with these Maven coordinates
| Group ID | Artifact ID | Version |
| :-----------------: | :---------: | :------------: |
| org.fxmisc.livedirs | livedirsfx | 1.0.0-SNAPSHOT |#### Gradle example
```groovy
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}dependencies {
compile group: 'org.fxmisc.livedirs', name: 'livedirsfx', version: '1.0.0-SNAPSHOT'
}
```#### Sbt example
```scala
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"libraryDependencies += "org.fxmisc.livedirs" % "livedirsfx" % "1.0.0-SNAPSHOT"
```### Method 2: as an unmanaged dependency
Download the latest [JAR](https://oss.sonatype.org/content/repositories/snapshots/org/fxmisc/livedirs/livedirsfx/1.0.0-SNAPSHOT/) or [fat JAR (including dependencies)](https://googledrive.com/host/0B4a5AnNnZhkbMzRneXVNUEI3anc/downloads/) and place it on your classpath.
Links
-----[Javadoc](http://www.fxmisc.org/livedirs/javadoc/org/fxmisc/livedirs/package-summary.html)