Skip to content

Commit

Permalink
Attempt to fix jar resource issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinWoodring committed Feb 6, 2022
1 parent 6602cb9 commit 69d002e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'

// This dependency is used by the application.
implementation 'commons-io:commons-io:2.11.0'
implementation 'com.google.guava:guava:30.1.1-jre'

}
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/booglejr/dfaify/DFAify.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.booglejr.dfaify;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;

import javax.xml.parsers.ParserConfigurationException;

import com.booglejr.dfaify.controllers.AppController;
import com.booglejr.dfaify.models.AppModel;
import com.booglejr.dfaify.models.dfa.DFA;
import com.booglejr.dfaify.views.AppView;

import org.apache.commons.io.IOUtils;
import org.xml.sax.SAXException;

import javafx.application.Application;
Expand All @@ -31,9 +35,17 @@ public void start(Stage stage) throws ParserConfigurationException, SAXException
hostServices = getHostServices();

stage.setTitle("DFAify");
stage.getIcons().add(new Image(this.getClass().getResource("/com/booglejr/dfaify/dfaify.png").toString()));

AppModel appModel = new AppModel(new File(this.getClass().getResource("/com/booglejr/dfaify/examples/one-bit-adder.xml").toURI()));
InputStream is = DFAify.class.getResourceAsStream("/com/booglejr/dfaify/dfaify.png");
final File tempFile = File.createTempFile("tempImage", ".png");
tempFile.deleteOnExit();
try (FileOutputStream out = new FileOutputStream(tempFile)) {
IOUtils.copy(is, out);
}

stage.getIcons().add(new Image(tempFile.toString()));

AppModel appModel = new AppModel(DFAify.class.getResourceAsStream("/com/booglejr/dfaify/examples/one-bit-adder.xml"));
AppController appController = new AppController(appModel, stage);
AppView appView = new AppView(appModel, appController);

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/booglejr/dfaify/models/AppModel.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
package com.booglejr.dfaify.models;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.ParserConfigurationException;

import com.booglejr.dfaify.models.dfa.DFA;
import com.booglejr.dfaify.models.dfa.DFAReader;
import com.booglejr.dfaify.models.dfa.error.TooManyConnectionsTakingSameCharError;

import org.apache.commons.io.IOUtils;
import org.xml.sax.SAXException;

public class AppModel {
public DFA dfa;
public String log;

public AppModel(File file){
loadNewDFA(file);
public AppModel(InputStream is) throws FileNotFoundException, IOException{
final File tempFile = File.createTempFile("temp", ".xml");
tempFile.deleteOnExit();
try (FileOutputStream out = new FileOutputStream(tempFile)) {
IOUtils.copy(is, out);
}
loadNewDFA(tempFile);
log = new String();
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
requires javafx.controls;
requires javafx.web;
requires jdk.jsobject;
requires org.apache.commons.io;

exports com.booglejr.dfaify;
}

0 comments on commit 69d002e

Please sign in to comment.