forked from j62/ctbrec
1
0
Fork 0

Code cleanup

This commit is contained in:
0xboobface 2019-12-30 18:35:27 +01:00
parent 52bc8a6b64
commit b1e312aaac
1 changed files with 25 additions and 27 deletions

View File

@ -52,7 +52,6 @@ import javafx.application.Application;
import javafx.application.HostServices; import javafx.application.HostServices;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Tab; import javafx.scene.control.Tab;
@ -65,7 +64,7 @@ import okhttp3.Response;
public class CamrecApplication extends Application { public class CamrecApplication extends Application {
static final transient Logger LOG = LoggerFactory.getLogger(CamrecApplication.class); static final Logger LOG = LoggerFactory.getLogger(CamrecApplication.class);
private Config config; private Config config;
private Recorder recorder; private Recorder recorder;
@ -158,7 +157,7 @@ public class CamrecApplication extends Application {
rootPane.getTabs().add(new HelpTab()); rootPane.getTabs().add(new HelpTab());
switchToStartTab(); switchToStartTab();
writeColorSchemeStyleSheet(primaryStage); writeColorSchemeStyleSheet();
Color base = Color.web(Config.getInstance().getSettings().colorBase); Color base = Color.web(Config.getInstance().getSettings().colorBase);
if(!base.equals(Color.WHITE)) { if(!base.equals(Color.WHITE)) {
loadStyleSheet(primaryStage, "color.css"); loadStyleSheet(primaryStage, "color.css");
@ -180,7 +179,7 @@ public class CamrecApplication extends Application {
primaryStage.xProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowX = newVal.intValue()); primaryStage.xProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowX = newVal.intValue());
primaryStage.yProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowY = newVal.intValue()); primaryStage.yProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowY = newVal.intValue());
primaryStage.show(); primaryStage.show();
primaryStage.setOnCloseRequest((e) -> { primaryStage.setOnCloseRequest(e -> {
e.consume(); e.consume();
Alert shutdownInfo = new AutosizeAlert(Alert.AlertType.INFORMATION, primaryStage.getScene()); Alert shutdownInfo = new AutosizeAlert(Alert.AlertType.INFORMATION, primaryStage.getScene());
shutdownInfo.setTitle("Shutdown"); shutdownInfo.setTitle("Shutdown");
@ -222,21 +221,19 @@ public class CamrecApplication extends Application {
try { try {
ExternalBrowser.getInstance().close(); ExternalBrowser.getInstance().close();
} catch (IOException e) { } catch (IOException e) {
// noop
} }
} }
}.start(); }.start();
}); });
// register changelistener to activate / deactivate tabs, when the user switches between them // register changelistener to activate / deactivate tabs, when the user switches between them
rootPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() { rootPane.getSelectionModel().selectedItemProperty().addListener((ChangeListener<Tab>) (ov, from, to) -> {
@Override if (from instanceof TabSelectionListener) {
public void changed(ObservableValue<? extends Tab> ov, Tab from, Tab to) { ((TabSelectionListener) from).deselected();
if (from != null && from instanceof TabSelectionListener) { }
((TabSelectionListener) from).deselected(); if (to instanceof TabSelectionListener) {
} ((TabSelectionListener) to).selected();
if (to != null && to instanceof TabSelectionListener) {
((TabSelectionListener) to).selected();
}
} }
}); });
} }
@ -249,14 +246,15 @@ public class CamrecApplication extends Application {
// which is annoying as f // which is annoying as f
Thread.sleep(TimeUnit.MINUTES.toMillis(1)); Thread.sleep(TimeUnit.MINUTES.toMillis(1));
for (EventHandlerConfiguration config : Config.getInstance().getSettings().eventHandlers) { for (EventHandlerConfiguration eventHandlerConfig : Config.getInstance().getSettings().eventHandlers) {
EventHandler handler = new EventHandler(config); EventHandler handler = new EventHandler(eventHandlerConfig);
EventBusHolder.register(handler); EventBusHolder.register(handler);
LOG.debug("Registered event handler for {} {}", config.getEvent(), config.getName()); LOG.debug("Registered event handler for {} {}", eventHandlerConfig.getEvent(), eventHandlerConfig.getName());
} }
LOG.debug("Alert System registered"); LOG.debug("Alert System registered");
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); Thread.currentThread().interrupt();
LOG.info("Interrupted before alter system has been registered");
} }
}).start(); }).start();
} }
@ -269,8 +267,8 @@ public class CamrecApplication extends Application {
try { try {
List<Model> models = recorder.getCurrentlyRecording(); List<Model> models = recorder.getCurrentlyRecording();
long count = models.size(); long count = models.size();
String _title = count > 0 ? "(" + count + ") " + title : title; String windowTitle = count > 0 ? "(" + count + ") " + title : title;
Platform.runLater(() -> primaryStage.setTitle(_title)); Platform.runLater(() -> primaryStage.setTitle(windowTitle));
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Couldn't update window title", e); LOG.warn("Couldn't update window title", e);
} }
@ -279,7 +277,7 @@ public class CamrecApplication extends Application {
}); });
} }
private void writeColorSchemeStyleSheet(Stage primaryStage) { private void writeColorSchemeStyleSheet() {
File colorCss = new File(Config.getInstance().getConfigDir(), "color.css"); File colorCss = new File(Config.getInstance().getConfigDir(), "color.css");
try(FileOutputStream fos = new FileOutputStream(colorCss)) { try(FileOutputStream fos = new FileOutputStream(colorCss)) {
String content = ".root {\n" + String content = ".root {\n" +
@ -407,8 +405,8 @@ public class CamrecApplication extends Application {
static class Release { static class Release {
private String name; private String name;
private String tag_name; private String tagName;
private String html_url; private String htmlUrl;
public String getName() { public String getName() {
return name; return name;
@ -419,23 +417,23 @@ public class CamrecApplication extends Application {
} }
public String getTagName() { public String getTagName() {
return tag_name; return tagName;
} }
public void setTagName(String tagName) { public void setTagName(String tagName) {
this.tag_name = tagName; this.tagName = tagName;
} }
public String getHtmlUrl() { public String getHtmlUrl() {
return html_url; return htmlUrl;
} }
public void setHtmlUrl(String htmlUrl) { public void setHtmlUrl(String htmlUrl) {
this.html_url = htmlUrl; this.htmlUrl = htmlUrl;
} }
public Version getVersion() { public Version getVersion() {
return Version.of(tag_name); return Version.of(tagName);
} }
} }
} }