├── .gitignore ├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ ├── question.md │ ├── bug_report.md │ └── feature_request.md ├── stagepro-sampler ├── src │ └── main │ │ ├── resources │ │ └── com │ │ │ └── techsenger │ │ │ └── stagepro │ │ │ └── sampler │ │ │ ├── icon-dark.png │ │ │ ├── icon-light.png │ │ │ ├── sampler.css │ │ │ └── sample.css │ │ └── java │ │ ├── com │ │ └── techsenger │ │ │ └── stagepro │ │ │ └── sampler │ │ │ ├── package-info.java │ │ │ ├── Sample.java │ │ │ └── Sampler.java │ │ └── module-info.java └── pom.xml ├── stagepro-core ├── src │ └── main │ │ ├── java │ │ ├── com │ │ │ └── techsenger │ │ │ │ └── stagepro │ │ │ │ └── core │ │ │ │ ├── package-info.java │ │ │ │ ├── StageResizeEvent.java │ │ │ │ ├── SimpleStageController.java │ │ │ │ ├── MaximizeButton.java │ │ │ │ ├── StandardStageController.java │ │ │ │ └── BaseStageController.java │ │ └── module-info.java │ │ └── resources │ │ └── com │ │ └── techsenger │ │ └── stagepro │ │ └── core │ │ └── stage.css └── pom.xml ├── pom.xml ├── README.md └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: techsenger -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask a question about this project 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve the project 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /stagepro-sampler/src/main/resources/com/techsenger/stagepro/sampler/icon-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/stagepro/HEAD/stagepro-sampler/src/main/resources/com/techsenger/stagepro/sampler/icon-dark.png -------------------------------------------------------------------------------- /stagepro-sampler/src/main/resources/com/techsenger/stagepro/sampler/icon-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techsenger/stagepro/HEAD/stagepro-sampler/src/main/resources/com/techsenger/stagepro/sampler/icon-light.png -------------------------------------------------------------------------------- /stagepro-core/src/main/java/com/techsenger/stagepro/core/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.stagepro.core; 18 | -------------------------------------------------------------------------------- /stagepro-sampler/src/main/java/com/techsenger/stagepro/sampler/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.stagepro.sampler; 18 | -------------------------------------------------------------------------------- /stagepro-sampler/src/main/resources/com/techsenger/stagepro/sampler/sampler.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | Author : Pavel Castornii 19 | */ 20 | 21 | .table-view .table-column { 22 | -fx-alignment: CENTER-LEFT; 23 | } 24 | 25 | .table-view .table-column.action { 26 | -fx-alignment: CENTER; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /stagepro-core/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.stagepro.core { 18 | requires org.slf4j; 19 | requires com.techsenger.toolkit.fx; 20 | requires javafx.base; 21 | requires javafx.graphics; 22 | requires javafx.controls; 23 | 24 | exports com.techsenger.stagepro.core; 25 | } -------------------------------------------------------------------------------- /stagepro-sampler/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module com.techsenger.stagepro.sampler { 18 | requires com.techsenger.toolkit.fx; 19 | requires com.techsenger.stagepro.core; 20 | requires org.slf4j; 21 | requires javafx.base; 22 | requires javafx.graphics; 23 | requires javafx.controls; 24 | 25 | exports com.techsenger.stagepro.sampler; 26 | } -------------------------------------------------------------------------------- /stagepro-core/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.techsenger.stagepro 6 | stagepro 7 | 1.2.0-SNAPSHOT 8 | 9 | 10 | com.techsenger.stagepro 11 | stagepro-core 12 | jar 13 | StagePro - Core 14 | The core module that contains all the classes for working with the StagePro 15 | 16 | 17 | 18 | org.slf4j 19 | slf4j-api 20 | 21 | 22 | com.techsenger.toolkit 23 | toolkit-fx 24 | 25 | 26 | org.openjfx 27 | javafx-base 28 | 29 | 30 | org.openjfx 31 | javafx-graphics 32 | 33 | 34 | org.openjfx 35 | javafx-controls 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /stagepro-sampler/src/main/java/com/techsenger/stagepro/sampler/Sample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.stagepro.sampler; 18 | 19 | /** 20 | * 21 | * @author Pavel Castornii 22 | */ 23 | public class Sample { 24 | 25 | private final int id; 26 | 27 | private final String controller; 28 | 29 | private final String description; 30 | 31 | private final Runnable action; 32 | 33 | public Sample(int id, String controller, String description, Runnable action) { 34 | this.id = id; 35 | this.controller = controller; 36 | this.description = description; 37 | this.action = action; 38 | } 39 | 40 | public int getId() { 41 | return id; 42 | } 43 | 44 | public String getController() { 45 | return controller; 46 | } 47 | 48 | public String getDescription() { 49 | return description; 50 | } 51 | 52 | public Runnable getAction() { 53 | return action; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /stagepro-sampler/src/main/resources/com/techsenger/stagepro/sampler/sample.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | Author : Pavel Castornii 19 | */ 20 | 21 | .stage-box > .title-bar > .icon-view { 22 | -fx-image: url("icon-light.png"); 23 | } 24 | 25 | .stage-box > .title-bar > .menu-bar { 26 | -fx-background-color: #CCCCCC; 27 | } 28 | 29 | .stage-box > .title-bar > .menu-bar >.container { 30 | -fx-padding: 0; 31 | } 32 | 33 | .stage-box.dark > .title-bar { 34 | -fx-background-color: #000030; 35 | } 36 | 37 | .stage-box.dark > .title-bar > .menu-bar { 38 | -fx-background-color: #000030; 39 | } 40 | 41 | .stage-box.dark > .title-bar > .menu-bar .label { 42 | -fx-text-fill: #ffffff; 43 | } 44 | 45 | .stage-box.dark > .title-bar > .icon-view { 46 | -fx-image: url("icon-dark.png"); 47 | } 48 | 49 | .stage-box.dark > .title-bar > .title-label { 50 | -fx-text-fill: #ffffff; 51 | } 52 | 53 | .stage-box.dark > .title-bar > .button-box > .button { 54 | -fx-background-color: #000060; 55 | } 56 | 57 | .stage-box.dark > .title-bar > .button-box > .button > .icon { 58 | -fx-background-color: #ffffff; 59 | } -------------------------------------------------------------------------------- /stagepro-sampler/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.techsenger.stagepro 6 | stagepro 7 | 1.2.0-SNAPSHOT 8 | 9 | 10 | com.techsenger.stagepro 11 | stagepro-sampler 12 | jar 13 | StagePro - Sampler 14 | The demonstration module that showcases the capabilities of StagePro 15 | 16 | 17 | 18 | com.techsenger.toolkit 19 | toolkit-fx 20 | 21 | 22 | com.techsenger.stagepro 23 | stagepro-core 24 | 25 | 26 | org.slf4j 27 | slf4j-api 28 | 29 | 30 | org.openjfx 31 | javafx-base 32 | 33 | 34 | org.openjfx 35 | javafx-graphics 36 | 37 | 38 | org.openjfx 39 | javafx-controls 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.openjfx 48 | javafx-maven-plugin 49 | ${javafx.plugin.version} 50 | 51 | com.techsenger.stagepro.sampler.Sampler 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /stagepro-core/src/main/java/com/techsenger/stagepro/core/StageResizeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.stagepro.core; 18 | 19 | import javafx.event.Event; 20 | import javafx.event.EventType; 21 | import javafx.scene.input.MouseEvent; 22 | 23 | /** 24 | * Custom event for tracking Stage resize operations in JavaFX. 25 | * 26 | *

This implementation deliberately avoids extending WindowEvent to prevent any potential interference with 27 | * JavaFX's native window event handling. The independent event hierarchy ensures clean separation while maintaining 28 | * focus on Stage-specific behavior.

29 | * 30 | *

The STARTED/FINISHED naming follows JavaFX's established convention for interaction events, mirroring patterns 31 | * like ScrollEvent.SCROLL_STARTED/SCROLL_FINISHED.

32 | * 33 | * @author Pavel Castornii 34 | */ 35 | public class StageResizeEvent extends Event { 36 | 37 | /** 38 | * Common supertype for all stage resize event types. 39 | */ 40 | public static final EventType ANY = new EventType<>(Event.ANY, "STAGE_RESIZE"); 41 | 42 | /** 43 | * This event occurs when user starts resizing a stage (mouse pressed on border). 44 | */ 45 | public static final EventType STAGE_RESIZE_STARTED = 46 | new EventType<>(StageResizeEvent.ANY, "STAGE_RESIZE_STARTED"); 47 | 48 | /** 49 | * This event occurs when user finishes resizing a stage (mouse released). 50 | */ 51 | public static final EventType STAGE_RESIZE_FINISHED = 52 | new EventType<>(StageResizeEvent.ANY, "STAGE_RESIZE_FINISHED"); 53 | 54 | private final MouseEvent mouseEvent; 55 | 56 | public StageResizeEvent(EventType eventType, MouseEvent mouseEvent) { 57 | super(eventType); 58 | this.mouseEvent = mouseEvent; 59 | } 60 | 61 | public MouseEvent getMouseEvent() { 62 | return mouseEvent; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /stagepro-core/src/main/java/com/techsenger/stagepro/core/SimpleStageController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.stagepro.core; 18 | 19 | import com.techsenger.toolkit.fx.Spacer; 20 | import javafx.scene.control.Button; 21 | import javafx.scene.control.Label; 22 | import javafx.scene.image.ImageView; 23 | import javafx.scene.layout.Region; 24 | import javafx.stage.Stage; 25 | 26 | /** 27 | * A stage with a title and a close button. 28 | * 29 | * @author Pavel Castornii 30 | */ 31 | public class SimpleStageController extends BaseStageController { 32 | 33 | private final ImageView iconView = new ImageView(); 34 | 35 | private final Label titleLabel = new Label(); 36 | 37 | private final Button closeButton = new Button(null, new Region()); 38 | 39 | public SimpleStageController(Stage stage, double width, double height) { 40 | this(stage, width, height, true); 41 | } 42 | 43 | public SimpleStageController(Stage stage, double width, double height, boolean initTitleBar) { 44 | super(stage, width, height); 45 | build(); 46 | bind(); 47 | addHandlers(); 48 | if (initTitleBar) { 49 | getButtonBox().getChildren().add(closeButton); 50 | getTitleBar().getChildren().addAll(iconView, titleLabel, new Spacer(), getButtonBox()); 51 | } 52 | } 53 | 54 | public ImageView getIconView() { 55 | return iconView; 56 | } 57 | 58 | public Label getTitleLabel() { 59 | return titleLabel; 60 | } 61 | 62 | public Button getCloseButton() { 63 | return closeButton; 64 | } 65 | 66 | private void build() { 67 | this.iconView.getStyleClass().add("icon-view"); 68 | this.titleLabel.getStyleClass().add("title-label"); 69 | this.closeButton.getGraphic().getStyleClass().add("icon"); 70 | this.closeButton.getStyleClass().add("close-button"); 71 | } 72 | 73 | private void bind() { 74 | this.titleLabel.textProperty().bindBidirectional(getStage().titleProperty()); 75 | } 76 | 77 | private void addHandlers() { 78 | this.closeButton.setOnAction(e -> getStage().close()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.techsenger.maven.root 6 | maven-root 7 | 1.6.0-SNAPSHOT 8 | 9 | 10 | com.techsenger.stagepro 11 | stagepro 12 | 1.2.0-SNAPSHOT 13 | pom 14 | StagePro 15 | StagePro is a library for creating custom JavaFX stages with full control 16 | 17 | 18 | 19 | Apache License, Version 2.0 20 | http://www.apache.org/licenses/LICENSE-2.0 21 | 22 | 23 | 24 | https://github.com/techsenger/stagepro 25 | 26 | 27 | scm:git:https://github.com/techsenger/stagepro.git 28 | scm:git:https://github.com/techsenger/stagepro.git 29 | https://github.com/techsenger/stagepro 30 | 31 | 32 | 33 | GitHub 34 | https://github.com/techsenger/stagepro/issues 35 | 36 | 37 | 38 | 39 | pcastornii 40 | Pavel Castornii 41 | 42 | 43 | 44 | 45 | 46 | repsy-snapshots 47 | https://repo.repsy.io/mvn/techsenger/snapshots 48 | 49 | false 50 | 51 | 52 | true 53 | 54 | 55 | 56 | 57 | 58 | stagepro-sampler 59 | 60 | 61 | 62 | 63 | 64 | com.techsenger.osp.bom 65 | osp-bom 66 | 1.7.0-SNAPSHOT 67 | pom 68 | import 69 | 70 | 71 | 72 | com.techsenger.stagepro 73 | stagepro-core 74 | ${project.version} 75 | 76 | 77 | 78 | 79 | 80 | stagepro-core 81 | stagepro-sampler 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /stagepro-core/src/main/java/com/techsenger/stagepro/core/MaximizeButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.stagepro.core; 18 | 19 | import javafx.beans.property.IntegerProperty; 20 | import javafx.beans.property.ObjectProperty; 21 | import javafx.beans.property.SimpleIntegerProperty; 22 | import javafx.beans.property.SimpleObjectProperty; 23 | import javafx.scene.Node; 24 | import javafx.scene.control.Button; 25 | 26 | /** 27 | * 28 | * @author Pavel Castornii 29 | */ 30 | public class MaximizeButton extends Button { 31 | 32 | /** 33 | * Defines the policy for the behavior of the maximize button in stages where the {@code resizable} property is 34 | * {@code false}. 35 | * 36 | */ 37 | public enum ResizableStatePolicy { 38 | 39 | /** 40 | * The maximize button's visibility behavior is controlled (i.e., it may be shown or hidden). 41 | */ 42 | VISIBILITY, 43 | 44 | /** 45 | * The maximize button's interactivity behavior is controlled (i.e., it may be enabled or disabled). 46 | */ 47 | INTERACTIVITY 48 | } 49 | 50 | private final ObjectProperty policy = new SimpleObjectProperty<>(); 51 | 52 | /** 53 | * The index of the button in button box. It is required to add/remove button according to its policy. 54 | * Button with index -1 will be ignored. 55 | */ 56 | private final IntegerProperty index = new SimpleIntegerProperty(-1); 57 | 58 | public MaximizeButton() { 59 | 60 | } 61 | 62 | public MaximizeButton(ResizableStatePolicy policy) { 63 | this(policy, null, null); 64 | } 65 | 66 | public MaximizeButton(ResizableStatePolicy policy, String string) { 67 | this(policy, string, null); 68 | } 69 | 70 | public MaximizeButton(ResizableStatePolicy policy, String string, Node node) { 71 | super(string, node); 72 | this.policy.set(policy); 73 | getStyleClass().add("maximize-button"); 74 | } 75 | 76 | public ObjectProperty policyProperty() { 77 | return policy; 78 | } 79 | 80 | public ResizableStatePolicy getPolicy() { 81 | return policy.get(); 82 | } 83 | 84 | public void setPolicy(ResizableStatePolicy policy) { 85 | this.policy.set(policy); 86 | } 87 | 88 | IntegerProperty indexProperty() { 89 | return index; 90 | } 91 | 92 | int getIndex() { 93 | return index.get(); 94 | } 95 | 96 | void setIndex(int index) { 97 | this.index.set(index); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /stagepro-core/src/main/resources/com/techsenger/stagepro/core/stage.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | Author : Pavel Castornii 19 | */ 20 | 21 | .stage-box { 22 | /* ... */ 23 | -fx-background-color: #AAAAAA, #FFFFFF; 24 | -fx-padding: 1; 25 | -fx-background-insets: 0, 1; 26 | -fx-background-radius: 5 5 0 0, 4 4 0 0; 27 | } 28 | 29 | .stage-box:maximized { 30 | -fx-background-radius: 0, 0; 31 | } 32 | 33 | .stage-box > .title-bar { 34 | -fx-min-height: 36px; 35 | -fx-pref-height: 36px; 36 | -fx-max-height: 36px; 37 | -fx-background-color: #CCCCCC; 38 | -fx-alignment: center_left; 39 | -fx-padding: 0 10 0 10; 40 | -fx-background-radius: 4 4 0 0; 41 | } 42 | 43 | .stage-box:maximized > .title-bar { 44 | -fx-background-radius: 0; 45 | } 46 | 47 | .stage-box > .title-bar > .icon-view { 48 | /* ... */ 49 | } 50 | 51 | .stage-box > .title-bar > .title-label { 52 | /* ... */ 53 | } 54 | 55 | .stage-box > .title-bar > .button-box { 56 | -fx-alignment: center; 57 | -fx-spacing: 10; 58 | } 59 | 60 | .stage-box > .title-bar > .button-box > .button { 61 | -fx-min-width: 20px; 62 | -fx-min-height: 20px; 63 | -fx-max-width: 20px; 64 | -fx-max-height: 20px; 65 | -fx-background-radius: 20; 66 | -fx-padding: 0; 67 | -fx-background-insets: 0; 68 | -fx-focus-traversable: false; 69 | } 70 | 71 | /* 72 | The width of the icon and the width of the button should be chosen in such a way that the spacing between the 73 | icon and the button is equal on both the left and right sides of the icon. The same applies to the spacing above and 74 | below the icon. Otherwise, the result will appear fuzzy due to -fx-position-shape. 75 | See https://openjfx.io/javadoc/23/javafx.graphics/javafx/scene/shape/Shape.html#interaction-with-coordinate-systems-heading 76 | */ 77 | .stage-box > .title-bar > .button-box > .button > .icon { 78 | -fx-scale-shape: false; 79 | -fx-pref-width:20px; 80 | -fx-pref-height:20px; 81 | -fx-background-color: #111111; 82 | } 83 | 84 | .stage-box > .title-bar > .button-box > .close-button > .icon { 85 | -fx-shape:"M0,0 H1 L 4,3 7,0 H8 V1 L 5,4 8,7 V8 H7 L 4,5 1,8 H0 V7 L 3,4 0,1 Z"; 86 | } 87 | 88 | .stage-box > .title-bar > .button-box > .minimize-button > .icon { 89 | -fx-shape:"M0,0 H10 V2 H0 Z"; 90 | } 91 | 92 | .stage-box > .title-bar > .button-box > .maximize-button > .icon { 93 | -fx-shape:"M0,0 H10 V2 H0 Z M0,0 H1 V9 H0 Z M0,10 H10 V9 H0 Z M10,0 V9 H9 V0 Z"; 94 | } 95 | 96 | .stage-box:maximized > .title-bar > .button-box > .maximize-button > .icon { 97 | -fx-shape:"M0,2 H8 V4 H0 Z M0,2 H1 V10 H0 Z M0,9 H8 V10 H0 Z M7,2 H8 V10 H7 Z M2,0 H3 V2 H2 Z M2,0 H10 V1 H2 Z M9,0 H10 V8 H9 Z M8,7 H10 V8 H8 Z"; 98 | } 99 | 100 | .stage-box > .content-area { 101 | /* ... */ 102 | } 103 | 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Techsenger StagePro 2 | 3 | Techsenger StagePro is a library that allows you to create custom stages with nearly any configuration, while remaining 4 | easy to use. The project also includes a sampler module, featuring key samples to help you get started with the library. 5 | 6 | ## Table of Contents 7 | * [Demo](#demo) 8 | * [Light Theme](#demo-light-theme) 9 | * [Dark Theme](#demo-dark-theme) 10 | * [Features](#features) 11 | * [Limitations](#limitations) 12 | * [JavaFX Issues](#javafx-issues) 13 | * [Dependencies](#dependencies) 14 | * [Usage](#usage) 15 | * [Code building](#code-building) 16 | * [Running Sampler](#sampler) 17 | * [License](#license) 18 | * [Contributing](#contributing) 19 | * [Support Us](#support-us) 20 | 21 | ## Demo 22 | 23 | ### Light Theme 24 | 25 | ![stagepro-light-theme](https://github.com/user-attachments/assets/ceee91fd-f43d-4193-adda-4ff0e70b0d8a) 26 | 27 | ### Dark Theme 28 | 29 | ![stagepro-dark-theme](https://github.com/user-attachments/assets/3fc4a59d-a745-4b99-bce5-d6d7cfa152c0) 30 | 31 | ## Features 32 | 33 | Key features include: 34 | 35 | * Fully customizable title bar configurations. 36 | * Support for dynamic configuration changes. 37 | * Ability to place basic buttons on either the left or right side. 38 | * Two maximize button policies. 39 | * Styling via CSS. 40 | * Dark mode support. 41 | * SVG-based button icons. 42 | * Only two events triggered during resizing (start and finish). 43 | 44 | ## Limitations 45 | 46 | * No shadow support. Currently, shadows for Stage are not supported as JavaFX provides no built-in way to render 47 | shadows around transparent windows. This would likely require platform-specific native code. 48 | * No native window management features. Edge-based behaviors like Windows Snap Layouts and GNOME Edge Tiling cannot 49 | be properly implemented using Java alone. These features also require platform-specific native code. 50 | 51 | ## JavaFX Issues 52 | 53 | * Use JavaFX 16–20 or versions after 24-ea+19 due to known bugs ([JDK-8344372](https://bugs.openjdk.org/browse/JDK-8344372)). 54 | * Resizing the stage via the top/left border causes jitter on the opposite side ([JDK-8347155](https://bugs.openjdk.org/browse/JDK-8347155)). 55 | 56 | ## Dependencies 57 | 58 | This project is available on Maven Central: 59 | 60 | ``` 61 | 62 | com.techsenger.stagepro 63 | stagepro-core 64 | ${stagepro.version} 65 | 66 | ``` 67 | 68 | ## Usage 69 | 70 | To create a standard Stage, use the code below. To explore all features, check out the examples in the sampler. 71 | 72 | ``` 73 | @Override 74 | public void start(Stage stage) { 75 | var controller = new StandardStageController(stage, 800, 600); 76 | var content = new VBox(...); 77 | controller.setContent(content); 78 | stage.show(); 79 | } 80 | ``` 81 | 82 | ## Code Building 83 | 84 | To build the library use standard Git and Maven commands: 85 | 86 | git clone https://github.com/techsenger/stagepro 87 | cd stagepro 88 | mvn clean install 89 | 90 | ## Running Sampler 91 | 92 | To run the sampler execute the following commands in the root of the project: 93 | 94 | cd stagepro-sampler 95 | mvn javafx:run 96 | 97 | Please note, that debugger settings are in `stagepro-sampler/pom.xml` file. 98 | 99 | ## License 100 | 101 | Techsenger StagePro is licensed under the Apache License, Version 2.0. 102 | 103 | ## Contributing 104 | 105 | We welcome all contributions. You can help by reporting bugs, suggesting improvements, or submitting pull requests 106 | with fixes and new features. If you have any questions, feel free to reach out — we’ll be happy to assist you. 107 | 108 | ## Support Us 109 | 110 | You can support our open-source work through [GitHub Sponsors](https://github.com/sponsors/techsenger). 111 | Your contribution helps us maintain projects, develop new features, and provide ongoing improvements. 112 | Multiple sponsorship tiers are available, each offering different levels of recognition and benefits. 113 | 114 | -------------------------------------------------------------------------------- /stagepro-core/src/main/java/com/techsenger/stagepro/core/StandardStageController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.stagepro.core; 18 | 19 | import com.techsenger.toolkit.fx.Spacer; 20 | import javafx.collections.ListChangeListener; 21 | import javafx.scene.Node; 22 | import javafx.scene.control.Button; 23 | import javafx.scene.input.MouseEvent; 24 | import javafx.scene.layout.Region; 25 | import javafx.stage.Stage; 26 | 27 | /** 28 | * 29 | * @author Pavel Castornii 30 | */ 31 | public class StandardStageController extends SimpleStageController { 32 | 33 | private final Button minimizeButton = new Button(null, new Region()); 34 | 35 | private final MaximizeButton maximizeButton = 36 | new MaximizeButton(MaximizeButton.ResizableStatePolicy.VISIBILITY, null, new Region()); 37 | 38 | private boolean buttonBoxListenerEnabled = true; 39 | 40 | public StandardStageController(Stage stage, double width, double height) { 41 | this(stage, width, height, true); 42 | } 43 | 44 | public StandardStageController(Stage stage, double width, double height, boolean initTitleBar) { 45 | super(stage, width, height, false); 46 | build(); 47 | addListeners(); 48 | addHandlers(); 49 | if (initTitleBar) { 50 | getButtonBox().getChildren().addAll(minimizeButton, maximizeButton, getCloseButton()); 51 | getTitleBar().getChildren().addAll(getIconView(), getTitleLabel(), new Spacer(), getButtonBox()); 52 | } 53 | } 54 | 55 | public Button getMinimizeButton() { 56 | return minimizeButton; 57 | } 58 | 59 | public MaximizeButton getMaximizeButton() { 60 | return maximizeButton; 61 | } 62 | 63 | private void build() { 64 | this.minimizeButton.getStyleClass().add("minimize-button"); 65 | this.minimizeButton.getGraphic().getStyleClass().add("icon"); 66 | maximizeButton.getGraphic().getStyleClass().add("icon"); 67 | } 68 | 69 | private void addListeners() { 70 | getButtonBox().getChildren().addListener((ListChangeListener) (e) -> { 71 | if (this.buttonBoxListenerEnabled) { 72 | this.maximizeButton.setIndex(getButtonBox().getChildren().indexOf(this.maximizeButton)); 73 | applyMaximizeButtonPolicy(); 74 | } 75 | }); 76 | getStage().resizableProperty().addListener((ov, oldV, newV) -> applyMaximizeButtonPolicy()); 77 | this.maximizeButton.policyProperty().addListener((ov, oldV, newV) -> applyMaximizeButtonPolicy()); 78 | } 79 | 80 | private void addHandlers() { 81 | minimizeButton.setOnAction(e -> getStage().setIconified(true)); 82 | maximizeButton.setOnAction(e -> getStage().setMaximized(!getStage().isMaximized())); 83 | getTitleBar().addEventFilter(MouseEvent.MOUSE_CLICKED, e -> { 84 | if (e.getClickCount() == 2) { 85 | getStage().setMaximized(!getStage().isMaximized()); 86 | e.consume(); 87 | } 88 | }); 89 | } 90 | 91 | private void applyMaximizeButtonPolicy() { 92 | if (this.maximizeButton.getIndex() == -1) { 93 | return; 94 | } 95 | if (maximizeButton.getPolicy() == MaximizeButton.ResizableStatePolicy.INTERACTIVITY) { 96 | maximizeButton.setDisable(!getStage().isResizable()); 97 | //always visible 98 | if (this.getMaximizeButton().getParent() != getButtonBox()) { 99 | getButtonBox().getChildren().add(maximizeButton.getIndex(), maximizeButton); 100 | } 101 | } else { 102 | //always not disable 103 | maximizeButton.setDisable(false); 104 | this.buttonBoxListenerEnabled = false; 105 | if (getStage().isResizable()) { 106 | if (this.getMaximizeButton().getParent() != getButtonBox()) { 107 | getButtonBox().getChildren().add(maximizeButton.getIndex(), maximizeButton); 108 | } 109 | } else { 110 | if (this.getMaximizeButton().getParent() == getButtonBox()) { 111 | getButtonBox().getChildren().remove(maximizeButton.getIndex()); 112 | } 113 | } 114 | this.buttonBoxListenerEnabled = true; 115 | } 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /stagepro-core/src/main/java/com/techsenger/stagepro/core/BaseStageController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.stagepro.core; 18 | 19 | import com.techsenger.toolkit.fx.StageResizer; 20 | import javafx.beans.binding.Bindings; 21 | import javafx.beans.property.ObjectProperty; 22 | import javafx.beans.property.SimpleObjectProperty; 23 | import javafx.css.PseudoClass; 24 | import javafx.scene.Node; 25 | import javafx.scene.Scene; 26 | import javafx.scene.control.Label; 27 | import javafx.scene.input.MouseEvent; 28 | import javafx.scene.layout.HBox; 29 | import javafx.scene.layout.Priority; 30 | import javafx.scene.layout.StackPane; 31 | import javafx.scene.layout.VBox; 32 | import javafx.scene.paint.Color; 33 | import javafx.stage.Stage; 34 | import javafx.stage.StageStyle; 35 | 36 | /** 37 | * Base stage controller: no title icon, label and buttons. Use this controller for creating non standard stages. 38 | * 39 | * @author Pavel Castornii 40 | */ 41 | public class BaseStageController { 42 | 43 | private static final PseudoClass MAXIMIZED_PSEUDO_CLASS = PseudoClass.getPseudoClass("maximized"); 44 | 45 | private final Stage stage; 46 | 47 | private final double width; 48 | 49 | private final double height; 50 | 51 | private final HBox titleBar = new HBox(); 52 | 53 | private final HBox buttonBox = new HBox(); 54 | 55 | private final VBox contentArea = new VBox(); 56 | 57 | private final VBox stageBox = new VBox(titleBar, contentArea); 58 | 59 | private final ObjectProperty content = new SimpleObjectProperty<>(); 60 | 61 | private double pressedX; 62 | 63 | private double pressedY; 64 | 65 | private double pressedMouseX; 66 | 67 | private double pressedMouseY; 68 | 69 | private StageResizer resizer; 70 | 71 | /** 72 | * Calling {@link Stage#initStyle(javafx.stage.StageStyle)} on a visible stage will throw an 73 | * {@link java.lang.IllegalStateException}: "Cannot set style once stage has been made visible." 74 | * 75 | *

Additionally, to remove a StagePro stage, it is necessary to call {@link Stage#hide()}. 76 | * For this reason, adding a deinitialize method for the controller is unnecessary. If you need 77 | * to remove this controller and use a standard JavaFX stage, simply create a new stage instance. 78 | */ 79 | public BaseStageController(Stage stage, double width, double height) { 80 | this.stage = stage; 81 | this.width = width; 82 | this.height = height; 83 | build(); 84 | bind(); 85 | addListeners(); 86 | addHandlers(); 87 | } 88 | 89 | public ObjectProperty contentProperty() { 90 | return content; 91 | } 92 | 93 | public Node getContent() { 94 | return this.content.get(); 95 | } 96 | 97 | public void setContent(Node content) { 98 | this.content.set(content); 99 | } 100 | 101 | public HBox getTitleBar() { 102 | return this.titleBar; 103 | } 104 | 105 | public HBox getButtonBox() { 106 | return buttonBox; 107 | } 108 | 109 | public Stage getStage() { 110 | return stage; 111 | } 112 | 113 | protected StageResizer getResizer() { 114 | return resizer; 115 | } 116 | 117 | /** 118 | * Returns the stage box that is the root of the scene. 119 | * 120 | * @return 121 | */ 122 | protected VBox getStageBox() { 123 | return stageBox; 124 | } 125 | 126 | private void build() { 127 | //with StageStyle.UNDECORATED resizing works slowly, besides with UNDECORATED style background bahind radius 128 | //corners will be visible 129 | this.stage.initStyle(StageStyle.TRANSPARENT); 130 | this.stage.setWidth(width); 131 | this.stage.setHeight(height); 132 | var scene = new Scene(this.stageBox); 133 | scene.setFill(Color.TRANSPARENT); 134 | stage.setScene(scene); 135 | this.resizer = new StageResizer(this.stage.minWidthProperty(), this.stage.minHeightProperty(), 136 | this.stage.maxWidthProperty(), this.stage.maxHeightProperty(), (e) -> onResizingStarted(e), 137 | (e) -> onResizingFinished(e)); 138 | this.resizer.initialize(stage); 139 | VBox.setVgrow(stageBox, Priority.ALWAYS); 140 | //there are different stylesheet priorities for scene and node 141 | scene.getStylesheets().add(BaseStageController.class.getResource("stage.css").toExternalForm()); 142 | this.stageBox.getStyleClass().add("stage-box"); 143 | VBox.setVgrow(this.contentArea, Priority.ALWAYS); 144 | this.contentArea.getStyleClass().add("content-area"); 145 | this.titleBar.getStyleClass().add("title-bar"); 146 | this.buttonBox.getStyleClass().add("button-box"); 147 | checkMaximizedPseudoClass(getStage().maximizedProperty().get()); 148 | setEmptyContent(); 149 | } 150 | 151 | private void bind() { 152 | this.resizer.disabledProperty() 153 | .bind(this.stage.maximizedProperty().or(Bindings.not(this.stage.resizableProperty()))); 154 | } 155 | 156 | private void addListeners() { 157 | this.content.addListener((ov, oldValue, newV) -> { 158 | if (newV != null) { 159 | setNewContent(newV); 160 | } else { 161 | setEmptyContent(); 162 | } 163 | }); 164 | this.stage.maximizedProperty().addListener((ov, oldV, newV) -> checkMaximizedPseudoClass(newV)); 165 | } 166 | 167 | private void addHandlers() { 168 | this.titleBar.setOnMousePressed((event) -> this.doOnTitleBarMousePressed(event)); 169 | this.titleBar.setOnMouseDragged((event) -> this.doOnTitleBarMouseDragged(event)); 170 | } 171 | 172 | private void doOnTitleBarMousePressed(MouseEvent event) { 173 | this.pressedMouseX = event.getScreenX(); 174 | this.pressedMouseY = event.getScreenY(); 175 | this.pressedX = this.stage.getX(); 176 | this.pressedY = this.stage.getY(); 177 | event.consume(); 178 | } 179 | 180 | private void doOnTitleBarMouseDragged(MouseEvent event) { 181 | var mouseXDiff = event.getScreenX() - this.pressedMouseX; 182 | var mouseYDiff = event.getScreenY() - this.pressedMouseY; 183 | var newX = this.pressedX + mouseXDiff; 184 | var newY = this.pressedY + mouseYDiff; 185 | //it seems that javafx checks valid positions itself 186 | this.stage.setX(newX); 187 | this.stage.setY(newY); 188 | event.consume(); 189 | } 190 | 191 | private void setNewContent(Node content) { 192 | this.contentArea.getChildren().clear(); 193 | if (content != null) { 194 | VBox.setVgrow(content, Priority.ALWAYS); 195 | this.contentArea.getChildren().add(content); 196 | } else { 197 | setEmptyContent(); 198 | } 199 | } 200 | 201 | private void setEmptyContent() { 202 | var label = new Label("No Content"); 203 | var node = new StackPane(label); 204 | setNewContent(node); 205 | } 206 | 207 | private void onResizingStarted(MouseEvent mouseEvent) { 208 | var event = new StageResizeEvent(StageResizeEvent.STAGE_RESIZE_STARTED, mouseEvent); 209 | this.stage.fireEvent(event); 210 | } 211 | 212 | private void onResizingFinished(MouseEvent mouseEvent) { 213 | var event = new StageResizeEvent(StageResizeEvent.STAGE_RESIZE_FINISHED, mouseEvent); 214 | this.stage.fireEvent(event); 215 | } 216 | 217 | private void checkMaximizedPseudoClass(boolean maximized) { 218 | this.stageBox.pseudoClassStateChanged(MAXIMIZED_PSEUDO_CLASS, maximized); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /stagepro-sampler/src/main/java/com/techsenger/stagepro/sampler/Sampler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024-2025 Pavel Castornii. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.techsenger.stagepro.sampler; 18 | 19 | import com.techsenger.stagepro.core.BaseStageController; 20 | import com.techsenger.stagepro.core.MaximizeButton.ResizableStatePolicy; 21 | import com.techsenger.stagepro.core.SimpleStageController; 22 | import com.techsenger.stagepro.core.StageResizeEvent; 23 | import com.techsenger.stagepro.core.StandardStageController; 24 | import com.techsenger.toolkit.fx.Spacer; 25 | import java.util.List; 26 | import javafx.application.Application; 27 | import javafx.beans.property.ReadOnlyObjectWrapper; 28 | import javafx.beans.property.ReadOnlyStringWrapper; 29 | import javafx.collections.FXCollections; 30 | import javafx.collections.ObservableList; 31 | import javafx.event.EventHandler; 32 | import javafx.geometry.Insets; 33 | import javafx.scene.Scene; 34 | import javafx.scene.control.Button; 35 | import javafx.scene.control.CheckBox; 36 | import javafx.scene.control.ComboBox; 37 | import javafx.scene.control.Label; 38 | import javafx.scene.control.Menu; 39 | import javafx.scene.control.MenuBar; 40 | import javafx.scene.control.TableCell; 41 | import javafx.scene.control.TableColumn; 42 | import javafx.scene.control.TableView; 43 | import javafx.scene.layout.BorderPane; 44 | import javafx.scene.layout.GridPane; 45 | import javafx.scene.layout.Priority; 46 | import javafx.scene.layout.Region; 47 | import javafx.scene.layout.VBox; 48 | import javafx.stage.Stage; 49 | 50 | /** 51 | * 52 | * @author Pavel Castornii 53 | */ 54 | public class Sampler extends Application { 55 | 56 | private static final double SAMPLE_STAGE_WIDTH = 600; 57 | 58 | private static final double SAMPLE_STAGE_HEIGHT = 400; 59 | 60 | public static void main(String[] args) { 61 | launch(args); 62 | } 63 | 64 | @Override 65 | public void start(Stage primaryStage) { 66 | ObservableList samples = FXCollections.observableArrayList(createSamples()); 67 | TableView tableView = new TableView<>(); 68 | tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); 69 | tableView.setItems(samples); 70 | 71 | TableColumn idColumn = new TableColumn<>("Id"); 72 | idColumn.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getId())); 73 | idColumn.setMaxWidth(50); 74 | idColumn.setMinWidth(50); 75 | idColumn.setResizable(false); 76 | 77 | TableColumn controllerColumn = new TableColumn<>("Controller"); 78 | controllerColumn.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getController())); 79 | controllerColumn.setMaxWidth(250); 80 | controllerColumn.setMinWidth(250); 81 | controllerColumn.setResizable(false); 82 | 83 | TableColumn descriptionColumn = new TableColumn<>("Description"); 84 | descriptionColumn.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getDescription())); 85 | 86 | TableColumn actionColumn = new TableColumn<>("Action"); 87 | actionColumn.getStyleClass().add("action"); 88 | actionColumn.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getAction())); 89 | actionColumn.setMaxWidth(100); 90 | actionColumn.setMinWidth(100); 91 | actionColumn.setResizable(false); 92 | actionColumn.setCellFactory(column -> { 93 | TableCell cell = new TableCell<>() { 94 | 95 | private final Button button = new Button("Run"); 96 | 97 | { 98 | button.setOnAction(event -> { 99 | Sample sample = getTableRow().getItem(); 100 | if (sample != null) { 101 | sample.getAction().run(); 102 | } 103 | }); 104 | button.setPadding(new Insets(3, 6, 3, 6)); 105 | setPadding(new Insets(2)); 106 | } 107 | 108 | @Override 109 | protected void updateItem(Runnable sample, boolean empty) { 110 | super.updateItem(sample, empty); 111 | if (sample == null || empty) { 112 | setGraphic(null); 113 | } else { 114 | setGraphic(button); 115 | } 116 | } 117 | }; 118 | return cell; 119 | }); 120 | 121 | tableView.getColumns().addAll(idColumn, controllerColumn, descriptionColumn, actionColumn); 122 | 123 | VBox root = new VBox(tableView); 124 | VBox.setVgrow(tableView, Priority.ALWAYS); 125 | Scene scene = new Scene(root, 1000, 400); 126 | scene.getStylesheets().add(Sampler.class.getResource("sampler.css").toExternalForm()); 127 | primaryStage.setScene(scene); 128 | primaryStage.setTitle("StagePro Sampler"); 129 | primaryStage.show(); 130 | } 131 | 132 | private List createSamples() { 133 | return List.of( 134 | createSample1(), 135 | createSample2(), 136 | createSample3(), 137 | createSample4(), 138 | createSample5() 139 | ); 140 | } 141 | 142 | private Sample createSample1() { 143 | return new Sample(1, BaseStageController.class.getSimpleName(), "Empty title bar", () -> { 144 | var stage = new Stage(); 145 | var controller = new BaseStageController(stage, SAMPLE_STAGE_WIDTH, SAMPLE_STAGE_HEIGHT); 146 | setStylesheet(controller); 147 | setContent(controller); 148 | stage.show(); 149 | }); 150 | } 151 | 152 | private Sample createSample2() { 153 | return new Sample(2, SimpleStageController.class.getSimpleName(), 154 | "Icon and text on the left, close button on the right", () -> { 155 | var stage = new Stage(); 156 | var controller = new SimpleStageController(stage, SAMPLE_STAGE_WIDTH, SAMPLE_STAGE_HEIGHT); 157 | setTitle(controller); 158 | setStylesheet(controller); 159 | setContent(controller); 160 | stage.show(); 161 | }); 162 | } 163 | 164 | private Sample createSample3() { 165 | return new Sample(3, StandardStageController.class.getSimpleName(), 166 | "Icon and text on the left, three buttons on the right", () -> { 167 | var stage = new Stage(); 168 | var controller = new StandardStageController(stage, SAMPLE_STAGE_WIDTH, SAMPLE_STAGE_HEIGHT); 169 | setTitle(controller); 170 | setStylesheet(controller); 171 | setContent(controller); 172 | stage.show(); 173 | }); 174 | } 175 | 176 | private Sample createSample4() { 177 | class LeftStandardStageController extends StandardStageController { 178 | 179 | LeftStandardStageController(Stage stage, double width, double height) { 180 | super(stage, width, height, false); 181 | getButtonBox().getChildren().addAll(getCloseButton(), getMinimizeButton(), getMaximizeButton()); 182 | getTitleBar().getChildren().addAll(getButtonBox(), new Spacer(10.0), getTitleLabel(), 183 | new Spacer()); 184 | } 185 | } 186 | return new Sample(4, LeftStandardStageController.class.getSimpleName(), 187 | "Three buttons, text on the left", () -> { 188 | var stage = new Stage(); 189 | var controller = new LeftStandardStageController(stage, SAMPLE_STAGE_WIDTH, SAMPLE_STAGE_HEIGHT); 190 | setTitle(controller); 191 | setStylesheet(controller); 192 | setContent(controller); 193 | stage.show(); 194 | }); 195 | } 196 | 197 | private Sample createSample5() { 198 | return new Sample(5, StandardStageController.class.getSimpleName(), 199 | "Icon and menu on the left, three buttons on the right", () -> { 200 | var stage = new Stage(); 201 | class LeftStandardStageController extends StandardStageController { 202 | 203 | private final Menu fileMenu = new Menu("_File"); 204 | 205 | private final Menu editMenu = new Menu("_Edit"); 206 | 207 | private final Menu helptMenu = new Menu("_Help"); 208 | 209 | private final MenuBar menuBar = new MenuBar(fileMenu, editMenu, helptMenu); 210 | 211 | LeftStandardStageController(Stage stage, double width, double height) { 212 | super(stage, width, height, false); 213 | getButtonBox().getChildren().addAll(getMinimizeButton(), getMaximizeButton(), getCloseButton()); 214 | getTitleBar().getChildren().addAll(getIconView(), menuBar, new Spacer(), getButtonBox()); 215 | } 216 | } 217 | var controller = new LeftStandardStageController(stage, SAMPLE_STAGE_WIDTH, SAMPLE_STAGE_HEIGHT); 218 | setTitle(controller); 219 | setStylesheet(controller); 220 | setContent(controller); 221 | stage.show(); 222 | }); 223 | } 224 | 225 | private void setTitle(SimpleStageController controller) { 226 | controller.getTitleLabel().setText("Title"); 227 | 228 | } 229 | 230 | private void setStylesheet(BaseStageController controller) { 231 | controller.getStage().getScene().getStylesheets().add(Sampler.class.getResource("sample.css").toExternalForm()); 232 | } 233 | 234 | private void setContent(BaseStageController controller) { 235 | var stage = controller.getStage(); 236 | var gridPane = new GridPane(); 237 | gridPane.setHgap(10); 238 | gridPane.setVgap(10); 239 | gridPane.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE); 240 | 241 | var rowIndex = 0; 242 | if (controller.getClass() == BaseStageController.class) { 243 | var button = new Button("Close"); 244 | button.setMaxWidth(Double.MAX_VALUE); 245 | button.setOnAction(e -> stage.close()); 246 | GridPane.setHgrow(button, Priority.ALWAYS); 247 | GridPane.setColumnSpan(button, 2); 248 | gridPane.add(button, 0, rowIndex); 249 | rowIndex++; 250 | } 251 | if (controller instanceof StandardStageController) { 252 | gridPane.add(new Label("Max Button Policy"), 0, rowIndex); 253 | var polcies = FXCollections.observableArrayList(ResizableStatePolicy.VISIBILITY, 254 | ResizableStatePolicy.INTERACTIVITY); 255 | var policyComboBox = new ComboBox(polcies); 256 | var maxButton = ((StandardStageController) controller).getMaximizeButton(); 257 | policyComboBox.valueProperty().bindBidirectional(maxButton.policyProperty()); 258 | gridPane.add(policyComboBox, 1, rowIndex); 259 | rowIndex++; 260 | } 261 | 262 | var resizableCheckBox = new CheckBox("Resizable"); 263 | resizableCheckBox.selectedProperty().bindBidirectional(stage.resizableProperty()); 264 | gridPane.add(resizableCheckBox, 0, rowIndex); 265 | var darkThemeCheckBox = new CheckBox("Dark Theme"); 266 | darkThemeCheckBox.selectedProperty().addListener((ov, oldV, newV) -> { 267 | if (newV) { 268 | controller.getStage().getScene().getRoot().getStyleClass().add("dark"); 269 | } else { 270 | controller.getStage().getScene().getRoot().getStyleClass().remove("dark"); 271 | } 272 | }); 273 | gridPane.add(darkThemeCheckBox, 1, rowIndex); 274 | 275 | rowIndex++; 276 | EventHandler started = e -> System.out.println("Resize started"); 277 | EventHandler finished = e -> System.out.println("Resize finished"); 278 | var resizeHandlersCheckBox = new CheckBox("Resize Handlers"); 279 | resizeHandlersCheckBox.selectedProperty().addListener((ov, oldV, newV) -> { 280 | if (newV) { 281 | stage.addEventHandler(StageResizeEvent.STAGE_RESIZE_STARTED, started); 282 | stage.addEventHandler(StageResizeEvent.STAGE_RESIZE_FINISHED, finished); 283 | } else { 284 | stage.removeEventHandler(StageResizeEvent.STAGE_RESIZE_STARTED, started); 285 | stage.removeEventHandler(StageResizeEvent.STAGE_RESIZE_FINISHED, finished); 286 | } 287 | }); 288 | gridPane.add(resizeHandlersCheckBox, 0, rowIndex); 289 | 290 | var content = new BorderPane(); 291 | content.setCenter(gridPane); 292 | controller.setContent(content); 293 | } 294 | 295 | } 296 | --------------------------------------------------------------------------------