Search in sources :

Example 1 with CN.getCurrentForm

use of com.codename1.ui.CN.getCurrentForm in project CodeRAD by shannah.

the class FormController method tryCloneAndReplaceCurrentForm.

/**
 * Tries to {@link #cloneAndReplace(FormController)} the current FormController
 * @return True if it succeeds.  False if it fails.  It will fail either the current form doesn't have a form controller,
 * or there is no current form.
 */
public static boolean tryCloneAndReplaceCurrentForm() {
    Form currentForm = CN.getCurrentForm();
    if (currentForm == null) {
        return false;
    }
    ViewController bc = ViewController.getViewController(currentForm);
    if (bc == null)
        return false;
    FormController fc = bc.getFormController();
    if (fc == null)
        return false;
    try {
        cloneAndReplace(fc);
        return true;
    } catch (Exception ex) {
        return false;
    }
}
Also used : Form(com.codename1.ui.Form)

Example 2 with CN.getCurrentForm

use of com.codename1.ui.CN.getCurrentForm in project CodeRAD by shannah.

the class ApplicationController method getCurrentFormController.

public FormController getCurrentFormController() {
    Form f = CN.getCurrentForm();
    if (f == null) {
        return null;
    }
    ViewController vc = ViewController.getViewController(f);
    if (vc == null) {
        return null;
    }
    return vc.getFormController();
}
Also used : CN.getCurrentForm(com.codename1.ui.CN.getCurrentForm)

Example 3 with CN.getCurrentForm

use of com.codename1.ui.CN.getCurrentForm in project CodenameOne by codenameone.

the class GoogleLoginSample method showContactsForm.

public void showContactsForm(UserData data) {
    Form f = new Form("Contact Info");
    f.setToolbar(new Toolbar());
    f.getToolbar().setTitle("Contact Info");
    Form prev = CN.getCurrentForm();
    if (prev != null) {
        f.getToolbar().setBackCommand(new Command("Back") {

            public void actionPerformed(ActionEvent evt) {
                prev.show();
            }
        });
    }
    f.add(new Label("You are logged in as " + fullName));
    Button logout = new Button("Log out");
    logout.addActionListener(e -> {
        GoogleConnect.getInstance().doLogout();
        Preferences.set(tokenPrefix + "tokenExpires", -1);
        Preferences.set(tokenPrefix + "token", (String) null);
        showLoginForm();
    });
    f.add(logout);
    f.show();
}
Also used : Form(com.codename1.ui.Form) Command(com.codename1.ui.Command) Button(com.codename1.ui.Button) ActionEvent(com.codename1.ui.events.ActionEvent) Label(com.codename1.ui.Label) Toolbar(com.codename1.ui.Toolbar)

Example 4 with CN.getCurrentForm

use of com.codename1.ui.CN.getCurrentForm in project CodenameOne by codenameone.

the class JavaSEPort method deinitializeSync.

