Skip to content

Commit

Permalink
[nodefx] New module with a zoomable panel and canvas.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Nov 19, 2017
1 parent b8b5cfc commit 9247741
Show file tree
Hide file tree
Showing 13 changed files with 4,783 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ AFC library contains the following alive modules:
| mathfx
| JavaFX implementation of the mathematic and geometry tools

| link:http://arakhne.org/afc/apidocs/index.html?org/arakhne/afc/nodefx/package-summary.html[JavaFX Nodes and Components]
|
| org.arakhne.afc.advanced
| nodefx
| Set of nodes and components for JavaFX, e.g. a viewer with zoom support.

| link:http://arakhne.org/afc/apidocs/index.html?org/arakhne/afc/io/shape/package-summary.html[Shape File Reader and Writer]
|
| org.arakhne.afc.advanced
Expand Down
86 changes: 86 additions & 0 deletions advanced/nodefx/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>advanced</artifactId>
<groupId>org.arakhne.afc.advanced</groupId>
<version>15.0-SNAPSHOT</version>
</parent>

<artifactId>nodefx</artifactId>
<name>JavaFX Nodes and Components</name>
<inceptionYear>2017</inceptionYear>

<properties>
<manifest.file>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifest.file>
</properties>

<dependencies>
<dependency>
<groupId>org.arakhne.afc.core</groupId>
<artifactId>mathgeom</artifactId>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>jfxrt</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArguments>
<properties>${jdtcompilerconfpath}</properties>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<sourceDirectory>src/main/java</sourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<index>false</index>
<manifestFile>${manifest.file}</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifestFile>${manifest.file}</manifestFile>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>

<instructions>
<Export-Package>org.arakhne.afc.nodefx.*</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* $Id$
* This file is a part of the Arakhne Foundation Classes, http://www.arakhne.org/afc
*
* Copyright (c) 2000-2012 Stephane GALLAND.
* Copyright (c) 2005-10, Multiagent Team, Laboratoire Systemes et Transports,
* Universite de Technologie de Belfort-Montbeliard.
* Copyright (c) 2013-2018 The original authors, and other authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.arakhne.afc.nodefx;

import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import org.eclipse.xtext.xbase.lib.Pure;

import org.arakhne.afc.math.geometry.d2.afp.Rectangle2afp;

