Improve layout and look of StatusPane
This commit is contained in:
parent
27dac97384
commit
70bb052c94
|
@ -3,21 +3,32 @@ package ctbrec.ui.news;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.FormatStyle;
|
import java.time.format.FormatStyle;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import ctbrec.io.HtmlParser;
|
import ctbrec.io.HtmlParser;
|
||||||
import ctbrec.ui.DesktopIntegration;
|
import ctbrec.ui.DesktopIntegration;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Orientation;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.ScrollBar;
|
||||||
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
public class StatusPane extends StackPane {
|
public class StatusPane extends StackPane {
|
||||||
|
|
||||||
|
TextArea content;
|
||||||
|
Button reply;
|
||||||
|
|
||||||
public StatusPane(Status status) {
|
public StatusPane(Status status) {
|
||||||
String text = HtmlParser.getText("<div>" + status.getContent() + "</div>", "div");
|
String text = HtmlParser.getText("<div>" + status.getContent() + "</div>", "div");
|
||||||
TextArea content = new TextArea(text);
|
|
||||||
|
content = new TextArea(text);
|
||||||
content.setMaxHeight(130);
|
content.setMaxHeight(130);
|
||||||
content.setEditable(false);
|
content.setEditable(false);
|
||||||
content.setWrapText(true);
|
content.setWrapText(true);
|
||||||
|
@ -26,14 +37,49 @@ public class StatusPane extends StackPane {
|
||||||
ZonedDateTime createdAt = status.getCreationTime();
|
ZonedDateTime createdAt = status.getCreationTime();
|
||||||
String creationTime = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT).format(createdAt);
|
String creationTime = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT).format(createdAt);
|
||||||
Label time = new Label(creationTime);
|
Label time = new Label(creationTime);
|
||||||
|
time.setStyle("-fx-background-color: -fx-base");
|
||||||
|
time.setOpacity(.7);
|
||||||
|
time.setPadding(new Insets(3));
|
||||||
|
time.setOnMouseEntered(evt -> time.setOpacity(1));
|
||||||
|
time.setOnMouseExited(evt -> time.setOpacity(.7));
|
||||||
getChildren().add(time);
|
getChildren().add(time);
|
||||||
StackPane.setMargin(time, new Insets(5));
|
StackPane.setMargin(time, new Insets(5, 5, 5, 10));
|
||||||
StackPane.setAlignment(time, Pos.BOTTOM_LEFT);
|
StackPane.setAlignment(time, Pos.BOTTOM_LEFT);
|
||||||
|
Rectangle clip = new Rectangle(time.getWidth(), time.getHeight());
|
||||||
|
clip.heightProperty().bind(time.heightProperty());
|
||||||
|
clip.widthProperty().bind(time.widthProperty());
|
||||||
|
clip.setArcHeight(5);
|
||||||
|
clip.arcWidthProperty().bind(clip.arcHeightProperty());
|
||||||
|
time.setClip(clip);
|
||||||
|
|
||||||
Button reply = new Button("Reply");
|
reply = new Button("Reply");
|
||||||
reply.setOnAction((evt) -> DesktopIntegration.open(status.getUrl()));
|
reply.setOnAction((evt) -> DesktopIntegration.open(status.getUrl()));
|
||||||
getChildren().add(reply);
|
getChildren().add(reply);
|
||||||
StackPane.setMargin(reply, new Insets(5));
|
StackPane.setMargin(reply, new Insets(5, 5, 5, 5));
|
||||||
StackPane.setAlignment(reply, Pos.BOTTOM_RIGHT);
|
StackPane.setAlignment(reply, Pos.BOTTOM_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void layoutChildren() {
|
||||||
|
ObservableList<Node> childrenUnmodifiable = content.getChildrenUnmodifiable();
|
||||||
|
for (Node node : childrenUnmodifiable) {
|
||||||
|
if (node instanceof ScrollPane) {
|
||||||
|
ScrollPane scrollPane = (ScrollPane) node;
|
||||||
|
Set<Node> nodes = scrollPane.lookupAll(".scroll-bar");
|
||||||
|
for (final Node child : nodes) {
|
||||||
|
if (child instanceof ScrollBar) {
|
||||||
|
ScrollBar sb = (ScrollBar) child;
|
||||||
|
if (sb.getOrientation() == Orientation.VERTICAL) {
|
||||||
|
if (sb.isVisible()) {
|
||||||
|
StackPane.setMargin(reply, new Insets(5, 22, 5, 5));
|
||||||
|
} else {
|
||||||
|
StackPane.setMargin(reply, new Insets(5, 5, 5, 5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.layoutChildren();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue