-
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.
Merge pull request #5 from CherryPill/A-a-c_#2
A a c #2
- Loading branch information
Showing
13 changed files
with
516 additions
and
105 deletions.
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
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 |
---|---|---|
@@ -1,42 +1,58 @@ | ||
package application.io; | ||
|
||
import application.converter.Converter; | ||
import application.ui.WindowFactory; | ||
import application.utility.MessageWrapper; | ||
import application.utility.Utility; | ||
import javafx.beans.binding.Bindings; | ||
import javafx.scene.control.Alert; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.ProgressBar; | ||
import javafx.scene.paint.Color; | ||
import javafx.stage.Modality; | ||
import javafx.stage.Stage; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class ConversionService { | ||
|
||
private WindowFactory windowFactory = new WindowFactory(); | ||
|
||
public void convertFiles(List<File> inputFiles, | ||
File o, | ||
File outputDir, | ||
int blocks, | ||
Converter.UI_OUTFILE_CONVERSION_TYPE conversion, | ||
Converter.UI_OUTFILE_CONVERSION_TYPE conversionType, | ||
Color b, | ||
Color f) throws IOException { | ||
String outFileName; | ||
Converter.CONV_TYPE type = null; | ||
for (File i : inputFiles) { | ||
if (conversion == Converter.UI_OUTFILE_CONVERSION_TYPE.IMG) { | ||
outFileName = Utility.omitExtension(i.getName()) + "_" + UUID.randomUUID() + "." + Utility.inferExtension(i.getName()); | ||
if (Utility.inferExtension(i.getName()).equals("gif")) { | ||
type = Converter.CONV_TYPE.IMG_GIF; | ||
} else { | ||
type = Converter.CONV_TYPE.IMG_OTHER; | ||
} | ||
} else { | ||
outFileName = Utility.omitExtension(i.getName()) + "_" + UUID.randomUUID() + ".txt"; | ||
type = Converter.CONV_TYPE.TXT; | ||
} | ||
Converter c = new Converter(i, | ||
blocks, | ||
type, | ||
Utility.getAwtColorFromFXColor(b), | ||
Utility.getAwtColorFromFXColor(f)); | ||
c.setOutFile(outFileName); | ||
c.convert(o); | ||
} | ||
Stage progressBarWindow = windowFactory.createWindowFromFXML( | ||
Modality.APPLICATION_MODAL); | ||
progressBarWindow.show(); | ||
Converter conversionTask = new Converter( | ||
inputFiles, | ||
outputDir, | ||
conversionType, | ||
blocks, | ||
Utility.getAwtColorFromFXColor(b), | ||
Utility.getAwtColorFromFXColor(f), | ||
progressBarWindow | ||
); | ||
|
||
ProgressBar pbNode = (ProgressBar) progressBarWindow.getScene().lookup("#perFrameProgressBar"); | ||
pbNode.progressProperty().bind(conversionTask.progressProperty()); | ||
Label individualProgressBarLabel = (Label) progressBarWindow.getScene().lookup("#individualProgressLabel"); | ||
individualProgressBarLabel.textProperty().bind( | ||
Bindings.createStringBinding( | ||
() -> conversionTask.getMessage(), | ||
conversionTask.messageProperty() | ||
) | ||
); | ||
conversionTask.setOnSucceeded(event -> { | ||
progressBarWindow.close(); | ||
MessageWrapper.showMessage("Finished converting", | ||
Alert.AlertType.INFORMATION); | ||
}); | ||
new Thread(conversionTask).start(); | ||
} | ||
} |
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
Oops, something went wrong.