use of com.codename1.tools.translator.bytecodes.Invoke in project CodenameOne by codenameone.
the class PickMIDlet method startMIDlet.
public static void startMIDlet(Hashtable themeHash) {
Accessor.setTheme(themeHash);
Preferences pref = Preferences.userNodeForPackage(ResourceEditorView.class);
String jar = pref.get("jar", null);
String midlet = pref.get("midlet", null);
if (jar != null && midlet != null) {
File jarFile = new File(jar);
if (jarFile.exists()) {
try {
URLClassLoader cl = URLClassLoader.newInstance(new URL[] { jarFile.toURI().toURL() }, PickMIDlet.class.getClassLoader());
StringTokenizer tokenizer = new StringTokenizer((String) midlet, " ,");
String s = tokenizer.nextToken();
while (tokenizer.hasMoreTokens()) {
s = tokenizer.nextToken();
}
Class cls = cl.loadClass(s);
JavaSEPortWithSVGSupport.setClassLoader(cls);
EditableResources.setResourcesClassLoader(cls);
Accessor.setTheme(themeHash);
Object app = cls.newInstance();
JarFile zip = new JarFile(jarFile);
Attributes m = zip.getManifest().getMainAttributes();
cls.getDeclaredMethod("init", new Class[] { Object.class }).invoke(app, new Object[] { null });
cls.getDeclaredMethod("start", new Class[0]).invoke(app, new Object[0]);
// there might be an ongoing transition and the form.show() method is serial
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (Display.getInstance().getCurrent() != null) {
Display.getInstance().getCurrent().refreshTheme();
return;
} else {
new Thread() {
public void run() {
try {
sleep(100);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
Display.getInstance().callSerially(this);
}
}.start();
}
}
});
return;
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
JavaSEPortWithSVGSupport.setClassLoader(PickMIDlet.class);
LiveDemo l = new LiveDemo();
l.init(null);
l.start();
Accessor.setTheme(themeHash);
Form current = Display.getInstance().getCurrent();
if (current != null) {
current.refreshTheme();
}
}
use of com.codename1.tools.translator.bytecodes.Invoke in project CodenameOne by codenameone.
the class Container method isObscuredByChildren.
/**
* Invoked internally to indicate if child components are hiding this container
* thus removing the need to invoke its own paint methods
* @return true if child components are obscuring this component
*/
boolean isObscuredByChildren() {
if (!blockOverdraw) {
return false;
}
if (!getLayout().obscuresPotential(this)) {
return false;
}
Style s = getStyle();
if (s.getPaddingTop() != 0 || s.getPaddingLeftNoRTL() != 0 || s.getPaddingRightNoRTL() != 0 || s.getPaddingBottom() != 0) {
return false;
}
int size = components.size();
for (int iter = 0; iter < size; iter++) {
Component cmp = components.get(iter);
s = cmp.getStyle();
if (cmp.getWidth() == 0 || cmp.getHeight() == 0) {
continue;
}
// need to think of a better way, this means we invoke the same logic recurisvely again and again by a factor of depth. Not good...
if (cmp instanceof Container) {
if (!((Container) cmp).getLayout().obscuresPotential(this)) {
return false;
}
if (s.getOpacity() != 0xff || s.getMarginTop() != 0 || s.getMarginLeftNoRTL() != 0 || s.getMarginRightNoRTL() != 0 || s.getMarginBottom() != 0) {
return false;
}
if ((s.getBgTransparency() & 0xff) != 0xff && !((Container) cmp).isObscuredByChildren()) {
return false;
}
} else {
if ((s.getBgTransparency() & 0xff) != 0xff || s.getOpacity() != 0xff || s.getMarginTop() != 0 || s.getMarginLeftNoRTL() != 0 || s.getMarginRightNoRTL() != 0 || s.getMarginBottom() != 0) {
return false;
}
}
}
return true;
}
use of com.codename1.tools.translator.bytecodes.Invoke in project CodenameOne by codenameone.
the class Display method init.
/**
* This is the INTERNAL Display initialization method, it will be removed in future versions of the API.
* This method must be called before any Form is shown
*
* @param m platform specific object used by the implementation
* @deprecated this method is invoked internally do not invoke it!
*/
public static void init(Object m) {
if (!INSTANCE.codenameOneRunning) {
INSTANCE.codenameOneRunning = true;
INSTANCE.displayInitTime = System.currentTimeMillis();
// restore menu state from previous run if exists
int commandBehaviour = COMMAND_BEHAVIOR_DEFAULT;
if (INSTANCE.impl != null) {
commandBehaviour = INSTANCE.impl.getCommandBehavior();
}
INSTANCE.impl = (CodenameOneImplementation) ImplementationFactory.getInstance().createImplementation();
INSTANCE.impl.setDisplayLock(lock);
INSTANCE.impl.initImpl(m);
INSTANCE.codenameOneGraphics = new Graphics(INSTANCE.impl.getNativeGraphics());
INSTANCE.codenameOneGraphics.paintPeersBehind = INSTANCE.impl.paintNativePeersBehind();
INSTANCE.impl.setCodenameOneGraphics(INSTANCE.codenameOneGraphics);
// only enable but never disable the third softbutton
if (INSTANCE.impl.isThirdSoftButton()) {
INSTANCE.thirdSoftButton = true;
}
if (INSTANCE.impl.getSoftkeyCount() > 0) {
MenuBar.leftSK = INSTANCE.impl.getSoftkeyCode(0)[0];
if (INSTANCE.impl.getSoftkeyCount() > 1) {
MenuBar.rightSK = INSTANCE.impl.getSoftkeyCode(1)[0];
if (INSTANCE.impl.getSoftkeyCode(1).length > 1) {
MenuBar.rightSK2 = INSTANCE.impl.getSoftkeyCode(1)[1];
}
}
}
MenuBar.backSK = INSTANCE.impl.getBackKeyCode();
MenuBar.backspaceSK = INSTANCE.impl.getBackspaceKeyCode();
MenuBar.clearSK = INSTANCE.impl.getClearKeyCode();
INSTANCE.PATHLENGTH = INSTANCE.impl.getDragPathLength();
INSTANCE.dragPathX = new float[INSTANCE.PATHLENGTH];
INSTANCE.dragPathY = new float[INSTANCE.PATHLENGTH];
INSTANCE.dragPathTime = new long[INSTANCE.PATHLENGTH];
com.codename1.util.StringUtil.setImplementation(INSTANCE.impl);
com.codename1.io.Util.setImplementation(INSTANCE.impl);
// generally its probably a bug but we can let it slide...
if (INSTANCE.edt == null) {
INSTANCE.touchScreen = INSTANCE.impl.isTouchDevice();
// initialize the Codename One EDT which from now on will take all responsibility
// for the event delivery.
INSTANCE.edt = new CodenameOneThread(new RunnableWrapper(null, 3), "EDT");
INSTANCE.impl.setThreadPriority(INSTANCE.edt, INSTANCE.impl.getEDTThreadPriority());
INSTANCE.edt.start();
}
INSTANCE.impl.postInit();
INSTANCE.setCommandBehavior(commandBehaviour);
} else {
INSTANCE.impl.confirmControlView();
}
}
use of com.codename1.tools.translator.bytecodes.Invoke in project CodenameOne by codenameone.
the class InfiniteScrollAdapter method addMoreComponents.
/**
* Invoke this method to add additional components to the container, if you use
* addComponent/removeComponent you will get undefined behavior.
* @param components the components to add
* @param areThereMore whether additional components exist
*/
public void addMoreComponents(Component[] components, boolean areThereMore) {
infiniteContainer.removeComponent(ip);
infiniteContainer.removeComponent(endMarker);
for (Component c : components) {
c.setY(infiniteContainer.getHeight());
infiniteContainer.addComponent(c);
}
if (componentLimit > 0) {
int diff = infiniteContainer.getComponentCount() - componentLimit;
while (diff > 0) {
infiniteContainer.removeComponent(infiniteContainer.getComponentAt(0));
diff--;
}
}
infiniteContainer.revalidate();
if (areThereMore) {
// if this is animated we get redundant calls to reached end
infiniteContainer.addComponent(endMarker);
infiniteContainer.revalidate();
}
}
use of com.codename1.tools.translator.bytecodes.Invoke in project CodenameOne by codenameone.
the class JavaSEPort method init.
/**
* @inheritDoc
*/
public void init(Object m) {
inInit = true;
File updater = new File(System.getProperty("user.home") + File.separator + ".codenameone" + File.separator + "UpdateCodenameOne.jar");
if (!updater.exists()) {
System.out.println("******************************************************************************");
System.out.println("* It seems that you are using an old plugin version please upate to the latest plugin and invoke Codename One -> Codename One Settings -> Basic -> Update Client Libs");
System.out.println("******************************************************************************");
}
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
boolean desktopSkin = pref.getBoolean("desktopSkin", false);
if (desktopSkin && m == null) {
Toolkit tk = Toolkit.getDefaultToolkit();
setDefaultPixelMilliRatio(tk.getScreenResolution() / 25.4 * getRetinaScale());
pixelMilliRatio = getDefaultPixelMilliRatio();
JPanel panel = new javax.swing.JPanel();
panel.setLayout(new BorderLayout());
JPanel bottom = new javax.swing.JPanel();
panel.setOpaque(false);
bottom.setLayout(new FlowLayout(FlowLayout.RIGHT));
widthLabel = new JLabel("Width: ");
heightLabel = new JLabel(" Height: ");
bottom.add(widthLabel);
bottom.add(heightLabel);
panel.add(bottom, BorderLayout.SOUTH);
JFrame frame = new JFrame();
// frame.addWindowListener(new WindowListener() {
//
// });
frame.setLayout(new BorderLayout());
frame.add(panel, BorderLayout.CENTER);
frame.setSize(new Dimension(300, 400));
m = panel;
window = frame;
}
setInvokePointerHover(desktopSkin || invokePointerHover);
// this is essential for push and other things to work in the simulator
Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
String user = p.get("user", null);
if (user != null) {
Display d = Display.getInstance();
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);
}
}
try {
Class.forName("javafx.embed.swing.JFXPanel");
Platform.setImplicitExit(false);
fxExists = true;
} catch (Throwable ex) {
}
String hide = System.getProperty("hideMenu", "false");
if (hide != null && hide.equals("true")) {
showMenu = false;
}
URLConnection.setDefaultAllowUserInteraction(true);
HttpURLConnection.setFollowRedirects(false);
if (!blockMonitors && pref.getBoolean("NetworkMonitor", false)) {
showNetworkMonitor();
}
if (!blockMonitors && pref.getBoolean("PushSimulator", false)) {
pushSimulation = new PushSimulator();
pushSimulation.setVisible(true);
}
if (!blockMonitors && pref.getBoolean("PerformanceMonitor", false)) {
showPerformanceMonitor();
}
if (defaultInitTarget != null && m == null) {
m = defaultInitTarget;
}
if (canvas.getParent() != null) {
canvas.getParent().remove(canvas);
}
if (m != null && m instanceof java.awt.Container) {
java.awt.Container cnt = (java.awt.Container) m;
if (cnt.getLayout() instanceof java.awt.BorderLayout) {
cnt.add(java.awt.BorderLayout.CENTER, canvas);
} else {
cnt.add(canvas);
}
} else {
window = new JFrame();
window.setLayout(new java.awt.BorderLayout());
hSelector = new JScrollBar(Scrollbar.HORIZONTAL);
vSelector = new JScrollBar(Scrollbar.VERTICAL);
hSelector.addAdjustmentListener(canvas);
vSelector.addAdjustmentListener(canvas);
scrollableSkin = pref.getBoolean("Scrollable", true);
if (scrollableSkin) {
window.add(java.awt.BorderLayout.SOUTH, hSelector);
window.add(java.awt.BorderLayout.EAST, vSelector);
}
window.add(java.awt.BorderLayout.CENTER, canvas);
}
if (window != null) {
java.awt.Image large = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/application64.png"));
java.awt.Image small = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/application48.png"));
try {
// setIconImages is only available in JDK 1.6
window.setIconImages(Arrays.asList(new java.awt.Image[] { large, small }));
} catch (Throwable err) {
window.setIconImage(small);
}
window.addWindowListener(new WindowListener() {
public void windowOpened(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
Display.getInstance().exitApplication();
}
public void windowClosed(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
});
window.setLocationByPlatform(true);
android6PermissionsFlag = pref.getBoolean("Android6Permissions", false);
alwaysOnTop = pref.getBoolean("AlwaysOnTop", false);
window.setAlwaysOnTop(alwaysOnTop);
String reset = System.getProperty("resetSkins");
if (reset != null && reset.equals("true")) {
System.setProperty("resetSkins", "");
pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.put("skins", DEFAULT_SKINS);
}
if (hasSkins()) {
if (m == null) {
String f = System.getProperty("skin");
if (f != null) {
loadSkinFile(f, window);
} else {
String d = System.getProperty("dskin");
f = pref.get("skin", d);
loadSkinFile(f, window);
}
} else {
try {
installMenu(window, true);
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
Resources.setRuntimeMultiImageEnabled(true);
window.setUndecorated(true);
window.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
window.pack();
if (getSkin() != null && !scrollableSkin) {
float w1 = ((float) canvas.getWidth() * (float) retinaScale) / ((float) getSkin().getWidth());
float h1 = ((float) canvas.getHeight() * (float) retinaScale) / ((float) getSkin().getHeight());
zoomLevel = Math.min(h1, w1);
}
portrait = pref.getBoolean("Portrait", true);
if (!portrait && getSkin() != null) {
canvas.setForcedSize(new java.awt.Dimension((int) (getSkin().getWidth() / retinaScale), (int) (getSkin().getHeight() / retinaScale)));
window.setSize(new java.awt.Dimension((int) (getSkin().getWidth() / retinaScale), (int) (getSkin().getHeight() / retinaScale)));
}
window.setVisible(true);
}
if (useNativeInput) {
Display.getInstance().setDefaultVirtualKeyboard(null);
}
float factor = ((float) getDisplayHeight()) / 480.0f;
if (factor > 0 && autoAdjustFontSize && getSkin() != null) {
// set a reasonable default font size
setFontSize((int) (15.0f * factor), (int) (11.0f * factor), (int) (19.0f * factor));
}
if (m instanceof Runnable) {
Display.getInstance().callSerially((Runnable) m);
}
inInit = false;
}
Aggregations