Search in sources :

Example 1 with Char

use of com.codename1.ui.TextSelection.Char in project CodeRAD by shannah.

the class FirstCharEntityImageRenderer method getLetterBackground.

private Image getLetterBackground(char c) {
    c = Character.toUpperCase(c);
    String cstr = "" + c;
    int color = colors[Math.max(0, c - 'A') % colors.length];
    Image i = backgroundImageCache.get(color);
    if (i != null) {
        return i;
    }
    int circleMaskWidth = width;
    int circleMaskHeight = height;
    Image img = Image.createImage(circleMaskWidth, circleMaskHeight, 0);
    Graphics g = img.getGraphics();
    g.setAntiAliased(true);
    g.setColor(color);
    g.fillArc(1, 1, circleMaskWidth - 2, circleMaskHeight - 2, 0, 360);
    backgroundImageCache.put(color, img);
    return img;
}
Also used : Graphics(com.codename1.ui.Graphics) Image(com.codename1.ui.Image) ComponentImage(ca.weblite.shared.components.ComponentImage)

Example 2 with Char

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

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icons above) to the given component using the
 * styling of the label</p>
 * <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
 * @param l a multibutton
 * @param icon one of the MATERIAL_* icons
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(MultiButton l, char icon, float size) {
    if (Font.isTrueTypeFileSupported()) {
        Style s = new Style(l.getUnselectedStyle());
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        l.setIcon(FontImage.create("" + icon, s));
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 3 with Char

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

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icons above) to the given component using the
 * styling of the label</p>
 * <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
 * @param l a SpanButton
 * @param icon one of the MATERIAL_* icons
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(SpanButton l, char icon, float size) {
    if (Font.isTrueTypeFileSupported()) {
        Style s = new Style(l.getUnselectedStyle());
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        l.setIcon(FontImage.create("" + icon, s));
        Style sel = l.getSelectedStyle();
        Style pre = l.getPressedStyle();
        Style dis = l.getDisabledStyle();
        if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
            sel = new Style(sel);
            sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
            l.setRolloverIcon(FontImage.create("" + icon, sel));
        }
        if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
            pre = new Style(pre);
            pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
            l.setPressedIcon(FontImage.create("" + icon, pre));
        }
        if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
            dis = new Style(dis);
            dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
            l.setDisabledIcon(FontImage.create("" + icon, dis));
        }
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 4 with Char

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

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icon constants) to the given command using the
 * given UIID. Notice that the pressed/selected &amp; disabled states will be set appropriately.</p>
 *
 * @param c a command
 * @param icon one of the MATERIAL_* icons
 * @param uiid the UIID for the command (e.g. TitleCommand)
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(Command c, char icon, String uiid, float size) {
    if (Font.isTrueTypeFileSupported()) {
        UIManager uim = UIManager.getInstance();
        Style s = uim.getComponentStyle(uiid);
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        c.setIcon(FontImage.create("" + icon, s));
        Style sel = uim.getComponentSelectedStyle(uiid);
        Style pre = uim.getComponentCustomStyle(uiid, "press");
        Style dis = uim.getComponentCustomStyle(uiid, "dis");
        ;
        if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
            sel = new Style(sel);
            sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
            c.setRolloverIcon(FontImage.create("" + icon, sel));
        }
        if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
            pre = new Style(pre);
            pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
            c.setPressedIcon(FontImage.create("" + icon, pre));
        }
        if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
            dis = new Style(dis);
            dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
            c.setDisabledIcon(FontImage.create("" + icon, dis));
        }
    }
}
Also used : UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style)

Example 5 with Char

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

the class ResourceEditorView method initImagesComboBox.

/**
 * Creates a sorted image combo box that includes image previews. The combo box
 * can be searched by typing a letter even when images are used for the values...
 */
public static void initImagesComboBox(JComboBox cb, final EditableResources res, boolean asString, final boolean includeNull, boolean blockTimelines) {
    String[] imgs = res.getImageResourceNames();
    if (blockTimelines) {
        List<String> nonT = new ArrayList<String>();
        for (String c : imgs) {
            if (!(res.getImage(c) instanceof Timeline)) {
                nonT.add(c);
            }
        }
        imgs = new String[nonT.size()];
        nonT.toArray(imgs);
    }
    final String[] images = imgs;
    Arrays.sort(images, String.CASE_INSENSITIVE_ORDER);
    if (asString) {
        if (includeNull) {
            String[] n = new String[images.length + 1];
            System.arraycopy(images, 0, n, 1, images.length);
            cb.setModel(new DefaultComboBoxModel(n));
        } else {
            cb.setModel(new DefaultComboBoxModel(images));
        }
        cb.setRenderer(new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                boolean n = false;
                if (value == null) {
                    value = "[null]";
                    n = true;
                }
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (!n) {
                    setIcon(new CodenameOneImageIcon(res.getImage((String) value), 24, 24));
                } else {
                    setIcon(null);
                }
                return this;
            }
        });
    } else {
        int offset = 0;
        com.codename1.ui.Image[] arr;
        if (includeNull) {
            arr = new com.codename1.ui.Image[images.length + 1];
            offset++;
        } else {
            arr = new com.codename1.ui.Image[images.length];
        }
        for (String c : images) {
            arr[offset] = res.getImage(c);
            offset++;
        }
        cb.setModel(new DefaultComboBoxModel(arr));
        cb.setKeySelectionManager(new JComboBox.KeySelectionManager() {

            private String current;

            private long lastPress;

            public int selectionForKey(char aKey, ComboBoxModel aModel) {
                long t = System.currentTimeMillis();
                aKey = Character.toLowerCase(aKey);
                if (t - lastPress < 800) {
                    current += aKey;
                } else {
                    current = "" + aKey;
                }
                lastPress = t;
                for (int iter = 0; iter < images.length; iter++) {
                    if (images[iter].toLowerCase().startsWith(current)) {
                        if (includeNull) {
                            return iter + 1;
                        }
                        return iter;
                    }
                }
                return -1;
            }
        });
        cb.setRenderer(new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                com.codename1.ui.Image i = (com.codename1.ui.Image) value;
                if (value == null) {
                    value = "[null]";
                } else {
                    value = res.findId(value);
                }
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (i != null) {
                    setIcon(new CodenameOneImageIcon(i, 24, 24));
                } else {
                    setIcon(null);
                }
                return this;
            }
        });
    }
}
Also used : JComboBox(javax.swing.JComboBox) ArrayList(java.util.ArrayList) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage) Timeline(com.codename1.ui.animations.Timeline) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) AnimationObject(com.codename1.ui.animations.AnimationObject) Component(java.awt.Component) UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) JList(javax.swing.JList) ComboBoxModel(javax.swing.ComboBoxModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

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