📄 form.java
字号:
/**
* Adds Component to the Form's Content Pane
*
* @param cmp the added param
*/
public void addComponent(int index, Component cmp) {
contentPane.addComponent(index, cmp);
//setShouldCalcPreferredSize(true);
}
public void replace(Component current, Component next, Transition t) {
contentPane.replace(current, next, t);
setShouldCalcPreferredSize(true);
}
/**
* Removes a component from the Form's Content Pane
*
* @param cmp the component to be removed
*/
public void removeComponent(Component cmp) {
contentPane.removeComponent(cmp);
//focusManager.setRoot(contentPane, null);
setShouldCalcPreferredSize(true);
}
/**
* Registering media component to this Form, that like to receive
* animation events
*
* @param mediaCmp the Form media component to be registered
*/
void registerMediaComponent(Component mediaCmp) {
if (mediaComponents == null) {
mediaComponents = new Vector();
}
if (!mediaComponents.contains(mediaCmp)) {
mediaComponents.addElement(mediaCmp);
}
}
/**
* Used by implementation to prevent flickering when flushing the double buffer
*/
boolean hasMedia() {
return mediaComponents != null && mediaComponents.size() > 0;
}
/**
* Indicate that cmp would no longer like to receive animation events
*
* @param cmp component that would no longer receive animation events
*/
void deregisterMediaComponent(Component mediaCmp) {
mediaComponents.removeElement(mediaCmp);
}
/**
* The given component is interested in animating its appearance and will start
* receiving callbacks when it is visible in the form allowing it to animate
* its appearance. This method would not register a compnent instance more than once
*
* @param cmp component that would be animated
*/
public void registerAnimated(Animation cmp) {
if (animatableComponents == null) {
animatableComponents = new Vector();
}
if (!animatableComponents.contains(cmp)) {
animatableComponents.addElement(cmp);
}
}
/**
* Indicate that cmp would no longer like to receive animation events
*
* @param cmp component that would no longer receive animation events
*/
public void deregisterAnimated(Animation cmp) {
if (animatableComponents != null) {
animatableComponents.removeElement(cmp);
}
}
/**
* Returns the offset of the component within the up/down focus sequence
*
* @return offset between 0 and number of components or -1 for an error
*/
int getFocusPosition(Component c) {
initFocusDown();
return focusDownSequence.indexOf(c);
}
/**
* Makes sure all animations are repainted so they would be rendered in every
* frame
*/
void repaintAnimations() {
// prevent animations from playing with a popup
if (animatableComponents != null) {
// we don't save size() in a varible since the animate method may deregister
// the animation thus invalidating the size
for (int iter = 0; iter < animatableComponents.size(); iter++) {
Animation c = (Animation) animatableComponents.elementAt(iter);
if (c.animate()) {
if (c instanceof Component) {
Rectangle rect = ((Component) c).getDirtyRegion();
if (rect != null) {
((Component) c).repaint(rect.getX(), rect.getY(), rect.getSize().getWidth(), rect.getSize().getHeight());
} else {
((Component) c).repaint();
}
} else {
Display.getInstance().repaint(c);
}
}
}
}
}
/**
* If this method returns true the EDT won't go to sleep indefinitely
*
* @return true is form has animation; otherwise false
*/
boolean hasAnimations() {
return animatableComponents != null && animatableComponents.size() > 0;
}
/**
* @inheritDoc
*/
public void refreshTheme() {
// when changing the theme when a title/menu bar is not visible the refresh
// won't apply to them. We need to protect against this occurance.
if (menuBar != null && menuBar.getParent() == null) {
menuBar.refreshTheme();
}
if (title != null && title.getParent() == null) {
title.refreshTheme();
}
super.refreshTheme();
}
/**
* Exposing the background painting for the benefit of animations
*
* @param g the form graphics
*/
public void paintBackground(Graphics g) {
super.paintBackground(g);
}
/**
* This property allows us to define a an animation that will draw the transition for
* entering this form. A transition is an animation that would occur when
* switching from one form to another.
*
* @return the Form in transition
*/
public Transition getTransitionInAnimator() {
return transitionInAnimator;
}
/**
* This property allows us to define a an animation that will draw the transition for
* entering this form. A transition is an animation that would occur when
* switching from one form to another.
*
* @param transitionInAnimator the Form in transition
*/
public void setTransitionInAnimator(Transition transitionInAnimator) {
this.transitionInAnimator = transitionInAnimator;
}
/**
* This property allows us to define a an animation that will draw the transition for
* exiting this form. A transition is an animation that would occur when
* switching from one form to another.
*
* @return the Form out transition
*/
public Transition getTransitionOutAnimator() {
return transitionOutAnimator;
}
/**
* This property allows us to define a an animation that will draw the transition for
* exiting this form. A transition is an animation that would occur when
* switching from one form to another.
*
* @param transitionOutAnimator the Form out transition
*/
public void setTransitionOutAnimator(Transition transitionOutAnimator) {
this.transitionOutAnimator = transitionOutAnimator;
}
/**
* A listener that is invoked when a command is clicked allowing multiple commands
* to be handled by a single block
*
* @param commandListener the command action listener
*/
public void setCommandListener(ActionListener commandListener) {
this.commandListener = commandListener;
}
/**
* Invoked to allow subclasses of form to handle a command from one point
* rather than implementing many command instances. All commands selected
* on the form will trigger this method implicitly.
*
* @param cmd the form commmand object
*/
protected void actionCommand(Command cmd) {
}
/**
* Invoked to allow subclasses of form to handle a command from one point
* rather than implementing many command instances
*/
private void actionCommandImpl(Command cmd) {
if (cmd != selectCommand) {
if (commandListener != null) {
commandListener.actionPerformed(new ActionEvent(cmd));
}
actionCommand(cmd);
} else {
Component c = getFocused();
if (c != null) {
c.fireClicked();
}
}
}
void initFocused() {
if (focused == null) {
layoutContainer();
initFocusDown();
if (focusDownSequence.size() > 0) {
setFocused((Component) focusDownSequence.elementAt(0));
}
}
}
/**
* Dislays the current form on the screen
*/
public void show() {
if (transitionOutAnimator == null && transitionInAnimator == null) {
initLaf(UIManager.getInstance().getLookAndFeel());
}
initFocused();
com.sun.lwuit.Display.getInstance().setCurrent(this);
onShow();
}
/**
* @inheritDoc
*/
public void setSmoothScrolling(boolean smoothScrolling) {
// invoked by the constructor for component
if (contentPane != null) {
contentPane.setSmoothScrolling(smoothScrolling);
}
}
/**
* @inheritDoc
*/
public boolean isSmoothScrolling() {
return contentPane.isSmoothScrolling();
}
/**
* @inheritDoc
*/
public int getScrollAnimationSpeed() {
return contentPane.getScrollAnimationSpeed();
}
/**
* @inheritDoc
*/
public void setScrollAnimationSpeed(int animationSpeed) {
contentPane.setScrollAnimationSpeed(animationSpeed);
}
/**
* Allows subclasses to bind functionality that occurs immediately after
* a specific form or dialog appears on the screen
*/
protected void onShow() {
}
/**
* This method shows the form as a modal alert allowing us to produce a behavior
* of an alert/dialog box. This method will block the calling thread even if the
* calling thread is the EDT. Notice that this method will not release the block
* until dispose is called even if show() from another form is called!
* <p>Modal dialogs Allow the forms "content" to "hang in mid air" this is especially useful for
* dialogs where you would want the underlying form to "peek" from behind the
* form.
*
* @param top space in pixels between the top of the screen and the form
* @param bottom space in pixels between the bottom of the screen and the form
* @param left space in pixels between the left of the screen and the form
* @param right space in pixels between the right of the screen and the form
* @param includeTitle whether the title should hang in the top of the screen or
* be glued onto the content pane
* @param modal indictes if this is a modal or modeless dialog true for modal dialogs
*/
void showModal(int top, int bottom, int left, int right, boolean includeTitle, boolean modal) {
Display.getInstance().flushEdt();
if (previousForm == null) {
previousForm = Display.getInstance().getCurrent();
// special case for application opening with a dialog before any form is shown
if (previousForm == null) {
previousForm = new Form();
previousForm.show();
}
previousForm.tint = true;
}
Painter p = getStyle().getBgPainter();
if (top > 0 || bottom > 0 || left > 0 || right > 0) {
if (includeTitle) {
title.getStyle().setMargin(top, 0, left, right);
contentPane.getStyle().setMargin(0, bottom, left, right);
} else {
contentPane.getStyle().setMargin(top, bottom, left, right);
}
BGPainter b = new BGPainter(this, p);
b.setIgnorCoordinates(true);
getStyle().setBgPainter(b);
b.setPreviousForm(previousForm);
}
if (modal) {
Display.getInstance().invokeAndBlock(new RunnableWrapper(this, p));
} else {
initFocused();
if (getTransitionOutAnimator() == null && getTransitionInAnimator() == null) {
initLaf(UIManager.getInstance().getLookAndFeel());
}
initComponentImpl();
Display.getInstance().setCurrent(this);
onShow();
}
}
/**
* The default version of show modal shows the dialog occupying the center portion
* of the screen.
*/
void showModal() {
showDialog(true);
}
/**
* The default version of show dialog shows the dialog occupying the center portion
* of the screen.
*/
void showDialog(boolean modal) {
int h = Display.getInstance().getDisplayHeight() - menuBar.getPreferredH() - title.getPreferredH();
int w = Display.getInstance().getDisplayWidth();
int topSpace = h / 100 * 20;
int bottomSpace = h / 100 * 10;
int sideSpace = w / 100 * 20;
showModal(topSpace, bottomSpace, sideSpace, sideSpace, true, modal);
}
/**
* Works only for modal forms by returning to the previous form
*/
void dispose() {
disposeImpl();
}
/**
* Works only for modal forms by returning to the previous form
*/
void disposeImpl() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -