modules/controls/src/main/java/com/sun/javafx/scene/control/EmbeddedTextContextMenuContent.java

Print this page




  92             MenuItemContainer menuItemContainer = new MenuItemContainer(item);
  93             menuItemContainer.visibleProperty().bind(item.visibleProperty());
  94             menuBox.getChildren().add(menuItemContainer);
  95         }
  96     }
  97 
  98     private void hideAllMenus(MenuItem item) {
  99         contextMenu.hide();
 100 
 101         Menu parentMenu;
 102         while ((parentMenu = item.getParentMenu()) != null) {
 103             parentMenu.hide();
 104             item = parentMenu;
 105         }
 106         if (parentMenu == null && item.getParentPopup() != null) {
 107             item.getParentPopup().hide();
 108         }
 109     }
 110 
 111     @Override protected double computePrefHeight(double width) {
 112         final double pointerHeight = snapSize(pointer.prefHeight(width));
 113         final double menuBoxHeight = snapSize(menuBox.prefHeight(width));
 114         return snappedTopInset() + pointerHeight + menuBoxHeight + snappedBottomInset();
 115     }
 116 
 117     @Override protected double computePrefWidth(double height) {
 118         final double menuBoxWidth = snapSize(menuBox.prefWidth(height));
 119         return snappedLeftInset() + menuBoxWidth + snappedRightInset();
 120     }
 121 
 122     @Override protected void layoutChildren() {
 123         final double left = snappedLeftInset();
 124         final double right = snappedRightInset();
 125         final double top = snappedTopInset();
 126         final double width = getWidth() - (left + right);
 127         final double pointerWidth = snapSize(Utils.boundedSize(pointer.prefWidth(-1), pointer.minWidth(-1), pointer.maxWidth(-1)));
 128         final double pointerHeight = snapSize(Utils.boundedSize(pointer.prefWidth(-1), pointer.minWidth(-1), pointer.maxWidth(-1)));
 129         final double menuBoxWidth = snapSize(Utils.boundedSize(menuBox.prefWidth(-1), menuBox.minWidth(-1), menuBox.maxWidth(-1)));
 130         final double menuBoxHeight = snapSize(Utils.boundedSize(menuBox.prefWidth(-1), menuBox.minWidth(-1), menuBox.maxWidth(-1)));
 131         double sceneX = 0;
 132         double screenX = 0;
 133         double pointerX = 0;
 134 
 135         // Get the positions of the cursor from the TextArea/TextField and draw the arrow underneath it.
 136         Map<Object,Object> properties = null;
 137         if (contextMenu.getOwnerNode() instanceof TextArea) {
 138             properties = ((TextArea)contextMenu.getOwnerNode()).getProperties();
 139         } else if (contextMenu.getOwnerNode() instanceof TextField) {
 140             properties = ((TextField)contextMenu.getOwnerNode()).getProperties();
 141         }
 142 
 143         if (properties != null) {
 144             if (properties.containsKey("CONTEXT_MENU_SCENE_X")) {
 145                 sceneX = Double.valueOf(properties.get("CONTEXT_MENU_SCENE_X").toString());
 146                 properties.remove("CONTEXT_MENU_SCENE_X");
 147             }
 148 
 149             if (properties.containsKey("CONTEXT_MENU_SCREEN_X")) {
 150                 screenX = Double.valueOf(properties.get("CONTEXT_MENU_SCREEN_X").toString());




  92             MenuItemContainer menuItemContainer = new MenuItemContainer(item);
  93             menuItemContainer.visibleProperty().bind(item.visibleProperty());
  94             menuBox.getChildren().add(menuItemContainer);
  95         }
  96     }
  97 
  98     private void hideAllMenus(MenuItem item) {
  99         contextMenu.hide();
 100 
 101         Menu parentMenu;
 102         while ((parentMenu = item.getParentMenu()) != null) {
 103             parentMenu.hide();
 104             item = parentMenu;
 105         }
 106         if (parentMenu == null && item.getParentPopup() != null) {
 107             item.getParentPopup().hide();
 108         }
 109     }
 110 
 111     @Override protected double computePrefHeight(double width) {
 112         final double pointerHeight = snapSizeY(pointer.prefHeight(width));
 113         final double menuBoxHeight = snapSizeY(menuBox.prefHeight(width));
 114         return snappedTopInset() + pointerHeight + menuBoxHeight + snappedBottomInset();
 115     }
 116 
 117     @Override protected double computePrefWidth(double height) {
 118         final double menuBoxWidth = snapSizeX(menuBox.prefWidth(height));
 119         return snappedLeftInset() + menuBoxWidth + snappedRightInset();
 120     }
 121 
 122     @Override protected void layoutChildren() {
 123         final double left = snappedLeftInset();
 124         final double right = snappedRightInset();
 125         final double top = snappedTopInset();
 126         final double width = getWidth() - (left + right);
 127         final double pointerWidth = snapSizeX(Utils.boundedSize(pointer.prefWidth(-1), pointer.minWidth(-1), pointer.maxWidth(-1)));
 128         final double pointerHeight = snapSizeY(Utils.boundedSize(pointer.prefWidth(-1), pointer.minWidth(-1), pointer.maxWidth(-1)));
 129         final double menuBoxWidth = snapSizeX(Utils.boundedSize(menuBox.prefWidth(-1), menuBox.minWidth(-1), menuBox.maxWidth(-1)));
 130         final double menuBoxHeight = snapSizeY(Utils.boundedSize(menuBox.prefWidth(-1), menuBox.minWidth(-1), menuBox.maxWidth(-1)));
 131         double sceneX = 0;
 132         double screenX = 0;
 133         double pointerX = 0;
 134 
 135         // Get the positions of the cursor from the TextArea/TextField and draw the arrow underneath it.
 136         Map<Object,Object> properties = null;
 137         if (contextMenu.getOwnerNode() instanceof TextArea) {
 138             properties = ((TextArea)contextMenu.getOwnerNode()).getProperties();
 139         } else if (contextMenu.getOwnerNode() instanceof TextField) {
 140             properties = ((TextField)contextMenu.getOwnerNode()).getProperties();
 141         }
 142 
 143         if (properties != null) {
 144             if (properties.containsKey("CONTEXT_MENU_SCENE_X")) {
 145                 sceneX = Double.valueOf(properties.get("CONTEXT_MENU_SCENE_X").toString());
 146                 properties.remove("CONTEXT_MENU_SCENE_X");
 147             }
 148 
 149             if (properties.containsKey("CONTEXT_MENU_SCREEN_X")) {
 150                 screenX = Double.valueOf(properties.get("CONTEXT_MENU_SCREEN_X").toString());