Search in sources :

Example 1 with Component

use of com.codename1.ui.Component in project codenameone-google-maps by codenameone.

the class MapLayout method layoutContainer.

@Override
public void layoutContainer(Container parent) {
    // if (true) {
    // return;
    // }
    int parentX = 0;
    int parentY = 0;
    for (Component current : parent) {
        Coord crd = (Coord) current.getClientProperty(COORD_KEY);
        Point p = (Point) current.getClientProperty(POINT_KEY);
        if (p == null) {
            p = map.getScreenCoordinate(crd);
            current.putClientProperty(POINT_KEY, p);
        }
        Float h = (Float) current.getClientProperty(HORIZONTAL_ALIGNMENT);
        if (h == null) {
            h = 0f;
        }
        Float v = (Float) current.getClientProperty(VERTICAL_ALIGNMENT);
        if (v == null) {
            v = 0f;
        }
        current.setSize(current.getPreferredSize());
        current.setX(convertX(p.getX() - parentX, current.getWidth(), h));
        current.setY(convertY(p.getY() - parentY, current.getHeight(), v));
    }
}
Also used : Coord(com.codename1.maps.Coord) Point(com.codename1.ui.geom.Point) Component(com.codename1.ui.Component) Point(com.codename1.ui.geom.Point)

Example 2 with Component

use of com.codename1.ui.Component in project codenameone-google-maps by codenameone.

the class MapInfoPanel method styleLabels.

private void styleLabels(Component... roots) {
    for (Component c : roots) {
        if (c instanceof Label) {
            Label l = (Label) c;
            l.getAllStyles().setFgColor(0xffffff);
            l.getAllStyles().setBgTransparency(0);
            l.getAllStyles().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
        }
        if (c instanceof Container) {
            Container cnt = (Container) c;
            for (Component child : cnt) {
                styleLabels(child);
            }
        }
    }
}
Also used : Container(com.codename1.ui.Container) MapContainer(com.codename1.googlemaps.MapContainer) Label(com.codename1.ui.Label) Component(com.codename1.ui.Component)

Example 3 with Component

use of com.codename1.ui.Component in project CodenameOne by codenameone.

the class GenericListCellRenderer method findComponentsOfInterest.

private void findComponentsOfInterest(Component cmp, ArrayList dest) {
    if (cmp instanceof Container) {
        Container c = (Container) cmp;
        int count = c.getComponentCount();
        for (int iter = 0; iter < count; iter++) {
            findComponentsOfInterest(c.getComponentAt(iter), dest);
        }
        return;
    }
    // performance optimization for fixed images in lists
    if (cmp.getName() != null) {
        if (cmp instanceof Label) {
            Label l = (Label) cmp;
            if (l.getName().toLowerCase().endsWith("fixed") && l.getIcon() != null) {
                l.getIcon().lock();
            }
            dest.add(cmp);
            return;
        }
        if (cmp instanceof TextArea) {
            dest.add(cmp);
            return;
        }
    }
}
Also used : Container(com.codename1.ui.Container) TextArea(com.codename1.ui.TextArea) Label(com.codename1.ui.Label)

Example 4 with Component

use of com.codename1.ui.Component in project CodenameOne by codenameone.

the class GenericListCellRenderer method setComponentValue.

/**
 * Initializes the given component with the given value
 *
 * @param cmp one of the components that is or is a part of the renderer
 * @param value the value to install into the component
 */
