Search in sources :

Example 56 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class JavaSEPort method registerPush.

@Override
public void registerPush(Hashtable meta, boolean noFallback) {
    Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
    String user = p.get("user", null);
    Display d = Display.getInstance();
    if (user == null) {
        JPanel pnl = new JPanel();
        JTextField tf = new JTextField(20);
        pnl.add(new JLabel("E-Mail For Push"));
        pnl.add(tf);
        JOptionPane.showMessageDialog(canvas, pnl, "Email For Push", JOptionPane.PLAIN_MESSAGE);
        user = tf.getText();
        p.put("user", user);
    }
    d.setProperty("built_by_user", user);
    String mainClass = System.getProperty("MainClass");
    if (mainClass != null) {
        mainClass = mainClass.substring(0, mainClass.lastIndexOf('.'));
        d.setProperty("package_name", mainClass);
    }
    super.registerPush(meta, noFallback);
    if (pushSimulation != null && pushSimulation.isVisible()) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                JOptionPane.showMessageDialog(window, "registerForPush invoked. Use the buttons in the push simulator to send the appropriate callback to your app", "Push Registration", JOptionPane.INFORMATION_MESSAGE);
            }
        });
    }
}
Also used : Preferences(java.util.prefs.Preferences) Display(com.codename1.ui.Display)

Example 57 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class TestRecorder method bindListListener.

private void bindListListener(final com.codename1.ui.Component cmp, final ListModel m) {
    if (cmp.getClientProperty("CN1$listenerBound") == null) {
        cmp.putClientProperty("CN1$listenerBound", Boolean.TRUE);
        m.addSelectionListener(new SelectionListener() {

            public void selectionChanged(int oldSelected, int newSelected) {
                generatedCode += "        selectInList(" + getPathOrName(cmp) + ", " + newSelected + ");\n";
                updateTestCode();
            }
        });
    }
}
Also used : SelectionListener(com.codename1.ui.events.SelectionListener)

Example 58 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class TestRecorder method eventPointerReleased.

void eventPointerReleased(int x, int y) {
    if (isRecording()) {
        com.codename1.ui.Component cmp = Display.getInstance().getCurrent().getComponentAt(x, y);
        if (isListComponent(cmp)) {
            return;
        }
        if (dragged) {
            if (dragToScroll.isSelected()) {
                com.codename1.ui.Component scrollTo;
                if (y > pointerPressedY) {
                    scrollTo = findLowestVisibleComponent();
                } else {
                    scrollTo = findHighestVisibleComponent();
                }
                if (scrollTo != null && scrollTo != Display.getInstance().getCurrent() && scrollTo != Display.getInstance().getCurrent().getContentPane()) {
                    String name = scrollTo.getName();
                    if (name != null) {
                        generatedCode += "        ensureVisible(\"" + name + "\");\n";
                    } else {
                        String pp = getPathToComponent(scrollTo);
                        if (pp == null) {
                            return;
                        }
                        generatedCode += "        ensureVisible(" + pp + ");\n";
                    }
                    updateTestCode();
                }
            } else {
                addWaitStatement();
                generatedCode += "        pointerRelease" + generatePointerEventArguments(x, y);
                updateTestCode();
            }
        } else {
            if (isToolbarComponent(cmp)) {
                if (cmp instanceof com.codename1.ui.Button) {
                    Command cmd = ((com.codename1.ui.Button) cmp).getCommand();
                    if (cmd != null) {
                        int offset = 0;
                        Command[] commands = TestUtils.getToolbarCommands();
                        for (Command c : commands) {
                            if (c == cmd) {
                                generatedCode += "        assertEqual(getToolbarCommands().length, " + commands.length + ");\n";
                                generatedCode += "        executeToolbarCommandAtOffset(" + offset + ");\n";
                                updateTestCode();
                                return;
                            }
                            offset++;
                        }
                    } else {
                        if (cmp.getUIID().equals("MenuButton")) {
                            // side menu button
                            generatedCode += "        showSidemenu();\n";
                            updateTestCode();
                            return;
                        }
                    }
                }
            }
            if (cmp instanceof com.codename1.ui.Button) {
                com.codename1.ui.Button btn = (com.codename1.ui.Button) cmp;
                // special case for back command on iOS
                if (btn.getCommand() != null && btn.getCommand() == Display.getInstance().getCurrent().getBackCommand()) {
                    generatedCode += "        goBack();\n";
                } else {
                    if (btn.getName() != null && btn.getName().length() > 0) {
                        generatedCode += "        clickButtonByName(\"" + btn.getName() + "\");\n";
                    } else {
                        if (btn.getText() != null && btn.getText().length() > 0) {
                            generatedCode += "        clickButtonByLabel(\"" + btn.getText() + "\");\n";
                        } else {
                            String pp = getPathToComponent(cmp);
                            if (pp == null || pp.equals("(String)null")) {
                                return;
                            }
                            generatedCode += "        clickButtonByPath(" + pp + ");\n";
                        }
                    }
                }
                updateTestCode();
                return;
            }
            if (cmp instanceof com.codename1.ui.TextArea) {
                // ignore this, its probably initiating edit which we will capture soon
                return;
            }
            generatedCode += "        pointerPress" + generatePointerEventArguments(pointerPressedX, pointerPressedY);
            addWaitStatement();
            generatedCode += "        pointerRelease" + generatePointerEventArguments(x, y);
            updateTestCode();
        }
    }
}
Also used : Command(com.codename1.ui.Command) Component(com.codename1.ui.Component)

