Search in sources :

Example 26 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class LazyValueC method readObjectArrayForListModel.

private Object[] readObjectArrayForListModel(DataInputStream in, Resources res) throws IOException {
    Object[] elements = new Object[in.readInt()];
    int elen = elements.length;
    for (int iter = 0; iter < elen; iter++) {
        switch(in.readByte()) {
            case // String
            1:
                elements[iter] = in.readUTF();
                break;
            case // hashtable of Strings
            2:
                int hashSize = in.readInt();
                Hashtable val = new Hashtable();
                elements[iter] = val;
                for (int i = 0; i < hashSize; i++) {
                    int type = in.readInt();
                    if (type == 1) {
                        // String
                        String key = in.readUTF();
                        Object value = in.readUTF();
                        if (key.equals("$navigation")) {
                            Command cmd = createCommandImpl((String) value, null, -1, (String) value, false, "");
                            cmd.putClientProperty(COMMAND_ACTION, (String) value);
                            value = cmd;
                        }
                        val.put(key, value);
                    } else {
                        val.put(in.readUTF(), res.getImage(in.readUTF()));
                    }
                }
                break;
        }
    }
    return elements;
}
Also used : Command(com.codename1.ui.Command) Hashtable(java.util.Hashtable)

Example 27 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class LazyValueC method postCreateComponents.

/**
 * Invoked after the components were created to allow properties that require the entire
 * tree to exist to update the component. This is useful for properties that point
 * at other components.
 */
