use of com.codename1.ui.animations.Motion in project CodenameOne by codenameone.
the class Component method createStyleAnimation.
ComponentAnimation createStyleAnimation(final Style sourceStyle, final Style destStyle, final int duration, final String destUIID) {
int d = duration;
Motion m = null;
if (sourceStyle.getFgColor() != destStyle.getFgColor()) {
m = Motion.createLinearColorMotion(sourceStyle.getFgColor(), destStyle.getFgColor(), d);
}
final Motion fgColorMotion = m;
m = null;
if (sourceStyle.getOpacity() != destStyle.getOpacity()) {
m = Motion.createLinearColorMotion(sourceStyle.getOpacity(), destStyle.getOpacity(), d);
}
final Motion opacityMotion = m;
m = null;
if (sourceStyle.getFont().getHeight() != destStyle.getFont().getHeight() && sourceStyle.getFont().isTTFNativeFont()) {
// allows for fractional font sizes
m = Motion.createLinearMotion(sourceStyle.getFont().getHeight() * 100, destStyle.getFont().getHeight() * 100, d);
}
final Motion fontMotion = m;
m = null;
if (sourceStyle.getPaddingTop() != destStyle.getPaddingTop()) {
m = Motion.createLinearMotion(sourceStyle.getPaddingTop(), destStyle.getPaddingTop(), d);
}
final Motion paddingTop = m;
m = null;
if (sourceStyle.getPaddingBottom() != destStyle.getPaddingBottom()) {
m = Motion.createLinearMotion(sourceStyle.getPaddingBottom(), destStyle.getPaddingBottom(), d);
}
final Motion paddingBottom = m;
m = null;
if (sourceStyle.getPaddingLeftNoRTL() != destStyle.getPaddingLeftNoRTL()) {
m = Motion.createLinearMotion(sourceStyle.getPaddingLeftNoRTL(), destStyle.getPaddingLeftNoRTL(), d);
}
final Motion paddingLeft = m;
m = null;
if (sourceStyle.getPaddingRightNoRTL() != destStyle.getPaddingRightNoRTL()) {
m = Motion.createLinearMotion(sourceStyle.getPaddingRightNoRTL(), destStyle.getPaddingRightNoRTL(), d);
}
final Motion paddingRight = m;
m = null;
if (sourceStyle.getMarginTop() != destStyle.getMarginTop()) {
m = Motion.createLinearMotion(sourceStyle.getMarginTop(), destStyle.getMarginTop(), d);
}
final Motion marginTop = m;
m = null;
if (sourceStyle.getMarginBottom() != destStyle.getMarginBottom()) {
m = Motion.createLinearMotion(sourceStyle.getMarginBottom(), destStyle.getMarginBottom(), d);
}
final Motion marginBottom = m;
m = null;
if (sourceStyle.getMarginLeftNoRTL() != destStyle.getMarginLeftNoRTL()) {
m = Motion.createLinearMotion(sourceStyle.getMarginLeftNoRTL(), destStyle.getMarginLeftNoRTL(), d);
}
final Motion marginLeft = m;
m = null;
if (sourceStyle.getMarginRightNoRTL() != destStyle.getMarginRightNoRTL()) {
m = Motion.createLinearMotion(sourceStyle.getMarginRightNoRTL(), destStyle.getMarginRightNoRTL(), d);
}
final Motion marginRight = m;
m = null;
if (paddingLeft != null || paddingRight != null || paddingTop != null || paddingBottom != null) {
// convert the padding to pixels for smooth animation
int left = sourceStyle.getPaddingLeftNoRTL();
int right = sourceStyle.getPaddingRightNoRTL();
int top = sourceStyle.getPaddingTop();
int bottom = sourceStyle.getPaddingBottom();
sourceStyle.setPaddingUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
sourceStyle.setPadding(top, bottom, left, right);
}
if (marginLeft != null || marginRight != null || marginTop != null || marginBottom != null) {
// convert the margin to pixels for smooth animation
int left = sourceStyle.getMarginLeftNoRTL();
int right = sourceStyle.getMarginRightNoRTL();
int top = sourceStyle.getMarginTop();
int bottom = sourceStyle.getMarginBottom();
sourceStyle.setMarginUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
sourceStyle.setMargin(top, bottom, left, right);
}
final AnimationTransitionPainter ap = new AnimationTransitionPainter();
if (sourceStyle.getBgTransparency() != 0 || destStyle.getBgTransparency() != 0 || (sourceStyle.getBorder() != null && sourceStyle.getBorder().isEmptyBorder()) || (destStyle.getBorder() != null && destStyle.getBorder().isEmptyBorder()) || sourceStyle.getBgImage() != null || destStyle.getBgImage() != null) {
ap.original = sourceStyle.getBgPainter();
ap.dest = destStyle.getBgPainter();
ap.originalStyle = sourceStyle;
ap.destStyle = destStyle;
if (ap.dest == null) {
ap.dest = new BGPainter();
}
sourceStyle.setBgPainter(ap);
}
final Motion bgMotion = Motion.createLinearMotion(0, 255, d);
return new ComponentAnimation() {
private boolean finished;
private boolean stepMode;
private boolean started;
@Override
public boolean isStepModeSupported() {
return true;
}
@Override
public int getMaxSteps() {
return duration;
}
@Override
public void setStep(int step) {
stepMode = true;
if (!finished) {
if (bgMotion != null) {
bgMotion.setCurrentMotionTime(step);
}
if (fgColorMotion != null) {
fgColorMotion.setCurrentMotionTime(step);
}
if (opacityMotion != null) {
opacityMotion.setCurrentMotionTime(step);
}
if (fontMotion != null) {
fontMotion.setCurrentMotionTime(step);
}
if (paddingTop != null) {
paddingTop.setCurrentMotionTime(step);
}
if (paddingBottom != null) {
paddingBottom.setCurrentMotionTime(step);
}
if (paddingLeft != null) {
paddingLeft.setCurrentMotionTime(step);
}
if (paddingRight != null) {
paddingRight.setCurrentMotionTime(step);
}
if (marginTop != null) {
marginTop.setCurrentMotionTime(step);
}
if (marginBottom != null) {
marginBottom.setCurrentMotionTime(step);
}
if (marginLeft != null) {
marginLeft.setCurrentMotionTime(step);
}
if (marginRight != null) {
marginRight.setCurrentMotionTime(step);
}
}
super.setStep(step);
}
@Override
public boolean isInProgress() {
if (!stepMode && !started) {
return true;
}
return stepMode || !((bgMotion == null || bgMotion.isFinished()) && (opacityMotion == null || opacityMotion.isFinished()) && (fgColorMotion == null || fgColorMotion.isFinished()) && (paddingLeft == null || paddingLeft.isFinished()) && (paddingRight == null || paddingRight.isFinished()) && (paddingTop == null || paddingTop.isFinished()) && (paddingBottom == null || paddingBottom.isFinished()) && (marginLeft == null || marginLeft.isFinished()) && (marginRight == null || marginRight.isFinished()) && (marginTop == null || marginTop.isFinished()) && (marginBottom == null || marginBottom.isFinished()) && (fontMotion == null || fontMotion.isFinished()));
}
@Override
protected void updateState() {
if (finished) {
return;
}
if (!started && !stepMode) {
started = true;
if (bgMotion != null) {
bgMotion.start();
}
if (opacityMotion != null) {
opacityMotion.start();
}
if (fgColorMotion != null) {
fgColorMotion.start();
}
if (fontMotion != null) {
fontMotion.start();
}
if (paddingTop != null) {
paddingTop.start();
}
if (paddingBottom != null) {
paddingBottom.start();
}
if (paddingLeft != null) {
paddingLeft.start();
}
if (paddingRight != null) {
paddingRight.start();
}
if (marginTop != null) {
marginTop.start();
}
if (marginBottom != null) {
marginBottom.start();
}
if (marginLeft != null) {
marginLeft.start();
}
if (marginRight != null) {
marginRight.start();
}
}
if (!isInProgress()) {
finished = true;
if (destUIID != null) {
setUIID(destUIID);
}
} else {
if (opacityMotion != null) {
sourceStyle.setOpacity(opacityMotion.getValue());
}
if (fgColorMotion != null) {
sourceStyle.setFgColor(fgColorMotion.getValue());
}
if (bgMotion != null) {
ap.alpha = bgMotion.getValue();
}
if (fontMotion != null) {
Font fnt = sourceStyle.getFont();
fnt = fnt.derive(((float) fontMotion.getValue()) / 100.0f, fnt.getStyle());
sourceStyle.setFont(fnt);
}
if (paddingTop != null) {
sourceStyle.setPadding(TOP, paddingTop.getValue());
}
if (paddingBottom != null) {
sourceStyle.setPadding(BOTTOM, paddingBottom.getValue());
}
if (paddingLeft != null) {
sourceStyle.setPadding(LEFT, paddingLeft.getValue());
}
if (paddingRight != null) {
sourceStyle.setPadding(RIGHT, paddingRight.getValue());
}
if (marginTop != null) {
sourceStyle.setMargin(TOP, marginTop.getValue());
}
if (marginBottom != null) {
sourceStyle.setMargin(BOTTOM, marginBottom.getValue());
}
if (marginLeft != null) {
sourceStyle.setMargin(LEFT, marginLeft.getValue());
}
if (marginRight != null) {
sourceStyle.setMargin(RIGHT, marginRight.getValue());
}
}
}
@Override
public void flush() {
if (bgMotion != null) {
bgMotion.finish();
}
if (opacityMotion != null) {
opacityMotion.finish();
}
if (fgColorMotion != null) {
fgColorMotion.finish();
}
if (fontMotion != null) {
fontMotion.finish();
}
if (paddingTop != null) {
paddingTop.finish();
}
if (paddingBottom != null) {
paddingBottom.finish();
}
if (paddingLeft != null) {
paddingLeft.finish();
}
if (paddingRight != null) {
paddingRight.finish();
}
if (marginTop != null) {
marginTop.finish();
}
if (marginBottom != null) {
marginBottom.finish();
}
if (marginLeft != null) {
marginLeft.finish();
}
if (marginRight != null) {
marginRight.finish();
}
updateState();
}
};
}
use of com.codename1.ui.animations.Motion in project CodenameOne by codenameone.
the class Container method createAndStartAnimateMotion.
private Motion createAndStartAnimateMotion(int start, int destination, int duration) {
Motion m = createAnimateMotion(start, destination, duration);
m.start();
return m;
}
use of com.codename1.ui.animations.Motion in project CodenameOne by codenameone.
the class CommonTransitions method paintShiftFadeHierarchy.
private void paintShiftFadeHierarchy(Container c, int alpha, Graphics g, boolean incoming) {
int componentCount = c.getComponentCount();
for (int iter = 0; iter < componentCount; iter++) {
Component current = c.getComponentAt(iter);
if (current instanceof Container) {
paintShiftFadeHierarchy((Container) current, alpha, g, incoming);
continue;
}
g.setAlpha(alpha);
Motion m = getComponentShiftMotion(current, incoming);
if (m != null) {
int tval = m.getValue();
g.translate(tval, 0);
current.paintComponent(g, false);
g.translate(-tval, 0);
}
g.setAlpha(255);
}
}
use of com.codename1.ui.animations.Motion in project CodenameOne by codenameone.
the class CommonTransitions method initTransition.
/**
* {@inheritDoc}
*/
public void initTransition() {
firstFinished = false;
if (transitionType == TYPE_EMPTY) {
return;
}
startTime = System.currentTimeMillis();
Component source = getSource();
Component destination = getDestination();
position = 0;
int w = source.getWidth();
int h = source.getHeight();
// improper replace() calls, this may still be valid and shouldn't fail
if (w <= 0 || h <= 0) {
return;
}
// nothing to prepare in advance for a shift fade transition
if (transitionType == TYPE_SLIDE_AND_FADE) {
if (getSource() instanceof Form && getDestination() instanceof Form) {
motion = createMotion(100, 200, speed);
motion2 = createMotion(0, getDestination().getWidth(), speed);
motion.start();
motion2.start();
return;
}
transitionType = TYPE_SLIDE;
}
if (transitionType == TYPE_PULSATE_DIALOG) {
if (getDestination() instanceof Dialog) {
motion = createMotion(600, 1100, 150);
motion.start();
motion2 = createMotion(100, 255, 225);
motion2.start();
pulseState = 0;
Component c = getDialogParent(getDestination());
originalX = c.getX();
originalY = c.getY();
originalWidth = c.getWidth();
originalHeight = c.getHeight();
Display d = Display.getInstance();
Dialog dlg = (Dialog) destination;
// transparent image!
buffer = Image.createImage(Math.min(d.getDisplayWidth(), getDialogParent(dlg).getWidth()), Math.min(d.getDisplayHeight(), dlg.getContentPane().getParent().getHeight() + getDialogTitleHeight(dlg)), 0);
Graphics g = buffer.getGraphics();
Style stl = dlg.getDialogComponent().getStyle();
byte bgt = stl.getBgTransparency();
stl.setBgTransparency(0xff);
drawDialogCmp(buffer.getGraphics(), dlg);
stl.setBgTransparency(bgt & 0xff, true);
return;
}
transitionType = TYPE_EMPTY;
motion = createMotion(0, 0, 0);
pulseState = (byte) 3;
return;
}
if (Display.getInstance().areMutableImagesFast() || transitionType == TYPE_TIMELINE) {
if (buffer == null) {
buffer = createMutableImage(w, h);
} else {
// this might happen when screen orientation changes
if (buffer.getWidth() != w || buffer.getHeight() != h) {
buffer = createMutableImage(w, h);
rgbBuffer = null;
// slide motion might need resetting since screen size is different
motion = null;
}
}
}
if (transitionType == TYPE_FADE) {
motion = createMotion(0, 256, speed);
motion.start();
if (Display.getInstance().areMutableImagesFast()) {
Graphics g = buffer.getGraphics();
g.translate(-source.getAbsoluteX(), -source.getAbsoluteY());
if (getSource().getParent() != null) {
getSource().getComponentForm().paintComponent(g);
}
getSource().paintBackgrounds(g);
g.setClip(0, 0, buffer.getWidth() + source.getAbsoluteX(), buffer.getHeight() + source.getAbsoluteY());
paint(g, getDestination(), 0, 0);
rgbBuffer = new RGBImage(buffer.getRGBCached(), buffer.getWidth(), buffer.getHeight());
paint(g, getSource(), 0, 0, true);
g.translate(source.getAbsoluteX(), source.getAbsoluteY());
}
return;
}
if (transitionType == TYPE_TIMELINE) {
Graphics g = buffer.getGraphics();
g.translate(-source.getAbsoluteX(), -source.getAbsoluteY());
g.setClip(0, 0, buffer.getWidth() + source.getAbsoluteX(), buffer.getHeight() + source.getAbsoluteY());
if (timeline.getWidth() != buffer.getWidth() || timeline.getHeight() != buffer.getHeight()) {
timeline = timeline.scaled(buffer.getWidth(), buffer.getHeight());
}
if (timeline instanceof Timeline) {
((Timeline) timeline).setTime(0);
((Timeline) timeline).setLoop(false);
((Timeline) timeline).setAnimationDelay(0);
}
paint(g, getDestination(), 0, 0);
g.translate(source.getAbsoluteX(), source.getAbsoluteY());
return;
}
if (transitionType == TYPE_SLIDE || transitionType == TYPE_FAST_SLIDE || transitionType == TYPE_COVER || transitionType == TYPE_UNCOVER) {
int dest;
int startOffset = 0;
boolean direction = forward;
// flip the direction only for horizontal slides
if ((source.getUIManager().getLookAndFeel().isRTL()) && slideType == SLIDE_HORIZONTAL) {
direction = !direction;
}
if (slideType == SLIDE_HORIZONTAL) {
dest = w;
if (destination instanceof Dialog) {
startOffset = w - getDialogParent(destination).getWidth();
if (direction) {
startOffset -= getDialogParent(destination).getStyle().getMarginLeft(destination.isRTL());
} else {
startOffset -= getDialogParent(destination).getStyle().getMarginRight(destination.isRTL());
}
} else {
if (source instanceof Dialog) {
dest = getDialogParent(source).getWidth();
if (direction) {
dest += getDialogParent(source).getStyle().getMarginLeft(source.isRTL());
} else {
dest += getDialogParent(source).getStyle().getMarginRight(source.isRTL());
}
}
}
} else {
dest = h;
if (destination instanceof Dialog) {
startOffset = h - getDialogParent(destination).getHeight() - getDialogTitleHeight((Dialog) destination);
if (direction) {
startOffset -= getDialogParent(destination).getStyle().getMarginBottom();
} else {
startOffset -= getDialogParent(destination).getStyle().getMarginTop();
startOffset -= ((Dialog) destination).getTitleStyle().getMarginTop();
if (!drawDialogMenu && ((Dialog) destination).getCommandCount() > 0) {
Container p = ((Dialog) destination).getSoftButton(0).getParent();
if (p != null) {
startOffset -= p.getHeight();
}
}
}
} else {
if (source instanceof Dialog) {
dest = getDialogParent(source).getHeight() + getDialogTitleHeight((Dialog) source);
if (direction) {
dest += getDialogParent(source).getStyle().getMarginBottom();
} else {
dest += getDialogParent(source).getStyle().getMarginTop();
dest += ((Dialog) source).getTitleStyle().getMarginTop();
if (((Dialog) source).getCommandCount() > 0) {
Container p = ((Dialog) source).getSoftButton(0).getParent();
if (p != null) {
dest += p.getHeight();
}
}
}
}
}
}
motion = createMotion(startOffset, dest, speed);
if (!Display.getInstance().areMutableImagesFast()) {
motion.start();
buffer = null;
return;
}
// make sure the destination is painted fully at least once
// we must use a full buffer otherwise the clipping will take effect
Graphics g = buffer.getGraphics();
// tinting is expensive
if (getSource() instanceof Dialog) {
paint(g, getDestination(), 0, 0);
if (transitionType == TYPE_FAST_SLIDE && !(destination instanceof Dialog)) {
Dialog d = (Dialog) source;
secondaryBuffer = createMutableImage(getDialogParent(d).getWidth(), getDialogParent(d).getHeight() + getDialogTitleHeight(d));
drawDialogCmp(secondaryBuffer.getGraphics(), d);
}
} else {
if (getDestination() instanceof Dialog) {
paint(g, getSource(), 0, 0);
if (transitionType == TYPE_FAST_SLIDE && !(source instanceof Dialog)) {
Dialog d = (Dialog) destination;
secondaryBuffer = createMutableImage(getDialogParent(d).getWidth(), d.getContentPane().getParent().getHeight() + getDialogTitleHeight(d));
drawDialogCmp(secondaryBuffer.getGraphics(), d);
}
} else {
paint(g, source, -source.getAbsoluteX(), -source.getAbsoluteY(), true);
if (transitionType == TYPE_FAST_SLIDE) {
secondaryBuffer = createMutableImage(destination.getWidth(), destination.getHeight());
paint(secondaryBuffer.getGraphics(), destination, -destination.getAbsoluteX(), -destination.getAbsoluteY());
}
}
}
motion.start();
}
}
use of com.codename1.ui.animations.Motion in project CodenameOne by codenameone.
the class SideMenuBar method createMenu.
private Form createMenu(final String placement) {
final Form m = new Form() {
private boolean pressedInRightPanel;
private boolean manualMotionLock;
protected boolean shouldSendPointerReleaseToOtherForm() {
return true;
}
void actionCommandImpl(Command cmd, ActionEvent ev) {
if (cmd instanceof SideMenuBar.CommandWrapper) {
cmd = ((SideMenuBar.CommandWrapper) cmd).cmd;
ev = new ActionEvent(cmd, ActionEvent.Type.Command);
}
final Command c = cmd;
final ActionEvent e = ev;
Display.getInstance().scheduleBackgroundTask(new Runnable() {
public void run() {
Display.getInstance().invokeAndBlock(new Runnable() {
public void run() {
while (Display.getInstance().getCurrent() != parent) {
try {
Thread.sleep(40);
} catch (Exception ex) {
}
}
}
});
Display.getInstance().callSerially(new Runnable() {
public void run() {
parent.actionCommandImpl(c, e);
}
});
}
});
}
protected void sizeChanged(int w, int h) {
Style formStyle = getStyle();
int width = w - (formStyle.getHorizontalMargins());
parent.sizeChangedInternal(w, h);
// close the menu
if (getWidth() != width) {
closeMenu();
}
super.sizeChanged(w, h);
}
public void pointerPressed(int x, int y) {
if (manualMotionLock) {
return;
}
super.pointerPressed(x, y);
if (rightPanel.contains(x, y)) {
pressedInRightPanel = true;
}
}
public void pointerDragged(int[] x, int[] y) {
if (manualMotionLock) {
return;
}
if (!transitionRunning && pressedInRightPanel) {
dragActivated = true;
pressedInRightPanel = false;
}
if (dragActivated) {
setMenuGlassPane(menu, placement);
draggedX = x[0];
repaint();
return;
}
super.pointerDragged(x, y);
}
public void pointerReleased(int x, int y) {
if (manualMotionLock) {
return;
}
super.pointerReleased(x, y);
boolean isRTLValue = isRTL();
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
isRTLValue = !isRTLValue;
}
int displayWidth = Display.getInstance().getDisplayWidth();
if (isRTLValue) {
if (!transitionRunning && dragActivated && x < (displayWidth - rightPanel.getWidth()) / 2) {
final Motion motion = Motion.createEaseInOutMotion(draggedX, rightPanel.getWidth(), 200);
motion.start();
registerAnimated(new Animation() {
public boolean animate() {
draggedX = motion.getValue();
if (motion.isFinished()) {
dragActivated = false;
Display.getInstance().getCurrent().setGlassPane(null);
deregisterAnimated(this);
}
return true;
}
public void paint(Graphics g) {
repaint();
}
});
return;
}
} else {
if (!transitionRunning && dragActivated && x > (displayWidth - rightPanel.getWidth()) / 2) {
final Motion motion = Motion.createEaseInOutMotion(draggedX, Display.getInstance().getDisplayWidth() - rightPanel.getWidth(), 200);
motion.start();
registerAnimated(new Animation() {
public boolean animate() {
draggedX = motion.getValue();
if (motion.isFinished()) {
dragActivated = false;
Display.getInstance().getCurrent().setGlassPane(null);
deregisterAnimated(this);
}
return true;
}
public void paint(Graphics g) {
repaint();
}
});
return;
}
}
if (dragActivated || rightPanel.contains(x, y)) {
setMenuGlassPane(menu, placement);
draggedX = x;
int start = x;
int end = 0;
if (isRTLValue) {
end = getWidth();
}
final Motion motion = Motion.createEaseInOutMotion(start, end, getUIManager().getThemeConstant("sideMenuAnimSpeedInt", 300));
motion.start();
manualMotionLock = true;
sideSwipePotential = false;
rightSideSwipePotential = false;
topSwipePotential = false;
registerAnimated(new Animation() {
public boolean animate() {
draggedX = motion.getValue();
if (motion.isFinished()) {
dragActivated = false;
}
return true;
}
public void paint(Graphics g) {
repaint();
if (draggedX == motion.getDestinationValue() && motion.isFinished()) {
parent.setTransitionInAnimator(CommonTransitions.createEmpty());
parent.show();
deregisterAnimated(this);
Display.getInstance().callSerially(new Runnable() {
public void run() {
clean();
}
});
}
}
});
}
}
public void keyReleased(int keyCode) {
if (keyCode == leftSK) {
if (transitionRunning) {
return;
}
closeMenu();
return;
}
super.keyReleased(keyCode);
}
};
m.setScrollable(false);
m.removeComponentFromForm(m.getTitleArea());
m.putClientProperty("Menu", "true");
m.setTransitionInAnimator(CommonTransitions.createEmpty());
m.setTransitionOutAnimator(CommonTransitions.createEmpty());
m.setBackCommand(new Command("") {
public void actionPerformed(ActionEvent evt) {
if (transitionRunning) {
return;
}
closeMenu();
}
});
m.setLayout(new BorderLayout());
if (Display.getInstance().areMutableImagesFast()) {
rightPanel = new Container(new BorderLayout());
} else {
rightPanel = new Container(new BorderLayout()) {
public void paintBackground(Graphics g) {
}
public void paintBackgrounds(Graphics g) {
}
public void paint(Graphics g) {
Component c = (Component) rightPanel.getClientProperty("$parent");
// not sure why its happening: https://code.google.com/p/codenameone/issues/detail?id=1072
if (c != null) {
boolean b = c.isVisible();
c.setVisible(true);
int x = getAbsoluteX();
g.translate(x, 0);
Container.sidemenuBarTranslation = x;
c.paintComponent(g, true);
Container.sidemenuBarTranslation = 0;
g.translate(-x, 0);
c.setVisible(b);
}
}
};
}
if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
int v = 0;
if (Display.getInstance().isPortrait()) {
if (Display.getInstance().isTablet()) {
v = getUIManager().getThemeConstant("topMenuSizeTabPortraitInt", -1);
if (v < 0) {
v = m.getHeight() * 2 / 3;
} else {
v = m.getHeight() / 100 * v;
}
} else {
v = getUIManager().getThemeConstant("topMenuSizePortraitInt", -1);
if (v < 0) {
v = openButton.getHeight();
} else {
v = m.getHeight() / 100 * v;
}
}
} else {
if (Display.getInstance().isTablet()) {
v = getUIManager().getThemeConstant("topMenuSizeTabLandscapeInt", -1);
if (v < 0) {
v = m.getHeight() * 3 / 4;
} else {
v = m.getWidth() / 100 * v;
}
} else {
v = getUIManager().getThemeConstant("topMenuSizeLandscapeInt", -1);
if (v < 0) {
v = m.getHeight() * 4 / 10;
} else {
v = m.getHeight() / 100 * v;
}
}
}
rightPanel.setPreferredH(v);
} else {
if (Display.getInstance().isPortrait()) {
int v = 0;
if (Display.getInstance().isTablet()) {
v = getUIManager().getThemeConstant("sideMenuSizeTabPortraitInt", -1);
if (v < 0) {
v = m.getWidth() * 2 / 3;
} else {
v = m.getWidth() / 100 * v;
}
} else {
v = getUIManager().getThemeConstant("sideMenuSizePortraitInt", -1);
if (v < 0) {
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
if (isRTL()) {
v = openButton.getWidth();
} else {
v = rightSideButton.getWidth();
}
} else {
v = openButton.getWidth();
}
} else {
v = m.getWidth() / 100 * v;
}
}
rightPanel.setPreferredW(v);
} else {
int v = 0;
if (Display.getInstance().isTablet()) {
v = getUIManager().getThemeConstant("sideMenuSizeTabLandscapeInt", -1);
if (v < 0) {
v = m.getWidth() * 3 / 4;
} else {
v = m.getWidth() / 100 * v;
}
} else {
v = getUIManager().getThemeConstant("sideMenuSizeLandscapeInt", -1);
if (v < 0) {
v = m.getWidth() * 4 / 10;
} else {
v = m.getWidth() / 100 * v;
}
}
rightPanel.setPreferredW(v);
}
}
if (sidePanel != null) {
sidePanel.removeAll();
sidePanel = null;
}
sidePanel = createSideNavigationComponent(getCommands(), placement);
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
m.addComponent(BorderLayout.WEST, rightPanel);
m.addComponent(BorderLayout.CENTER, sidePanel);
} else {
if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
m.addComponent(BorderLayout.NORTH, rightPanel);
m.addComponent(BorderLayout.CENTER, sidePanel);
Button button = new Button(" ");
button.setUIID("Container");
button.setPreferredH(Display.getInstance().getDisplayHeight() / 10);
m.addComponent(BorderLayout.SOUTH, button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
closeMenu();
}
});
} else {
m.addComponent(BorderLayout.EAST, rightPanel);
m.addComponent(BorderLayout.CENTER, sidePanel);
}
}
m.putClientProperty("cn1$sideMenuParent", this);
return m;
}
Aggregations