Skip to content

Commit

Permalink
Changed detached toolbar to dynamically resize based on the number of…
Browse files Browse the repository at this point in the history
… icons in the toolbar and their size.
  • Loading branch information
EasyG0ing1 committed Apr 18, 2022
1 parent 399c876 commit 893aaab
Show file tree
Hide file tree
Showing 18 changed files with 477 additions and 399 deletions.
6 changes: 0 additions & 6 deletions src/main/java/com/redmondsims/gistfx/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ public static void main(String[] args) {
if (arg.toLowerCase().startsWith("wipesql")) {
Action.wipeSQLOnly();
}
if (arg.toLowerCase().startsWith("iconbase=")) {
String num = arg.replaceFirst("iconbase=", "");
double value = Double.parseDouble(num);
AppSettings.set().iconBaseSize(value);
System.out.println("iconbase set to " + value);
}
if (arg.toLowerCase().startsWith("iconsize=")) {
String num = arg.replaceFirst("iconsize=", "");
int value = Integer.parseInt(num);
Expand Down
131 changes: 92 additions & 39 deletions src/main/java/com/redmondsims/gistfx/alerts/ToolWindow.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.redmondsims.gistfx.alerts;

import com.redmondsims.gistfx.preferences.AppSettings;
import com.redmondsims.gistfx.preferences.LiveSettings;
import com.redmondsims.gistfx.sceneone.SceneOne;
import com.redmondsims.gistfx.ui.gist.treefactory.Toolbox;
import com.redmondsims.gistfx.utils.Util;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.Event;
Expand All @@ -25,6 +26,13 @@

public class ToolWindow {

private enum Source {
QUARTER,
HALF,
THREE_QUARTER,
FULL
}

private final String sceneId;
private AnchorPane ap;
private final double width;
Expand Down Expand Up @@ -174,37 +182,57 @@ public void resizeHeight(Double height) {
SceneOne.resizeHeight(sceneId,height);
}

private void createScene() {
defineParent();
if (callingStage != null) {
SceneOne.set(ap,sceneId,callingStage)
.size(width,height)
.title(title)
.styleSheets(AppSettings.get().theme().getStyleSheet())
.size(width,height)
.onCloseEvent(onCloseHandler)
.modality(initModality)
.initStyle(transparentStyle ? StageStyle.TRANSPARENT : StageStyle.DECORATED)
.build();
}
else {
SceneOne.set(ap,sceneId)
.size(width,height)
.title(title)
.styleSheets(AppSettings.get().theme().getStyleSheet())
.initStyle(transparentStyle ? StageStyle.TRANSPARENT : StageStyle.DECORATED)
.modality(initModality)
.size(width,height)
.onCloseEvent(onCloseHandler)
.alwaysOnTop()
.build();
}
}

public void showAndWait(Toolbox toolBox) {
if(SceneOne.sceneExists(sceneId)) {
SceneOne.removeScene(sceneId);
}
createScene();
setContent(toolBox);
SceneOne.showAndWait(sceneId);
if (afterCloseEvent != null) afterCloseEvent.handle(new ActionEvent());
}

public void showAndWait() {
if(!SceneOne.sceneExists(sceneId)) {
defineParent();
if (callingStage != null) {
SceneOne.set(ap,sceneId,callingStage)
.size(width,height)
.title(title)
.styleSheets(AppSettings.get().theme().getStyleSheet())
.size(width,height)
.onCloseEvent(onCloseHandler)
.modality(initModality)
.initStyle(transparentStyle ? StageStyle.TRANSPARENT : StageStyle.DECORATED)
.showAndWait();
}
else {
SceneOne.set(ap,sceneId)
.size(width,height)
.title(title)
.styleSheets(AppSettings.get().theme().getStyleSheet())
.initStyle(transparentStyle ? StageStyle.TRANSPARENT : StageStyle.DECORATED)
.modality(initModality)
.size(width,height)
.onCloseEvent(onCloseHandler)
.alwaysOnTop()
.showAndWait();
}
if (afterCloseEvent != null) afterCloseEvent.handle(new ActionEvent());
createScene();
}
else {
SceneOne.showScene(sceneId);
SceneOne.showAndWait(sceneId);
if (afterCloseEvent != null) afterCloseEvent.handle(new ActionEvent());
}

public void show() {
if(!SceneOne.sceneExists(sceneId)) {
createScene();
}
SceneOne.showScene(sceneId);
setContent(this.content);
}

private void defineParent() {
Expand Down Expand Up @@ -251,30 +279,55 @@ private void setNodePosition(Node node, double left, double right, double top, d
if (right != -1) setRightAnchor(node, right);
}

public void setStyleSheet (String styleSheet) {
SceneOne.getScene(sceneId).getStylesheets().clear();
SceneOne.getScene(sceneId).getStylesheets().add(styleSheet);
}

public String getSceneId() {
return sceneId;
}

public void hide() {
SceneOne.hide(sceneId);
public void setContent(Toolbox toolbox) {
if (ap == null) {
if (this.content == null)
ap = new AnchorPane();
else
ap = new AnchorPane(this.content);
}
ap.getChildren().remove(this.content);
this.content = toolbox.content();
ap.getChildren().add(this.content);
SceneOne.setWindowSize(sceneId, toolbox.width(), toolbox.height() * calcOffset(toolbox.height()));
}

public void show() {
SceneOne.showScene(sceneId);
setContent(this.content);
private double calcOffset(double value) {
double coreValue = value - 40;
double range = 170;
double oneQuarter = range * .25;
double oneHalf = range * .5;
double threeQuarter = range * .75;
double finalOffset = Util.reMap(value,40,210,1.3,.66,3);
Source source;
if( coreValue <= oneQuarter) source = Source.QUARTER;
else if (coreValue <= oneHalf) source = Source.HALF;
else if (coreValue <= threeQuarter) source = Source.THREE_QUARTER;
else source = Source.FULL;
switch(source) {
case QUARTER -> finalOffset = Util.reMap(coreValue, 0, oneQuarter, 1.3, .91, 3);
case HALF -> finalOffset = Util.reMap(coreValue, oneQuarter, oneHalf, .89, .75, 3);
case THREE_QUARTER -> finalOffset = Util.reMap(coreValue, oneHalf, threeQuarter, .75, .685, 3);
case FULL -> finalOffset = Util.reMap(coreValue, threeQuarter, range, .69, .66, 3);
};
return finalOffset;
}

public void setContent(Node content) {
if(ap == null) {
if(this.content == null)
ap = new AnchorPane();
else
ap = new AnchorPane(this.content);
}
if (this.content != null) {
ap.getChildren().remove(this.content);
this.content = content;
ap.getChildren().add(this.content);
setNodePosition(this.content,0,0,0,noButtons ? 0 : 50);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.redmondsims.gistfx.networking.Payload;
import com.redmondsims.gistfx.sceneone.SceneOne;
import com.redmondsims.gistfx.ui.gist.GistWindow;
import com.redmondsims.gistfx.ui.gist.factory.TreeNode;
import com.redmondsims.gistfx.ui.gist.treefactory.TreeNode;
import com.redmondsims.gistfx.utils.Resources;
import com.redmondsims.gistfx.utils.Status;
import javafx.application.Platform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ public double dividerExpanded() {
return prefs.getDouble(LABEL.DIVIDER_EXPANDED.Name(), 0.0);
}

public double iconBaseSize() {
return prefs.getDouble(LABEL.ICON_BASE_SIZE.Name(), 25.0);
public Integer iconBaseSize() {
return prefs.getInt(LABEL.ICON_BASE_SIZE.Name(), 25);
}

public ColorOption trayIconColorOption() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ public void dividerExpanded(double value) {
prefs.putDouble(LABEL.DIVIDER_EXPANDED.Name(), value);
}

public void iconBaseSize(double value) {
public void iconBaseSize(Integer value) {
AppSettings.clear().iconBaseSize();
prefs.putDouble(LABEL.ICON_BASE_SIZE.Name(), value);
prefs.putInt(LABEL.ICON_BASE_SIZE.Name(), value);
}

public void trayIconColorOption(ColorOption option) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.util.Duration;
import org.apache.commons.math3.util.Precision;

import java.awt.*;
Expand Down Expand Up @@ -60,7 +61,7 @@ public VBox content(GistWindow gistWindow) {
btnExpanded = new Button("Enable Expanded");
lblMessage = new Label();
lblIconSize = new Label("Icon Size");
spinner = new Spinner<>(1,200,(int) AppSettings.get().iconBaseSize());
spinner = new Spinner<>(15,100,(int) AppSettings.get().iconBaseSize());
lblMessage.setId("LargerFont");

lblAtRest.setAlignment(Pos.CENTER_RIGHT);
Expand Down Expand Up @@ -148,9 +149,12 @@ public VBox content(GistWindow gistWindow) {
state = State.EXPANDED;
});

spinner.setOnMouseClicked(e->{
gistWindow.setIconSize((double) spinner.getValue());
AppSettings.set().iconBaseSize((double) spinner.getValue());
spinner.setInitialDelay(Duration.millis(900));
spinner.getValueFactory().setValue(AppSettings.get().iconBaseSize());

spinner.getValueFactory().valueProperty().addListener((observable, oldValue, newValue) -> {
gistWindow.setIconSize((double) newValue);
AppSettings.set().iconBaseSize(newValue);
});

Tooltip.install(btnAtRest, Action.newTooltip("This will put the main screen into a wide mode with the\ndivider at resting position. Set the desired location of\nthe divider when in the 'at rest' state."));
Expand Down
57 changes: 36 additions & 21 deletions src/main/java/com/redmondsims/gistfx/sceneone/SceneOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ public static void autoSize() {
autoSize(defaultSceneName);
}

public static void doSize(String sceneName) {
Platform.runLater(() -> {
autoSize(sceneName);
});
}

public static void setWidth(String sceneName, double width) {
sceneMap.get(sceneName).sizeToWidth(width);
}

/**
* Named methods (called by above default Methods or called externally by passing in a sceneName
*/
Expand Down Expand Up @@ -195,6 +205,11 @@ public static Show showAndWait(String sceneName) {
return new Show(sceneName,true);
}

public static void showAndWait(String sceneName, double width, double height) {
checkScene(sceneName);
sceneMap.get(sceneName).showAndWait(width, height);
}

public static boolean isShowing(String sceneName) {
if(sceneMap.containsKey(sceneName)) {
return sceneMap.get(sceneName).isShowing();
Expand All @@ -206,6 +221,11 @@ public static boolean sceneExists(String sceneName) {
return sceneMap.containsKey(sceneName);
}

public static void removeScene(String sceneName) {
checkScene(sceneName);
sceneMap.remove(sceneName);
}

public static void setOnKeyPressed(String sceneName, EventHandler<? super KeyEvent> event) {
checkScene(sceneName);
sceneMap.get(sceneName).setOnKeyPressed(event);
Expand Down Expand Up @@ -243,7 +263,7 @@ public static void setHiddenOnLostFocus(String sceneName, boolean hiddenOnLostFo

public static void setWindowSize(String sceneName,double width, double height) {
checkScene(sceneName);
sceneMap.get(sceneName).setWindowSize(width,height);
sceneMap.get(sceneName).setSize(width,height);
}

public static void runOnShown(String sceneName, EventHandler<Event> handler) {
Expand Down Expand Up @@ -820,13 +840,6 @@ public void resize(Stage stage) {
stage.setHeight(VALUES.get(SIZE.HEIGHT));
}
}

public void resize(Window window) {
if(isSet()) {
window.setWidth(VALUES.get(SIZE.WIDTH));
window.setHeight(VALUES.get(SIZE.HEIGHT));
}
}
}

private Parent root;
Expand Down Expand Up @@ -854,6 +867,8 @@ public void resize(Window window) {
private final Stage owner;
private double originalWidth = 0;
private double originalHeight= 0;
private double desiredWidth = 0;
private double desiredHeight = 0;
private boolean alwaysOnTop;

private final ChangeListener<Boolean> lostFocusListener = (observable, oldValue, newValue) -> {
Expand Down Expand Up @@ -948,7 +963,7 @@ private void setTitle() {
private void getStageForScene() {
StageObject stageObject = stageMap.getOrDefault(sceneName,stageMap.get(defaultSceneName));
stage = stageObject.get();
if(!stage.isShowing()) {
if(!stage.isShowing() && !stageObject.hasShown) {
if (stageStyle != null) stage.initStyle(stageStyle);
if (modality != null) stage.initModality(modality);
}
Expand Down Expand Up @@ -1054,7 +1069,7 @@ private void postShowProcessing() {
if (onShowEventHandler != null) {
onShowEventHandler.handle(null);
}
sceneSize.resize(this.window);
sceneSize.resize(this.stage);
}

private void showScene() {
Expand Down Expand Up @@ -1091,6 +1106,12 @@ public void showAndWait() {
showScene();
}

public void showAndWait(double width, double height) {
sceneSize.setWidth(width);
sceneSize.setHeight(height);
showAndWait();
}

private Term getDisplacement() {
if (scenePosition.isSet()) return Term.EXACT;
else return Term.CENTERED;
Expand Down Expand Up @@ -1122,17 +1143,7 @@ public void setParent(Parent root) {

public void setSize(double width, double height) {
sceneSize.set(width,height);
sceneSize.resize(this.window);
}

public void setWindowSize(double width, double height) {
if(window.isShowing()) {
sceneSize.set(width,height);
sceneSize.resize(this.window);
}
else {
System.out.println("Window not showing");
}
sceneSize.resize(this.stage);
}

public void setPosition(double posX, double posY) {
Expand Down Expand Up @@ -1291,6 +1302,10 @@ public void autoSize() {
scene.getWindow().sizeToScene();
}

public void sizeToWidth(double width) {
stage.setWidth(width);
}

public boolean isFullscreen() {
return stage.isMaximized();
}
Expand Down
Loading

0 comments on commit 893aaab

Please sign in to comment.