Skip to content

Commit

Permalink
feat(app): upgrade versions and add grid background
Browse files Browse the repository at this point in the history
  • Loading branch information
DaiYuANg committed Dec 21, 2024
1 parent 6ab1c6b commit ce36b79
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 78 deletions.
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jdk = "21"
ikonliJavafx = "12.3.1"
slf4j = "2.0.16"
ikonli = "12.3.1"
junit = "5.11.3"
junit = "5.11.4"
testcontainers = "1.20.4"
mockito = "5.14.2"
gestalt = "0.35.1"
Expand All @@ -16,13 +16,13 @@ jdbi = "3.45.0"
fury = "0.9.0"
avajeValidaor = "2.4"
h2 = "2.3.232"
asciidoctor = "4.0.3"
asciidoctor = "4.0.4"
avajeInject = "11.1-RC1"
record-builder = "44"
mutinyVertx = "3.17.1"
schemacrawler = "16.24.1"
polyglot = "24.1.1"
ebean = "15.8.0"
ebean = "15.8.1"
immutables = "2.10.1"

[plugins]
Expand Down Expand Up @@ -51,7 +51,7 @@ asciidoctorEditconfig = { id = "org.asciidoctor.editorconfig", version.ref = "as
apache-common-io = { group = "commons-io", name = "commons-io", version = "2.18.0" }
apache-common-lang3 = { group = "org.apache.commons", name = "commons-lang3", version = "3.17.0" }
apache-common-pool = { group = "org.apache.commons", name = "commons-pool2", version = "2.12.0" }
apache-common-collection = { group = "org.apache.commons", name = "commons-collections4", version = "4.5.0-M2" }
apache-common-collection = { group = "org.apache.commons", name = "commons-collections4", version = "4.5.0-M3" }
apache-common-text = { group = "org.apache.commons", name = "commons-text", version = "1.13.0" }
apache-common-db-util = { group = "commons-dbutils", name = "commons-dbutils", version = "1.8.1" }
directories = { group = "dev.dirs", name = "directories", version = "26" }
Expand All @@ -63,7 +63,7 @@ slf4jJdkPlatform = { group = "org.slf4j", name = "slf4j-jdk-platform-logging", v
slf4jJulBridage = { group = "org.slf4j", name = "jul-to-slf4j", version.ref = "slf4j" }

oshi = { group = "com.github.oshi", name = "oshi-core-java11", version = "6.6.5" }
logback = { group = "ch.qos.logback", name = "logback-classic", version = "1.5.12" }
logback = { group = "ch.qos.logback", name = "logback-classic", version = "1.5.14" }

#UI
simpleicon = { group = "org.kordamp.ikonli", name = "ikonli-simpleicons-pack", version.ref = "ikonli" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,38 @@
package org.visual.app.component;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.DoublePropertyBase;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.stream.IntStream;

@Slf4j
public class GridBackground extends Region {
// This is to make the stroke be drawn 'on pixel'.
private static final double HALF_PIXEL_OFFSET = -0.5;

private static final String STYLE_CLASS = "graph-editor-grid";

private static final Color DEFAULT_GRID_COLOR = Color.rgb(222, 248, 255);

private double mLastWidth = -1;
private double mLastHeight = -1;
private final Path mGrid = new Path();
// private final StyleableObjectProperty<Color> mGridColor = new SimpleStyleableObjectProperty<>(DEFAULT_GRID_COLOR);

private final DoubleProperty mGridSpacing = new DoublePropertyBase(0.5) {

@Override
public Object getBean() {
return GridBackground.this;
}

@Contract(pure = true)
@Override
public @NotNull String getName() {
return "gridSpacing";
}

@Override
protected void invalidated() {
draw(getWidth(), getHeight());
}
};

public GridBackground() {
setManaged(false);
super();
mGrid.strokeProperty().set(DEFAULT_GRID_COLOR);
getStyleClass().add(STYLE_CLASS);
setManaged(true);
setMouseTransparent(true);
// mGrid.strokeProperty().bind(mGridColor);
getChildren().add(mGrid);
}

// @Override
// protected void layoutChildren() {
//
// }

@Override
public void resize(double pWidth, double pHeight) {
super.resize(pWidth, pHeight);
Expand All @@ -64,34 +45,20 @@ public void resize(double pWidth, double pHeight) {
}

void draw(final double pWidth, final double pHeight) {
val spacing = getGridSpacing();
val hLineCount = (int) Math.floor((pHeight + 1) / spacing);
val vLineCount = (int) Math.floor((pWidth + 1) / spacing);

IntStream.range(0, hLineCount)
.mapToDouble(i -> (i + 1) * spacing + HALF_PIXEL_OFFSET).forEach(y -> {
mGrid.getElements().add(new MoveTo(0, y));
mGrid.getElements().add(new LineTo(pWidth, y));
});

IntStream
.range(0, vLineCount)
.mapToDouble(i -> (i + 1) * spacing + HALF_PIXEL_OFFSET).forEach(x -> {
mGrid.getElements().add(new MoveTo(x, 0));
mGrid.getElements().add(new LineTo(x, pHeight));
});
}

public double getGridSpacing() {
return mGridSpacing.get();
}

public void setGridSpacing(final double gridSpacing) {
mGridSpacing.set(gridSpacing);
}
val spacing = 0.5;
val hLineCount = Math.floor((pHeight + 1) / spacing);
val vLineCount = Math.floor((pWidth + 1) / spacing);

for (int i = 0; i < hLineCount; i++) {
val y = (i + 1) * spacing + HALF_PIXEL_OFFSET;
mGrid.getElements().add(new MoveTo(0, y));
mGrid.getElements().add(new LineTo(pWidth, y));
}

public DoubleProperty gridSpacingProperty() {
return mGridSpacing;
for (int i = 0; i < vLineCount; i++) {
val x = (i + 1) * spacing + HALF_PIXEL_OFFSET;
mGrid.getElements().add(new MoveTo(x, 0));
mGrid.getElements().add(new LineTo(x, pHeight));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import javafx.scene.control.Label;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.visual.app.service.MANIFESTService;
import org.visual.app.model.MANIFEST;

import java.net.URL;
import java.util.ResourceBundle;
Expand All @@ -19,7 +18,7 @@
@RequiredArgsConstructor
public class AboutController implements Initializable {

private final MANIFESTService manifestService;
private final MANIFEST manifest;
@FXML
private Label manifestVersion;
@FXML
Expand Down Expand Up @@ -53,7 +52,6 @@ public class AboutController implements Initializable {

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
val manifest = manifestService.read();
log.atInfo().log("Current:{}", manifest);
manifestVersion.setText("Manifest Version: " + manifest.manifestVersion());
implementationTitle.setText("Implementation Title: " + manifest.implementationTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ public void handleCreateNewProject(ActionEvent actionEvent) {

}

public void handleOpenExistingProject(ActionEvent actionEvent) {
public void handleOpenExistingProject() {
val window = root.getScene().getWindow();
val chooser = new DirectoryChooser();
chooser.setInitialDirectory(userDir);
val dir = chooser.showDialog(window);
log.atInfo().log("Choose :{}", dir);
Platform.runLater(() -> {
val chooser = new DirectoryChooser();
chooser.setInitialDirectory(userDir);
val dir = chooser.showDialog(window);
log.atInfo().log("Choose :{}", dir);
});
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.visual.app.service;
package org.visual.app.factory;

import io.avaje.inject.Bean;
import io.avaje.inject.Factory;
import io.vavr.control.Try;
import jakarta.inject.Singleton;
import lombok.Cleanup;
import lombok.SneakyThrows;
import lombok.val;
Expand All @@ -10,11 +11,12 @@

import java.util.Properties;

@Singleton
public class MANIFESTService {
@Factory
public class ManifestFactory {

@Bean
@SneakyThrows
public MANIFEST read() {
MANIFEST manifest() {
@Cleanup val inputStream = getClass().getResourceAsStream("/META-INF/MANIFEST.MF");
return Try.of(Properties::new)
.andThenTry((manifest) -> manifest.load(inputStream))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<?import org.visual.app.component.GridBackground?>
<StackPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.visual.app.controller.workspace.EditorController"
style="-fx-background-color: white;"
>

<ScrollPane fx:id="root" fitToHeight="true" fitToWidth="true" vbarPolicy="ALWAYS" hbarPolicy="ALWAYS">
<GridBackground />
<AnchorPane prefHeight="10000" prefWidth="10000" fx:id="area">
<!-- 内容区域可以放其他控件 -->
</AnchorPane>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
fx:controller="org.visual.app.controller.workspace.TabController"
>
<Tab text="Tab 1">
<fx:include source="Editor.fxml"/>
<GridBackground prefWidth="200" prefHeight="200" />
<!-- <fx:include source="Editor.fxml"/>-->
</Tab>
</TabPane>

0 comments on commit ce36b79

Please sign in to comment.