Search in sources :

Example 21 with Timeline

use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.

the class EditableResources method writeTimeline.

private void writeTimeline(DataOutputStream output, Timeline t) throws IOException {
    output.writeInt(t.getDuration());
    output.writeInt(t.getSize().getWidth());
    output.writeInt(t.getSize().getHeight());
    AnimationObject[] animations = new AnimationObject[t.getAnimationCount()];
    output.writeShort(animations.length);
    for (int iter = 0; iter < animations.length; iter++) {
        animations[iter] = t.getAnimation(iter);
        String name = AnimationAccessor.getImageName(animations[iter]);
        if (name == null) {
            name = findId(AnimationAccessor.getImage(animations[iter]));
        }
        output.writeUTF(name);
        int startTime = animations[iter].getStartTime();
        int animDuration = animations[iter].getEndTime() - startTime;
        output.writeInt(startTime);
        output.writeInt(animDuration);
        Motion motionX = AnimationAccessor.getMotionX(animations[iter]);
        Motion motionY = AnimationAccessor.getMotionY(animations[iter]);
        output.writeInt(motionX.getSourceValue());
        output.writeInt(motionY.getSourceValue());
        int frameDelay = AnimationAccessor.getFrameDelay(animations[iter]);
        output.writeInt(frameDelay);
        if (frameDelay > -1) {
            output.writeInt(AnimationAccessor.getFrameWidth(animations[iter]));
            output.writeInt(AnimationAccessor.getFrameHeight(animations[iter]));
        }
        if (motionX.getSourceValue() != motionX.getDestinationValue()) {
            output.writeBoolean(true);
            output.writeInt(AnimationAccessor.getMotionType(motionX));
            output.writeInt(motionX.getDestinationValue());
        } else {
            output.writeBoolean(false);
        }
        if (motionY.getSourceValue() != motionY.getDestinationValue()) {
            output.writeBoolean(true);
            output.writeInt(AnimationAccessor.getMotionType(motionY));
            output.writeInt(motionY.getDestinationValue());
        } else {
            output.writeBoolean(false);
        }
        writeMotion(AnimationAccessor.getWidth(animations[iter]), output);
        writeMotion(AnimationAccessor.getHeight(animations[iter]), output);
        writeMotion(AnimationAccessor.getOpacity(animations[iter]), output);
        writeMotion(AnimationAccessor.getOrientation(animations[iter]), output);
    }
}
Also used : Motion(com.codename1.ui.animations.Motion) AnimationObject(com.codename1.ui.animations.AnimationObject)

Example 22 with Timeline

use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.

the class ImageRGBEditor method findImageUseImpl.

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

Example 23 with Timeline

use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.

the class ResourceEditorView method removeImageOrAnimation.