private void setComponentValue(Component cmp, Object value, Component parent, Component rootRenderer) {
    // process so renderer selected/unselected styles are applied
    if (cmp.getName().toLowerCase().endsWith("fixed")) {
        return;
    }
    if (cmp instanceof Label) {
        if (value instanceof Image) {
            Image i = (Image) value;
            if (i.isAnimation()) {
                if (pendingAnimations == null) {
                    pendingAnimations = new ArrayList<Image>();
                }
                if (!pendingAnimations.contains(i)) {
                    pendingAnimations.add(i);
                    if (parentList == null) {
                        parentList = parent;
                    }
                    if (parentList != null) {
                        Form f = parentList.getComponentForm();
                        if (f != null) {
                            f.registerAnimated(mon);
                            waitingForRegisterAnimation = false;
                        } else {
                            waitingForRegisterAnimation = true;
                        }
                    }
                } else {
                    if (waitingForRegisterAnimation) {
                        if (parentList != null) {
                            Form f = parentList.getComponentForm();
                            if (f != null) {
                                f.registerAnimated(mon);
                                waitingForRegisterAnimation = false;
                            }
                        }
                    }
                }
            }
            Image oldImage = ((Label) cmp).getIcon();
            ((Label) cmp).setIcon(i);
            ((Label) cmp).setText("");
            if (oldImage == null || oldImage.getWidth() != i.getWidth() || oldImage.getHeight() != i.getHeight()) {
                ((Container) rootRenderer).revalidate();
            }
            return;
        } else {
            ((Label) cmp).setIcon(null);
        }
        if (cmp instanceof CheckBox) {
            ((CheckBox) cmp).setSelected(isSelectedValue(value));
            return;
        }
        if (cmp instanceof RadioButton) {
            ((RadioButton) cmp).setSelected(isSelectedValue(value));
            return;
        }
        if (cmp instanceof Slider) {
            ((Slider) cmp).setProgress(((Integer) value).intValue());
            return;
        }
        Label l = (Label) cmp;
        if (value == null) {
            l.setText("");
        } else {
            if (value instanceof Label) {
                l.setText(((Label) value).getText());
                l.setIcon(((Label) value).getIcon());
            } else {
                l.setText(value.toString());
            }
        }
        if (firstCharacterRTL) {
            String t = l.getText();
            if (t.length() > 0) {
                l.setRTL(Display.getInstance().isRTL(t.charAt(0)));
            }
        }
        return;
    }
    if (cmp instanceof TextArea) {
        if (value == null) {
            ((TextArea) cmp).setText("");
        } else {
            ((TextArea) cmp).setText(value.toString());
        }
    }
}
Also used : Container(com.codename1.ui.Container) Slider(com.codename1.ui.Slider) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) CheckBox(com.codename1.ui.CheckBox) Label(com.codename1.ui.Label) RadioButton(com.codename1.ui.RadioButton) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage) URLImage(com.codename1.ui.URLImage)

Example 5 with Component

use of com.codename1.ui.Component in project CodenameOne by codenameone.

the class GenericListCellRenderer method extractLastClickedComponent.

/**
 * Allows partitioning the renderer into "areas" that can be clicked. When
 * receiving an action event in the list this method allows a developer to
 * query the renderer to "see" whether a button within the component was "touched"
 * by the user on a touch screen device.
 * This method will reset the value to null after returning a none-null value!
 *
 * @return a button or null
 */
public Button extractLastClickedComponent() {
    Button c = lastClickedComponent;
    lastClickedComponent = null;
    return c;
}
Also used : RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button)

Aggregations

Component (com.codename1.ui.Component)152 Style (com.codename1.ui.plaf.Style)61 Container (com.codename1.ui.Container)55 Form (com.codename1.ui.Form)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)40 TextArea (com.codename1.ui.TextArea)31 ActionEvent (com.codename1.ui.events.ActionEvent)28 Dimension (com.codename1.ui.geom.Dimension)28 Label (com.codename1.ui.Label)25 Point (com.codename1.ui.geom.Point)22 ArrayList (java.util.ArrayList)22 Rectangle (com.codename1.ui.geom.Rectangle)21 Vector (java.util.Vector)18 Button (com.codename1.ui.Button)16 Dialog (com.codename1.ui.Dialog)16 Hashtable (java.util.Hashtable)16 Image (com.codename1.ui.Image)15 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)13 BoxLayout (com.codename1.ui.layouts.BoxLayout)13