Java Code Examples for com.codename1.ui.layouts.BorderLayout#setCenterBehavior()

The following examples show how to use com.codename1.ui.layouts.BorderLayout#setCenterBehavior() . 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: Flickr.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
private static void addWaitingProgress(Form f, boolean center, Container pane) {
    pane.setVisible(false);
    Container cnt = f.getLayeredPane();
    BorderLayout bl = new BorderLayout();
    bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    cnt.setLayout(bl);
    if (center) {
        cnt.addComponent(BorderLayout.CENTER, new InfiniteProgress());
    } else {
        Container top = new Container();
        BorderLayout bl1 = new BorderLayout();
        bl1.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
        top.setLayout(bl1);
        top.addComponent(BorderLayout.CENTER, new InfiniteProgress());

        cnt.addComponent(BorderLayout.NORTH, top);
    }
}
 
Example 2
Source File: FBDemo.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
private Component showMyFriends() {
    final Container c = new Container(new BorderLayout());
    c.setScrollable(false);
    BorderLayout bl = new BorderLayout();
    bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    Container p = new Container(bl);
    p.addComponent(BorderLayout.CENTER, new InfiniteProgress());

    c.addComponent(BorderLayout.CENTER, p);
    final List myFriends = new List();
    myFriends.setRenderer(new FriendsRenderer());
    try {
        FaceBookAccess.getInstance().getUserFriends("me", (DefaultListModel) myFriends.getModel(), new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                c.removeAll();
                c.addComponent(BorderLayout.CENTER, myFriends);
                c.revalidate();
            }
        });
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return c;
}
 
Example 3
Source File: MenuBar.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
void adaptTitleLayoutBackCommandStructure() {
    Container t = getTitleAreaContainer();
    if (t.getComponentCount() - componentCountOffset(t) == 3) {
        return;
    }
    BorderLayout titleLayout = (BorderLayout) t.getLayout();
    if (Display.COMMAND_BEHAVIOR_ICS == getCommandBehavior()) {
        titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        getTitleComponent().getUnselectedStyle().setAlignment(Component.LEFT, true);
    } else {
        titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    }
    t.removeAll();
    t.addComponent(BorderLayout.CENTER, getTitleComponent());
    Container leftContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
    Container rightContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
    t.addComponent(BorderLayout.EAST, rightContainer);
    t.addComponent(BorderLayout.WEST, leftContainer);
    initTitleBarStatus();
}
 
Example 4
Source File: Tabs.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void initLaf(UIManager manager) {
    super.initLaf(manager);
    int tabPlace = manager.getThemeConstant("tabPlacementInt", -1);
    tabsFillRows = manager.isThemeConstant("tabsFillRowsBool", false);
    tabsGridLayout = manager.isThemeConstant("tabsGridBool", false);
    changeTabOnFocus = manager.isThemeConstant("changeTabOnFocusBool", false);
    BorderLayout bd = (BorderLayout)super.getLayout();
    if(bd != null) {
        if(manager.isThemeConstant("tabsOnTopBool", false)) {
            if(bd.getCenterBehavior() != BorderLayout.CENTER_BEHAVIOR_TOTAL_BELOW) {
                bd.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_TOTAL_BELOW);
                checkTabsCanBeSeen();
            }
        } else {
            bd.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        }
    }
    changeTabContainerStyleOnFocus =  manager.isThemeConstant("changeTabContainerStyleOnFocusBool", false);
    if(tabPlace != -1){
        tabPlacement = tabPlace;
    }
}
 
Example 5
Source File: PhotoShare.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
private void showLoginForm() {
    Form login = new Form("Login");
    BorderLayout bl = new BorderLayout();
    bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    ComponentGroup loginDetails = new ComponentGroup();
    
    TextField displayName = new TextField();
    displayName.setHint("Display Name");
    loginDetails.addComponent(displayName);

    final TextField email = new TextField();
    email.setHint("E-Mail");
    loginDetails.addComponent(email);

    Button send = new Button("Send Verification");
    loginDetails.addComponent(send);
    
    send.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            onSendAction(email);
        }
    });
    
    login.setLayout(bl);
    login.addComponent(BorderLayout.CENTER, loginDetails);
    login.show();
}
 
