Search in sources :

Example 11 with Display

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

the class JavaSEPort method registerPush.

@Override
public void registerPush(Hashtable meta, boolean noFallback) {
    Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
    String user = p.get("user", null);
    Display d = Display.getInstance();
    if (user == null) {
        JPanel pnl = new JPanel();
        JTextField tf = new JTextField(20);
        pnl.add(new JLabel("E-Mail For Push"));
        pnl.add(tf);
        JOptionPane.showMessageDialog(canvas, pnl, "Email For Push", JOptionPane.PLAIN_MESSAGE);
        user = tf.getText();
        p.put("user", user);
    }
    d.setProperty("built_by_user", user);
    String mainClass = System.getProperty("MainClass");
    if (mainClass != null) {
        mainClass = mainClass.substring(0, mainClass.lastIndexOf('.'));
        d.setProperty("package_name", mainClass);
    }
    super.registerPush(meta, noFallback);
    if (pushSimulation != null && pushSimulation.isVisible()) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                JOptionPane.showMessageDialog(window, "registerForPush invoked. Use the buttons in the push simulator to send the appropriate callback to your app", "Push Registration", JOptionPane.INFORMATION_MESSAGE);
            }
        });
    }
}
Also used : Preferences(java.util.prefs.Preferences) Display(com.codename1.ui.Display)

Example 12 with Display

use of com.codename1.ui.Display 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();
    }
}
Also used : CodenameOneThread(com.codename1.impl.CodenameOneThread)

Example 13 with Display

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

the class Display method setCurrent.

/**
 * Displays the given Form on the screen.
 *
 * @param newForm the Form to Display
 */
void setCurrent(final Form newForm, boolean reverse) {
    if (edt == null) {
        throw new IllegalStateException("Initialize must be invoked before setCurrent!");
    }
    Form current = impl.getCurrentForm();
    if (autoFoldVKBOnFormSwitch && !(newForm instanceof Dialog)) {
        setShowVirtualKeyboard(false);
    }
    if (current == newForm) {
        current.revalidate();
        current.repaint();
        current.onShowCompletedImpl();
        return;
    }
    if (impl.isEditingText()) {
        switch(showDuringEdit) {
            case SHOW_DURING_EDIT_ALLOW_DISCARD:
                break;
            case SHOW_DURING_EDIT_ALLOW_SAVE:
                impl.saveTextEditingState();
                break;
            case SHOW_DURING_EDIT_EXCEPTION:
                throw new IllegalStateException("Show during edit");
            case SHOW_DURING_EDIT_IGNORE:
                return;
            case SHOW_DURING_EDIT_SET_AS_NEXT:
                impl.setCurrentForm(newForm);
                return;
        }
    }
    if (!isEdt()) {
        callSerially(new RunnableWrapper(newForm, null, reverse));
        return;
    }
    if (current != null) {
        if (current.isInitialized()) {
            current.deinitializeImpl();
        } else {
            Form fg = getCurrentUpcoming();
            if (fg != current) {
                if (fg.isInitialized()) {
                    fg.deinitializeImpl();
                }
            }
        }
    }
    if (!newForm.isInitialized()) {
        newForm.initComponentImpl();
    }
    if (newForm.getWidth() != getDisplayWidth() || newForm.getHeight() != getDisplayHeight()) {
        newForm.setSize(new Dimension(getDisplayWidth(), getDisplayHeight()));
        newForm.setShouldCalcPreferredSize(true);
        newForm.layoutContainer();
    } else {
        // if shouldLayout is true
        newForm.layoutContainer();
    }
    boolean transitionExists = false;
    if (animationQueue != null && animationQueue.size() > 0) {
        Object o = animationQueue.get(animationQueue.size() - 1);
        if (o instanceof Transition) {
            current = (Form) ((Transition) o).getDestination();
            impl.setCurrentForm(current);
        }
    }
    if (current != null) {
        // to the correct parent!
        if (current instanceof Dialog && ((Dialog) current).isMenu()) {
            Transition t = current.getTransitionOutAnimator();
            if (t != null) {
                // go back to the parent form first
                if (((Dialog) current).getPreviousForm() != null) {
                    initTransition(t.copy(false), current, ((Dialog) current).getPreviousForm());
                }
            }
            current = ((Dialog) current).getPreviousForm();
            impl.setCurrentForm(current);
        }
        // prevent the transition from occurring from a form into itself
        if (newForm != current) {
            if ((current != null && current.getTransitionOutAnimator() != null) || newForm.getTransitionInAnimator() != null) {
                if (animationQueue == null) {
                    animationQueue = new ArrayList<Animation>();
                }
                // transitions which are a bit sensitive
                if (current != null && (!(newForm instanceof Dialog))) {
                    Transition t = current.getTransitionOutAnimator();
                    if (current != null && t != null) {
                        transitionExists = initTransition(t.copy(reverse), current, newForm);
                    }
                }
                if (current != null && !(current instanceof Dialog)) {
                    Transition t = newForm.getTransitionInAnimator();
                    if (t != null) {
                        transitionExists = initTransition(t.copy(reverse), current, newForm);
                    }
                }
            }
        }
    }
    synchronized (lock) {
        lock.notify();
    }
    if (!transitionExists) {
        if (animationQueue == null || animationQueue.size() == 0) {
            setCurrentForm(newForm);
        } else {
            // we need to add an empty transition to "serialize" this
            // screen change...
            Transition t = CommonTransitions.createEmpty();
            initTransition(t, current, newForm);
        }
    }
}
Also used : Transition(com.codename1.ui.animations.Transition) Animation(com.codename1.ui.animations.Animation) Dimension(com.codename1.ui.geom.Dimension)

