Search in sources :

Example 16 with List

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

the class ResourceEditorView method initCommandMapAndNameToClassLookup.

private static void initCommandMapAndNameToClassLookup(final Map<String, String> nameToClassLookup, final Map<String, Integer> commandMap, final List<Integer> unhandledCommands, final List<String[]> actionComponentNames, final Map<String, String> allComponents) {
    // register the proper handlers for the component types used
    UIBuilderOverride.registerCustom();
    PickMIDlet.getCustomComponents();
    for (String currentResourceName : loadedResources.getUIResourceNames()) {
        final String currentName = currentResourceName;
        UIBuilder b = new UIBuilder() {

            protected com.codename1.ui.Command createCommand(String commandName, com.codename1.ui.Image icon, int commandId, String action) {
                if (unhandledCommands != null) {
                    if (action == null) {
                        unhandledCommands.add(commandId);
                    }
                }
                // we already have that command id...
                if (commandMap.values().contains(commandId)) {
                    removeCommandDups(commandMap, commandId);
                }
                if (commandName == null || commandName.length() == 0) {
                    commandName = "Command" + commandId;
                }
                commandName = normalizeFormName(currentName) + normalizeFormName(commandName);
                commandMap.put(commandName, commandId);
                return super.createCommand(commandName, icon, commandId, action);
            }

            public boolean caseInsensitiveContainsKey(String s) {
                return caseInsensitiveKey(s) != null;
            }

            public String caseInsensitiveKey(String s) {
                for (String k : allComponents.keySet()) {
                    if (k.equalsIgnoreCase(s)) {
                        return k;
                    }
                }
                return null;
            }

            public void postCreateComponent(com.codename1.ui.Component cmp) {
                if (allComponents != null) {
                    String name = cmp.getName();
                    String componentClass = cmp.getClass().getName();
                    if (allComponents.containsKey(name)) {
                        if (!componentClass.equals(allComponents.get(name))) {
                            allComponents.put(name, "com.codename1.ui.Component");
                        } else {
                            allComponents.put(name, componentClass);
                        }
                    } else {
                        if (!caseInsensitiveContainsKey(name)) {
                            allComponents.put(name, componentClass);
                        }
                    }
                }
                com.codename1.ui.Component actual = cmp;
                if (cmp instanceof com.codename1.ui.Container) {
                    actual = ((com.codename1.ui.Container) cmp).getLeadComponent();
                    if (actual == null) {
                        actual = cmp;
                    }
                }
                if (actionComponentNames != null && (actual instanceof com.codename1.ui.Button || actual instanceof com.codename1.ui.List || actual instanceof com.codename1.ui.list.ContainerList || actual instanceof com.codename1.ui.TextArea || actual instanceof com.codename1.ui.Calendar)) {
                    if (actual instanceof com.codename1.ui.Button) {
                        if (((com.codename1.ui.Button) actual).getCommand() != null) {
                            return;
                        }
                    }
                    String componentName = cmp.getName();
                    for (String[] arr : actionComponentNames) {
                        if (arr[0].equals(componentName) && arr[1].equals(currentName)) {
                            return;
                        }
                    }
                    actionComponentNames.add(new String[] { componentName, currentName });
                }
            }

            protected com.codename1.ui.Component createComponentInstance(String componentType, Class cls) {
                if (cls.getName().startsWith("com.codename1.ui.")) {
                    // subpackage of CodenameOne should be registered
                    if (cls.getName().lastIndexOf(".") > 15) {
                        nameToClassLookup.put(componentType, cls.getName());
                    }
                } else {
                    nameToClassLookup.put(componentType, cls.getName());
                }
                return null;
            }
        };
        b.createContainer(loadedResources, currentResourceName);
    }
}
Also used : JTextArea(javax.swing.JTextArea) UIBuilder(com.codename1.ui.util.UIBuilder) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) List(java.util.List) JList(javax.swing.JList) Component(java.awt.Component)

Example 17 with List

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

the class ResourceEditorApp method generateResourceFile.

private static void generateResourceFile(File f, String themeName, String ui) throws Exception {
    System.out.println("Generating resource file " + f + " theme " + themeName + " template " + ui);
    EditableResources res = new EditableResources();
    // "native", "leather", "tzone", "tipster", "blank"
    String template = "Native_Theme";
    if (themeName.equalsIgnoreCase("leather")) {
        template = "Leather";
    }
    if (themeName.equalsIgnoreCase("chrome")) {
        template = "Chrome";
    }
    if (themeName.equalsIgnoreCase("tzone")) {
        template = "tzone_theme";
    }
    if (themeName.equalsIgnoreCase("tipster")) {
        template = "tipster_theme";
    }
    if (themeName.equalsIgnoreCase("socialboo")) {
        template = "socialboo";
    }
    if (themeName.equalsIgnoreCase("mapper")) {
        template = "mapper";
    }
    if (themeName.equalsIgnoreCase("flatblue")) {
        template = "FlatBlueTheme";
    }
    if (themeName.equalsIgnoreCase("flatred")) {
        template = "FlatRedTheme";
    }
    if (themeName.equalsIgnoreCase("flatorange")) {
        template = "FlatOrangeTheme";
    }
    if (themeName.equalsIgnoreCase("business")) {
        template = "BusinessTheme";
    }
    res.setTheme("Theme", importRes(res, template));
    if ("HiWorld".equalsIgnoreCase(ui)) {
        importRes(res, "HiWorldTemplate");
        generate(res, f);
    } else {
        if ("Tabs".equalsIgnoreCase(ui)) {
            importRes(res, "Tabs");
            generate(res, f);
        } else {
            if ("List".equalsIgnoreCase(ui)) {
                importRes(res, "ListOfItems");
                generate(res, f);
            } else {
                if ("NewHi".equalsIgnoreCase(ui)) {
                    importImage("android-icon.png", res);
                    importImage("apple-icon.png", res);
                    importImage("windows-icon.png", res);
                    importImage("duke-no-logos.png", res);
                    Map m = res.getTheme("Theme");
                    m.put("GetStarted.fgColor", "ffffff");
                    m.put("GetStarted.sel#fgColor", "ffffff");
                    m.put("GetStarted.press#fgColor", "ffffff");
                    m.put("GetStarted.bgColor", "339900");
                    m.put("GetStarted.sel#bgColor", "339900");
                    m.put("GetStarted.press#bgColor", "339900");
                    m.put("GetStarted.transparency", "255");
                    m.put("GetStarted.sel#transparency", "255");
                    m.put("GetStarted.press#transparency", "255");
                    Integer centerAlign = new Integer(4);
                    m.put("GetStarted.align", centerAlign);
                    m.put("GetStarted.sel#align", centerAlign);
                    m.put("GetStarted.press#align", centerAlign);
                    m.put("GetStarted.padding", "1,1,1,1");
                    m.put("GetStarted.padUnit", new byte[] { Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS });
                    m.put("GetStarted.sel#padding", "1,1,1,1");
                    m.put("GetStarted.sel#padUnit", new byte[] { Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS });
                    m.put("GetStarted.press#padding", "1,1,1,1");
                    m.put("GetStarted.press#padUnit", new byte[] { Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS });
                    m.put("GetStarted.font", new EditorTTFFont("native:MainLight", 3, 2.5f, Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM)));
                }
            }
        }
    }
    FileOutputStream os = new FileOutputStream(f);
    res.save(os);
    os.close();
}
Also used : EditorTTFFont(com.codename1.ui.EditorTTFFont) FileOutputStream(java.io.FileOutputStream) EditableResources(com.codename1.ui.util.EditableResources) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with List

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

the class Import9Patch method create9Patch.

// GEN-LAST:event_okButtonActionPerformed
private void create9Patch(List<BufferedImage> biList, List<Integer> densities) {
    List<com.codename1.ui.EncodedImage> topLeftCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> topRightCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> bottomLeftCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> bottomRightCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> centerCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> topImageCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> bottomImageCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> leftImageCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> rightImageCodenameOne = new ArrayList<EncodedImage>();
    for (BufferedImage bi : biList) {
        int left = 0;
        for (int x = 0; x < bi.getWidth(); x++) {
            int pixel = bi.getRGB(x, 0);
            if ((pixel & 0xff000000) == 0xff000000) {
                break;
            }
            left++;
        }
        int right = 0;
        for (int x = bi.getWidth() - 1; x > 0; x--) {
            int pixel = bi.getRGB(x, 0);
            if ((pixel & 0xff000000) == 0xff000000) {
                break;
            }
            right++;
        }
        int top = 0;
        for (int y = 0; y < bi.getHeight(); y++) {
            int pixel = bi.getRGB(0, y);
            if ((pixel & 0xff000000) == 0xff000000) {
                break;
            }
            top++;
        }
        int bottom = 0;
        for (int y = bi.getHeight() - 1; y > 0; y--) {
            int pixel = bi.getRGB(0, y);
            if ((pixel & 0xff000000) == 0xff000000) {
                break;
            }
            bottom++;
        }
        bi = bi.getSubimage(1, 1, bi.getWidth() - 2, bi.getHeight() - 2);
        top--;
        bottom--;
        left--;
        right--;
        BufferedImage topLeft = bi.getSubimage(0, 0, left, top);
        BufferedImage topRight = bi.getSubimage(bi.getWidth() - right, 0, right, top);
        BufferedImage bottomLeft = bi.getSubimage(0, bi.getHeight() - bottom, left, bottom);
        BufferedImage bottomRight = bi.getSubimage(bi.getWidth() - right, bi.getHeight() - bottom, right, bottom);
        BufferedImage center = bi.getSubimage(left, top, bi.getWidth() - right - left, bi.getHeight() - bottom - top);
        BufferedImage topImage = bi.getSubimage(left, 0, bi.getWidth() - left - right, top);
        BufferedImage bottomImage = bi.getSubimage(left, bi.getHeight() - bottom, bi.getWidth() - left - right, bottom);
        BufferedImage leftImage = bi.getSubimage(0, top, left, bi.getHeight() - top - bottom);
        BufferedImage rightImage = bi.getSubimage(bi.getWidth() - right, top, right, bi.getHeight() - top - bottom);
        topLeftCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(topLeft)));
        topRightCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(topRight)));
        bottomLeftCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(bottomLeft)));
        bottomRightCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(bottomRight)));
        centerCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(center)));
        topImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(topImage)));
        bottomImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(bottomImage)));
        leftImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(leftImage)));
        rightImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(rightImage)));
    }
    String prefix = (String) uiidCombo.getSelectedItem() + ".";
    switch(styleState.getSelectedIndex()) {
        case 1:
            prefix += "sel#";
            break;
        case 2:
            prefix += "press#";
            break;
        case 3:
            prefix += "dis#";
            break;
    }
    com.codename1.ui.EncodedImage topLeftCodenameOneE = storeImage(topLeftCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage topRightCodenameOneE = storeImage(topRightCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage bottomLeftCodenameOneE = storeImage(bottomLeftCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage bottomRightCodenameOneE = storeImage(bottomRightCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage centerCodenameOneE = storeImage(centerCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage topImageCodenameOneE = storeImage(topImageCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage bottomImageCodenameOneE = storeImage(bottomImageCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage leftImageCodenameOneE = storeImage(leftImageCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage rightImageCodenameOneE = storeImage(rightImageCodenameOne, densities, prefix + " ");
    com.codename1.ui.plaf.Border b = com.codename1.ui.plaf.Border.createImageScaledBorder(topImageCodenameOneE, bottomImageCodenameOneE, leftImageCodenameOneE, rightImageCodenameOneE, topLeftCodenameOneE, topRightCodenameOneE, bottomLeftCodenameOneE, bottomRightCodenameOneE, centerCodenameOneE);
    Hashtable newTheme = new Hashtable(res.getTheme(theme));
    newTheme.put(prefix + "border", b);
    res.setTheme(theme, newTheme);
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage) EncodedImage(com.codename1.ui.EncodedImage)

Example 19 with List

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

the class BorderEditor method updateBorder.

private void updateBorder(boolean updateEnabled) {
    if (updateEnabled) {
        okButton.setEnabled(true);
        for (JComponent c : comboSelectionEnabled[0]) {
            c.setEnabled(false);
        }
        if (borderType.getSelectedIndex() > 1) {
            List<JComponent> colorElements = colorComponents;
            if (borderType.getSelectedIndex() == 6 && !imageMode.isSelected()) {
                colorElements = new ArrayList<JComponent>();
            } else {
                if (borderType.getSelectedIndex() < 6 && !themeColors.isSelected()) {
                    colorElements = new ArrayList<JComponent>();
                } else {
                    if (borderType.getSelectedIndex() > 6) {
                        colorElements = new ArrayList<JComponent>();
                    }
                }
            }
            for (JComponent c : comboSelectionEnabled[borderType.getSelectedIndex()]) {
                // if colors arrive from the theme then don't enable any color related element
                c.setEnabled(!colorElements.contains(c));
            }
        }
    }
    if (borderType.getSelectedIndex() == borderType.getItemCount() - 2) {
        // we need to use a special case because a theme with no images will have a different offset for the border
        currentBorder = RoundBorder.create().color(getColor(backgroundColor)).opacity(((Number) opacity.getValue()).intValue()).rectangle(isRectangle.isSelected()).shadowBlur(((Number) shadowBlur.getValue()).floatValue()).shadowOpacity(((Number) shadowOpacity.getValue()).intValue()).shadowSpread(((Number) shadowSpread.getValue()).intValue()).shadowX(((Number) shadowX.getValue()).floatValue()).shadowY(((Number) shadowY.getValue()).floatValue()).stroke(((Number) strokeThickness.getValue()).floatValue(), strokeMillimeter.isSelected()).strokeColor(getColor(strokeColor)).strokeOpacity(((Number) strokeOpacity.getValue()).intValue());
    } else {
        if (borderType.getSelectedIndex() == borderType.getItemCount() - 1) {
            // we need to use a special case because a theme with no images will have a different offset for the border
            currentBorder = RoundRectBorder.create().shadowBlur(((Number) rrShadowBlur.getValue()).floatValue()).shadowOpacity(((Number) rrShadowOpacity.getValue()).intValue()).shadowSpread(((Number) rrShadowSpread.getValue()).floatValue()).shadowX(((Number) rrShadowX.getValue()).floatValue()).shadowY(((Number) rrShadowY.getValue()).floatValue()).stroke(((Number) rrStrokeThickness.getValue()).floatValue(), rrStrokeMillimeter.isSelected()).strokeColor(getColor(rrStrokeColor)).strokeOpacity(((Number) rrStrokeOpacity.getValue()).intValue()).bezierCorners(rrBezier.isSelected()).cornerRadius(((Number) rrRadius.getValue()).floatValue()).bottomOnlyMode(rrMode.getSelectedIndex() == 1).topOnlyMode(rrMode.getSelectedIndex() == 2);
        } else {
            switch(borderType.getSelectedIndex()) {
                case 0:
                    // null border
                    currentBorder = null;
                    break;
                case 1:
                    // empty border
                    currentBorder = Border.getEmpty();
                    break;
                case 2:
                    // bevel border
                    if (themeColors.isSelected()) {
                        if (raisedBorder.isSelected()) {
                            currentBorder = Border.createBevelRaised();
                        } else {
                            currentBorder = Border.createBevelLowered();
                        }
                    } else {
                        if (raisedBorder.isSelected()) {
                            currentBorder = Border.createBevelRaised(getColor(highlightColor), getColor(secondaryHighlightColor), getColor(shadowColor), getColor(secondaryShadowColor));
                        } else {
                            currentBorder = Border.createBevelLowered(getColor(highlightColor), getColor(secondaryHighlightColor), getColor(shadowColor), getColor(secondaryShadowColor));
                        }
                    }
                    break;
                case 3:
                    // etched border
                    if (themeColors.isSelected()) {
                        if (raisedBorder.isSelected()) {
                            currentBorder = Border.createEtchedRaised();
                        } else {
                            currentBorder = Border.createEtchedLowered();
                        }
                    } else {
                        if (raisedBorder.isSelected()) {
                            currentBorder = Border.createEtchedRaised(getColor(highlightColor), getColor(shadowColor));
                        } else {
                            currentBorder = Border.createEtchedLowered(getColor(highlightColor), getColor(shadowColor));
                        }
                    }
                    break;
                case 7:
                    {
                        // this is a theme with no images
                        if (borderType.getItemCount() < 8) {
                            break;
                        }
                        // image border
                        Image c = getButtonImageBorderIcon(this.center);
                        if (imageMode.isSelected()) {
                            currentBorder = Border.createImageBorder(getButtonImageBorderIconNotNull(top), getButtonImageBorderIconNotNull(topLeft), c);
                        } else {
                            currentBorder = Border.createImageBorder(getButtonImageBorderIconNotNull(top), getButtonImageBorderIconNotNull(bottom), getButtonImageBorderIconNotNull(left), getButtonImageBorderIconNotNull(right), getButtonImageBorderIconNotNull(topLeft), getButtonImageBorderIconNotNull(topRight), getButtonImageBorderIconNotNull(bottomLeft), getButtonImageBorderIconNotNull(bottomRight), c);
                        }
                        break;
                    }
                case 8:
                    {
                        Image c = getButtonImageBorderIcon(this.center);
                        currentBorder = Border.createHorizonalImageBorder(getButtonImageBorderIconNotNull(left), getButtonImageBorderIconNotNull(right), c);
                        break;
                    }
                case 9:
                    {
                        Image c = getButtonImageBorderIcon(this.center);
                        currentBorder = Border.createVerticalImageBorder(getButtonImageBorderIconNotNull(top), getButtonImageBorderIconNotNull(bottom), c);
                        break;
                    }
                case 4:
                    // line border
                    if (thicknessMillimeters.isSelected()) {
                        if (themeColors.isSelected()) {
                            currentBorder = Border.createLineBorder(((Number) thickness.getValue()).floatValue());
                        } else {
                            currentBorder = Border.createLineBorder(((Number) thickness.getValue()).floatValue(), getColor(lineColor));
                        }
                    } else {
                        if (themeColors.isSelected()) {
                            currentBorder = Border.createLineBorder(((Number) thickness.getValue()).intValue());
                        } else {
                            currentBorder = Border.createLineBorder(((Number) thickness.getValue()).intValue(), getColor(lineColor));
                        }
                    }
                    break;
                case 5:
                    // underline border
                    if (thicknessMillimeters.isSelected()) {
                        if (themeColors.isSelected()) {
                            currentBorder = Border.createUndelineBorder(((Number) thickness.getValue()).floatValue());
                        } else {
                            currentBorder = Border.createUnderlineBorder(((Number) thickness.getValue()).floatValue(), getColor(lineColor));
                        }
                    } else {
                        if (themeColors.isSelected()) {
                            currentBorder = Border.createUndelineBorder(((Number) thickness.getValue()).intValue());
                        } else {
                            currentBorder = Border.createUnderlineBorder(((Number) thickness.getValue()).intValue(), getColor(lineColor));
                        }
                    }
                    break;
                case 6:
                    // rounded border
                    if (themeColors.isSelected()) {
                        currentBorder = Border.createRoundBorder(((Number) arcWidth.getValue()).intValue(), ((Number) arcHeight.getValue()).intValue());
                    } else {
                        currentBorder = Border.createRoundBorder(((Number) arcWidth.getValue()).intValue(), ((Number) arcHeight.getValue()).intValue(), getColor(lineColor));
                    }
                    break;
            }
        }
    }
    final CodenameOneComponentWrapper w = (CodenameOneComponentWrapper) imageBorderPreview;
    final Border finalBorder = currentBorder;
    final Button b = (Button) w.getCodenameOneComponent();
    Display.getInstance().callSerially(new Runnable() {

        @Override
        public void run() {
            b.clearClientProperties();
            b.setPreferredSize(new com.codename1.ui.geom.Dimension(200, 100));
            b.getAllStyles().setPadding(20, 20, 20, 20);
            b.getAllStyles().setBorder(finalBorder);
            b.getParent().revalidate();
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    w.revalidate();
                }
            });
        }
    });
}
Also used : CodenameOneComponentWrapper(com.codename1.ui.resource.util.CodenameOneComponentWrapper) JComponent(javax.swing.JComponent) Image(com.codename1.ui.Image) Button(com.codename1.ui.Button) JButton(javax.swing.JButton) RoundRectBorder(com.codename1.ui.plaf.RoundRectBorder) RoundBorder(com.codename1.ui.plaf.RoundBorder) Border(com.codename1.ui.plaf.Border)

Example 20 with List

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

the class ImageDownloadService method createImageToFileSystem.

/**
 * Constructs an image request that will automatically populate the given list
 * when the response arrives, it will cache the file locally as a file
 * in the file storage.
 * This assumes the GenericListCellRenderer style of
 * list which relies on a map based model approach.
 *
 * @param url the image URL
 * @param targetList the list that should be updated when the data arrives
 * @param targetOffset the offset within the list to insert the image
 * @param targetKey the key for the map in the target offset
 * @param destFile local file to store the data into the given path
 */
private static void createImageToFileSystem(final String url, final Component targetList, final ListModel targetModel, final int targetOffset, final String targetKey, final String destFile, final Dimension toScale, final byte priority, final Image placeholderImage, final boolean maintainAspectRatio) {
    if (Display.getInstance().isEdt()) {
        Display.getInstance().scheduleBackgroundTask(new Runnable() {

            public void run() {
                createImageToFileSystem(url, targetList, targetModel, targetOffset, targetKey, destFile, toScale, priority, placeholderImage, maintainAspectRatio);
            }
        });
        return;
    }
    // image not found on cache go and download from the url
    ImageDownloadService i = new ImageDownloadService(url, targetList, targetOffset, targetKey);
    i.targetModel = targetModel;
    i.maintainAspectRatio = maintainAspectRatio;
    Image im = cacheImage(null, false, destFile, toScale, placeholderImage, maintainAspectRatio);
    if (im != null) {
        i.setEntryInListModel(targetOffset, im);
        targetList.repaint();
        return;
    }
    i.cacheImages = true;
    i.destinationFile = destFile;
    i.toScale = toScale;
    i.placeholder = placeholderImage;
    i.setPriority(priority);
    i.setFailSilently(true);
    NetworkManager.getInstance().addToQueue(i);
}
Also used : EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image) FileEncodedImage(com.codename1.components.FileEncodedImage) StorageImage(com.codename1.components.StorageImage)

Aggregations

Paint (com.codename1.charts.compat.Paint)26 ArrayList (java.util.ArrayList)24 Component (com.codename1.ui.Component)16 List (com.codename1.ui.List)13 Point (com.codename1.charts.models.Point)11 BorderLayout (com.codename1.ui.layouts.BorderLayout)11 Hashtable (java.util.Hashtable)11 Container (com.codename1.ui.Container)9 ContainerList (com.codename1.ui.list.ContainerList)9 Button (com.codename1.ui.Button)8 List (java.util.List)8 TextArea (com.codename1.ui.TextArea)7 Dimension (com.codename1.ui.geom.Dimension)7 EncodedImage (com.codename1.ui.EncodedImage)6 Label (com.codename1.ui.Label)6 RadioButton (com.codename1.ui.RadioButton)5 ActionListener (com.codename1.ui.events.ActionListener)5 JList (javax.swing.JList)4 FileEncodedImage (com.codename1.components.FileEncodedImage)3 StorageImage (com.codename1.components.StorageImage)3