Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.scene.shape.Line;
- @FunctionalInterface
- public interface LineInfoDisplayer {
- String getInfo(Line line);
- public static enum InfoType {
- DISTANCE, MIDPOINT, VERTHORZ;
- }
- public static LineInfoDisplayer createLineInfoDisplayer(InfoType type) {
- //if (Line.line != null)
- if (type == InfoType.DISTANCE) {
- return line -> {
- String outputString = "";
- if (line != null) {
- double xParam = Math.abs(line.getEndX() - line.getStartX());
- double yParam = Math.abs(line.getEndY() - line.getStartY());
- double distance = Math.hypot(xParam, yParam);
- outputString = String.format("DISTANCE: %,.2f", distance);
- }
- return outputString;
- };
- } else if (type == InfoType.MIDPOINT) {
- return line -> {
- String outputString = "";
- if (line != null) {
- double xMid = (line.getStartX() + line.getEndX()) / 2;
- double yMid = (line.getStartY() + line.getEndY()) / 2;
- outputString = String.format("MIDPOINT: %,.0f,%,.0f", xMid, yMid);
- }
- return outputString;
- };
- } else if (type == InfoType.VERTHORZ) {
- return line -> {
- String outputString = "";
- if (line != null) {
- boolean isVertical = Double.compare(line.getStartX(), line.getEndX()) == 0;
- boolean isHorizontal = Double.compare(line.getStartY(), line.getEndY()) == 0;
- outputString = String.format("HORIZONTAL? %b\nVERTICAL? %b",isHorizontal,
- isVertical);
- }
- return outputString;
- };
- } else {
- return null;
- }
- } // end createLineInfoDisplayer()
- } // end LineInfoDisplayer
Add Comment
Please, Sign In to add comment