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);
}
}
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;
}
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;
}
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];
}
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);
}
}
Aggregations