}
protected final Node rootNode;
public MenuDemo() {
rootNode = new DefaultNode( "menuNode" );
final DefaultNode fileMenuNode = new DefaultNode( "file", Lookups.singletonLookup( Action.class, new FileAction() ) );
rootNode.addChild( fileMenuNode );
fileMenuNode.addChild( new DefaultNode( "open", Lookups.singletonLookup( Action.class, new OpenAction() ) ) );
fileMenuNode.addChild( new DefaultNode( "close", Lookups.singletonLookup( Action.class, new CloseAction() ) ) );
fileMenuNode.addChild( new DefaultNode( "increate counter", Lookups.singletonLookup( Action.class, new CounterAction() ) ) );
DefaultNode recentlyOpenedFilesNode = new DefaultNode( "recentlyOpenedFiles", Lookups.singletonLookup( Action.class, new RecentFilesAction() ) );
fileMenuNode.addChild( recentlyOpenedFilesNode );
recentlyOpenedFilesNode.addChild( new DefaultNode( "file0", Lookups.singletonLookup( Action.class, new RecentFileAction( "file0" ) ) ) );
recentlyOpenedFilesNode.addChild( new DefaultNode( "file1", Lookups.singletonLookup( Action.class, new RecentFileAction( "file1" ) ) ) );
recentlyOpenedFilesNode.addChild( new DefaultNode( "file2", Lookups.singletonLookup( Action.class, new RecentFileAction( "file2" ) ) ) );
recentlyOpenedFilesNode.addChild( new DefaultNode( "file3", Lookups.dynamicLookup( new RecentFileAction( "file3" ), new NodePresenter() {
@Override
@NotNull
protected y.base.Node createPresentation() {
y.base.Node node = super.createPresentation();
( ( Graph2D ) node.getGraph() ).getRealizer( node ).setFillColor( Color.CYAN );
return node;
}
} ) ) );
fileMenuNode.addChild( new DefaultNode( "separator", Lookups.dynamicLookup( new JSeparator() ) ) );
{
final DynamicLookup lookup = new DynamicLookup();
final AbstractAction[] actions = new AbstractAction[2];
actions[0] = new AbstractAction( "action0" ) {
public void actionPerformed( ActionEvent e ) {
lookup.addValue( actions[1] );
}
};
actions[1] = new AbstractAction( "action1" ) {
public void actionPerformed( ActionEvent e ) {
lookup.addValue( actions[0] );
}
};
lookup.addValue( actions[0] );
fileMenuNode.addChild( new DefaultNode( "toggleAction", lookup ) );
}
fileMenuNode.addChild( new DefaultNode( "separator1", Lookups.dynamicLookup( new JSeparator() ) ) );
addAction = new AbstractAction( "Add Another Item" ) {
public void actionPerformed( ActionEvent e ) {
fileMenuNode.addChild( new DefaultNode( String.valueOf( System.currentTimeMillis() ), Lookups.singletonLookup( Action.class, addAction ) ) );
}
};
fileMenuNode.addChild( new DefaultNode( "addAction", Lookups.singletonLookup( Action.class, addAction ) ) );
rootNode.addChild( new DefaultNode( "customEditMenu", Lookups.dynamicLookup( new EditFileAction(), new MySpecialEditMenuPresenter() ) ) );
}