Skip to content

Commit

Permalink
Modify BasicDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
naotsugu committed Dec 23, 2023
1 parent 82660d7 commit c483019
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.mammb.code.editor.ui.app;

import com.mammb.code.editor.ui.app.control.BasicDialog;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;

public class UiAboutDialog extends UiDialog<ButtonType> {
public UiAboutDialog(UiColor themeColor) {
super(themeColor);
public class AboutDialog extends BasicDialog {

public AboutDialog() {
super();
final DialogPane dialogPane = getDialogPane();
dialogPane.setContentText("min-editor " + Version.value);
dialogPane.getButtonTypes().addAll(ButtonType.CLOSE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ private Stage buildScene(Stage stage, Context context) {
var scene = new Scene(borderPane);
//scene.getStylesheets().add(getClass().getResource("/app.css").toExternalForm());
scene.getStylesheets().add(css(uiColor));
StCss.install(context.preference().colorScheme()).into(scene);
StCss.setScheme(context.preference().colorScheme());
StCss.of().into(scene);
stage.setScene(scene);
stage.setTitle("min-editor");
stage.setOnCloseRequest(editorPane::handleCloseRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public UiCommandBar(UiColor themeColor) {
forward.setDisable(true);
backward.setDisable(true);

menu.setOnMouseClicked(e -> new UiAboutDialog(uiColor).showAndWait());
menu.setOnMouseClicked(e -> new AboutDialog().showAndWait());

setBackground(uiColor.backgroundFill());

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
/*
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mammb.code.editor.ui.app.control;

import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;

/**
* The BasicDialog.
* @author Naotsugu Kobayashi
*/
public class BasicDialog extends Dialog<ButtonType> {

public BasicDialog() {
StCss.instance.into(getDialogPane());
StCss.rootOf().into(getDialogPane());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ CssRun join(CssRun other) {
}

void into(Scene scene) {
scene.getStylesheets().add("data:text/css;base64," +
Base64.getEncoder().encodeToString(cssText.getBytes(StandardCharsets.UTF_8)));
scene.getStylesheets().add(dataUrl(cssText));
}

void into(Parent parent) {
parent.getStylesheets().add(cssText);
parent.getStylesheets().add(dataUrl(cssText));
}

private String dataUrl(String text) {
return "data:text/css;base64," +
Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
import static com.mammb.code.editor.ui.app.control.CssProcessor.CSS;

/**
* The StCss.
* The theme css.
* @author Naotsugu Kobayashi
*/
public class StCss {

/** The StCss instance. */
static final StCss instance = new StCss(CssRun.empty);
/** The style theme. */
private static volatile StyleTheme styleTheme = StyleTheme.dark();

/** The css run. */
private CssRun cssRun;
Expand All @@ -44,36 +44,52 @@ private StCss(CssRun cssRun) {


/**
* Install.
* Set the scheme.
* @param cs the color scheme
* @return the StCss
*/
public static synchronized StCss install(ColorScheme cs) {
var st = switch (cs) {
case DARK -> StyleTheme.dark();
public static void setScheme(ColorScheme cs) {
styleTheme = switch (cs) {
case DARK -> StyleTheme.dark();
case LIGHT -> StyleTheme.light();
};
instance.cssRun = buildCss().on(st);
return instance;
}


public void into(Scene scene) {
cssRun.into(scene);
/**
* Create the theme css.
* @return the StCss
*/
public static StCss of() {
var css = Css.join(root, Icon.css, FlatButton.css);
return new StCss(css.on(styleTheme));
}


public void into(Parent parent) {
cssRun.into(parent);
/**
* Create the theme css.
* @return the StCss
*/
public static StCss of(Css css) {
return new StCss(css.on(styleTheme));
}


/**
* Build css.
* @return Css
* Create the root theme css.
* @return the StCss
*/
private static Css buildCss() {
return Css.join(root, Icon.css, FlatButton.css);
public static StCss rootOf() {
return of(root);
}


public void into(Scene scene) {
cssRun.into(scene);
}


public void into(Parent parent) {
cssRun.into(parent);
}


Expand Down

This file was deleted.

0 comments on commit c483019

Please sign in to comment.