使用场景/舞台作为按钮打开另一个场景/舞台

时间:2017-01-09 17:19:59

标签: java javafx

我在解决这个问题时遇到了困难,而且我无法找到解决这个问题的正确答案。我希望场景/舞台用作按钮来打开另一个场景/舞台,并且两者都在同一个方法上调用。这是完整的方法:

 public void createChatWindowMinimized(int agentKey, String message)
    {            
        LOGGER.enterMethod();

        try{                
            ChatAgentsController chatController = null;

            User agent = getModel().getRealtimeAgentNode().getUser(agentKey);
            String firstNameLastName = agent.getFirstname() + " " + agent.getLastName();

            UserAvatar userAvatar = getModel().getRealtimeAgentNode().getUserAvatar(agentKey);

            ImageView agentAvatar;

            agentAvatar = new ImageView();

            Stage toastStage = new Stage();
            toastStage.initStyle(StageStyle.UNDECORATED);
            toastStage.setHeight(120);
            toastStage.setWidth(250);


            BorderPane toastBorderPane = new BorderPane();
            Scene toastScene = new Scene(toastBorderPane);
            toastScene.getStylesheets().add(this.getClass().getResource("MessageToaster.css").toExternalForm());

            if(userAvatar == null || userAvatar.getBuffer() == null)                            
                agentAvatar.getStyleClass().add("AgentDefaultAvatar");
            else            
                agentAvatar.setImage(new Image(new ByteArrayInputStream(userAvatar.getBuffer()), 48, 48, true, true) );

            VBox vboxToastImage = new VBox();
            vboxToastImage.getStyleClass().add("ToasterImage");                
            ImageView imgToastAgent = agentAvatar;
            imgToastAgent.setFitHeight(60);
            imgToastAgent.setFitWidth(60);                
            vboxToastImage.getChildren().add(imgToastAgent);
            toastBorderPane.setLeft(vboxToastImage);

            VBox vboxInCenter = new VBox();
            Label userName = new Label(firstNameLastName);
            userName.getStyleClass().add("ToasterUserName");

            Text toasterContent = new Text(message);
            toasterContent.getStyleClass().add("ToasterMessage");

            vboxInCenter.getChildren().addAll(userName, toasterContent);
            vboxInCenter.getStyleClass().add("ToasterBox");
            toastBorderPane.setCenter(vboxInCenter);
            toastBorderPane.getStyleClass().add("ToasterBorderPane");


            Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();

            toastStage.setX(primaryScreenBounds.getMinX() + primaryScreenBounds.getWidth() - TOASTER_WINDOW_WIDTH);
            toastStage.setY(primaryScreenBounds.getMinY() + primaryScreenBounds.getHeight() - TOASTER_WINDOW_HEIGHT);                
            toastStage.setScene(toastScene);
            // check if a chat window for this user already exists
            if (chatAgentsMap.containsKey(agentKey))
            {
                // chat window has been created
                chatController = chatAgentsMap.get(agentKey);
                LOGGER.message(String.format("Showing chat window for agent '%d'.", agentKey));                    
                if(!chatController.getChatStage().isFocused()){
                    toastStage.show();
                    chatController.getChatStage().show();
                }
            }
            else
            {
                // create new chat window                    
                LOGGER.message(String.format("Creating chat window for agent '%d'.", agentKey));                    
                chatController = ChatAgentsController.create(this, agentKey, connectedToOpenfireServer, true);
                toastStage.show();
                toastStage.setAlwaysOnTop(true);

                 //-----Here is where I want that the toastStage or the toastScene is clickable by mouse and that it opens the window already created chatController


                chatController.getChatStage().show();
                chatAgentsMap.put(agentKey, chatController);
            }

            if (chatController != null && message != null)  // append received message to the chat text area
                chatController.addChatEntry(agentKey, message);
        }
        catch (Throwable t)
        {
            LOGGER.error(t);
        }
        finally
        {
            LOGGER.leaveMethod();
        }
    }

我一直试图使用来自CLICK的鼠标事件,但是我没有用,因为我实例化另一个窗口的变量(chatController.getChatStage(。。show())不是最终的。

0 个答案:

没有答案