下面列出了怎么用javafx.scene.effect.BoxBlur的API类实例代码及写法,或者点击链接到github查看源代码。
@FXML
private void changePasswordAction(ActionEvent event)
{
mainTopAnchorPane.setEffect(new BoxBlur());
passwordStage = new Stage();
passwordStage.setOnCloseRequest(new EventHandler<WindowEvent>()
{
@Override
public void handle(WindowEvent t)
{
mainTopAnchorPane.effectProperty().setValue(null);
}
});
passwordStage.setTitle("Change Password");
passwordStage.initModality(Modality.APPLICATION_MODAL);
passwordStage.initStyle(StageStyle.UTILITY);
passwordStage.setResizable(false);
try
{
Parent passwordParent = FXMLLoader.load(getClass().getResource("changepassword.fxml"));
passwordStage.setScene(new Scene(passwordParent));
passwordStage.show();
} catch (IOException ex)
{
}
}
@FXML
private void activityLogButtonAction(ActionEvent event)
{
mainTopAnchorPane.setEffect(new BoxBlur());
passwordStage = new Stage();
passwordStage.setOnCloseRequest(new EventHandler<WindowEvent>()
{
@Override
public void handle(WindowEvent t)
{
mainTopAnchorPane.effectProperty().setValue(null);
}
});
passwordStage.setTitle("Activity Log");
passwordStage.initModality(Modality.APPLICATION_MODAL);
passwordStage.initStyle(StageStyle.UTILITY);
passwordStage.setResizable(false);
try
{
Parent passwordParent = FXMLLoader.load(getClass().getResource("activityLog.fxml"));
passwordStage.setScene(new Scene(passwordParent));
passwordStage.show();
} catch (IOException ex)
{
}
}
@FXML
private void viewPayBillAction(ActionEvent event)
{
MainProgramSceneController.mainTopAnchorPane.setEffect(new BoxBlur());
billStage = new Stage();
billStage.setOnCloseRequest(new EventHandler<WindowEvent>()
{
@Override
public void handle(WindowEvent t)
{
MainProgramSceneController.mainTopAnchorPane.effectProperty().setValue(null);
}
});
billStage.setTitle("View And Pay Due Bills");
billStage.initModality(Modality.APPLICATION_MODAL);
billStage.initStyle(StageStyle.UTILITY);
billStage.setResizable(false);
try
{
Parent passwordParent = FXMLLoader.load(getClass().getResource("viewPayBill.fxml"));
billStage.setScene(new Scene(passwordParent));
billStage.show();
} catch (IOException ex)
{
}
}
public static void showMaterialDialog(StackPane root, Node nodeToBeBlurred, List<JFXButton> controls, String header, String body) {
BoxBlur blur = new BoxBlur(3, 3, 3);
if (controls.isEmpty()) {
controls.add(new JFXButton("Okay"));
}
JFXDialogLayout dialogLayout = new JFXDialogLayout();
JFXDialog dialog = new JFXDialog(root, dialogLayout, JFXDialog.DialogTransition.TOP);
controls.forEach(controlButton -> {
controlButton.getStyleClass().add("dialog-button");
controlButton.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent mouseEvent) -> {
dialog.close();
});
});
dialogLayout.setHeading(new Label(header));
dialogLayout.setBody(new Label(body));
dialogLayout.setActions(controls);
dialog.show();
dialog.setOnDialogClosed((JFXDialogEvent event1) -> {
nodeToBeBlurred.setEffect(null);
});
nodeToBeBlurred.setEffect(blur);
}
public Node toNode() {
Vector screenSize = viewport.getSizeSC();
if (screenSize.equals(currentScreenSize))
return microscope;
currentScreenSize = screenSize;
double minScreenSize = Math.min(screenSize.x, screenSize.y);
double maxScreenSize = Math.max(screenSize.x, screenSize.y);
// Leave an ample left/bottom black margin - otherwise, the background
// will be visible for a moment while enlarging the window.
Rectangle black = new Rectangle(-10, -10, maxScreenSize + 1000, maxScreenSize + 1000);
Circle hole = new Circle(screenSize.x / 2, screenSize.y / 2, minScreenSize / 2.03);
microscope = Shape.subtract(black, hole);
microscope.setEffect(new BoxBlur(5, 5, 1));
return microscope;
}
public void initDisabledBuild(){
isDisabledInLauncher = true;
BoxBlur b = new BoxBlur();
b.setWidth(5.0);
b.setHeight(5.0);
b.setIterations(1);
Blend bl = new Blend();
bl.setMode(BlendMode.SRC_OVER);
bl.setOpacity(1.0);
bl.setTopInput(b);
disabledPanel.setEffect(b);
//disabledPanel.setVisible(true);
nonValidPanel.setVisible(true);
}
private static Group createViewer(final MediaPlayer player, final double scale, boolean blur) {
Group mediaGroup = new Group();
final MediaView mediaView = new MediaView(player);
if (blur) {
BoxBlur bb = new BoxBlur();
bb.setWidth(4);
bb.setHeight(4);
bb.setIterations(1);
mediaView.setEffect(bb);
}
double width = player.getMedia().getWidth();
double height = player.getMedia().getHeight();
mediaView.setFitWidth(width);
mediaView.setTranslateX(-width/2.0);
mediaView.setScaleX(-scale);
mediaView.setFitHeight(height);
mediaView.setTranslateY(-height/2.0);
mediaView.setScaleY(scale);
mediaView.setDepthTest(DepthTest.ENABLE);
mediaGroup.getChildren().add(mediaView);
return mediaGroup;
}
private static Group createViewer(final MediaPlayer player, final double scale, boolean blur) {
Group mediaGroup = new Group();
final MediaView mediaView = new MediaView(player);
if (blur) {
BoxBlur bb = new BoxBlur();
bb.setWidth(4);
bb.setHeight(4);
bb.setIterations(1);
mediaView.setEffect(bb);
}
double width = player.getMedia().getWidth();
double height = player.getMedia().getHeight();
mediaView.setFitWidth(width);
mediaView.setTranslateX(-width/2.0);
mediaView.setScaleX(-scale);
mediaView.setFitHeight(height);
mediaView.setTranslateY(-height/2.0);
mediaView.setScaleY(scale);
mediaView.setDepthTest(DepthTest.ENABLE);
mediaGroup.getChildren().add(mediaView);
return mediaGroup;
}
protected void onMouseEvent(MouseEvent event) {
if (pressed == null) {
// no processing if no node is pressed
return;
}
// node is pressed, process all mouse events
EventType<? extends Event> type = event.getEventType();
if (type.equals(MouseEvent.MOUSE_RELEASED)) {
System.out.println("release " + pressed);
pressed.setEffect(null);
IAnchor ifxAnchor = anchors.get(pressed);
if (ifxAnchor != null) {
Set<AnchorKey> keys = ifxAnchor.positionsUnmodifiableProperty()
.keySet();
for (AnchorKey key : keys) {
key.getAnchored().setEffect(new BoxBlur());
}
}
pressed = null;
nodesUnderMouse.clear();
} else if (type.equals(MouseEvent.MOUSE_DRAGGED)) {
double dx = event.getSceneX() - startMousePosition.getX();
double dy = event.getSceneY() - startMousePosition.getY();
pressed.setLayoutX(startLayoutPosition.getX() + dx);
pressed.setLayoutY(startLayoutPosition.getY() + dy);
boolean changed = updateNodesUnderMouse(event.getSceneX(),
event.getSceneY());
if (changed) {
System.out.println(
"targets: " + Arrays.asList(nodesUnderMouse.toArray()));
}
}
}
public static void disableSound() {
// logger.log(Level.SEVERE, "Disabling the sound UI in MainScene.");
BoxBlur blur = new BoxBlur(1.0, 1.0, 1);
soundVBox.setEffect(blur);
if (musicSlider != null) {
musicSlider.setDisable(true);// .setValue(0);
musicSlider.setEffect(blur);
}
if (soundEffectSlider != null) {
soundEffectSlider.setDisable(true);// .setValue(0);
soundEffectSlider.setEffect(blur);
}
if (musicMuteBox != null) {
musicMuteBox.setDisable(true);
musicMuteBox.setEffect(blur);
}
if (soundEffectMuteBox != null) {
soundEffectMuteBox.setEffect(blur);
soundEffectMuteBox.setDisable(true);
}
// if (effectLabel != null)
effectLabel.setEffect(blur);
// if (trackLabel != null)
trackLabel.setEffect(blur);
}
protected void onSceneSizeChange(double width, double height) {
// clear visuals
anchors.clear();
contentLayer.getChildren().clear();
handleLayer.getChildren().clear();
// generate contents
int count = 64;
for (int i = 0; i < count; i++) {
handleLayer.getChildren().add(draggable(generate(width, height)));
}
// generate random curves between
for (int i = 0; i < count; i++) {
Node n = handleLayer.getChildren()
.get((int) (Math.random() * count / 2));
Node m = null;
while (m == null || m == n) {
m = handleLayer.getChildren()
.get((int) (Math.random() * count / 2));
}
Connection connection = new Connection();
IAnchor an, am;
if (anchors.containsKey(n)) {
an = anchors.get(n);
} else {
an = new DynamicAnchor(n);
anchors.put(n, an);
}
if (anchors.containsKey(m)) {
am = anchors.get(m);
} else {
am = new DynamicAnchor(n);
anchors.put(m, am);
}
connection.setStartAnchor(an);
connection.setEndAnchor(am);
connection.setEffect(new BoxBlur());
contentLayer.getChildren().add(connection);
}
}
private Scene createScene()
{
final int verticalSpacing = 5;
VBox info = new VBox(verticalSpacing);
Text name = new Text(RESOURCES.getString("application.name"));
name.setStyle("-fx-font-size: 18pt;");
Text version = new Text(String.format("%s %s", RESOURCES.getString("dialog.about.version"),
UMLEditor.VERSION));
Text copyright = new Text(RESOURCES.getString("application.copyright"));
Text license = new Text(RESOURCES.getString("dialog.about.license"));
Text quotes = new Text(RESOURCES.getString("quotes.copyright"));
Hyperlink link = new Hyperlink(RESOURCES.getString("dialog.about.link"));
link.setBorder(Border.EMPTY);
link.setPadding(new Insets(0));
link.setOnMouseClicked(e -> UMLEditor.openBrowser(RESOURCES.getString("dialog.about.url")));
link.setUnderline(true);
link.setFocusTraversable(false);
info.getChildren().addAll(name, version, copyright, license, link, quotes);
final int padding = 15;
HBox layout = new HBox(padding);
layout.setStyle("-fx-background-color: gainsboro;");
layout.setPadding(new Insets(padding));
layout.setAlignment(Pos.CENTER_LEFT);
ImageView logo = new ImageView(RESOURCES.getString("application.icon"));
logo.setEffect(new BoxBlur());
layout.getChildren().addAll(logo, info);
layout.setAlignment(Pos.TOP_CENTER);
aStage.requestFocus();
aStage.addEventHandler(KeyEvent.KEY_PRESSED, pEvent ->
{
if (pEvent.getCode() == KeyCode.ENTER)
{
aStage.close();
}
});
return new Scene(layout);
}
private Effect getBlurEffect(double zoomLevel) {
int blurAmount = Math.min((int) (15 * (zoomLevel - 0.7)), 10);
return new BoxBlur(blurAmount, blurAmount, 1);
}