use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class TestRecorder method visitComponents.
private void visitComponents(com.codename1.ui.Container cnt, ComponentVisitor v) {
v.visit(cnt);
int count = cnt.getComponentCount();
for (int iter = 0; iter < count; iter++) {
com.codename1.ui.Component current = cnt.getComponentAt(iter);
if (current instanceof com.codename1.ui.Container) {
visitComponents((com.codename1.ui.Container) current, v);
} else {
v.visit(current);
}
}
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class TestRecorder method generatePointerEventArguments.
private String generatePointerEventArguments(int x, int y) {
com.codename1.ui.Component cmp = getCodenameOneComponentAt(x, y);
if (cmp.getParent() instanceof Form) {
cmp = cmp.getParent();
}
String componentName = cmp.getName();
if (componentName == null) {
componentName = getPathToComponent(cmp);
} else {
componentName = "\"" + componentName + "\"";
}
float actualX = ((float) x - cmp.getAbsoluteX()) / ((float) cmp.getWidth());
float actualY = ((float) y - cmp.getAbsoluteY()) / ((float) cmp.getHeight());
return "(" + actualX + "f, " + actualY + "f, " + componentName + ");\n";
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class TestRecorder method bindListListener.
private void bindListListener(final com.codename1.ui.Component cmp, final ListModel m) {
if (cmp.getClientProperty("CN1$listenerBound") == null) {
cmp.putClientProperty("CN1$listenerBound", Boolean.TRUE);
m.addSelectionListener(new SelectionListener() {
public void selectionChanged(int oldSelected, int newSelected) {
generatedCode += " selectInList(" + getPathOrName(cmp) + ", " + newSelected + ");\n";
updateTestCode();
}
});
}
}
use of com.codename1.rad.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("-stopOnFail")) {
pos++;
stopOnFail = true;
continue;
}
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("-landscape")) {
forceLandscape = true;
pos++;
continue;
}
if (s.equalsIgnoreCase("-portrait")) {
forcePortrait = true;
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;
}
if (forceLandscape) {
System.out.println("Forcing landscape");
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.putBoolean("Portrait", false);
pref.sync();
} else {
if (forcePortrait) {
System.out.println("Forcing portrait");
Preferences pref = Preferences.userNodeForPackage(JavaSEPort.class);
pref.putBoolean("Portrait", true);
pref.sync();
}
}
System.out.println("Preparing to execute " + tests.length + " tests");
String classPathStr = System.getProperty("java.class.path");
if (System.getProperty("cn1.class.path") != null) {
classPathStr += File.pathSeparator + System.getProperty("cn1.class.path");
}
StringTokenizer t = new StringTokenizer(classPathStr, 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();
int exitCode = 0;
if (failedTests > 0) {
System.out.println("Test execution finished, some failed tests occured. Passed: " + passedTests + " tests. Failed: " + failedTests + " tests.");
exitCode = 100;
} else {
System.out.println("All tests passed. Total " + passedTests + " tests passed");
}
System.exit(exitCode);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(3);
}
}
use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class ComponentSelector method setIcon.
/**
* Sets the icon of all elements in this set to a material icon. This will use
* the foreground color of each label as the icon's foreground color.
* @param materialIcon The icon charcode.
* @param size The size of the icon (in mm)
* @return Self for chaining
* @see FontImage#createMaterial(char, com.codename1.ui.plaf.Style, float)
*/
public ComponentSelector setIcon(char materialIcon, float size) {
for (Component c : this) {
if (c instanceof Label) {
Label l = (Label) c;
Style style = new Style();
Style cStyle = c.getUnselectedStyle();
style.setBgTransparency(0);
style.setFgColor(cStyle.getFgColor());
l.setIcon(FontImage.createMaterial(materialIcon, style, size));
if (c instanceof Button) {
Button b = (Button) c;
style = new Style();
cStyle = c.getPressedStyle();
style.setBgTransparency(0);
style.setFgColor(cStyle.getFgColor());
b.setPressedIcon(FontImage.createMaterial(materialIcon, style, size));
}
}
}
return this;
}
Aggregations