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;
}
}
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();
}
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();
}
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();
}
}
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);
}
}
Aggregations