Search in sources :

Example 26 with Name

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

the class UserInterfaceEditor method createCustomComponentButton.

private void createCustomComponentButton(final CustomComponent c) {
    try {
        final JButton b = new JButton(c.getType());
        b.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jdesktop/swingx/resources/placeholder32.png")));
        b.setHorizontalAlignment(SwingConstants.LEFT);
        b.setBorder(null);
        userComponents.add(b);
        b.putClientProperty("CustomComponent", c);
        final Class codenameOneBaseClass = c.getCls();
        makeDraggable(b, codenameOneBaseClass, c.getType(), c);
        b.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (lockForDragging) {
                    lockForDragging = false;
                    return;
                }
                try {
                    if (c.isUiResource()) {
                        UIBuilderOverride u = new UIBuilderOverride();
                        com.codename1.ui.Component cmp = u.createContainer(res, c.getType());
                        String t = (String) cmp.getClientProperty(TYPE_KEY);
                        if (t == null) {
                            cmp.putClientProperty(TYPE_KEY, c.getType());
                            t = c.getType();
                        }
                        addComponentToContainer(cmp, t);
                        return;
                    }
                    com.codename1.ui.Component cmp = (com.codename1.ui.Component) codenameOneBaseClass.newInstance();
                    cmp.putClientProperty("CustomComponent", c);
                    cmp.putClientProperty(TYPE_KEY, c.getType());
                    initializeComponentText(cmp);
                    addComponentToContainer(cmp, c.getType());
                } catch (Exception err) {
                    err.printStackTrace();
                    JOptionPane.showMessageDialog(UserInterfaceEditor.this, err.getClass().getName() + ": " + err, "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
    /*b.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    if(BaseForm.isRightClick(e)) {
                        JPopupMenu p = new JPopupMenu();
                        AbstractAction deleteAction = new AbstractAction("Delete") {
                            public void actionPerformed(ActionEvent e) {
                                componentPalette.remove(b);
                                componentPalette.revalidate();
                                customComponents.remove(c);
                                res.setUi(name, persistContainer(containerInstance));
                            }
                        };
                        p.add(deleteAction);
                        p.show(b, e.getPoint().x, e.getPoint().y);
                    }
                }
            });*/
    } catch (Exception err) {
        err.printStackTrace();
        JOptionPane.showMessageDialog(UserInterfaceEditor.this, err.getClass().getName() + ": " + err, "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ActionListener(java.awt.event.ActionListener) ImageIcon(javax.swing.ImageIcon) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 27 with Name

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

the class UserInterfaceEditor method addComponentToContainer.

private void addComponentToContainer(com.codename1.ui.Component c, String name) {
    if (c instanceof com.codename1.ui.Label || c instanceof com.codename1.ui.TextArea) {
        setPropertyModified(c, PROPERTY_TEXT);
    }
    c.putClientProperty(TYPE_KEY, name);
    c.setName(findUniqueName(name));
    com.codename1.ui.Container destContainer = containerInstance;
    if (componentHierarchy.getSelectionPath() != null) {
        com.codename1.ui.Component cmp = (com.codename1.ui.Component) componentHierarchy.getSelectionPath().getLastPathComponent();
        if (isActualContainer(cmp)) {
            destContainer = (com.codename1.ui.Container) cmp;
        } else {
            destContainer = cmp.getParent();
        }
    }
    if (destContainer instanceof com.codename1.ui.Tabs) {
        ((com.codename1.ui.Tabs) destContainer).addTab("Tab", c);
    } else {
        if (destContainer.getLayout() instanceof com.codename1.ui.layouts.BorderLayout) {
            destContainer.addComponent(findAvailableSpotInBorderLayout(destContainer), c);
        } else {
            destContainer.addComponent(c);
        }
    }
    containerInstance.revalidate();
    destContainer.revalidate();
    /*int[] index = new int[] {componentHierarchy.getModel().getIndexOfChild(c.getParent(), c)};
        Object[] children = new Object[] {c};
        c = c.getParent();
        Object[] path = pathToComponent(c);
        if(path != null && path.length > 0) {
            ((ComponentHierarchyModel)componentHierarchy.getModel()).fireTreeNodesInserted(
                    new TreeModelEvent(componentHierarchy.getModel(), new TreePath(path), index, children));
            uiPreview.repaint();
            saveUI();
        }*/
    ((ComponentHierarchyModel) componentHierarchy.getModel()).fireTreeStructureChanged(new TreeModelEvent(componentHierarchy.getModel(), new TreePath(componentHierarchy.getModel().getRoot())));
    uiPreview.repaint();
    saveUI();
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) BorderLayout(com.codename1.ui.layouts.BorderLayout) TreePath(javax.swing.tree.TreePath) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 28 with Name

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

the class EditableResources method setMultiImage.

public void setMultiImage(final String name, final MultiImage value) {
    // we need to replace the image in all the themes...
    final Object oldValue = getResourceObject(name);
    pushUndoable(new UndoableEdit() {

        @Override
        protected String performAction() {
            replaceThemeValue(oldValue, value);
            setResource(name, MAGIC_IMAGE, value);
            return name;
        }

        @Override
        protected String performUndo() {
            replaceThemeValue(value, value);
            setResource(name, MAGIC_IMAGE, oldValue);
            return name;
        }
    });
}
Also used : AnimationObject(com.codename1.ui.animations.AnimationObject)

Example 29 with Name

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

the class EditableResources method setSVGDPIs.

public void setSVGDPIs(final String name, final int[] dpi, final int[] widths, final int[] heights) {
    final SVG sv = (SVG) getImage(name).getSVGDocument();
    final int[] currentDPIs = sv.getDpis();
    final int[] currentWidths = sv.getWidthForDPI();
    final int[] currentHeights = sv.getHeightForDPI();
    pushUndoable(new UndoableEdit() {

        @Override
        protected String performAction() {
            sv.setDpis(dpi);
            sv.setWidthForDPI(widths);
            sv.setHeightForDPI(heights);
            return name;
        }

        @Override
        protected String performUndo() {
            sv.setDpis(currentDPIs);
            sv.setWidthForDPI(currentWidths);
            sv.setHeightForDPI(currentHeights);
            return name;
        }
    });
}
Also used : SVG(com.codename1.impl.javase.SVG)

Example 30 with Name

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

the class EditableResources method setImage.

public void setImage(final String name, final com.codename1.ui.Image value) {
    if (overrideResource != null) {
        overrideResource.setImage(name, value);
        return;
    }
    // we need to replace the image in all the themes...
    final com.codename1.ui.Image oldValue = getImage(name);
    byte type;
    if (value instanceof Timeline) {
        type = MAGIC_TIMELINE;
    } else {
        type = MAGIC_IMAGE;
    }
    final byte finalType = type;
    pushUndoable(new UndoableEdit() {

        @Override
        protected String performAction() {
            replaceThemeValue(oldValue, value);
            setResource(name, finalType, value);
            return name;
        }

        @Override
        protected String performUndo() {
            replaceThemeValue(value, oldValue);
            setResource(name, finalType, oldValue);
            return name;
        }
    });
}
Also used : Timeline(com.codename1.ui.animations.Timeline) Image(com.codename1.ui.Image)

Aggregations

IOException (java.io.IOException)36 Component (com.codename1.ui.Component)17 Hashtable (java.util.Hashtable)17 ArrayList (java.util.ArrayList)16 AnimationObject (com.codename1.ui.animations.AnimationObject)15 File (java.io.File)14 Form (com.codename1.ui.Form)13 ByteArrayInputStream (java.io.ByteArrayInputStream)13 FileInputStream (java.io.FileInputStream)13 InputStream (java.io.InputStream)12 Label (com.codename1.ui.Label)11 Button (com.codename1.ui.Button)10 Container (com.codename1.ui.Container)10 EncodedImage (com.codename1.ui.EncodedImage)10 TextArea (com.codename1.ui.TextArea)10 BorderLayout (com.codename1.ui.layouts.BorderLayout)10 Point (java.awt.Point)10 FileOutputStream (java.io.FileOutputStream)10 Paint (android.graphics.Paint)8 BufferedInputStream (com.codename1.io.BufferedInputStream)7