Java Code Examples for com.codename1.ui.Form#setBackCommand()
The following examples show how to use
com.codename1.ui.Form#setBackCommand() .
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: PhotoShare.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
private void showMainForm() { final Form photos = new Form("Photos"); photos.setLayout(new BorderLayout()); GridLayout gr = new GridLayout(1, 1); final Container grid = new Container(gr); gr.setAutoFit(true); grid.setScrollableY(true); grid.addPullToRefresh(new Runnable() { public void run() { refreshGrid(grid); } }); grid.addComponent(new InfiniteProgress()); photos.addComponent(BorderLayout.CENTER, grid); photos.removeAllCommands(); photos.setBackCommand(null); photos.addCommand(createPictureCommand(grid)); photos.show(); refreshGrid(grid); }
Example 2
Source File: Log.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Places a form with the log as a TextArea on the screen, this method can * be attached to appear at a given time or using a fixed global key. Using * this method might cause a problem with further log output * @deprecated this method is an outdated method that's no longer supported */ public static void showLog() { try { String text = getLogContent(); TextArea area = new TextArea(text, 5, 20); Form f = new Form("Log"); f.setScrollable(false); final Form current = Display.getInstance().getCurrent(); Command back = new Command("Back") { public void actionPerformed(ActionEvent ev) { current.show(); } }; f.addCommand(back); f.setBackCommand(back); f.setLayout(new BorderLayout()); f.addComponent(BorderLayout.CENTER, area); f.show(); } catch (Exception ex) { ex.printStackTrace(); } }
Example 3
Source File: PropertyCross.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
/** * Helper method to implement the back command to the main form * @param f the form from which we would be returning */ private void addBackToHome(Form f) { // the back command maps to the physical button on devices other than iPhone and creates the back arrow appearance on iOS f.setBackCommand(new Command("PropertyCross") { @Override public void actionPerformed(ActionEvent evt) { showMainForm(true, null, null); } }); }
Example 4
Source File: PhotoShare.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
Command createBackCommand(final Container viewerParent, final Container grid) { return new Command("Back") { @Override public void actionPerformed(ActionEvent evt) { viewerParent.getParent().replace(viewerParent, grid, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 300)); Form frm = Display.getInstance().getCurrent(); frm.setBackCommand(null); } }; }
Example 5
Source File: MapsDemo.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
private void showMeOnMap() { Form map = new Form("Map"); map.setLayout(new BorderLayout()); map.setScrollable(false); final MapComponent mc = new MapComponent(); putMeOnMap(mc); mc.zoomToLayers(); map.addComponent(BorderLayout.CENTER, mc); map.getToolbar().addCommandToLeftBar(new MapsDemo.BackCommand()); map.setBackCommand(new MapsDemo.BackCommand()); map.show(); }
Example 6
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * Invoked internally to set the back command on the form, this method allows subclasses * to change the behavior of back command adding or disable it * @param f the form * @param backCommand the back command */ protected void setBackCommand(Form f, Command backCommand) { if(f.getToolbar() != null) { f.getToolbar().setBackCommand(backCommand); } else { if(shouldAddBackCommandToMenu()) { f.addCommand(backCommand, f.getCommandCount()); } f.setBackCommand(backCommand); } }
Example 7
Source File: Oauth2.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * This method shows an authentication for login form * * @param al a listener that will receive at its source either a token for * the service or an exception in case of a failure * @return a component that should be displayed to the user in order to * perform the authentication */ public void showAuthentication(final ActionListener al) { if (useBrowserWindow) { final BrowserWindow win = new BrowserWindow(buildURL()); win.setTitle("Login"); win.addLoadListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String url = (String)evt.getSource(); if (url.startsWith(redirectURI)) { win.close(); handleURL((String)evt.getSource(), null, al, null, null, null); } } }); win.show(); return; } final Form old = Display.getInstance().getCurrent(); InfiniteProgress inf = new InfiniteProgress(); final Dialog progress = inf.showInifiniteBlocking(); Form authenticationForm = new Form("Login"); authenticationForm.setScrollable(false); if (old != null) { Command cancel = new Command("Cancel") { public void actionPerformed(ActionEvent ev) { if (Display.getInstance().getCurrent() == progress) { progress.dispose(); } old.showBack(); } }; if (authenticationForm.getToolbar() != null){ authenticationForm.getToolbar().addCommandToLeftBar(cancel); } else { authenticationForm.addCommand(cancel); } authenticationForm.setBackCommand(cancel); } authenticationForm.setLayout(new BorderLayout()); authenticationForm.addComponent(BorderLayout.CENTER, createLoginComponent(al, authenticationForm, old, progress)); }
Example 8
Source File: InterFormContainerSample.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public void start() { Button sharedButton = new Button("Shared Button"); InterFormContainer cnt = new InterFormContainer(sharedButton); InterFormContainer cnt2 = new InterFormContainer(sharedButton); Toolbar.setGlobalToolbar(true); Form hi = new Form("Transitions", new BorderLayout()); Container c = new Container(BoxLayout.y()); hi.add(BorderLayout.CENTER, c); hi.add(BorderLayout.SOUTH, cnt); Style bg = hi.getContentPane().getUnselectedStyle(); bg.setBgTransparency(255); bg.setBgColor(0xff0000); Button showTransition = new Button("Show"); Picker pick = new Picker(); pick.setStrings("Slide", "SlideFade", "Cover", "Uncover", "Fade", "Flip"); pick.setSelectedString("Slide"); TextField duration = new TextField("10000", "Duration", 6, TextArea.NUMERIC); CheckBox horizontal = CheckBox.createToggle("Horizontal"); pick.addActionListener((e) -> { String s = pick.getSelectedString().toLowerCase(); horizontal.setEnabled(s.equals("slide") || s.indexOf("cover") > -1); }); horizontal.setSelected(true); c.add(showTransition). add(pick). add(duration). add(horizontal); Form dest = new Form("Destination", new BorderLayout()); sharedButton.addActionListener(e -> { if (sharedButton.getComponentForm() == hi) { dest.show(); } else { hi.showBack(); } }); dest.add(BorderLayout.SOUTH, cnt2); bg = dest.getContentPane().getUnselectedStyle(); bg.setBgTransparency(255); bg.setBgColor(0xff); dest.setBackCommand( dest.getToolbar().addCommandToLeftBar("Back", null, (e) -> hi.showBack())); showTransition.addActionListener((e) -> { int h = CommonTransitions.SLIDE_HORIZONTAL; if (!horizontal.isSelected()) { h = CommonTransitions.SLIDE_VERTICAL; } switch (pick.getSelectedString()) { case "Slide": hi.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000))); break; case "SlideFade": hi.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000))); break; case "Cover": hi.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000))); break; case "Uncover": hi.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000))); break; case "Fade": hi.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000))); dest.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000))); break; case "Flip": hi.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000))); dest.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000))); break; } dest.show(); }); hi.show(); }