Skip to content

style: format code with Google Java Format #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 36 additions & 40 deletions src/graphvisualizer/containers/ContentResizerPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,57 +32,53 @@
import javafx.scene.transform.Scale;

/**
*
* @author brunomnsilva
*/
public class ContentResizerPane extends Pane {

private final Node content;
private final DoubleProperty resizeFActor = new SimpleDoubleProperty(1);
private final Node content;
private final DoubleProperty resizeFActor = new SimpleDoubleProperty(1);

public ContentResizerPane(Node content) {
this.content = content;
public ContentResizerPane(Node content) {
this.content = content;

getChildren().add(content);
getChildren().add(content);

Scale scale = new Scale(1.0, 1.0);
content.getTransforms().add(scale);
Scale scale = new Scale(1.0, 1.0);
content.getTransforms().add(scale);

resizeFActor.addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
scale.setX(newValue.doubleValue());
scale.setY(newValue.doubleValue());
requestLayout();
resizeFActor.addListener(
(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
scale.setX(newValue.doubleValue());
scale.setY(newValue.doubleValue());
requestLayout();
});
}

}

@Override
protected void layoutChildren() {
Pos pos = Pos.TOP_LEFT;
double width = getWidth();
double height = getHeight();
double top = getInsets().getTop();
double right = getInsets().getRight();
double left = getInsets().getLeft();
double bottom = getInsets().getBottom();
double contentWidth = (width - left - right) / resizeFActor.get();
double contentHeight = (height - top - bottom) / resizeFActor.get();
layoutInArea(content, left, top,
contentWidth, contentHeight,
0, null,
pos.getHpos(),
pos.getVpos());
}
@Override
protected void layoutChildren() {
Pos pos = Pos.TOP_LEFT;
double width = getWidth();
double height = getHeight();
double top = getInsets().getTop();
double right = getInsets().getRight();
double left = getInsets().getLeft();
double bottom = getInsets().getBottom();
double contentWidth = (width - left - right) / resizeFActor.get();
double contentHeight = (height - top - bottom) / resizeFActor.get();
layoutInArea(
content, left, top, contentWidth, contentHeight, 0, null, pos.getHpos(), pos.getVpos());
}

public final Double getResizeFactor() {
return resizeFActor.get();
}
public final Double getResizeFactor() {
return resizeFActor.get();
}

public final void setResizeFactor(Double resizeFactor) {
this.resizeFActor.set(resizeFactor);
}
public final void setResizeFactor(Double resizeFactor) {
this.resizeFActor.set(resizeFactor);
}

public final DoubleProperty resizeFactorProperty() {
return resizeFActor;
}
public final DoubleProperty resizeFactorProperty() {
return resizeFActor;
}
}
217 changes: 106 additions & 111 deletions src/graphvisualizer/containers/ContentZoomPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,169 +36,164 @@
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

