Skip to content

Commit 46ec363

Browse files
committed
bugfixes
1 parent 0a37bea commit 46ec363

24 files changed

+196
-67
lines changed

fonts/Abandoned.italic.ttf

-18.4 KB
Binary file not shown.

fonts/Abandoned.ttf

-19.6 KB
Binary file not shown.

src/main/java/io/github/vincemann/subtitleBuddy/classpathFileFinder/ClassPathFileFinder.java src/main/java/io/github/vincemann/subtitleBuddy/classpathFileFinder/ReadOnlyClassPathFileFinder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* creates a tempfile and copies content from classpath Resource stream into it
88
*
99
*/
10-
public interface ClassPathFileFinder {
10+
public interface ReadOnlyClassPathFileFinder {
1111

1212
/**
1313
*

src/main/java/io/github/vincemann/subtitleBuddy/classpathFileFinder/SpringClassPathFileFinder.java src/main/java/io/github/vincemann/subtitleBuddy/classpathFileFinder/TempFileCreatingReadOnlyClassPathFileFinder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.util.*;
1414

1515
@Singleton
16-
public class SpringClassPathFileFinder implements ClassPathFileFinder {
16+
public class TempFileCreatingReadOnlyClassPathFileFinder implements ReadOnlyClassPathFileFinder {
1717

1818
@Override
1919
public LoadedClassPathFile findFileOnClassPath(String relPath) throws IOException {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.github.vincemann.subtitleBuddy.config.configFileManager;
2+
3+
import java.io.File;
4+
5+
public interface ConfigFileManager {
6+
7+
/**
8+
* Finds the ConfigFile with name {@param fileName}.
9+
* ConfigFile must be writable.
10+
* @return FileObject representing ConfigFile
11+
*/
12+
public File findConfigFile(String fileName) throws ConfigFileManagerException;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.github.vincemann.subtitleBuddy.config.configFileManager;
2+
3+
public class ConfigFileManagerException extends Exception {
4+
5+
public ConfigFileManagerException() {
6+
}
7+
8+
public ConfigFileManagerException(String message) {
9+
super(message);
10+
}
11+
12+
public ConfigFileManagerException(String message, Throwable cause) {
13+
super(message, cause);
14+
}
15+
16+
public ConfigFileManagerException(Throwable cause) {
17+
super(cause);
18+
}
19+
20+
public ConfigFileManagerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
21+
super(message, cause, enableSuppression, writableStackTrace);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package io.github.vincemann.subtitleBuddy.config.configFileManager;
2+
3+
import io.github.vincemann.subtitleBuddy.classpathFileFinder.LoadedClassPathFile;
4+
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ReadOnlyClassPathFileFinder;
5+
import io.github.vincemann.subtitleBuddy.runningExecutableFinder.RunningExecutableFinder;
6+
import io.github.vincemann.subtitleBuddy.runningExecutableFinder.RunningExecutableNotFoundException;
7+
import lombok.extern.log4j.Log4j;
8+
import lombok.extern.slf4j.Slf4j;
9+
10+
import javax.inject.Inject;
11+
import javax.inject.Singleton;
12+
import java.io.File;
13+
import java.io.FileNotFoundException;
14+
import java.io.IOException;
15+
import java.nio.file.Files;
16+
import java.nio.file.Path;
17+
import java.nio.file.Paths;
18+
import java.nio.file.StandardCopyOption;
19+
import java.util.concurrent.atomic.AtomicReference;
20+
21+
/**
22+
* Finds a configFile, with a specified name, inside the jar and extracts it to the folder, in which the jar is located.
23+
* If the configFile, with the specified name, is already in the folder, than this file is taken.
24+
*
25+
* This process ensures, that the file is editable. (And also easily editable by the user)
26+
*/
27+
@Singleton
28+
@Log4j
29+
public class ExtractingConfigFileManager implements ConfigFileManager {
30+
31+
private RunningExecutableFinder runningExecutableFinder;
32+
private ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder;
33+
34+
@Inject
35+
public ExtractingConfigFileManager(RunningExecutableFinder runningExecutableFinder, ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder) {
36+
this.runningExecutableFinder = runningExecutableFinder;
37+
this.readOnlyClassPathFileFinder = readOnlyClassPathFileFinder;
38+
}
39+
40+
@Override
41+
public File findConfigFile(String fileName) throws ConfigFileManagerException{
42+
try {
43+
//is file in folder of jar?
44+
Path runningExecutable = runningExecutableFinder.findRunningExecutable();
45+
Path jarFolder = runningExecutable.getParent();
46+
AtomicReference<Path> foundConfigFileInJarFolder = new AtomicReference<>();
47+
Files.walk(jarFolder, 1).forEach(path -> {
48+
if (path.getFileName().equals(Paths.get(fileName))) {
49+
//we found the configFile
50+
foundConfigFileInJarFolder.set(path);
51+
}
52+
});
53+
if (foundConfigFileInJarFolder.get() != null) {
54+
//we found the configFile
55+
return foundConfigFileInJarFolder.get().toFile();
56+
}
57+
//the config file is not in the folder of the jar
58+
//lets continue searching in the jar
59+
LoadedClassPathFile classPathFile = readOnlyClassPathFileFinder.findFileOnClassPath(fileName);
60+
//copy file from classPath to folder of jar
61+
Path targetPath = jarFolder.resolve(fileName);
62+
Files.copy(Paths.get(classPathFile.getFile().toURI()),targetPath, StandardCopyOption.COPY_ATTRIBUTES);
63+
//assert that copy operation worked
64+
File targetConfigFile = targetPath.toFile();
65+
if(!targetConfigFile.exists()){
66+
throw new FileNotFoundException("Copy Operation failed. Config File not found in jar Directory");
67+
}else {
68+
return targetConfigFile;
69+
}
70+
}catch (RunningExecutableNotFoundException|IOException e) {
71+
throw new ConfigFileManagerException(e);
72+
}
73+
}
74+
}

src/main/java/io/github/vincemann/subtitleBuddy/config/propertiesFile/ApachePropertiesFile.java

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import lombok.extern.log4j.Log4j;
55
import org.apache.commons.configuration.ConfigurationException;
66
import org.apache.commons.configuration.PropertiesConfiguration;
7+
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
78

89
import java.io.File;
910

src/main/java/io/github/vincemann/subtitleBuddy/filechooser/SwingFileChooser.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
import javax.swing.filechooser.FileNameExtensionFilter;
1515
import javax.validation.constraints.NotNull;
1616
import java.io.File;
17+
import java.nio.file.Files;
18+
import java.nio.file.InvalidPathException;
19+
import java.nio.file.Paths;
1720

1821
@Log4j
1922
@Singleton
@@ -36,21 +39,26 @@ private SwingFileChooser(@NotNull @Named(UIStringsFileKeys.SRT_FILE_TYPE_KEY) St
3639
public File letUserChooseFile() throws UserQuitException {
3740
log.debug( "Filechooser swing check ");
3841
JFileChooser chooser = null;
39-
40-
4142
try {
4243
String startingDir = lastPathHandler.getSavedPath();
4344
log.debug( "Saved Path: " + startingDir + " was found, starting from there");
44-
chooser = new JFileChooser(startingDir);
45+
if(Files.exists(Paths.get(startingDir))) {
46+
chooser = new JFileChooser(startingDir);
47+
}else {
48+
log.debug("Saved Path was invalid, starting from root directory");
49+
chooser = new JFileChooser();
50+
}
4551
} catch (PropertyNotFoundException e) {
4652
log.warn( "No saved Path was found, starting at root directory");
4753
chooser = new JFileChooser();
54+
}catch (InvalidPathException e){
55+
log.debug("Saved Path was invalid, starting from root directory");
56+
chooser = new JFileChooser();
4857
}
4958

5059
chooser.setDialogTitle(dialogTitle);
5160

5261

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

src/main/java/io/github/vincemann/subtitleBuddy/gui/stages/stageController/AbstractStageController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ protected void onFXMLInitialize(){}
250250
*/
251251
protected void onStageCreate(Stage stage){ }
252252

253-
protected void onShowStage(){}
253+
protected void onShowStage(){ }
254254

255255
protected Vector2D getSize() {
256256
return size;

src/main/java/io/github/vincemann/subtitleBuddy/gui/stages/stageController/movieStage/MovieStageController.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.google.inject.name.Named;
99
import io.github.vincemann.subtitleBuddy.config.propertiesFile.PropertyFileKeys;
1010
import io.github.vincemann.subtitleBuddy.config.uiStringsFile.UIStringsFileKeys;
11-
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ClassPathFileFinder;
11+
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ReadOnlyClassPathFileFinder;
1212
import io.github.vincemann.subtitleBuddy.events.MovieTextPositionChangedEvent;
1313
import io.github.vincemann.subtitleBuddy.events.SwitchSrtDisplayerEvent;
1414
import io.github.vincemann.subtitleBuddy.gui.srtDisplayer.MovieSrtDisplayer;
@@ -105,16 +105,16 @@ public class MovieStageController extends AbstractStageController implements Mov
105105
public MovieStageController(@Named(UIStringsFileKeys.MOVIE_STAGE_TITLE_KEY) String title,
106106
SrtFontManager srtFontManager, EventBus eventBus,
107107
@Named(PropertyFileKeys.USER_MOVIE_TEXT_POSITION_KEY) String movieVBoxPosString,
108-
ClassPathFileFinder classPathFileFinder,
108+
ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder,
109109
@Named(PropertyFileKeys.CLICK_WARNING_IMAGE_PATH_KEY) String clickWarningImagePath)
110110
throws IOException {
111-
super(classPathFileFinder.findFileOnClassPath(MOVIE_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(), title, getScreenBoundsVector());
111+
super(readOnlyClassPathFileFinder.findFileOnClassPath(MOVIE_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(), title, getScreenBoundsVector());
112112
this.srtFontManager = srtFontManager;
113113
this.eventBus= eventBus;
114114
this.movieVBoxPos = loadMovieVBoxStartPos(movieVBoxPosString,getSize());
115115
this.updateSubtitleExecutionLimiter = new ExecutionLimiter(SUBTITLE_UPDATE_SLEEP_DURATION,this::updateSubtitle);
116116
createStage(this);
117-
this.clickWarning = createImageView(movieVBox, classPathFileFinder.findFileOnClassPath(clickWarningImagePath).getFile(),new Vector2D(MOVIE_CLICK_WARNING_SIZE,MOVIE_CLICK_WARNING_SIZE));
117+
this.clickWarning = createImageView(movieVBox, readOnlyClassPathFileFinder.findFileOnClassPath(clickWarningImagePath).getFile(),new Vector2D(MOVIE_CLICK_WARNING_SIZE,MOVIE_CLICK_WARNING_SIZE));
118118
constructorInit();
119119
}
120120

src/main/java/io/github/vincemann/subtitleBuddy/gui/stages/stageController/optionsStage/OptionsStageController.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.google.inject.name.Named;
99
import io.github.vincemann.subtitleBuddy.config.propertiesFile.PropertyFileKeys;
1010
import io.github.vincemann.subtitleBuddy.config.uiStringsFile.UIStringsFileKeys;
11-
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ClassPathFileFinder;
11+
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ReadOnlyClassPathFileFinder;
1212
import io.github.vincemann.subtitleBuddy.events.SrtFontColorChangeEvent;
1313
import io.github.vincemann.subtitleBuddy.events.SrtFontChangeEvent;
1414
import io.github.vincemann.subtitleBuddy.events.ToggleHotKeyEvent;
@@ -71,7 +71,7 @@ public class OptionsStageController extends AbstractStageController implements O
7171

7272
private SrtFontManager srtFontManager;
7373

74-
private ClassPathFileFinder classPathFileFinder;
74+
private ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder;
7575

7676

7777
private String userFontsPath;
@@ -89,13 +89,13 @@ public OptionsStageController(EventBus eventBus, @Named(PropertyFileKeys.FONTS_P
8989
@Named(PropertyFileKeys.OPTIONS_WINDOW_SIZE_KEY) Vector2D size,
9090
@Named(PropertyFileKeys.NEXT_CLICK_HOT_KEY_TOGGLED_KEY) boolean nextClickCountsToggled,
9191
@Named(PropertyFileKeys.START_STOP_HOT_KEY_TOGGLED_KEY) boolean startStopHotKeyToggled,
92-
ClassPathFileFinder classPathFileFinder,
92+
ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder,
9393
FontsLocationManager fontsLocationManager)
9494
throws IOException {
95-
super(classPathFileFinder.findFileOnClassPath(OPTIONS_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(), title, size);
95+
super(readOnlyClassPathFileFinder.findFileOnClassPath(OPTIONS_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(), title, size);
9696
createStage(this);
9797
this.fontsLocationManager = fontsLocationManager;
98-
this.classPathFileFinder = classPathFileFinder;
98+
this.readOnlyClassPathFileFinder = readOnlyClassPathFileFinder;
9999
this.eventBus = eventBus;
100100
this.srtFontManager = srtFontManager;
101101
//geht nicht anders weil apache constants nur List<Object> getList() supported..

src/main/java/io/github/vincemann/subtitleBuddy/gui/stages/stageController/settingsStage/SettingsStageController.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.google.inject.Inject;
88
import com.google.inject.Singleton;
99
import com.google.inject.name.Named;
10-
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ClassPathFileFinder;
10+
import io.github.vincemann.subtitleBuddy.classpathFileFinder.ReadOnlyClassPathFileFinder;
1111
import io.github.vincemann.subtitleBuddy.config.propertiesFile.PropertyFileKeys;
1212
import io.github.vincemann.subtitleBuddy.config.uiStringsFile.UIStringsFileKeys;
1313
import io.github.vincemann.subtitleBuddy.events.RequestSrtParserUpdateEvent;
@@ -130,7 +130,7 @@ public SettingsStageController(Stage mainStage,
130130
@Named(PropertyFileKeys.SETTINGS_FONT_SIZE_KEY) int settingsFontSize,
131131
@Named(PropertyFileKeys.FAST_FORWARD_DELTA_KEY) int fastForwardDelta,
132132
EventBus eventBus,
133-
ClassPathFileFinder classPathFileFinder,
133+
ReadOnlyClassPathFileFinder readOnlyClassPathFileFinder,
134134
@Named(PropertyFileKeys.CLICK_WARNING_IMAGE_PATH_KEY) String clickWarningImagePath,
135135
@Named(UIStringsFileKeys.START_BUTTON_TEXT_KEY) String startButtonText,
136136
@Named(UIStringsFileKeys.STOP_BUTTON_TEXT_KEY) String stopButtonText,
@@ -140,10 +140,10 @@ public SettingsStageController(Stage mainStage,
140140
@Named(UIStringsFileKeys.TIMESTAMP_JUMP_HINT_TEXT_KEY) String timestampJumpHintTextString
141141
)
142142
throws IOException {
143-
super(classPathFileFinder.findFileOnClassPath(SETTINGS_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(),windowTitle,
143+
super(readOnlyClassPathFileFinder.findFileOnClassPath(SETTINGS_STAGE_FXML_FILE_PATH).getFile().toURI().toURL(),windowTitle,
144144
minSize);
145145
createStage(this,mainStage);
146-
this.settingsClickWarning = createImageView(imageHBox, classPathFileFinder.findFileOnClassPath(clickWarningImagePath).getFile(),new Vector2D(SETTINGS_CLICK_WARNING_SIZE,SETTINGS_CLICK_WARNING_SIZE));
146+
this.settingsClickWarning = createImageView(imageHBox, readOnlyClassPathFileFinder.findFileOnClassPath(clickWarningImagePath).getFile(),new Vector2D(SETTINGS_CLICK_WARNING_SIZE,SETTINGS_CLICK_WARNING_SIZE));
147147
this.settingsFontSize=settingsFontSize;
148148
this.srtParser = srtParser;
149149
this.eventBus=eventBus;
@@ -176,13 +176,12 @@ public Color getFontColor() {
176176
private void constructorInit(){
177177
setUIStrings();
178178
lastTimeStamp = Timestamp.ZERO();
179-
lastSubtitleText = new SubtitleText(Collections.singletonList(Collections.emptyList()));
179+
lastSubtitleText = srtParser.getCurrentSubtitleText();
180180
this.currentFont= srtFontManager.loadDefaultFont(settingsFontSize);
181181
if(timeStampWarningDuration<MIN_TIME_STAMP_WARNING_DURATION){
182182
timeStampWarningDuration=MIN_TIME_STAMP_WARNING_DURATION;
183183
}
184184
this.settingsClickWarning.setVisible(false);
185-
186185
}
187186

188187
private void setUIStrings(){
@@ -377,7 +376,7 @@ private void displayWrongTimeStampWarning(){
377376
@Override
378377
@FXML
379378
public void displaySubtitle(@NonNull SubtitleText subtitleText) {
380-
log.trace("asking javafx to display new subtitle on SettingsStageController : " + subtitleText);
379+
log.trace("asking javafx to display new subtitle in "+this.getClass().getSimpleName()+" : " + subtitleText);
381380
lastSubtitleText =subtitleText;
382381

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

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

417+
@Override
418+
protected void onShowStage() {
419+
super.onShowStage();
420+
}
421+
417422
@Override
418423
protected void onStageClose() {
419424
super.onStageClose();

0 commit comments

Comments
 (0)