Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vincemann committed Jul 31, 2019
1 parent 0a37bea commit 46ec363
Show file tree
Hide file tree
Showing 24 changed files with 196 additions and 67 deletions.
Binary file removed fonts/Abandoned.italic.ttf
Binary file not shown.
Binary file removed fonts/Abandoned.ttf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* creates a tempfile and copies content from classpath Resource stream into it
*
*/
public interface ClassPathFileFinder {
public interface ReadOnlyClassPathFileFinder {

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.*;

@Singleton
public class SpringClassPathFileFinder implements ClassPathFileFinder {
public class TempFileCreatingReadOnlyClassPathFileFinder implements ReadOnlyClassPathFileFinder {

@Override
public LoadedClassPathFile findFileOnClassPath(String relPath) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.vincemann.subtitleBuddy.config.configFileManager;

import java.io.File;

public interface ConfigFileManager {

/**
* Finds the ConfigFile with name {@param fileName}.
* ConfigFile must be writable.
* @return FileObject representing ConfigFile
*/
public File findConfigFile(String fileName) throws ConfigFileManagerException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.vincemann.subtitleBuddy.config.configFileManager;

public class ConfigFileManagerException extends Exception {

public ConfigFileManagerException() {
}

public ConfigFileManagerException(String message) {
super(message);
}

public ConfigFileManagerException(String message, Throwable cause) {
super(message, cause);
}

public ConfigFileManagerException(Throwable cause) {
super(cause);
}

public ConfigFileManagerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package io.github.vincemann.subtitleBuddy.config.configFileManager;

import io.github.vincemann.subtitleBuddy.classpathFileFinder.LoadedClassPathFile;
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ReadOnlyClassPathFileFinder;
import io.github.vincemann.subtitleBuddy.runningExecutableFinder.RunningExecutableFinder;
import io.github.vincemann.subtitleBuddy.runningExecutableFinder.RunningExecutableNotFoundException;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.concurrent.atomic.AtomicReference;

/**
* Finds a configFile, with a specified name, inside the jar and extracts it to the folder, in which the jar is located.
* If the configFile, with the specified name, is already in the folder, than this file is taken.
*
* This process ensures, that the file is editable. (And also easily editable by the user)
*/
@Singleton
@Log4j
public class ExtractingConfigFileManager implements ConfigFileManager {

private RunningExecutableFinder runningExecutableFinder;
private ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder;

@Inject
public ExtractingConfigFileManager(RunningExecutableFinder runningExecutableFinder, ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder) {
this.runningExecutableFinder = runningExecutableFinder;
this.readOnlyClassPathFileFinder = readOnlyClassPathFileFinder;
}

@Override
public File findConfigFile(String fileName) throws ConfigFileManagerException{
try {
//is file in folder of jar?
Path runningExecutable = runningExecutableFinder.findRunningExecutable();
Path jarFolder = runningExecutable.getParent();
AtomicReference<Path> foundConfigFileInJarFolder = new AtomicReference<>();
Files.walk(jarFolder, 1).forEach(path -> {
if (path.getFileName().equals(Paths.get(fileName))) {
//we found the configFile
foundConfigFileInJarFolder.set(path);
}
});
if (foundConfigFileInJarFolder.get() != null) {
//we found the configFile
return foundConfigFileInJarFolder.get().toFile();
}
//the config file is not in the folder of the jar
//lets continue searching in the jar
LoadedClassPathFile classPathFile = readOnlyClassPathFileFinder.findFileOnClassPath(fileName);
//copy file from classPath to folder of jar
Path targetPath = jarFolder.resolve(fileName);
Files.copy(Paths.get(classPathFile.getFile().toURI()),targetPath, StandardCopyOption.COPY_ATTRIBUTES);
//assert that copy operation worked
File targetConfigFile = targetPath.toFile();
if(!targetConfigFile.exists()){
throw new FileNotFoundException("Copy Operation failed. Config File not found in jar Directory");
}else {
return targetConfigFile;
}
}catch (RunningExecutableNotFoundException|IOException e) {
throw new ConfigFileManagerException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.log4j.Log4j;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;

@Log4j
@Singleton
Expand All @@ -36,21 +39,26 @@ private SwingFileChooser(@NotNull @Named(UIStringsFileKeys.SRT_FILE_TYPE_KEY) St
public File letUserChooseFile() throws UserQuitException {
log.debug( "Filechooser swing check ");
JFileChooser chooser = null;


try {
String startingDir = lastPathHandler.getSavedPath();
log.debug( "Saved Path: " + startingDir + " was found, starting from there");
chooser = new JFileChooser(startingDir);
if(Files.exists(Paths.get(startingDir))) {
chooser = new JFileChooser(startingDir);
}else {
log.debug("Saved Path was invalid, starting from root directory");
chooser = new JFileChooser();
}
} catch (PropertyNotFoundException e) {
log.warn( "No saved Path was found, starting at root directory");
chooser = new JFileChooser();
}catch (InvalidPathException e){
log.debug("Saved Path was invalid, starting from root directory");
chooser = new JFileChooser();
}

chooser.setDialogTitle(dialogTitle);


//todo checken ob hier immernoch eine current modification exception fliegt
FileNameExtensionFilter filter = new FileNameExtensionFilter(description, fileTypes);
chooser.setFileFilter(filter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected void onFXMLInitialize(){}
*/
protected void onStageCreate(Stage stage){ }

protected void onShowStage(){}
protected void onShowStage(){ }

protected Vector2D getSize() {
return size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.google.inject.name.Named;
import io.github.vincemann.subtitleBuddy.config.propertiesFile.PropertyFileKeys;
import io.github.vincemann.subtitleBuddy.config.uiStringsFile.UIStringsFileKeys;
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ClassPathFileFinder;
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ReadOnlyClassPathFileFinder;
import io.github.vincemann.subtitleBuddy.events.MovieTextPositionChangedEvent;
import io.github.vincemann.subtitleBuddy.events.SwitchSrtDisplayerEvent;
import io.github.vincemann.subtitleBuddy.gui.srtDisplayer.MovieSrtDisplayer;
Expand Down Expand Up @@ -105,16 +105,16 @@ public class MovieStageController extends AbstractStageController implements Mov
public MovieStageController(@Named(UIStringsFileKeys.MOVIE_STAGE_TITLE_KEY) String title,
SrtFontManager srtFontManager, EventBus eventBus,
@Named(PropertyFileKeys.USER_MOVIE_TEXT_POSITION_KEY) String movieVBoxPosString,
ClassPathFileFinder classPathFileFinder,
ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder,
@Named(PropertyFileKeys.CLICK_WARNING_IMAGE_PATH_KEY) String clickWarningImagePath)
throws IOException {
super(classPathFileFinder.findFileOnClassPath(MOVIE_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(), title, getScreenBoundsVector());
super(readOnlyClassPathFileFinder.findFileOnClassPath(MOVIE_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(), title, getScreenBoundsVector());
this.srtFontManager = srtFontManager;
this.eventBus= eventBus;
this.movieVBoxPos = loadMovieVBoxStartPos(movieVBoxPosString,getSize());
this.updateSubtitleExecutionLimiter = new ExecutionLimiter(SUBTITLE_UPDATE_SLEEP_DURATION,this::updateSubtitle);
createStage(this);
this.clickWarning = createImageView(movieVBox, classPathFileFinder.findFileOnClassPath(clickWarningImagePath).getFile(),new Vector2D(MOVIE_CLICK_WARNING_SIZE,MOVIE_CLICK_WARNING_SIZE));
this.clickWarning = createImageView(movieVBox, readOnlyClassPathFileFinder.findFileOnClassPath(clickWarningImagePath).getFile(),new Vector2D(MOVIE_CLICK_WARNING_SIZE,MOVIE_CLICK_WARNING_SIZE));
constructorInit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.google.inject.name.Named;
import io.github.vincemann.subtitleBuddy.config.propertiesFile.PropertyFileKeys;
import io.github.vincemann.subtitleBuddy.config.uiStringsFile.UIStringsFileKeys;
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ClassPathFileFinder;
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ReadOnlyClassPathFileFinder;
import io.github.vincemann.subtitleBuddy.events.SrtFontColorChangeEvent;
import io.github.vincemann.subtitleBuddy.events.SrtFontChangeEvent;
import io.github.vincemann.subtitleBuddy.events.ToggleHotKeyEvent;
Expand Down Expand Up @@ -71,7 +71,7 @@ public class OptionsStageController extends AbstractStageController implements O

private SrtFontManager srtFontManager;

private ClassPathFileFinder classPathFileFinder;
private ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder;


private String userFontsPath;
Expand All @@ -89,13 +89,13 @@ public OptionsStageController(EventBus eventBus, @Named(PropertyFileKeys.FONTS_P
@Named(PropertyFileKeys.OPTIONS_WINDOW_SIZE_KEY) Vector2D size,
@Named(PropertyFileKeys.NEXT_CLICK_HOT_KEY_TOGGLED_KEY) boolean nextClickCountsToggled,
@Named(PropertyFileKeys.START_STOP_HOT_KEY_TOGGLED_KEY) boolean startStopHotKeyToggled,
ClassPathFileFinder classPathFileFinder,
ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder,
FontsLocationManager fontsLocationManager)
throws IOException {
super(classPathFileFinder.findFileOnClassPath(OPTIONS_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(), title, size);
super(readOnlyClassPathFileFinder.findFileOnClassPath(OPTIONS_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(), title, size);
createStage(this);
this.fontsLocationManager = fontsLocationManager;
this.classPathFileFinder = classPathFileFinder;
this.readOnlyClassPathFileFinder = readOnlyClassPathFileFinder;
this.eventBus = eventBus;
this.srtFontManager = srtFontManager;
//geht nicht anders weil apache constants nur List<Object> getList() supported..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ClassPathFileFinder;
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ReadOnlyClassPathFileFinder;
import io.github.vincemann.subtitleBuddy.config.propertiesFile.PropertyFileKeys;
import io.github.vincemann.subtitleBuddy.config.uiStringsFile.UIStringsFileKeys;
import io.github.vincemann.subtitleBuddy.events.RequestSrtParserUpdateEvent;
Expand Down Expand Up @@ -130,7 +130,7 @@ public SettingsStageController(Stage mainStage,
@Named(PropertyFileKeys.SETTINGS_FONT_SIZE_KEY) int settingsFontSize,
@Named(PropertyFileKeys.FAST_FORWARD_DELTA_KEY) int fastForwardDelta,
EventBus eventBus,
ClassPathFileFinder classPathFileFinder,
ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder,
@Named(PropertyFileKeys.CLICK_WARNING_IMAGE_PATH_KEY) String clickWarningImagePath,
@Named(UIStringsFileKeys.START_BUTTON_TEXT_KEY) String startButtonText,
@Named(UIStringsFileKeys.STOP_BUTTON_TEXT_KEY) String stopButtonText,
Expand All @@ -140,10 +140,10 @@ public SettingsStageController(Stage mainStage,
@Named(UIStringsFileKeys.TIMESTAMP_JUMP_HINT_TEXT_KEY) String timestampJumpHintTextString
)
throws IOException {
super(classPathFileFinder.findFileOnClassPath(SETTINGS_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(),windowTitle,
super(readOnlyClassPathFileFinder.findFileOnClassPath(SETTINGS_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(),windowTitle,
minSize);
createStage(this,mainStage);
this.settingsClickWarning = createImageView(imageHBox, classPathFileFinder.findFileOnClassPath(clickWarningImagePath).getFile(),new Vector2D(SETTINGS_CLICK_WARNING_SIZE,SETTINGS_CLICK_WARNING_SIZE));
this.settingsClickWarning = createImageView(imageHBox, readOnlyClassPathFileFinder.findFileOnClassPath(clickWarningImagePath).getFile(),new Vector2D(SETTINGS_CLICK_WARNING_SIZE,SETTINGS_CLICK_WARNING_SIZE));
this.settingsFontSize=settingsFontSize;
this.srtParser = srtParser;
this.eventBus=eventBus;
Expand Down Expand Up @@ -176,13 +176,12 @@ public Color getFontColor() {
private void constructorInit(){
setUIStrings();
lastTimeStamp = Timestamp.ZERO();
lastSubtitleText = new SubtitleText(Collections.singletonList(Collections.emptyList()));
lastSubtitleText = srtParser.getCurrentSubtitleText();
this.currentFont= srtFontManager.loadDefaultFont(settingsFontSize);
if(timeStampWarningDuration<MIN_TIME_STAMP_WARNING_DURATION){
timeStampWarningDuration=MIN_TIME_STAMP_WARNING_DURATION;
}
this.settingsClickWarning.setVisible(false);

}

private void setUIStrings(){
Expand Down Expand Up @@ -377,7 +376,7 @@ private void displayWrongTimeStampWarning(){
@Override
@FXML
public void displaySubtitle(@NonNull SubtitleText subtitleText) {
log.trace("asking javafx to display new subtitle on SettingsStageController : " + subtitleText);
log.trace("asking javafx to display new subtitle in "+this.getClass().getSimpleName()+" : " + subtitleText);
lastSubtitleText =subtitleText;

Platform.runLater(() -> {
Expand All @@ -396,6 +395,7 @@ public void displaySubtitle(@NonNull SubtitleText subtitleText) {
text.setFill(SettingsSrtDisplayer.DEFAULT_FONT_COLOR);
adjustTextSize(text,settingsFontSize);

log.trace("displaying text: " + text + " in "+this.getClass().getSimpleName());
settingsTextFlow.getChildren().add(text);
settingsTextFlow.getChildren().add(new Text(System.lineSeparator()));
}
Expand All @@ -414,6 +414,11 @@ public void setTime(@NonNull Timestamp time) {
});
}

@Override
protected void onShowStage() {
super.onShowStage();
}

@Override
protected void onStageClose() {
super.onStageClose();
Expand Down
Loading

0 comments on commit 46ec363

Please sign in to comment.