Skip to content

Commit

Permalink
Modify AddressPath
Browse files Browse the repository at this point in the history
  • Loading branch information
naotsugu committed Dec 16, 2023
1 parent b6d10c6 commit 85791fa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -56,7 +57,7 @@ public Path dirOn(int index) {

public List<Path> listSibling(int index) {
try (Stream<Path> s = Files.list(dirOn(index))) {
return s.toList();
return s.sorted(Comparator.comparing(p -> Files.isDirectory(p) ? -1 : 1)).toList();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ private static UiColor themeColor(Context context) {
}


private String css(UiColor themeColor) {
private String css(UiColor tc) {
var css = """
.root {
-fx-accent: rgba(121,134,203,0.5); /* Hue.INDIGO */
-fx-accent:rgba(121,134,203,0.5); /* Hue.INDIGO */
}
""";
return "data:text/css;base64," + Base64.getEncoder().encodeToString(css.getBytes(StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import javafx.animation.Timeline;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Point2D;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.stage.PopupWindow;
import javafx.util.Duration;
import java.nio.file.Path;

Expand All @@ -31,38 +33,50 @@
*/
public class UiAddressField extends UiPromptField {

/** The timeline. */
private Timeline timeline;

private PopupWindow popup;

private int pathPositionIndex = -1;


/**
* Constructor.
*
* @param themeColor the theme color
*/
public UiAddressField(UiColor themeColor) {
super(themeColor);
initHandler();
}


/**
* Initialize handler.
*/
private void initHandler() {
text().textProperty().addListener(this::handleTextProperty);
text().setOnMouseMoved(this::handleMouseMoved);
text().setOnMouseExited(e -> stopTimeline());
text().setOnKeyPressed(this::handleTextKeyPressed);
text().disabledProperty().addListener((ob, o, n) -> { if (n) stopTimeline(); });
}




private void handleTextProperty(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
setPrompt(UiIcon.contentOf(uiColor(), extension(newValue)));
}


/**
* Key pressed handler.
* @param e the key event
*/
private void handleTextKeyPressed(KeyEvent e) {
stopTimeline();
}


private void handleMouseMoved(MouseEvent e) {

if (!getScene().getWindow().isFocused()) {
Expand All @@ -87,28 +101,31 @@ private void handleMouseMoved(MouseEvent e) {
stopTimeline();
}

trackPathPoint(index, pathText);
trackPathPoint(index, pathText, point);

}


private void trackPathPoint(int index, String pathText) {
private void trackPathPoint(int index, String pathText, Point2D point) {
if (timeline != null) return;
pathPositionIndex = index;
timeline = new Timeline();
timeline.setCycleCount(1);

var kf = new KeyFrame(Duration.millis(1000), e -> {
var p = AddressPath.of(Path.of(pathText));
//var popup = new UiFileNavPopup(uiColor(), p.listSibling(index));
//popup.show(UiAddressField.this.getScene().getWindow());
var popup = UiPopupMenu.of(uiColor(), p.listSibling(index));
popup.show(UiAddressField.this.getScene().getWindow());
var keyFrame = new KeyFrame(Duration.millis(1000), e -> {
if (popup != null) {
popup.hide();
}
var addressPath = AddressPath.of(Path.of(pathText));
popup = UiPopupMenu.of(uiColor(), addressPath.listSibling(index));
popup.show(UiAddressField.this.getScene().getWindow(),
point.getX(), text().localToScreen(text().getBoundsInLocal()).getMaxY());
});
timeline.getKeyFrames().add(kf);
timeline.getKeyFrames().add(keyFrame);
timeline.play();
}


private void stopTimeline() {
if (timeline != null) {
timeline.stop();
Expand All @@ -117,6 +134,7 @@ private void stopTimeline() {
pathPositionIndex = -1;
}


private static String extension(String string) {
int index = string.lastIndexOf(".") + 1;
return (index > 0 && index < string.length()) ? string.substring(index) : "";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.mammb.code.editor.ui.app;

import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import java.nio.file.Path;
Expand All @@ -34,7 +35,6 @@ public UiPopupMenu(UiColor themeColor, MenuItem... items) {
super(items);
this.uiColor = themeColor;
setStyle(css(uiColor));

}


Expand All @@ -44,6 +44,14 @@ public static UiPopupMenu of(UiColor tc, List<Path> paths) {
return new UiPopupMenu(tc, items);
}


public void show(Node ownerNode, double anchorX, double anchorY) {
setMaxHeight(300);
setPrefHeight(300);
super.show(ownerNode, anchorX, anchorY);
}


private String css(UiColor tc) {
return """
-fx-background-color:%s;
Expand Down

0 comments on commit 85791fa

Please sign in to comment.