Java Code Examples for com.codename1.ui.Form#getFocused()

The following examples show how to use com.codename1.ui.Form#getFocused() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidKeyboard.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void showKeyboard(boolean show) {
//        manager.restartInput(myView);
//        if (keyboardShowing != show) {
//            manager.toggleSoftInputFromWindow(myView.getWindowToken(), 0, 0);
//            this.keyboardShowing = show;
//        }
        System.out.println("showKeyboard " + show);
        Form current = Display.getInstance().getCurrent();
        if(current != null){
            Component cmp = current.getFocused();
            if(cmp != null && cmp instanceof TextArea){
                TextArea txt = (TextArea)cmp;
                if(show){
                    Display.getInstance().editString(txt, txt.getMaxSize(), txt.getConstraint(), txt.getText(), 0);
                }
            }
        }else{
            InPlaceEditView.endEdit();
        }
//        if(!show){
//            impl.saveTextEditingState();
//        }
    }
 
Example 2
Source File: IOSVirtualKeyboard.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void showKeyboard(boolean show) {
    if (show) {
        if (isVirtualKeyboardShowing()) {
            return;
        }
        Form f = CN.getCurrentForm();
        if (f != null) {
            Component focused = f.getFocused();
            if (focused != null && focused.isEditable() && focused.isEnabled() && focused.isVisible() && !focused.isEditing()) {
                focused.startEditingAsync();
            }
        }
    } else {
        if (!isVirtualKeyboardShowing()) {
            return;
        }
        impl.stopTextEditing();
    }
}
 
Example 3
Source File: UIBuilder.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the state of the current form which we are about to leave as part
 * of the navigation logic. When a back command will return to this form the
 * state would be restored using setFormState.
 * The default implementation of this method restores focus and list selection.
 * You can add arbitrary keys to the form state, keys starting with a $ sign
 * are reserved for the UIBuilder base class use.
 *
 * @param f the form whose state should be preserved
 * @return arbitrary state object
 */
protected Hashtable getFormState(Form f) {
    Component c = f.getFocused();
    Hashtable h = new Hashtable();
    // can happen if we navigate away from a form that was shown without the GUI builder
    if(f.getName() != null) {
        h.put(FORM_STATE_KEY_NAME, f.getName());
    }
    if(c != null) {
        if(c instanceof List) {
            h.put(FORM_STATE_KEY_SELECTION, new Integer(((List)c).getSelectedIndex()));
        }
        if(c.getName() != null) {
            h.put(FORM_STATE_KEY_FOCUS, c.getName());
        }
        if(f.getTitle() != null) {
            h.put(FORM_STATE_KEY_TITLE, f.getTitle());
        }
    }
    storeComponentState(f, h);
    return h;
}
 
Example 4
Source File: UIBuilder.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method is the container navigation equivalent of getFormState() see
 * that method for details.
 * @param cnt the container
 * @return the state
 */
protected Hashtable getContainerState(Container cnt) {
    Component c = null;
    Form parentForm = cnt.getComponentForm();
    if(parentForm != null) {
        c = parentForm.getFocused();
    }
    Hashtable h = new Hashtable();
    h.put(FORM_STATE_KEY_NAME, cnt.getName());
    h.put(FORM_STATE_KEY_CONTAINER, "");
    if(c != null && isParentOf(cnt, c)) {
        if(c instanceof List) {
            h.put(FORM_STATE_KEY_SELECTION, new Integer(((List)c).getSelectedIndex()));
        }
        if(c.getName() != null) {
            h.put(FORM_STATE_KEY_FOCUS, c.getName());
        }
        return h;
    }
    storeComponentState(cnt, h);
    return h;
}
 
Example 5
Source File: BlackBerryVirtualKeyboard.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void showKeyboard(boolean show) {
    // we need this since when opening the VKB the text field loses focus and tries to fold the keyboard for some reason
    if(blockFolding && !show) {
        return;
    }
    if(canvas.getVirtualKeyboard() == null){
        return;
    }
    if(show) { 
        if(isVirtualKeyboardShowing()){
            return;
        }
        canvas.getVirtualKeyboard().setVisibility(VirtualKeyboard.SHOW);
        
        Form current = canvas.getImplementation().getCurrentForm();
        Component focus = current.getFocused();
        if(focus != null && focus instanceof TextArea){
            TextArea txtCmp = (TextArea) focus;
            if((txtCmp.getConstraint() & TextArea.NON_PREDICTIVE) == 0){
                canvas.getImplementation().editString(txtCmp, txtCmp.getMaxSize(), txtCmp.getConstraint(), txtCmp.getText(), 0);
            }
        }            
    } else {
        canvas.getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE);
        canvas.getImplementation().finishEdit(true);
    }
}
 
Example 6
Source File: BlackBerryCanvas.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void paint(Graphics g) {
    int f = getFieldCount();
    if(f > 0) {
        g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);

        Form currentForm = Display.getInstance().getCurrent();
        for(int iter = 0 ; iter < f ; iter++) {
            Field fld = getField(iter);
            int pops = 0;
            if(currentForm != null) {
                PeerComponent p = findPeer(currentForm.getContentPane(), fld);
                if(p != null) {
                    pops = clipOnLWUITBounds(p, g);
                } else {
                    Component cmp = currentForm.getFocused();

                    // we are now editing an edit field
                    if(cmp != null && cmp instanceof TextArea && cmp.hasFocus() && fld instanceof EditField) {
                        pops = clipOnLWUITBounds(cmp, g);
                        int x = fld.getLeft();
                        int y = fld.getTop();
                        g.clear(x, y, Math.max(cmp.getWidth(), fld.getWidth()),
                                Math.max(cmp.getHeight(), fld.getHeight()));
                    }
                }
            }
            paintChild(g, fld);
            while(pops > 0) {
                g.popContext();
                pops--;
            }
        }
    } else {
        g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);
    }
    g.setColor(0);
    g.drawText(debug, 0, 0);
    painted = true;
}
 
Example 7
Source File: Table.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the selected row in the table
 *
 * @return the offset of the selected row in the table if a selection exists
 */
public int getSelectedRow() {
    Form f = getComponentForm();
    if(f != null) {
        Component c = f.getFocused();
        if(c != null) {
            return getCellRow(c);
        }
    }
    return -1;
}
 
Example 8
Source File: Table.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the selected column in the table
 *
 * @return the offset of the selected column in the table if a selection exists
 */
public int getSelectedColumn() {
    Form f = getComponentForm();
    if(f != null) {
        Component c = f.getFocused();
        if(c != null) {
            return getCellColumn(c);
        }
    }
    return -1;
}