Search in sources :

Example 31 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class BubbleTransition method drawDialogCmp.

private void drawDialogCmp(Graphics g, Dialog dlg) {
    Painter p = dlg.getStyle().getBgPainter();
    dlg.getStyle().setBgPainter(null);
    g.setClip(0, 0, dlg.getWidth(), dlg.getHeight());
    g.translate(-getDialogParent(dlg).getX(), -getDialogParent(dlg).getY());
    getDialogParent(dlg).paintComponent(g, false);
    if (dlg.getCommandCount() > 0) {
        Component menuBar = dlg.getSoftButton(0).getParent();
        if (menuBar != null) {
            g.setClip(0, 0, dlg.getWidth(), dlg.getHeight());
            menuBar.paintComponent(g, false);
        }
    }
    dlg.getStyle().setBgPainter(p);
}
Also used : Painter(com.codename1.ui.Painter) Component(com.codename1.ui.Component)

Example 32 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class CommonTransitions method paintAlpha.

private void paintAlpha(Graphics graphics) {
    Component src = getSource();
    int w = src.getWidth();
    int h = src.getHeight();
    int position = this.position;
    if (position > 255) {
        position = 255;
    } else {
        if (position < 0) {
            position = 0;
        }
    }
    // for slow mutable images
    if (buffer == null) {
        Component dest = getDestination();
        Component srcCmp = src;
        Component destCmp = dest;
        int alpha = position;
        if (src instanceof Dialog && dest instanceof Form) {
            srcCmp = dest;
            destCmp = src;
            alpha = 255 - position;
        }
        paint(graphics, srcCmp, 0, 0);
        destCmp.setX(srcCmp.getX());
        destCmp.setY(srcCmp.getY());
        destCmp.setWidth(srcCmp.getWidth());
        destCmp.setHeight(srcCmp.getHeight());
        graphics.setAlpha(alpha);
        paint(graphics, destCmp, 0, 0);
        graphics.setAlpha(255);
        return;
    }
    // this will always be invoked on the EDT so there is no race condition risk
    if (rgbBuffer != null || secondaryBuffer != null) {
        if (secondaryBuffer != null) {
            Component dest = getDestination();
            int x = dest.getAbsoluteX();
            int y = dest.getAbsoluteY();
            graphics.drawImage(buffer, x, y);
            graphics.setAlpha(position);
            graphics.drawImage(secondaryBuffer, x, y);
            graphics.setAlpha(0xff);
        } else {
            int alpha = position << 24;
            int[] bufferArray = rgbBuffer.getRGB();
            int size = bufferArray.length;
            for (int iter = 0; iter < size; iter++) {
                bufferArray[iter] = ((bufferArray[iter] & 0xFFFFFF) | alpha);
            }
            Component dest = getDestination();
            int x = dest.getAbsoluteX();
            int y = dest.getAbsoluteY();
            graphics.drawImage(buffer, x, y);
            graphics.drawImage(rgbBuffer, x, y);
        }
    }
}
Also used : Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) Component(com.codename1.ui.Component)

Example 33 with Dialog

use of com.codename1.ui.Dialog 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();
    }
}
Also used : Graphics(com.codename1.ui.Graphics) Container(com.codename1.ui.Container) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component) RGBImage(com.codename1.ui.RGBImage) Display(com.codename1.ui.Display)

Example 34 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class CommonTransitions method paintSlideAtPosition.

private void paintSlideAtPosition(Graphics g, int slideX, int slideY) {
    Component source = getSource();
    // if this is the first form we can't do a slide transition since we have no source form
    if (source == null) {
        return;
    }
    Component dest = getDestination();
    int w = source.getWidth();
    int h = source.getHeight();
    if (slideType == SLIDE_HORIZONTAL) {
        h = 0;
    } else {
        w = 0;
    }
    boolean dir = forward;
    if (dest != null && dest.getUIManager().getLookAndFeel().isRTL() && slideType == SLIDE_HORIZONTAL) {
        dir = !dir;
    }
    if (dir) {
        w = -w;
        h = -h;
    } else {
        slideX = -slideX;
        slideY = -slideY;
    }
    g.setClip(source.getAbsoluteX() + source.getScrollX(), source.getAbsoluteY() + source.getScrollY(), source.getWidth(), source.getHeight());
    // dialog animation is slightly different...
    if (source instanceof Dialog) {
        if (buffer != null) {
            g.drawImage(buffer, 0, 0);
        } else {
            paint(g, dest, 0, 0);
        }
        paint(g, source, -slideX, -slideY);
        return;
    }
    if (dest instanceof Dialog) {
        if (buffer != null) {
            g.drawImage(buffer, 0, 0);
        } else {
            paint(g, source, 0, 0);
        }
        paint(g, dest, -slideX - w, -slideY - h);
        return;
    }
    if (source.getParent() != null || buffer == null) {
        source.paintBackgrounds(g);
        paint(g, source, slideX, slideY);
    } else {
        g.drawImage(buffer, slideX, slideY);
    }
    paint(g, dest, slideX + w, slideY + h);
}
Also used : Dialog(com.codename1.ui.Dialog) Component(com.codename1.ui.Component)

