Skip to content

Commit f4a0b09

Browse files
committed
PTBAS-738: Improve styling
1 parent 6d6431e commit f4a0b09

File tree

3 files changed

+62
-30
lines changed

3 files changed

+62
-30
lines changed

src/main/java/de/doubleslash/keeptime/view/ExternalProjectsSyncController.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ protected void updateItem(List<Project> item, boolean empty) {
290290
vbox.getChildren().add(row);
291291

292292
// Set tooltip for the label
293-
Label label = (Label) row.getChildren().get(1); // Assuming label is second in HBox
293+
Label label = (Label) row.getChildren().get(1);
294294
Tooltip tooltip = new Tooltip(label.getText());
295295
label.setTooltip(tooltip);
296296
}
@@ -302,8 +302,8 @@ private HBox createRow(Color color, String text) {
302302
Circle circle = new Circle(6, color);
303303
Label label = new Label(text);
304304

305-
label.setMaxWidth(Double.MAX_VALUE); // Allow layout to constrain width
306-
HBox.setHgrow(label, Priority.ALWAYS); // Let label grow within HBox
305+
label.setMaxWidth(Double.MAX_VALUE);
306+
HBox.setHgrow(label, Priority.ALWAYS);
307307

308308
return new HBox(5, circle, label);
309309
}
@@ -452,9 +452,14 @@ protected void updateItem(TableRow item, boolean empty) {
452452
.map(n -> ((Text) n).getText())
453453
.collect(Collectors.joining());
454454

455+
456+
455457
if (!item.bookingHint.isEmpty().get()) {
458+
statusFlow = new TextFlow(statusFlow);
456459
tooltip.setText(status + "\n" + item.bookingHint.get());
457-
setStyle("-fx-background-color: #EFEFEF");
460+
Text icon = new Text("ⓘ ");
461+
icon.setStyle("-fx-text-fill: #1c2070; -fx-font-size: 14px;");
462+
statusFlow.getChildren().add(0, icon);
458463
}
459464
else {
460465
tooltip.setText(status);
@@ -463,6 +468,7 @@ protected void updateItem(TableRow item, boolean empty) {
463468
// Fix Cell height not aligning with Textflow
464469
// https://stackoverflow.com/questions/42855724/textflow-inside-tablecell-not-correct-cell-height
465470
statusFlow.maxWidthProperty().bind(column.widthProperty());
471+
466472
setGraphic(new Group(statusFlow));
467473

468474
setTooltip(tooltip);
@@ -721,6 +727,9 @@ public static LocalTime incrementToNextHour(LocalTime time) {
721727
}
722728

723729
public static LocalTime decrementToNextHour(LocalTime time) {
730+
if (time.getHour() == 0)
731+
return LocalTime.MIDNIGHT;
732+
724733
return time.minusHours(1).withMinute(0).withSecond(0).withNano(0);
725734
}
726735

src/main/java/de/doubleslash/keeptime/viewpopup/SearchPopup.java

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import javafx.collections.ListChangeListener;
66
import javafx.collections.ObservableList;
77
import javafx.geometry.Bounds;
8+
import javafx.geometry.Pos;
89
import javafx.scene.Node;
9-
import javafx.scene.control.Button;
10-
import javafx.scene.control.ListCell;
11-
import javafx.scene.control.ListView;
12-
import javafx.scene.control.TextField;
10+
import javafx.scene.control.*;
1311
import javafx.scene.input.KeyCode;
12+
import javafx.scene.layout.HBox;
13+
import javafx.scene.layout.Priority;
14+
import javafx.scene.layout.StackPane;
1415
import javafx.stage.Popup;
1516

1617
import java.util.function.Consumer;
@@ -32,7 +33,6 @@ public class SearchPopup<T> {
3233
public SearchPopup() {
3334
popup.setAutoHide(true);
3435
popup.getContent().add(suggestionList);
35-
suggestionList.setMaxHeight(150);
3636

3737
setupStyle();
3838

@@ -74,8 +74,13 @@ public SearchPopup() {
7474
} else if (ev.getCode() == KeyCode.UP &&
7575
suggestionList.getSelectionModel().getSelectedIndex() == 0) {
7676
searchField.requestFocus();
77+
} else if (ev.getCode() == KeyCode.ESCAPE) {
78+
hide();
79+
searchField.getParent().requestFocus();
7780
}
7881
});
82+
83+
// Mouse events
7984
suggestionList.setOnMouseClicked(ev -> {
8085
T selected = suggestionList.getSelectionModel().getSelectedItem();
8186
if (selected != null) {
@@ -84,14 +89,7 @@ public SearchPopup() {
8489

8590
});
8691

87-
// Custom string for suggestions
88-
suggestionList.setCellFactory(listView -> new ListCell<>() {
89-
@Override
90-
protected void updateItem(T item, boolean empty) {
91-
super.updateItem(item, empty);
92-
setText((empty || item == null) ? null : displayTextFunction.apply(item));
93-
}
94-
});
92+
searchField.setOnMouseClicked(ev -> show(searchField));
9593
}
9694

9795
private void filterList(String input) {
@@ -113,10 +111,42 @@ private void handleSelection(T selected) {
113111
if (selectionHandler != null) selectionHandler.accept(selected);
114112
popup.hide();
115113
searchField.clear();
114+
searchField.setPromptText("Select project…");
115+
searchField.getParent().requestFocus();
116116
}
117117

118118
private void setupStyle() {
119-
searchField.getStyleClass().add("text-field");
119+
HBox.setHgrow(searchField, Priority.ALWAYS);
120+
searchField.setPromptText("Select project…");
121+
searchField.getStyleClass().add("combo-box");
122+
123+
suggestionList.getStyleClass().add("scroll-pane");
124+
suggestionList.setMaxHeight(200);
125+
126+
suggestionList.setCellFactory(listView -> new ListCell<>() {
127+
private final Label label = new Label();
128+
private final StackPane pane = new StackPane(label);
129+
130+
{
131+
label.setWrapText(true);
132+
label.setStyle("-fx-padding: 5;");
133+
pane.setAlignment(Pos.CENTER_LEFT);
134+
pane.setMinWidth(0);
135+
pane.setPrefWidth(1);
136+
}
137+
138+
@Override
139+
protected void updateItem(T item, boolean empty) {
140+
super.updateItem(item, empty);
141+
if (empty || item == null) {
142+
setGraphic(null);
143+
} else {
144+
label.setText(displayTextFunction.apply(item));
145+
setGraphic(pane);
146+
}
147+
}
148+
});
149+
120150
showSuggestionsButton.getStyleClass().add("secondary-button");
121151
}
122152

@@ -152,6 +182,7 @@ public Button getSuggestionsButton() {
152182
public void show(Node owner) {
153183
if (owner == null) return;
154184
Bounds bounds = owner.localToScreen(owner.getBoundsInLocal());
185+
suggestionList.setPrefWidth(searchField.getWidth());
155186
popup.show(owner, bounds.getMinX(), bounds.getMaxY());
156187
}
157188

src/main/resources/layouts/externalProjectSync.fxml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<?import javafx.geometry.*?>
43
<?import javafx.scene.control.*?>
54
<?import javafx.scene.layout.*?>
65
<?import javafx.scene.text.*?>
@@ -43,24 +42,17 @@
4342
</HBox>
4443
</children>
4544
</HBox>
46-
<VBox spacing="15.0" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="5.0">
45+
<HBox alignment="CENTER" layoutX="489.0" layoutY="531.0" prefHeight="69.0" prefWidth="511.0" spacing="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
4746
<children>
48-
<HBox spacing="5.0">
49-
<children>
50-
<HBox fx:id="heimatTaskSearchContainer" alignment="CENTER" nodeOrientation="LEFT_TO_RIGHT" prefHeight="30.0" prefWidth="200.0">
51-
<HBox.margin>
52-
<Insets />
53-
</HBox.margin></HBox>
54-
</children>
55-
</HBox>
56-
<HBox alignment="TOP_RIGHT" spacing="5.0">
47+
<HBox fx:id="heimatTaskSearchContainer" alignment="CENTER" prefHeight="69.0" prefWidth="376.0" />
48+
<HBox alignment="CENTER" prefHeight="54.0" prefWidth="102.0" spacing="5.0">
5749
<children>
5850
<Button fx:id="saveButton" mnemonicParsing="false" styleClass="primary-button" text="Sync" />
5951
<Button fx:id="cancelButton" mnemonicParsing="false" styleClass="secondary-button" text="Cancel" />
6052
</children>
6153
</HBox>
6254
</children>
63-
</VBox>
55+
</HBox>
6456
</children>
6557
</AnchorPane>
6658
<VBox fx:id="loadingScreen" alignment="CENTER" spacing="10.0" visible="false">

0 commit comments

Comments
 (0)