Search in sources :

Example 21 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class PerformanceMonitor method refreshFrameActionPerformed.

// GEN-LAST:event_runGCActionPerformed
private void refreshFrameActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_refreshFrameActionPerformed
    componentHierarchy.setModel(new ComponentTreeModel(Display.getInstance().getCurrent()));
    componentHierarchy.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            String s = value.toString();
            if (value instanceof Component) {
                s = ((Component) value).getUIID() + ": " + s;
            }
            // To change body of generated methods, choose Tools | Templates.
            return super.getTreeCellRendererComponent(tree, s, sel, expanded, leaf, row, hasFocus);
        }
    });
    Display.getInstance().callSerially(new Runnable() {

        public void run() {
            trackDrawing = true;
            Display.getInstance().getCurrent().repaint();
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    // data collected
                    trackDrawing = false;
                    renderedItems.setModel(createTableModel());
                }
            });
        }
    });
}
Also used : JTree(javax.swing.JTree) AttributedString(java.text.AttributedString) Component(com.codename1.ui.Component) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 22 with Data

use of com.codename1.ui.util.xml.Data 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("-testCases")) {
                    pos++;
                    testCases = argv[pos].split(",");
                    pos++;
                    continue;
                }
                if (s.equalsIgnoreCase("-skins")) {
                    pos++;
                    skins = argv[pos].split(",");
                    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;
        }
        System.out.println("Preparing to execute " + tests.length + " tests");
        StringTokenizer t = new StringTokenizer(System.getProperty("java.class.path"), 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();
        if (failedTests > 0) {
            System.out.println("Test execution finished, some failed tests occured. Passed: " + passedTests + " tests. Failed: " + failedTests + " tests.");
        } else {
            System.out.println("All tests passed. Total " + passedTests + " tests passed");
        }
        System.exit(0);
    } 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) StringTokenizer(java.util.StringTokenizer) JUnitXMLReporting(com.codename1.testing.JUnitXMLReporting) File(java.io.File)

Example 23 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class Image method createIndexed.

/**
 * Creates an indexed image with byte data this method may return a native indexed image rather than
 * an instance of the IndexedImage class
 *
 * @param width image width
 * @param height image height
 * @param palette the color palette to use with the byte data
 * @param data byte data containing palette offsets to map to ARGB colors
 * @deprecated try to avoid using indexed images explicitly
 */
public static Image createIndexed(int width, int height, int[] palette, byte[] data) {
    IndexedImage i = new IndexedImage(width, height, palette, data);
    CodenameOneImplementation impl = Display.impl;
    if (impl.isNativeIndexed()) {
        return new Image(impl.createNativeIndexed(i));
    }
    return i;
}
Also used : CodenameOneImplementation(com.codename1.impl.CodenameOneImplementation)

Example 24 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class SignIn method showGoogleUser.

private void showGoogleUser(String token) {
    ConnectionRequest req = new ConnectionRequest();
    req.addRequestHeader("Authorization", "Bearer " + token);
    req.setUrl("https://www.googleapis.com/plus/v1/people/me");
    req.setPost(false);
    InfiniteProgress ip = new InfiniteProgress();
    Dialog d = ip.showInifiniteBlocking();
    NetworkManager.getInstance().addToQueueAndWait(req);
    d.dispose();
    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("displayName");
    Map im = (Map) map.get("image");
    String url = (String) im.get("url");
    Form userForm = new UserForm(name, (EncodedImage) theme.getImage("user.png"), url);
    userForm.show();
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) InputStreamReader(java.io.InputStreamReader) InfiniteProgress(com.codename1.components.InfiniteProgress) ByteArrayInputStream(java.io.ByteArrayInputStream) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) JSONParser(com.codename1.io.JSONParser) IOException(java.io.IOException) Map(java.util.Map)

Example 25 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class SignIn method showFacebookUser.

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();
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) InputStreamReader(java.io.InputStreamReader) InfiniteProgress(com.codename1.components.InfiniteProgress) ByteArrayInputStream(java.io.ByteArrayInputStream) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) JSONParser(com.codename1.io.JSONParser) IOException(java.io.IOException) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)18 EncodedImage (com.codename1.ui.EncodedImage)12 Hashtable (java.util.Hashtable)12 Image (com.codename1.ui.Image)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)9 FileInputStream (java.io.FileInputStream)8 ActionEvent (com.codename1.ui.events.ActionEvent)7 ActionListener (com.codename1.ui.events.ActionListener)7 FileEncodedImage (com.codename1.components.FileEncodedImage)6 ConnectionRequest (com.codename1.io.ConnectionRequest)6 File (java.io.File)6 Intent (android.content.Intent)5 StorageImage (com.codename1.components.StorageImage)5 IntentResultListener (com.codename1.impl.android.IntentResultListener)5 EditableResources (com.codename1.ui.util.EditableResources)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 DataInputStream (java.io.DataInputStream)5 Vector (java.util.Vector)5 CodenameOneActivity (com.codename1.impl.android.CodenameOneActivity)4