Example 14 with Display

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

the class Form method showModal.

/**
 * 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
 * @param includeTitle whether the title should hang in the top of the screen or
 * be glued onto the content pane
 * @param modal indictes if this is a modal or modeless dialog true for modal dialogs
 */
void showModal(int top, int bottom, int left, int right, boolean includeTitle, boolean modal, boolean reverse) {
    Display.getInstance().flushEdt();
    if (previousForm == null) {
        previousForm = Display.getInstance().getCurrent();
        // special case for application opening with a dialog before any form is shown
        if (previousForm == null) {
            previousForm = new Form();
            previousForm.show();
        } else {
            if (previousForm instanceof Dialog) {
                Dialog previousDialog = (Dialog) previousForm;
                if (previousDialog.isDisposed()) {
                    previousForm = Display.getInstance().getCurrentUpcoming();
                }
            }
        }
    }
    previousForm.tint = true;
    Painter p = getStyle().getBgPainter();
    if (top > 0 || bottom > 0 || left > 0 || right > 0) {
        if (!title.isVisible()) {
            includeTitle = false;
        }
        Style titleStyle = title.getStyle();
        titleStyle.removeListeners();
        Style contentStyle = contentPane.getUnselectedStyle();
        contentStyle.removeListeners();
        if (includeTitle) {
            titleStyle.setMargin(Component.TOP, top, false);
            titleStyle.setMargin(Component.BOTTOM, 0, false);
            titleStyle.setMargin(Component.LEFT, left, false);
            titleStyle.setMargin(Component.RIGHT, right, false);
            contentStyle.setMargin(Component.TOP, 0, false);
            contentStyle.setMargin(Component.BOTTOM, bottom, false);
            contentStyle.setMargin(Component.LEFT, left, false);
            contentStyle.setMargin(Component.RIGHT, right, false);
        } else {
            titleStyle.setMargin(Component.TOP, 0, false);
            titleStyle.setMargin(Component.BOTTOM, 0, false);
            titleStyle.setMargin(Component.LEFT, 0, false);
            titleStyle.setMargin(Component.RIGHT, 0, false);
            contentStyle.setMargin(Component.TOP, top, false);
            contentStyle.setMargin(Component.BOTTOM, bottom, false);
            contentStyle.setMargin(Component.LEFT, left, false);
            contentStyle.setMargin(Component.RIGHT, right, false);
        }
        titleStyle.setMarginUnit(null);
        contentStyle.setMarginUnit(null);
        initDialogBgPainter(p, previousForm);
        revalidate();
    }
    initFocused();
    if (getTransitionOutAnimator() == null && getTransitionInAnimator() == null) {
        initLaf(getUIManager());
    }
    initComponentImpl();
    Display.getInstance().setCurrent(this, reverse);
    onShow();
    if (modal) {
        // called to display a dialog and wait for modality
        Display.getInstance().invokeAndBlock(new RunnableWrapper(this, p, reverse));
        // if the virtual keyboard was opend by the dialog close it
        Display.getInstance().setShowVirtualKeyboard(false);
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 15 with Display

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

the class Button method fireActionEvent.

/**
 * Allows subclasses to override action event behavior
 * {@inheritDoc}
 *
 * @param x the x position of the click if applicable (can be 0 or -1 otherwise)
 * @param y the y position of the click if applicable (can be 0 or -1 otherwise)
 */
protected void fireActionEvent(int x, int y) {
    super.fireActionEvent();
    if (cmd != null) {
        ActionEvent ev = new ActionEvent(cmd, this, x, y);
        dispatcher.fireActionEvent(ev);
        if (!ev.isConsumed()) {
            Form f = getComponentForm();
            if (f != null) {
                f.actionCommandImplNoRecurseComponent(cmd, ev);
            }
        }
    } else {
        dispatcher.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed, x, y));
    }
    Display d = Display.getInstance();
    if (d.isBuiltinSoundsEnabled()) {
        d.playBuiltinSound(Display.SOUND_TYPE_BUTTON_PRESS);
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Aggregations

Display (com.codename1.ui.Display)10 Component (com.codename1.ui.Component)7 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 Container (com.codename1.ui.Container)4 Dialog (com.codename1.ui.Dialog)4 Form (com.codename1.ui.Form)4 IOException (java.io.IOException)4 RGBImage (com.codename1.ui.RGBImage)3 InputStream (java.io.InputStream)3 ParseException (java.text.ParseException)3 Hashtable (java.util.Hashtable)3 Cursor (android.database.Cursor)2 Paint (android.graphics.Paint)2 Paint (com.codename1.charts.compat.Paint)2 Point (com.codename1.charts.models.Point)2 SpanButton (com.codename1.components.SpanButton)2 Address (com.codename1.contacts.Address)2 Contact (com.codename1.contacts.Contact)2 Button (com.codename1.ui.Button)2 Font (com.codename1.ui.Font)2