use of com.codename1.ui.Form in project CodenameOne by codenameone.
the class InteractionDialog method cleanupLayer.
private void cleanupLayer(Form f) {
if (formMode) {
Container c = (Container) f.getFormLayeredPane(InteractionDialog.class, true);
c.removeAll();
c.remove();
}
}
use of com.codename1.ui.Form in project CodenameOne by codenameone.
the class InteractionDialog method show.
/**
* 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
*/
public void show(int top, int bottom, int left, int right) {
disposed = false;
Form f = Display.getInstance().getCurrent();
getUnselectedStyle().setMargin(TOP, top);
getUnselectedStyle().setMargin(BOTTOM, bottom);
getUnselectedStyle().setMargin(LEFT, left);
getUnselectedStyle().setMargin(RIGHT, right);
getUnselectedStyle().setMarginUnit(new byte[] { Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS });
// might occur when showing the dialog twice...
remove();
getLayeredPane(f).addComponent(BorderLayout.center(this));
if (animateShow) {
int x = left + (f.getWidth() - right - left) / 2;
int y = top + (f.getHeight() - bottom - top) / 2;
if (repositionAnimation) {
getParent().setX(x);
getParent().setY(y);
getParent().setWidth(1);
getParent().setHeight(1);
} else {
getParent().setX(getX());
getParent().setY(getY());
setX(0);
setY(0);
getParent().setWidth(getWidth());
getParent().setHeight(getHeight());
}
getLayeredPane(f).animateLayout(400);
} else {
getLayeredPane(f).revalidate();
}
/*
Form f = Display.getInstance().getCurrent();
f.getLayeredPane().setLayout(new BorderLayout());
getUnselectedStyle().setMargin(TOP, top);
getUnselectedStyle().setMargin(BOTTOM, bottom);
getUnselectedStyle().setMargin(LEFT, left);
getUnselectedStyle().setMargin(RIGHT, right);
getUnselectedStyle().setMarginUnit(new byte[] {Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS, Style.UNIT_TYPE_PIXELS});
f.getLayeredPane().addComponent(BorderLayout.CENTER, this);
if(animateShow) {
int x = left + (f.getWidth() - right - left) / 2;
int y = top + (f.getHeight() - bottom - top) / 2;
setX(x);
setY(y);
setWidth(1);
setHeight(1);
f.getLayeredPane().animateLayout(400);
} else {
f.getLayeredPane().revalidate();
}
*/
}
use of com.codename1.ui.Form in project CodenameOne by codenameone.
the class Border method createImageSplicedBorder.
/**
* The given image is spliced into 9 pieces based on the provided top, right, bottom, and left insets, and the resulting
* sub-images are used to form a 9-piece image border via {@link #createImageBorder(com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image, com.codename1.ui.Image) }
*
* <p>Insets are all given in a (u,v) coordinate space where (0,0) is the top-left corner of the image, and (1.0, 1.0) is the bottom-right corner of the image.</p>
* @param img The image to be used as a background image and spliced.
* @param topInset
* @param rightInset
* @param bottomInset
* @param leftInset
* @return A 9-piece image border.
*/
public static Border createImageSplicedBorder(Image img, double topInset, double rightInset, double bottomInset, double leftInset) {
Border b = new Border();
b.type = TYPE_IMAGE;
int w = img.getWidth();
int h = img.getHeight();
int topInsetPx = (int) Math.round(h * topInset);
int leftInsetPx = (int) Math.round(w * leftInset);
int rightInsetPx = (int) Math.round(w * rightInset);
int bottomInsetPx = (int) Math.round(h * bottomInset);
// We need to make sure that every splice has a positive width and height
if (topInsetPx + bottomInsetPx >= h) {
bottomInsetPx = h - topInsetPx - 1;
if (bottomInsetPx < 1) {
bottomInsetPx = 1;
topInsetPx = h - bottomInsetPx - 1;
}
}
if (leftInsetPx + rightInsetPx >= w) {
rightInsetPx = w - leftInsetPx - 1;
if (rightInsetPx < 1) {
rightInsetPx = 1;
leftInsetPx = w - rightInsetPx - 1;
}
}
Image top = img.subImage(leftInsetPx, 0, w - leftInsetPx - rightInsetPx, topInsetPx, true);
Image bottom = img.subImage(leftInsetPx, h - bottomInsetPx, w - leftInsetPx - rightInsetPx, bottomInsetPx, true);
Image left = img.subImage(0, topInsetPx, leftInsetPx, h - topInsetPx - bottomInsetPx, true);
Image right = img.subImage(w - rightInsetPx, topInsetPx, rightInsetPx, h - topInsetPx - bottomInsetPx, true);
Image topLeft = img.subImage(0, 0, leftInsetPx, topInsetPx, true);
Image topRight = img.subImage(w - rightInsetPx, 0, rightInsetPx, topInsetPx, true);
Image bottomLeft = img.subImage(0, h - bottomInsetPx, leftInsetPx, bottomInsetPx, true);
Image bottomRight = img.subImage(w - rightInsetPx, h - bottomInsetPx, rightInsetPx, bottomInsetPx, true);
Image background = img.subImage(leftInsetPx, topInsetPx, w - leftInsetPx - rightInsetPx, h - topInsetPx - bottomInsetPx, true);
b.images = new Image[] { top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight, background };
return b;
}
use of com.codename1.ui.Form in project CodenameOne by codenameone.
the class DefaultLookAndFeel method drawPullToRefresh.
/**
* {@inheritDoc}
*/
public void drawPullToRefresh(Graphics g, final Component cmp, boolean taskExecuted) {
final Form parentForm = cmp.getComponentForm();
final int scrollY = cmp.getScrollY();
Component cmpToDraw;
if (taskExecuted) {
cmpToDraw = updating;
} else {
if (-scrollY > getPullToRefreshHeight()) {
cmpToDraw = releaseToRefresh;
} else {
cmpToDraw = pullDown;
}
}
if (pull.getComponentAt(0) != updating && cmpToDraw != pull.getComponentAt(0)) {
parentForm.registerAnimated(new Animation() {
int counter = 0;
Image i;
{
i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
if (i == null) {
i = getDefaultRefreshIcon();
}
}
public boolean animate() {
counter++;
if (pull.getComponentAt(0) == releaseToRefresh) {
((Label) releaseToRefresh).setIcon(i.rotate(180 - (180 / 6) * counter));
} else {
((Label) pullDown).setIcon(i.rotate(180 * counter / 6));
}
if (counter == 6) {
((Label) releaseToRefresh).setIcon(i);
((Label) pullDown).setIcon(i.rotate(180));
parentForm.deregisterAnimated(this);
}
cmp.repaint(cmp.getAbsoluteX(), cmp.getAbsoluteY() - getPullToRefreshHeight(), cmp.getWidth(), getPullToRefreshHeight());
return false;
}
public void paint(Graphics g) {
}
});
}
if (pull.getComponentAt(0) != cmpToDraw && cmpToDraw instanceof Label && (pull.getComponentAt(0) instanceof Label)) {
((Label) cmpToDraw).setIcon(((Label) pull.getComponentAt(0)).getIcon());
}
Component current = pull.getComponentAt(0);
if (current != cmpToDraw) {
pull.replace(current, cmpToDraw, null);
}
pull.setWidth(cmp.getWidth());
pull.setX(cmp.getAbsoluteX());
pull.setY(cmp.getY() - scrollY - getPullToRefreshHeight());
pull.layoutContainer();
pull.paintComponent(g);
}
use of com.codename1.ui.Form in project CodenameOne by codenameone.
the class SwipeBackSupport method bind.
/**
* Binds support for swiping to the given forms
*
* @param currentForm the current form
* @param destination the destination form which can be created lazily
*/
protected void bind(final Form currentForm, final LazyValue<Form> destination) {
pointerDragged = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (sideSwipePotential) {
final int x = evt.getX();
final int y = evt.getY();
if (Math.abs(y - initialDragY) > x - initialDragX) {
sideSwipePotential = false;
return;
}
evt.consume();
if (dragActivated) {
currentX = x;
Display.getInstance().getCurrent().repaint();
} else {
if (x - initialDragX > Display.getInstance().convertToPixels(currentForm.getUIManager().getThemeConstant("backGestureThresholdInt", 5), true)) {
dragActivated = true;
destinationForm = destination.get();
startBackTransition(currentForm, destinationForm);
}
}
}
}
};
pointerReleased = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (dragActivated) {
int destNumberX = Display.getInstance().getDisplayWidth();
int incrementsX = Display.getInstance().convertToPixels(3, true);
if (currentX < destNumberX / 2) {
destinationForm = currentForm;
destNumberX = 0;
incrementsX *= -1;
}
final int destNumber = destNumberX;
final int increments = incrementsX;
Display.getInstance().getCurrent().registerAnimated(new Animation() {
public boolean animate() {
currentX += increments;
if (currentX > 0 && currentX >= destNumber || currentX < 0 && currentX <= destNumber) {
currentX = destNumber;
Transition t = destinationForm.getTransitionInAnimator();
destinationForm.setTransitionInAnimator(CommonTransitions.createEmpty());
destinationForm.show();
destinationForm.setTransitionInAnimator(t);
destinationForm = null;
dragActivated = false;
return false;
}
return true;
}
public void paint(Graphics g) {
}
});
}
}
};
pointerPressed = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
sideSwipePotential = false;
int displayWidth = Display.getInstance().getDisplayWidth();
sideSwipePotential = !transitionRunning && evt.getX() < displayWidth / currentForm.getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
initialDragX = evt.getX();
initialDragY = evt.getY();
/*if (sideSwipePotential) {
Component c = Display.getInstance().getCurrent().getComponentAt(initialDragX, initialDragY);
if (c != null && c.shouldBlockSideSwipe()) {
sideSwipePotential = false;
}
}*/
}
};
currentForm.addPointerDraggedListener(pointerDragged);
currentForm.addPointerReleasedListener(pointerReleased);
currentForm.addPointerPressedListener(pointerPressed);
}
Aggregations