Gluon Charm 4.0.0 GlassPane不再是模态?

时间:2016-10-31 17:47:43

标签: gluon gluon-mobile

我使用以下代码在Layer中安装GlassPane并显示:

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

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

Charm 3.0.0上,图层在当前视图的顶部显示模态,在Charm 4.0.0上图层不再是模态。 那么是否有一个内置函数来再次显示它的模态,或者我们是否必须使用EventFilter

修改

ProgressLayer complete code (不适应魅力4.0.0)

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);
   }
}

enter image description here

只要操作正在运行,就会显示progressLayer,除非您按下中间的紫色图标,否则您无法中断操作或隐藏图层:

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

这就是问题所在。 root未使用整个屏幕大小时,root类似按钮未涵盖的UI控件,例如可以激活。这种行为与Gluon Charm 3.0.0相反

1 个答案:

答案 0 :(得分:1)

您是否尝试过myLayer.setAutoHide(false)

根据autoHideProperty()的{​​{1}}:

  

表示该图层在其边界外被点击时是否应该隐藏 - 默认情况下这是真的。

修改

这是一个适合我的小项目:

的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")));
    }
}

当我运行它并点击按钮时,背景淡化设置为0.5只是为了看到所有场景都被玻璃窗格覆盖,我不能点击任何底层按钮,直到图层通过暂停过渡隐藏。

JavaDoc