use of javafx.scene.layout.Background in project uPMT by coco35700.
the class MainViewTransformations method addBorderPaneMomentListener.
public static void addBorderPaneMomentListener(MomentExpVBox moment, Main main) {
moment.getMomentPane().setOnDragExited(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
moment.getMomentPane().setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
}
});
moment.getMomentPane().setOnDragOver(new EventHandler<DragEvent>() {
public void handle(DragEvent event) {
// Checking if a type is already present
boolean doesntalreadyHasType = true;
String typeType = event.getDragboard().getRtf();
for (Node n : moment.getTypeSpace().getChildren()) {
TypeClassRepresentationController type = (TypeClassRepresentationController) n;
if (type.getClasse().getName().equals(typeType)) {
doesntalreadyHasType = false;
break;
}
}
boolean cond = true;
MomentExperience draggedMoment = null;
try {
draggedMoment = (MomentExperience) Serializer.deserialize((byte[]) event.getDragboard().getContent(MomentExpVBox.df));
if (draggedMoment != null) {
// draggedMoment ne peut pas etre depose sur lui meme
if (draggedMoment.equals(moment.getMoment()))
cond = false;
else // draggedMoment ne peut pas etre depose sur ses enfants
if (moment.isAChildOf(draggedMoment))
cond = false;
else // draggedMoment ne peut pas etre depose sur son pere direct
if (moment.isDirectParentOf(draggedMoment))
cond = false;
} else
cond = false;
} catch (Exception e) {
}
// setting the drag autorizations
if (((event.getDragboard().getString().equals("ajoutType") && doesntalreadyHasType) || event.getDragboard().getString().equals("ajoutMoment") || event.getDragboard().getString().equals("moveMoment")) && cond) {
event.acceptTransferModes(TransferMode.ANY);
moment.getMomentPane().setBackground(new Background(new BackgroundFill(Color.GRAY, CornerRadii.EMPTY, Insets.EMPTY)));
}
event.consume();
}
});
moment.getMomentPane().setOnDragDropped(new EventHandler<DragEvent>() {
public void handle(DragEvent event) {
if (event.getDragboard().getString().equals("ajoutType")) {
AddTypeCommand cmd = new AddTypeCommand(moment, event, main);
cmd.execute();
UndoCollector.INSTANCE.add(cmd);
}
if (event.getDragboard().getString().equals("ajoutMoment")) {
// Add Moment to a Moment : int: index in sous-moment / Moment: parentMoment / Main
MomentExperience newMoment = newMoment = new MomentExperience();
if (event.getDragboard().getContent(DataFormat.HTML) != null) {
newMoment.setDescripteme((String) event.getDragboard().getContent(DataFormat.HTML));
}
AddMomentCommand cmd = new AddMomentCommand(moment.getMoment().getSubMoments().size(), newMoment, moment.getMoment(), main);
cmd.execute();
UndoCollector.INSTANCE.add(cmd);
}
if (event.getDragboard().getString().equals("moveMoment")) {
MomentExperience serial = null;
try {
serial = (MomentExperience) Serializer.deserialize((byte[]) event.getDragboard().getContent(MomentExpVBox.df));
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
MoveMomentToMomentCommand cmd = new MoveMomentToMomentCommand(serial, moment.getMoment(), moment.getMoment().getSubMoments().size(), main);
cmd.execute();
UndoCollector.INSTANCE.add(cmd);
}
event.setDropCompleted(true);
moment.getMomentPane().setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
event.consume();
}
});
// Click the moment panel
moment.getMomentPane().setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getButton().equals(MouseButton.PRIMARY)) {
main.setCurrentMoment(moment);
boolean childHasFocus = false;
for (Node type : moment.getTypeSpace().getChildren()) {
TypeClassRepresentationController tt = (TypeClassRepresentationController) type;
if (tt.isFocused()) {
childHasFocus = true;
}
}
if (!childHasFocus) {
moment.requestFocus();
}
String print = "row: " + moment.getMoment().getRow() + "; column: " + moment.getMoment().getGridCol() + "; parent: balek";
/*if(moment.hasParent()) print+=moment.getMoment().getParent(main).getNom();
else print+=" null";*/
// System.out.println(print);
}
}
});
moment.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) {
if (newPropertyValue) {
moment.setBorderColor("#039ED3");
} else {
moment.setBorderColor("black");
}
}
});
}
use of javafx.scene.layout.Background in project S4T1TM2 by CSUS-CSC-131-Spring2018.
the class JavaFXDemo method start.
/**
* Typically (or at least, by convention), Java applications that apply JavaFX Stages (Windows) extend the JavaFX Application class
* JEP 153 (http://openjdk.java.net/jeps/153) allows Java to launch JavaFX Applications without a declared main method (although, must be specified in the manifest)
*
* However, a main method with additional procedures may be defined. Implicitly, the default main method for a JavaFX application follows below:
*/
/*
public static void main(String[] args) {
Application.launch(JavaFXDemo.class);
}
*/
@Override
public void start(Stage primaryStage) throws Exception {
// primaryStage is the default stage JavaFX builds for you
// Exception is part of the Application#start(Stage) signature, but can be removed if no exceptions are thrown in your procedure
// define attributes for the primary stage
primaryStage.setTitle("Default Title");
// alternatively, you may set the scene dimensions in the constructor, and the Stage will inherit from those
primaryStage.setHeight(600);
primaryStage.setWidth(800);
// Pane is one of the simplest forms of containers, there exist others for different purposes (StackPane, ScrollPane, etc...)
// Since rootPane will be set as the root pane, it will automatically inherit width/height from the scene (which may inherit from the primary stage)
Pane rootPane = new Pane();
// Creates a text input field, using the JFoenix UI extension. The standard JavaFX one is TextField
JFXTextField field = new JFXTextField();
field.setPromptText("Placeholder value...");
// Most JavaFX elements extend from one of the parent types - javafx.scene.Node
// Nodes have observable and bindable values, and elements that will inherit and possibly add more properties
// Some properties are readonly, and some are read and writeable
// Properties have a datatype
// for example, we can bind the title of the window to the value of the text field, which will overwrite the currently defined title "Default Title" immediately
primaryStage.titleProperty().bind(field.textProperty());
// Mathematical calculations can be done with observable values, such as subtraction
// If any value updates that is being depended on, it will update
// Center the text field to the 3/4th the width, and 1/2 the height
// field.x = rootPane.width * 3/4 - field.width * 1/2
field.layoutXProperty().bind(rootPane.widthProperty().multiply(.75f).subtract(field.widthProperty().divide(2)));
// field.x = rootPane.width * 1/4 - field.width * 1/2
field.layoutYProperty().bind(rootPane.heightProperty().multiply(.5).subtract(field.heightProperty().divide(2)));
// part of JFoenix's material design
// when the textbox is focused
field.setFocusColor(Color.GREEN);
// when it is not focused
field.setUnFocusColor(Color.RED);
// define a background (very cumbersome in java, easier in css)
// field.setBackground(new Background(new BackgroundFill(Color.GRAY, null, null )));
// so why not just use inline CSS?
field.setStyle("-fx-background-color: gray;");
// we need to add field to the rootPane as a child, Nodes can be added to anything that is a `Parent`, which a Pane is
rootPane.getChildren().add(field);
// lets try a button
// text inside button
JFXButton button = new JFXButton("Random Text");
// or just define it later
button.setText("Defined");
// or bind it to a constant value?!
button.textProperty().bind(StringConstant.valueOf("A constant"));
// more JFoenix UI control, let's make the button more defined
button.setButtonType(JFXButton.ButtonType.RAISED);
button.setBackground(new Background(new BackgroundFill(Color.rgb(97, 118, 207), null, null)));
// There's pretty much a infinite amount of ways you can do anything in JavaFX
// lets create a event handler
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// event gives you things you may be interested in
System.out.println("Clicked! Is shift down: " + event.isShiftDown());
}
});
// boilerplate is bothersome, lets try Java 8's concise lambdas
button.setOnMouseClicked(event -> System.out.println("Clicked! Is shift down: " + event.isShiftDown()));
// again, add it
// no layoutX or layoutY was specified, it will just be by default placed in the upper left corner (aka the origin)
rootPane.getChildren().add(button);
// all primary stages need a Scene for the window
Scene scene = new Scene(rootPane);
// additional content can be defined here for a scene, like background color
scene.setFill(Color.GRAY);
// set the scene
primaryStage.setScene(scene);
// Show the stage!
primaryStage.show();
// By default, closing all JavaFX Stages will implicitly exit the JavaFX platform, making it cumbersome to create a new stage
// For applications that get minimized to a tray icon, that is not desirable.
// That can be disabled by executing the following:
// Platform.setImplicitExit(false);
}
use of javafx.scene.layout.Background in project KNOBS by ESSICS.
the class Knob method initComponents.
protected void initComponents() {
angleStepProperty().bind(Bindings.divide(ANGLE_RANGE, Bindings.subtract(maxValueProperty(), minValueProperty())));
backgroundProperty().bind(Bindings.createObjectBinding(() -> Color.TRANSPARENT.equals(getBackgroundColor()) ? Background.EMPTY : new Background(new BackgroundFill(getBackgroundColor(), CornerRadii.EMPTY, Insets.EMPTY)), backgroundColorProperty()));
dropShadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), PREFERRED_WIDTH * 0.016, 0.0, 0, PREFERRED_WIDTH * 0.028);
highlight = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(255, 255, 255, 0.20), PREFERRED_WIDTH * 0.008, 0.0, 0, PREFERRED_WIDTH * 0.008);
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.20), PREFERRED_WIDTH * 0.008, 0.0, 0, -PREFERRED_WIDTH * 0.008);
highlight.setInput(innerShadow);
dropShadow.setInput(highlight);
barGradient = new ConicalGradient(reorderStops(getGradientStops()));
barArc = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, BAR_START_ANGLE, 0);
barArc.setType(ArcType.OPEN);
barArc.setStrokeLineCap(StrokeLineCap.ROUND);
barArc.setFill(null);
barArc.setStroke(barGradient.getImagePattern(new Rectangle(0, 0, PREFERRED_WIDTH, PREFERRED_HEIGHT)));
currentValueBarArc = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, BAR_START_ANGLE, 0);
currentValueBarArc.setType(ArcType.OPEN);
currentValueBarArc.setStrokeLineCap(StrokeLineCap.ROUND);
currentValueBarArc.setFill(null);
currentValueBarArc.strokeProperty().bind(currentValueColorProperty());
currentValueBarArc.lengthProperty().bind(Bindings.createDoubleBinding(() -> {
double localMin = (isZeroDetentEnabled() && getMinValue() < 0) ? Math.min(0, getMaxValue()) : getMinValue();
double length = getAngleStep() * (localMin - getCurrentValue());
if (length == 0) {
length = getAngleStep() * (getMinValue() - getMaxValue()) / 10000;
}
return length;
}, angleStepProperty(), currentValueProperty(), maxValueProperty(), minValueProperty(), zeroDetentEnabledProperty()));
currentValueBarArc.opacityProperty().bind(Bindings.createDoubleBinding(() -> {
double localMin = (isZeroDetentEnabled() && getMinValue() < 0) ? Math.min(0, getMaxValue()) : getMinValue();
double length = getAngleStep() * (localMin - getCurrentValue());
if (length == 0) {
return 0.6666;
} else {
return 1.0;
}
}, angleStepProperty(), currentValueProperty(), maxValueProperty(), minValueProperty(), zeroDetentEnabledProperty()));
currentValueBarArc.startAngleProperty().bind(Bindings.createDoubleBinding(() -> {
double angle = BAR_START_ANGLE;
if (isZeroDetentEnabled() && getMinValue() < 0) {
angle += Math.max(getAngleStep() * getMinValue(), -ANGLE_RANGE);
}
return angle;
}, angleStepProperty(), minValueProperty(), zeroDetentEnabledProperty()));
double center = PREFERRED_WIDTH * 0.5;
ring = Shape.subtract(new Circle(center, center, PREFERRED_WIDTH * 0.42), new Circle(center, center, PREFERRED_WIDTH * 0.3));
ring.fillProperty().bind(colorProperty());
ring.setEffect(dropShadow);
ring.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
if (!isDisabled() && !isDragDisabled()) {
touchRotate(e.getSceneX(), e.getSceneY());
}
});
ring.addEventHandler(MouseEvent.MOUSE_DRAGGED, e -> {
if (!isDisabled() && !isDragDisabled()) {
touchRotate(e.getSceneX(), e.getSceneY());
}
});
ring.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> {
if (!isDisabled() && !isDragDisabled()) {
fireTargeValueSet();
}
});
mainCircle = new Circle();
mainCircle.fillProperty().bind(Bindings.createObjectBinding(() -> getColor().darker().darker(), colorProperty()));
mainCircle.setOnMouseClicked(doubleClickHandler);
text = new Text(String.format(format, getCurrentValue()));
text.fillProperty().bind(textColorProperty());
text.setOnMouseClicked(doubleClickHandler);
text.setTextOrigin(VPos.CENTER);
targetText = new Text(String.format(format, getTargetValue()));
targetText.fillProperty().bind(Bindings.createObjectBinding(() -> getTextColor().darker(), textColorProperty()));
targetText.setOnMouseClicked(doubleClickHandler);
targetText.setTextOrigin(VPos.CENTER);
targetText.visibleProperty().bind(Bindings.createBooleanBinding(() -> isTargetValueAlwaysVisible() || !close(getCurrentValue(), getTargetValue(), (getMaxValue() - getMinValue()) * PROXIMITY_ERROR), targetValueAlwaysVisibleProperty(), currentValueProperty(), targetValueProperty(), maxValueProperty(), minValueProperty()));
unitText = new Text(getUnit());
unitText.fillProperty().bind(Bindings.createObjectBinding(() -> getTextColor().darker(), textColorProperty()));
unitText.setOnMouseClicked(doubleClickHandler);
unitText.setTextOrigin(VPos.CENTER);
textMinTag = new Polygon(0.0, 0.7, 0.6, 0.7, 0.6, 0.9, 0.0, 0.9);
textMinTag.fillProperty().bind(Bindings.createObjectBinding(() -> getColor().darker().darker(), colorProperty()));
textMinTag.visibleProperty().bind(extremaVisibleProperty());
textMin = new Text(String.format(format, getMinValue()));
textMin.fillProperty().bind(Bindings.createObjectBinding(() -> getTextColor().darker(), textColorProperty()));
textMin.setTextOrigin(VPos.CENTER);
textMin.visibleProperty().bind(extremaVisibleProperty());
textMaxTag = new Polygon(0.0, 0.7, 0.6, 0.7, 0.6, 0.9, 0.0, 0.9);
textMaxTag.fillProperty().bind(Bindings.createObjectBinding(() -> getColor().darker().darker(), colorProperty()));
textMaxTag.visibleProperty().bind(extremaVisibleProperty());
textMax = new Text(String.format(format, getMaxValue()));
textMax.fillProperty().bind(Bindings.createObjectBinding(() -> getTextColor().darker(), textColorProperty()));
textMax.setTextOrigin(VPos.CENTER);
textMax.visibleProperty().bind(extremaVisibleProperty());
tagBarArc = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.46, PREFERRED_HEIGHT * 0.46, BAR_START_ANGLE + 15, 50);
tagBarArc.setType(ArcType.OPEN);
tagBarArc.setStrokeLineCap(StrokeLineCap.ROUND);
tagBarArc.setFill(null);
tagBarArc.strokeProperty().bind(tagColorProperty());
tagBarArc.visibleProperty().bind(tagVisibleProperty());
indicatorRotate = new Rotate(-ANGLE_RANGE * 0.5, center, center);
indicatorGlow = new DropShadow(BlurType.TWO_PASS_BOX, getIndicatorColor(), PREFERRED_WIDTH * 0.020, 0.0, 0, 0);
indicatorInnerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.50), PREFERRED_WIDTH * 0.008, 0.0, 0, PREFERRED_WIDTH * 0.008);
indicatorHighlight = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(255, 255, 255, 0.35), PREFERRED_WIDTH * 0.008, 0.0, 0, -PREFERRED_WIDTH * 0.008);
indicatorRotate.angleProperty().bind(Bindings.subtract(Bindings.multiply(Bindings.subtract(targetValueProperty(), minValueProperty()), angleStepProperty()), ANGLE_RANGE * 0.5));
indicatorGlow.colorProperty().bind(selectionColorProperty());
indicatorHighlight.setInput(indicatorInnerShadow);
indicator = new Circle();
indicator.effectProperty().bind(Bindings.createObjectBinding(() -> isSelected() ? indicatorGlow : null, selectionColorProperty(), selectedProperty()));
indicator.disableProperty().bind(dragDisabledProperty());
indicator.fillProperty().bind(Bindings.createObjectBinding(() -> {
Color c = isSelected() ? getSelectionColor() : getIndicatorColor();
return isDragDisabled() ? c.deriveColor(0, 1, 0.92, 0.6) : c;
}, colorProperty(), dragDisabledProperty(), indicatorColorProperty(), selectionColorProperty(), selectedProperty()));
indicator.strokeProperty().bind(Bindings.createObjectBinding(() -> {
Color c = isSelected() ? getSelectionColor().darker().darker() : getIndicatorColor().darker().darker();
return isDragDisabled() ? c.deriveColor(0, 1, 0.92, 0.6) : c;
}, colorProperty(), dragDisabledProperty(), indicatorColorProperty(), selectionColorProperty(), selectedProperty()));
indicator.setMouseTransparent(true);
indicator.getTransforms().add(indicatorRotate);
Group indicatorGroup = new Group(indicator);
indicatorGroup.setEffect(indicatorHighlight);
pane = new Pane(barArc, currentValueBarArc, ring, mainCircle, text, targetText, unitText, textMinTag, textMin, textMaxTag, textMax, tagBarArc, indicatorGroup);
pane.setPrefSize(PREFERRED_HEIGHT, PREFERRED_HEIGHT);
pane.backgroundProperty().bind(Bindings.createObjectBinding(() -> new Background(new BackgroundFill(getColor().darker(), new CornerRadii(1024), Insets.EMPTY)), colorProperty()));
pane.setEffect(highlight);
Platform.runLater(() -> getChildren().setAll(pane));
}
use of javafx.scene.layout.Background in project JFoenix by jfoenixadmin.
the class JFXComboBox method defaultNodeConverter.
private static <T> NodeConverter<T> defaultNodeConverter() {
return new NodeConverter<T>() {
@Override
public Node toNode(T object) {
if (object == null) {
return null;
}
StackPane selectedValueContainer = new StackPane();
selectedValueContainer.getStyleClass().add("combo-box-selected-value-container");
selectedValueContainer.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, null, null)));
Label selectedValueLabel = object instanceof Label ? new Label(((Label) object).getText()) : new Label(object.toString());
selectedValueLabel.setTextFill(Color.BLACK);
selectedValueContainer.getChildren().add(selectedValueLabel);
StackPane.setAlignment(selectedValueLabel, Pos.CENTER_LEFT);
StackPane.setMargin(selectedValueLabel, new Insets(0, 0, 0, 5));
return selectedValueContainer;
}
@SuppressWarnings("unchecked")
@Override
public T fromNode(Node node) {
return (T) node;
}
@Override
public String toString(T object) {
if (object == null) {
return null;
}
if (object instanceof Label) {
return ((Label) object).getText();
}
return object.toString();
}
};
}
use of javafx.scene.layout.Background in project JFoenix by jfoenixadmin.
the class JFXDecorator method initializeContainers.
private void initializeContainers(Node node, boolean fullScreen, boolean max, boolean min) {
buttonsContainer = new HBox();
buttonsContainer.getStyleClass().add("jfx-decorator-buttons-container");
buttonsContainer.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY)));
// BINDING
buttonsContainer.setPadding(new Insets(4));
buttonsContainer.setAlignment(Pos.CENTER_RIGHT);
// customize decorator buttons
List<JFXButton> btns = new ArrayList<>();
if (fullScreen) {
btns.add(btnFull);
}
if (min) {
btns.add(btnMin);
}
if (max) {
btns.add(btnMax);
// maximize/restore the window on header double click
buttonsContainer.addEventHandler(MouseEvent.MOUSE_CLICKED, (mouseEvent) -> {
if (mouseEvent.getClickCount() == 2) {
btnMax.fire();
}
});
}
btns.add(btnClose);
text = new Text();
text.getStyleClass().addAll("jfx-decorator-text", "title", "jfx-decorator-title");
text.setFill(Color.WHITE);
// binds the Text's text to title
text.textProperty().bind(title);
// binds title to the primaryStage's title
title.bind(primaryStage.titleProperty());
graphicContainer = new HBox();
graphicContainer.setPickOnBounds(false);
graphicContainer.setAlignment(Pos.CENTER_LEFT);
graphicContainer.getChildren().setAll(text);
HBox graphicTextContainer = new HBox(graphicContainer, text);
graphicTextContainer.getStyleClass().add("jfx-decorator-title-container");
graphicTextContainer.setAlignment(Pos.CENTER_LEFT);
graphicTextContainer.setPickOnBounds(false);
HBox.setHgrow(graphicTextContainer, Priority.ALWAYS);
HBox.setMargin(graphicContainer, new Insets(0, 8, 0, 8));
buttonsContainer.getChildren().setAll(graphicTextContainer);
buttonsContainer.getChildren().addAll(btns);
buttonsContainer.addEventHandler(MouseEvent.MOUSE_ENTERED, (enter) -> allowMove = true);
buttonsContainer.addEventHandler(MouseEvent.MOUSE_EXITED, (enter) -> {
if (!isDragging) {
allowMove = false;
}
});
buttonsContainer.setMinWidth(180);
contentPlaceHolder.getStyleClass().add("jfx-decorator-content-container");
contentPlaceHolder.setMinSize(0, 0);
StackPane clippedContainer = new StackPane(node);
contentPlaceHolder.getChildren().add(clippedContainer);
((Region) node).setMinSize(0, 0);
VBox.setVgrow(contentPlaceHolder, Priority.ALWAYS);
contentPlaceHolder.getStyleClass().add("resize-border");
contentPlaceHolder.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(0, 4, 4, 4))));
// BINDING
Rectangle clip = new Rectangle();
clip.widthProperty().bind(clippedContainer.widthProperty());
clip.heightProperty().bind(clippedContainer.heightProperty());
clippedContainer.setClip(clip);
this.getChildren().addAll(buttonsContainer, contentPlaceHolder);
}
Aggregations