Search in sources :

Example 26 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class ThemeEditor method initMIDlet.

private void initMIDlet() {
    JavaSEPortWithSVGSupport.setShowEDTWarnings(false);
    JavaSEPortWithSVGSupport.setShowEDTViolationStacks(false);
    // its a UI form
    if (uiPreviewContent.getSelectedIndex() == uiPreviewContent.getModel().getSize() - 1) {
        previewPanel.removeAll();
        if (com.codename1.ui.Display.isInitialized()) {
            com.codename1.ui.Display.deinitialize();
        }
        JavaSEPortWithSVGSupport.setDefaultInitTarget(previewPanel);
        com.codename1.ui.Display.init(previewPanel);
        previewPanel.getComponent(0).setBounds(0, 0, get(widthResoltution), get(heightResolution));
        previewPanel.getComponent(0).setPreferredSize(new java.awt.Dimension(get(widthResoltution), get(heightResolution)));
        PickMIDlet.startMIDlet(themeHash);
    } else {
        Preferences.userNodeForPackage(getClass()).put("uiPreviewContent", (String) uiPreviewContent.getSelectedItem());
        Accessor.setTheme(themeHash);
        if (com.codename1.ui.Display.isInitialized()) {
            com.codename1.ui.Display.deinitialize();
        }
        previewPanel.removeAll();
        com.codename1.ui.Display.init(previewPanel);
        previewPanel.getComponent(0).setBounds(0, 0, get(widthResoltution), get(heightResolution));
        previewPanel.getComponent(0).setPreferredSize(new java.awt.Dimension(get(widthResoltution), get(heightResolution)));
        com.codename1.ui.util.UIBuilder.registerCustomComponent("Table", com.codename1.ui.table.Table.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("MediaPlayer", com.codename1.components.MediaPlayer.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("ContainerList", com.codename1.ui.list.ContainerList.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("ComponentGroup", com.codename1.ui.ComponentGroup.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("Tree", com.codename1.ui.tree.Tree.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("HTMLComponent", com.codename1.ui.html.HTMLComponent.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("RSSReader", com.codename1.components.RSSReader.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("FileTree", com.codename1.components.FileTree.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("WebBrowser", com.codename1.components.WebBrowser.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("NumericSpinner", com.codename1.ui.spinner.NumericSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("DateSpinner", com.codename1.ui.spinner.DateSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("TimeSpinner", com.codename1.ui.spinner.TimeSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("DateTimeSpinner", com.codename1.ui.spinner.DateTimeSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("GenericSpinner", com.codename1.ui.spinner.GenericSpinner.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("LikeButton", com.codename1.facebook.ui.LikeButton.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("InfiniteProgress", com.codename1.components.InfiniteProgress.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("MultiButton", com.codename1.components.MultiButton.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("SpanButton", com.codename1.components.SpanButton.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("SpanLabel", com.codename1.components.SpanLabel.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("Ads", com.codename1.components.Ads.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("MapComponent", com.codename1.maps.MapComponent.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("MultiList", com.codename1.ui.list.MultiList.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("ShareButton", com.codename1.components.ShareButton.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("OnOffSwitch", com.codename1.components.OnOffSwitch.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("ImageViewer", com.codename1.components.ImageViewer.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("AutoCompleteTextField", com.codename1.ui.AutoCompleteTextField.class);
        com.codename1.ui.util.UIBuilder.registerCustomComponent("Picker", com.codename1.ui.spinner.Picker.class);
        Display.getInstance().callSerially(new Runnable() {

            @Override
            public void run() {
                com.codename1.ui.util.UIBuilder builder = new com.codename1.ui.util.UIBuilder();
                final com.codename1.ui.Container c = builder.createContainer(resources, (String) uiPreviewContent.getSelectedItem());
                if (c instanceof com.codename1.ui.Form) {
                    if (c instanceof com.codename1.ui.Dialog) {
                        com.codename1.ui.animations.Transition t = ((com.codename1.ui.Dialog) c).getTransitionInAnimator();
                        ((com.codename1.ui.Dialog) c).setTransitionInAnimator(com.codename1.ui.animations.CommonTransitions.createEmpty());
                        ((com.codename1.ui.Dialog) c).showModeless();
                        ((com.codename1.ui.Dialog) c).setTransitionInAnimator(t);
                    } else {
                        com.codename1.ui.animations.Transition t = ((com.codename1.ui.Form) c).getTransitionInAnimator();
                        ((com.codename1.ui.Form) c).setTransitionInAnimator(com.codename1.ui.animations.CommonTransitions.createEmpty());
                        ((com.codename1.ui.Form) c).show();
                        ((com.codename1.ui.Form) c).setTransitionInAnimator(t);
                    }
                } else {
                    com.codename1.ui.Form f = new Form();
                    f.setTransitionInAnimator(com.codename1.ui.animations.CommonTransitions.createEmpty());
                    f.setLayout(new com.codename1.ui.layouts.BorderLayout());
                    f.addComponent(com.codename1.ui.layouts.BorderLayout.CENTER, c);
                    f.show();
                }
            }
        });
    }
}
Also used : Form(com.codename1.ui.Form) Form(com.codename1.ui.Form) UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) Hashtable(java.util.Hashtable)

Example 27 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class EditableResources method openFileWithXMLSupport.

public void openFileWithXMLSupport(File f) throws IOException {
    if (xmlEnabled && f.getParentFile().getName().equals("src")) {
        File res = new File(f.getParentFile().getParentFile(), "res");
        if (res.exists()) {
            File xml = new File(res, f.getName().substring(0, f.getName().length() - 3) + "xml");
            if (xml.exists()) {
                loadingMode = true;
                com.codename1.ui.Font.clearBitmapCache();
                clear();
                try {
                    File resDir = new File(res, f.getName().substring(0, f.getName().length() - 4));
                    // open the XML file...
                    JAXBContext ctx = JAXBContext.newInstance(ResourceFileXML.class);
                    ResourceFileXML xmlData = (ResourceFileXML) ctx.createUnmarshaller().unmarshal(xml);
                    boolean normalize = xmlData.getMajorVersion() > 1 || xmlData.getMinorVersion() > 5;
                    majorVersion = (short) xmlData.getMajorVersion();
                    minorVersion = (short) xmlData.getMinorVersion();
                    xmlUI = xmlData.isUseXmlUI();
                    if (xmlData.getData() != null) {
                        for (Data d : xmlData.getData()) {
                            setResource(d.getName(), MAGIC_DATA, readFile(resDir, d.getName(), normalize));
                        }
                    }
                    if (xmlData.getLegacyFont() != null) {
                        for (LegacyFont d : xmlData.getLegacyFont()) {
                            String name = d.getName();
                            if (normalize) {
                                name = normalizeFileName(name);
                            }
                            DataInputStream fi = new DataInputStream(new FileInputStream(new File(resDir, name)));
                            setResource(d.getName(), MAGIC_FONT, loadFont(fi, d.getName(), false));
                            fi.close();
                        }
                    }
                    if (xmlData.getImage() != null) {
                        for (com.codename1.ui.util.xml.Image d : xmlData.getImage()) {
                            if (d.getType() == null) {
                                // standara JPG or PNG
                                String name = d.getName();
                                if (normalize) {
                                    name = normalizeFileName(name);
                                }
                                FileInputStream fi = new FileInputStream(new File(resDir, name));
                                EncodedImage e = EncodedImage.create(fi);
                                fi.close();
                                setResource(d.getName(), MAGIC_IMAGE, e);
                                continue;
                            }
                            if ("svg".equals(d.getType())) {
                                setResource(d.getName(), MAGIC_IMAGE, Image.createSVG(d.getType(), false, readFile(resDir, d.getName(), normalize)));
                                continue;
                            }
                            if ("timeline".equals(d.getType())) {
                                String name = d.getName();
                                if (normalize) {
                                    name = normalizeFileName(name);
                                }
                                DataInputStream fi = new DataInputStream(new FileInputStream(new File(resDir, name)));
                                setResource(d.getName(), MAGIC_IMAGE, readTimeline(fi));
                                fi.close();
                                continue;
                            }
                            if ("multi".equals(d.getType())) {
                                String name = d.getName();
                                if (normalize) {
                                    name = normalizeFileName(name);
                                }
                                File multiImageDir = new File(resDir, name);
                                File hd4k = new File(multiImageDir, "4k.png");
                                File hd2 = new File(multiImageDir, "2hd.png");
                                File hd560 = new File(multiImageDir, "560.png");
                                File hd = new File(multiImageDir, "hd.png");
                                File veryhigh = new File(multiImageDir, "veryhigh.png");
                                File high = new File(multiImageDir, "high.png");
                                File medium = new File(multiImageDir, "medium.png");
                                File low = new File(multiImageDir, "low.png");
                                File veryLow = new File(multiImageDir, "verylow.png");
                                Map<Integer, EncodedImage> images = new HashMap<Integer, EncodedImage>();
                                if (hd4k.exists()) {
                                    images.put(new Integer(Display.DENSITY_4K), EncodedImage.create(readFileNoNormal(hd4k)));
                                }
                                if (hd2.exists()) {
                                    images.put(new Integer(Display.DENSITY_2HD), EncodedImage.create(readFileNoNormal(hd2)));
                                }
                                if (hd560.exists()) {
                                    images.put(new Integer(Display.DENSITY_560), EncodedImage.create(readFileNoNormal(hd560)));
                                }
                                if (hd.exists()) {
                                    images.put(new Integer(Display.DENSITY_HD), EncodedImage.create(readFileNoNormal(hd)));
                                }
                                if (veryhigh.exists()) {
                                    images.put(new Integer(Display.DENSITY_VERY_HIGH), EncodedImage.create(readFileNoNormal(veryhigh)));
                                }
                                if (high.exists()) {
                                    images.put(new Integer(Display.DENSITY_HIGH), EncodedImage.create(readFileNoNormal(high)));
                                }
                                if (medium.exists()) {
                                    images.put(new Integer(Display.DENSITY_MEDIUM), EncodedImage.create(readFileNoNormal(medium)));
                                }
                                if (low.exists()) {
                                    images.put(new Integer(Display.DENSITY_LOW), EncodedImage.create(readFileNoNormal(low)));
                                }
                                if (veryLow.exists()) {
                                    images.put(new Integer(Display.DENSITY_VERY_LOW), EncodedImage.create(readFileNoNormal(veryLow)));
                                }
                                int[] dpis = new int[images.size()];
                                EncodedImage[] imageArray = new EncodedImage[images.size()];
                                int count = 0;
                                for (Map.Entry<Integer, EncodedImage> m : images.entrySet()) {
                                    dpis[count] = m.getKey().intValue();
                                    imageArray[count] = m.getValue();
                                    count++;
                                }
                                MultiImage result = new MultiImage();
                                result.setDpi(dpis);
                                result.setInternalImages(imageArray);
                                setResource(d.getName(), MAGIC_IMAGE, result);
                                continue;
                            }
                        }
                    }
                    if (xmlData.getL10n() != null) {
                        for (L10n d : xmlData.getL10n()) {
                            Hashtable<String, Hashtable<String, String>> l10n = new Hashtable<String, Hashtable<String, String>>();
                            for (Lang l : d.getLang()) {
                                Hashtable<String, String> language = new Hashtable<String, String>();
                                if (l != null && l.getEntry() != null) {
                                    for (Entry e : l.getEntry()) {
                                        language.put(e.getKey(), e.getValue());
                                    }
                                }
                                l10n.put(l.getName(), language);
                            }
                            setResource(d.getName(), MAGIC_L10N, l10n);
                        }
                    }
                    if (xmlData.getTheme() != null) {
                        for (Theme d : xmlData.getTheme()) {
                            Hashtable<String, Object> theme = new Hashtable<String, Object>();
                            theme.put("uninitialized", Boolean.TRUE);
                            if (d.getVal() != null) {
                                for (Val v : d.getVal()) {
                                    String key = v.getKey();
                                    if (key.endsWith("align") || key.endsWith("textDecoration") || key.endsWith(Style.ELEVATION)) {
                                        theme.put(key, Integer.valueOf(v.getValue()));
                                        continue;
                                    }
                                    if (key.endsWith(Style.BACKGROUND_TYPE) || key.endsWith(Style.BACKGROUND_ALIGNMENT) || key.endsWith(Style.ICON_GAP_UNIT)) {
                                        theme.put(key, Byte.valueOf(v.getValue()));
                                        continue;
                                    }
                                    if (key.endsWith(Style.SURFACE)) {
                                        theme.put(key, Boolean.valueOf(v.getValue()));
                                        continue;
                                    }
                                    if (key.endsWith(Style.ICON_GAP)) {
                                        theme.put(key, Float.valueOf(v.getValue()));
                                        continue;
                                    }
                                    // padding and or margin type
                                    if (key.endsWith("Unit")) {
                                        String[] s = v.getValue().split(",");
                                        theme.put(key, new byte[] { Byte.parseByte(s[0]), Byte.parseByte(s[1]), Byte.parseByte(s[2]), Byte.parseByte(s[3]) });
                                        continue;
                                    }
                                    theme.put(key, v.getValue());
                                }
                            }
                            if (d.getBorder() != null) {
                                for (com.codename1.ui.util.xml.Border b : d.getBorder()) {
                                    if ("empty".equals(b.getType())) {
                                        theme.put(b.getKey(), Border.createEmpty());
                                        continue;
                                    }
                                    if ("round".equals(b.getType())) {
                                        RoundBorder rb = RoundBorder.create();
                                        rb = rb.opacity(b.getOpacity());
                                        rb = rb.color(b.getRoundBorderColor());
                                        rb = rb.rectangle(b.isRectangle());
                                        rb = rb.shadowBlur(b.getShadowBlur());
                                        rb = rb.shadowOpacity(b.getShadowOpacity());
                                        rb = rb.shadowSpread((int) b.getShadowSpread(), b.isShadowMM());
                                        rb = rb.shadowX(b.getShadowX());
                                        rb = rb.shadowY(b.getShadowY());
                                        rb = rb.stroke(b.getStrokeThickness(), b.isStrokeMM());
                                        rb = rb.strokeColor(b.getStrokeColor());
                                        rb = rb.strokeOpacity(b.getStrokeOpacity());
                                        theme.put(b.getKey(), rb);
                                        continue;
                                    }
                                    if ("css".equals(b.getType())) {
                                        CSSBorder cb = new CSSBorder(this, b.getCSS());
                                        theme.put(b.getKey(), cb);
                                        continue;
                                    }
                                    if ("roundRect".equals(b.getType())) {
                                        RoundRectBorder rb = RoundRectBorder.create();
                                        rb = rb.shadowBlur(b.getShadowBlur());
                                        rb = rb.shadowOpacity(b.getShadowOpacity());
                                        rb = rb.shadowSpread(b.getShadowSpread());
                                        rb = rb.shadowX(b.getShadowX());
                                        rb = rb.shadowY(b.getShadowY());
                                        rb = rb.stroke(b.getStrokeThickness(), b.isStrokeMM());
                                        rb = rb.strokeColor(b.getStrokeColor());
                                        rb = rb.strokeOpacity(b.getStrokeOpacity());
                                        rb = rb.bezierCorners(b.isBezierCorners());
                                        if (b.isTopOnlyMode()) {
                                            rb.topOnlyMode(true);
                                        } else if (b.isBottomOnlyMode()) {
                                            rb.bottomOnlyMode(true);
                                        }
                                        rb = rb.cornerRadius(b.getCornerRadius());
                                        theme.put(b.getKey(), rb);
                                        continue;
                                    }
                                    if ("line".equals(b.getType())) {
                                        if (b.getColor() == null) {
                                            if (b.isMillimeters()) {
                                                theme.put(b.getKey(), Border.createLineBorder(b.getThickness().floatValue()));
                                            } else {
                                                theme.put(b.getKey(), Border.createLineBorder(b.getThickness().intValue()));
                                            }
                                        } else {
                                            if (b.isMillimeters()) {
                                                theme.put(b.getKey(), Border.createLineBorder(b.getThickness().floatValue(), b.getColor().intValue()));
                                            } else {
                                                theme.put(b.getKey(), Border.createLineBorder(b.getThickness().intValue(), b.getColor().intValue()));
                                            }
                                        }
                                        continue;
                                    }
                                    if ("underline".equals(b.getType())) {
                                        if (b.getColor() == null) {
                                            theme.put(b.getKey(), Border.createUndelineBorder(b.getThickness().intValue()));
                                        } else {
                                            theme.put(b.getKey(), Border.createUnderlineBorder(b.getThickness().intValue(), b.getColor().intValue()));
                                        }
                                        continue;
                                    }
                                    if ("rounded".equals(b.getType())) {
                                        if (b.getColor() == null) {
                                            theme.put(b.getKey(), Border.createRoundBorder(b.getArcW().intValue(), b.getArcH().intValue()));
                                        } else {
                                            theme.put(b.getKey(), Border.createRoundBorder(b.getArcW().intValue(), b.getArcH().intValue(), b.getColor().intValue()));
                                        }
                                        continue;
                                    }
                                    if ("etchedRaised".equals(b.getType())) {
                                        if (b.getColor() == null) {
                                            theme.put(b.getKey(), Border.createEtchedRaised());
                                        } else {
                                            theme.put(b.getKey(), Border.createEtchedRaised(b.getColor().intValue(), b.getColorB().intValue()));
                                        }
                                        continue;
                                    }
                                    if ("etchedLowered".equals(b.getType())) {
                                        if (b.getColor() == null) {
                                            theme.put(b.getKey(), Border.createEtchedLowered());
                                        } else {
                                            theme.put(b.getKey(), Border.createEtchedLowered(b.getColor().intValue(), b.getColorB().intValue()));
                                        }
                                        continue;
                                    }
                                    if ("bevelLowered".equals(b.getType())) {
                                        if (b.getColor() == null) {
                                            theme.put(b.getKey(), Border.createBevelLowered());
                                        } else {
                                            theme.put(b.getKey(), Border.createBevelLowered(b.getColor().intValue(), b.getColorB().intValue(), b.getColorC().intValue(), b.getColorD().intValue()));
                                        }
                                        continue;
                                    }
                                    if ("bevelRaised".equals(b.getType())) {
                                        if (b.getColor() == null) {
                                            theme.put(b.getKey(), Border.createBevelRaised());
                                        } else {
                                            theme.put(b.getKey(), Border.createBevelRaised(b.getColor().intValue(), b.getColorB().intValue(), b.getColorC().intValue(), b.getColorD().intValue()));
                                        }
                                        continue;
                                    }
                                    if ("image".equals(b.getType())) {
                                        int imageCount = 2;
                                        if (b.getI9() != null) {
                                            imageCount = 9;
                                        } else {
                                            if (b.getI8() != null) {
                                                imageCount = 8;
                                            } else {
                                                if (b.getI3() != null) {
                                                    imageCount = 3;
                                                }
                                            }
                                        }
                                        String[] borderInstance;
                                        switch(imageCount) {
                                            case 2:
                                                borderInstance = new String[] { b.getI1(), b.getI2() };
                                                break;
                                            case 3:
                                                borderInstance = new String[] { b.getI1(), b.getI2(), b.getI3() };
                                                break;
                                            case 8:
                                                borderInstance = new String[] { b.getI1(), b.getI2(), b.getI3(), b.getI4(), b.getI5(), b.getI6(), b.getI7(), b.getI8() };
                                                break;
                                            default:
                                                borderInstance = new String[] { b.getI1(), b.getI2(), b.getI3(), b.getI4(), b.getI5(), b.getI6(), b.getI7(), b.getI8(), b.getI9() };
                                                break;
                                        }
                                        theme.put(b.getKey(), borderInstance);
                                        continue;
                                    }
                                    if ("imageH".equals(b.getType())) {
                                        theme.put(b.getKey(), new String[] { "h", b.getI1(), b.getI2(), b.getI3() });
                                        continue;
                                    }
                                    if ("imageV".equals(b.getType())) {
                                        theme.put(b.getKey(), new String[] { "v", b.getI1(), b.getI2(), b.getI3() });
                                        continue;
                                    }
                                }
                            }
                            if (d.getFont() != null) {
                                for (com.codename1.ui.util.xml.Font b : d.getFont()) {
                                    if ("ttf".equals(b.getType())) {
                                        com.codename1.ui.Font system = com.codename1.ui.Font.createSystemFont(b.getFace().intValue(), b.getStyle().intValue(), b.getSize().intValue());
                                        EditorTTFFont t;
                                        if (b.getName().startsWith("native:")) {
                                            t = new EditorTTFFont(b.getName(), b.getSizeSettings().intValue(), b.getActualSize().floatValue(), system);
                                        } else {
                                            t = new EditorTTFFont(new File(f.getParentFile(), b.getName()), b.getSizeSettings().intValue(), b.getActualSize().floatValue(), system);
                                        }
                                        theme.put(b.getKey(), t);
                                        continue;
                                    }
                                    if ("system".equals(b.getType())) {
                                        com.codename1.ui.Font system = com.codename1.ui.Font.createSystemFont(b.getFace().intValue(), b.getStyle().intValue(), b.getSize().intValue());
                                        theme.put(b.getKey(), system);
                                        continue;
                                    }
                                // bitmap fonts aren't supported right now
                                }
                            }
                            if (d.getGradient() != null) {
                                for (com.codename1.ui.util.xml.Gradient b : d.getGradient()) {
                                    theme.put(b.getKey(), new Object[] { b.getColor1(), b.getColor2(), b.getPosX(), b.getPosY(), b.getRadius() });
                                }
                            }
                            setResource(d.getName(), MAGIC_THEME, theme);
                        }
                    }
                    // we load the UI last since it might depend on images or other elements in the future
                    if (xmlData.getUi() != null) {
                        if (xmlData.isUseXmlUI()) {
                            ArrayList<ComponentEntry> guiElements = new ArrayList<ComponentEntry>();
                            // place renderers first
                            final ArrayList<String> renderers = new ArrayList<String>();
                            for (Ui d : xmlData.getUi()) {
                                JAXBContext componentContext = JAXBContext.newInstance(ComponentEntry.class);
                                File uiFile = new File(resDir, normalizeFileName(d.getName()) + ".ui");
                                ComponentEntry uiXMLData = (ComponentEntry) componentContext.createUnmarshaller().unmarshal(uiFile);
                                guiElements.add(uiXMLData);
                                uiXMLData.findRendererers(renderers);
                            }
                            Collections.sort(guiElements, new Comparator<ComponentEntry>() {

                                private final ArrayList<String> entries1 = new ArrayList<String>();

                                private final ArrayList<String> entries2 = new ArrayList<String>();

                                @Override
                                public int compare(ComponentEntry o1, ComponentEntry o2) {
                                    if (renderers.contains(o1.getName())) {
                                        return -1;
                                    }
                                    if (renderers.contains(o2.getName())) {
                                        return 1;
                                    }
                                    entries1.clear();
                                    entries2.clear();
                                    o1.findEmbeddedDependencies(entries1);
                                    o2.findEmbeddedDependencies(entries2);
                                    if (entries1.size() == 0) {
                                        if (entries2.size() == 0) {
                                            return 0;
                                        }
                                        return -1;
                                    } else {
                                        if (entries2.size() == 0) {
                                            return 1;
                                        }
                                    }
                                    for (String e : entries1) {
                                        if (e.equals(o2.getName())) {
                                            return 1;
                                        }
                                    }
                                    for (String e : entries2) {
                                        if (e.equals(o1.getName())) {
                                            return -1;
                                        }
                                    }
                                    return 0;
                                }
                            });
                            for (ComponentEntry uiXMLData : guiElements) {
                                UIBuilderOverride uib = new UIBuilderOverride();
                                com.codename1.ui.Container cnt = uib.createInstance(uiXMLData, this);
                                // encountered an error loading the component fallback to loading with the binary types
                                if (cnt == null) {
                                    for (Ui ui : xmlData.getUi()) {
                                        setResource(uiXMLData.getName(), MAGIC_UI, readFile(resDir, ui.getName(), normalize));
                                    }
                                    break;
                                } else {
                                    byte[] data = UserInterfaceEditor.persistContainer(cnt, this);
                                    setResource(uiXMLData.getName(), MAGIC_UI, data);
                                }
                            }
                        } else {
                            for (Ui d : xmlData.getUi()) {
                                setResource(d.getName(), MAGIC_UI, readFile(resDir, d.getName(), normalize));
                            }
                        }
                    }
                    loadingMode = false;
                    modified = false;
                    updateModified();
                    // can occure when a resource file is opened via the constructor
                    if (undoQueue != null) {
                        undoQueue.clear();
                        redoQueue.clear();
                    }
                    return;
                } catch (JAXBException err) {
                    err.printStackTrace();
                }
            }
        }
    }
    openFile(new FileInputStream(f));
}
Also used : Val(com.codename1.ui.util.xml.Val) LegacyFont(com.codename1.ui.util.xml.LegacyFont) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EditorTTFFont(com.codename1.ui.EditorTTFFont) ComponentEntry(com.codename1.ui.util.xml.comps.ComponentEntry) ResourceFileXML(com.codename1.ui.util.xml.ResourceFileXML) JAXBException(javax.xml.bind.JAXBException) Lang(com.codename1.ui.util.xml.Lang) FileInputStream(java.io.FileInputStream) Ui(com.codename1.ui.util.xml.Ui) AnimationObject(com.codename1.ui.animations.AnimationObject) RoundBorder(com.codename1.ui.plaf.RoundBorder) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) L10n(com.codename1.ui.util.xml.L10n) JAXBContext(javax.xml.bind.JAXBContext) Entry(com.codename1.ui.util.xml.Entry) ComponentEntry(com.codename1.ui.util.xml.comps.ComponentEntry) RoundRectBorder(com.codename1.ui.plaf.RoundRectBorder) Hashtable(java.util.Hashtable) Data(com.codename1.ui.util.xml.Data) DataInputStream(java.io.DataInputStream) EncodedImage(com.codename1.ui.EncodedImage) CSSBorder(com.codename1.ui.plaf.CSSBorder) Theme(com.codename1.ui.util.xml.Theme)

Example 28 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class ToastBar method updateStatus.

/**
 * Updates the ToastBar UI component with the settings of the current status.
 */
private void updateStatus() {
    final ToastBarComponent c = getToastBarComponent();
    moveLayerToFront();
    if (c != null) {
        try {
            if (updatingStatus) {
                pendingUpdateStatus = true;
                return;
            }
            updatingStatus = true;
            if (c.currentlyShowing != null && !statuses.contains(c.currentlyShowing)) {
                c.currentlyShowing = null;
            }
            if (c.currentlyShowing == null || statuses.isEmpty()) {
                if (!statuses.isEmpty()) {
                    c.currentlyShowing = statuses.get(statuses.size() - 1);
                } else {
                    setVisible(false);
                    return;
                }
            }
            Status s = c.currentlyShowing;
            Label l = new Label(s.getMessage() != null ? s.getMessage() : "", defaultMessageUIID);
            c.leadButton.getListeners().clear();
            c.leadButton.addActionListener(s.getListener());
            c.leadButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent evt) {
                    if (c.currentlyShowing != null && !c.currentlyShowing.showProgressIndicator) {
                        c.currentlyShowing.clear();
                        evt.consume();
                    }
                    ToastBar.this.setVisible(false);
                }
            });
            c.progressLabel.setVisible(s.isShowProgressIndicator());
            if (c.progressLabel.isVisible()) {
                if (!c.contains(c.progressLabel)) {
                    c.addComponent(BorderLayout.EAST, c.progressLabel);
                }
                Image anim = c.progressLabel.getAnimation();
                if (anim != null && anim.getWidth() > 0) {
                    c.progressLabel.setWidth(anim.getWidth());
                }
                if (anim != null && anim.getHeight() > 0) {
                    c.progressLabel.setHeight(anim.getHeight());
                }
            } else {
                if (c.contains(c.progressLabel)) {
                    c.removeComponent(c.progressLabel);
                }
            }
            c.progressBar.setVisible(s.getProgress() >= -1);
            if (s.getProgress() >= -1) {
                if (!c.contains(c.progressBar)) {
                    c.addComponent(BorderLayout.SOUTH, c.progressBar);
                }
                if (s.getProgress() < 0) {
                    c.progressBar.setInfinite(true);
                } else {
                    c.progressBar.setInfinite(false);
                    c.progressBar.setProgress(s.getProgress());
                }
            } else {
                c.removeComponent(c.progressBar);
            }
            c.icon.setVisible(s.getIcon() != null);
            if (s.getIcon() != null && c.icon.getIcon() != s.getIcon()) {
                c.icon.setIcon(s.getIcon());
            }
            if (s.getIcon() == null && c.contains(c.icon)) {
                c.removeComponent(c.icon);
            } else if (s.getIcon() != null && !c.contains(c.icon)) {
                c.addComponent(BorderLayout.WEST, c.icon);
            }
            String oldText = c.label.getText();
            if (!oldText.equals(l.getText())) {
                if (s.getUiid() != null) {
                    c.setUIID(s.getUiid());
                } else if (defaultUIID != null) {
                    c.setUIID(defaultUIID);
                }
                if (c.isVisible()) {
                    TextArea newLabel = new TextArea();
                    newLabel.setUIID(defaultMessageUIID);
                    // newLabel.setColumns(l.getText().length()+1);
                    // newLabel.setRows(l.getText().length()+1);
                    newLabel.setFocusable(false);
                    newLabel.setEditable(false);
                    newLabel.setVerticalAlignment(Component.CENTER);
                    // newLabel.getAllStyles().setFgColor(0xffffff);
                    if (s.getMessageUIID() != null) {
                        newLabel.setUIID(s.getMessageUIID());
                    } else if (defaultMessageUIID != null) {
                        newLabel.setUIID(defaultMessageUIID);
                    } else {
                        newLabel.setUIID(c.label.getUIID());
                    }
                    if (s.getUiid() != null) {
                        c.setUIID(s.getUiid());
                    } else if (defaultUIID != null) {
                        c.setUIID(defaultUIID);
                    }
                    newLabel.setWidth(c.label.getWidth());
                    newLabel.setText(l.getText());
                    Dimension oldTextAreaSize = UIManager.getInstance().getLookAndFeel().getTextAreaSize(c.label, true);
                    Dimension newTexAreaSize = UIManager.getInstance().getLookAndFeel().getTextAreaSize(newLabel, true);
                    // https://stackoverflow.com/questions/46172993/codename-one-toastbar-nullpointerexception
                    if (c.label.getParent() != null) {
                        c.label.getParent().replaceAndWait(c.label, newLabel, CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, true, 300));
                        c.label = newLabel;
                        if (oldTextAreaSize.getHeight() != newTexAreaSize.getHeight()) {
                            c.label.setPreferredH(newTexAreaSize.getHeight());
                            c.getParent().animateHierarchyAndWait(300);
                        }
                    }
                } else {
                    if (s.getMessageUIID() != null) {
                        c.label.setUIID(s.getMessageUIID());
                    } else if (defaultMessageUIID != null) {
                        c.label.setUIID(defaultMessageUIID);
                    }
                    if (s.getUiid() != null) {
                        c.setUIID(s.getUiid());
                    } else if (defaultUIID != null) {
                        c.setUIID(defaultUIID);
                    }
                    c.label.setText(l.getText());
                    // c.label.setColumns(l.getText().length()+1);
                    // c.label.setRows(l.getText().length()+1);
                    c.label.setPreferredW(c.getWidth());
                    c.revalidate();
                }
            } else {
                c.revalidate();
            }
        } finally {
            updatingStatus = false;
            if (pendingUpdateStatus) {
                pendingUpdateStatus = false;
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        updateStatus();
                    }
                });
            }
        }
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) TextArea(com.codename1.ui.TextArea) ActionEvent(com.codename1.ui.events.ActionEvent) Label(com.codename1.ui.Label) Dimension(com.codename1.ui.geom.Dimension) FontImage(com.codename1.ui.FontImage) Image(com.codename1.ui.Image)

Example 29 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class AddResourceDialog method addResource.

public String addResource(EditableResources res, ResourceEditorView view) {
    // "Image", "Animation", "Font", "Theme", "Data", "Localization (L10N)"
    String newName = name.getText();
    for (String r : res.getResourceNames()) {
        if (r.equalsIgnoreCase(newName)) {
            JOptionPane.showMessageDialog(this, "A resource called: " + newName + " already exists\nYou must delete the resource first.", "Add Resource", JOptionPane.ERROR_MESSAGE);
            return null;
        }
    }
    switch(type.getSelectedIndex()) {
        case // image
        IMAGE:
            ImageRGBEditor imageEditor = new ImageRGBEditor(res, name.getText(), view);
            imageEditor.selectFile();
            view.setSelectedResource(name.getText());
            break;
        case MULTI_IMAGE:
            ImageMultiEditor multiImageEditor = new ImageMultiEditor(res, name.getText(), view);
            view.setSelectedResource(name.getText());
            break;
        case TIMELINE:
            new TimelineEditor(res, name.getText(), view);
            view.setSelectedResource(name.getText());
            break;
        case // animation
        ANIMATION:
            TimelineEditor.selectFile(view, res, name.getText());
            /*ImageEditor animationEditor = new ImageEditor(res, name.getText());
                animationEditor.setAnimation(true);
                animationEditor.selectFile(view);*/
            break;
        case // font
        FONT:
            new FontEditor(res, new EditorFont(com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_MEDIUM), null, "Arial-plain-12", true, RenderingHints.VALUE_TEXT_ANTIALIAS_ON, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,;:!@/\\*()[]{}|#$%^&<>?'\"+- "), name.getText()).createFont();
            view.setSelectedResource(name.getText());
            break;
        case // theme
        THEME:
            res.setTheme(name.getText(), new Hashtable());
            view.setSelectedResource(name.getText());
            // ResourceEditorView.expandAndSelect(tree, name.getText());
            break;
        case // data
        DATA:
            DataEditor dataEditor = new DataEditor(res, name.getText());
            dataEditor.selectDataFile(view);
            view.setSelectedResource(name.getText());
            break;
        case // localization
        LOCALIZATION:
            Hashtable h = new Hashtable();
            Hashtable local = new Hashtable();
            local.put("cancel", "Cancel");
            local.put("ok", "OK");
            local.put("menu", "Menu");
            local.put("select", "Select");
            local.put("edit", "Edit");
            h.put("en", local);
            res.setL10N(name.getText(), h);
            view.setSelectedResource(name.getText());
            // ResourceEditorView.expandAndSelect(tree, name.getText());
            break;
        case UI:
            UserInterfaceEditor uiEditor = new UserInterfaceEditor(name.getText(), res, view.getProjectGeneratorSettings(), view);
            view.setSelectedResource(name.getText());
            break;
    }
    return name.getText();
}
Also used : Hashtable(java.util.Hashtable) EditorFont(com.codename1.ui.EditorFont)

Example 30 with UI

use of com.codename1.rad.ui.UI in project CodenameOne by codenameone.

the class AddThemeEntry method updateThemePreview.

// GEN-LAST:event_trueTypeFontSizeValueStateChanged
private void updateThemePreview() {
    if (disableRefresh) {
        return;
    }
    updateThemeHashtable(themeHash);
    refreshTheme(themeHash);
    String name = codenameOnePreview.getComponentAt(0).getClass().getName();
    String selectedName = (String) componentName.getSelectedItem();
    if (!name.endsWith(selectedName)) {
        try {
            com.codename1.ui.Component c;
            if (selectedName.equals("BrowserComponent")) {
                // special case
                c = new com.codename1.ui.Label("Preview", "BrowserComponent");
            } else {
                Class cls = Class.forName("com.codename1.ui." + selectedName);
                c = (com.codename1.ui.Component) cls.newInstance();
                if (c instanceof com.codename1.ui.Label) {
                    ((com.codename1.ui.Label) c).setText("Preview");
                } else {
                    if (c instanceof com.codename1.ui.List) {
                        ((com.codename1.ui.List) c).setModel(new com.codename1.ui.list.DefaultListModel(new Object[] { "Preview 1", "Preview 2", "Preview 3" }));
                    }
                }
            }
            codenameOnePreview.removeAll();
            codenameOnePreview.addComponent(com.codename1.ui.layouts.BorderLayout.CENTER, c);
        } catch (Throwable t) {
            codenameOnePreview.removeAll();
            com.codename1.ui.Label l = new com.codename1.ui.Label("Preview");
            l.setUIID(selectedName);
            codenameOnePreview.addComponent(com.codename1.ui.layouts.BorderLayout.CENTER, l);
        }
    }
    com.codename1.ui.plaf.Style s;
    if (prefix != null && prefix.length() > 0) {
        s = com.codename1.ui.plaf.UIManager.getInstance().getComponentCustomStyle(selectedName, prefix.substring(0, prefix.length() - 1));
    } else {
        s = com.codename1.ui.plaf.UIManager.getInstance().getComponentStyle(selectedName);
    }
    codenameOnePreview.getComponentAt(0).setUnselectedStyle(s);
    codenameOnePreview.revalidate();
    previewPane.repaint();
}
Also used : Style(com.codename1.ui.plaf.Style) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List)

Aggregations

Component (com.codename1.ui.Component)10 Label (com.codename1.ui.Label)9 ArrayList (java.util.ArrayList)9 Container (com.codename1.ui.Container)8 Form (com.codename1.ui.Form)8 IOException (java.io.IOException)8 TextArea (com.codename1.ui.TextArea)6 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 HashMap (java.util.HashMap)6 Vector (java.util.Vector)6 Entity (com.codename1.rad.models.Entity)5 Hashtable (java.util.Hashtable)5 EntityList (com.codename1.rad.models.EntityList)4 ActionNode (com.codename1.rad.nodes.ActionNode)4 EncodedImage (com.codename1.ui.EncodedImage)4 FontImage (com.codename1.ui.FontImage)4 Border (com.codename1.ui.plaf.Border)4 Log (com.codename1.io.Log)3 EntityTypeBuilder.entityTypeBuilder (com.codename1.rad.models.EntityTypeBuilder.entityTypeBuilder)3 Thing (com.codename1.rad.schemas.Thing)3