Search in sources :

Example 11 with Timeline

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

the class TimelineEditor method pauseActionPerformed.

// GEN-LAST:event_playActionPerformed
private void pauseActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_pauseActionPerformed
    Timeline t = (Timeline) renderer.getImage();
    t.setPause(true);
    play.setEnabled(true);
    pause.setEnabled(false);
    if (refreshTimeline != null) {
        refreshTimeline.stop();
        refreshTimeline = null;
    }
}
Also used : Timeline(com.codename1.ui.animations.Timeline)

Example 12 with Timeline

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

the class ResourceEditorView method isInUse.

/**
 * Returns true if the given image is used by a theme or timeline animation,
 * false otherwise.
 */
private boolean isInUse(String imageName) {
    Object multi = loadedResources.getResourceObject(imageName);
    if (multi instanceof EditableResources.MultiImage) {
        EditableResources.MultiImage m = (EditableResources.MultiImage) multi;
        for (com.codename1.ui.Image i : m.getInternalImages()) {
            if (isInUse(i)) {
                return true;
            }
        }
        return false;
    }
    com.codename1.ui.Image resourceValue = loadedResources.getImage(imageName);
    return isInUse(resourceValue);
}
Also used : AnimationObject(com.codename1.ui.animations.AnimationObject) EditableResources(com.codename1.ui.util.EditableResources)

Example 13 with Timeline

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

the class ResourceEditorView method initImagesComboBox.

/**
 * Creates a sorted image combo box that includes image previews. The combo box
 * can be searched by typing a letter even when images are used for the values...
 */
public static void initImagesComboBox(JComboBox cb, final EditableResources res, boolean asString, final boolean includeNull, boolean blockTimelines) {
    String[] imgs = res.getImageResourceNames();
    if (blockTimelines) {
        List<String> nonT = new ArrayList<String>();
        for (String c : imgs) {
            if (!(res.getImage(c) instanceof Timeline)) {
                nonT.add(c);
            }
        }
        imgs = new String[nonT.size()];
        nonT.toArray(imgs);
    }
    final String[] images = imgs;
    Arrays.sort(images, String.CASE_INSENSITIVE_ORDER);
    if (asString) {
        if (includeNull) {
            String[] n = new String[images.length + 1];
            System.arraycopy(images, 0, n, 1, images.length);
            cb.setModel(new DefaultComboBoxModel(n));
        } else {
            cb.setModel(new DefaultComboBoxModel(images));
        }
        cb.setRenderer(new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                boolean n = false;
                if (value == null) {
                    value = "[null]";
                    n = true;
                }
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (!n) {
                    setIcon(new CodenameOneImageIcon(res.getImage((String) value), 24, 24));
                } else {
                    setIcon(null);
                }
                return this;
            }
        });
    } else {
        int offset = 0;
        com.codename1.ui.Image[] arr;
        if (includeNull) {
            arr = new com.codename1.ui.Image[images.length + 1];
            offset++;
        } else {
            arr = new com.codename1.ui.Image[images.length];
        }
        for (String c : images) {
            arr[offset] = res.getImage(c);
            offset++;
        }
        cb.setModel(new DefaultComboBoxModel(arr));
        cb.setKeySelectionManager(new JComboBox.KeySelectionManager() {

            private String current;

            private long lastPress;

            public int selectionForKey(char aKey, ComboBoxModel aModel) {
                long t = System.currentTimeMillis();
                aKey = Character.toLowerCase(aKey);
                if (t - lastPress < 800) {
                    current += aKey;
                } else {
                    current = "" + aKey;
                }
                lastPress = t;
                for (int iter = 0; iter < images.length; iter++) {
                    if (images[iter].toLowerCase().startsWith(current)) {
                        if (includeNull) {
                            return iter + 1;
                        }
                        return iter;
                    }
                }
                return -1;
            }
        });
        cb.setRenderer(new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                com.codename1.ui.Image i = (com.codename1.ui.Image) value;
                if (value == null) {
                    value = "[null]";
                } else {
                    value = res.findId(value);
                }
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (i != null) {
                    setIcon(new CodenameOneImageIcon(i, 24, 24));
                } else {
                    setIcon(null);
                }
                return this;
            }
        });
    }
}
Also used : JComboBox(javax.swing.JComboBox) ArrayList(java.util.ArrayList) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage) Timeline(com.codename1.ui.animations.Timeline) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) AnimationObject(com.codename1.ui.animations.AnimationObject) Component(java.awt.Component) UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) JList(javax.swing.JList) ComboBoxModel(javax.swing.ComboBoxModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 14 with Timeline

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

the class CodenameOneImageRenderer method mouseClicked.

public void mouseClicked(MouseEvent e) {
    Timeline t = (Timeline) image;
    AnimationObject selection = t.getAnimationAt(e.getX(), e.getY());
    // editing
    if (selection == null) {
        animationObjectList.clearSelection();
    } else {
        if (e.getClickCount() == 2) {
            selectValue(selection);
            MouseListener[] ls = animationObjectList.getListeners(MouseListener.class);
            for (MouseListener l : ls) {
                l.mouseClicked(e);
            }
        } else {
            // selection
            selectValue(selection);
        }
    }
    repaint();
}
Also used : Timeline(com.codename1.ui.animations.Timeline) MouseListener(java.awt.event.MouseListener) AnimationObject(com.codename1.ui.animations.AnimationObject)

Example 15 with Timeline

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

the class CodenameOneImageRenderer method mouseReleased.

public void mouseReleased(MouseEvent e) {
    Timeline t = (Timeline) image;
    if (dragging != null && t.isPause()) {
        // if this is a right mouse button update the source position
        editor.updatePosition(e.getX(), e.getY(), dragging, BaseForm.isRightClick(e));
        dragging = null;
    }
    repaint();
}
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