com.codename1.ui.Form Java Examples
The following examples show how to use
com.codename1.ui.Form.
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: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * 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 #2
Source File: SignIn.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void showFacebookUser(String token){ ConnectionRequest req = new ConnectionRequest(); req.setPost(false); req.setUrl("https://graph.facebook.com/v2.3/me"); req.addArgumentNoEncoding("access_token", token); InfiniteProgress ip = new InfiniteProgress(); Dialog d = ip.showInifiniteBlocking(); NetworkManager.getInstance().addToQueueAndWait(req); byte[] data = req.getResponseData(); JSONParser parser = new JSONParser(); Map map = null; try { map = parser.parseJSON(new InputStreamReader(new ByteArrayInputStream(data), "UTF-8")); } catch (IOException ex) { ex.printStackTrace(); } String name = (String) map.get("name"); d.dispose(); Form userForm = new UserForm(name, (EncodedImage) theme.getImage("user.png"), "https://graph.facebook.com/v2.3/me/picture?access_token=" + token); userForm.show(); }
Example #3
Source File: BudgetDoughnutChart.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
/** * Executes the chart demo. * * @param context the context * @return the built intent */ public Form execute() { List<double[]> values = new ArrayList<double[]>(); values.add(new double[] { 12, 14, 11, 10, 19 }); values.add(new double[] { 10, 9, 14, 20, 11 }); List<String[]> titles = new ArrayList<String[]>(); titles.add(new String[] { "P1", "P2", "P3", "P4", "P5" }); titles.add(new String[] { "Project1", "Project2", "Project3", "Project4", "Project5" }); int[] colors = new int[] { ColorUtil.BLUE, ColorUtil.GREEN, ColorUtil.MAGENTA, ColorUtil.YELLOW, ColorUtil.CYAN }; DefaultRenderer renderer = buildCategoryRenderer(colors); renderer.setApplyBackgroundColor(true); renderer.setBackgroundColor(ColorUtil.rgb(222, 222, 200)); renderer.setLabelsColor(ColorUtil.GRAY); DoughnutChart chart = new DoughnutChart(buildMultipleCategoryDataset("Project budget", titles, values), renderer); ChartComponent c = new ChartComponent(chart); return wrap("Doughnut Chart Demo", c); }
Example #4
Source File: FloatingActionButton.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * This is a utility method to bind the FAB to a given Container, it will return a new container to add or will * use the layered pane if the container is a content pane. * * @param cnt the Container to add the FAB to * @param orientation one of Component.RIGHT/LEFT/CENTER * @param valign one of Component.TOP/BOTTOM/CENTER * * @return a new Container that contains the cnt and the FAB on top or null in the case of a content pane */ public Container bindFabToContainer(Component cnt, int orientation, int valign) { FlowLayout flow = new FlowLayout(orientation); flow.setValign(valign); Form f = cnt.getComponentForm(); if(f != null && (f.getContentPane() == cnt || f == cnt)) { // special case for content pane installs the button directly on the content pane Container layers = f.getLayeredPane(getClass(), true); layers.setLayout(flow); layers.add(this); return null; } Container conUpper = new Container(flow); conUpper.add(this); return LayeredLayout.encloseIn(cnt, conUpper); }
Example #5
Source File: SharedJavascriptContextSample.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", new BorderLayout()); TextArea input = new TextArea(); TextArea output = new TextArea(); output.setEditable(false); Button execute = new Button("Run"); execute.addActionListener(evt->{ BrowserComponent bc = CN.getSharedJavascriptContext().ready().get(); bc.execute("callback.onSuccess(window.eval(${0}))", new Object[]{input.getText()}, res->{ output.setText(res.toString()); }); }); SplitPane split = new SplitPane(SplitPane.VERTICAL_SPLIT, input, output, "0", "50%", "99%"); hi.add(CENTER, split); hi.add(NORTH, execute); hi.show(); }
Example #6
Source File: LinearGradientSample.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
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 #7
Source File: ContainerList.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void updateComponentCount() { int cc = getComponentCount(); int modelCount = model.getSize(); if(cc != modelCount) { if(cc < modelCount) { for(int iter = cc ; iter < modelCount ; iter++) { addComponent(new Entry(iter)); } } else { while(getComponentCount() > modelCount) { removeComponent(getComponentAt(getComponentCount() - 1)); } } Form f = getComponentForm(); if(f != null) { f.revalidate(); } } }
Example #8
Source File: WebSocketsSample.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
void showLogin() { Form f = new Form("Login"); f.addComponent(new Label("Name: ")); final TextField nameField = new TextField(); f.addComponent(nameField); f.addComponent(new Button(new Command("Login"){ @Override public void actionPerformed(ActionEvent evt) { System.out.println("Hello"); if (sock.getReadyState() == WebSocketState.OPEN) { System.out.println("Open"); sock.send(nameField.getText()); showChat(); } else { System.out.println("Closed"); Dialog.show("Dialog", "The socket is not open: "+sock.getReadyState(), "OK", null); sock.reconnect(); } } })); f.show(); }
Example #9
Source File: BrowserWindowSample.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); Button openBrowser = new Button("Open Browser"); openBrowser.addActionListener(e->{ BrowserWindow win = new BrowserWindow("https://weblite.ca"); win.addCloseListener(evt->{ System.out.println("Browser was closed"); }); win.addLoadListener(evt->{ System.out.println("Loaded page "+evt.getSource()); }); win.setTitle("Web Browser"); win.show(); }); hi.add(openBrowser); hi.show(); }
Example #10
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void processCommandImpl(ActionEvent ev, Command cmd) { processCommand(ev, cmd); if(ev.isConsumed()) { return; } if(globalCommandListeners != null) { globalCommandListeners.fireActionEvent(ev); if(ev.isConsumed()) { return; } } if(localCommandListeners != null) { Form f = Display.getInstance().getCurrent(); EventDispatcher e = (EventDispatcher)localCommandListeners.get(f.getName()); if(e != null) { e.fireActionEvent(ev); } } }
Example #11
Source File: AbstractDemoChart.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
protected Form wrap(String title, Component c){ c.getStyle().setBgColor(0xff0000); Form f = new Form(title); f.setLayout(new BorderLayout()); if (isDrawOnMutableImage()) { int dispW = Display.getInstance().getDisplayWidth(); int dispH = Display.getInstance().getDisplayHeight(); Image img = Image.createImage((int)(dispW * 0.8), (int)(dispH * 0.8), 0x0); Graphics g = img.getGraphics(); c.setWidth((int)(dispW * 0.8)); c.setHeight((int)(dispH * 0.8)); c.paint(g); f.addComponent(BorderLayout.CENTER, new Label(img)); } else { f.addComponent(BorderLayout.CENTER, c); } return f; }
Example #12
Source File: TestRecorder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private com.codename1.ui.Component findHighestVisibleComponent() { Form f = Display.getInstance().getCurrent(); final com.codename1.ui.Component[] cmp = new com.codename1.ui.Component[1]; visitComponents(f.getContentPane(), new ComponentVisitor() { int highest = Display.getInstance().getDisplayHeight(); public void visit(Component c) { int abY = c.getAbsoluteY(); if(abY < highest && abY >= 0) { highest = abY; cmp[0] = c; } } }); return cmp[0]; }
Example #13
Source File: TestRecorder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void assertLabelsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_assertLabelsActionPerformed Form f = Display.getInstance().getCurrent(); visitComponents(f.getContentPane(), new ComponentVisitor() { public void visit(Component c) { if(c instanceof com.codename1.ui.Label) { com.codename1.ui.Label lbl = (com.codename1.ui.Label)c; String labelText = "null"; if(lbl.getText() != null) { labelText = "\"" + lbl.getText().replace("\n", "\\n") + "\""; } if(lbl.getName() != null) { generatedCode += " assertLabel(" + getPathOrName(lbl) + ", " + labelText + ");\n"; } else { generatedCode += " assertLabel(" + labelText + ");\n"; } } } }); updateTestCode(); }
Example #14
Source File: ToolbarRTLTest.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World", BoxLayout.y()); Toolbar tb = new Toolbar(); hi.setToolbar(tb); tb.addCommandToLeftSideMenu(new Command("Test") {; public void actionPerformed(ActionEvent e) { System.out.println("Action clicked"); } }); hi.add(new Label("Hi World")); hi.show(); }
Example #15
Source File: UIBuilder.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void initBackForm(Form f) { Vector formNavigationStack = baseFormNavigationStack; if(formNavigationStack != null && formNavigationStack.size() > 0) { setFormState(f, (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1)); formNavigationStack.removeElementAt(formNavigationStack.size() - 1); if(formNavigationStack.size() > 0) { Hashtable previous = (Hashtable)formNavigationStack.elementAt(formNavigationStack.size() - 1); String commandAction = (String)previous.get(FORM_STATE_KEY_NAME); Command backCommand = createCommandImpl(getBackCommandText((String)previous.get(FORM_STATE_KEY_TITLE)), null, BACK_COMMAND_ID, commandAction, true, ""); setBackCommand(f, backCommand); // trigger listener creation if this is the only command in the form getFormListenerInstance(f, null); backCommand.putClientProperty(COMMAND_ARGUMENTS, ""); backCommand.putClientProperty(COMMAND_ACTION, commandAction); } } }
Example #16
Source File: SocialChat.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
private void showPendingMessages(Form f) { if(Storage.getInstance().exists("pendingMessages")) { java.util.List<Message> pendingMessages = (java.util.List<Message>)Storage.getInstance().readObject("pendingMessages"); Message m = pendingMessages.get(0); pendingMessages.remove(0); respond(m); if(pendingMessages.size() == 0) { Storage.getInstance().deleteStorageFile("pendingMessages"); } else { Storage.getInstance().writeObject("pendingMessages", pendingMessages); UITimer uit = new UITimer(() -> { showPendingMessages(f); }); uit.schedule(3500, false, f); } } }
Example #17
Source File: TestComponent.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
private void getComponentAt_int_int_label() { log("Testing getComponentAt(x, y) with label"); int w = Display.getInstance().getDisplayWidth(); int h = Display.getInstance().getDisplayHeight(); Form f = new Form("My Form", new BorderLayout()); Label l = new Label("Hello"); f.add(BorderLayout.CENTER, l); f.show(); TestUtils.waitForFormTitle("My Form", 2000); Component middleComponent = f.getComponentAt(w/2, h/2); assertEqual(l, middleComponent, "Found wrong component"); }
Example #18
Source File: InteractionDialog.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ @Override protected void deinitialize() { super.deinitialize(); if(disposed) { Form f = getComponentForm(); if(f != null) { if (pressedListener != null) { f.removePointerPressedListener(pressedListener); } if (releasedListener != null) { f.removePointerReleasedListener(releasedListener); } Container pp = getLayeredPane(f); Container p = getParent(); remove(); if (p.getComponentCount() == 0) { p.remove(); } //pp.removeAll(); pp.revalidateWithAnimationSafety(); cleanupLayer(f); } } }
Example #19
Source File: SignatureComponentDemo.java From codenameone-demos with GNU General Public License v2.0 | 6 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Signature Component"); hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS)); hi.add("Enter Your Name:"); hi.add(new TextField()); hi.add("Signature:"); SignatureComponent sig = new SignatureComponent(); sig.addActionListener((evt)-> { System.out.println("The signature was changed"); Image img = sig.getSignatureImage(); // Now we can do whatever we want with the image of this signature. }); hi.addComponent(sig); hi.show(); }
Example #20
Source File: AsyncMediaSample.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { if(current != null){ current.show(); return; } Form hi = new Form("Hi World"); new Recorder().initUI(hi); hi.show(); }
Example #21
Source File: TextEditUtil.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * * @return the next editable TextArea after the currently edited component. */ private static Component getPrevEditComponent() { if (curEditedComponent != null) { Form parent = curEditedComponent.getComponentForm(); if (parent != null) { return parent.getPreviousComponent(curEditedComponent); } } return null; }
Example #22
Source File: BlackBerryVirtualKeyboard.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
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 #23
Source File: BlackBerryCanvas.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
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 #24
Source File: ChartComponent.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start(){ Form f = ChartComponent.this.getComponentForm(); if ( f != null ){ f.registerAnimated(this); this.motion.start(); } else { animations.remove(this); } }
Example #25
Source File: FillShapeTest.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void start() { Form f = new Form("Test Fill Shape"); f.setLayout(BorderLayout.center()); ButtonGroup bg = new ButtonGroup(); drawStringBtn = RadioButton.createToggle("String", bg); drawPathBtn = RadioButton.createToggle("Path", bg); f.add(BorderLayout.CENTER, new DrawingCanvas()); f.add(BorderLayout.NORTH, GridLayout.encloseIn(drawStringBtn, drawPathBtn)); f.show(); }
Example #26
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 #27
Source File: Login.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
private static void signIn(final Form main) { FaceBookAccess.setClientId("132970916828080"); FaceBookAccess.setClientSecret("6aaf4c8ea791f08ea15735eb647becfe"); FaceBookAccess.setRedirectURI("http://www.codenameone.com/"); FaceBookAccess.setPermissions(new String[]{"user_location", "user_photos", "friends_photos", "publish_stream", "read_stream", "user_relationships", "user_birthday", "friends_birthday", "friends_relationships", "read_mailbox", "user_events", "friends_events", "user_about_me"}); FaceBookAccess.getInstance().showAuthentication(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (evt.getSource() instanceof String) { String token = (String) evt.getSource(); String expires = Oauth2.getExpires(); TOKEN = token; System.out.println("recived a token " + token + " which expires on " + expires); //store token for future queries. Storage.getInstance().writeObject("token", token); if (main != null) { main.showBack(); } } else { Exception err = (Exception) evt.getSource(); err.printStackTrace(); Dialog.show("Error", "An error occurred while logging in: " + err, "OK", null); } } }); }
Example #28
Source File: CameraKitPickerTest7.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public void showAnotherForm(){ Form form = new Form(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE)); form.setScrollable(false); Container container = new Container(BoxLayout.y()); container.add(new Label("Test", "heading5")); container.add(new Label("", "newLine")); container.add(new Label("", "newLine")); final Picker fromDate = new Picker(); fromDate.setType(Display.PICKER_TYPE_DATE); container.add(new Label("From Date", "heading7")); container.add(fromDate); container.add(new Label("", "newLine")); final Picker toDate = new Picker(); toDate.setType(Display.PICKER_TYPE_DATE); container.add(new Label("To Date", "heading7")); container.add(toDate); Button nextBtn = new Button("Proceed"); nextBtn.setUIID("loginBtn"); nextBtn.addActionListener((ev) -> { DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); String fromDateStr = dateFormat.format(fromDate.getDate()); String toDateStr = dateFormat.format(toDate.getDate()); }); container.add(new Label("", "newLine")); container.add(new Label("", "newLine")); container.add(nextBtn); form.add(BorderLayout.CENTER, container); form.show(); }
Example #29
Source File: SwipeBackSupport.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
void startBackTransition(final Form currentForm, Form destination) { final Transition t = destination.getTransitionOutAnimator().copy(true); if(t instanceof CommonTransitions) { Transition originalTransition = currentForm.getTransitionOutAnimator(); currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty()); Form blank = new Form() { protected boolean shouldSendPointerReleaseToOtherForm() { return true; } }; blank.addPointerDraggedListener(pointerDragged); blank.addPointerReleasedListener(pointerReleased); blank.addPointerPressedListener(pointerPressed); blank.setTransitionInAnimator(CommonTransitions.createEmpty()); blank.setTransitionOutAnimator(CommonTransitions.createEmpty()); blank.show(); currentForm.setTransitionOutAnimator(originalTransition); ((CommonTransitions)t).setMotion(new LazyValue<Motion>() { public Motion get(Object... args) { return new ManualMotion(((Integer)args[0]).intValue(), ((Integer)args[1]).intValue(), ((Integer)args[2]).intValue()); } }); t.init(currentForm, destination); t.initTransition(); blank.setGlassPane(new Painter() { public void paint(Graphics g, Rectangle rect) { t.animate(); t.paint(g); } }); } }
Example #30
Source File: Table.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * 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; }