Search in sources :

Example 26 with EditableResources

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

the class PulsateEditor method pulsateWizard.

public void pulsateWizard(EditableResources res, JComponent parent) {
    File[] f = ResourceEditorView.showOpenFileChooser("Image", ".png", ".jpg", ".jpeg", ".gif");
    if (f != null && f.length > 0) {
        try {
            timelineName.setText(f[0].getName());
            sourceImage = ImageIO.read(f[0]);
            updateTimeline();
            timer = new javax.swing.Timer(130, new java.awt.event.ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    if (previewLabel.animate()) {
                        previewLabel.repaint();
                        preview.repaint();
                    }
                }
            });
            timer.setRepeats(true);
            timer.setCoalesce(true);
            timer.start();
            int val = JOptionPane.showConfirmDialog(parent, this, "Edit Effect", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            timer.stop();
            if (val == JOptionPane.OK_OPTION) {
                store(res, currentImage, timelineName.getText() + ": TL ");
                for (EncodedImage img : internalImages) {
                    store(res, img, timelineName.getText() + ": Fr ");
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(parent, "Error in reading image file", "File Read Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) File(java.io.File) EncodedImage(com.codename1.ui.EncodedImage)

Example 27 with EditableResources

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

the class ResourceEditorApp method importRes.

private static Hashtable importRes(EditableResources res, String file) {
    InputStream is = ResourceEditorApp.class.getResourceAsStream("/templates/" + file + ".res");
    Hashtable theme = new Hashtable();
    if (is != null) {
        try {
            EditableResources r = new EditableResources();
            r.openFile(is);
            is.close();
            if (r.getThemeResourceNames().length > 0) {
                theme = r.getTheme(r.getThemeResourceNames()[0]);
            }
            ResourceEditorView.checkDuplicateResourcesLoop(r, res.getImageResourceNames(), r.getImageResourceNames(), "Rename Image", "Image ", true, null);
            ResourceEditorView.checkDuplicateResourcesLoop(r, res.getL10NResourceNames(), r.getL10NResourceNames(), "Rename Localization", "Localization ", true, null);
            ResourceEditorView.checkDuplicateResourcesLoop(r, res.getDataResourceNames(), r.getDataResourceNames(), "Rename Data", "Data ", true, null);
            ResourceEditorView.checkDuplicateResourcesLoop(r, res.getUIResourceNames(), r.getUIResourceNames(), "Rename GUI", "GUI ", true, null);
            ResourceEditorView.checkDuplicateResourcesLoop(r, res.getFontResourceNames(), r.getFontResourceNames(), "Rename Font", "Font ", true, null);
            for (String s : r.getImageResourceNames()) {
                if (r.isMultiImage(s)) {
                    res.setMultiImage(s, (EditableResources.MultiImage) r.getResourceObject(s));
                } else {
                    res.setImage(s, r.getImage(s));
                }
            }
            for (String s : r.getL10NResourceNames()) {
                res.setL10N(s, (Hashtable) r.getResourceObject(s));
            }
            for (String s : r.getDataResourceNames()) {
                res.setData(s, (byte[]) r.getResourceObject(s));
            }
            for (String s : r.getUIResourceNames()) {
                res.setUi(s, (byte[]) r.getResourceObject(s));
            }
            for (String s : r.getFontResourceNames()) {
                res.setFont(s, r.getFont(s));
            }
        } catch (IOException err) {
            err.printStackTrace();
        }
    }
    return theme;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) IOException(java.io.IOException) EditableResources(com.codename1.ui.util.EditableResources)

Example 28 with EditableResources

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

the class ImageTask method addToResources.

@Override
public void addToResources(EditableResources e) throws IOException {
    Image i;
    InputStream input = new FileInputStream(file);
    i = EncodedImage.create(input);
    input.close();
    e.setImage(getName(), i);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage) FileInputStream(java.io.FileInputStream)

Example 29 with EditableResources

use of com.codename1.ui.util.EditableResources 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 EditableResources

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

the class AddThemeResource method addResource.

// GEN-LAST:event_templateActionPerformed
public String addResource(EditableResources res, ResourceEditorView view) {
    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;
        }
    }
    Hashtable theme = new Hashtable();
    InputStream is = getClass().getResourceAsStream("/templates/" + template.getSelectedItem().toString() + ".res");
    if (is != null) {
        try {
            EditableResources r = new EditableResources();
            r.openFile(is);
            is.close();
            theme = r.getTheme(r.getThemeResourceNames()[0]);
            view.checkDuplicateResourcesLoop(r, res.getImageResourceNames(), r.getImageResourceNames(), "Rename Image", "Image ", true);
            view.checkDuplicateResourcesLoop(r, res.getL10NResourceNames(), r.getL10NResourceNames(), "Rename Localization", "Localization ", true);
            view.checkDuplicateResourcesLoop(r, res.getDataResourceNames(), r.getDataResourceNames(), "Rename Data", "Data ", true);
            view.checkDuplicateResourcesLoop(r, res.getUIResourceNames(), r.getUIResourceNames(), "Rename GUI", "GUI ", true);
            view.checkDuplicateResourcesLoop(r, res.getFontResourceNames(), r.getFontResourceNames(), "Rename Font", "Font ", true);
            for (String s : r.getImageResourceNames()) {
                if (r.isMultiImage(s)) {
                    res.setMultiImage(s, (EditableResources.MultiImage) r.getResourceObject(s));
                } else {
                    res.setImage(s, r.getImage(s));
                }
            }
            for (String s : r.getL10NResourceNames()) {
                res.setL10N(s, (Hashtable) r.getResourceObject(s));
            }
            for (String s : r.getDataResourceNames()) {
                res.setData(s, (byte[]) r.getResourceObject(s));
            }
            for (String s : r.getUIResourceNames()) {
                res.setUi(s, (byte[]) r.getResourceObject(s));
            }
            for (String s : r.getFontResourceNames()) {
                res.setFont(s, r.getFont(s));
            }
        } catch (IOException err) {
            err.printStackTrace();
        }
    }
    res.setTheme(name.getText(), theme);
    view.setSelectedResource(name.getText());
    return name.getText();
}
Also used : Hashtable(java.util.Hashtable) InputStream(java.io.InputStream) IOException(java.io.IOException) EditableResources(com.codename1.ui.util.EditableResources)

Aggregations

EditableResources (com.codename1.ui.util.EditableResources)12 IOException (java.io.IOException)12 Hashtable (java.util.Hashtable)11 ArrayList (java.util.ArrayList)10 EncodedImage (com.codename1.ui.EncodedImage)8 File (java.io.File)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)7 AnimationObject (com.codename1.ui.animations.AnimationObject)6 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)6 FileOutputStream (java.io.FileOutputStream)6 Point (java.awt.Point)5 BufferedImage (java.awt.image.BufferedImage)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Container (com.codename1.ui.Container)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 TableLayout (com.codename1.ui.table.TableLayout)4 EmbeddedContainer (com.codename1.ui.util.EmbeddedContainer)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4