-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting implementation of the
jpro-file
module
- Loading branch information
Showing
12 changed files
with
900 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dependencies { | ||
implementation "com.sandec.jpro:jpro-webapi:$JPRO_VERSION" | ||
implementation "org.jetbrains:annotations:$JETBRAINS_ANNOTATIONS_VERSION" | ||
runtimeOnly "ch.qos.logback:logback-classic:$LOGBACK_VERSION" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Module descriptor for JPro File Manager module. | ||
* | ||
* @author Besmir Beqiri | ||
*/ | ||
module one.jpro.platform.file { | ||
requires javafx.controls; | ||
requires jpro.webapi; | ||
requires org.jetbrains.annotations; | ||
|
||
exports one.jpro.platform.file; | ||
exports one.jpro.platform.file.picker; | ||
} |
80 changes: 80 additions & 0 deletions
80
jpro-file/src/main/java/one/jpro/platform/file/ExtensionFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package one.jpro.platform.file; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Creates an {@code ExtensionFilter} with the specified description | ||
* and the file name extensions. | ||
* <p> | ||
* File name extension should be specified in the {@code *.<extension>} | ||
* format. | ||
* | ||
* @param description the textual description for the filter | ||
* @param extensions a list of the accepted file name extensions | ||
* @author Besmir Beqiri | ||
*/ | ||
public record ExtensionFilter(String description, List<String> extensions) { | ||
|
||
/** | ||
* Compact constructor for {@code ExtensionFilter}. | ||
* | ||
* @throws NullPointerException if the description or the extensions are {@code null} | ||
* @throws IllegalArgumentException if the description or the extensions are empty | ||
*/ | ||
public ExtensionFilter { | ||
validateArgs(description, extensions); | ||
} | ||
|
||
/** | ||
* Creates an {@code ExtensionFilter} with the specified description | ||
* and the file name extensions. | ||
* <p> | ||
* File name extension should be specified in the {@code *.<extension>} | ||
* format. | ||
* | ||
* @param description the textual description for the filter | ||
* @param extensions an array of the accepted file name extensions | ||
* @throws NullPointerException if the description or the extensions are {@code null} | ||
* @throws IllegalArgumentException if the description or the extensions are empty | ||
* @return the created {@code ExtensionFilter} | ||
*/ | ||
public static ExtensionFilter of(String description, String... extensions) { | ||
return new ExtensionFilter(description, List.of(extensions)); | ||
} | ||
|
||
/** | ||
* Validates the arguments. | ||
* | ||
* @param description the textual description for the filter | ||
* @param extensions the accepted file name extensions | ||
* @throws NullPointerException if the description or the extensions are {@code null} | ||
* @throws IllegalArgumentException if the description or the extensions are empty | ||
*/ | ||
private static void validateArgs(final String description, final List<String> extensions) { | ||
if (description == null) { | ||
throw new NullPointerException("Description must not be null"); | ||
} | ||
|
||
if (description.isEmpty()) { | ||
throw new IllegalArgumentException("Description must not be empty"); | ||
} | ||
|
||
if (extensions == null) { | ||
throw new NullPointerException("Extensions must not be null"); | ||
} | ||
|
||
if (extensions.isEmpty()) { | ||
throw new IllegalArgumentException("At least one extension must be defined"); | ||
} | ||
|
||
for (String extension : extensions) { | ||
if (extension == null) { | ||
throw new NullPointerException("Extension must not be null"); | ||
} | ||
|
||
if (extension.isEmpty()) { | ||
throw new IllegalArgumentException("Extension must not be empty"); | ||
} | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
jpro-file/src/main/java/one/jpro/platform/file/FileSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package one.jpro.platform.file; | ||
|
||
import javafx.beans.property.ReadOnlyLongProperty; | ||
import javafx.beans.property.ReadOnlyLongWrapper; | ||
import javafx.beans.property.ReadOnlyStringProperty; | ||
import javafx.beans.property.ReadOnlyStringWrapper; | ||
|
||
/** | ||
* File source. | ||
* | ||
* @author Besmir Beqiri | ||
*/ | ||
public sealed abstract class FileSource<T> permits NativeFileSource, WebFileSource { | ||
|
||
private final T platformBlob; | ||
|
||
public FileSource(T platformBlob) { | ||
this.platformBlob = platformBlob; | ||
} | ||
|
||
public final T getPlatformFile() { | ||
return platformBlob; | ||
} | ||
|
||
abstract String _getName(); | ||
|
||
// name property | ||
private ReadOnlyStringWrapper nameProperty; | ||
|
||
public final String getName() { | ||
return nameProperty == null ? _getName() : nameProperty.get(); | ||
} | ||
|
||
public final ReadOnlyStringProperty nameProperty() { | ||
if (nameProperty == null) { | ||
nameProperty = new ReadOnlyStringWrapper(this, "name", _getName()); | ||
} | ||
return nameProperty.getReadOnlyProperty(); | ||
} | ||
|
||
abstract long _getSize(); | ||
|
||
// size property | ||
private ReadOnlyLongWrapper sizeProperty; | ||
|
||
public final long getSize() { | ||
return sizeProperty == null ? _getSize() : sizeProperty.get(); | ||
} | ||
|
||
public final ReadOnlyLongProperty sizeProperty() { | ||
if (sizeProperty == null) { | ||
sizeProperty = new ReadOnlyLongWrapper(this, "size", _getSize()); | ||
} | ||
return sizeProperty.getReadOnlyProperty(); | ||
} | ||
|
||
abstract String _getObjectURL(); | ||
|
||
// objectURL property | ||
private ReadOnlyStringWrapper objectURLProperty; | ||
|
||
public final String getObjectURL() { | ||
return objectURLProperty == null ? _getObjectURL() : objectURLProperty.get(); | ||
} | ||
|
||
public final ReadOnlyStringProperty objectURLProperty() { | ||
if (objectURLProperty == null) { | ||
objectURLProperty = new ReadOnlyStringWrapper(this, "objectURL", _getObjectURL()); | ||
} | ||
return objectURLProperty.getReadOnlyProperty(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
jpro-file/src/main/java/one/jpro/platform/file/NativeFileSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package one.jpro.platform.file; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Java file source. | ||
* | ||
* @author Besmir Beqiri | ||
*/ | ||
public final class NativeFileSource extends FileSource<File> { | ||
|
||
public NativeFileSource(final File file) { | ||
super(file); | ||
} | ||
|
||
@Override | ||
String _getName() { | ||
return getPlatformFile().getName(); | ||
} | ||
|
||
@Override | ||
long _getSize() { | ||
return getPlatformFile().length(); | ||
} | ||
|
||
@Override | ||
String _getObjectURL() { | ||
return getPlatformFile().toURI().toString(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
jpro-file/src/main/java/one/jpro/platform/file/WebFileSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package one.jpro.platform.file; | ||
|
||
import com.jpro.webapi.WebAPI; | ||
|
||
/** | ||
* Web file source. | ||
* | ||
* @author Besmir Beqiri | ||
*/ | ||
public final class WebFileSource extends FileSource<WebAPI.JSFile> { | ||
|
||
public WebFileSource(WebAPI.JSFile jsFile) { | ||
super(jsFile); | ||
} | ||
|
||
@Override | ||
String _getName() { | ||
return getPlatformFile().getFilename(); | ||
} | ||
|
||
@Override | ||
long _getSize() { | ||
return getPlatformFile().getFileSize(); | ||
} | ||
|
||
@Override | ||
String _getObjectURL() { | ||
return getPlatformFile().getObjectURL().getName(); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.