Add SiteTab class, which contains the tabs and a header

The header can contains things like, the token label
This commit is contained in:
0xboobface 2018-10-22 18:21:47 +02:00
parent 1ba003fe56
commit 0f39aa6fc0
4 changed files with 71 additions and 48 deletions

View File

@ -105,7 +105,7 @@ public class MyFreeCams implements Site {
@Override
public boolean supportsTips() {
return false;
return true;
}
@Override

View File

@ -32,19 +32,11 @@ import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.image.Image;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import okhttp3.Request;
import okhttp3.Response;
@ -57,19 +49,17 @@ public class CamrecApplication extends Application {
private Recorder recorder;
static HostServices hostServices;
private SettingsTab settingsTab;
private TabPane tabPane = new TabPane();
private TabPane rootPane = new TabPane();
static EventBus bus;
private HBox tokenPanel;
private Site site;
private List<Site> sites = new ArrayList<>();
@Override
public void start(Stage primaryStage) throws Exception {
site = new MyFreeCams();
sites.add(site);
Chaturbate ctb = new Chaturbate();
sites.add(ctb);
site = new MyFreeCams();
sites.add(site);
loadConfig();
bus = new AsyncEventBus(Executors.newSingleThreadExecutor());
hostServices = getHostServices();
@ -97,12 +87,10 @@ public class CamrecApplication extends Application {
Scene scene = new Scene(rootPane, windowWidth, windowHeight);
primaryStage.setScene(scene);
for (Site site : sites) {
SiteTabPane siteTabPane = new SiteTabPane(site, scene);
Tab siteTab = new Tab(site.getName());
siteTab.setClosable(false);
siteTab.setContent(siteTabPane);
SiteTab siteTab = new SiteTab(site, scene);
rootPane.getTabs().add(siteTab);
}
((SiteTab)rootPane.getTabs().get(0)).selected();
RecordedModelsTab modelsTab = new RecordedModelsTab("Recording", recorder, site);
rootPane.getTabs().add(modelsTab);
@ -168,37 +156,6 @@ public class CamrecApplication extends Application {
}
}
});
String username = Config.getInstance().getSettings().username;
if (site.supportsTips() && username != null && !username.trim().isEmpty()) {
double fontSize = tabPane.getTabMaxHeight() / 2 - 1;
Button buyTokens = new Button("Buy Tokens");
buyTokens.setFont(Font.font(fontSize));
buyTokens.setOnAction((e) -> DesktopIntergation.open(site.getBuyTokensLink()));
buyTokens.setMaxHeight(tabPane.getTabMaxHeight());
TokenLabel tokenBalance = new TokenLabel(site);
tokenPanel = new HBox(5, tokenBalance, buyTokens);
tokenPanel.setAlignment(Pos.BASELINE_RIGHT);
tokenPanel.setMaxHeight(tabPane.getTabMaxHeight());
tokenPanel.setMaxWidth(200);
tokenBalance.setFont(Font.font(fontSize));
HBox.setMargin(tokenBalance, new Insets(0, 5, 0, 0));
HBox.setMargin(buyTokens, new Insets(0, 5, 0, 0));
for (Node node : tabPane.getChildrenUnmodifiable()) {
if (node.getStyleClass().contains("tab-header-area")) {
Parent header = (Parent) node;
for (Node nd : header.getChildrenUnmodifiable()) {
if (nd.getStyleClass().contains("tab-header-background")) {
StackPane pane = (StackPane) nd;
StackPane.setAlignment(tokenPanel, Pos.CENTER_RIGHT);
pane.getChildren().add(tokenPanel);
}
}
}
}
tokenBalance.loadBalance();
}
}
private void createRecorder() {

View File

@ -0,0 +1,52 @@
package ctbrec.ui;
import ctbrec.Config;
import ctbrec.sites.Site;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
public class SiteTab extends Tab implements TabSelectionListener {
private BorderPane rootPane = new BorderPane();
private HBox tokenPanel;
private SiteTabPane siteTabPane;
public SiteTab(Site site, Scene scene) {
super(site.getName());
setClosable(false);
setContent(rootPane);
siteTabPane = new SiteTabPane(site, scene);
rootPane.setCenter(siteTabPane);
String username = Config.getInstance().getSettings().username;
if (site.supportsTips() && username != null && !username.trim().isEmpty()) {
Button buyTokens = new Button("Buy Tokens");
buyTokens.setOnAction((e) -> DesktopIntergation.open(site.getBuyTokensLink()));
TokenLabel tokenBalance = new TokenLabel(site);
tokenPanel = new HBox(5, tokenBalance, buyTokens);
tokenPanel.setAlignment(Pos.BASELINE_RIGHT);
rootPane.setTop(tokenPanel);
// HBox.setMargin(tokenBalance, new Insets(0, 5, 0, 0));
// HBox.setMargin(buyTokens, new Insets(0, 5, 0, 0));
tokenBalance.loadBalance();
BorderPane.setMargin(tokenPanel, new Insets(5, 10, 0, 10));
}
}
@Override
public void selected() {
siteTabPane.selected();
}
@Override
public void deselected() {
siteTabPane.deselected();
}
}

View File

@ -31,4 +31,18 @@ public class SiteTabPane extends TabPane {
}
});
}
public void selected() {
Tab selectedTab = getSelectionModel().getSelectedItem();
if(selectedTab instanceof TabSelectionListener) {
((TabSelectionListener) selectedTab).selected();
}
}
public void deselected() {
Tab selectedTab = getSelectionModel().getSelectedItem();
if(selectedTab instanceof TabSelectionListener) {
((TabSelectionListener) selectedTab).deselected();
}
}
}