Example 6
Source File: MenuBar.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes the MenuBar from the parent Form
 */
protected void unInstallMenuBar() {
    parent.removeComponentFromForm(this);
    Container t = getTitleAreaContainer();
    BorderLayout titleLayout = (BorderLayout) t.getLayout();
    titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
    Component l = getTitleComponent();
    t.removeAll();
    if (l.getParent() != null) {
        l.getParent().removeComponent(l);
    }
    t.addComponent(BorderLayout.CENTER, l);
    initTitleBarStatus();
}
 
Example 7
Source File: Tabs.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an empty <code>TabbedPane</code> with the specified tab placement
 * of either: <code>Component.TOP</code>, <code>Component.BOTTOM</code>,
 * <code>Component.LEFT</code>, or <code>Component.RIGHT</code>.
 *
 * @param tabP the placement for the tabs relative to the content
 */
public Tabs(int tabP) {
    super(new BorderLayout());
    focusListener = new TabFocusListener();
    contentPane.setUIID("TabbedPane");
    super.addComponent(BorderLayout.CENTER, contentPane);
    tabsContainer = new Container();
    tabsContainer.setSafeArea(true);
    tabsContainer.setUIID("TabsContainer");
    tabsContainer.setScrollVisible(false);
    tabsContainer.getStyle().setMargin(0, 0, 0, 0);
    if(tabP == -1){
        setTabPlacement(tabPlacement);
    }else{
        setTabPlacement(tabP);
    }
    press = new SwipeListener(SwipeListener.PRESS);
    drag = new SwipeListener(SwipeListener.DRAG);
    release = new SwipeListener(SwipeListener.RELEASE);
    setUIID("Tabs");
    BorderLayout bd = (BorderLayout)super.getLayout();
    if(bd != null) {
        if(UIManager.getInstance().isThemeConstant("tabsOnTopBool", false)) {
            bd.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_TOTAL_BELOW);
        } else {
            bd.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        }
    }
    
}
 
Example 8
Source File: Poker.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The splash screen is relatively bare bones. Its important to have a splash screen for iOS 
 * since the build process generates a screenshot of this screen to speed up perceived performance
 */
public void showSplashScreen() {
    final Form splash = new Form();
    
    // a border layout places components in the center and the 4 sides.
    // by default it scales the center component so here we configure
    // it to place the component in the actual center
    BorderLayout border = new BorderLayout();
    border.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    splash.setLayout(border);
    
    // by default the form's content pane is scrollable on the Y axis
    // we need to disable it here
    splash.setScrollable(false);
    Label title = new Label("Poker Ace");
    
    // The UIID is used to determine the appearance of the component in the theme
    title.setUIID("SplashTitle");
    Label subtitle = new Label("By Codename One");
    subtitle.setUIID("SplashSubTitle");
    
    splash.addComponent(BorderLayout.NORTH, title);
    splash.addComponent(BorderLayout.SOUTH, subtitle);
    Label as = new Label(cards.getImage("as.png"));
    Label ah = new Label(cards.getImage("ah.png"));
    Label ac = new Label(cards.getImage("ac.png"));
    Label ad = new Label(cards.getImage("ad.png"));

    // a layered layout places components one on top of the other in the same dimension, it is
    // useful for transparency but in this case we are using it for an animation
    final Container center = new Container(new LayeredLayout());
    center.addComponent(as);
    center.addComponent(ah);
    center.addComponent(ac);
    center.addComponent(ad);
    
    splash.addComponent(BorderLayout.CENTER, center);
            
    splash.show();
    splash.setTransitionOutAnimator(CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, true, 800));

    // postpone the animation to the next cycle of the EDT to allow the UI to render fully once
    Display.getInstance().callSerially(new Runnable() {
        public void run() {
            // We replace the layout so the cards will be laid out in a line and animate the hierarchy
            // over 2 seconds, this effectively creates the effect of cards spreading out
            center.setLayout(new BoxLayout(BoxLayout.X_AXIS));
            center.setShouldCalcPreferredSize(true);
            splash.getContentPane().animateHierarchy(2000);

            // after showing the animation we wait for 2.5 seconds and then show the game with a nice
            // transition, notice that we use UI timer which is invoked on the Codename One EDT thread!
            new UITimer(new Runnable() {
                public void run() {
                    showGameUI();
                }
            }).schedule(2500, false, splash);
        }
    });
}
 
