Last active
September 19, 2018 00:57
-
-
Save koifish082/0a5f1524ec2167d42cac4c0e442143af to your computer and use it in GitHub Desktop.
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
buildscript { | |
dependencies { | |
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2' | |
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4' | |
} | |
repositories { | |
jcenter() | |
mavenLocal() | |
mavenCentral() | |
} | |
} | |
plugins { | |
id 'java' | |
} | |
version '1.0-SNAPSHOT' | |
apply plugin: 'java' | |
apply plugin: 'application' | |
apply plugin: 'com.github.johnrengelman.shadow' | |
apply plugin: 'javafx-gradle-plugin' | |
mainClassName = 'presentation.MainApp' | |
sourceCompatibility = 1.8 | |
repositories { | |
mavenLocal() | |
mavenCentral() | |
} | |
dependencies { | |
testCompile group: 'junit', name: 'junit', version: '4.12' | |
// Camera lib | |
compile 'com.github.sarxos:webcam-capture:0.3.12' | |
compile 'org.slf4j:slf4j-log4j12:1.7.21' | |
// RxJavaFX | |
implementation "io.reactivex.rxjava2:rxjava:2.2.2" | |
// Retrofit | |
implementation 'com.squareup.retrofit2:retrofit:2.4.0' | |
implementation 'com.squareup.retrofit2:converter-gson:2.4.0' | |
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' | |
// Batik (for loading AVG) | |
compile group: 'org.apache.xmlgraphics', name: 'batik-transcoder', version: '1.10' | |
} | |
jfx { | |
mainClass = 'MainApp' | |
vendor = 'myVendor' | |
} | |
jar { | |
manifest { | |
attributes 'Main-Class': 'presentation.MainApp' | |
} | |
from { | |
configurations.compile.collect { | |
it.isDirectory() ? it : zipTree(it) | |
} | |
} | |
} | |
sourceSets { | |
main { | |
java { | |
srcDirs 'src/main/java' | |
} | |
resources { | |
srcDirs 'src/main/resources' | |
} | |
} | |
} |
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
package presentation.utils; | |
import javafx.embed.swing.SwingFXUtils; | |
import javafx.scene.image.ImageView; | |
import javafx.scene.image.WritableImage; | |
import org.apache.batik.transcoder.TranscoderException; | |
import org.apache.batik.transcoder.TranscoderInput; | |
import org.apache.batik.transcoder.image.PNGTranscoder; | |
import java.awt.image.BufferedImage; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.net.URL; | |
public class ImageUtil { | |
public static void loadSvgImage(ImageView target, String resourcePath, int withd, int height) { | |
SvgTranscoder imageTranscoder = new SvgTranscoder(); | |
imageTranscoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) withd); | |
imageTranscoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) height); | |
try { | |
URL imagePath = ImageUtil.class.getResource(resourcePath); | |
TranscoderInput input = new TranscoderInput(new FileReader(imagePath.getFile())); | |
imageTranscoder.transcode(input, null); | |
} catch (FileNotFoundException | TranscoderException e) { | |
e.printStackTrace(); | |
} | |
BufferedImage bimage = imageTranscoder.getImage(); | |
WritableImage wimage = SwingFXUtils.toFXImage(bimage, null); | |
target.setImage(wimage); | |
} | |
} |
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
package presentation; | |
import javafx.application.Application; | |
import javafx.stage.Stage; | |
import presentation.navigator.MenuNavigator; | |
public class MainApp extends Application { | |
public static Stage primaryStage; | |
private MenuNavigator navigator; | |
public MainApp() { | |
navigator = new MenuNavigator(); | |
} | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
MainApp.primaryStage = primaryStage; | |
navigator.launchMenuStage(primaryStage); | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
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
package presentation.utils; | |
import org.apache.batik.transcoder.TranscoderOutput; | |
import org.apache.batik.transcoder.image.ImageTranscoder; | |
import java.awt.image.BufferedImage; | |
public class SvgTranscoder extends ImageTranscoder { | |
private BufferedImage image = null; | |
@Override | |
public BufferedImage createImage(int w, int h) { | |
image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); | |
return image; | |
} | |
@Override | |
public void writeImage(BufferedImage img, TranscoderOutput out) { | |
} | |
public BufferedImage getImage() { | |
return image; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment