use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class SignatureComponent method setSignatureImage.
/**
* Sets the signature image for this field. This will also scale the image and
* show it as the icon for the button.
* @param img The image to set as the signature image.
*/
public void setSignatureImage(Image img) {
if (img != signatureImage) {
signatureImage = img;
lead.setText("");
if (img != null) {
int maxW = lead.getWidth() - lead.getStyle().getPaddingLeftNoRTL() - lead.getStyle().getPaddingRightNoRTL();
int maxH = lead.getHeight() - lead.getStyle().getPaddingTop() - lead.getStyle().getPaddingBottom();
Image icon = img;
if (icon.getWidth() > maxW || icon.getHeight() > maxH) {
icon = icon.scaledSmallerRatio(maxW, maxH);
}
lead.setIcon(icon);
} else {
lead.setText(localize("SignatureComponent.LeadText", "Press to sign"));
lead.setIcon(null);
}
}
}
use of com.codename1.ui.Button 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.Button in project CodenameOne by codenameone.
the class BarCodeScanner method startScaning.
private void startScaning(ScanResult callback) {
this.callback = callback;
try {
// Add the listener for scan and cancel
Container cmdContainer = new Container(new FlowLayout(Component.CENTER));
Button scanButton = new Button(new Command("Scan") {
public void actionPerformed(ActionEvent evt) {
cameraForm.repaint();
if (snapshotThread != null) {
snapshotThread.continueRun();
}
}
});
Button cancelButton = new Button(new Command("Cancel") {
public void actionPerformed(ActionEvent evt) {
if (snapshotThread != null) {
snapshotThread.stop();
cancelScan();
}
}
});
cmdContainer.addComponent(scanButton);
cmdContainer.addComponent(cancelButton);
cameraForm = new Form();
cameraForm.setScrollable(false);
cameraForm.setLayout(new BorderLayout());
cameraForm.addComponent(BorderLayout.CENTER, media.getVideoComponent());
cameraForm.addComponent(BorderLayout.SOUTH, cmdContainer);
} catch (Exception e) {
// throw new AppException("Image/video capture not supported on this phone", e).setCode(97);
e.printStackTrace();
}
startScan();
}
use of com.codename1.ui.Button 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;
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class Dialog method placeButtonCommands.
/**
* Places the given commands in the dialog command area, this is very useful for touch devices.
*
* @param cmds the commands to place
* @deprecated this method shouldn't be invoked externally, it should have been private
*/
public void placeButtonCommands(Command[] cmds) {
buttonCommands = cmds;
Container buttonArea;
if (getUIManager().isThemeConstant("dlgCommandGridBool", false)) {
buttonArea = new Container(new GridLayout(1, cmds.length));
} else {
buttonArea = new Container(new FlowLayout(CENTER));
}
buttonArea.setUIID("DialogCommandArea");
String uiid = getUIManager().getThemeConstant("dlgButtonCommandUIID", null);
addButtonBar(buttonArea);
if (cmds.length > 0) {
String lineColor = getUIManager().getThemeConstant("dlgInvisibleButtons", null);
if (cmds.length > 3) {
lineColor = null;
}
int largest = Integer.parseInt(getUIManager().getThemeConstant("dlgCommandButtonSizeInt", "0"));
for (int iter = 0; iter < cmds.length; iter++) {
Button b = new Button(cmds[iter]);
if (uiid != null) {
b.setUIID(uiid);
}
// special case for dialog butons uppercase on Android
if (Button.isCapsTextDefault()) {
b.setCapsText(true);
}
largest = Math.max(b.getPreferredW(), largest);
if (lineColor != null && lineColor.length() > 0) {
int color = Integer.parseInt(lineColor, 16);
Border brd = null;
if (iter < cmds.length - 1) {
brd = Border.createCompoundBorder(Border.createLineBorder(1, color), null, null, Border.createLineBorder(1, color));
} else {
brd = Border.createCompoundBorder(Border.createLineBorder(1, color), null, null, null);
}
b.getUnselectedStyle().setBorder(brd);
b.getSelectedStyle().setBorder(brd);
b.getPressedStyle().setBorder(brd);
}
buttonArea.addComponent(b);
}
for (int iter = 0; iter < cmds.length; iter++) {
buttonArea.getComponentAt(iter).setPreferredW(largest);
}
buttonArea.getComponentAt(0).requestFocus();
}
}
Aggregations