📄 form.java
字号:
}
case Display.GAME_UP: {
if (focused.getNextFocusUp() != null) {
focused = focused.getNextFocusUp();
} else {
initFocusDown();
int i = focusDownSequence.indexOf(focused) - 1;
if (i < 0) {
i = focusDownSequence.size() - 1;
}
focused = (Component) focusDownSequence.elementAt(i);
}
break;
}
case Display.GAME_RIGHT: {
if (focused.getNextFocusRight() != null) {
focused = focused.getNextFocusRight();
} else {
initFocusRight();
int i = focusRightSequence.indexOf(focused) + 1;
if (i == focusRightSequence.size()) {
i = 0;
}
focused = (Component) focusRightSequence.elementAt(i);
}
break;
}
case Display.GAME_LEFT: {
if (focused.getNextFocusLeft() != null) {
focused = focused.getNextFocusLeft();
} else {
initFocusRight();
int i = focusRightSequence.indexOf(focused) - 1;
if (i < 0) {
i = focusRightSequence.size() - 1;
}
focused = (Component) focusRightSequence.elementAt(i);
}
break;
}
default:
return;
}
setFocused(focused);
if (focused != null) {
scrollComponentToVisible(focused);
}
}
/**
* Makes sure the component is visible in the scroll if this container
* is scrollable
*
* @param c the componant to be visible
*/
public void scrollComponentToVisible(Component c) {
Container parent = c.getParent();
while (parent != null) {
if (parent.isScrollable()) {
parent.scrollComponentToVisible(c);
return;
}
parent = parent.getParent();
}
}
/**
* Determine the cell renderer used to render menu elements for themeing the
* look of the menu options
*
* @param menuCellRenderer the menu cell renderer
*/
public void setMenuCellRenderer(ListCellRenderer menuCellRenderer) {
menuBar.setMenuCellRenderer(menuCellRenderer);
}
/**
* Clear menu commands from the menu bar
*/
public void removeAllCommands() {
menuBar.removeAllCommands();
}
/**
* Request focus for a form child component
*
* @param cmp the form child component
*/
void requestFocus(Component cmp) {
if (cmp.isFocusable() && contains(cmp)) {
scrollComponentToVisible(cmp);
setFocused(cmp);
}
}
/**
* @inheritDoc
*/
public void paint(Graphics g) {
super.paintBackground(g);
super.paint(g);
if (tint) {
g.setColor(tintColor);
g.fillRect(0, 0, getWidth(), getHeight(), (byte) ((tintColor >> 24) & 0xff));
}
}
/**
* @inheritDoc
*/
public void setScrollable(boolean scrollable) {
contentPane.setScrollable(scrollable);
}
/**
* Displays the given popup on top of the current form
*
* @param pop the displayed popup
*/
void showPopup(Popup pop) {
if (current == null || !current.equals(pop)) {
current = pop;
lastFocused = focused;
focusCycleRoot = pop.getContents();
if (focusCycleRoot.isFocusable()) {
setFocused(focusCycleRoot);
} else {
// Shai: focus patch for animation bug in combo boxes might need
// to rethink some concepts about popups
setFocused(((Container) focusCycleRoot).getComponentAt(0));
//initFocused();
}
}
focusCycleRoot.repaint();
}
/**
* Hides the popup from the current form
*/
void hidePopups() {
if (current != null) {
current = null;
//contentPane.removeComponent(focusCycleRoot);
focusCycleRoot = contentPane;
setFocused(lastFocused);
repaint();
}
}
/**
* @inheritDoc
*/
public void setVisible(boolean visible) {
super.setVisible(visible);
if (mediaComponents != null) {
int size = mediaComponents.size();
for (int i = 0; i < size; i++) {
Component mediaCmp = (Component) mediaComponents.elementAt(i);
mediaCmp.setVisible(visible);
}
}
}
/**
* Default color for the screen tint when a dialog or a menu is shown
*
* @return the tint color when a dialog or a menu is shown
*/
public int getTintColor() {
return tintColor;
}
/**
* Default color for the screen tint when a dialog or a menu is shown
*
* @param tintColor the tint color when a dialog or a menu is shown
*/
public void setTintColor(int tintColor) {
this.tintColor = tintColor;
}
void addSelectCommand() {
if (Display.getInstance().isThirdSoftButton()) {
if (selectCommand == null) {
selectCommand = new Command(UIManager.getInstance().localize("select", "Select"));
}
addCommand(selectCommand);
}
}
void removeSelectCommand() {
if (Display.getInstance().isThirdSoftButton()) {
removeCommand(selectCommand);
}
}
/**
* Sets the menu transitions for showing/hiding the menu, can be null...
*
* @param transitionIn the transition that will play when the menu appears
* @param transitionOut the transition that will play when the menu is folded
*/
public void setMenuTransitions(Transition transitionIn, Transition transitionOut) {
menuBar.setTransitions(transitionIn, transitionOut);
}
/**
* @inheritDoc
*/
protected String paramString() {
return super.paramString() + ", title = " + title +
", visible = " + isVisible();
}
/**
* A menu is implemented as a dialog, this method allows you to override dialog
* display in order to customize the dialog menu in various ways
*
* @param menu a dialog containing menu options that can be customized
* @return the command selected by the user in the dialog (not menu) Select or Cancel
*/
protected Command showMenuDialog(Dialog menu) {
int marginLeft = (int) (Form.this.getWidth() * 0.25f);
int marginRight = 0;
if (isReverseSoftButtons()) {
marginRight = marginLeft;
marginLeft = 0;
}
int height = Form.this.getHeight() / 2;
return menu.show(height, 0, marginLeft, marginRight, true);
}
/**
* Allows an individual form to reverse the layout direction of the softbuttons
*
* @return The value of UIManager.getInstance().getLookAndFeel().isReverseSoftButtons()
*/
protected boolean isReverseSoftButtons() {
return UIManager.getInstance().getLookAndFeel().isReverseSoftButtons();
}
/**
* Creates the list component containing the commands within the given vector
* used for showing the menu dialog
*
* @param commands list of command objects
* @return List object
*/
protected List createCommandList(Vector commands) {
List l = new List(commands);
l.setStyle(UIManager.getInstance().getComponentStyle("CommandList"));
((Component)l.getRenderer()).setStyle(UIManager.getInstance().getComponentStyle("Command"));
l.setFixedSelection(List.FIXED_NONE_CYCLIC);
return l;
}
class MenuBar extends Container implements ActionListener {
private Command menuCommand;
private Vector commands = new Vector();
private Button[] soft;
private Command[] softCommand;
private Button left;
private Button right;
private Button main;
private ListCellRenderer menuCellRenderer;
private Transition transitionIn;
private Transition transitionOut;
private List commandList;
private Command selectMenuItem;
private Command cancelMenuItem;
private Style menuStyle;
public MenuBar() {
menuStyle = UIManager.getInstance().getComponentStyle("Menu");
menuCommand = new Command(UIManager.getInstance().localize("menu", "Menu"));
LookAndFeel lf = UIManager.getInstance().getLookAndFeel();
// use the slide transition by default
if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
transitionIn = lf.getDefaultMenuTransitionIn();
transitionOut = lf.getDefaultMenuTransitionOut();
} else {
transitionIn = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300, true);
transitionOut = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300, true);
}
if (Display.getInstance().isThirdSoftButton()) {
setLayout(new GridLayout(1, 3));
soft = new Button[]{createSoftButton(), createSoftButton(), createSoftButton()};
main = soft[0];
main.setAlignment(Label.CENTER);
left = soft[1];
right = soft[2];
addComponent(left);
addComponent(main);
addComponent(right);
if (isReverseSoftButtons()) {
Button b = soft[1];
soft[1] = soft[2];
soft[2] = b;
}
} else {
setLayout(new GridLayout(1, 2));
soft = new Button[]{createSoftButton(), createSoftButton()};
main = soft[0];
left = soft[0];
right = soft[1];
addComponent(left);
addComponent(right);
if (isReverseSoftButtons()) {
Button b = soft[0];
soft[0] = soft[1];
soft[1] = b;
}
}
left.setAlignment(Label.LEFT);
right.setAlignment(Label.RIGHT);
softCommand = new Command[soft.length];
}
/**
* Updates the command mapping to the softbuttons
*/
private void updateCommands() {
soft[0].setText("");
soft[1].setText("");
int commandSize = commands.size();
if (soft.length > 2) {
soft[2].setText("");
if (commandSize > 2) {
if (commandSize > 3) {
softCommand[2] = menuCommand;
} else {
softCommand[2] = (Command) commands.elementAt(commands.size() - 3);
}
soft[2].setText(softCommand[2].getCommandName());
soft[2].setIcon(softCommand[2].getIcon());
} else {
softCommand[2] = null;
}
}
if (commandSize > 0) {
softCommand[0] = (Command) commands.elementAt(commands.size() - 1);
soft[0].setText(softCommand[0].getCommandName());
soft[0].setIcon(softCommand[0].getIcon());
if (commandSize > 1) {
if (soft.length == 2 && commandSize > 2) {
softCommand[1] = menuCommand;
} else {
softCommand[1] = (Command) commands.elementAt(commands.size() - 2);
}
soft[1].setText(softCommand[1].getCommandName());
soft[1].setIcon(softCommand[1].getIcon());
} else {
softCommand[1] = null;
}
} else {
softCommand[0] = null;
softCommand[1] = null;
}
// we need to add the menu bar to an already visible form
if (commandSize == 1) {
if(Form.this.isVisible()) {
Form.this.revalidate();
}
}
}
/**
* Invoked when a softbutton is pressed
*/
public void actionPerformed(ActionEvent evt) {
if (evt.isConsumed()) {
return;
}
Object src = evt.getSource();
if (commandList == null) {
Button source = (Button) sr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -