com.codename1.components.SpanLabel Java Examples

The following examples show how to use com.codename1.components.SpanLabel. 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: LinearGradientSample.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", new BorderLayout());
    Picker picker = new Picker();
    picker.setStrings("No cycle", "Repeat", "Reflect");
    picker.addActionListener(e->{
        if ("No cycle".equals(picker.getValue())) {
            cycleMethod = NO_CYCLE;
        } else if ("Repeat".equals(picker.getValue())) {
            cycleMethod = REPEAT;
        } else if ("Reflect".equals(picker.getValue())) {
            cycleMethod = REFLECT;
        }
        hi.repaint();
    });
    hi.add(BorderLayout.NORTH, BoxLayout.encloseY(new SpanLabel("Drag pointer below to generate gradients"), new Label("Gradient Cycle Type:"), picker));
    hi.add(BorderLayout.CENTER, new MyComponent());
    hi.show();
}
 
Example #3
Source File: NestedFormWithSwipeableTabsTest2776.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form outer = new Form("", new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE));
    outer.getToolbar().hideToolbar();
    Form inner = new Form("Tabs", new BorderLayout());
    Container layeredPane1 = inner.getLayeredPane(NestedFormWithSwipeableTabsTest2776.class, 1);
    layeredPane1.setLayout(new BorderLayout());
    Container layeredPane2 = inner.getLayeredPane(AnotherClass.class, 2);
    layeredPane2.setLayout(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));

    Tabs tab = new Tabs();
    tab.addTab("Tab1", new SpanLabel("Tab 1"));
    tab.addTab("Tab2", new SpanLabel("Tab 2"));

    inner.add(BorderLayout.CENTER, tab);
    outer.add(BorderLayout.CENTER, inner);
    outer.revalidate();
    outer.show();
}
 
Example #4
Source File: DrSbaitso.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
void say(Container destination, String text, boolean question) {
    SpanLabel t = new SpanLabel(text);
    t.setWidth(destination.getWidth());
    t.setX(0);
    t.setHeight(t.getPreferredH());
    
    if(question) {
        t.setY(Display.getInstance().getDisplayHeight());
        t.setTextUIID("BubbleUser");
        t.setIconPosition(BorderLayout.EAST);
        t.setIcon(userPicture);
        t.setTextBlockAlign(Component.RIGHT);
    } else {
        t.setY(0);
        t.setTextUIID("BubbleSbaitso");
        t.setTextBlockAlign(Component.LEFT);
    }
    destination.addComponent(t);
    destination.animateLayoutAndWait(400);
    destination.scrollComponentToVisible(t);
}
 
Example #5
Source File: UnicodeFontsSample.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    Label l = new Label("重新开始重新开始");
    l.getStyle().setFont(Font.createTrueTypeFont(Font.NATIVE_MAIN_REGULAR, 5f));
    hi.add(l);
    
    String emoji = "Here is an 重新开始重新开始 alien: \uD83D\uDC7D! ";
    String s = "";
    for(int i = 0 ; i < 30 ; i++) {
        s += emoji;
    }
    SpanLabel sl = new SpanLabel(s);
    sl.getTextAllStyles().setFont(Font.createTrueTypeFont(Font.NATIVE_MAIN_REGULAR, 3f));
    hi.add(sl);
    hi.show();
}
 
Example #6
Source File: ArrayTests2768.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    Button b = new Button("Run Test");
    SpanLabel result = new SpanLabel();
    b.addActionListener(e->{
        try {
            if (new MyTest().runTest()) {
                result.setText("Success");
            } else {
                result.setText("Failed");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            result.setText("Failed: "+ex.getMessage());
        }
        hi.revalidateWithAnimationSafety();
    });
    hi.addAll(b, result);
    hi.show();
}
 
Example #7
Source File: SpanLabelTest2897.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Welcome");
    Container container = new Container(BoxLayout.y());
    SpanLabel label = new SpanLabel("Span label only shows one row. We need to update the columns for rendering, otherwise it will still wrap at the old number of columns.");
    container.add(label);
    
    
    SpanLabel label1 = new SpanLabel("Set span label text component row count manually. We need to update the columns for rendering, otherwise it will still wrap at the old number of columns.");
    //label1.getTextComponent().setRows(4);
    container.add(label1);
    SpanButton btn = new SpanButton("Hello");
    container.add(btn);
     btn = new SpanButton("Set span button text component row count manually. We need to update the columns for rendering, otherwise it will still wrap at the old number of columns.");
    container.add(btn);
    hi.add(container);
    hi.show();
}
 
Example #8
Source File: SpanLabelLayeredLayoutPreferredSizeTest3000.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void testBorderLayout() {
    Button showPopUp = new Button("Show PopUp in Border Layout");
    Form f = new Form(BoxLayout.y());
    f.setName("testBorderLayout");
    f.add(showPopUp);

    showPopUp.addActionListener((e) -> {

        SpanLabel messageSpanLabel = new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos. Tap the following button to open the gallery. You should be able to select multiple images and videos.");
        messageSpanLabel.setName("messageSpanLabel");
        Container centerContainerOuter = new Container(new BorderLayout(CENTER_BEHAVIOR_CENTER));
        centerContainerOuter.add(CENTER, messageSpanLabel);

        Container layeredPane = getCurrentForm().getLayeredPane();
        layeredPane.setLayout(new LayeredLayout());        
        layeredPane.add(centerContainerOuter);
        layeredPane.setVisible(true);

        getCurrentForm().revalidate();     
    });
    showPopUp.setName("showBorderLayout");
    f.show();
    waitForFormName("testBorderLayout");
    clickButtonByName("showBorderLayout");
    SpanLabel spanLabel = (SpanLabel)findByName("messageSpanLabel");
    Label l = new Label("Tap the following");
    
    assertTrue(spanLabel.getHeight() > l.getPreferredH() * 2, "Span Label height is too small.  Should be at least a few lines.");
    
    
}
 
Example #9
Source File: CSSVariablesSample.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    Container cnt1 = new Container(BoxLayout.y(), "Cnt1");
    Container cnt2 = new Container(BoxLayout.y(), "Cnt2");
    cnt1.add(new SpanLabel("Pink Container using CSS variable"));
    cnt2.add(new SpanLabel("Green Container because CSS variable not defined"));
    hi.addAll(cnt1, cnt2);
    hi.show();
}
 
Example #10
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 #11
Source File: SpanLabelTest2980.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Layout lay = new FlowLayout();
    //Layout lay = BoxLayout.y();
    Form hi = new Form("Gallery Test", lay);
    hi.add(new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos."));
    
    Button btn = new Button("Run Test");
    SpanLabel files = new SpanLabel();
    SpanLabel result = new SpanLabel();
    btn.addActionListener(l -> {
        try {
            SpanLabelTests2980 test = new SpanLabelTests2980();
            test.runTest();
            result.setText("Test Passed");
        } catch (Throwable t) {
            result.setText("Failed: "+t.getMessage());
        }
        hi.revalidateWithAnimationSafety();
    });
    hi.addAll(btn, files, result);
    
    hi.show();
}
 
Example #12
Source File: InterFormContainerSample.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void start_old() {
    if (current != null) {
        current.show();
        return;
    }
    Form f1 = new Form("Form 1", new BorderLayout());
    f1.setTransitionOutAnimator(CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, true, 300));
    Form f2 = new Form("Form 2", new BorderLayout());
    f2.setTransitionOutAnimator(CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, true, 300));

    Form f3 = new Form("Form 3", new BorderLayout());
    Button f3Back = new Button("Back");
    f3Back.addActionListener(e -> {
        f2.showBack();
    });
    f3.add(BorderLayout.CENTER, new SpanLabel("This form doesn't have an interform container"));
    f3.add(BorderLayout.SOUTH, f3Back);
    f1.add(BorderLayout.CENTER, new Label("Hi World"));

    Button sharedButton = new Button("Shared Button");
    sharedButton.addActionListener(e -> {
        if (sharedButton.getComponentForm() == f1) {
            f2.show();
        } else {
            f1.showBack();
        }
    });
    InterFormContainer cnt = new InterFormContainer(sharedButton);
    f1.add(BorderLayout.SOUTH, cnt);

    Button goto3 = new Button("Goto Form 3");
    goto3.addActionListener(e -> {
        f3.show();
    });
    InterFormContainer cnt2 = new InterFormContainer(sharedButton);
    f2.add(BorderLayout.CENTER, BoxLayout.encloseY(new Label("Now on Form 2"), goto3));
    f2.add(BorderLayout.SOUTH, cnt2);

    f1.show();
}
 
Example #13
Source File: CompoundAnimationSample.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    
    Form hi = new Form("Toolbar", new BoxLayout(BoxLayout.Y_AXIS));
    EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
    URLImage background = URLImage.createToStorage(placeholder, "400px-AGameOfThrones.jpg",
            "http://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg");
    background.fetch();
    Style stitle = hi.getToolbar().getTitleComponent().getUnselectedStyle();
    stitle.setBgImage(background);
    stitle.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
    stitle.setPaddingUnit(Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS);
    stitle.setPaddingTop(15);
    SpanButton credit = new SpanButton("This excerpt is from A Wiki Of Ice And Fire. Please check it out by clicking here!");
    credit.addActionListener((e) -> Display.getInstance().execute("http://awoiaf.westeros.org/index.php/A_Game_of_Thrones"));
    hi.add(new SpanLabel("A Game of Thrones is the first of seven planned novels in A Song of Ice and Fire, an epic fantasy series by American author George R. R. Martin. It was first published on 6 August 1996. The novel was nominated for the 1998 Nebula Award and the 1997 World Fantasy Award,[1] and won the 1997 Locus Award.[2] The novella Blood of the Dragon, comprising the Daenerys Targaryen chapters from the novel, won the 1997 Hugo Award for Best Novella. ")).
            add(new Label("Plot introduction", "Heading")).
            add(new SpanLabel("A Game of Thrones is set in the Seven Kingdoms of Westeros, a land reminiscent of Medieval Europe. In Westeros the seasons last for years, sometimes decades, at a time.\n\n" +
                "Fifteen years prior to the novel, the Seven Kingdoms were torn apart by a civil war, known alternately as \"Robert's Rebellion\" and the \"War of the Usurper.\" Prince Rhaegar Targaryen kidnapped Lyanna Stark, arousing the ire of her family and of her betrothed, Lord Robert Baratheon (the war's titular rebel). The Mad King, Aerys II Targaryen, had Lyanna's father and eldest brother executed when they demanded her safe return. Her second brother, Eddard, joined his boyhood friend Robert Baratheon and Jon Arryn, with whom they had been fostered as children, in declaring war against the ruling Targaryen dynasty, securing the allegiances of House Tully and House Arryn through a network of dynastic marriages (Lord Eddard to Catelyn Tully and Lord Arryn to Lysa Tully). The powerful House Tyrell continued to support the King, but House Lannister and House Martell both stalled due to insults against their houses by the Targaryens. The civil war climaxed with the Battle of the Trident, when Prince Rhaegar was killed in battle by Robert Baratheon. The Lannisters finally agreed to support King Aerys, but then brutally... ")).
            add(credit);

    hi.getToolbar().setTitleCentered(false);
    ComponentAnimation title = 
    //        hi.getToolbar().getTitleComponent().createStyleAnimation("Title", 200);
    
        ComponentAnimation.compoundAnimation(
            hi.getToolbar().createStyleAnimation("Container", 200),
            hi.getToolbar().getTitleComponent().createStyleAnimation("Title", 200)
        );
    hi.getAnimationManager().onTitleScrollAnimation(title);
    hi.show();
}
 
Example #14
Source File: AutocompleteOverrideFilterSample.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void showForm() {
        Form hi = new Form("Auto Complete", new BoxLayout(BoxLayout.Y_AXIS));
  final DefaultListModel<String> options = new DefaultListModel<>();
  AutoCompleteTextField ac = new AutoCompleteTextField(options) {
      @Override
      protected boolean filter(String text) {
          if(text.length() == 0) {
              return false;
          }
          String[] l = searchLocations(text);
          if(l == null || l.length == 0) {
              return false;
          }
  
          options.removeAll();
          for(String s : l) {
              options.addItem(s);
          }
          return true;
      }
  
  };
  ac.setMinimumElementsShownInPopup(5);
  hi.add(ac);
  hi.add(new SpanLabel("This demo requires a valid google API key to be set below "
           + "you can get this key for the webservice (not the native key) by following the instructions here: "
           + "https://developers.google.com/places/web-service/get-api-key"));
  hi.add(apiKey);
  hi.getToolbar().addCommandToRightBar("Get Key", null, e -> Display.getInstance().execute("https://developers.google.com/places/web-service/get-api-key"));
  hi.show();
}
 
Example #15
Source File: SpanLabelTestAllStyles2891.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form f = new Form("Spanny", new LayeredLayout());
    SpanLabel body = new SpanLabel("Just a text!");
    body.getTextAllStyles().setAlignment(Component.CENTER);
    f.add(body);
    
    f.show();
}
 
Example #16
Source File: TabsAnimationSample2957.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Tabs", new BorderLayout());
    Tabs t = new Tabs();
    SpanLabel t1 = new SpanLabel("Blue");
    t1.getAllStyles().setBgColor(0xff);
    t1.getAllStyles().setBgTransparency(255);
    Container cont1 = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    cont1.add(t1);
    SpanLabel t2 = new SpanLabel("Green");
    t2.getAllStyles().setBgColor(0xff00);
    t2.getAllStyles().setBgTransparency(255);
    Container cont2 = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    cont2.add(t2);
    SpanLabel t3 = new SpanLabel("Red");
    t3.getAllStyles().setBgColor(0xff0000);
    t3.getAllStyles().setBgTransparency(255);
    Container cont3 = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    cont3.add(t3);
    t.addTab("Blue", cont1);
    t.addTab("Green", cont2);
    t.addTab("Red", cont3);

    UITimer.timer(500, true, hi, () -> {
        int idx = t.getSelectedIndex() + 1;
        if (idx >= t.getTabCount()) {
            idx = 0;
        }
        t.setSelectedIndex(idx, true);
    });

    hi.add(CENTER, t);
    hi.show();
}
 
Example #17
Source File: SpanLabelTests2980.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void testBorderLayout() {
    System.out.println("Testing SpanLabel preferred size in BorderLayout.  https://github.com/codenameone/CodenameOne/issues/3000");
    //Button showPopUp = new Button("Show PopUp in Border Layout");
    Form f = new Form(BoxLayout.y());
    f.setName("testBorderLayout");
    //f.add(showPopUp);
    SpanLabel messageSpanLabel = new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos. Tap the following button to open the gallery. You should be able to select multiple images and videos.");
    //showPopUp.addActionListener((e) -> {
    Runnable showPopup = () -> {
        
        messageSpanLabel.setName("messageSpanLabel");
        Container centerContainerOuter = new Container(new BorderLayout(CENTER_BEHAVIOR_CENTER));
        centerContainerOuter.add(CENTER, messageSpanLabel);

        Container layeredPane = getCurrentForm().getLayeredPane();
        layeredPane.setLayout(new LayeredLayout());        
        layeredPane.add(centerContainerOuter);
        layeredPane.setVisible(true);

        getCurrentForm().revalidate();     
    };
    //showPopUp.setName("showBorderLayout");
    f.show();
    waitForFormName("testBorderLayout");
    //clickButtonByName("showBorderLayout");
    showPopup.run();
    waitFor(500); // give time for click to take effect
    SpanLabel spanLabel = messageSpanLabel; //(SpanLabel)findByName("messageSpanLabel");
    Label l = new Label("Tap the following");

    assertTrue(spanLabel.getHeight() > l.getPreferredH() * 2, "Span Label height is too small.  Should be at least a few lines.");
    System.out.println("Finished SpanLabel BorderLayout test");

}
 
Example #18
Source File: ComponentSelector.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the text on the first component in this set that supports this property.  Currently this works with
 * Label, TextArea, SpanLabel, and SpanButtons, and subclasses thereof. 
 * @return 
 */
public String getText() {
    for (Component c : this) {
        if (c instanceof Label) {
            return ((Label)c).getText();
        } else if (c instanceof TextArea) {
            return ((TextArea)c).getText();
        } else if (c instanceof SpanLabel) {
            return ((SpanLabel)c).getText();
        } else if (c instanceof SpanButton) {
            return ((SpanButton)c).getText();
        }
    }
    return null;
}
 
Example #19
Source File: ComponentSelector.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the text on all components in found set that support this.  Currently this works with
 * Label, TextArea, SpanLabel, and SpanButtons, and subclasses thereof.
 * @param text The text to set in the componnet.
 * @return 
 */
public ComponentSelector setText(String text) {
    for (Component c : this) {
        if (c instanceof Label) {
            ((Label)c).setText(text);
        } else if (c instanceof TextArea) {
            ((TextArea)c).setText(text);
        } else if (c instanceof SpanLabel) {
            ((SpanLabel)c).setText(text);
        } else if (c instanceof SpanButton) {
            ((SpanButton)c).setText(text);
        }
    }
    return this;
}
 
Example #20
Source File: DrSbaitso.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
private DataChangedListener createSearchListener(final TextField searchField, final Container discussion, final Button ask) {
    return new DataChangedListener() {
        private boolean animateLock;
        public void dataChanged(int type, int index) {
            String t = searchField.getText();
            int count = discussion.getComponentCount();
            if(t.length() == 0) {
                ask.setEnabled(true);
                for(int iter = 0 ; iter < count ; iter++) {
                    Component c = discussion.getComponentAt(iter);
                    c.setPreferredSize(null);
                    c.setVisible(true);
                }
                animateChanage();
                return;
            }              
            t = t.toLowerCase();
            ask.setEnabled(false);
            for(int iter = 0 ; iter < count ; iter++) {
                SpanLabel tt = (SpanLabel)discussion.getComponentAt(iter);
                if(tt.getText().toLowerCase().indexOf(t) < 0) {
                    tt.setPreferredSize(new Dimension(1, 1));
                    tt.setVisible(false);
                } else {
                    tt.setPreferredSize(null);
                    tt.setVisible(true);
                }
            }
            animateChanage();
        }
        private void animateChanage() {
            if(!animateLock) {
                animateLock = true;
                discussion.animateLayoutAndWait(300);
                animateLock = false;
            }
        }
    };        
}
 
Example #21
Source File: ReactDemo.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
Component createMovieEntry(Result data) {
    Container entry = BorderLayout.center(
            BoxLayout.encloseY(
                    new SpanLabel(data.getAsString("title"), "Line1"), 
                    new Label(data.getAsString("year"), "Line2"))).
            add(BorderLayout.WEST, 
                    URLImage.createToStorage(placeholder, data.getAsString("id"), 
                                data.getAsString("posters/thumbnail")));
    return entry;
}
 
