implement code suggestions

Signed-off-by: Armin Schrenk <armin.schrenk@skymatic.de>
This commit is contained in:
Armin Schrenk
2025-12-05 17:32:24 +01:00
parent b83a3c27c6
commit 5b9e70da33
2 changed files with 42 additions and 5 deletions

View File

@@ -2,20 +2,48 @@ package org.cryptomator.ui.common;
import javafx.stage.Screen;
/**
* Utility class providing methods regarding the OS bar.
*/
public class SystemBarUtil {
public enum Placement {
/**
* OS Bar placed at the left screen edge
*/
LEFT,
/**
* OS Bar placed at the top screen edge
*/
TOP,
/**
* OS Bar placed at the right screen edge
*/
RIGHT,
/**
* OS Bar placed at the bottom screen edge
*/
BOTTOM;
}
/**
* Determines the placement of the OS bar on the given screen.
* <p>
* <b>Assuming the OS bar fills one screen edge completely</b>,
* this method determines that screen edge by comparing the actual screen bounds with the visual ones.
* <p>
* If the screen does not have a system bar, the bottom placement is returned.
* If the screen does have multiple system bars, the first in following priority is returned:
* LEFT, TOP, RIGHT, BOTTOM.
*
* @param screen a {@link Screen} where an OS bar exists
* @return {@link Placement} indicating the screen edge.
*/
public static Placement getPlacementOfSystembar(Screen screen) {
var bounds = screen.getBounds();
var vBounds = screen.getVisualBounds();
//assumption: the system bar fills a whole screen side
if(bounds.getMinX() != vBounds.getMinX()){
if (bounds.getMinX() != vBounds.getMinX()) {
return Placement.LEFT;
} else if (bounds.getMinY() != vBounds.getMinY()) {
return Placement.TOP;

View File

@@ -1,6 +1,5 @@
package org.cryptomator.ui.notification;
import org.cryptomator.cryptofs.event.FilesystemEvent;
import org.cryptomator.event.VaultEvent;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.fxapp.FxNotificationRadar;
@@ -25,6 +24,8 @@ import java.util.concurrent.ExecutorService;
@NotificationScoped
public class NotificationController implements FxController {
private static final String BUG_MSG = "IF YOU SEE THIS MESSAGE, PLEASE CONTACT THE DEVELOPERS OF CRYPTOMATOR ABOUT A BUG IN THE NOTIFICATION DISPLAY";
private final Stage window;
private final SimpleListProperty<VaultEvent> notificationsProp;
private final IntegerProperty selectionIndex;
@@ -42,7 +43,7 @@ public class NotificationController implements FxController {
this.selectionIndex = new SimpleIntegerProperty(0);
this.selectedEvent = new SimpleObjectProperty<>();
selectionIndex.addListener((_, _, n) -> {
if (! notificationsProp.isEmpty()) {
if (!notificationsProp.isEmpty()) {
selectedEvent.setValue(notificationsProp.get(n.intValue()));
}
});
@@ -61,10 +62,18 @@ public class NotificationController implements FxController {
//TODO: Translations!
private void adjustTexts(ObservableValue<? extends VaultEvent> observable, VaultEvent oldEvent, VaultEvent newEvent) {
if (newEvent == null) {
message.set("NO CONTENT");
description.set(BUG_MSG);
actionText.set(null);
return;
}
switch (newEvent.actualEvent()) {
default -> {
message.set("NO CONTENT");
description.set("IF YOU SEE THIS MESSAGE, PLEASE CONTACT THE DEVELOPERS OF CRYPTOMATOR ABOUT A BUG IN THE NOTIFICATION DISPLAY");
description.set(BUG_MSG);
actionText.set(null);
}
}
}
@@ -147,7 +156,7 @@ public class NotificationController implements FxController {
}
public boolean isButtonVisible() {
return actionText.get() != null;
return actionText.get() != null && !actionText.get().isBlank();
}
public ObservableStringValue pagingProperty() {