Search in sources :

Example 31 with Char

use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.

the class HTMLComponent method handleImageMapArea.

/**
 * Handles an area definition for an image map
 *
 * @param areaTag The AREA tag
 */
private void handleImageMapArea(HTMLElement areaTag) {
    if (curImageMap != null) {
        String shape = areaTag.getAttributeById(HTMLElement.ATTR_SHAPE);
        boolean supportedShape = false;
        if (shape != null) {
            String hrefStr = areaTag.getAttributeById(HTMLElement.ATTR_HREF);
            if (shape.equalsIgnoreCase("default")) {
                supportedShape = true;
                curImageMap.setDefaultLink(hrefStr);
            } else if ((shape.equalsIgnoreCase("rect")) || (shape.equalsIgnoreCase("circle"))) {
                supportedShape = true;
                String coordsStr = areaTag.getAttributeById(HTMLElement.ATTR_COORDS);
                if ((coordsStr != null) && (hrefStr != null)) {
                    String curValStr = "";
                    int[] coords = new int[4];
                    int curCoord = 0;
                    boolean error = true;
                    try {
                        for (int c = 0; c < coordsStr.length(); c++) {
                            char ch = coordsStr.charAt(c);
                            if (ch != ',') {
                                curValStr += ch;
                            } else {
                                coords[curCoord] = Integer.parseInt(curValStr);
                                curCoord++;
                                curValStr = "";
                            }
                        }
                        if (curValStr.length() > 0) {
                            coords[curCoord] = Integer.parseInt(curValStr);
                            curCoord++;
                        }
                        if (shape.equalsIgnoreCase("rect")) {
                            if (curCoord == 4) {
                                curImageMap.addRectArea(new Rectangle(coords[0], coords[1], coords[2] - coords[0], coords[3] - coords[1]), hrefStr);
                                error = false;
                            }
                        } else if (curCoord == 3) {
                            // circle
                            // coords[2] is the radius, and 0,1 are the center x,y
                            curImageMap.addRectArea(new Rectangle(coords[0] - coords[2], coords[1] - coords[2], coords[2] * 2 + 1, coords[2] * 2 + 1), hrefStr);
                            // Note: The 'circle' SHAPE in AREA tag is implemented as a rectangle to avoid complication of circle pixel collision
                            error = false;
                        }
                    } catch (Exception e) {
                    // Can be number format exception or index out of bounds
                    // do nothing - error will stay true
                    }
                    if (error) {
                        notifyImageMapError("AREA tag 'coords' property value is invalid (should be exactly 3 comma seperated numbers for circle, 4 for rectangle): " + coordsStr, HTMLCallback.ERROR_ATTIBUTE_VALUE_INVALID, HTMLElement.ATTR_COORDS, coordsStr);
                    }
                }
            }
        }
        if (!supportedShape) {
            notifyImageMapError("Unsupported or missing AREA tag 'shape' property: " + shape, HTMLCallback.ERROR_ATTIBUTE_VALUE_INVALID, HTMLElement.ATTR_SHAPE, shape);
        }
    } else {
        notifyImageMapError("AREA tag is defined without a parent MAP tag - ignoring", HTMLCallback.ERROR_INVALID_TAG_HIERARCHY, -1, null);
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 32 with Char

use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.

the class CSSEngine method setNowrapRecursive.

/**
 * Sets this element and all children to have unwrapped text.
 * In cases where text is already unwrapped no change will be made.
 * This will work only in FIXED_WIDTH mode (Checked before called)
 * Technically a lot of this logic can be found in HTMLComponent, but since we don't want to get into
 * the context of this element (i.e. what was the indentation, alignment etc.), we use this algorithm.
 *
 * @param element The element to apply text wrapping on
 */
private void setNowrapRecursive(final HTMLElement element) {
    // if (element.getId()==HTMLElement.TAG_TEXT) {
    if (element.isTextElement()) {
        // String text=element.getAttributeById(HTMLElement.ATTR_TITLE);
        String text = element.getText();
        final Vector ui = element.getUi();
        if ((text != null) && (ui != null) && (ui.size() > 1)) {
            // If it's just one word or already no-wrapped, no need to process
            String word = "";
            String newText = "";
            for (int c = 0; c < text.length(); c++) {
                char ch = text.charAt(c);
                if ((ch == ' ') || (ch == 10) || (ch == 13) || (ch == '\t') || (ch == '\n')) {
                    if (!word.equals("")) {
                        newText += word + " ";
                        word = "";
                    }
                } else {
                    word += ch;
                }
            }
            if (!word.equals("")) {
                newText += word + " ";
            }
            final Label label = (Label) ui.elementAt(0);
            setNowrapText(label, ui, newText, element);
        }
    }
    for (int i = 0; i < element.getNumChildren(); i++) {
        setNowrapRecursive((HTMLElement) element.getChildAt(i));
    }
    // If children elements' UI was changed, we need to recalc the UI of the parent
    element.recalcUi();
}
Also used : Label(com.codename1.ui.Label) Vector(java.util.Vector)

Example 33 with Char

use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.

the class BlackBerryImplementation method nativeEdit.

public void nativeEdit(final Component cmp, final int maxSize, final int constraint, String text, int keyCode) {
    if (nativeEdit != null) {
        finishEdit(true);
    }
    lightweightEdit = (TextArea) cmp;
    if (keyCode > 0 && getKeyboardType() == Display.KEYBOARD_TYPE_QWERTY) {
        // if this is a number
        if ((constraint & TextArea.DECIMAL) == TextArea.DECIMAL || (constraint & TextArea.NUMERIC) == TextArea.NUMERIC || (constraint & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) {
            if (keyCode == 119) {
                text += "1";
            } else if (keyCode == 101) {
                text += "2";
            } else if (keyCode == 114) {
                text += "3";
            } else if (keyCode == 115) {
                text += "4";
            } else if (keyCode == 100) {
                text += "5";
            } else if (keyCode == 102) {
                text += "6";
            } else if (keyCode == 122) {
                text += "7";
            } else if (keyCode == 120) {
                text += "8";
            } else if (keyCode == 99) {
                text += "9";
            }
        } else {
            text += ((char) keyCode);
        }
        lightweightEdit.setText(text);
    }
    class LightweightEdit implements Runnable, Animation {

        public void run() {
            long type = 0;
            TextArea lightweightEditTmp = lightweightEdit;
            if (lightweightEditTmp == null) {
                return;
            }
            int constraint = lightweightEditTmp.getConstraint();
            if ((constraint & TextArea.DECIMAL) == TextArea.DECIMAL) {
                type = BasicEditField.FILTER_REAL_NUMERIC;
            } else if ((constraint & TextArea.EMAILADDR) == TextArea.EMAILADDR) {
                type = BasicEditField.FILTER_EMAIL;
            } else if ((constraint & TextArea.NUMERIC) == TextArea.NUMERIC) {
                type = BasicEditField.FILTER_NUMERIC;
            }
            if ((constraint & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) {
                type = BasicEditField.FILTER_PHONE;
            }
            if ((constraint & TextArea.NON_PREDICTIVE) == TextArea.NON_PREDICTIVE) {
                type |= BasicEditField.NO_COMPLEX_INPUT;
            }
            if (lightweightEditTmp.isSingleLineTextArea()) {
                type |= BasicEditField.NO_NEWLINE;
            }
            if ((constraint & TextArea.PASSWORD) == TextArea.PASSWORD) {
                nativeEdit = new BBPasswordEditField(lightweightEditTmp, type, maxSize);
            } else {
                nativeEdit = new BBEditField(lightweightEditTmp, type, maxSize);
            }
            nativeEdit.setEditable(true);
            Font f = nativeEdit.getFont();
            if (f.getHeight() > lightweightEditTmp.getStyle().getFont().getHeight()) {
                nativeEdit.setFont(f.derive(f.getStyle(), lightweightEditTmp.getStyle().getFont().getHeight()));
            }
            canvas.add(nativeEdit);
            nativeEdit.setCursorPosition(lightweightEditTmp.getText().length());
            try {
                nativeEdit.setFocus();
            } catch (Throwable t) {
            // no idea why this throws an exception sometimes
            // t.printStackTrace();
            }
        }

        public boolean animate() {
            BasicEditField ef = nativeEdit;
            Component lw = lightweightEdit;
            if (lw == null || lw.getComponentForm() != Display.getInstance().getCurrent()) {
                Display.getInstance().getCurrent().deregisterAnimated(this);
                finishEdit(false);
            } else {
                if (ef != null) {
                    if (ef.isDirty()) {
                        lw.repaint();
                    }
                }
            }
            return false;
        }

        public void paint(com.codename1.ui.Graphics g) {
        }
    }
    LightweightEdit lw = new LightweightEdit();
    Display.getInstance().getCurrent().registerAnimated(lw);
    Application.getApplication().invokeLater(lw);
}
Also used : TextArea(com.codename1.ui.TextArea) BasicEditField(net.rim.device.api.ui.component.BasicEditField) Font(net.rim.device.api.ui.Font) Graphics(net.rim.device.api.ui.Graphics) Animation(com.codename1.ui.animations.Animation) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Example 34 with Char

use of com.codename1.ui.TextSelection.Char 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 the label.
 * @param materialIcon The material icon charcode.
 * @return Self for chaining.
 */
public ComponentSelector setIcon(char materialIcon) {
    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, 3));
            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, 3));
            }
        }
    }
    return this;
}
Also used : SpanButton(com.codename1.components.SpanButton) SpanLabel(com.codename1.components.SpanLabel) Style(com.codename1.ui.plaf.Style)