Example #22
Source File: SocialChat.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
private Component respondNoLayout(Container chatArea, String text, Image roundedHimOrHerImage) {
    SpanLabel answer = new SpanLabel(text);
    answer.setIcon(roundedHimOrHerImage);
    answer.setIconPosition(BorderLayout.EAST);
    answer.setTextUIID("BubbleThem");
    answer.setTextBlockAlign(Component.RIGHT);
    chatArea.addComponent(answer);        
    return answer;
}
 
Example #23
Source File: SocialChat.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
private Component sayNoLayout(Container chatArea, String text) {
    SpanLabel t = new SpanLabel(text);
    t.setIcon(roundedMeImage);
    t.setTextBlockAlign(Component.LEFT);
    t.setTextUIID("BubbleMe");
    chatArea.addComponent(t);
    return t;
}
 
Example #24
Source File: PropertyCross.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Shows the favorites screen 
 */
void showFavs() {
    final Form favsForm = new Form("Favourites");
    addBackToHome(favsForm);
    favsForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    if(favoritesList.size() == 0) {
        favsForm.addComponent(new SpanLabel("You have not added any properties to your favourites"));
    } else {
        // this is really trivial we just take the favorites and show them as a set of buttons
        for(Map<String, Object> c : favoritesList) {
            MultiButton mb = new MultiButton();
            final Map<String, Object> currentListing = c;
            String thumb_url = (String)currentListing.get("thumb_url");
            String guid = (String)currentListing.get("guid");
            String price_formatted = (String)currentListing.get("price_formatted");
            String summary = (String)currentListing.get("summary");
            mb.setIcon(URLImage.createToStorage(placeholder, guid, thumb_url, URLImage.RESIZE_SCALE_TO_FILL));
            mb.setTextLine1(price_formatted);
            mb.setTextLine2(summary);
            mb.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    showPropertyDetails(favsForm, currentListing);
                }
            });
            favsForm.addComponent(mb);
        }
    }
    favsForm.show();
}
 
Example #25
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 #26
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();
}
 
Example #27
Source File: SpanLabelTests2980.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean runTest() throws Exception {
    if (layout == null) {
        Layout[] layouts = new Layout[]{
            new FlowLayout(),
            BoxLayout.x(),
            BoxLayout.y()
        };
        for (Layout l : layouts) {
            layout = l;
            runTest();
        }
        return true;
    }
    System.out.println("Laying out SpanLabel with layout " + layout);
    Label label = new Label("Tap the following");

    Container cnt = new Container(layout) {
        @Override
        protected Dimension calcPreferredSize() {
            return new Dimension(label.getPreferredW(), CN.convertToPixels(1000));
        }

        @Override
        public int getWidth() {
            return label.getPreferredW();
        }

        @Override
        public int getHeight() {
            return CN.convertToPixels(1000);
        }

    };
    cnt.setScrollableX(false);
    cnt.setScrollableY(false);
    cnt.setWidth(label.getPreferredW());
    cnt.setHeight(CN.convertToPixels(1000));
    SpanLabel sl = new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos.");

    sl.setName("TheSpanLabel");
    cnt.add(sl);
    cnt.add(new Button("Click Me"));
    cnt.setShouldCalcPreferredSize(true);
    cnt.layoutContainer();
    assertTrue(sl.getHeight() > label.getPreferredH() * 2, "Span Label height is too low for layout " + layout + ": was " + sl.getHeight() + " but should be at least " + (label.getPreferredH() * 2));

    SpanButton sb = new SpanButton("Tap the following button to open the gallery. You should be able to select multiple images and videos.");

    sb.setName("TheSpanButton");
    cnt.removeAll();
    cnt.add(sb);
    cnt.add(new Button("Click Me"));
    cnt.setShouldCalcPreferredSize(true);
    cnt.layoutContainer();
    assertTrue(sb.getHeight() > label.getPreferredH() * 2, "Span button height is too low for layout " + layout + ": was " + sb.getHeight() + " but should be at least " + (label.getPreferredH() * 2));

    
    testBorderLayout();
    
    return true;
}
 
