Skip to content

Commit

Permalink
Merge pull request #7 from JordanMartinez/treeItemGeneral
Browse files Browse the repository at this point in the history
Generalize the content of TreeItems from Path to arbitrary T, given functions T -> Path and Path -> T.
  • Loading branch information
TomasMikula committed Mar 13, 2016
2 parents 97f0608 + 8e0f6f0 commit 7e1d22c
Show file tree
Hide file tree
Showing 23 changed files with 650 additions and 212 deletions.
111 changes: 11 additions & 100 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,107 +1,18 @@
version = '1.0.0-SNAPSHOT'
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'signing'
version = '1.0.0-SNAPSHOT'

repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

group = 'org.fxmisc.livedirs'

dependencies {
compile group: 'org.reactfx', name: 'reactfx', version: '2.0-M4u1'
}

javadoc {
// ignore missing Javadoc comments or tags
options.addStringOption('Xdoclint:all,-missing', '-quiet')
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}

artifacts {
archives jar

archives javadocJar
archives sourcesJar
}

signing {
sign configurations.archives
}

signArchives.onlyIf {
project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')
}

def doUploadArchives = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')

if(doUploadArchives) {
uploadArchives {
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}

snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots') {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}

pom.project {
name 'LiveDirsFX'
packaging 'jar'
description 'Directory tree model for JavaFX that watches the filesystem for changes.'
url 'http://www.fxmisc.org/livedirs/'

scm {
url 'scm:git@github.com:TomasMikula/LiveDirsFX.git'
connection 'scm:git@github.com:TomasMikula/LiveDirsFX.git'
developerConnection 'scm:git@github.com:TomasMikula/LiveDirsFX.git'
}

licenses {
license {
name 'The BSD 2-Clause License'
url 'http://opensource.org/licenses/BSD-2-Clause'
distribution 'repo'
}
}

developers {
developer {
name 'Tomas Mikula'
}
}
}
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
}

uploadArchives.onlyIf { doUploadArchives }
sourceCompatibility = '1.8'
targetCompatibility = '1.8'

task fatJar(type: Jar, dependsOn: classes) {
appendix = 'fat'
from sourceSets.main.output
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
compileJava.options.deprecation = true
}

assemble.dependsOn fatJar
27 changes: 27 additions & 0 deletions livedirsfx-demo/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
group 'org.fxmisc.livedirs'

dependencies {
compile project(":livedirsfx")
compile group: 'org.reactfx', name: 'reactfx', version: '2.0-M4u1'
}

task fatJar(type: Jar, dependsOn: classes) {
appendix = 'fat'
from sourceSets.main.output
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
}

assemble.dependsOn fatJar

task CheckBoxLiveDirs(type: JavaExec, dependsOn: classes) {
main = 'org.fxmisc.livedirs.demo.CheckBoxLiveDirs'
classpath = files(sourceSets.main.output, configurations.runtime)
description = 'Demonstrates a working LiveDirs instance that displays its items as though' +
'they are CheckBoxTreeItems'
}

task NormalLiveDirs(type: JavaExec, dependsOn: classes) {
main = 'org.fxmisc.livedirs.demo.NormalLiveDirs'
classpath = files(sourceSets.main.output, configurations.runtime)
description = 'Demonstrates a working LiveDirs instance that displays its items normally'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Created 2016 by Jordan Martinez
*
* The author dedicates this to the public domain
*/

package org.fxmisc.livedirs.demo;


public enum ChangeSource {
INTERNAL,
EXTERNAL
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Created 2016 by Jordan Martinez
*
* The author dedicates this to the public domain
*/

package org.fxmisc.livedirs.demo;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.TreeView;
import javafx.stage.Stage;
import org.fxmisc.livedirs.LiveDirs;
import org.fxmisc.livedirs.demo.checkbox.CheckBoxContentImpl;
import org.fxmisc.livedirs.demo.checkbox.TreeCellFactories;

import java.io.IOException;
import java.nio.file.Paths;

public class CheckBoxLiveDirs extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) {
TreeView<CheckBoxContentImpl> view = new TreeView<>();
view.setShowRoot(false);
view.setCellFactory(TreeCellFactories.checkBoxFactory());

try {
// create a LiveDirs instance for use on the JavaFX Application Thread
// and make it display its items as though they were CheckBoxTreeItems
LiveDirs<ChangeSource, CheckBoxContentImpl> dirs = new LiveDirs<>(ChangeSource.EXTERNAL,
CheckBoxContentImpl::getPath, CheckBoxContentImpl::new, Platform::runLater);

// set directory to watch
dirs.addTopLevelDirectory(Paths.get(System.getProperty("user.home"), "Documents").toAbsolutePath());
view.setRoot(dirs.model().getRoot());

// stop DirWatcher's thread
primaryStage.setOnCloseRequest(val -> dirs.dispose());
} catch (IOException e) {
e.printStackTrace();
}

primaryStage.setScene(new Scene(view, 500, 500));
primaryStage.show();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Created 2016 by Jordan Martinez
*
* The author dedicates this to the public domain
*/

package org.fxmisc.livedirs.demo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TreeView;
import javafx.stage.Stage;
import org.fxmisc.livedirs.LiveDirs;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class NormalLiveDirs extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) {
TreeView<Path> view = new TreeView<>();
view.setShowRoot(false);

try {
// create a LiveDirs instance for use on the JavaFX Application Thread
LiveDirs<ChangeSource, Path> dirs = LiveDirs.getInstance(ChangeSource.EXTERNAL);

// set directory to watch
dirs.addTopLevelDirectory(Paths.get(System.getProperty("user.home"), "Documents").toAbsolutePath());
view.setRoot(dirs.model().getRoot());

// stop DirWatcher's thread
primaryStage.setOnCloseRequest(val -> dirs.dispose());
} catch (IOException e) {
e.printStackTrace();
}

primaryStage.setScene(new Scene(view, 500, 500));
primaryStage.show();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Created 2016 by Jordan Martinez
*
* The author dedicates this to the public domain
*/

package org.fxmisc.livedirs.demo.checkbox;

import org.reactfx.value.Var;

import java.nio.file.Path;

public interface CheckBoxContent {

/** The State of the {@link javafx.scene.control.CheckBox} */
enum State {
UNCHECKED,
UNDEFINED,
CHECKED
}

State getState();
void setState(State value);
Var<State> stateProperty();

Path getPath();
void setPath(Path p);

void lock();
void unlock();
boolean isLocked();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Created 2016 by Jordan Martinez
*
* The author dedicates this to the public domain
*/

package org.fxmisc.livedirs.demo.checkbox;

import org.reactfx.value.Var;

import java.nio.file.Path;

/**
* A basic implementation of {@link CheckBoxContent}
*/
public class CheckBoxContentImpl implements CheckBoxContent {

private final Var<State> state = Var.newSimpleVar(State.UNCHECKED);
public final State getState() { return state.getValue(); }
public final void setState(State value) { state.setValue(value); }
public final Var<State> stateProperty() { return state; }

private Path path;
public final Path getPath() { return path; }
public final void setPath(Path p) { path = p; }

private boolean locked = false;
public final boolean isLocked() { return locked; }
public final void lock() { locked = true; }
public final void unlock() { locked = false; }

public CheckBoxContentImpl(Path p) {
path = p;
}
}

0 comments on commit 7e1d22c

Please sign in to comment.