Skip to content

Commit

Permalink
Improve Java2D graphical effects.
Browse files Browse the repository at this point in the history
  • Loading branch information
colorizenl committed Feb 18, 2024
1 parent 22624cf commit d4d9e52
Show file tree
Hide file tree
Showing 96 changed files with 672 additions and 963 deletions.
11 changes: 4 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "io.freefair.lombok" version "8.4"
id "com.github.ben-manes.versions" version "0.50.0"
id "com.github.ben-manes.versions" version "0.51.0"
}

apply plugin: "java-library"
Expand All @@ -9,7 +9,7 @@ apply plugin: "maven-publish"
apply plugin: "signing"

group = "nl.colorize"
version = "2024.1"
version = "2024.2"
compileJava.options.encoding = "UTF-8"

java {
Expand All @@ -18,6 +18,8 @@ java {
sourceSets.main.java.srcDirs = ["source"]
sourceSets.main.resources.srcDirs = ["resources"]
sourceSets.test.java.srcDirs = ["test"]
withJavadocJar()
withSourcesJar()
}

repositories {
Expand All @@ -30,11 +32,6 @@ dependencies {
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
}

java {
withJavadocJar()
withSourcesJar()
}

test {
useJUnitPlatform()
}
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ to the dependencies section in `pom.xml`:
<dependency>
<groupId>nl.colorize</groupId>
<artifactId>colorize-java-commons</artifactId>
<version>2024.1</version>
<version>2024.2</version>
</dependency>

The library can also be used in Gradle projects:

dependencies {
implementation "nl.colorize:colorize-java-commons:2024.1"
implementation "nl.colorize:colorize-java-commons:2024.2"
}

Documentation
Expand Down Expand Up @@ -121,7 +121,7 @@ The following Gradle build tasks are available:
License
-------

Copyright 2007-2023 Colorize
Copyright 2007-2024 Colorize

> Licensed under the Apache License, Version 2.0 (the "License");
> you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/CSVRecord.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
17 changes: 16 additions & 1 deletion source/nl/colorize/util/CompactFormatter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand All @@ -23,12 +23,27 @@
*/
public class CompactFormatter extends Formatter {

private boolean includeClassName;

public CompactFormatter(boolean includeClassName) {
this.includeClassName = includeClassName;
}

public CompactFormatter() {
this(false);
}

@Override
public String format(LogRecord record) {
StringBuilder log = new StringBuilder();
log.append(format(record.getMillis()));
log.append(" ");
log.append(Strings.padEnd(record.getLevel().toString(), 9, ' '));
if (includeClassName) {
log.append(record.getSourceClassName());
log.append(System.lineSeparator());
log.append(Strings.repeat(" ", 30));
}
log.append(record.getMessage());
log.append(System.lineSeparator());
if (record.getThrown() != null) {
Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/DateParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/FileUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/LoadUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
10 changes: 6 additions & 4 deletions source/nl/colorize/util/LogHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -205,9 +205,11 @@ public static String getStackTrace(Throwable e) {
}

StringWriter buffer = new StringWriter();
PrintWriter writer = new PrintWriter(buffer);
e.printStackTrace(writer);
writer.close();

try (PrintWriter writer = new PrintWriter(buffer)) {
e.printStackTrace(writer);
}

return buffer.toString();
}

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/Platform.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/PropertyDeserializer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/ReflectionUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/Resource.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/ResourceException.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
36 changes: 35 additions & 1 deletion source/nl/colorize/util/ResourceFile.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand All @@ -14,6 +14,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;

/**
Expand Down Expand Up @@ -61,6 +64,37 @@ public String getName() {
}
return path.substring(index + 1);
}

/**
* Returns a URI that describes the location of this resource file. For
* resource files in the local file system, this returns a {@code file://}
* URI. For classpath resources in JAR files, this returns a {@code jar:}
* URI.
*
* @throws ResourceException if this resource file cannot be located.
*/
public URI toURI() {
// Attempt 1: Locate file in classpath.
ClassLoader classLoader = ResourceFile.class.getClassLoader();
URL inClassPath = classLoader.getResource(path);

if (inClassPath != null) {
try {
return inClassPath.toURI();
} catch (URISyntaxException e) {
throw new ResourceException("Invalid classpath resource URL: " + inClassPath);
}
}

// Attempt 2: Locate file in local file system.
File inFileSystem = new File(path);

if (inFileSystem.exists() && !inFileSystem.isDirectory()) {
return inFileSystem.toURI();
}

throw new ResourceException("Resource file not found: " + path);
}

@Override
public InputStream openStream() {
Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/Stopwatch.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
57 changes: 56 additions & 1 deletion source/nl/colorize/util/Subscribable.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

package nl.colorize.util;

import com.google.common.base.Preconditions;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
Expand All @@ -14,6 +16,7 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -121,6 +124,58 @@ public void next(Callable<T> operation) {
}
}

/**
* Attempts to perform an operation for the specified number of attempts,
* automatically retrying the operation if the initial attempt(s) failed.
* Note {@code attempts} includes the original attempt, so the number of
* retries is basically {@code attempts - 1}.
* <p>
* If the operation is not successful, an error is sent to subscribers
* based on the last failed attempt.
*/
public void retry(Callable<T> operation, int attempts) {
retry(operation, attempts, 0L);
}

/**
* Attempts to perform an operation for the specified number of attempts,
* automatically retrying the operation if the initial attempt(s) failed.
* The specified time delay (in milliseconds) is applied in between
* attempts. Note {@code attempts} includes the original attempt, so the
* number of retries is basically {@code attempts - 1}.
* <p>
* If the operation is not successful, an error is sent to subscribers
* based on the last failed attempt.
*/
public void retry(Callable<T> operation, int attempts, long delay) {
Preconditions.checkArgument(attempts >= 1, "Invalid number of attempts: " + attempts);
Preconditions.checkArgument(delay >= 0L, "Invalid delay: " + delay);

Exception thrown = null;

for (int i = 0; i < attempts; i++) {
try {
T event = operation.call();
next(event);
return;
} catch (Exception e) {
thrown = e;
LOGGER.log(Level.WARNING, "Operation failed, retrying");
}

if (delay > 0L) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
LOGGER.warning("Retry delay interrupted");
}
}
}

LOGGER.warning("Operation failed after " + attempts + " attempts");
nextError(thrown);
}

/**
* Registers the specified callback functions as event and error
* subscribers. The subscribers will immediately be notified of previously
Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/TextUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/TranslationBundle.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/Version.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/animation/Animatable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/animation/Interpolation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/animation/KeyFrame.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/util/animation/Timeline.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Colorize Java Commons
// Copyright 2007-2023 Colorize
// Copyright 2007-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit d4d9e52

Please sign in to comment.