Example 59 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class TestRecorder method generatePointerEventArguments.

private String generatePointerEventArguments(int x, int y) {
    com.codename1.ui.Component cmp = getCodenameOneComponentAt(x, y);
    if (cmp.getParent() instanceof Form) {
        cmp = cmp.getParent();
    }
    String componentName = cmp.getName();
    if (componentName == null) {
        componentName = getPathToComponent(cmp);
    } else {
        componentName = "\"" + componentName + "\"";
    }
    float actualX = ((float) x - cmp.getAbsoluteX()) / ((float) cmp.getWidth());
    float actualY = ((float) y - cmp.getAbsoluteY()) / ((float) cmp.getHeight());
    return "(" + actualX + "f, " + actualY + "f, " + componentName + ");\n";
}
Also used : Form(com.codename1.ui.Form) Component(com.codename1.ui.Component)

Example 60 with com.codename1.ui

use of com.codename1.ui in project CodenameOne by codenameone.

the class TestRecorder method visitComponents.

private void visitComponents(com.codename1.ui.Container cnt, ComponentVisitor v) {
    v.visit(cnt);
    int count = cnt.getComponentCount();
    for (int iter = 0; iter < count; iter++) {
        com.codename1.ui.Component current = cnt.getComponentAt(iter);
        if (current instanceof com.codename1.ui.Container) {
            visitComponents((com.codename1.ui.Container) current, v);
        } else {
            v.visit(current);
        }
    }
}
Also used : Component(com.codename1.ui.Component)

Aggregations

EncodedImage (com.codename1.ui.EncodedImage)26 Component (com.codename1.ui.Component)23 Point (java.awt.Point)23 IOException (java.io.IOException)23 AnimationObject (com.codename1.ui.animations.AnimationObject)22 ArrayList (java.util.ArrayList)22 BufferedImage (java.awt.image.BufferedImage)19 Hashtable (java.util.Hashtable)18 Form (com.codename1.ui.Form)15 Timeline (com.codename1.ui.animations.Timeline)15 Image (com.codename1.ui.Image)13 EditableResources (com.codename1.ui.util.EditableResources)13 File (java.io.File)13 Vector (java.util.Vector)13 TextArea (com.codename1.ui.TextArea)12 Border (com.codename1.ui.plaf.Border)12 Label (com.codename1.ui.Label)10 BorderLayout (com.codename1.ui.layouts.BorderLayout)10 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)10 Container (com.codename1.ui.Container)9