Search in sources :

Example 66 with com.codename1.rad.models

use of com.codename1.rad.models 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)

Example 67 with com.codename1.rad.models

use of com.codename1.rad.models 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 68 with com.codename1.rad.models

use of com.codename1.rad.models 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 69 with com.codename1.rad.models

use of com.codename1.rad.models in project CodenameOne by codenameone.

the class TestRunner method init.

private void init(String[] argv) {
    try {
        if (argv[0].startsWith("-") || argv[0].startsWith("/")) {
            printUsage();
            return;
        }
        try {
            mainClass = argv[0];
            int pos = 1;
            while (pos < argv.length) {
                String s = argv[pos];
                if (s.equalsIgnoreCase("-stopOnFail")) {
                    pos++;
                    stopOnFail = true;
                    continue;
                }
                if (s.equalsIgnoreCase("-testCases")) {
                    pos++;
                    testCases = argv[pos].split(",");
                    pos++;
                    continue;
                }
                if (s.equalsIgnoreCase("-skins")) {
                    pos++;
                    skins = argv[pos].split(",");
                    pos++;
                    continue;
                }
                if (s.equalsIgnoreCase("-landscape")) {
                    forceLandscape = true;
                    pos++;
                    continue;
                }
                if (s.equalsIgnoreCase("-portrait")) {
                    forcePortrait = true;
                    pos++;
                    continue;
                }
                if (s.equalsIgnoreCase("-quietMode")) {
                    quietMode = true;
                    pos++;
                    continue;
                }
                if (s.equalsIgnoreCase("-junitXML")) {
                    TestReporting.setInstance(new JUnitXMLReporting());
                }
                if (s.equalsIgnoreCase("-cleanMode")) {
                    cleanMode = true;
                    pos++;
                    continue;
                }
                System.out.println("Unrecognized argument: " + s);
                printUsage();
                System.exit(1);
                return;
            }
        } catch (Exception err) {
            err.printStackTrace();
            printUsage();
            return;
        }
        String[] tests;
        if (testCases == null || testCases.length == 0) {
            InputStream is = getClass().getResourceAsStream("/tests.dat");
            if (is == null) {
                System.err.println("Test data not found in the file, make sure the ant task was executed in full");
                System.exit(2);
                return;
            }
            DataInputStream di = new DataInputStream(is);
            int version = di.readInt();
            if (version > VERSION) {
                System.err.println("Tests were built with a new version of Codename One and can't be executed with this runner");
                System.exit(4);
                return;
            }
            tests = new String[di.readInt()];
            for (int iter = 0; iter < tests.length; iter++) {
                tests[iter] = di.readUTF();
            }
            di.close();
        } else {
            tests = testCases;
        }
        if (forceLandscape) {
            System.out.println("Forcing landscape");
            Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
            pref.putBoolean("Portrait", false);
            pref.sync();
        } else {
            if (forcePortrait) {
                System.out.println("Forcing portrait");
                Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
                pref.putBoolean("Portrait", true);
                pref.sync();
            }
        }
        System.out.println("Preparing to execute " + tests.length + " tests");
        String classPathStr = System.getProperty("java.class.path");
        if (System.getProperty("cn1.class.path") != null) {
            classPathStr += File.pathSeparator + System.getProperty("cn1.class.path");
        }
        StringTokenizer t = new StringTokenizer(classPathStr, File.pathSeparator);
        File[] files = new File[t.countTokens()];
        for (int iter = 0; iter < files.length; iter++) {
            files[iter] = new File(t.nextToken());
        }
        int passedTests = 0;
        int failedTests = 0;
        if (cleanMode) {
            for (String currentTestClass : tests) {
                ClassLoader ldr = new ClassPathLoader(files);
                Class c = Class.forName("com.codename1.impl.javase.TestExecuter", true, ldr);
                Method m = c.getDeclaredMethod("runTest", String.class, String.class, Boolean.TYPE);
                Boolean passed = (Boolean) m.invoke(null, mainClass, currentTestClass, quietMode);
                if (passed.booleanValue()) {
                    passedTests++;
                } else {
                    failedTests++;
                    if (stopOnFail) {
                        System.exit(100);
                        return;
                    }
                }
            }
        } else {
            ClassLoader ldr = new ClassPathLoader(files);
            Class c = Class.forName("com.codename1.impl.javase.TestExecuter", true, ldr);
            for (String currentTestClass : tests) {
                Method m = c.getDeclaredMethod("runTest", String.class, String.class, Boolean.TYPE);
                Boolean passed = (Boolean) m.invoke(null, mainClass, currentTestClass, quietMode);
                if (passed.booleanValue()) {
                    System.out.println(currentTestClass + " passed!");
                    passedTests++;
                } else {
                    System.out.println(currentTestClass + " failed!");
                    failedTests++;
                    if (stopOnFail) {
                        System.exit(100);
                        return;
                    }
                }
            }
        }
        TestReporting.getInstance().testExecutionFinished();
        int exitCode = 0;
        if (failedTests > 0) {
            System.out.println("Test execution finished, some failed tests occured. Passed: " + passedTests + " tests. Failed: " + failedTests + " tests.");
            exitCode = 100;
        } else {
            System.out.println("All tests passed. Total " + passedTests + " tests passed");
        }
        System.exit(exitCode);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(3);
    }
}
Also used : DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) Method(java.lang.reflect.Method) DataInputStream(java.io.DataInputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) StringTokenizer(java.util.StringTokenizer) JUnitXMLReporting(com.codename1.testing.JUnitXMLReporting) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 70 with com.codename1.rad.models

