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