拖放问题(Mac)

时间:2012-05-28 14:29:59

标签: macos javafx-2

我在运行我的代码时出现了一些问题,这些代码在Windows下运行,现在我已经在Mac上了。这个与拖放有关,它曾经用于Windows(写一次,调试到处都是!)但是现在没有触发onDragDropped事件(我已经使用System.out.println()进行了测试)。这是代码。任何帮助表示赞赏。提前致谢

    HRWindowGridPane.setOnDragEntered(new EventHandler<DragEvent>() {


        @Override
        public void handle(DragEvent event) {
            System.out.println("Drag entered");
            lblPhoto.setEffect(finalBlend);
            event.consume();
        }
    });

    HRWindowGridPane.setOnDragExited(new EventHandler<DragEvent>() {

        @Override
        public void handle(DragEvent event) {
            lblPhoto.setEffect(null);
            System.out.println("Drag exited");
            event.consume();
        }
    });

    EventHandler<DragEvent> onDragOver = new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data is dragged over the target */
            /* accept it only if it is not dragged from the same node 
             * and if it has a string data */
            if (event.getGestureSource() != HRWindowGridPane &&
                    event.getDragboard().hasFiles()) {
                /* allow for both copying and moving, whatever user chooses */
                event.acceptTransferModes(TransferMode.ANY);
                System.out.println("Drag over");
            }

            event.consume();
        }
    };
    HRWindowGridPane.setOnDragOver(onDragOver);

    HRWindowGridPane.setOnDragDropped(new EventHandler<DragEvent>() 
    {

        @Override
        public void handle(DragEvent event) 
        {
            System.out.println("Drag dropping");
            Dragboard db = event.getDragboard();
            System.out.println("Drag dropped: got dragboard from event!");

            if(db.hasFiles())
            {
                System.out.println("Drag dropped: dragboard has files!");
                 for(File file:db.getFiles())
                 {
                     if(file.getName().contains(".jpg") ||  file.getName().contains(".jpeg") || file.getName().contains(".JPG"))
                     {
                        Image img;
                        try
                        {
                            System.out.println("Everything is fine until image processing... hmmm");
                            img = new Image(file.toURI().toURL().toString(), 118.0, 88.0, false, true);
                            ImageView view = new ImageView(img);
                            view.setFitWidth(118.0);
                            view.setFitHeight(88.0);
                            view.resize(118.0, 88.0);
                            lblPhoto.setGraphic(view);
                            avatarImage = file;
                        } 
                        catch (IOException e) 
                        {
                            e.printStackTrace();
                        }

                     }
                     else
                     {
                         AlertWindow alert = new AlertWindow("Falha", "O Arquivo não é uma imagem JPG válida");
                         try 
                         {
                            Stage stage = new Stage();

                            alert.start(stage);

                            stage.toFront();
                            HRWindowGridPane.toBack();
                            stage.centerOnScreen();
                            stage.show();

                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                     }

                 }


            }

            event.setDropCompleted(true);
            event.consume();
        }

    });

    HRWindowGridPane.setOnDragDone(new EventHandler<DragEvent>() {

        @Override
        public void handle(DragEvent event) 
        {
            System.out.println("Drag done");
        }
    });

有关该系统的更多信息:

Brunos-MacBook-Pro:~ bruno$ java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

Javafx版本2.1

1 个答案:

答案 0 :(得分:0)

问题出现在jira现在是一个bug。这是我从另一个论坛获得的链接,希望在2.2为ga时修复。

http://javafx-jira.kenai.com/browse/RT-20253

修改

更新此答案。当JavaFX-2成为GA时,解决了拖放问题。它的工作就像MacOS X上的魅力,jre 1.7 +