/** This feature describes all the parameters that must
* be used to center logical points on the screen view.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 15.0
*/
public class CenteringTransform {

private static final String TRANSLATION_X_PROPERTY = "translationX"; //$NON-NLS-1$

private static final String TRANSLATION_Y_PROPERTY = "translationY"; //$NON-NLS-1$

/** Is the translation to add to the logical coordinate.
*/
private final DoubleProperty translationX;

/** Indicates if the X axis is flipped.
*/
private final BooleanProperty invertX;

/** Is the translation to add to the logical coordinate.
*/
private final DoubleProperty translationY;

/** Indicates if the Y axis is flipped.
*/
private final BooleanProperty invertY;

/** Constructor.
*
* @param invertedAxisX indicates if the x axis of the document is inverted regarding the JavaFX x axis.
* @param invertedAxisY indicates if the y axis of the document is inverted regarding the JavaFX y axis.
* @param visibleArea the bounds of the viewport in document coordinates.
*/
public CenteringTransform(
BooleanProperty invertedAxisX,
BooleanProperty invertedAxisY,
ReadOnlyObjectProperty<Rectangle2afp<?, ?, ?, ?, ?, ?>> visibleArea) {
this.invertX = invertedAxisX;
this.invertY = invertedAxisY;

this.translationX = new SimpleDoubleProperty(this, TRANSLATION_X_PROPERTY);
this.translationX.bind(Bindings.createDoubleBinding(
() -> {
final double center = visibleArea.get().getCenterX();
return this.invertX.get() ? center : -center;
}, visibleArea, this.invertX));
this.translationY = new SimpleDoubleProperty(this, TRANSLATION_Y_PROPERTY);
this.translationY.bind(Bindings.createDoubleBinding(
() -> {
final double center = visibleArea.get().getCenterY();
return this.invertY.get() ? center : -center;
}, visibleArea));
}

/** Replies if the x axis of the displayed data is inverted regarding to the
* standard JavaFX coordinate system.
*
* @return the x coordinate of the viewport center in document coordinates.
*/
@Pure
public boolean isInvertedAxisX() {
return this.invertX.get();
}

/** Replies if the Y axis of the displayed data is inverted regarding to the
* standard JavaFX coordinate system.
*
* @return the Y coordinate of the viewport center in document coordinates.
*/
@Pure
public boolean isInvertedAxisY() {
return this.invertY.get();
}

/** Change the coordinate system of {@code x} from the
* global document coordinate system to the "centered" graphical coordinate system.
*
* @param x the x document coordinate to convert.
* @return the x coordinate in the "centered" graphical coordinate system.
*/
@Pure
public double toCenterX(double x) {
final double adjustedX = this.invertX.get() ? -x : x;
return adjustedX + this.translationX.get();
}

/** Change the coordinate system of {@code y} from the
* global document coordinate system to the "centered" graphical coordinate system.
*
* @param y the y document coordinate to convert.
* @return the x coordinate in the "centered" graphical coordinate system.
*/
@Pure
public double toCenterY(double y) {
final double adjustedY = this.invertY.get() ? -y : y;
return adjustedY + this.translationY.get();
}

/** Change the coordinate system of {@code x} from the
* "centered" graphical coordinate system to the global document coordinate system.
*
* @param x the x graphical coordinate to convert.
* @return the x coordinate in the global document coordinate system.
*/
@Pure
public double toGlobalX(double x) {
final double adjustedX = x - this.translationX.get();
return this.invertX.get() ? adjustedX : -adjustedX;
}

/** Change the coordinate system of {@code y} from the
* "centered" graphical coordinate system to the global document coordinate system.
*
* @param y the y graphical coordinate to convert.
* @return the x coordinate in the global coordinate system.
*/
@Pure
public double toGlobalY(double y) {
final double adjustedY = y - this.translationY.get();
return this.invertY.get() ? adjustedY : -adjustedY;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* $Id$
* This file is a part of the Arakhne Foundation Classes, http://www.arakhne.org/afc
*
* Copyright (c) 2000-2012 Stephane GALLAND.
* Copyright (c) 2005-10, Multiagent Team, Laboratoire Systemes et Transports,
* Universite de Technologie de Belfort-Montbeliard.
* Copyright (c) 2013-2018 The original authors, and other authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.arakhne.afc.nodefx;

import org.eclipse.xtext.xbase.lib.Pure;

import org.arakhne.afc.math.geometry.d2.afp.BoundedElement2afp;
import org.arakhne.afc.util.InformedIterable;

/** Drawer of a document.
*
* @param <T> the type of the elements to draw.
* @param <DT> the type of the document.
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 15.0
*/
public interface DocumentDrawer<T, DT extends InformedIterable<? super T> & BoundedElement2afp<?>> extends Drawer<DT> {

/** Replies the element drawer.
*
* @return the element drawer.
*/
@Pure
Drawer<? super T> getElementDrawer();

/** Replies the type of the elements inside this container.
*
* @return the type of the elements inside this container.
*/
@Pure
Class<? extends T> getContainedElementType();

/** Replies if the given element could be drawn.
*
* @param gc the current graphics context.
* @param mapelement the element to draw.
* @return {@code true} to draw the element. {@code false} to hide the element.
*/
boolean isDrawable(ZoomableGraphicsContext gc, T mapelement);

}
50 changes: 50 additions & 0 deletions advanced/nodefx/src/main/java/org/arakhne/afc/nodefx/Drawer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* $Id$
* This file is a part of the Arakhne Foundation Classes, http://www.arakhne.org/afc
*
* Copyright (c) 2000-2012 Stephane GALLAND.
* Copyright (c) 2005-10, Multiagent Team, Laboratoire Systemes et Transports,
* Universite de Technologie de Belfort-Montbeliard.
* Copyright (c) 2013-2018 The original authors, and other authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.arakhne.afc.nodefx;

import org.eclipse.xtext.xbase.lib.Pure;

/** Draw of an element.
*
* @param <T> the type of the element to draw.
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 15.0
*/
public interface Drawer<T> {

/** Draw the given document elements.
*
* @param gc the graphics context that must be used for drawing.
* @param element the element to draw.
*/
void draw(ZoomableGraphicsContext gc, T element);

/** Replies the type of the components that could be drawn by this drawer.
*
* @return the type of the elements.
*/
@Pure
Class<? extends T> getElementType();

}

0 comments on commit 9247741

Please sign in to comment.