use of com.codename1.tools.translator.bytecodes.Field in project CodenameOne by codenameone.
the class BlackBerryCanvas method paint.
public void paint(Graphics g) {
int f = getFieldCount();
if (f > 0) {
g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);
Form currentForm = Display.getInstance().getCurrent();
for (int iter = 0; iter < f; iter++) {
Field fld = getField(iter);
int pops = 0;
if (currentForm != null) {
PeerComponent p = findPeer(currentForm.getContentPane(), fld);
if (p != null) {
pops = clipOnLWUITBounds(p, g);
} else {
Component cmp = currentForm.getFocused();
// we are now editing an edit field
if (cmp != null && cmp instanceof TextArea && cmp.hasFocus() && fld instanceof EditField) {
pops = clipOnLWUITBounds(cmp, g);
int x = fld.getLeft();
int y = fld.getTop();
g.clear(x, y, Math.max(cmp.getWidth(), fld.getWidth()), Math.max(cmp.getHeight(), fld.getHeight()));
}
}
}
paintChild(g, fld);
while (pops > 0) {
g.popContext();
pops--;
}
}
} else {
g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);
}
g.setColor(0);
g.drawText(debug, 0, 0);
painted = true;
}
use of com.codename1.tools.translator.bytecodes.Field 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.tools.translator.bytecodes.Field in project CodenameOne by codenameone.
the class HTMLComponent method handleTableCell.
/**
* Handles a single table cell (a TD tag)
*
* @param tdTag The TD tag element
* @param align The current alignment
*/
private void handleTableCell(HTMLElement tdTag, int align) {
newLineIfNotEmpty(align);
tableCells.addElement(curContainer);
Container cell = new Container();
cell.getStyle().setBgTransparency(0);
cell.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
// int border=0;
HTMLElement trTag = (HTMLElement) tdTag.getParent();
while ((trTag != null) && (trTag.getTagId() != HTMLElement.TAG_TR)) {
// Though in strict XHTML TR can only contain TD/TH - in some HTMLs TR doesn't have to be the direct parent of the tdTag, i.e.: <tr><b><td>...</td>... </b></tr>
trTag = (HTMLElement) trTag.getParent();
}
// Commented since the table border should not affect cell border
/*if (trTag!=null) { // Null checks to prevent exceptions for a TD tag without table etc.
HTMLElement tableTag=(HTMLElement)trTag.getParent();
while ((tableTag!=null) && (tableTag.getTagId()!=HTMLElement.TAG_TABLE)) { // Though in strict XHTML TABLE can only contain TR - in some HTMLs it might be different
tableTag=(HTMLElement)tableTag.getParent();
}
if (tableTag!=null) {
border=getInt(tableTag.getAttributeById(HTMLElement.ATTR_BORDER));
}
}
cell.getUnselectedStyle().setPadding(border, border, border, border);
cell.getSelectedStyle().setPadding(border, border, border, border);*/
// Constraint constraint = new Constraint();
CellConstraint constraint = new CellConstraint();
int halign = align;
int valign = Component.CENTER;
if (trTag != null) {
HTMLElement tGroupTag = (HTMLElement) trTag.getParent();
int tagId = tGroupTag.getTagId();
if ((tagId == HTMLElement.TAG_TBODY) || (tagId == HTMLElement.TAG_THEAD) || (tagId == HTMLElement.TAG_TFOOT)) {
// Get the default TR alignment
halign = getHorizAlign(tGroupTag.getAttributeById(HTMLElement.ATTR_ALIGN), halign, false);
// Get the default TR valignment
valign = getVertAlign(tGroupTag.getAttributeById(HTMLElement.ATTR_VALIGN), valign);
}
// Get the default TR alignment
halign = getHorizAlign(trTag.getAttributeById(HTMLElement.ATTR_ALIGN), halign, false);
// Get the default TR valignment
valign = getVertAlign(trTag.getAttributeById(HTMLElement.ATTR_VALIGN), valign);
}
halign = getHorizAlign(tdTag.getAttributeById(HTMLElement.ATTR_ALIGN), halign, false);
valign = getVertAlign(tdTag.getAttributeById(HTMLElement.ATTR_VALIGN), valign);
int colspan = getInt(tdTag.getAttributeById(HTMLElement.ATTR_COLSPAN));
int rowspan = getInt(tdTag.getAttributeById(HTMLElement.ATTR_ROWSPAN));
String cWidth = tdTag.getAttributeById(HTMLElement.ATTR_WIDTH);
int pW = getPercentage(cWidth);
if ((pW > 0) && (pW < 100)) {
// constraint.setWidthPercentage(pW); //TODO - Setting a width constraint currently makes the field width 0 - needs to be fixed in TableLayout
} else {
pW = getInt(cWidth);
if (pW != 0) {
cell.setPreferredW(pW);
}
}
String cHeight = tdTag.getAttributeById(HTMLElement.ATTR_HEIGHT);
int pH = getPercentage(cHeight);
if ((pH > 0) && (pH < 100)) {
// constraint.setHeightPercentage(pH); //TODO - Setting a height constraint currently makes the field height 0 - needs to be fixed in TableLayout
} else {
pH = getInt(cHeight);
if (pH != 0) {
cell.setPreferredH(pH);
}
}
constraint.setHorizontalAlign(halign);
constraint.setVerticalAlign(valign);
if (colspan > 1) {
constraint.setHorizontalSpan(colspan);
}
if (rowspan > 1) {
constraint.setVerticalSpan(rowspan);
}
curContainer = cell;
if (curTable != null) {
curTable.addCell(cell, (tdTag.getTagId() == HTMLElement.TAG_TH), constraint);
}
if (loadCSS) {
tdTag.setAssociatedComponents(cell);
if (trTag != null) {
trTag.addAssociatedComponent(cell);
}
}
}
use of com.codename1.tools.translator.bytecodes.Field in project CodenameOne by codenameone.
the class TextComponent method constructUI.
void constructUI() {
if (getComponentCount() == 0) {
if (isOnTopMode() && isFocusAnimation()) {
getLabel().setUIID("FloatingHint");
setLayout(new LayeredLayout());
Container tfContainer = BorderLayout.center(field).add(BorderLayout.NORTH, getLabel()).add(BorderLayout.SOUTH, getErrorMessage());
add(tfContainer);
Label errorMessageFiller = new Label();
Component.setSameSize(errorMessageFiller, getErrorMessage());
animationLayer = BorderLayout.south(errorMessageFiller);
add(animationLayer);
if (field.getText() == null || field.getText().length() == 0) {
field.setHint(getLabel().getText());
getLabel().setVisible(false);
}
} else {
super.constructUI();
}
}
}
use of com.codename1.tools.translator.bytecodes.Field in project CodenameOne by codenameone.
the class HTMLForm method submit.
/**
* Called when the a form submit is needed.
* This querys all form fields, creates a URL accordingly and sets it to the HTMLComponent
*/
void submit(String submitKey, String submitVal) {
if (action == null) {
return;
}
// If this is turned to true anywhere, the form will not be submitted
boolean error = false;
String url = action;
String params = null;
if (comps.size() > 0) {
params = "";
for (Enumeration e = comps.keys(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
Object input = comps.get(key);
key = HTMLUtils.encodeString(key);
String value = "";
if (input instanceof String) {
// hidden
value = HTMLUtils.encodeString((String) input);
params += key + "=" + value + "&";
} else if (input instanceof Hashtable) {
// checkbox / radiobutton
Hashtable options = (Hashtable) input;
for (Enumeration e2 = options.keys(); e2.hasMoreElements(); ) {
Button b = (Button) e2.nextElement();
if (b.isSelected()) {
params += key + "=" + HTMLUtils.encodeString((String) options.get(b)) + "&";
}
}
} else if (input instanceof TextArea) {
// catches both textareas and text input fields
TextArea tf = ((TextArea) input);
String text = tf.getText();
String errorMsg = null;
if (HTMLComponent.SUPPORT_INPUT_FORMAT) {
boolean ok = false;
if (text.equals("")) {
// check empty - Note that emptyok/-wap-input-required overrides input format
if (emptyNotOk.contains(tf)) {
errorMsg = htmlC.getUIManager().localize("html.format.emptynotok", "Field can't be empty");
error = true;
} else if (emptyOk.contains(tf)) {
ok = true;
}
}
if ((!error) && (!ok)) {
// If there's already an error or it has been cleared by the emptyOK field, no need to check
HTMLInputFormat inputFormat = (HTMLInputFormat) inputFormats.get(tf);
if ((inputFormat != null) && (!inputFormat.verifyString(text))) {
String emptyStr = "";
if (emptyOk.contains(tf)) {
emptyStr = htmlC.getUIManager().localize("html.format.oremptyok", " or an empty string");
} else if (emptyNotOk.contains(tf)) {
emptyStr = htmlC.getUIManager().localize("html.format.andemptynotok", " and cannot be an empty string");
}
errorMsg = htmlC.getUIManager().localize("html.format.errordesc", "Malformed text. Correct value: ") + inputFormat.toString() + emptyStr;
error = true;
}
}
}
if (htmlC.getHTMLCallback() != null) {
int type = HTMLCallback.FIELD_TEXT;
if ((tf.getConstraint() & TextArea.PASSWORD) != 0) {
type = HTMLCallback.FIELD_PASSWORD;
}
text = htmlC.getHTMLCallback().fieldSubmitted(htmlC, tf, url, key, text, type, errorMsg);
}
if (errorMsg == null) {
params += key + "=" + HTMLUtils.encodeString(text) + "&";
}
} else if (input instanceof ComboBox) {
// drop down lists (single selection)
Object item = ((ComboBox) input).getSelectedItem();
if (item instanceof OptionItem) {
value = ((OptionItem) item).getValue();
params += key + "=" + HTMLUtils.encodeString(value) + "&";
}
// if not - value may be an OPTGROUP label in an only optgroup combobox
} else if (input instanceof MultiComboBox) {
// drop down lists (multiple selection)
Vector selected = ((MultiComboBox) input).getSelected();
for (int i = 0; i < selected.size(); i++) {
Object item = selected.elementAt(i);
if (item instanceof OptionItem) {
value = ((OptionItem) item).getValue();
params += key + "=" + HTMLUtils.encodeString(value) + "&";
}
// if not - value may be an OPTGROUP label in an only optgroup combobox
}
}
}
if (params.endsWith("&")) {
// trim the extra &
params = params.substring(0, params.length() - 1);
}
}
// Add the submit button param, only if the key is non-null (unnamed submit buttons are not passed as parameters)
if (submitKey != null) {
if (params == null) {
params = "";
}
if (!params.equals("")) {
params = params + "&";
}
params = params + HTMLUtils.encodeString(submitKey) + "=" + HTMLUtils.encodeString(submitVal);
}
if (!error) {
DocumentInfo docInfo = new DocumentInfo(url, params, isPostMethod);
if ((encType != null) && (!encType.equals(""))) {
docInfo.setEncoding(encType);
}
htmlC.setPage(docInfo);
}
}
Aggregations