use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class CSSEngine method setNowrapText.
/**
* Replaces a wrapped text with an unwrapped version.
* This in fact removes all the labels that contains a single word each, and replaces them with one label that contains the whole text.
* This way the label is not wrapped.
*
* @param label The first label of this text element (can be derived from ui but already fetched before the call)
* @param ui The vector consisting all components (labels) that contain the text's words
* @param newText The new text that should replace current components (unwrapped text without extra white spaces)
* @param element The text element
*/
private void setNowrapText(Label label, Vector ui, String newText, HTMLElement element) {
label.setText(newText);
for (int i = 1; i < ui.size(); i++) {
Component cmp = (Component) ui.elementAt(i);
cmp.getParent().removeComponent(cmp);
}
if (label instanceof HTMLLink) {
// Reset all associated link fragments so we don't have unneeded references
((HTMLLink) label).childLinks = new Vector();
}
element.setAssociatedComponents(label);
label.getParent().revalidate();
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class CSSEngine method handleContentProperty.
/**
* Handles a CSS content property
*
* @param element The element this content property
* @param selector The CSS selector that includes the content property
* @param htmlC The HTMLComponent
*/
private void handleContentProperty(HTMLElement element, CSSElement selector, HTMLComponent htmlC) {
boolean after = ((selector.getSelectorPseudoClass() & CSSElement.PC_AFTER) != 0);
String content = selector.getAttributeById(CSSElement.CSS_CONTENT);
if (content != null) {
// if there's no content, we don't add anything
Component cmp = after ? (Component) element.getUi().lastElement() : (Component) element.getUi().firstElement();
Component styleCmp = cmp;
Container parent = null;
int pos = 0;
if (cmp instanceof Container) {
parent = ((Container) cmp);
while ((parent.getComponentCount() > 0) && (parent.getComponentAt(after ? parent.getComponentCount() - 1 : 0) instanceof Container)) {
// find the actual content
parent = (Container) parent.getComponentAt(after ? parent.getComponentCount() - 1 : 0);
}
if (parent.getComponentCount() > 0) {
pos = after ? parent.getComponentCount() - 1 : 0;
styleCmp = parent.getComponentAt(pos);
}
} else {
parent = cmp.getParent();
pos = cmp.getParent().getComponentIndex(cmp);
}
if (after) {
pos++;
}
int initPos = pos;
String str = "";
// to make sure the last expression is evaluated, note that this will not print an extra space in any case, since it is out of the quotes if any
content = content + " ";
boolean segment = false;
for (int i = 0; i < content.length(); i++) {
char c = content.charAt(i);
Label lbl = null;
if (c == '"') {
segment = !segment;
if ((!segment) && (str.length() > 0)) {
lbl = new Label(str);
str = "";
}
} else if (CSSParser.isWhiteSpace(c)) {
if (segment) {
str += c;
lbl = new Label(str);
} else if (str.length() > 0) {
lbl = evalContentExpression(htmlC, str, element, selector);
if (lbl == null) {
// if we didn't find a match we search for the following expressions which are used to remove added content
int removeQuoteType = -1;
boolean removeAll = false;
if ((str.equals("none")) || (str.equals("normal"))) {
// normal/none means remove all content
removeAll = true;
} else if (str.equals("no-open-quote")) {
// 0 is the quote type for open quote, 1 for closed one
removeQuoteType = 0;
} else if (str.equals("no-close-quote")) {
removeQuoteType = 1;
}
if ((removeAll) || (removeQuoteType != -1)) {
Vector v = element.getUi();
if (v != null) {
Vector toRemove = new Vector();
for (Enumeration e = v.elements(); e.hasMoreElements(); ) {
Component ui = (Component) e.nextElement();
String conStr = (String) ui.getClientProperty(CLIENT_PROPERTY_CSS_CONTENT);
if ((conStr != null) && (((after) && (conStr.equals("a"))) || ((!after) && (conStr.equals("b"))))) {
boolean remove = true;
if (removeQuoteType != -1) {
Object obj = ui.getClientProperty(HTMLComponent.CLIENT_PROPERTY_QUOTE);
if (obj != null) {
int quoteType = ((Integer) obj).intValue();
remove = (quoteType == removeQuoteType);
} else {
remove = false;
}
}
if (remove) {
parent.removeComponent(ui);
toRemove.addElement(ui);
}
}
}
for (Enumeration e = toRemove.elements(); e.hasMoreElements(); ) {
v.removeElement(e.nextElement());
}
}
// stop processing after removal clauses such as none/normal
return;
}
}
}
str = "";
} else {
str += c;
}
if (lbl != null) {
if (after) {
element.addAssociatedComponent(lbl);
} else {
element.addAssociatedComponentAt(pos - initPos, lbl);
}
lbl.setUnselectedStyle(new Style(styleCmp.getUnselectedStyle()));
lbl.putClientProperty(CLIENT_PROPERTY_CSS_CONTENT, after ? "a" : "b");
if (parent.getComponentCount() == 0) {
parent.addComponent(lbl);
} else {
parent.addComponent(pos, lbl);
}
pos++;
applyStyleToUIElement(lbl, selector, element, htmlC);
}
}
}
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class SideMenuBar method createSideNavigationPanel.
Container createSideNavigationPanel(Vector commands, String placement) {
Container menu = constructSideNavigationComponent();
if (getUIManager().isThemeConstant("paintsTitleBarBool", false)) {
Container bar = new Container();
bar.setUIID("StatusBarSideMenu");
addComponentToSideMenu(menu, bar);
}
if (!getUIManager().isThemeConstant("sideMenuTensileDragBool", true)) {
menu.setTensileDragEnabled(false);
}
for (int iter = commands.size() - 1; iter > -1; iter--) {
Command c = (Command) commands.elementAt(iter);
if (c.getClientProperty(COMMAND_PLACEMENT_KEY) != placement) {
continue;
}
Component cmp = (Component) c.getClientProperty(COMMAND_SIDE_COMPONENT);
if (cmp != null) {
if (cmp.getParent() != null) {
cmp.getParent().removeAll();
}
if (c.getClientProperty(COMMAND_ACTIONABLE) != null && c.getClientProperty(COMMAND_ACTIONABLE).equals(Boolean.TRUE)) {
Container cnt = new Container(new BorderLayout());
cnt.addComponent(BorderLayout.CENTER, cmp);
Button btn = createTouchCommandButton(c);
btn.setParent(cnt);
cnt.setLeadComponent(btn);
addComponentToSideMenu(menu, cnt);
} else {
addComponentToSideMenu(menu, cmp);
}
initTitleBarStatus();
} else {
// special case: hide back button that doesn't have text, icon or a side component entry
if (parent.getBackCommand() == c && (c.getCommandName() == null || c.getCommandName().length() == 0) && c.getIcon() == null) {
continue;
}
addComponentToSideMenu(menu, createTouchCommandButton(c));
}
}
boolean isRTLValue = isRTL();
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
isRTLValue = !isRTLValue;
}
UIManager uim = menu.getUIManager();
boolean shadowEnabled = uim.isThemeConstant("sideMenuShadowBool", true);
Image sh = (Image) uim.getThemeImageConstant("sideMenuShadowImage");
if (sh == null && shadowEnabled) {
sh = Resources.getSystemResource().getImage("sidemenu-shadow.png");
}
if (isRTLValue && sh != null) {
sh = sh.flipHorizontally(true);
}
final Image shadow = sh;
if (shadow == null) {
return menu;
} else {
Container main = new Container(new LayeredLayout());
Label shadowLabel = new Label();
shadowLabel.getStyle().setBackgroundType(Style.BACKGROUND_IMAGE_TILE_VERTICAL_ALIGN_CENTER);
shadowLabel.getStyle().setBgImage(shadow);
shadowLabel.getStyle().setPadding(0, 0, 0, 0);
shadowLabel.getStyle().setMargin(0, 0, 0, 0);
shadowLabel.getStyle().setBgTransparency(0);
Container c = new Container(new BorderLayout());
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
shadowLabel.setPreferredW(shadow.getWidth());
c.addComponent(BorderLayout.WEST, shadowLabel);
shadowLabel.getStyle().setBgImage(shadow.rotate180Degrees(true));
} else {
if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
// shadowLabel.setPreferredH(shadow.getHeight());
// c.addComponent(BorderLayout.SOUTH, shadowLabel);
// shadowLabel.getStyle().setBgImage(shadow.rotate90Degrees(true));
} else {
shadowLabel.setPreferredW(shadow.getWidth());
c.addComponent(BorderLayout.EAST, shadowLabel);
}
}
main.addComponent(menu);
main.addComponent(c);
return main;
}
}
use of com.codename1.ui.Label 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.ui.Label 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