Search in sources :

Example 6 with UIBuilderOverride

use of com.codename1.ui.util.UIBuilderOverride in project CodenameOne by codenameone.

the class ImageRGBEditor method findImageUseImpl.

private static void findImageUseImpl(com.codename1.ui.Image resourceValue, Vector users, EditableResources res, JLabel borderPreview) {
    for (String themeName : res.getThemeResourceNames()) {
        Hashtable theme = res.getTheme(themeName);
        for (Object key : theme.keySet()) {
            Object value = theme.get(key);
            if (value instanceof com.codename1.ui.Image) {
                if (value.equals(resourceValue)) {
                    addToUsers((String) key, users);
                }
            }
            if (value instanceof Border) {
                Border b = (Border) value;
                // BORDER_TYPE_IMAGE
                if (Accessor.getType(b) == Accessor.TYPE_IMAGE || Accessor.getType(b) == Accessor.TYPE_IMAGE_HORIZONTAL || Accessor.getType(b) == Accessor.TYPE_IMAGE_VERTICAL) {
                    com.codename1.ui.Image[] images = Accessor.getImages(b);
                    for (int i = 0; i < images.length; i++) {
                        if (images[i] == resourceValue) {
                            addToUsers((String) key, users);
                            if (borderPreview != null && borderPreview.getIcon() == null) {
                                int borderWidth = Math.max(100, b.getMinimumWidth());
                                int borderHeight = Math.max(100, b.getMinimumHeight());
                                com.codename1.ui.Image img = com.codename1.ui.Image.createImage(borderWidth, borderHeight);
                                com.codename1.ui.Label l = new com.codename1.ui.Label("Preview");
                                l.getStyle().setBorder(b);
                                l.setSize(new com.codename1.ui.geom.Dimension(borderWidth, borderHeight));
                                l.paintComponent(img.getGraphics());
                                CodenameOneImageIcon icon = new CodenameOneImageIcon(img, borderWidth, borderHeight);
                                borderPreview.setIcon(icon);
                            }
                        }
                    }
                }
            }
        }
    }
    // check if a timeline is making use of said image and replace it
    for (String image : res.getImageResourceNames()) {
        com.codename1.ui.Image current = res.getImage(image);
        if (current instanceof com.codename1.ui.animations.Timeline) {
            com.codename1.ui.animations.Timeline time = (com.codename1.ui.animations.Timeline) current;
            for (int iter = 0; iter < time.getAnimationCount(); iter++) {
                com.codename1.ui.animations.AnimationObject o = time.getAnimation(iter);
                if (AnimationAccessor.getImage(o) == resourceValue) {
                    addToUsers(image, users);
                }
            }
        }
    }
    // check if a UI resource is making use of the image
    UIBuilderOverride builder = new UIBuilderOverride();
    for (String uiResource : res.getUIResourceNames()) {
        com.codename1.ui.Container c = builder.createContainer(res, uiResource);
        if (ResourceEditorView.findImageInContainer(c, resourceValue)) {
            addToUsers(uiResource, users);
        }
    }
}
Also used : UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) Hashtable(java.util.Hashtable) JLabel(javax.swing.JLabel) EncodedImage(com.codename1.ui.EncodedImage) Border(com.codename1.ui.plaf.Border)

Example 7 with UIBuilderOverride

use of com.codename1.ui.util.UIBuilderOverride in project CodenameOne by codenameone.

the class L10nEditor method syncWithUIActionPerformed.

// GEN-LAST:event_editHTMLActionPerformed
private void syncWithUIActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_syncWithUIActionPerformed
    Accessor.setResourceBundle(null);
    final Map<String, String> allKeys = new HashMap<String, String>();
    com.codename1.ui.plaf.UIManager original = com.codename1.ui.plaf.UIManager.getInstance();
    Accessor.setUIManager(new com.codename1.ui.plaf.ProtectedUIManager() {

        public String localize(String key, String defaultValue) {
            if (key != null && key.length() > 0 && defaultValue != null && defaultValue.length() > 0) {
                allKeys.put(key, defaultValue);
            }
            return super.localize(key, defaultValue);
        }
    });
    UIBuilderOverride o = new UIBuilderOverride();
    for (String resources : res.getUIResourceNames()) {
        o.createContainer(res, resources);
    }
    Accessor.setUIManager(original);
    for (String currentKey : allKeys.keySet()) {
        if (!keys.contains(currentKey)) {
            keys.add(currentKey);
            for (Object locale : localeList) {
                res.setLocaleProperty(localeName, (String) locale, currentKey, allKeys.get(currentKey));
            }
        }
    }
    initTable();
}
Also used : UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) HashMap(java.util.HashMap) EventObject(java.util.EventObject)

Aggregations

UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)5 ArrayList (java.util.ArrayList)4 EncodedImage (com.codename1.ui.EncodedImage)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 Hashtable (java.util.Hashtable)3 EditorTTFFont (com.codename1.ui.EditorTTFFont)2 AnimationObject (com.codename1.ui.animations.AnimationObject)2 Border (com.codename1.ui.plaf.Border)2 RoundBorder (com.codename1.ui.plaf.RoundBorder)2 RoundRectBorder (com.codename1.ui.plaf.RoundRectBorder)2 LegacyFont (com.codename1.ui.util.xml.LegacyFont)2 DataInputStream (java.io.DataInputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 HashMap (java.util.HashMap)2 SVG (com.codename1.impl.javase.SVG)1 Command (com.codename1.ui.Command)1 Container (com.codename1.ui.Container)1