public void deinitializeSync() {
    final Thread[] t = new Thread[1];
    final boolean[] finished = new boolean[1];
    Display.getInstance().callSeriallyAndWait(new Runnable() {

        @Override
        public void run() {
            try {
                t[0] = Thread.currentThread();
                Form currForm = CN.getCurrentForm();
                if (currForm != null) {
                    // Change to a dummy form to allow the current form to run its shutdown hooks.
                    Form dummy = new Form();
                    dummy.setTransitionInAnimator(null);
                    dummy.setTransitionOutAnimator(null);
                    currForm.setTransitionInAnimator(null);
                    currForm.setTransitionOutAnimator(null);
                    dummy.show();
                }
                ArrayList<Runnable> toDeinitialize = new ArrayList<Runnable>(deinitializeHooks);
                deinitializeHooks.clear();
                for (Runnable r : toDeinitialize) {
                    r.run();
                }
            } finally {
                finished[0] = true;
            }
        }
    }, 250);
    Display.deinitialize();
    if (netMonitor != null) {
        netMonitor.dispose();
        netMonitor = null;
    }
    NetworkManager.getInstance().shutdownSync();
    try {
        if (t[0] != null) {
            long maxWait = 5000L;
            long startTime = System.currentTimeMillis();
            while (!finished[0] && (System.currentTimeMillis() - maxWait < startTime)) {
                Thread.sleep(100);
            }
        // t[0].join();
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}
Also used : Form(com.codename1.ui.Form)

Example 5 with CN.getCurrentForm

use of com.codename1.ui.CN.getCurrentForm in project CodenameOne by codenameone.

the class IOSImplementation method updateNativeTextEditorFrame.

private static void updateNativeTextEditorFrame(boolean requestFocus) {
    if (instance.currentEditing != null) {
        TextArea cmp = instance.currentEditing;
        Form form = cmp.getComponentForm();
        if (form == null || form != CN.getCurrentForm()) {
            instance.stopTextEditing();
            return;
        }
        int x = cmp.getAbsoluteX() + cmp.getScrollX();
        int y = cmp.getAbsoluteY() + cmp.getScrollY();
        int w = cmp.getWidth();
        int h = cmp.getHeight();
        String key = LAST_UPDATED_EDITOR_BOUNDS_KEY;
        Rectangle lastUpdatedBounds = (Rectangle) cmp.getClientProperty(key);
        if (lastUpdatedBounds != null) {
            if (lastUpdatedBounds.getX() == x && lastUpdatedBounds.getY() == y && lastUpdatedBounds.getWidth() == w && lastUpdatedBounds.getHeight() == h) {
                return;
            }
            lastUpdatedBounds.setBounds(x, y, w, h);
        } else {
            lastUpdatedBounds = new Rectangle(x, y, w, h);
            cmp.putClientProperty(key, lastUpdatedBounds);
        }
        final Style stl = cmp.getStyle();
        final boolean rtl = UIManager.getInstance().getLookAndFeel().isRTL();
        if (requestFocus) {
            instance.doNotHideTextEditorSemaphore++;
            try {
                instance.currentEditing.requestFocus();
            } finally {
                instance.doNotHideTextEditorSemaphore--;
            }
        }
        x = cmp.getAbsoluteX() + cmp.getScrollX();
        y = cmp.getAbsoluteY() + cmp.getScrollY();
        w = cmp.getWidth();
        h = cmp.getHeight();
        int pt = stl.getPaddingTop();
        int pb = stl.getPaddingBottom();
        int pl = stl.getPaddingLeft(rtl);
        int pr = stl.getPaddingRight(rtl);
        /*
            if(cmp.isSingleLineTextArea()) {
                switch(cmp.getVerticalAlignment()) {
                    case TextArea.CENTER:
                        if(h > cmp.getPreferredH()) {
                            y += (h / 2 - cmp.getPreferredH() / 2);
                        }
                        break;
                    case TextArea.BOTTOM:
                        if(h > cmp.getPreferredH()) {
                            y += (h - cmp.getPreferredH());
                        }
                        break;
                }
            }
            */
        Container contentPane = form.getContentPane();
        if (!contentPane.contains(cmp)) {
            contentPane = form;
        }
        Style contentPaneStyle = contentPane.getStyle();
        int minY = contentPane.getAbsoluteY() + contentPane.getScrollY() + contentPaneStyle.getPaddingTop();
        int maxH = Display.getInstance().getDisplayHeight() - minY - nativeInstance.getVKBHeight();
        if (y < minY) {
            h -= (minY - y);
            y = minY;
        }
        if (h > maxH) {
            // For text areas, we don't want the keyboard to cover part of the
            // typing region.  So we will try to size the component to
            // to only go up to the top edge of the keyboard
            // that should allow the OS to enable scrolling properly.... at least
            // in theory.
            h = maxH;
        }
        if (h < 0) {
            // There isn't room for the editor at all.
            Log.p("No room for text editor.  h=" + h);
            instance.stopTextEditing();
            return;
        }
        if (x < 0 || y < 0 || w <= 0 || h <= 0) {
            instance.stopTextEditing();
            return;
        }
        nativeInstance.resizeNativeTextView(x, y, w, h, pt, pr, pb, pl);
    }
}
Also used : Container(com.codename1.ui.Container) TextArea(com.codename1.ui.TextArea) Form(com.codename1.ui.Form) Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style)

Aggregations

Form (com.codename1.ui.Form)10 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 Toolbar (com.codename1.ui.Toolbar)3 ActionEvent (com.codename1.ui.events.ActionEvent)3 AudioRecorderComponent (com.codename1.components.AudioRecorderComponent)2 FileSystemStorage (com.codename1.io.FileSystemStorage)2 MediaRecorderBuilder (com.codename1.media.MediaRecorderBuilder)2 Button (com.codename1.ui.Button)2 Label (com.codename1.ui.Label)2 ActionListener (com.codename1.ui.events.ActionListener)2 Rectangle (com.codename1.ui.geom.Rectangle)2 Style (com.codename1.ui.plaf.Style)2 SpanLabel (com.codename1.components.SpanLabel)1 File (com.codename1.io.File)1 com.codename1.ui (com.codename1.ui)1 CN.getCurrentForm (com.codename1.ui.CN.getCurrentForm)1 Command (com.codename1.ui.Command)1 ComponentClosure (com.codename1.ui.ComponentSelector.ComponentClosure)1 Container (com.codename1.ui.Container)1 Sheet (com.codename1.ui.Sheet)1