use of com.codename1.ui in project CodenameOne by codenameone.
the class JavaSEPort method registerPush.
@Override
public void registerPush(Hashtable meta, boolean noFallback) {
Preferences p = Preferences.userNodeForPackage(com.codename1.ui.Component.class);
String user = p.get("user", null);
Display d = Display.getInstance();
if (user == null) {
JPanel pnl = new JPanel();
JTextField tf = new JTextField(20);
pnl.add(new JLabel("E-Mail For Push"));
pnl.add(tf);
JOptionPane.showMessageDialog(canvas, pnl, "Email For Push", JOptionPane.PLAIN_MESSAGE);
user = tf.getText();
p.put("user", user);
}
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);
}
super.registerPush(meta, noFallback);
if (pushSimulation != null && pushSimulation.isVisible()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(window, "registerForPush invoked. Use the buttons in the push simulator to send the appropriate callback to your app", "Push Registration", JOptionPane.INFORMATION_MESSAGE);
}
});
}
}
use of com.codename1.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.ui in project CodenameOne by codenameone.
the class TestRecorder method eventPointerReleased.
void eventPointerReleased(int x, int y) {
if (isRecording()) {
com.codename1.ui.Component cmp = Display.getInstance().getCurrent().getComponentAt(x, y);
if (isListComponent(cmp)) {
return;
}
if (dragged) {
if (dragToScroll.isSelected()) {
com.codename1.ui.Component scrollTo;
if (y > pointerPressedY) {
scrollTo = findLowestVisibleComponent();
} else {
scrollTo = findHighestVisibleComponent();
}
if (scrollTo != null && scrollTo != Display.getInstance().getCurrent() && scrollTo != Display.getInstance().getCurrent().getContentPane()) {
String name = scrollTo.getName();
if (name != null) {
generatedCode += " ensureVisible(\"" + name + "\");\n";
} else {
String pp = getPathToComponent(scrollTo);
if (pp == null) {
return;
}
generatedCode += " ensureVisible(" + pp + ");\n";
}
updateTestCode();
}
} else {
addWaitStatement();
generatedCode += " pointerRelease" + generatePointerEventArguments(x, y);
updateTestCode();
}
} else {
if (isToolbarComponent(cmp)) {
if (cmp instanceof com.codename1.ui.Button) {
Command cmd = ((com.codename1.ui.Button) cmp).getCommand();
if (cmd != null) {
int offset = 0;
Command[] commands = TestUtils.getToolbarCommands();
for (Command c : commands) {
if (c == cmd) {
generatedCode += " assertEqual(getToolbarCommands().length, " + commands.length + ");\n";
generatedCode += " executeToolbarCommandAtOffset(" + offset + ");\n";
updateTestCode();
return;
}
offset++;
}
} else {
if (cmp.getUIID().equals("MenuButton")) {
// side menu button
generatedCode += " showSidemenu();\n";
updateTestCode();
return;
}
}
}
}
if (cmp instanceof com.codename1.ui.Button) {
com.codename1.ui.Button btn = (com.codename1.ui.Button) cmp;
// special case for back command on iOS
if (btn.getCommand() != null && btn.getCommand() == Display.getInstance().getCurrent().getBackCommand()) {
generatedCode += " goBack();\n";
} else {
if (btn.getName() != null && btn.getName().length() > 0) {
generatedCode += " clickButtonByName(\"" + btn.getName() + "\");\n";
} else {
if (btn.getText() != null && btn.getText().length() > 0) {
generatedCode += " clickButtonByLabel(\"" + btn.getText() + "\");\n";
} else {
String pp = getPathToComponent(cmp);
if (pp == null || pp.equals("(String)null")) {
return;
}
generatedCode += " clickButtonByPath(" + pp + ");\n";
}
}
}
updateTestCode();
return;
}
if (cmp instanceof com.codename1.ui.TextArea) {
// ignore this, its probably initiating edit which we will capture soon
return;
}
generatedCode += " pointerPress" + generatePointerEventArguments(pointerPressedX, pointerPressedY);
addWaitStatement();
generatedCode += " pointerRelease" + generatePointerEventArguments(x, y);
updateTestCode();
}
}
}
use of com.codename1.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.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);
}
}
}
Aggregations