private void postCreateComponents(DataInputStream in, Container parent, Resources res) throws Exception {
    // finds the component whose properties need to update
    String name = in.readUTF();
    Component lastComponent = null;
    while (name.length() > 0) {
        if (lastComponent == null || !lastComponent.getName().equals(name)) {
            lastComponent = findByName(name, parent);
        }
        Component c = lastComponent;
        int property = in.readInt();
        modifyingProperty(c, property);
        switch(property) {
            case PROPERTY_COMMAND_LEGACY:
                {
                    readCommand(in, c, parent, res, true);
                    break;
                }
            case PROPERTY_COMMAND:
                {
                    readCommand(in, c, parent, res, false);
                    break;
                }
            case PROPERTY_LABEL_FOR:
                c.setLabelForComponent((Label) findByName(in.readUTF(), parent));
                break;
            case PROPERTY_LEAD_COMPONENT:
                ((Container) c).setLeadComponent(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_UP:
                c.setNextFocusUp(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_DOWN:
                c.setNextFocusDown(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_LEFT:
                c.setNextFocusLeft(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_RIGHT:
                c.setNextFocusRight(findByName(in.readUTF(), parent));
                break;
        }
        name = in.readUTF();
    }
}
Also used : Container(com.codename1.ui.Container) Component(com.codename1.ui.Component)

Example 28 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class Spinner method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g) {
    super.paint(g);
    if (spinnerHandle != null) {
        Style s = getStyle();
        g.drawImage(spinnerHandle, getX() + getWidth() - spinnerHandle.getWidth() - s.getHorizontalPadding(), getY() + s.getPaddingTop());
    }
    if (System.currentTimeMillis() - inputSkipDelay < lastKeyInteraction || quickType.isPendingCommit()) {
        quickType.setWidth(Math.min(getWidth(), quickType.getPreferredW()));
        quickType.setHeight(Math.min(getHeight(), quickType.getPreferredH()));
        Style s = quickType.getStyle();
        quickType.setY(getScrollY() + getY());
        // positioning based on date/time
        if (getRenderer() instanceof DateTimeRenderer) {
            switch(currentInputAlign) {
                case LEFT:
                    quickType.setX(getX());
                    break;
                case RIGHT:
                    quickType.setX(getX() + quickType.getStyle().getFont().charWidth(TextArea.getWidestChar()) * 4 + s.getMarginRightNoRTL());
                    break;
                default:
                    quickType.setX(getX() + quickType.getStyle().getFont().charWidth(TextArea.getWidestChar()) * 2 + s.getMarginLeftNoRTL());
                    break;
            }
        } else {
            quickType.setX(getX());
        }
        quickType.paintComponent(g, true);
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 29 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class SpinnerNode method render.

// @Override
public void render(Graphics g) {
    g.setColor(overlayStyle.getBgColor());
    int alpha = g.getAlpha();
    g.setAlpha(255);
    g.fillRect(0, 0, (int) boundsInLocal.get().getWidth(), (int) boundsInLocal.get().getHeight());
    g.setAlpha(alpha);
    super.render(g);
    int clipX = g.getClipX();
    int clipY = g.getClipY();
    int clipW = g.getClipWidth();
    int clipH = g.getClipHeight();
    Rectangle2D overlayRect = selectedRowOverlay.getBoundsInScene(new Rectangle2D());
    double magnification = 1.35;
    double oldScaleX = scaleX.get();
    double oldScaleY = scaleY.get();
    double oldTranslateX = translateX.get();
    scaleX.set(oldScaleX * magnification);
    scaleY.set(oldScaleY * magnification);
    switch(getRowStyle().getAlignment()) {
        case Component.LEFT:
            translateX.set(oldTranslateX + boundsInLocal.get().getWidth() * (magnification - 1.0) / 2 / magnification);
            break;
        case Component.RIGHT:
            translateX.set(oldTranslateX - boundsInLocal.get().getWidth() * (magnification - 1.0) / 2 / magnification);
            break;
    }
    selectedRowOverlay.visible.set(false);
    g.setClip((int) overlayRect.getX(), (int) overlayRect.getY() + 1, (int) overlayRect.getWidth(), (int) overlayRect.getHeight() - 2);
    super.render(g);
    selectedRowOverlay.visible.set(true);
    g.setClip(clipX, clipY, clipW, clipH);
    scaleX.set(oldScaleX);
    scaleY.set(oldScaleY);
    translateX.set(oldTranslateX);
}
Also used : Rectangle2D(com.codename1.ui.geom.Rectangle2D)

Example 30 with Switch

use of com.codename1.components.Switch in project CodenameOne by codenameone.

the class TextPainter method paint.

/**
 * Paints the text onto the provided graphics context.
 * @param g The graphics to paint onto.
 * @param bounds The bounding rect.
 * @param node The node whose content we are painting.
 */
@Override
public void paint(Graphics g, Rectangle bounds, Node node) {
    Style style = node.getStyle();
    if (style == null) {
        return;
    }
    Font font = style.getFont();
    if (font == null) {
        font = Font.getDefaultFont();
    }
    int textWidth = font.stringWidth(text);
    int textHeight = font.getHeight();
    int innerX = bounds.getX() + style.getPaddingLeft(false);
    int innerY = bounds.getY() + style.getPaddingTop();
    int innerW = bounds.getWidth() - style.getHorizontalPadding();
    int innerH = bounds.getHeight() - style.getVerticalPadding();
    int x = innerX;
    int y = innerY;
    switch(style.getAlignment()) {
        case Component.CENTER:
            x = innerX + innerW / 2 - textWidth / 2;
            break;
        case Component.RIGHT:
            x = innerX + innerW - textWidth;
            break;
    }
    switch(vAlign) {
        case Component.CENTER:
            y = innerY + innerH / 2 - textHeight / 2;
            break;
        case Component.BOTTOM:
            y = innerY + innerH - textHeight;
            break;
    }
    g.setFont(font);
    g.setColor(style.getFgColor());
    int alpha = g.concatenateAlpha(style.getFgAlpha());
    g.drawString(text, x, y);
    g.setAlpha(alpha);
}
Also used : Style(com.codename1.ui.plaf.Style) Font(com.codename1.ui.Font)

Aggregations

Component (com.codename1.ui.Component)19 Font (com.codename1.ui.Font)18 Container (com.codename1.ui.Container)15 Form (com.codename1.ui.Form)14 Style (com.codename1.ui.plaf.Style)12 Button (com.codename1.ui.Button)11 Image (com.codename1.ui.Image)11 TextArea (com.codename1.ui.TextArea)11 ArrayList (java.util.ArrayList)11 File (java.io.File)10 IOException (java.io.IOException)10 Hashtable (java.util.Hashtable)10 BorderLayout (com.codename1.ui.layouts.BorderLayout)9 Label (com.codename1.ui.Label)8 FileInputStream (java.io.FileInputStream)8 ActionListener (com.codename1.ui.events.ActionListener)7 TextField (com.codename1.ui.TextField)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 EncodedImage (com.codename1.ui.EncodedImage)5