Search in sources :

Example 86 with com.codename1.rad.models

use of com.codename1.rad.models in project CodenameOne by codenameone.

the class TimelineEditor method cloneCurrentTimeline.

// </editor-fold>//GEN-END:initComponents
private Timeline cloneCurrentTimeline() {
    Timeline t = (Timeline) res.getImage(name);
    AnimationObject[] arr = new AnimationObject[t.getAnimationCount()];
    for (int iter = 0; iter < arr.length; iter++) {
        arr[iter] = t.getAnimation(iter);
    }
    Timeline nt = Timeline.createTimeline(getValue(duration), arr, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
    nt.setPause(t.isPause());
    nt.setTime(t.getTime());
    return nt;
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

Example 87 with com.codename1.rad.models

use of com.codename1.rad.models in project CodenameOne by codenameone.

the class TimelineEditor method moveUpActionPerformed.

// GEN-LAST:event_duplicateObjectActionPerformed
private void moveUpActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_moveUpActionPerformed
    int i = animationObjectList.getSelectedRow();
    Timeline t = cloneCurrentTimeline();
    AnimationObject[] animations = new AnimationObject[t.getAnimationCount()];
    for (int iter = 0; iter < animations.length; iter++) {
        animations[iter] = t.getAnimation(iter);
    }
    AnimationObject o = animations[i - 1];
    animations[i - 1] = animations[i];
    animations[i] = o;
    Timeline nt = Timeline.createTimeline(getValue(duration), animations, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
    nt.setPause(t.isPause());
    setImage(nt);
    moveUp.setEnabled(i > 1);
    moveDown.setEnabled(true);
    animationObjectList.getSelectionModel().setSelectionInterval(i - 1, i - 1);
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

Example 88 with com.codename1.rad.models

use of com.codename1.rad.models 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 89 with com.codename1.rad.models

use of com.codename1.rad.models in project CodenameOne by codenameone.

the class TimelineEditor method selectFile.

/**
 * Selects a gif file using a file chooser and converts it to a timeline
 */
public static void selectFile(ResourceEditorView view, EditableResources res, String timelineName) {
    File[] files = ResourceEditorView.showOpenFileChooser("Images", ".gif");
    if (files != null) {
        File sel = files[0];
        if (timelineName == null) {
            timelineName = sel.getName();
        }
        Preferences.userNodeForPackage(view.getClass()).put("lastDir", sel.getParentFile().getAbsolutePath());
        ImageReader iReader = ImageIO.getImageReadersBySuffix("gif").next();
        try {
            iReader.setInput(ImageIO.createImageInputStream(new FileInputStream(sel)));
            int frames = iReader.getNumImages(true);
            AnimationObject[] anims = new AnimationObject[frames];
            int currentTime = 0;
            for (int frameIter = 0; frameIter < frames; frameIter++) {
                BufferedImage currentImage = iReader.read(frameIter);
                ByteArrayOutputStream bo = new ByteArrayOutputStream();
                ImageIO.write(currentImage, "png", bo);
                bo.close();
                // create a PNG image in the resource file
                String label = sel.getName() + " frame:" + frameIter;
                EncodedImage i = EncodedImage.create(bo.toByteArray());
                res.setImage(label, i);
                int duration = Math.max(40, AnimationImpl.getFrameTime(iReader, frameIter));
                Point pos = AnimationImpl.getPixelOffsets(iReader, frameIter);
                anims[frameIter] = AnimationObject.createAnimationImage(i, pos.x, pos.y);
                anims[frameIter].setStartTime(currentTime);
                anims[frameIter].setEndTime(100000000);
                String disposeMethod = getDisposalMethod(iReader, frameIter);
                if (disposeMethod != null) {
                    if ("restoreToBackgroundColor".equals(disposeMethod)) {
                        if (frameIter + 1 < frames) {
                            int t = Math.max(40, AnimationImpl.getFrameTime(iReader, frameIter + 1));
                            anims[frameIter].setEndTime(currentTime + t);
                        } else {
                            anims[frameIter].setEndTime(currentTime + duration);
                        }
                    // for(int iter = frameIter ; iter >= 0 ; iter--) {
                    // anims[iter].setEndTime(currentTime);
                    // }
                    }
                // "none" |
                // "doNotDispose" | "restoreToBackgroundColor" |
                // "restoreToPrevious"
                }
                currentTime += duration;
            }
            Timeline t = Timeline.createTimeline(currentTime, anims, new com.codename1.ui.geom.Dimension(iReader.getWidth(0), iReader.getHeight(0)));
            res.setImage(timelineName, t);
            view.setSelectedResource(timelineName);
        } catch (IOException err) {
            err.printStackTrace();
            JOptionPane.showMessageDialog(JFrame.getFrames()[0], "Error reading file " + err, "IO Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Point(java.awt.Point) IOException(java.io.IOException) EncodedImage(com.codename1.ui.EncodedImage) FileInputStream(java.io.FileInputStream) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) ImageReader(javax.imageio.ImageReader) File(java.io.File)

Example 90 with com.codename1.rad.models

use of com.codename1.rad.models in project CodenameOne by codenameone.

the class UserInterfaceEditor method appendComponentXMLBody.

private static void appendComponentXMLBody(com.codename1.ui.Container containerInstance, com.codename1.ui.Component cmp, StringBuilder build, EditableResources res, String indent) {
    if (isPropertyModified(cmp, PROPERTY_LAYOUT_CONSTRAINT) || (cmp.getParent() != null && cmp.getParent().getLayout() instanceof com.codename1.ui.layouts.BorderLayout)) {
        if (cmp.getParent() != null && cmp != containerInstance && cmp.getClientProperty("%base_form%") == null) {
            com.codename1.ui.layouts.Layout l = cmp.getParent().getLayout();
            if (l instanceof com.codename1.ui.layouts.BorderLayout) {
                build.append(indent);
                build.append("<layoutConstraint value=\"");
                build.append((String) l.getComponentConstraint(cmp));
                build.append("\" />\n");
            } else {
                if (l instanceof com.codename1.ui.table.TableLayout) {
                    build.append(indent);
                    com.codename1.ui.table.TableLayout.Constraint con = (com.codename1.ui.table.TableLayout.Constraint) l.getComponentConstraint(cmp);
                    build.append("<layoutConstraint row=\"");
                    build.append(getInt("row", con.getClass(), con));
                    build.append("\" column=\"");
                    build.append(getInt("column", con.getClass(), con));
                    build.append("\" height=\"");
                    build.append(getInt("height", con.getClass(), con));
                    build.append("\" width=\"");
                    build.append(getInt("width", con.getClass(), con));
                    build.append("\" align=\"");
                    build.append(getInt("align", con.getClass(), con));
                    build.append("\" spanHorizontal=\"");
                    build.append(getInt("spanHorizontal", con.getClass(), con));
                    build.append("\" valign=\"");
                    build.append(getInt("valign", con.getClass(), con));
                    build.append("\" spanVertical=\"");
                    build.append(getInt("spanVertical", con.getClass(), con));
                    build.append("\" />\n");
                }
            }
        }
    }
    // don't persist children of subclasses like Table etc.
    if (cmp.getClass() == com.codename1.ui.Container.class || cmp instanceof com.codename1.ui.Form || cmp instanceof com.codename1.ui.ComponentGroup) {
        com.codename1.ui.Container cnt = (com.codename1.ui.Container) cmp;
        if (cnt instanceof com.codename1.ui.Form) {
            cnt = ((com.codename1.ui.Form) cnt).getContentPane();
        }
        for (int iter = 0; iter < cnt.getComponentCount(); iter++) {
            persistToXML(containerInstance, cnt.getComponentAt(iter), build, res, indent);
        }
    }
    if (cmp instanceof com.codename1.ui.List && !(cmp instanceof com.codename1.components.RSSReader)) {
        com.codename1.ui.List lst = (com.codename1.ui.List) cmp;
        for (int iter = 0; iter < lst.getModel().getSize(); iter++) {
            Object o = lst.getModel().getItemAt(iter);
            appendMapOrString(o, build, indent, res);
        }
    }
    if (isPropertyModified(cmp, PROPERTY_CUSTOM)) {
        for (String propName : cmp.getPropertyNames()) {
            if (isCustomPropertyModified(cmp, propName) && !propName.startsWith("$")) {
                build.append(indent);
                build.append("<custom name=\"");
                build.append(propName);
                Class type = getPropertyCustomType(cmp, propName);
                Object value = cmp.getPropertyValue(propName);
                if (value == null) {
                    build.append("\" />\n");
                    continue;
                }
                if (type.isArray()) {
                    // 2d array
                    if (type.getComponentType().isArray()) {
                        build.append("\" type=\"");
                        build.append(type.getComponentType().getComponentType().getName());
                        build.append("\" array=\"true\" dimensions=\"2");
                    } else {
                        build.append("\" type=\"");
                        build.append(type.getComponentType().getName());
                        build.append("\" array=\"true\" dimensions=\"1");
                    }
                } else {
                    build.append("\" type=\"");
                    build.append(type.getName());
                }
                build.append("\" ");
                if (type == String.class) {
                    build.append("value=\"");
                    build.append(xmlize((String) value));
                    build.append("\" />\n");
                    continue;
                }
                if (type == String[].class) {
                    build.append(">\n");
                    String[] result = (String[]) value;
                    for (int i = 0; i < result.length; i++) {
                        build.append(indent);
                        build.append("  ");
                        build.append("<str>");
                        build.append(xmlize(result[i]));
                        build.append("</str>\n");
                    }
                    build.append(indent);
                    build.append("</custom>\n");
                    continue;
                }
                if (type == String[][].class) {
                    String[][] result = (String[][]) value;
                    build.append(">\n");
                    for (int i = 0; i < result.length; i++) {
                        build.append(indent);
                        build.append("  ");
                        build.append("<arr>");
                        for (int j = 0; j < result[i].length; j++) {
                            build.append(indent);
                            build.append("    ");
                            build.append("<str>");
                            build.append(xmlize(result[i][j]));
                            build.append("</str>\n");
                        }
                        build.append(indent);
                        build.append("  ");
                        build.append("</arr>\n");
                    }
                    build.append(indent);
                    build.append("</custom>\n");
                    continue;
                }
                if (type == Integer.class) {
                    build.append("value=\"");
                    build.append(((Number) value).intValue());
                    build.append("\" />\n");
                    continue;
                }
                if (type == Long.class) {
                    build.append("value=\"");
                    build.append(((Number) value).longValue());
                    build.append("\" />\n");
                    continue;
                }
                if (type == Double.class) {
                    build.append("value=\"");
                    build.append(((Number) value).doubleValue());
                    build.append("\" />\n");
                    continue;
                }
                if (type == Date.class) {
                    build.append("value=\"");
                    build.append(((Date) value).getTime());
                    build.append("\" />\n");
                    continue;
                }
                if (type == Float.class) {
                    build.append("value=\"");
                    build.append(((Number) value).floatValue());
                    build.append("\" />\n");
                    continue;
                }
                if (type == Byte.class) {
                    build.append("value=\"");
                    build.append(((Number) value).byteValue());
                    build.append("\" />\n");
                    continue;
                }
                if (type == Boolean.class) {
                    build.append("value=\"");
                    build.append(((Boolean) value).booleanValue());
                    build.append("\" />\n");
                    continue;
                }
                if (type == com.codename1.ui.Image[].class) {
                    com.codename1.ui.Image[] result = (com.codename1.ui.Image[]) value;
                    build.append(">\n");
                    for (int i = 0; i < result.length; i++) {
                        build.append(indent);
                        build.append("  ");
                        if (result[i] == null) {
                            build.append("<str/>\n");
                        } else {
                            String id = res.findId(result[i]);
                            if (id == null) {
                                build.append("<str/>\n");
                            } else {
                                build.append("<str>");
                                build.append(xmlize(id));
                                build.append("</str>\n");
                            }
                        }
                    }
                    build.append(indent);
                    build.append("</custom>\n");
                    continue;
                }
                if (type == com.codename1.ui.Image.class) {
                    com.codename1.ui.Image result = (com.codename1.ui.Image) value;
                    String id = res.findId(result);
                    if (id != null) {
                        build.append("value=\"");
                        build.append(xmlize(id));
                    }
                    build.append("\" />\n");
                    continue;
                }
                if (type == com.codename1.ui.Container.class) {
                    build.append("value=\"");
                    build.append(xmlize(((com.codename1.ui.Container) value).getName()));
                    build.append("\" />\n");
                    continue;
                }
                if (type == com.codename1.ui.list.CellRenderer.class) {
                    com.codename1.ui.list.GenericListCellRenderer g = (com.codename1.ui.list.GenericListCellRenderer) value;
                    if (g.getSelectedEven() == null) {
                        build.append(" selectedRenderer=\"");
                        build.append(xmlize(g.getSelected().getName()));
                        build.append("\" unselectedRenderer=\"");
                        build.append(xmlize(g.getUnselected().getName()));
                        build.append("\" ");
                    } else {
                        build.append(" selectedRenderer=\"");
                        build.append(xmlize(g.getSelected().getName()));
                        build.append("\" unselectedRenderer=\"");
                        build.append(xmlize(g.getUnselected().getName()));
                        build.append(" selectedRendererEven=\"");
                        build.append(xmlize(g.getSelectedEven().getName()));
                        build.append("\" unselectedRendererEven=\"");
                        build.append(xmlize(g.getUnselectedEven().getName()));
                        build.append("\" ");
                    }
                    build.append("\" />\n");
                    continue;
                }
                if (type == Object[].class) {
                    build.append(">\n");
                    Object[] arr = (Object[]) value;
                    for (int iter = 0; iter < arr.length; iter++) {
                        Object o = arr[iter];
                        appendMapOrString(o, build, indent, res);
                    }
                    build.append(indent);
                    build.append("</custom>\n");
                    continue;
                }
                // none of the above then its a char
                build.append("value=\"");
                build.append(xmlize("" + ((Character) value).charValue()));
                build.append("\" />\n");
            }
        }
    }
}
Also used : EmbeddedContainer(com.codename1.ui.util.EmbeddedContainer) BorderLayout(com.codename1.ui.layouts.BorderLayout) ArrayList(java.util.ArrayList) List(java.util.List) JList(javax.swing.JList) TableLayout(com.codename1.ui.table.TableLayout) Hashtable(java.util.Hashtable) BorderLayout(com.codename1.ui.layouts.BorderLayout) Point(java.awt.Point) EventObject(java.util.EventObject)

Aggregations

IOException (java.io.IOException)34 EncodedImage (com.codename1.ui.EncodedImage)28 ArrayList (java.util.ArrayList)27 Point (java.awt.Point)25 File (java.io.File)24 AnimationObject (com.codename1.ui.animations.AnimationObject)22 BufferedImage (java.awt.image.BufferedImage)22 Hashtable (java.util.Hashtable)19 Component (com.codename1.ui.Component)18 Form (com.codename1.ui.Form)18 Image (com.codename1.ui.Image)16 EditableResources (com.codename1.ui.util.EditableResources)16 FileInputStream (java.io.FileInputStream)16 Timeline (com.codename1.ui.animations.Timeline)15 BorderLayout (com.codename1.ui.layouts.BorderLayout)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)11 FileOutputStream (java.io.FileOutputStream)10 AttributedString (java.text.AttributedString)10 EditorFont (com.codename1.ui.EditorFont)9