📄 menubar.java
字号:
//# {
//# //System.out.println("calling single right command");
//# this.screen.callCommandListener(this.singleRightCommand);
//# } else if (this.commandsList.size() > 0
//# && isOpenKeySelected)
//# {
//# setOpen( true );
//# }
//# //System.out.println("nothing was clicked...");
//# return true;
//# // okay, y is above the menu bar, so let the commandContainer process the event:
//# } else if (this.isOpened) {
//# relY -= this.commandsContainer.relativeY;
//#if tmp.RightOptions
//# // the menu is painted at the lower right corner:
//# relX -= this.screen.screenWidth - this.commandsContainerWidth;
//#endif
//#
//# boolean handled = this.commandsContainer.handlePointerPressed(relX, relY);
//# if (!handled) {
//# setOpen( false );
//# }
//# return true;
//# // // a menu-item could have been selected:
//# // if (x <= this.commandsContainer.xLeftPos + this.commandsContainerWidth
//# // && y >= this.commandsContainerY )
//# // {
//# //
//# // //boolean handled = this.commandsContainer.handlePointerPressed( x, y );
//# // //System.out.println("handling pointer pressed in open menu at " + x + ", " + y + ": " + handled);
//# // this.commandsContainer.handlePointerPressed( x, y );
//# // int focusedIndex = this.commandsContainer.getFocusedIndex();
//# // Command cmd = (Command) this.commandsList.get( focusedIndex );
//# // this.screen.callCommandListener( cmd );
//# // return true;
//# // }
//# }
//# return false;
//# }
//#endif
public void setStyle(Style style) {
//#if !polish.Bugs.noTranslucencyWithDrawRgb
if (this.overlayBackground == null) {
//#if polish.color.overlay:defined
//# int color = 0;
//#= color = ${polish.color.overlay};
//# if ((color & 0xFF000000) != 0) {
//# this.overlayBackground = new TranslucentSimpleBackground( color );
//# }
//#else
this.overlayBackground = new TranslucentSimpleBackground( 0x88000000 );
//#endif
}
//#endif
//#if tmp.useInvisibleMenuBar
//# this.background = null;
//# this.border = null;
//#else
super.setStyle(style);
//#ifdef polish.css.menubar-show-image-and-text
//# Boolean showImageAndTextBool = style.getBooleanProperty( 51 );
//# if (showImageAndTextBool != null) {
//# this.showImageAndText = showImageAndTextBool.booleanValue();
//# }
//#endif
//#ifdef polish.css.menubar-options-image
//# String optionsUrl = style.getProperty(50);
//# if (optionsUrl != null) {
//# try {
//# this.optionsImage = StyleSheet.getImage(optionsUrl, this, false);
//# int imageHeight = this.optionsImage.getHeight();
//# if (imageHeight > this.contentHeight) {
//# this.contentHeight = imageHeight;
//# }
//# } catch (IOException e) {
//#debug error
//# System.out.println("Unable to load options-image " + optionsUrl + e );
//# }
//# }
//#endif
//#ifdef polish.css.menubar-select-image
//# String selectUrl = style.getProperty(48);
//# if (selectUrl != null) {
//# try {
//# this.selectImage = StyleSheet.getImage(selectUrl, this, false);
//# int imageHeight = this.selectImage.getHeight();
//# if (imageHeight > this.contentHeight) {
//# this.contentHeight = imageHeight;
//# }
//# } catch (IOException e) {
//#debug error
//# System.out.println("Unable to load select-image " + selectUrl + e );
//# }
//# }
//#endif
//#ifdef polish.css.menubar-cancel-image
//# String cancelUrl = style.getProperty(49);
//# if (cancelUrl != null) {
//# try {
//# this.cancelImage = StyleSheet.getImage(cancelUrl, this, false);
//# int imageHeight = this.cancelImage.getHeight();
//# if (imageHeight > this.contentHeight) {
//# this.contentHeight = imageHeight;
//# }
//# } catch (IOException e) {
//#debug error
//# System.out.println("Unable to load cancel-image " + cancelUrl + e );
//# }
//# }
//#endif
//#endif
}
public boolean animate() {
boolean animated = false;
if (this.background != null) {
animated = animated | this.background.animate();
}
if (this.isOpened) {
animated = animated | this.commandsContainer.animate();
}
if (this.singleLeftCommandItem != null) {
animated = animated | this.singleLeftCommandItem.animate();
}
if (this.singleRightCommandItem != null) {
animated = animated | this.singleRightCommandItem.animate();
}
return animated;
}
/**
* Adds the given command as a subcommand to the specified parent command.
*
* @param parentCommand the parent command
* @param childCommand the child command
* @throws IllegalStateException when the parent command has not be added before
* @see #addSubCommand(Command, Command, Style)
*/
public void addSubCommand(Command childCommand, Command parentCommand) {
//#style menuitem, menu, default
addSubCommand(childCommand, parentCommand, de.enough.polish.ui.StyleSheet.menuitemStyle );
}
/**
* Adds the given command as a subcommand to the specified parent command.
*
* @param parentCommand the parent command
* @param childCommand the child command
* @param commandStyle the style for the command
* @throws IllegalStateException when the parent command has not be added before
* @see #addSubCommand(Command, Command)
*/
public void addSubCommand(Command childCommand, Command parentCommand, Style commandStyle) {
//#if tmp.useInvisibleMenuBar
//# if (parentCommand == this.positiveCommand) {
//# this.positiveCommand = null;
//# }
//#endif
// find parent CommandItem:
CommandItem parentCommandItem = (CommandItem) this.allCommands.get( parentCommand );
if (parentCommand == this.singleLeftCommand ){
addCommand( parentCommandItem );
this.singleLeftCommand = null;
//#if tmp.RightOptions
//# if (this.singleRightCommand != null) {
//# Command cmd = this.singleRightCommand;
//# this.singleRightCommand = null;
//# addCommand( cmd );
//# }
//#endif
} else if (parentCommand == this.singleRightCommand ){
addCommand( parentCommandItem );
this.singleRightCommand = null;
//#if !tmp.RightOptions
if (this.singleLeftCommand != null) {
Command cmd = this.singleLeftCommand;
this.singleLeftCommand = null;
addCommand( cmd );
}
//#endif
}
if ( parentCommandItem == null ) {
throw new IllegalStateException();
}
CommandItem child = new CommandItem( childCommand, parentCommandItem, commandStyle );
this.allCommands.put( childCommand, child);
parentCommandItem.addChild( child );
if (this.isOpened) {
this.isInitialized = false;
repaint();
}
}
/**
* Adds the given command item to the list of commands at the appropriate place.
*
* @param item the command item
*/
private void addCommand(CommandItem item ) {
Command cmd = item.command;
int priority = cmd.getPriority();
//#debug
//# System.out.println("Adding command " + cmd.getLabel() + " to the commands list...");
if ( this.commandsList.size() == 0 ) {
this.commandsList.add( cmd );
this.commandsContainer.add( item );
} else {
// there are already several commands,
// so add this cmd to the appropriate sorted position:
Command[] myCommands = (Command[]) this.commandsList.toArray( new Command[ this.commandsList.size() ]);
boolean inserted = false;
for (int i = 0; i < myCommands.length; i++) {
Command command = myCommands[i];
if ( cmd == command ) {
return;
}
if (command.getPriority() > priority ) {
this.commandsList.add( i, cmd );
this.commandsContainer.add(i, item);
inserted = true;
break;
}
}
if (!inserted) {
this.commandsList.add( cmd );
this.commandsContainer.add( item );
}
}
}
/**
* Removes all commands from this MenuBar.
* This option is only available when the "menu" fullscreen mode is activated.
*/
public void removeAllCommands() {
this.commands.clear();
this.commandsContainer.clear();
}
/**
* Retrieves the CommandItem used for rendering the specified command.
*
* @param command the command
* @return the corresponding CommandItem or null when this command is not present in this MenuBar.
*/
public CommandItem getCommandItem(Command command) {
int index = this.commands.indexOf(command);
if (index != -1) {
return (CommandItem) this.commandsContainer.get(index);
} else if (command == this.singleLeftCommand){
return this.singleLeftCommandItem;
} else if (command == this.singleLeftCommand) {
return this.singleRightCommandItem;
} else {
for (int i = 0; i < this.commandsContainer.size(); i++) {
CommandItem item = (CommandItem) this.commandsContainer.get(i);
item = item.getChild(command);
if (item != null) {
return item;
}
}
}
return null;
}
/* (non-Javadoc)
* @see de.enough.polish.ui.Item#getItemAt(int, int)
*/
public Item getItemAt(int relX, int relY) {
if (this.isOpened && relY < 0) {
return this.commandsContainer.getItemAt(relX - this.commandsContainer.relativeX, relY - this.commandsContainer.relativeY);
} else if (relY >= 0) {
// test for left or right commanditem:
Item item = this.singleLeftCommandItem.getItemAt(relX - this.singleLeftCommandItem.relativeX, relY - this.singleLeftCommandItem.relativeY);
if (item != null) {
return item;
}
item = this.singleRightCommandItem.getItemAt(relX - this.singleRightCommandItem.relativeX, relY - this.singleRightCommandItem.relativeY);
if (item != null) {
return item;
}
}
return super.getItemAt(relX, relY);
}
//#ifdef polish.MenuBar.additionalMethods:defined
//#include ${polish.MenuBar.additionalMethods}
//#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -