Java Code Examples for com.codename1.components.SpanLabel#setText()

The following examples show how to use com.codename1.components.SpanLabel#setText() . 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: StateMachine.java    From parse4cn1 with Apache License 2.0 6 votes vote down vote up
@Override
protected void beforeMain(Form f) {
    if (Parse.getPlatform() != Parse.EPlatform.WINDOWS_PHONE) {
        findContainer4(f).removeComponent(findRetryInstallation(f));
    }
    
    final SpanLabel pushNotes = findSpanLabelPushNotes(f);
    pushNotes.setText("Note:"
            + "\n- Messages will be delivered to ALL subscribers of the \"test\" channel (which includes this device)."
            + "\n- (Part of) the installation ID of the sender will automatically be included in the push message so that you can distinguish your messages :)"
            + "\n- The Parse backend for this app is a free Parse App so free quota limits apply. Use sparingly or the limit might be hit and your messages will fail."
            + "\n- To aid debugging, you can use the 'Show app logging' in the 'Demo' tab (though it may fail on some platforms e.g. simulator due to dependency on the filesystem API).");
    handleForegroundPush = findCheckBoxHandleForegroundPush(f).isSelected();
    handleBackgroundPush = findCheckBoxHandleBackgroundPush(f).isSelected();
    
        
    // A trick copied from the Kitchen Sink demo which is particularly
    // useful on Windows phone where the title is shown in small font by default
    // It's sufficient to do this only on the first form as it changes the theme
    // which in turn propagates to the other forms
    setTitleFont(f);
}
 
Example 2
Source File: StateMachine.java    From parse4cn1 with Apache License 2.0 5 votes vote down vote up
private void initPushButton(final Form f, boolean enable, final String statusMsg) {
    final Button pushButton = findButtonSendPush(f);
    pushButton.setEnabled(enable);
    
    final SpanLabel pushStatus = findSpanLabelPushStatus(f);
    pushStatus.setText(statusMsg);
    pushStatus.setTextUIID(enable ? "Label" : "WarningLabel");
}
 
Example 3
Source File: LoadingTextAnimationSample.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void showForm() {
    Form f = new Form("Hello", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE));
    Form prev = CN.getCurrentForm();
    Toolbar tb = new Toolbar();
    f.setToolbar(tb);
    tb.addCommandToLeftBar("Back", null, evt->{
        prev.showBack();
    });
    SpanLabel profileText = new SpanLabel();
    
    profileText.setText("placeholder");
    f.add(BorderLayout.CENTER, profileText);
    // Replace the label by a CircleProgress to indicate that it is loading.
    LoadingTextAnimation.markComponentLoading(profileText);
    Button next = new Button("Next");
    next.addActionListener(e->{
        showLabelTest();
    });
    f.add(BorderLayout.SOUTH, next);
    AsyncResource<MyData> request = fetchDataAsync();
    request.ready(data -> {
        profileText.setText(data.getProfileText());

        // Replace the progress with the nameLabel now that
        // it is ready, using a fade transition
        LoadingTextAnimation.markComponentReady(profileText, CommonTransitions.createFade(300));
    });
    
    f.show();

}
 
Example 4
Source File: StateMachine.java    From parse4cn1 with Apache License 2.0 4 votes vote down vote up
private void getInstallationId(Form f) {
    
    SpanLabel installationLabel = findLabelInstallation(f);
    
    if (installationLabel != null) {
        boolean failed = true;
        String installationIdText = null;
  
        try {
            ParseInstallation installation = ParseInstallation.getCurrentInstallation();

            if (installation != null) {
                installationIdText = installation.getInstallationId();
                installation.subscribeToChannel("test");
                failed = false;
            } else {
                installationIdText = "Could not retrieve current installation!";
            }
        } catch (ParseException ex) {
            if (installationIdText == null) {
                installationIdText = "Failed to retrieve installation. ";
            } else {
                installationIdText += "\nFailed to subscribe to test channel. ";
            }
            installationIdText += "Error: " + ex.getMessage();
            int code = ex.getCode();
            installationIdText += " Error code = " + code + ((code < 0) ? " (local)" : " (from Parse)");
        }

        installationLabel.setText(installationIdText + "\n"); // crude layouting :)
        if (failed) {
            installationLabel.setTextUIID("WarningLabel");
        } else {
            installationLabel.setTextUIID("Label");
            Button button = findRetryInstallation(f);
            if (button != null) {
                findContainer4(f).removeComponent(button);
                f.revalidate();
            }
        }
        
        initPushButton(f, !failed, 
                (failed ? "Sending push is disabled since installation id could not be retrieved" : ""));
    }
}
 
Example 5
Source File: TextSelectionSample.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.setScrollableY(false);
    TextSelection sel = hi.getTextSelection();
    sel.addTextSelectionListener(e->{
        //System.out.println("Text selection has changed");
    });
    
    sel.setEnabled(true);
    Label label = new Label("This label should be selectable");
    label.setTextSelectionEnabled(true);
    Label label2 = new Label("Some more text");
    label2.setTextSelectionEnabled(true);
    hi.add(label);
    hi.add(new TextField("Hello Universe"));
    hi.add(label2);
    hi.add(new Label("Hi World"));
    
    Container cnt = new Container(BoxLayout.x());
    cnt.setScrollableX(true);
    cnt.getStyle().setBorder(Border.createLineBorder(1, 0x0));
    cnt.setPreferredH(CN.convertToPixels(5));
    cnt.setPreferredW(CN.convertToPixels(20));
    
    TextArea ta = new TextArea();
    ta.setText("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.");
    ta.setEnabled(false);
    ta.setRows(6);
    hi.add(ta);
    
    SpanLabel sl = new SpanLabel();
    sl.setText(ta.getText());
    sl.setTextSelectionEnabled(true);
    hi.add(sl);
    
    
    TextField tf = new TextField();
    tf.setText("Hello World.  This is a test field");
    tf.setEnabled(false);
    hi.add(tf);
    
    Label l = new Label("This is a test with some long text to see if this works.  It should just flow when it runs out of space");
    l.setTextSelectionEnabled(true);
    cnt.add(l);
    
    Container cntY = new Container(BoxLayout.y());
    cntY.setScrollableY(true);
    cntY.getStyle().setBorder(Border.createLineBorder(1, 0x0));
    for (int i=0; i<50; i++) {
        Label li = new Label("List item "+i);
        li.setTextSelectionEnabled(true);
        cntY.add(li);
    }
    hi.add(cnt);
    hi.add(cntY);
    
    $(cnt, cntY).selectAllStyles().setMarginMillimeters(4);
    
    
    hi.show();
}