use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class UIManager method initFirstTheme.
/**
* This is a shorthand notation for boilerplate code for initializing the first theme in the given resource file
* and catching/doing nothing with the IOException since this would be invoked too early in the program
* where we would be out of options if something like that happens. Effectively this is the same as writing:
* <pre>
* try {
* theme = Resources.openLayered(resourceFile);
* UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
* } catch(IOException e){
* e.printStackTrace();
* }
* </pre>
* @param resourceFile the name of the resource file starting with / and without the res extension
* @return the resource file or null in case of a failure
*/
public static Resources initFirstTheme(String resourceFile) {
try {
Resources theme = Resources.openLayered(resourceFile);
UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
Resources.setGlobalResources(theme);
return theme;
} catch (IOException e) {
Log.e(e);
}
return null;
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class BorderLayout method addLayoutComponent.
/**
* {@inheritDoc}
*/
public void addLayoutComponent(Object name, Component comp, Container c) {
// helper check for a common mistake...
if (name == null) {
throw new IllegalArgumentException("Cannot add component to BorderLayout Container without constraint parameter");
}
// allows us to work with Component constraints too which makes some code simpler
if (name instanceof Integer) {
switch(((Integer) name).intValue()) {
case Component.TOP:
name = NORTH;
break;
case Component.BOTTOM:
name = SOUTH;
break;
case Component.LEFT:
name = WEST;
break;
case Component.RIGHT:
name = EAST;
break;
case Component.CENTER:
name = CENTER;
break;
default:
throw new IllegalArgumentException("BorderLayout Container expects one of the constraints BorderLayout.NORTH/SOUTH/EAST/WEST/CENTER");
}
}
Component previous = null;
/* Assign the component to one of the known regions of the layout.
*/
if (CENTER.equals(name)) {
previous = portraitCenter;
portraitCenter = comp;
} else if (NORTH.equals(name)) {
previous = portraitNorth;
portraitNorth = comp;
} else if (SOUTH.equals(name)) {
previous = portraitSouth;
portraitSouth = comp;
} else if (EAST.equals(name)) {
previous = portraitEast;
portraitEast = comp;
} else if (WEST.equals(name)) {
previous = portraitWest;
portraitWest = comp;
} else if (OVERLAY.equals(name)) {
previous = overlay;
overlay = comp;
} else {
throw new IllegalArgumentException("cannot add to layout: unknown constraint: " + name);
}
if (previous != null && previous != comp) {
c.removeComponent(previous);
}
}
use of com.codename1.rad.models.Property.Name in project CodenameOne by codenameone.
the class ListFilesTest method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", new BorderLayout());
Button add = new Button("Add Directory");
add.addActionListener(e -> {
callSerially(() -> {
Command ok = new Command("OK");
Command cancel = new Command("Cancel");
TextField fileName = new TextField("", "File Path", 20, TextField.NON_PREDICTIVE);
if (ok == Dialog.show("File Path", fileName, new Command[] { ok, cancel })) {
File f = new File(fileName.getText());
if (!f.mkdir()) {
ToastBar.showErrorMessage("Failed to create directory");
}
}
});
});
Button rename = new Button("Rename File");
rename.addActionListener(e -> {
callSerially(() -> {
Command ok = new Command("OK");
Command cancel = new Command("Cancel");
TextField fileName = new TextField("", "File Path", 20, TextField.NON_PREDICTIVE);
TextField newName = new TextField("", "New Name", 20, TextField.NON_PREDICTIVE);
if (ok == Dialog.show("File Path", BoxLayout.encloseY(fileName, newName), new Command[] { ok, cancel })) {
File f = new File(fileName.getText());
FileSystemStorage fs = FileSystemStorage.getInstance();
fs.rename(f.getPath(), newName.getText());
}
});
});
TextArea listing = new TextArea();
Button refresh = new Button("Refresh");
refresh.addActionListener(e -> {
File f = new File(FileSystemStorage.getInstance().getAppHomePath());
StringBuilder sb = new StringBuilder();
appendChildren(sb, f, 0);
listing.setText(sb.toString());
});
hi.add(BorderLayout.NORTH, FlowLayout.encloseCenter(add, rename)).add(BorderLayout.CENTER, listing).add(BorderLayout.SOUTH, refresh);
hi.show();
}
use of com.codename1.rad.models.Property.Name 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.rad.models.Property.Name in project CodenameOne by codenameone.
the class TestUtils method assertLabel.
/**
* Asserts that we have a label with the given text baring the given name
* @param path the path of the label
* @param text the text of the label
*/
public static void assertLabel(int[] path, String text) {
if (verbose) {
log("assertLabel(" + toString(path) + ", " + text + ")");
}
Label l = (Label) getComponentByPath(path);
assertBool(l != null, "Null label" + text);
assertBool(text == l.getText() || text.equals(l.getText()), ("" + l.getText()) + " != " + text);
}
Aggregations