use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class ComponentSelector method fadeIn.
/**
* Fade in this set of components. Prior to calling this, the component visibility should
* be set to "false".
* @param duration The duration of the fade in.
* @param callback Callback to run when animation completes.
* @return
*/
public ComponentSelector fadeIn(final int duration, final SuccessCallback<ComponentSelector> callback) {
final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
AnimationManager mgr = null;
ArrayList<ComponentAnimation> animations1 = new ArrayList<ComponentAnimation>();
final ArrayList<ComponentAnimation> animations2 = new ArrayList<ComponentAnimation>();
final ArrayList<Component> animatingComponents = new ArrayList<Component>();
for (Component c : this) {
Container parent = c.getParent();
if (parent != null) {
AnimationManager cmgr = c.getAnimationManager();
if (cmgr != null) {
mgr = cmgr;
Container placeholder = new Container();
// placeholder.getStyle().setBgColor(0xff0000);
// placeholder.getStyle().setBgTransparency(255);
// placeholder.setShowEvenIfBlank(true);
c.putClientProperty(placeholderProperty, placeholder);
Component.setSameHeight(placeholder, c);
Component.setSameWidth(placeholder, c);
$(placeholder).setMargin(c.getStyle().getMarginTop(), c.getStyle().getMarginRight(false), c.getStyle().getMarginBottom(), c.getStyle().getMarginLeft(false)).setPadding(c.getStyle().getPaddingTop(), c.getStyle().getPaddingRight(false), c.getStyle().getPaddingBottom(), c.getStyle().getPaddingLeft(false));
// System.out.println("Placeholder height "+c.getHeight());
// parent.replace(c, placeholder, false);
// c.setHidden(false);
ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createEmpty());
animations1.add(a);
animatingComponents.add(c);
}
// centerBackground.add(BorderLayout.CENTER, boxy);
}
}
if (mgr != null) {
mgr.addAnimation(ComponentAnimation.compoundAnimation(animations1.toArray(new ComponentAnimation[animations1.size()])), new Runnable() {
public void run() {
AnimationManager mgr = null;
for (final Component c : animatingComponents) {
Container placeholder = (Container) c.getClientProperty(placeholderProperty);
if (placeholder != null) {
// System.out.println("Placeholder height after replace "+(c.getHeight() + c.getStyle().getMarginBottom() + c.getStyle().getMarginTop()));
// System.out.println("Placeholder not null");
c.putClientProperty(placeholderProperty, null);
AnimationManager cmgr = placeholder.getAnimationManager();
if (cmgr != null) {
// System.out.println("Animation manager not null");
mgr = cmgr;
c.setVisible(true);
Container parent = placeholder.getParent();
if (parent != null) {
// System.out.println("Parent not null");
ComponentAnimation a = parent.createReplaceTransition(placeholder, c, CommonTransitions.createFade(duration));
animations2.add(a);
}
}
}
}
if (mgr != null) {
final AnimationManager fmgr = mgr;
$(new Runnable() {
public void run() {
fmgr.addAnimation(ComponentAnimation.compoundAnimation(animations2.toArray(new ComponentAnimation[animations2.size()])), new Runnable() {
public void run() {
if (callback != null) {
callback.onSucess(ComponentSelector.this);
}
}
});
}
});
}
}
});
}
return this;
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class ComponentSelector method fadeInAndWait.
/**
* Fades in this component and blocks until animation is complete.
* @param duration The duration of the animation.
* @return Self for chaining.
*/
public ComponentSelector fadeInAndWait(final int duration) {
final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
AnimationManager mgr = null;
ArrayList<ComponentAnimation> animations1 = new ArrayList<ComponentAnimation>();
final ArrayList<ComponentAnimation> animations2 = new ArrayList<ComponentAnimation>();
final ArrayList<Component> animatingComponents = new ArrayList<Component>();
for (Component c : this) {
Container parent = c.getParent();
if (parent != null) {
AnimationManager cmgr = c.getAnimationManager();
if (cmgr != null) {
mgr = cmgr;
Container placeholder = new Container();
// placeholder.getStyle().setBgColor(0xff0000);
// placeholder.getStyle().setBgTransparency(255);
// placeholder.setShowEvenIfBlank(true);
c.putClientProperty(placeholderProperty, placeholder);
Component.setSameHeight(placeholder, c);
Component.setSameWidth(placeholder, c);
$(placeholder).setMargin(c.getStyle().getMarginTop(), c.getStyle().getMarginRight(false), c.getStyle().getMarginBottom(), c.getStyle().getMarginLeft(false)).setPadding(c.getStyle().getPaddingTop(), c.getStyle().getPaddingRight(false), c.getStyle().getPaddingBottom(), c.getStyle().getPaddingLeft(false));
// System.out.println("Placeholder height "+c.getHeight());
// parent.replace(c, placeholder, false);
// c.setHidden(false);
ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createEmpty());
animations1.add(a);
animatingComponents.add(c);
}
// centerBackground.add(BorderLayout.CENTER, boxy);
}
}
if (mgr != null) {
mgr.addAnimationAndBlock(ComponentAnimation.compoundAnimation(animations1.toArray(new ComponentAnimation[animations1.size()])));
for (final Component c : animatingComponents) {
Container placeholder = (Container) c.getClientProperty(placeholderProperty);
if (placeholder != null) {
// System.out.println("Placeholder height after replace "+(c.getHeight() + c.getStyle().getMarginBottom() + c.getStyle().getMarginTop()));
// System.out.println("Placeholder not null");
c.putClientProperty(placeholderProperty, null);
AnimationManager cmgr = placeholder.getAnimationManager();
if (cmgr != null) {
// System.out.println("Animation manager not null");
mgr = cmgr;
c.setVisible(true);
Container parent = placeholder.getParent();
if (parent != null) {
// System.out.println("Parent not null");
ComponentAnimation a = parent.createReplaceTransition(placeholder, c, CommonTransitions.createFade(duration));
animations2.add(a);
}
}
}
}
if (mgr != null) {
mgr.addAnimationAndBlock(ComponentAnimation.compoundAnimation(animations2.toArray(new ComponentAnimation[animations2.size()])));
}
}
return this;
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class ComponentSelector method animateStyle.
/**
* Animates this set of components, replacing any modified style properties of the
* destination style to the components.
* @param destStyle The style to apply to the components via animation.
* @param duration The duration of the animation (ms)
* @param callback Callback to call after animation is complete.
* @return Self for chaining
* @see Component#createStyleAnimation(java.lang.String, int)
*/
public ComponentSelector animateStyle(Style destStyle, int duration, final SuccessCallback<ComponentSelector> callback) {
ArrayList<ComponentAnimation> animations = new ArrayList<ComponentAnimation>();
AnimationManager mgr = null;
for (Component c : this) {
AnimationManager cmgr = c.getAnimationManager();
if (cmgr != null) {
mgr = cmgr;
Style sourceStyle = c.getUnselectedStyle();
destStyle.merge(sourceStyle);
animations.add(c.createStyleAnimation(sourceStyle, destStyle, duration, null));
}
}
if (mgr != null) {
ComponentAnimation anim = ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()]));
mgr.addAnimation(anim, new Runnable() {
public void run() {
if (callback != null) {
callback.onSucess(ComponentSelector.this);
}
}
});
}
return this;
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class ComponentSelector method fadeOutAndWait.
/**
* Hide the matched elements by fading them to transparent. Blocks thread until animation is complete.
* @param duration Duration of animation.
* @return Self for chaining.
*/
public ComponentSelector fadeOutAndWait(int duration) {
final String placeholderProperty = "com.codename1.ui.ComponentSelector#fadeOutPlaceholder";
AnimationManager mgr = null;
ArrayList<ComponentAnimation> animations = new ArrayList<ComponentAnimation>();
final ArrayList<Component> animatingComponents = new ArrayList<Component>();
for (Component c : this) {
Container parent = c.getParent();
if (parent != null) {
AnimationManager cmgr = c.getAnimationManager();
if (cmgr != null) {
mgr = cmgr;
Container placeholder = new Container();
// placeholder.setShowEvenIfBlank(true);
c.putClientProperty(placeholderProperty, placeholder);
Component.setSameHeight(placeholder, c);
Component.setSameWidth(placeholder, c);
$(placeholder).setMargin(c.getStyle().getMarginTop(), c.getStyle().getMarginRight(false), c.getStyle().getMarginBottom(), c.getStyle().getMarginLeft(false)).setPadding(c.getStyle().getPaddingTop(), c.getStyle().getPaddingRight(false), c.getStyle().getPaddingBottom(), c.getStyle().getPaddingLeft(false));
ComponentAnimation a = parent.createReplaceTransition(c, placeholder, CommonTransitions.createFade(duration));
animations.add(a);
animatingComponents.add(c);
}
// centerBackground.add(BorderLayout.CENTER, boxy);
}
}
if (mgr != null) {
mgr.addAnimationAndBlock(ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()])));
for (final Component c : animatingComponents) {
c.setVisible(false);
final Container placeholder = (Container) c.getClientProperty(placeholderProperty);
c.putClientProperty(placeholderProperty, null);
if (placeholder != null) {
Container parent = placeholder.getParent();
if (parent != null) {
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
}
}
}
return this;
}
use of com.codename1.ui.animations.Animation in project CodenameOne by codenameone.
the class AddResourceDialog method addResource.
public String addResource(EditableResources res, ResourceEditorView view) {
// "Image", "Animation", "Font", "Theme", "Data", "Localization (L10N)"
String newName = name.getText();
for (String r : res.getResourceNames()) {
if (r.equalsIgnoreCase(newName)) {
JOptionPane.showMessageDialog(this, "A resource called: " + newName + " already exists\nYou must delete the resource first.", "Add Resource", JOptionPane.ERROR_MESSAGE);
return null;
}
}
switch(type.getSelectedIndex()) {
case // image
IMAGE:
ImageRGBEditor imageEditor = new ImageRGBEditor(res, name.getText(), view);
imageEditor.selectFile();
view.setSelectedResource(name.getText());
break;
case MULTI_IMAGE:
ImageMultiEditor multiImageEditor = new ImageMultiEditor(res, name.getText(), view);
view.setSelectedResource(name.getText());
break;
case TIMELINE:
new TimelineEditor(res, name.getText(), view);
view.setSelectedResource(name.getText());
break;
case // animation
ANIMATION:
TimelineEditor.selectFile(view, res, name.getText());
/*ImageEditor animationEditor = new ImageEditor(res, name.getText());
animationEditor.setAnimation(true);
animationEditor.selectFile(view);*/
break;
case // font
FONT:
new FontEditor(res, new EditorFont(com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_MEDIUM), null, "Arial-plain-12", true, RenderingHints.VALUE_TEXT_ANTIALIAS_ON, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,;:!@/\\*()[]{}|#$%^&<>?'\"+- "), name.getText()).createFont();
view.setSelectedResource(name.getText());
break;
case // theme
THEME:
res.setTheme(name.getText(), new Hashtable());
view.setSelectedResource(name.getText());
// ResourceEditorView.expandAndSelect(tree, name.getText());
break;
case // data
DATA:
DataEditor dataEditor = new DataEditor(res, name.getText());
dataEditor.selectDataFile(view);
view.setSelectedResource(name.getText());
break;
case // localization
LOCALIZATION:
Hashtable h = new Hashtable();
Hashtable local = new Hashtable();
local.put("cancel", "Cancel");
local.put("ok", "OK");
local.put("menu", "Menu");
local.put("select", "Select");
local.put("edit", "Edit");
h.put("en", local);
res.setL10N(name.getText(), h);
view.setSelectedResource(name.getText());
// ResourceEditorView.expandAndSelect(tree, name.getText());
break;
case UI:
UserInterfaceEditor uiEditor = new UserInterfaceEditor(name.getText(), res, view.getProjectGeneratorSettings(), view);
view.setSelectedResource(name.getText());
break;
}
return name.getText();
}
Aggregations