简体   繁体   中英

Gluon Charm 4.0.0 GlassPane not modal anymore?

I used following code to install a Layer in the GlassPane and show it:

glassPane.getLayers().add(myLayer);
MobileApplication.getInstance().addLayerFactory("myLayer", ()-> myLayer);

MobileApplication.getInstance().showLayer("myLayer");

While on Charm 3.0.0 the layer was showing modal on top of the current view, on Charm 4.0.0 the layer isn't modal anymore. So is there a build in function to show it modal again, or do we have to use an EventFilter ?

EDIT:

ProgressLayer complete code (not adapted to Charm 4.0.0)

Simplified code of ProgressLayer:

public class ProgressLayer extends Layer {

   private static final GlassPane GLASS_PANE = MobileApplication.getInstance().getGlassPane(); 
   private String layerName;

   private StackPane              root;
   private Circle                 clip;
   private double                 size;

     public ProgressLayer(Node icon, double radius, String layerName) {
        setAutoHide(false);
        this.layerName = layerName;
        size = radius * 2; 

        ProgressIndicator progress = new ProgressIndicator();
        progress.setStyle("-fx-color:#ff9100");
        progress.setRadius(radius);

        root = new StackPane(progress);

        if (icon != null) {
          icon.getStyleClass().add("progress-icon");

          clip = new Circle(radius-1);
          icon.setClip(clip);

          root.getChildren().add(icon);
        }

        getChildren().add(root);
        GLASS_PANE.getLayers().add(this);
    }

    @Override
    public void layoutChildren() {
        root.setVisible(isShowing());
        if (!isShowing()) {
          return;
        }

        root.resizeRelocate((GLASS_PANE.getWidth() - size) / 2, (GLASS_PANE.getHeight() - size) / 2, size, size);
        if (clip != null) {
          clip.setLayoutX(root.getWidth() / 2 -1);
          clip.setLayoutY(root.getHeight() /2 -1);
        }
    }

    public void setOnCancelled(EventHandler<MouseEvent> handler) {
        root.setOnMouseClicked(handler);
   }
}

在此处输入图片说明

As long as an operation is running, the progressLayer will be shown, and you are not able to interrupt the operation or hide the layer, unless you press the purple icon in the center:

progressLayer.setOnCancelled(e -> hideLayer(progressLayer.getLayerName()));

And here is the problem. When root doesn't use the whole screensize, UI controls that are not covered by root like buttons eg can be activated. This behaviour is in contrast to Gluon Charm 3.0.0

Have you tried myLayer.setAutoHide(false) ?

According to JavaDoc for autoHideProperty() :

Represents whether this Layer should hide when it is clicked outside its bounds - by default this is true.

EDIT

This is a small project that works for me:

build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.1.1'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'com.testmodal.TestModal'

dependencies {
    compile 'com.gluonhq:charm:4.0.1'
}

jfxmobile {
    downConfig {
        version = '3.0.0'
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'com.gluonhq.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}

TestModal

public class TestModal extends MobileApplication {

    public static final String BASIC_VIEW = HOME_VIEW;
    public static final String BASIC_LAYER = "My Layer";

    @Override
    public void init() {
        addViewFactory(BASIC_VIEW, () -> new BasicView(BASIC_VIEW));
        addLayerFactory(BASIC_LAYER, () -> new ProgressLayer(BASIC_LAYER));
    }

    @Override
    public void postInit(Scene scene) {
        Swatch.BLUE.assignTo(scene);
        ((Stage) scene.getWindow()).getIcons().add(new Image(TestModal.class.getResourceAsStream("/icon.png")));
    }

    class ProgressLayer extends Layer {

        private final Node root;

        public ProgressLayer(String layerName) {
            setAutoHide(false);

            ProgressIndicator progress = new ProgressIndicator();
            progress.setRadius(100);

            root = new StackPane(progress);
            getChildren().add(root);
            getGlassPane().getLayers().add(this);

            showingProperty().addListener((obs, ov, nv) -> {
                if (nv) {
                    setBackgroundFade(0.5);
                    PauseTransition p = new PauseTransition(Duration.seconds(3));
                    p.setOnFinished(e -> hideLayer(BASIC_LAYER));

                    p.playFromStart();
                }
            });
        }

        @Override
        public void layoutChildren() {
            root.resize(getGlassPane().getWidth(), getGlassPane().getHeight());
        }
    }
}

BasicView

public class BasicView extends View {

    public BasicView(String name) {
        super(name);

        Button button = new Button("Show Progress");
        button.setOnAction(e -> {
            MobileApplication.getInstance().showLayer(TestModal.BASIC_LAYER);
        });

        VBox controls = new VBox(button);
        controls.setAlignment(Pos.CENTER);

        setCenter(controls);
    }

    @Override
    protected void updateAppBar(AppBar appBar) {
        appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> System.out.println("Menu")));
        appBar.setTitleText("Basic View");
        appBar.getActionItems().add(MaterialDesignIcon.SEARCH.button(e -> System.out.println("Search")));
    }
}

When I run it, and click on the button, the background fade is set to 0.5 just to see that all the scene is covered by the glass pane, and I can't click on any of the underlying buttons until the layer is hidden via the pause transition.

层

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM