Skip to content

Commit 9377449

Browse files
committed
Make explorer and settings windows resizeble
1 parent 39e51d1 commit 9377449

File tree

7 files changed

+90
-30
lines changed

7 files changed

+90
-30
lines changed

src/main/java/com/github/introfog/gitwave/controller/ExecuteController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected void saveCommand() {
133133
protected void runCommand() {
134134
final String pathToGitBashExe = AppConfig.getInstance().getPathToGitBashExe();
135135
if (pathToGitBashExe == null || pathToGitBashExe.isEmpty()) {
136-
StageFactory.createModalStage("view/settings.fxml", "Settings").getStage().showAndWait();
136+
StageFactory.createModalSettingsWindow().getStage().showAndWait();
137137
} else if (!(new File(pathToGitBashExe)).exists()) {
138138
LOGGER.error("Specified GitBash.exe path '{}' points to not-existent file, running git command was skipped.", pathToGitBashExe);
139139
DialogFactory.createErrorAlert("Invalid path to GitBash.exe", "Specified path \"" + pathToGitBashExe +
@@ -160,12 +160,12 @@ protected void runCommand() {
160160

161161
@FXML
162162
protected void openSettings() {
163-
StageFactory.createModalStage("view/settings.fxml", "Settings").getStage().showAndWait();
163+
StageFactory.createModalSettingsWindow().getStage().showAndWait();
164164
}
165165

166166
@FXML
167167
protected void openAbout() {
168-
StageFactory.createModalStage("view/about.fxml", "About").getStage().showAndWait();
168+
StageFactory.createModalAboutWindow().getStage().showAndWait();
169169
}
170170

171171
@FXML

src/main/java/com/github/introfog/gitwave/controller/ExploreController.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,22 @@
3232
import javafx.scene.control.cell.TextFieldTableCell;
3333
import javafx.scene.input.KeyCode;
3434
import javafx.scene.input.MouseEvent;
35+
import javafx.scene.layout.AnchorPane;
3536

3637
public class ExploreController extends BaseController {
3738
@FXML
3839
private TableView<CommandDto> commandsTable;
3940

4041
@FXML
41-
protected Button addNew;
42+
private AnchorPane anchor;
4243

4344
private ExecuteController executeController;
4445

4546
@Override
4647
public void initialize(FxmlStageHolder fxmlStageHolder) {
4748
super.initialize(fxmlStageHolder);
4849
super.setClosingOnEscapePressing(fxmlStageHolder);
49-
fillTable();
50+
setUpAndFillTable();
5051
commandsTable.setOnKeyPressed(event -> {
5152
if (event.getCode() == KeyCode.ESCAPE) {
5253
fxmlStageHolder.getStage().close();
@@ -69,11 +70,6 @@ void setExecuteController(ExecuteController executeController) {
6970
this.executeController = executeController;
7071
}
7172

72-
void addNewCommand(CommandDto commandDto) {
73-
AppConfig.getInstance().addCommand(commandDto);
74-
commandsTable.getItems().add(commandDto);
75-
}
76-
7773
private void removeCommand(CommandDto item) {
7874
if (item == null) {
7975
return;
@@ -83,7 +79,7 @@ private void removeCommand(CommandDto item) {
8379
AppConfig.getInstance().removeCommand(item);
8480
}
8581

86-
private void fillTable() {
82+
private void setUpAndFillTable() {
8783
List<CommandDto> commandsDtoList = AppConfig.getInstance().getCommands();
8884
ObservableList<CommandDto> itemList = FXCollections.observableArrayList(commandsDtoList);
8985
commandsTable.setItems(itemList);
@@ -99,6 +95,14 @@ private void fillTable() {
9995
TableColumn<CommandDto, String> removeTableColumn = (TableColumn<CommandDto, String>) commandsTable.getColumns().get(2);
10096
removeTableColumn.setCellValueFactory(new PropertyValueFactory<>("description"));
10197
removeTableColumn.setCellFactory(column -> new RemoveTableCell(this));
98+
99+
100+
anchor.widthProperty().addListener((obs, oldVal, newVal) -> {
101+
double width = (newVal.doubleValue() - removeTableColumn.getWidth() - 4) * 0.5;
102+
// TODO there is a bug that when user change column width manually, and after that resize window, it automatically reset user changes
103+
commandTableColumn.setPrefWidth(width);
104+
descriptionTableColumn.setPrefWidth(width);
105+
});
102106
}
103107

104108
private static class RemoveTableCell extends TableCell<CommandDto, String> {

src/main/java/com/github/introfog/gitwave/controller/UpdateController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class UpdateController extends BaseController {
3131

3232
@FXML
3333
private TextField command;
34-
// TODO what if define long command or description? Set some limit.
34+
3535
@FXML
3636
private TextField description;
3737

src/main/java/com/github/introfog/gitwave/model/CommandExecutor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public static void searchGitReposAndExecuteCommand(String folderPath, String com
5555
}
5656
}
5757
} else {
58-
// TODO all logs must be stored in one static class as constants
5958
LOGGER.error("Specified folder either doesn't exist or isn't a directory, running git command was skipped.");
6059
}
6160
}

src/main/java/com/github/introfog/gitwave/model/StageFactory.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,26 @@ private StageFactory() {
3737

3838
public static FxmlStageHolder createModalExploreWindow() {
3939
FxmlStageHolder holder = StageFactory.createModalStage("view/explorer.fxml", "Command explorer");
40+
holder.getStage().setMinWidth(400);
41+
holder.getStage().setMinHeight(200);
42+
holder.getStage().setResizable(true);
43+
return holder;
44+
}
45+
46+
public static FxmlStageHolder createModalSettingsWindow() {
47+
FxmlStageHolder holder = StageFactory.createModalStage("view/settings.fxml", "Settings");
48+
holder.getStage().setMinWidth(500);
49+
holder.getStage().setMinHeight(240);
4050
holder.getStage().setResizable(true);
4151
return holder;
4252
}
4353

54+
public static FxmlStageHolder createModalAboutWindow() {
55+
FxmlStageHolder holder = StageFactory.createModalStage("view/about.fxml", "About");
56+
holder.getStage().setResizable(false);
57+
return holder;
58+
}
59+
4460
public static FxmlStageHolder createModalStage(String fxmlPath, String title) {
4561
Stage modalStage = new Stage();
4662
modalStage.initModality(Modality.APPLICATION_MODAL);

src/main/resources/com/github/introfog/gitwave/view/explorer.fxml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<?import javafx.scene.control.TableColumn?>
44
<?import javafx.scene.control.TableView?>
55
<?import javafx.scene.layout.AnchorPane?>
6-
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="275.0" prefWidth="600.0" style="-fx-font-family: verdana; -fx-font-size: 12;" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.introfog.gitwave.controller.ExploreController">
6+
<AnchorPane fx:id="anchor" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="275.0" prefWidth="600.0" style="-fx-font-family: verdana; -fx-font-size: 12;" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.introfog.gitwave.controller.ExploreController">
77
<children>
88
<TableView fx:id="commandsTable" onMouseClicked="#mouseClick" prefHeight="223.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
99
<columns>
10-
<TableColumn minWidth="283.0" prefWidth="-1.0" text="Command" />
11-
<TableColumn minWidth="283.0" prefWidth="-1.0" text="Description" />
12-
<TableColumn maxWidth="30.0" minWidth="30.0" prefWidth="30.0" resizable="false" />
10+
<TableColumn minWidth="100.0" prefWidth="-1.0" text="Command" />
11+
<TableColumn minWidth="100.0" prefWidth="-1.0" text="Description" />
12+
<TableColumn editable="false" maxWidth="30.0" minWidth="30.0" prefWidth="30.0" resizable="false" sortable="false" />
1313
</columns>
1414
</TableView>
1515
</children>
Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,65 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3+
<?import javafx.geometry.Insets?>
34
<?import javafx.scene.control.Button?>
45
<?import javafx.scene.control.Label?>
56
<?import javafx.scene.control.Separator?>
67
<?import javafx.scene.control.TextField?>
78
<?import javafx.scene.layout.AnchorPane?>
9+
<?import javafx.scene.layout.ColumnConstraints?>
10+
<?import javafx.scene.layout.GridPane?>
11+
<?import javafx.scene.layout.RowConstraints?>
812
<?import javafx.scene.text.Font?>
9-
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="181.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.introfog.gitwave.controller.SettingsController">
13+
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="550.0" style="-fx-font-family: verdana; -fx-font-size: 12;" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.introfog.gitwave.controller.SettingsController">
1014
<children>
11-
<Label layoutX="14.0" layoutY="20.0" prefHeight="17.0" prefWidth="409.0" text="Path to bash.exe on your PC (usually &quot;PATH_TO_GIT/bin/bash.exe&quot;)." />
12-
<TextField fx:id="pathToBashExe" layoutX="14.0" layoutY="46.0" prefHeight="25.0" prefWidth="409.0" />
13-
<Button layoutX="431.0" layoutY="46.0" mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" />
14-
<Button fx:id="save" layoutX="245.0" layoutY="142.0" mnemonicParsing="false" onAction="#save" text="Save" />
15-
<Label layoutX="14.0" layoutY="97.0" text="Remove all logs from &quot;logs&quot; folder" />
16-
<Button layoutX="219.0" layoutY="93.0" mnemonicParsing="false" onAction="#cleanLogs" text="Clean" />
17-
<Separator layoutX="14.0" layoutY="80.0" prefWidth="472.0" />
18-
<Separator layoutX="14.0" layoutY="130.0" prefWidth="472.0" />
19-
<Label fx:id="done" layoutX="280.0" layoutY="97.0" text="Done!" textFill="#34cd4b">
20-
<font>
21-
<Font name="System Bold" size="12.0" />
22-
</font></Label>
15+
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
16+
<columnConstraints>
17+
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
18+
</columnConstraints>
19+
<rowConstraints>
20+
<RowConstraints maxHeight="70.0" minHeight="70.0" prefHeight="70.0" vgrow="NEVER" />
21+
<RowConstraints maxHeight="55.0" minHeight="55.0" prefHeight="55.0" vgrow="SOMETIMES" />
22+
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="0.0" prefHeight="0.0" vgrow="ALWAYS" />
23+
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="NEVER" />
24+
</rowConstraints>
25+
<children>
26+
<AnchorPane prefHeight="200.0" prefWidth="200.0">
27+
<children>
28+
<Label prefHeight="17.0" prefWidth="430.0" text="Path to bash.exe on your PC (usually &quot;PATH_TO_GIT/bin/bash.exe&quot;)." AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
29+
<Button mnemonicParsing="false" onAction="#browseGitBashExe" text="Browse" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="30.0">
30+
<font>
31+
<Font name="Verdana" size="12.0" />
32+
</font>
33+
</Button>
34+
<Separator prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
35+
<TextField fx:id="pathToBashExe" prefHeight="25.0" prefWidth="426.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="80.0" AnchorPane.topAnchor="30.0" />
36+
</children>
37+
</AnchorPane>
38+
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
39+
<children>
40+
<Label text="Remove all logs from &quot;logs&quot; folder" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="20.0" />
41+
<Button mnemonicParsing="false" onAction="#cleanLogs" text="Clean" AnchorPane.leftAnchor="215.0" AnchorPane.topAnchor="16.0" />
42+
<Label fx:id="done" text="Done!" textFill="#34cd4b" AnchorPane.leftAnchor="280.0" AnchorPane.topAnchor="20.0">
43+
<font>
44+
<Font name="Verdana Bold" size="12.0" />
45+
</font>
46+
</Label>
47+
<Separator prefWidth="472.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
48+
</children>
49+
</AnchorPane>
50+
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="3">
51+
<children>
52+
<Button fx:id="save" mnemonicParsing="false" onAction="#save" text="Save" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
53+
<font>
54+
<Font name="Verdana" size="12.0" />
55+
</font>
56+
</Button>
57+
</children>
58+
</AnchorPane>
59+
</children>
60+
</GridPane>
2361
</children>
62+
<padding>
63+
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
64+
</padding>
2465
</AnchorPane>

0 commit comments

Comments
 (0)