package com.sun.glass.ui;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import com.sun.glass.ui.Pixels;
import com.sun.glass.ui.delegate.MenuDelegate;
import com.sun.glass.ui.delegate.MenuItemDelegate;
public final class {
public static class EventHandler {
public void handleMenuOpening(Menu menu, long time) {
}
public void handleMenuClosed(Menu menu, long time) {
}
}
public EventHandler getEventHandler() {
Application.checkEventThread();
return eventHandler;
}
public void setEventHandler(EventHandler eventHandler) {
Application.checkEventThread();
this.eventHandler = eventHandler;
}
private final MenuDelegate ;
private String ;
private boolean ;
private final List<Object> = new ArrayList<Object>();
private EventHandler eventHandler;
protected (String title) {
this(title, true);
}
protected (String title, boolean enabled) {
Application.checkEventThread();
this.title = title;
this.enabled = enabled;
delegate = PlatformFactory.getPlatformFactory().createMenuDelegate(this);
if (!delegate.createMenu(title, enabled)) {
throw new RuntimeException("Menu creation error.");
}
}
public String () {
Application.checkEventThread();
return title;
}
public void (String title) {
Application.checkEventThread();
if (delegate.setTitle(title)) {
this.title = title;
}
}
public boolean () {
Application.checkEventThread();
return enabled;
}
public void (boolean enabled) {
Application.checkEventThread();
if (delegate.setEnabled(enabled)) {
this.enabled = enabled;
}
}
public boolean (Pixels pixels) {
Application.checkEventThread();
return (delegate.setPixels(pixels));
}
public List<Object> () {
Application.checkEventThread();
return Collections.unmodifiableList(items);
}
public void (Menu menu) {
Application.checkEventThread();
insert(menu, items.size());
}
public void (MenuItem item) {
Application.checkEventThread();
insert(item, items.size());
}
public void (Menu menu, int pos) throws IndexOutOfBoundsException {
Application.checkEventThread();
if (menu == null) {
throw new IllegalArgumentException();
}
synchronized (items) {
if (pos < 0 || pos > items.size()) {
throw new IndexOutOfBoundsException();
}
MenuDelegate menuDelegate = menu.getDelegate();
if (delegate.insert(menuDelegate, pos)) {
items.add(pos, menu);
}
}
}
public void (MenuItem item, int pos) throws IndexOutOfBoundsException {
Application.checkEventThread();
synchronized (items) {
if (pos < 0 || pos > items.size()) {
throw new IndexOutOfBoundsException();
}
MenuItemDelegate itemDelegate = item != null ? item.getDelegate() : null;
if (delegate.insert(itemDelegate, pos)) {
items.add(pos, item);
}
}
}
public void (int pos) throws IndexOutOfBoundsException {
Application.checkEventThread();
synchronized (items) {
Object item = items.get(pos);
boolean success = false;
if (item == MenuItem.Separator) {
success = delegate.remove((MenuItemDelegate)null, pos);
} else if (item instanceof MenuItem) {
success = delegate.remove(((MenuItem)item).getDelegate(), pos);
} else {
success = delegate.remove(((Menu)item).getDelegate(), pos);
}
if (success) {
items.remove(pos);
}
}
}
MenuDelegate () {
return delegate;
}
protected void () {
if (this.eventHandler != null) {
eventHandler.handleMenuOpening(this, System.nanoTime());
}
}
protected void () {
if (this.eventHandler != null) {
eventHandler.handleMenuClosed(this, System.nanoTime());
}
}
}