Example 35 with Char

use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.

the class FontImage method setIcon.

/**
 * <p>Applies icon font from the font to the given label using the styling of the label.</p>
 * @param l The label or subclass(e.g. Button etc.)
 * @param font The font with icons.
 * @param icons List of icons to use.  [Unselected, Selected, Pressed, Pressed-Selected, Disabled].  If fewer icons are supplied than requested, it will use the last icon,
 * in the list for the remaining expected icons.
 * @param size The font size.
 * @since 7.0
 */
public static void setIcon(IconHolder l, Font font, char[] icons, float size) {
    Style s = new Style(l.getIconStyleComponent().getUnselectedStyle());
    s.setFont(font.derive(rightSize(s, size), Font.STYLE_PLAIN));
    l.setIcon(FontImage.create("" + icons[0], s));
    if (l instanceof SelectableIconHolder) {
        SelectableIconHolder b = (SelectableIconHolder) l;
        Style sel = b.getIconStyleComponent().getSelectedStyle();
        Style pre = b.getIconStyleComponent().getPressedStyle();
        Style dis = b.getIconStyleComponent().getDisabledStyle();
        if (icons[Math.min(1, icons.length - 1)] != icons[0] || sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency()) || (sel.getFgAlpha() != s.getFgAlpha())) {
            sel = new Style(sel);
            sel.setFont(font.derive(rightSize(sel, size), Font.STYLE_PLAIN));
            b.setRolloverPressedIcon(FontImage.create("" + icons[Math.min(1, icons.length - 1)], sel));
        } else {
            b.setRolloverPressedIcon(null);
        }
        if (icons[Math.min(2, icons.length - 1)] != icons[0] || pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency()) || (pre.getFgAlpha() != s.getFgAlpha())) {
            pre = new Style(pre);
            pre.setFont(font.derive(rightSize(pre, size), Font.STYLE_PLAIN));
            b.setPressedIcon(FontImage.create("" + icons[Math.min(2, icons.length - 1)], pre));
        // b.setRolloverPressedIcon(FontImage.create("" + icons[Math.min(3, icons.length-1)], pre));
        } else {
            b.setPressedIcon(null);
        }
        if (icons[Math.min(4, icons.length - 1)] != icons[0] || dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency()) || (dis.getFgAlpha() != s.getFgAlpha())) {
            dis = new Style(dis);
            dis.setFont(font.derive(rightSize(dis, size), Font.STYLE_PLAIN));
            b.setDisabledIcon(FontImage.create("" + icons[Math.min(4, icons.length - 1)], dis));
        } else {
            b.setDisabledIcon(null);
        }
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Aggregations

Style (com.codename1.ui.plaf.Style)15 Font (com.codename1.ui.Font)8 ArrayList (java.util.ArrayList)5 ComponentImage (ca.weblite.shared.components.ComponentImage)4 Image (com.codename1.ui.Image)4 Point (java.awt.Point)4 Hashtable (java.util.Hashtable)4 MultiButton (com.codename1.components.MultiButton)3 SpanButton (com.codename1.components.SpanButton)3 EventObject (java.util.EventObject)3 List (java.util.List)3 Vector (java.util.Vector)3 SpanLabel (com.codename1.components.SpanLabel)2 BadgeUIID (com.codename1.rad.attributes.BadgeUIID)2 IconUIID (com.codename1.rad.attributes.IconUIID)2 UIID (com.codename1.rad.attributes.UIID)2 Button (com.codename1.ui.Button)2 TextArea (com.codename1.ui.TextArea)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 UIManager (com.codename1.ui.plaf.UIManager)2