Search in sources :

Example 1 with PeerComponent

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

the class CodenameOneImplementation method setBrowserPageInHierarchy.

/**
 * Sets a relative URL from the html hierarchy
 *
 * @param browserPeer the peer component
 * @param url the url relative to the HTML directory
 */
public void setBrowserPageInHierarchy(PeerComponent browserPeer, String url) throws IOException {
    installTar();
    FileSystemStorage fs = FileSystemStorage.getInstance();
    String tardir = fs.getAppHomePath() + "cn1html";
    if (tardir.startsWith("/")) {
        tardir = "file://" + tardir;
    }
    if (url.startsWith("/")) {
        setBrowserURL(browserPeer, tardir + url);
    } else {
        setBrowserURL(browserPeer, tardir + "/" + url);
    }
}
Also used : FileSystemStorage(com.codename1.io.FileSystemStorage)

Example 2 with PeerComponent

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

the class BlackBerryCanvas method paint.

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;
}
Also used : EditField(net.rim.device.api.ui.component.EditField) Field(net.rim.device.api.ui.Field) PeerComponent(com.codename1.ui.PeerComponent) EditField(net.rim.device.api.ui.component.EditField) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Example 3 with PeerComponent

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

the class IOSImplementation method createBrowserComponent.

/*class RunnableCleanup implements Runnable {
        long[] peer;
        Runnable onCompletion;
        public void run() {
            if(onCompletion != null) {
                onCompletion.run();
            }
            if(peer != null && peer[0] != 0) {
                cleanupAudio(peer);
            }
        }
    }
    
    @Override
    public Object createAudio(String uri, Runnable onCompletion) throws IOException {
        RunnableCleanup c = new RunnableCleanup();
        long[] p = new long[] {nativeInstance.createAudio(uri, c)};
        c.peer = p;
        c.onCompletion = onCompletion;
        return p;
    }

    
    @Override
    public Object createAudio(InputStream stream, String mimeType, Runnable onCompletion) throws IOException {
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        byte[] buffer = new byte[8192];
        int size = stream.read(buffer);
        while(size > -1) {
            bo.write(buffer, 0, size);
            size = stream.read(buffer);
        }
        bo.close();
        stream.close();
        RunnableCleanup c = new RunnableCleanup();
        long[] p = new long[] {nativeInstance.createAudio(bo.toByteArray(), c)};
        c.peer = p;
        c.onCompletion = onCompletion;
        return p;
    }*/
@Override
public PeerComponent createBrowserComponent(Object browserComponent) {
    long browserPeer = nativeInstance.createBrowserComponent(browserComponent);
    PeerComponent pc = createNativePeer(new long[] { browserPeer });
    nativeInstance.releasePeer(browserPeer);
    return pc;
}
Also used : PeerComponent(com.codename1.ui.PeerComponent)

Example 4 with PeerComponent

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

the class JavaSEPort method createBrowserComponent.

public PeerComponent createBrowserComponent(final Object parent) {
    java.awt.Container cnt = canvas.getParent();
    while (!(cnt instanceof JFrame)) {
        cnt = cnt.getParent();
        if (cnt == null) {
            return null;
        }
    }
    final java.awt.Container c = cnt;
    final Exception[] err = new Exception[1];
    final javafx.embed.swing.JFXPanel webContainer = new CN1JFXPanel();
    final SEBrowserComponent[] bc = new SEBrowserComponent[1];
    Platform.runLater(new Runnable() {

        @Override
        public void run() {
            StackPane root = new StackPane();
            final WebView webView = new WebView();
            root.getChildren().add(webView);
            webContainer.setScene(new Scene(root));
            // now wait for the Swing side to finish initializing f'ing JavaFX is so broken its unbeliveable
            final SEBrowserComponent bcc = new SEBrowserComponent(JavaSEPort.this, ((JPanel) canvas.getParent()), webContainer, webView, (BrowserComponent) parent, hSelector, vSelector);
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    bc[0] = bcc;
                    synchronized (bc) {
                        bc.notify();
                    }
                }
            });
        }
    });
    Display.getInstance().invokeAndBlock(new Runnable() {

        @Override
        public void run() {
            synchronized (bc) {
                while (bc[0] == null && err[0] == null) {
                    try {
                        bc.wait(20);
                    } catch (InterruptedException ex) {
                    }
                }
            }
        }
    });
    return bc[0];
}
Also used : Scene(javafx.scene.Scene) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) EOFException(java.io.EOFException) FontFormatException(java.awt.FontFormatException) javax.swing(javax.swing) JFrame(javax.swing.JFrame) BrowserComponent(com.codename1.ui.BrowserComponent) WebView(javafx.scene.web.WebView) StackPane(javafx.scene.layout.StackPane) java.awt(java.awt)

Example 5 with PeerComponent

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

the class CodenameOneImplementation method setBrowserURL.

/**
 * Sets the page URL, jar: URL's must be supported by the implementation
 * @param browserPeer browser instance
 * @param url  the URL
 */
public void setBrowserURL(PeerComponent browserPeer, String url) {
    // load from jar:// URL's
    try {
        InputStream i = Display.getInstance().getResourceAsStream(getClass(), url.substring(6));
        if (i == null) {
            System.out.println("Local resource not found: " + url);
            return;
        }
        byte[] buffer = new byte[4096];
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        int size = i.read(buffer);
        while (size > -1) {
            bo.write(buffer, 0, size);
            size = i.read(buffer);
        }
        i.close();
        bo.close();
        String htmlText = new String(bo.toByteArray(), "UTF-8");
        String baseUrl = url.substring(0, url.lastIndexOf('/'));
        setBrowserPage(browserPeer, htmlText, baseUrl);
        return;
    } catch (IOException ex) {
        Log.e(ex);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) TarInputStream(com.codename1.io.tar.TarInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

PeerComponent (com.codename1.ui.PeerComponent)5 Component (com.codename1.ui.Component)3 BrowserComponent (com.codename1.ui.BrowserComponent)2 Form (com.codename1.ui.Form)2 TextArea (com.codename1.ui.TextArea)2 IOException (java.io.IOException)2 Field (net.rim.device.api.ui.Field)2 FileSystemStorage (com.codename1.io.FileSystemStorage)1 TarInputStream (com.codename1.io.tar.TarInputStream)1 ActionEvent (com.codename1.ui.events.ActionEvent)1 Dimension (com.codename1.ui.geom.Dimension)1 java.awt (java.awt)1 FontFormatException (java.awt.FontFormatException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 InputStream (java.io.InputStream)1 SQLException (java.sql.SQLException)1 ParseException (java.text.ParseException)1