Example #28
Source File: SpanLabelTest2980.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean runTest() throws Exception {
    if (layout == null) {
        Layout[] layouts = new Layout[]{
            new FlowLayout(),
            BoxLayout.x(),
            BoxLayout.y()
        };
        for (Layout l : layouts) {
            layout = l;
            runTest();
        }
        return true;
    }
    System.out.println("Laying out SpanLabel with layout "+layout);
    Label label = new Label("Tap the following");
    
    
    Container cnt = new Container(layout) {
        @Override
        protected Dimension calcPreferredSize() {
            return new Dimension(label.getPreferredW(), CN.convertToPixels(1000));
        }

        @Override
        public int getWidth() {
            return label.getPreferredW();
        }

        @Override
        public int getHeight() {
            return CN.convertToPixels(1000);
        }
        
        
        
        
        
        
    };
    cnt.setScrollableX(false);
    cnt.setScrollableY(false);
    cnt.setWidth(label.getPreferredW());
    cnt.setHeight(CN.convertToPixels(1000));
    SpanLabel sl = new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos.");
   
    sl.setName("TheSpanLabel");
    cnt.add(sl);
    cnt.add(new Button("Click Me"));
    cnt.setShouldCalcPreferredSize(true);
    cnt.layoutContainer();
    assertTrue(sl.getHeight() > label.getPreferredH() * 2, "Span Label height is too low for layout "+layout+": was "+sl.getHeight()+" but should be at least "+(label.getPreferredH() * 2));
    
    SpanButton sb = new SpanButton("Tap the following button to open the gallery. You should be able to select multiple images and videos.");
   
    sb.setName("TheSpanButton");
    cnt.removeAll();
    cnt.add(sb);
    cnt.add(new Button("Click Me"));
    cnt.setShouldCalcPreferredSize(true);
    cnt.layoutContainer();
    assertTrue(sb.getHeight() > label.getPreferredH() * 2, "Span button height is too low for layout "+layout+": was "+sb.getHeight()+" but should be at least "+(label.getPreferredH() * 2));
    
    
    return true;
}
 
Example #29
Source File: InfiniteProgressWithMessage.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());
    Button showProgress = new Button("Show InfiniteProgress");
    showProgress.addActionListener(e->{
        callSerially(()->{
            Dialog dlg = new Dialog();
            dlg.setDialogUIID("Container");
            dlg.setTintColor(0x0);
            dlg.setLayout(new BorderLayout());
            SpanLabel message = new SpanLabel("This is a progress message we wish to show");
            $("*", message).setFgColor(0xffffff);
            dlg.add(BorderLayout.CENTER, BoxLayout.encloseYCenter(FlowLayout.encloseCenter(new InfiniteProgress()), FlowLayout.encloseCenter(message)));

            dlg.setTransitionInAnimator(CommonTransitions.createEmpty());
            dlg.setTransitionOutAnimator(CommonTransitions.createEmpty());
            dlg.showPacked(BorderLayout.CENTER, false);

            //dlg.revalidateWithAnimationSafety();
            invokeAndBlock(()->{
                Util.sleep(5000);
            });
            dlg.dispose();
            
        });
    });
    
    Button showToastProgress = new Button("Show Toast Progress");
    showToastProgress.addActionListener(e->{
        callSerially(()->{
            Status status = ToastBar.getInstance().createStatus();
            status.setMessage("This is a progress message we wish to show");
            status.setShowProgressIndicator(true);
            status.show();
            invokeAndBlock(()->{
                Util.sleep(5000);
            });
            status.clear();
                    
        });
    });
    hi.addAll(showProgress, showToastProgress);
    hi.show();
}
 
Example #30
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" : ""));
    }
}