use of com.codename1.ui 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);
}
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class JavaSEPort method getTransform.
@Override
public void getTransform(Object graphics, Transform transform) {
checkEDT();
com.codename1.ui.Transform t = getNativeScreenGraphicsTransform(graphics);
if (t == null) {
transform.setIdentity();
} else {
transform.setTransform(t);
}
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class JavaSEPort method editStringLegacy.
public void editStringLegacy(final Component cmp, int maxSize, int constraint, String text, int keyCode) {
checkEDT();
java.awt.Component awtTf;
if (cmp instanceof com.codename1.ui.TextField) {
java.awt.TextField t = new java.awt.TextField();
awtTf = t;
t.setSelectionEnd(0);
t.setSelectionStart(0);
} else {
java.awt.TextArea t = new java.awt.TextArea("", 0, 0, java.awt.TextArea.SCROLLBARS_NONE);
;
awtTf = t;
t.setSelectionEnd(0);
t.setSelectionStart(0);
}
final java.awt.Component tf = awtTf;
if (keyCode > 0) {
text += ((char) keyCode);
setText(tf, text);
setCaretPosition(tf, text.length());
((com.codename1.ui.TextField) cmp).setText(getText(tf));
} else {
setText(tf, text);
}
canvas.add(tf);
if (getSkin() != null) {
tf.setBounds((int) ((cmp.getAbsoluteX() + getScreenCoordinates().x + canvas.x) * zoomLevel), (int) ((cmp.getAbsoluteY() + getScreenCoordinates().y + canvas.y) * zoomLevel), (int) (cmp.getWidth() * zoomLevel), (int) (cmp.getHeight() * zoomLevel));
java.awt.Font f = font(cmp.getStyle().getFont().getNativeFont());
tf.setFont(f.deriveFont(f.getSize2D() * zoomLevel));
} else {
tf.setBounds(cmp.getAbsoluteX(), cmp.getAbsoluteY(), cmp.getWidth(), cmp.getHeight());
tf.setFont(font(cmp.getStyle().getFont().getNativeFont()));
}
setCaretPosition(tf, getText(tf).length());
tf.requestFocus();
class Listener implements ActionListener, FocusListener, KeyListener, TextListener, Runnable {
public synchronized void run() {
while (tf.getParent() != null) {
try {
wait(20);
} catch (InterruptedException ex) {
}
}
}
public void actionPerformed(ActionEvent e) {
String txt = getText(tf);
if (testRecorder != null) {
testRecorder.editTextFieldCompleted(cmp, txt);
}
Display.getInstance().onEditingComplete(cmp, txt);
if (tf instanceof java.awt.TextField) {
((java.awt.TextField) tf).removeActionListener(this);
}
((TextComponent) tf).removeTextListener(this);
tf.removeFocusListener(this);
canvas.remove(tf);
synchronized (this) {
notify();
}
canvas.repaint();
}
public void focusGained(FocusEvent e) {
setCaretPosition(tf, getText(tf).length());
}
public void focusLost(FocusEvent e) {
actionPerformed(null);
}
public void keyTyped(KeyEvent e) {
String t = getText(tf);
if (t.length() >= ((TextArea) cmp).getMaxSize()) {
e.consume();
}
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
if (tf instanceof java.awt.TextField) {
actionPerformed(null);
} else {
if (getCaretPosition(tf) >= getText(tf).length() - 1) {
actionPerformed(null);
}
}
return;
}
if (e.getKeyCode() == KeyEvent.VK_UP) {
if (tf instanceof java.awt.TextField) {
actionPerformed(null);
} else {
if (getCaretPosition(tf) <= 2) {
actionPerformed(null);
}
}
return;
}
}
public void textValueChanged(TextEvent e) {
if (cmp instanceof com.codename1.ui.TextField) {
((com.codename1.ui.TextField) cmp).setText(getText(tf));
}
}
}
;
final Listener l = new Listener();
if (tf instanceof java.awt.TextField) {
((java.awt.TextField) tf).addActionListener(l);
}
((TextComponent) tf).addTextListener(l);
tf.addKeyListener(l);
tf.addFocusListener(l);
if (simulateAndroidKeyboard) {
java.util.Timer t = new java.util.Timer();
TimerTask tt = new TimerTask() {
@Override
public void run() {
if (!Display.getInstance().isEdt()) {
Display.getInstance().callSerially(this);
return;
}
if (tf.getParent() != null) {
final int height = getScreenCoordinates().height;
JavaSEPort.this.sizeChanged(getScreenCoordinates().width, height / 2);
new UITimer(new Runnable() {
public void run() {
if (tf.getParent() != null) {
new UITimer(this).schedule(100, false, Display.getInstance().getCurrent());
} else {
JavaSEPort.this.sizeChanged(getScreenCoordinates().width, height);
}
}
}).schedule(100, false, Display.getInstance().getCurrent());
}
}
};
t.schedule(tt, 300);
}
Display.getInstance().invokeAndBlock(l);
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class GameCanvasImplementation method capturePhoto.
public void capturePhoto(ActionListener response) {
captureResponse = response;
final Form current = Display.getInstance().getCurrent();
final Form cam = new Form();
cam.setScrollable(false);
cam.setTransitionInAnimator(CommonTransitions.createEmpty());
cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
cam.setLayout(new BorderLayout());
cam.show();
String platform = System.getProperty("microedition.platform");
MMAPIPlayer p = null;
if (platform != null && platform.indexOf("Nokia") >= 0) {
try {
p = MMAPIPlayer.createPlayer("capture://image", null);
} catch (Throwable e) {
// Ignore all exceptions for image capture, continue with video capture...
}
}
if (p == null) {
try {
p = MMAPIPlayer.createPlayer("capture://video", null);
} catch (Exception e) {
// The Nokia 2630 throws this if image/video capture is not supported
throw new RuntimeException("Image/video capture not supported on this phone");
}
}
final MMAPIPlayer player = p;
MIDPVideoComponent video = new MIDPVideoComponent(player, canvas);
video.play();
video.setVisible(true);
cam.addCommand(new com.codename1.ui.Command("Cancel") {
public void actionPerformed(ActionEvent evt) {
if (player != null) {
player.cleanup();
}
captureResponse.actionPerformed(null);
current.showBack();
}
});
final ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
cam.removeAll();
VideoControl cnt = (VideoControl) player.nativePlayer.getControl("VideoControl");
byte[] pic = cnt.getSnapshot("encoding=jpeg&width=" + current.getWidth() + "&height=" + current.getHeight());
String imagePath = getOutputMediaFile() + ".jpg";
OutputStream out = null;
try {
if (pic != null) {
out = FileSystemStorage.getInstance().openOutputStream(imagePath);
out.write(pic);
}
} catch (Throwable ex) {
ex.printStackTrace();
System.out.println("failed to store picture to " + imagePath);
} finally {
try {
if (out != null) {
out.close();
}
player.cleanup();
} catch (Throwable ex) {
ex.printStackTrace();
}
}
captureResponse.actionPerformed(new ActionEvent(imagePath));
current.showBack();
} catch (Throwable ex) {
ex.printStackTrace();
System.out.println("failed to take picture");
current.showBack();
}
}
};
cam.addGameKeyListener(Display.GAME_FIRE, l);
Container cn = new Container(new BorderLayout()) {
public void pointerReleased(int x, int y) {
l.actionPerformed(null);
}
};
cn.setFocusable(true);
cn.addComponent(BorderLayout.CENTER, video);
cam.addComponent(BorderLayout.CENTER, cn);
cam.revalidate();
// cam.addPointerReleasedListener(l);
}
use of com.codename1.ui in project CodenameOne by codenameone.
the class BlackBerryOS5Implementation method openOutputStream.
/**
* (non-Javadoc)
*
* @see
* com.codename1.impl.blackberry.BlackBerryImplementation#openOutputStream(java.lang.Object)
*/
public OutputStream openOutputStream(Object connection) throws IOException {
if (connection instanceof String) {
return super.openOutputStream(connection);
}
OutputStream os = ((HttpConnection) connection).openOutputStream();
// getSoftwareVersion() not available in legacy port,introduced at API 4.3.0
int majorVersion = DeviceInfo.getSoftwareVersion().charAt(0) - '0';
// in version 7, BBOS started supporting HTTP 1.1, so facade not required.
if (majorVersion < 7) {
os = new BlackBerryOutputStream(os);
}
return new BufferedOutputStream(os, ((HttpConnection) connection).getURL());
}
Aggregations