Search in sources :

Example 31 with Timeline

use of com.codename1.ui.animations.Timeline 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 32 with Timeline

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

the class CodenameOneImageRenderer method paintComponent.

@Override
public void paintComponent(Graphics g) {
    g.setColor(new Color(CheckerBoardColorCalibration.getColorA()));
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(new Color(CheckerBoardColorCalibration.getColorB()));
    int width = getWidth();
    int height = getHeight();
    for (int x = 0; x < width; x += 8) {
        if (x % 16 == 0) {
            for (int y = 0; y < height; y += 16) {
                g.fillRect(x, y, 8, 8);
            }
        } else {
            for (int y = 8; y < height; y += 16) {
                g.fillRect(x, y, 8, 8);
            }
        }
    }
    if (drawBorder) {
        g.setColor(Color.BLACK);
        g.drawRect(0, 0, image.getWidth() + 1, image.getHeight() + 1);
    }
    if (zoom != 1) {
        ((Graphics2D) g).scale(zoom, zoom);
    }
    if (animationObjectList != null) {
        if (((Timeline) image).isPause()) {
            int selectedRow = animationObjectList.getSelectedRow();
            AnimationObject sel = null;
            if (selectedRow > -1) {
                sel = ((TimelineEditor.AnimationObjectTableModel) animationObjectList.getModel()).getElementAt(selectedRow);
            }
            if (dragging != null) {
                if (draggingImage == null) {
                    draggingImage = new BufferedImage(AnimationAccessor.getWidthInt(dragging), AnimationAccessor.getHeightInt(dragging), BufferedImage.TYPE_INT_ARGB);
                    draggingImage.setRGB(0, 0, draggingImage.getWidth(), draggingImage.getHeight(), AnimationAccessor.getImageMethod(dragging).modifyAlpha((byte) 110).getRGB(), 0, draggingImage.getWidth());
                }
            } else {
                draggingImage = null;
            }
            if (sel != null) {
                Graphics2D g2d = (Graphics2D) g.create();
                g2d.drawImage(buffer[currentFrame], 0, 0, this);
                g2d.setColor(Color.BLUE);
                g2d.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                g2d.drawRect(AnimationAccessor.getX(sel), AnimationAccessor.getY(sel), AnimationAccessor.getWidthInt(sel), AnimationAccessor.getHeightInt(sel));
                if (draggingImage != null) {
                    g2d.drawImage(draggingImage, dragX, dragY, null);
                }
                g2d.dispose();
                return;
            }
        }
    }
    g.drawImage(buffer[currentFrame], 0, 0, this);
    if (draggingImage != null) {
        g.drawImage(draggingImage, dragX, dragY, null);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Timeline(com.codename1.ui.animations.Timeline) Color(java.awt.Color) AnimationObject(com.codename1.ui.animations.AnimationObject) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

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