Example 9
Source File: KitchenSink.java    From codenameone-demos with GNU General Public License v2.0 4 votes vote down vote up
private void showSplashAnimation() {
    Form splash = new Form();
    splash.setUIID("Splash");
    splash.getContentPane().setUIID("Container");
    splash.getTitleArea().setUIID("Container");
    BorderLayout border = new BorderLayout();
    border.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    splash.setLayout(border);
    splash.setScrollable(false);
    Label title = new Label("Kitchen Sink Demo");
    title.setUIID("SplashTitle");
    Label subtitle = new Label("By Codename One");
    subtitle.setUIID("SplashSubTitle");
    splash.addComponent(BorderLayout.NORTH, title);
    splash.addComponent(BorderLayout.SOUTH, subtitle);
    Label beaker = new Label(res.getImage("beaker.png"));
    final Label beakerLogo = new Label(res.getImage("beaker_logo.png"));
    beakerLogo.setVisible(false);
    Container layeredLayout = new Container(new LayeredLayout());
    splash.addComponent(BorderLayout.CENTER, layeredLayout);
    layeredLayout.addComponent(beaker);
    final Container logoParent = new Container(new BorderLayout());
    layeredLayout.addComponent(logoParent);
    logoParent.addComponent(BorderLayout.CENTER, beakerLogo);
    splash.revalidate();
    
    Display.getInstance().callSerially(new Runnable() {
        public void run() {
            beakerLogo.setVisible(true);
            beakerLogo.setX(0);
            beakerLogo.setY(0);
            beakerLogo.setWidth(3);
            beakerLogo.setHeight(3);
            logoParent.setShouldCalcPreferredSize(true);
            logoParent.animateLayoutFade(2000, 0);
        }
    });
    
    splash.show();
    splash.setTransitionOutAnimator(CommonTransitions.createFastSlide(CommonTransitions.SLIDE_VERTICAL, true, 300));
    new UITimer(new Runnable() {
        public void run() {
            showMainUI();
        }
    }).schedule(2500, false, splash);
}
 
Example 10
Source File: MenuBar.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private void updateTitleCommandPlacement() {
    int commandBehavior = getCommandBehavior();
    Container t = getTitleAreaContainer();
    BorderLayout titleLayout = (BorderLayout) t.getLayout();
    if (getParent() == null) {
        installMenuBar();
    } else {
        if (getParent() == getTitleAreaContainer() && commandBehavior != Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT
                && commandBehavior != Display.COMMAND_BEHAVIOR_ICS) {
            getParent().removeComponent(this);
            installMenuBar();
        }
    }
    if (!(parent instanceof Dialog)) {
        if ((commandBehavior == Display.COMMAND_BEHAVIOR_ICS || 
                commandBehavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION ||
                commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK)
                && parent.getTitle() != null && parent.getTitle().length() > 0) {
            synchronizeCommandsWithButtonsInBackbutton();

            return;
        } else {
            if (commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT
                    || commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK) {
                if (getParent() != null) {
                    if (getParent() == getTitleAreaContainer()) {
                        return;
                    }
                    getParent().removeComponent(this);
                }
                //getTitleAreaContainer().addComponent(BorderLayout.EAST, findRightTitleContainer());
                return;
            }
        }
    }
    if (t.getComponentCount() - componentCountOffset(t) > 1) {
        if (Display.COMMAND_BEHAVIOR_ICS == getCommandBehavior()) {
            titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        } else {
            titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
        }
        Component l = getTitleComponent();
        if (l.getParent() != null) {
            l.getParent().removeComponent(l);
        }
        t.removeAll();
        t.addComponent(BorderLayout.CENTER, l);
        initTitleBarStatus();
    }
}