use of com.codename1.rad.models in project CodenameOne by codenameone.

the class ComponentSelector method setIcon.

/**
 * Sets the icon of all elements in this set to a material icon.  This will use
 * the foreground color of each label as the icon's foreground color.
 * @param materialIcon The icon charcode.
 * @param size The size of the icon (in mm)
 * @return Self for chaining
 * @see FontImage#createMaterial(char, com.codename1.ui.plaf.Style, float)
 */
public ComponentSelector setIcon(char materialIcon, float size) {
    for (Component c : this) {
        if (c instanceof Label) {
            Label l = (Label) c;
            Style style = new Style();
            Style cStyle = c.getUnselectedStyle();
            style.setBgTransparency(0);
            style.setFgColor(cStyle.getFgColor());
            l.setIcon(FontImage.createMaterial(materialIcon, style, size));
            if (c instanceof Button) {
                Button b = (Button) c;
                style = new Style();
                cStyle = c.getPressedStyle();
                style.setBgTransparency(0);
                style.setFgColor(cStyle.getFgColor());
                b.setPressedIcon(FontImage.createMaterial(materialIcon, style, size));
            }
        }
    }
    return this;
}
Also used : SpanButton(com.codename1.components.SpanButton) SpanLabel(com.codename1.components.SpanLabel) Style(com.codename1.ui.plaf.Style)

Aggregations

IOException (java.io.IOException)34 EncodedImage (com.codename1.ui.EncodedImage)28 ArrayList (java.util.ArrayList)27 Point (java.awt.Point)25 File (java.io.File)24 AnimationObject (com.codename1.ui.animations.AnimationObject)22 BufferedImage (java.awt.image.BufferedImage)22 Hashtable (java.util.Hashtable)19 Component (com.codename1.ui.Component)18 Form (com.codename1.ui.Form)18 Image (com.codename1.ui.Image)16 EditableResources (com.codename1.ui.util.EditableResources)16 FileInputStream (java.io.FileInputStream)16 Timeline (com.codename1.ui.animations.Timeline)15 BorderLayout (com.codename1.ui.layouts.BorderLayout)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)11 FileOutputStream (java.io.FileOutputStream)10 AttributedString (java.text.AttributedString)10 EditorFont (com.codename1.ui.EditorFont)9