private void removeImageOrAnimation(String resourceToRemove) {
    Object resourceValue = loadedResources.getImage(resourceToRemove);
    if (!loadedResources.isOverrideMode()) {
        for (String themeName : loadedResources.getThemeResourceNames()) {
            Hashtable theme = loadedResources.getTheme(themeName);
            if (theme.values().contains(resourceValue)) {
                JOptionPane.showMessageDialog(mainPanel, "Image is in use by the theme" + "\nYou must remove it from the theme first", "Image In Use", JOptionPane.ERROR_MESSAGE);
                return;
            }
            // we need to check the existance of image borders to replace images there...
            for (Object v : theme.values()) {
                if (v instanceof Border) {
                    Border b = (Border) v;
                    // BORDER_TYPE_IMAGE
                    if (Accessor.getType(b) == 8) {
                        com.codename1.ui.Image[] images = Accessor.getImages(b);
                        for (int i = 0; i < images.length; i++) {
                            if (images[i] == resourceValue) {
                                JOptionPane.showMessageDialog(mainPanel, "Image is in use by the theme in a border" + "\nYou must remove it from the theme first", "Image In Use", JOptionPane.ERROR_MESSAGE);
                                return;
                            }
                        }
                    }
                }
            }
        }
        // check if a timeline is making use of said image and replace it
        for (String image : loadedResources.getImageResourceNames()) {
            com.codename1.ui.Image current = loadedResources.getImage(image);
            if (current instanceof com.codename1.ui.animations.Timeline) {
                com.codename1.ui.animations.Timeline time = (com.codename1.ui.animations.Timeline) current;
                for (int iter = 0; iter < time.getAnimationCount(); iter++) {
                    com.codename1.ui.animations.AnimationObject o = time.getAnimation(iter);
                    if (AnimationAccessor.getImage(o) == resourceValue) {
                        JOptionPane.showMessageDialog(mainPanel, "Image is in use by a timeline: " + image, "Image In Use", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            }
        }
        if (isInUse(loadedResources.getImage(resourceToRemove))) {
            JOptionPane.showMessageDialog(mainPanel, "Image is in use in the resource file", "Image In Use", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    removeSelection(resourceToRemove);
    imageList.refresh();
    imageListMain.refresh();
    imageListSVG.refresh();
    imageListMulti.refresh();
    imageListTimeline.refresh();
}
Also used : Hashtable(java.util.Hashtable) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage) Timeline(com.codename1.ui.animations.Timeline) Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) AnimationObject(com.codename1.ui.animations.AnimationObject) RoundRectBorder(com.codename1.ui.plaf.RoundRectBorder) RoundBorder(com.codename1.ui.plaf.RoundBorder) Border(com.codename1.ui.plaf.Border)

Example 24 with Timeline

use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.

the class TimelineEditor method removeAnimationObjectActionPerformed.

// GEN-LAST:event_addAnimationObjectActionPerformed
private void removeAnimationObjectActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_removeAnimationObjectActionPerformed
    Timeline t = (Timeline) res.getImage(name);
    AnimationObject[] animations = new AnimationObject[t.getAnimationCount() - 1];
    int offset = 0;
    for (int iter = 0; iter < t.getAnimationCount(); iter++) {
        if (iter != animationObjectList.getSelectedRow()) {
            animations[offset] = t.getAnimation(iter);
            offset++;
        }
    }
    ((AnimationObjectTableModel) animationObjectList.getModel()).remove(animationObjectList.getSelectedRow());
    Timeline nt = Timeline.createTimeline(getValue(duration), animations, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
    nt.setPause(t.isPause());
    setImage(nt);
    animationObjectList.clearSelection();
    duplicateObject.setEnabled(false);
    moveDown.setEnabled(false);
    moveUp.setEnabled(false);
    removeAnimationObject.setEnabled(false);
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

Example 25 with Timeline

use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.

the class TimelineEditor method timelineStateChanged.

// GEN-LAST:event_heightStateChanged
private void timelineStateChanged(javax.swing.event.ChangeEvent evt) {
    // GEN-FIRST:event_timelineStateChanged
    currentTime.setText("" + timeline.getValue());
    if (!refreshingTimelineLock) {
        Timeline t = (Timeline) renderer.getImage();
        t.setPause(false);
        t.setTime(timeline.getValue());
        renderer.updateAnimation();
        t.setPause(true);
    }
}
Also used : Timeline(com.codename1.ui.animations.Timeline)

Aggregations

Timeline (com.codename1.ui.animations.Timeline)23 AnimationObject (com.codename1.ui.animations.AnimationObject)18 EncodedImage (com.codename1.ui.EncodedImage)10 Point (java.awt.Point)9 BufferedImage (java.awt.image.BufferedImage)7 Image (com.codename1.ui.Image)6 Hashtable (java.util.Hashtable)6 Border (com.codename1.ui.plaf.Border)4 RoundBorder (com.codename1.ui.plaf.RoundBorder)4 RoundRectBorder (com.codename1.ui.plaf.RoundRectBorder)4 ArrayList (java.util.ArrayList)3 Component (com.codename1.ui.Component)2 Container (com.codename1.ui.Container)2 EditorFont (com.codename1.ui.EditorFont)2 EditorTTFFont (com.codename1.ui.EditorTTFFont)2 Dimension (com.codename1.ui.geom.Dimension)2 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)2 LegacyFont (com.codename1.ui.util.xml.LegacyFont)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2