Example 35 with Dialog

use of com.codename1.ui.Dialog in project CodenameOne by codenameone.

the class HTMLInputFormat method applyConstraints.

/**
 * Applies the constrains represented by this object to the given TextArea.
 * After invoking this method the returned TextArea should be used as restrictions are made sometimes on a new object.
 * In case this is a TextField, this method will also set the input modes as needed.
 *
 * @param ta The TextArea to apply the constraints on.
 * @return An instance of TextArea (Either the given one or a new one) with the constraints.
 */
TextArea applyConstraints(TextArea ta) {
    int widestConstraint = 0;
    for (Enumeration e = formatConstraints.elements(); e.hasMoreElements(); ) {
        FormatConstraint constraint = (FormatConstraint) e.nextElement();
        for (int i = 1; i <= 16; i *= 2) {
            if ((constraint.type & i) != 0) {
                widestConstraint |= i;
            }
        }
    }
    if (maxLength != Integer.MAX_VALUE) {
        ta.setMaxSize(maxLength);
    }
    if (widestConstraint == FormatConstraint.TYPE_NUMERIC) {
        ta.setConstraint(ta.getConstraint() | TextArea.NUMERIC);
    }
    if (ta instanceof TextField) {
        TextField tf = (TextField) ta;
        if (((widestConstraint & FormatConstraint.TYPE_SYMBOL) == 0) && ((widestConstraint & FormatConstraint.TYPE_ANY) == 0)) {
            // No symbols allowed
            tf = new TextField(ta.getText()) {

                protected void showSymbolDialog() {
                // Block symbols dialog
                }
            };
            tf.setConstraint(ta.getConstraint());
            ta = tf;
        }
        if ((widestConstraint & FormatConstraint.TYPE_ANY) != 0) {
            if ((widestConstraint & FormatConstraint.TYPE_UPPERCASE) != 0) {
                tf.setInputMode("ABC");
            } else {
                tf.setInputMode("abc");
            }
        } else {
            if ((widestConstraint & FormatConstraint.TYPE_LOWERCASE) == 0) {
                excludeInputMode(tf, "abc");
                excludeInputMode(tf, "Abc");
            }
            if ((widestConstraint & FormatConstraint.TYPE_UPPERCASE) == 0) {
                excludeInputMode(tf, "ABC");
                excludeInputMode(tf, "Abc");
            }
            if ((widestConstraint & FormatConstraint.TYPE_NUMERIC) == 0) {
                excludeInputMode(tf, "123");
            }
        }
    }
    return ta;
}
Also used : Enumeration(java.util.Enumeration) TextField(com.codename1.ui.TextField)

Aggregations

Dialog (com.codename1.ui.Dialog)28 Form (com.codename1.ui.Form)23 BorderLayout (com.codename1.ui.layouts.BorderLayout)17 Component (com.codename1.ui.Component)16 ActionEvent (com.codename1.ui.events.ActionEvent)14 Container (com.codename1.ui.Container)13 Style (com.codename1.ui.plaf.Style)12 ActionListener (com.codename1.ui.events.ActionListener)10 GridLayout (com.codename1.ui.layouts.GridLayout)8 UIManager (com.codename1.ui.plaf.UIManager)7 IOException (java.io.IOException)7 InfiniteProgress (com.codename1.components.InfiniteProgress)6 Command (com.codename1.ui.Command)6 Label (com.codename1.ui.Label)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 ConnectionRequest (com.codename1.io.ConnectionRequest)4 Button (com.codename1.ui.Button)4 CheckBox (com.codename1.ui.CheckBox)4 Painter (com.codename1.ui.Painter)4 TextArea (com.codename1.ui.TextArea)4