package com.sun.javafx.webkit.theme;
import com.sun.javafx.logging.PlatformLogger;
import com.sun.javafx.logging.PlatformLogger.Level;
import javafx.scene.control.Separator;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Menu;
import javafx.scene.control.CheckMenuItem;
import javafx.collections.ObservableList;
import javafx.collections.FXCollections;
import com.sun.webkit.ContextMenuItem;
public final class extends com.sun.webkit.ContextMenu {
private final static PlatformLogger = PlatformLogger.getLogger(ContextMenuImpl.class.getName());
private final ObservableList<ContextMenuItem> =
FXCollections.observableArrayList();
@Override protected void (final ShowContext showContext, int x, int y) {
if (log.isLoggable(Level.FINE)) {
log.fine("show at [{0}, {1}]", new Object[] {x, y});
}
final ContextMenu popupMenu = new ContextMenu();
popupMenu.setOnAction(t -> {
MenuItem item = (MenuItem) t.getTarget();
log.fine("onAction: item={0}", item);
showContext.notifyItemSelected(((MenuItemPeer)item).getItemPeer().getAction());
});
popupMenu.getItems().addAll(fillMenu());
PopupMenuImpl.doShow(popupMenu, showContext.getPage(), x, y);
}
@Override protected void (ContextMenuItem item) {
insertItem(item, items.size());
}
@Override protected void (ContextMenuItem item, int index) {
if (log.isLoggable(Level.FINE)) {
log.fine("item={0}, index={1}", new Object[] {item, index});
}
if (item == null) {
return;
}
items.remove(item);
if (items.size() == 0) {
items.add(item);
} else {
items.add(index, item);
}
}
@Override protected int () {
return items.size();
}
private MenuItem (ContextMenuItem item) {
log.fine("item={0}", item);
if (item.getType() == ContextMenuItem.SUBMENU_TYPE) {
MenuImpl menu = new MenuImpl(item.getTitle());
if (item.getSubmenu() != null) {
menu.getItems().addAll(((ContextMenuImpl)item.getSubmenu()).fillMenu());
}
return menu;
} else if (item.getType() == ContextMenuItem.ACTION_TYPE) {
MenuItem mi = null;
if (item.isChecked()) {
mi = new CheckMenuItemImpl(item);
} else {
mi = new MenuItemImpl(item);
}
mi.setDisable(!item.isEnabled());
return mi;
} else if (item.getType() == ContextMenuItem.SEPARATOR_TYPE) {
return new SeparatorImpl(item);
}
throw new java.lang.IllegalArgumentException("unexpected item type");
}
private ObservableList<MenuItem> () {
ObservableList<MenuItem> s = FXCollections.observableArrayList();
for (ContextMenuItem item: items) {
s.add(createMenuItem(item));
}
return s;
}
private interface {
public ContextMenuItem ();
}
private static final class extends MenuItem implements MenuItemPeer {
private final ContextMenuItem ;
private (ContextMenuItem itemPeer) { super(itemPeer.getTitle()); this.itemPeer = itemPeer; }
@Override public ContextMenuItem () { return itemPeer; }
}
private static final class extends CheckMenuItem implements MenuItemPeer {
private final ContextMenuItem ;
private (ContextMenuItem itemPeer) { this.itemPeer = itemPeer; }
@Override public ContextMenuItem () { return itemPeer; }
}
private static final class extends Menu {
private (String text) { super(text); }
}
static final class extends MenuItem implements MenuItemPeer {
private final ContextMenuItem ;
(ContextMenuItem itemPeer) {
this.itemPeer = itemPeer;
setGraphic(new Separator());
setDisable(true);
}
@Override public ContextMenuItem () { return itemPeer; }
}
}