pixivj-jfx

Supporting library for Pixivj using JavaFX.

License

License

GroupId

GroupId

com.github.hanshsieh
ArtifactId

ArtifactId

pixivjjfx
Last Version

Last Version

0.1.4-beta
Release Date

Release Date

Type

Type

jar
Description

Description

pixivj-jfx
Supporting library for Pixivj using JavaFX.
Project URL

Project URL

https://github.com/hanshsieh/pixivj-jfx
Source Code Management

Source Code Management

http://github.com/hanshsieh/pixivj-jfx

Download pixivjjfx

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.hanshsieh/pixivjjfx/ -->
<dependency>
    <groupId>com.github.hanshsieh</groupId>
    <artifactId>pixivjjfx</artifactId>
    <version>0.1.4-beta</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.hanshsieh/pixivjjfx/
implementation 'com.github.hanshsieh:pixivjjfx:0.1.4-beta'
// https://jarcasting.com/artifacts/com.github.hanshsieh/pixivjjfx/
implementation ("com.github.hanshsieh:pixivjjfx:0.1.4-beta")
'com.github.hanshsieh:pixivjjfx:jar:0.1.4-beta'
<dependency org="com.github.hanshsieh" name="pixivjjfx" rev="0.1.4-beta">
  <artifact name="pixivjjfx" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.hanshsieh', module='pixivjjfx', version='0.1.4-beta')
)
libraryDependencies += "com.github.hanshsieh" % "pixivjjfx" % "0.1.4-beta"
[com.github.hanshsieh/pixivjjfx "0.1.4-beta"]

Dependencies

compile (7)

Group / Artifact Type Version
org.openjfx : javafx-controls jar 15.0.1
org.openjfx : javafx-web jar 15.0.1
com.github.hanshsieh : pixivj jar 1.1.1-beta-SNAPSHOT
org.checkerframework : checker-qual jar 3.10.0
org.slf4j : slf4j-api jar 1.7.30
com.widen : urlbuilder jar 2.1.1
org.apache.commons : commons-lang3 jar 3.11

Project Modules

There are no modules declared in this project.

Pixivj-jfx

Supporting library for Pixivj using JavaFX.
Java CI
Maven Central

Usage

Dependency

Because of a dependency it uses, please add the following settings to your pom.xml (For Maven).

<project>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>bintray</name>
      <url>https://jcenter.bintray.com</url>
    </repository>
  </repositories>
</project>

Then, add this library to the dependencies of your project.
Check out here for the available versions.

Getting access-token using web view login

Here, we show an example for getting an access token by showing a web view with JavaFX.

import com.github.hanshsieh.pixivj.oauth.PixivOAuthClient;
import com.github.hanshsieh.pixivj.token.ThreadedTokenRefresher;
import com.github.hanshsieh.pixivj.token.TokenRefresher;
import com.github.hanshsieh.pixivjjfx.stage.PixivLoginStage;
import java.io.Closeable;
import javafx.application.Application;
import javafx.stage.Stage;
public class Test extends Application {
  @Override
  public void start(Stage primaryStage) {
    // Simulate a worker thread
    new Thread(() -> {
      PixivOAuthClient authClient = null;
      TokenRefresher tokenRefresher = null;
      PixivLoginStage loginStage;
      try {
        authClient = new PixivOAuthClient.Builder().build();
        tokenRefresher = new ThreadedTokenRefresher.Builder()
            .setAuthClient(authClient)
            .build();
        loginStage = new PixivLoginStage.Builder().buildInFxThread();
        WebViewTokenProvider tokenProvider = new WebViewTokenProvider.Builder()
            .setAuthClient(authClient)
            .setTokenRefresher(tokenRefresher)
            .setLoginStage(loginStage)
            .build();
        String accessToken = tokenProvider.getAccessToken();
        System.out.printf("Access token: %s", accessToken);
      } catch (Exception ex) {
        ex.printStackTrace();
      } finally {
        closeQuietly(authClient);
        closeQuietly(tokenRefresher);
      }
    }).start();
  }

  private static void closeQuietly(Closeable closeable) {
    if (closeable == null) {
      return;
    }
    try {
      closeable.close();
    } catch (Exception ex) {
      // Do nothing
    }
  }

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

Notice that when using JavaFX, you need to define an Application instance. The Application instance defines the entrypoint of a JavaFX application.
In the example, we use a separate thread to instantiate the PixivOAuthClient instance to simulate the case that you want to use the client in a worker thread (instead of JavaFX application thread).
It uses PixivLoginStage.Builder#buildInFxThread() to instantiate the PixivLoginStage. It's because PixivLoginStage is a JavaFX stage, and a JavaFX stage can only be instantiated and accessed in a JavaFX application thread. PixivLoginStage.Builder#buildInFxThread() helps you create the stage in the JavaFX application thread, and passed the object reference to the calling thread.

Contribution

Style

Please follow the Google coding style.
You may apply the IntelliJ style file here.

Release

Follow the guide at here to setup your PGP key and settings.xml.
Update the version in pom.xml appropriately.
Then, run

mvn -Duser.name="$(git config --get user.name)" clean deploy -P release

Versions

Version
0.1.4-beta
0.1.2-beta
0.1.1-beta