use of com.codename1.ui in project CodenameOne by codenameone.
the class Component method drawPainters.
private void drawPainters(com.codename1.ui.Graphics g, Component par, Component c, int x, int y, int w, int h) {
if (flatten && getWidth() > 0 && getHeight() > 0) {
Image i = (Image) getClientProperty("$FLAT");
int absX = getAbsoluteX() + getScrollX();
int absY = getAbsoluteY() + getScrollY();
if (i == null || i.getWidth() != getWidth() || i.getHeight() != getHeight()) {
i = Image.createImage(getWidth(), getHeight());
Graphics tg = i.getGraphics();
// tg.translate(g.getTranslateX(), g.getTranslateY());
drawPaintersImpl(tg, par, c, x, y, w, h);
paintBackgroundImpl(tg);
putClientProperty("$FLAT", i);
}
int tx = g.getTranslateX();
int ty = g.getTranslateY();
g.translate(-tx + absX, -ty + absY);
g.drawImage(i, 0, 0);
g.translate(tx - absX, ty - absY);
return;
}
drawPaintersImpl(g, par, c, x, y, w, h);
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class ComponentSelector method setIcon.
/**
* Sets the icon of all elements in this set to a material icon. This will use
* the foreground color of each label as the icon's foreground color.
* @param materialIcon The icon charcode.
* @param size The size of the icon (in mm)
* @return Self for chaining
* @see FontImage#createMaterial(char, com.codename1.ui.plaf.Style, float)
*/
public ComponentSelector setIcon(char materialIcon, float size) {
for (Component c : this) {
if (c instanceof Label) {
Label l = (Label) c;
Style style = new Style();
Style cStyle = c.getUnselectedStyle();
style.setBgTransparency(0);
style.setFgColor(cStyle.getFgColor());
l.setIcon(FontImage.createMaterial(materialIcon, style, size));
if (c instanceof Button) {
Button b = (Button) c;
style = new Style();
cStyle = c.getPressedStyle();
style.setBgTransparency(0);
style.setFgColor(cStyle.getFgColor());
b.setPressedIcon(FontImage.createMaterial(materialIcon, style, size));
}
}
}
return this;
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class ComponentSelector method setPadding.
/**
* Sets padding to all components in found set.
* @param top Top padding in pixels.
* @param right Right padding in pixels
* @param bottom Bottom padding in pixels.
* @param left Left padding in pixels.
* @return
* @see #getStyle(com.codename1.ui.Component)
*/
public ComponentSelector setPadding(int top, int right, int bottom, int left) {
Style s = currentStyle();
s.setPaddingUnit(Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS);
s.setPadding(top, bottom, left, right);
return this;
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class ComponentSelector method fadeOut.
/**
* Fades out components in this set.
* @param duration Duration of animation.
* @param callback Callback to run when animation completes.
* @return Self for chaining.
*/
public ComponentSelector fadeOut(int duration, final SuccessCallback<ComponentSelector> callback) {
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.addAnimation(ComponentAnimation.compoundAnimation(animations.toArray(new ComponentAnimation[animations.size()])), new Runnable() {
public void run() {
for (final Component c : animatingComponents) {
// c.setHidden(true);
c.setVisible(false);
final Container placeholder = (Container) c.getClientProperty(placeholderProperty);
c.putClientProperty(placeholderProperty, null);
if (placeholder != null) {
Container parent = placeholder.getParent();
/*
if (parent == null) {
System.out.println("Deferring replace back");
$(new Runnable() {
public void run() {
Container parent = placeholder.getParent();
if (parent != null) {
System.out.println("Found parent after deferral");
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
}
});
} else {
*/
if (parent != null) {
parent.replace(placeholder, c, CommonTransitions.createEmpty());
}
// }
}
}
if (callback != null) {
callback.onSucess(ComponentSelector.this);
}
}
});
}
return this;
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class Display method init.
/**
* This is the INTERNAL Display initialization method, it will be removed in future versions of the API.
* This method must be called before any Form is shown
*
* @param m platform specific object used by the implementation
* @deprecated this method is invoked internally do not invoke it!
*/
public static void init(Object m) {
if (!INSTANCE.codenameOneRunning) {
INSTANCE.codenameOneRunning = true;
INSTANCE.displayInitTime = System.currentTimeMillis();
// restore menu state from previous run if exists
int commandBehaviour = COMMAND_BEHAVIOR_DEFAULT;
if (INSTANCE.impl != null) {
commandBehaviour = INSTANCE.impl.getCommandBehavior();
}
INSTANCE.impl = (CodenameOneImplementation) ImplementationFactory.getInstance().createImplementation();
INSTANCE.impl.setDisplayLock(lock);
INSTANCE.impl.initImpl(m);
INSTANCE.codenameOneGraphics = new Graphics(INSTANCE.impl.getNativeGraphics());
INSTANCE.codenameOneGraphics.paintPeersBehind = INSTANCE.impl.paintNativePeersBehind();
INSTANCE.impl.setCodenameOneGraphics(INSTANCE.codenameOneGraphics);
// only enable but never disable the third softbutton
if (INSTANCE.impl.isThirdSoftButton()) {
INSTANCE.thirdSoftButton = true;
}
if (INSTANCE.impl.getSoftkeyCount() > 0) {
MenuBar.leftSK = INSTANCE.impl.getSoftkeyCode(0)[0];
if (INSTANCE.impl.getSoftkeyCount() > 1) {
MenuBar.rightSK = INSTANCE.impl.getSoftkeyCode(1)[0];
if (INSTANCE.impl.getSoftkeyCode(1).length > 1) {
MenuBar.rightSK2 = INSTANCE.impl.getSoftkeyCode(1)[1];
}
}
}
MenuBar.backSK = INSTANCE.impl.getBackKeyCode();
MenuBar.backspaceSK = INSTANCE.impl.getBackspaceKeyCode();
MenuBar.clearSK = INSTANCE.impl.getClearKeyCode();
INSTANCE.PATHLENGTH = INSTANCE.impl.getDragPathLength();
INSTANCE.dragPathX = new float[INSTANCE.PATHLENGTH];
INSTANCE.dragPathY = new float[INSTANCE.PATHLENGTH];
INSTANCE.dragPathTime = new long[INSTANCE.PATHLENGTH];
com.codename1.util.StringUtil.setImplementation(INSTANCE.impl);
com.codename1.io.Util.setImplementation(INSTANCE.impl);
// generally its probably a bug but we can let it slide...
if (INSTANCE.edt == null) {
INSTANCE.touchScreen = INSTANCE.impl.isTouchDevice();
// initialize the Codename One EDT which from now on will take all responsibility
// for the event delivery.
INSTANCE.edt = new CodenameOneThread(new RunnableWrapper(null, 3), "EDT");
INSTANCE.impl.setThreadPriority(INSTANCE.edt, INSTANCE.impl.getEDTThreadPriority());
INSTANCE.edt.start();
}
INSTANCE.impl.postInit();
INSTANCE.setCommandBehavior(commandBehaviour);
} else {
INSTANCE.impl.confirmControlView();
}
}
Aggregations