/**
* This class provides zooming and panning for a JavaFX node.
*
* It shows the zoom level with a slider control and reacts to mouse scrolls and
* mouse dragging.
* <p>It shows the zoom level with a slider control and reacts to mouse scrolls and mouse dragging.
*
* The content node is out forward in the z-index so it can react to mouse
* events first. The node should consume any event not meant to propagate to
* this pane.
* <p>The content node is out forward in the z-index so it can react to mouse events first. The node
* should consume any event not meant to propagate to this pane.
*
* @author brunomnsilva
*/
public class ContentZoomPane extends BorderPane {

/*
PAN AND ZOOM
*/
private final DoubleProperty scaleFactorProperty = new ReadOnlyDoubleWrapper(1);
private final Node content;
/*
PAN AND ZOOM
*/
private final DoubleProperty scaleFactorProperty = new ReadOnlyDoubleWrapper(1);
private final Node content;

private static final double MIN_SCALE = 1;
private static final double MAX_SCALE = 5;
private static final double SCROLL_DELTA = 0.25;
private static final double MIN_SCALE = 1;
private static final double MAX_SCALE = 5;
private static final double SCROLL_DELTA = 0.25;

public ContentZoomPane(Node content) {
if (content == null) {
throw new IllegalArgumentException("Content cannot be null.");
}

this.content = content;
public ContentZoomPane(Node content) {
if (content == null) {
throw new IllegalArgumentException("Content cannot be null.");
}

Node center = content;
content.toFront();
this.content = content;

setCenter(center);
setTop(createSlider());
Node center = content;
content.toFront();

enablePanAndZoom();
}
setCenter(center);
setTop(createSlider());

private Node createSlider() {
enablePanAndZoom();
}

Slider slider = new Slider(MIN_SCALE, MAX_SCALE, MIN_SCALE);
slider.setOrientation(Orientation.HORIZONTAL);
slider.setShowTickMarks(true);
slider.setShowTickLabels(true);
slider.setMajorTickUnit(SCROLL_DELTA);
slider.setMinorTickCount(1);
slider.setBlockIncrement(0.125f);
slider.setSnapToTicks(true);
private Node createSlider() {

Text label = new Text("Zoom");
Slider slider = new Slider(MIN_SCALE, MAX_SCALE, MIN_SCALE);
slider.setOrientation(Orientation.HORIZONTAL);
slider.setShowTickMarks(true);
slider.setShowTickLabels(true);
slider.setMajorTickUnit(SCROLL_DELTA);
slider.setMinorTickCount(1);
slider.setBlockIncrement(0.125f);
slider.setSnapToTicks(true);

HBox paneSlider = new HBox(label, slider);
Text label = new Text("Zoom");

paneSlider.setPadding(new Insets(10, 10, 10, 10));
paneSlider.setSpacing(20);
HBox.setHgrow(slider, Priority.ALWAYS);
HBox paneSlider = new HBox(label, slider);

slider.valueProperty().bind(this.scaleFactorProperty());

return paneSlider;
}
paneSlider.setPadding(new Insets(10, 10, 10, 10));
paneSlider.setSpacing(20);
HBox.setHgrow(slider, Priority.ALWAYS);

public void setContentPivot(double x, double y) {
content.setTranslateX(content.getTranslateX() - x);
content.setTranslateY(content.getTranslateY() - y);
}
slider.valueProperty().bind(this.scaleFactorProperty());

public static double boundValue(double value, double min, double max) {
return paneSlider;
}

if (Double.compare(value, min) < 0) {
return min;
}
public void setContentPivot(double x, double y) {
content.setTranslateX(content.getTranslateX() - x);
content.setTranslateY(content.getTranslateY() - y);
}

if (Double.compare(value, max) > 0) {
return max;
}
public static double boundValue(double value, double min, double max) {

return value;
if (Double.compare(value, min) < 0) {
return min;
}

private void enablePanAndZoom() {
if (Double.compare(value, max) > 0) {
return max;
}

setOnScroll((ScrollEvent event) -> {
return value;
}

double direction = event.getDeltaY() >= 0 ? 1 : -1;
private void enablePanAndZoom() {

double currentScale = scaleFactorProperty.getValue();
double computedScale = currentScale + direction * SCROLL_DELTA;
setOnScroll(
(ScrollEvent event) -> {
double direction = event.getDeltaY() >= 0 ? 1 : -1;

computedScale = boundValue(computedScale, MIN_SCALE, MAX_SCALE);
double currentScale = scaleFactorProperty.getValue();
double computedScale = currentScale + direction * SCROLL_DELTA;

if (currentScale != computedScale) {
computedScale = boundValue(computedScale, MIN_SCALE, MAX_SCALE);

content.setScaleX(computedScale);
content.setScaleY(computedScale);
if (currentScale != computedScale) {

if (computedScale == 1) {
content.setTranslateX(-getTranslateX());
content.setTranslateY(-getTranslateY());
} else {
scaleFactorProperty.setValue(computedScale);
content.setScaleX(computedScale);
content.setScaleY(computedScale);

Bounds bounds = content.localToScene(content.getBoundsInLocal());
double f = (computedScale / currentScale) - 1;
double dx = (event.getX() - (bounds.getWidth() / 2 + bounds.getMinX()));
double dy = (event.getY() - (bounds.getHeight() / 2 + bounds.getMinY()));
if (computedScale == 1) {
content.setTranslateX(-getTranslateX());
content.setTranslateY(-getTranslateY());
} else {
scaleFactorProperty.setValue(computedScale);

setContentPivot(f * dx, f * dy);
}
Bounds bounds = content.localToScene(content.getBoundsInLocal());
double f = (computedScale / currentScale) - 1;
double dx = (event.getX() - (bounds.getWidth() / 2 + bounds.getMinX()));
double dy = (event.getY() - (bounds.getHeight() / 2 + bounds.getMinY()));

setContentPivot(f * dx, f * dy);
}
//do not propagate
event.consume();

}
// do not propagate
event.consume();
});

final DragContext sceneDragContext = new DragContext();
final DragContext sceneDragContext = new DragContext();

setOnMousePressed((MouseEvent event) -> {
setOnMousePressed(
(MouseEvent event) -> {
if (event.isSecondaryButtonDown()) {
getScene().setCursor(Cursor.MOVE);

if (event.isSecondaryButtonDown()) {
getScene().setCursor(Cursor.MOVE);

sceneDragContext.mouseAnchorX = event.getX();
sceneDragContext.mouseAnchorY = event.getY();

sceneDragContext.translateAnchorX = content.getTranslateX();
sceneDragContext.translateAnchorY = content.getTranslateY();
}
sceneDragContext.mouseAnchorX = event.getX();
sceneDragContext.mouseAnchorY = event.getY();

sceneDragContext.translateAnchorX = content.getTranslateX();
sceneDragContext.translateAnchorY = content.getTranslateY();
}
});

setOnMouseReleased((MouseEvent event) -> {
getScene().setCursor(Cursor.DEFAULT);
setOnMouseReleased(
(MouseEvent event) -> {
getScene().setCursor(Cursor.DEFAULT);
});

setOnMouseDragged((MouseEvent event) -> {
if (event.isSecondaryButtonDown()) {

content.setTranslateX(sceneDragContext.translateAnchorX + event.getX() - sceneDragContext.mouseAnchorX);
content.setTranslateY(sceneDragContext.translateAnchorY + event.getY() - sceneDragContext.mouseAnchorY);
}
});

}
setOnMouseDragged(
(MouseEvent event) -> {
if (event.isSecondaryButtonDown()) {

public DoubleProperty scaleFactorProperty() {
return scaleFactorProperty;
}

class DragContext {
content.setTranslateX(
sceneDragContext.translateAnchorX + event.getX() - sceneDragContext.mouseAnchorX);
content.setTranslateY(
sceneDragContext.translateAnchorY + event.getY() - sceneDragContext.mouseAnchorY);
}
});
}

double mouseAnchorX;
double mouseAnchorY;
public DoubleProperty scaleFactorProperty() {
return scaleFactorProperty;
}

double translateAnchorX;
double translateAnchorY;
class DragContext {

}
double mouseAnchorX;
double mouseAnchorY;

double translateAnchorX;
double translateAnchorY;
}
}
Loading