< prev index next >

modules/javafx.web/src/main/java/com/sun/javafx/webkit/theme/ContextMenuImpl.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.webkit.theme;
  27 
  28 import java.util.logging.Logger;
  29 import java.util.logging.Level;
  30 
  31 import javafx.event.ActionEvent;
  32 import javafx.event.EventHandler;
  33 
  34 import javafx.scene.control.Separator;
  35 import javafx.scene.control.ContextMenu;
  36 import javafx.scene.control.MenuItem;
  37 import javafx.scene.control.Menu;
  38 import javafx.scene.control.CheckMenuItem;
  39 
  40 import javafx.collections.ObservableList;
  41 import javafx.collections.FXCollections;
  42 
  43 import com.sun.webkit.ContextMenuItem;
  44 
  45 public final class ContextMenuImpl extends com.sun.webkit.ContextMenu {
  46 
  47     private final static Logger log = Logger.getLogger(ContextMenuImpl.class.getName());
  48 
  49     private final ObservableList<ContextMenuItem> items =
  50             FXCollections.observableArrayList();
  51 
  52     @Override protected void show(final ShowContext showContext, int x, int y) {
  53         if (log.isLoggable(Level.FINE)) {
  54             log.log(Level.FINE, "show at [{0}, {1}]", new Object[] {x, y});
  55         }
  56         final ContextMenu popupMenu = new ContextMenu();
  57 
  58         popupMenu.setOnAction(t -> {
  59             MenuItem item = (MenuItem) t.getTarget();
  60             log.log(Level.FINE, "onAction: item={0}", item);
  61             showContext.notifyItemSelected(((MenuItemPeer)item).getItemPeer().getAction());
  62         });
  63 
  64         popupMenu.getItems().addAll(fillMenu());
  65         PopupMenuImpl.doShow(popupMenu, showContext.getPage(), x, y);
  66     }
  67 
  68     @Override protected void appendItem(ContextMenuItem item) {
  69         insertItem(item, items.size());
  70     }
  71 
  72     @Override protected void insertItem(ContextMenuItem item, int index) {
  73         if (log.isLoggable(Level.FINE)) {
  74             log.log(Level.FINE, "item={0}, index={1}", new Object[] {item, index});
  75         }
  76         if (item == null) {
  77             return;
  78         }
  79         items.remove(item);
  80 
  81         if (items.size() == 0) {
  82             items.add(item);
  83         } else {
  84             items.add(index, item);
  85         }
  86     }
  87 
  88     @Override protected int getItemCount() {
  89         return items.size();
  90     }
  91 
  92     private MenuItem createMenuItem(ContextMenuItem item) {
  93         log.log(Level.FINE, "item={0}", item);
  94 
  95         if (item.getType() == ContextMenuItem.SUBMENU_TYPE) {
  96             MenuImpl menu = new MenuImpl(item.getTitle());
  97             if (item.getSubmenu() != null) {
  98                 menu.getItems().addAll(((ContextMenuImpl)item.getSubmenu()).fillMenu());
  99             }
 100             return menu;
 101 
 102         } else if (item.getType() == ContextMenuItem.ACTION_TYPE) {
 103 
 104             MenuItem mi = null;
 105             if (item.isChecked()) {
 106                 mi = new CheckMenuItemImpl(item);
 107             } else {
 108                 mi = new MenuItemImpl(item);
 109             }
 110             mi.setDisable(!item.isEnabled());
 111             return mi;
 112 
 113         } else if (item.getType() == ContextMenuItem.SEPARATOR_TYPE) {




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.webkit.theme;
  27 
  28 import com.sun.javafx.logging.PlatformLogger;
  29 import com.sun.javafx.logging.PlatformLogger.Level;



  30 
  31 import javafx.scene.control.Separator;
  32 import javafx.scene.control.ContextMenu;
  33 import javafx.scene.control.MenuItem;
  34 import javafx.scene.control.Menu;
  35 import javafx.scene.control.CheckMenuItem;
  36 
  37 import javafx.collections.ObservableList;
  38 import javafx.collections.FXCollections;
  39 
  40 import com.sun.webkit.ContextMenuItem;
  41 
  42 public final class ContextMenuImpl extends com.sun.webkit.ContextMenu {
  43 
  44     private final static PlatformLogger log = PlatformLogger.getLogger(ContextMenuImpl.class.getName());
  45 
  46     private final ObservableList<ContextMenuItem> items =
  47             FXCollections.observableArrayList();
  48 
  49     @Override protected void show(final ShowContext showContext, int x, int y) {
  50         if (log.isLoggable(Level.FINE)) {
  51             log.fine("show at [{0}, {1}]", new Object[] {x, y});
  52         }
  53         final ContextMenu popupMenu = new ContextMenu();
  54 
  55         popupMenu.setOnAction(t -> {
  56             MenuItem item = (MenuItem) t.getTarget();
  57             log.fine("onAction: item={0}", item);
  58             showContext.notifyItemSelected(((MenuItemPeer)item).getItemPeer().getAction());
  59         });
  60 
  61         popupMenu.getItems().addAll(fillMenu());
  62         PopupMenuImpl.doShow(popupMenu, showContext.getPage(), x, y);
  63     }
  64 
  65     @Override protected void appendItem(ContextMenuItem item) {
  66         insertItem(item, items.size());
  67     }
  68 
  69     @Override protected void insertItem(ContextMenuItem item, int index) {
  70         if (log.isLoggable(Level.FINE)) {
  71             log.fine("item={0}, index={1}", new Object[] {item, index});
  72         }
  73         if (item == null) {
  74             return;
  75         }
  76         items.remove(item);
  77 
  78         if (items.size() == 0) {
  79             items.add(item);
  80         } else {
  81             items.add(index, item);
  82         }
  83     }
  84 
  85     @Override protected int getItemCount() {
  86         return items.size();
  87     }
  88 
  89     private MenuItem createMenuItem(ContextMenuItem item) {
  90         log.fine("item={0}", item);
  91 
  92         if (item.getType() == ContextMenuItem.SUBMENU_TYPE) {
  93             MenuImpl menu = new MenuImpl(item.getTitle());
  94             if (item.getSubmenu() != null) {
  95                 menu.getItems().addAll(((ContextMenuImpl)item.getSubmenu()).fillMenu());
  96             }
  97             return menu;
  98 
  99         } else if (item.getType() == ContextMenuItem.ACTION_TYPE) {
 100 
 101             MenuItem mi = null;
 102             if (item.isChecked()) {
 103                 mi = new CheckMenuItemImpl(item);
 104             } else {
 105                 mi = new MenuItemImpl(item);
 106             }
 107             mi.setDisable(!item.isEnabled());
 108             return mi;
 109 
 110         } else if (item.getType() == ContextMenuItem.SEPARATOR_TYPE) {


< prev index next >