Search in sources :

Example 11 with Name

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

the class ResourceEditorView method initCommandMapAndNameToClassLookup.

private static void initCommandMapAndNameToClassLookup(final Map<String, String> nameToClassLookup, final Map<String, Integer> commandMap, final List<Integer> unhandledCommands, final List<String[]> actionComponentNames, final Map<String, String> allComponents) {
    // register the proper handlers for the component types used
    UIBuilderOverride.registerCustom();
    PickMIDlet.getCustomComponents();
    for (String currentResourceName : loadedResources.getUIResourceNames()) {
        final String currentName = currentResourceName;
        UIBuilder b = new UIBuilder() {

            protected com.codename1.ui.Command createCommand(String commandName, com.codename1.ui.Image icon, int commandId, String action) {
                if (unhandledCommands != null) {
                    if (action == null) {
                        unhandledCommands.add(commandId);
                    }
                }
                // we already have that command id...
                if (commandMap.values().contains(commandId)) {
                    removeCommandDups(commandMap, commandId);
                }
                if (commandName == null || commandName.length() == 0) {
                    commandName = "Command" + commandId;
                }
                commandName = normalizeFormName(currentName) + normalizeFormName(commandName);
                commandMap.put(commandName, commandId);
                return super.createCommand(commandName, icon, commandId, action);
            }

            public boolean caseInsensitiveContainsKey(String s) {
                return caseInsensitiveKey(s) != null;
            }

            public String caseInsensitiveKey(String s) {
                for (String k : allComponents.keySet()) {
                    if (k.equalsIgnoreCase(s)) {
                        return k;
                    }
                }
                return null;
            }

            public void postCreateComponent(com.codename1.ui.Component cmp) {
                if (allComponents != null) {
                    String name = cmp.getName();
                    String componentClass = cmp.getClass().getName();
                    if (allComponents.containsKey(name)) {
                        if (!componentClass.equals(allComponents.get(name))) {
                            allComponents.put(name, "com.codename1.ui.Component");
                        } else {
                            allComponents.put(name, componentClass);
                        }
                    } else {
                        if (!caseInsensitiveContainsKey(name)) {
                            allComponents.put(name, componentClass);
                        }
                    }
                }
                com.codename1.ui.Component actual = cmp;
                if (cmp instanceof com.codename1.ui.Container) {
                    actual = ((com.codename1.ui.Container) cmp).getLeadComponent();
                    if (actual == null) {
                        actual = cmp;
                    }
                }
                if (actionComponentNames != null && (actual instanceof com.codename1.ui.Button || actual instanceof com.codename1.ui.List || actual instanceof com.codename1.ui.list.ContainerList || actual instanceof com.codename1.ui.TextArea || actual instanceof com.codename1.ui.Calendar)) {
                    if (actual instanceof com.codename1.ui.Button) {
                        if (((com.codename1.ui.Button) actual).getCommand() != null) {
                            return;
                        }
                    }
                    String componentName = cmp.getName();
                    for (String[] arr : actionComponentNames) {
                        if (arr[0].equals(componentName) && arr[1].equals(currentName)) {
                            return;
                        }
                    }
                    actionComponentNames.add(new String[] { componentName, currentName });
                }
            }

            protected com.codename1.ui.Component createComponentInstance(String componentType, Class cls) {
                if (cls.getName().startsWith("com.codename1.ui.")) {
                    // subpackage of CodenameOne should be registered
                    if (cls.getName().lastIndexOf(".") > 15) {
                        nameToClassLookup.put(componentType, cls.getName());
                    }
                } else {
                    nameToClassLookup.put(componentType, cls.getName());
                }
                return null;
            }
        };
        b.createContainer(loadedResources, currentResourceName);
    }
}
Also used : JTextArea(javax.swing.JTextArea) UIBuilder(com.codename1.ui.util.UIBuilder) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) List(java.util.List) JList(javax.swing.JList) Component(java.awt.Component)

Example 12 with Name

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

the class AddAndScaleMultiImage method initSpinner.

private void initSpinner(final JSpinner s, final String name, int defaultVal) {
    int val = Preferences.userNodeForPackage(ResourceEditorView.class).getInt(name, defaultVal);
    s.setModel(new SpinnerNumberModel(val, 0, 3000, 1));
    s.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            int val = ((Number) s.getValue()).intValue();
            if (val >= 0 && val <= 3000) {
                Preferences.userNodeForPackage(ResourceEditorView.class).putInt(name, val);
            }
        }
    });
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) ChangeEvent(javax.swing.event.ChangeEvent) ResourceEditorView(com.codename1.designer.ResourceEditorView) ChangeListener(javax.swing.event.ChangeListener)

Example 13 with Name

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

the class AddThemeEntry method setKeyValue.

private void setKeyValue(String key, Object value) {
    int pos = key.indexOf(".");
    String attr;
    if (pos > -1) {
        componentName.setSelectedItem(key.substring(0, pos));
        attr = key.substring(pos + 1, key.length());
    } else {
        componentName.setSelectedIndex(0);
        attr = key;
    }
    pos = attr.indexOf('#');
    if (pos > -1) {
        attr = attr.substring(pos + 1);
    }
    if (attr.indexOf("fgColor") > -1) {
        deriveForegroundColor.setSelected(false);
        highlightTab(1);
        changeColorButtonFG.setEnabled(true);
        colorValueFG.setEnabled(true);
        if (value instanceof String) {
            colorValueFG.setText((String) value);
        } else {
            colorValueFG.setText(Integer.toHexString(((Number) value).intValue()));
        }
        return;
    }
    if (attr.indexOf("bgColor") > -1) {
        deriveBackgroundColor.setSelected(false);
        highlightTab(1);
        changeColorButtonBG.setEnabled(true);
        colorValueBG.setEnabled(true);
        if (value instanceof String) {
            colorValueBG.setText((String) value);
        } else {
            colorValueBG.setText(Integer.toHexString(((Number) value).intValue()));
        }
        return;
    }
    if (attr.indexOf("derive") > -1) {
        highlightTab(6);
        baseStyle.setEnabled(true);
        baseStyleType.setEnabled(true);
        defineAttribute.setSelected(false);
        String baseItemValue = (String) value;
        int keyPos = baseItemValue.indexOf('.');
        if (keyPos < 0) {
            baseStyle.setSelectedItem(baseItemValue);
        } else {
            String b = baseItemValue.substring(0, keyPos);
            String k = baseItemValue.substring(keyPos + 1);
            baseStyle.setSelectedItem(b);
            if (k.equals("sel")) {
                baseStyleType.setSelectedIndex(1);
                return;
            }
            if (k.equals("press")) {
                baseStyleType.setSelectedIndex(2);
                return;
            }
            if (k.equals("dis")) {
                baseStyleType.setSelectedIndex(3);
                return;
            }
        }
        return;
    }
    if (attr.indexOf("align") > -1) {
        highlightTab(2);
        deriveAlignment.setSelected(false);
        alignmentCombo.setEnabled(true);
        switch(((Number) value).intValue()) {
            case com.codename1.ui.Component.LEFT:
                alignmentCombo.setSelectedIndex(0);
                break;
            case com.codename1.ui.Component.RIGHT:
                alignmentCombo.setSelectedIndex(1);
                break;
            case com.codename1.ui.Component.CENTER:
                alignmentCombo.setSelectedIndex(2);
                break;
        }
        return;
    }
    if (attr.indexOf("textDecoration") > -1) {
        highlightTab(7);
        deriveTextDecoration.setSelected(false);
        textDecorationCombo.setEnabled(true);
        switch(((Number) value).intValue()) {
            case com.codename1.ui.plaf.Style.TEXT_DECORATION_UNDERLINE:
                textDecorationCombo.setSelectedIndex(1);
                break;
            case com.codename1.ui.plaf.Style.TEXT_DECORATION_STRIKETHRU:
                textDecorationCombo.setSelectedIndex(2);
                break;
            case com.codename1.ui.plaf.Style.TEXT_DECORATION_3D:
                textDecorationCombo.setSelectedIndex(3);
                break;
            case com.codename1.ui.plaf.Style.TEXT_DECORATION_3D_LOWERED:
                textDecorationCombo.setSelectedIndex(4);
                break;
            default:
                textDecorationCombo.setSelectedIndex(0);
                break;
        }
        return;
    }
    if (attr.indexOf("border") > -1) {
        highlightTab(5);
        customizeBorder.setEnabled(true);
        deriveBorder.setSelected(false);
        borderLabel.setText(Accessor.toString((Border) value));
        ((CodenameOneComponentWrapper) borderLabel).getCodenameOneComponent().getStyle().setBorder((Border) value);
        borderLabel.repaint();
        if (value != null && value instanceof Border) {
            currentBorder = (Border) value;
        } else {
            currentBorder = Border.getDefaultBorder();
        }
        return;
    }
    if (attr.indexOf("font") > -1) {
        highlightTab(7);
        Font font = (Font) value;
        deriveFont.setSelected(false);
        systemFont.setEnabled(true);
        bitmapFont.setEnabled(true);
        if (resources.getFontResourceNames() != null) {
            for (String fontName : resources.getFontResourceNames()) {
                if (font == resources.getFont(fontName)) {
                    // this is a bitmap font
                    bitmapFont.setSelected(true);
                    bitmapFontValue.setEnabled(true);
                    addNewBitmapFont.setEnabled(true);
                    bitmapFontValue.setSelectedItem(fontName);
                    return;
                }
            }
        }
        // this is a system font
        systemFont.setSelected(true);
        fontFace.setEnabled(true);
        fontSize.setEnabled(true);
        fontStyle.setEnabled(true);
        trueTypeFont.setEnabled(trueTypeFont.getModel().getSize() > 0);
        trueTypeFontSizeOption.setEnabled(trueTypeFont.getModel().getSize() > 0);
        trueTypeFontSizeValue.setEnabled(trueTypeFont.getModel().getSize() > 0);
        fontFace.setSelectedIndex(getSystemFontOffset(font.getFace(), FONT_FACE_VALUES));
        fontSize.setSelectedIndex(getSystemFontOffset(font.getSize(), FONT_SIZE_VALUES));
        fontStyle.setSelectedIndex(getSystemFontOffset(font.getStyle(), FONT_STYLE_VALUES));
        if (font instanceof EditorTTFFont) {
            EditorTTFFont ed = (EditorTTFFont) font;
            if (ed.getFontFile() != null) {
                trueTypeFont.setSelectedItem(ed.getFontFile().getName());
                trueTypeFontSizeOption.setSelectedIndex(ed.getSizeSetting());
                trueTypeFontSizeValue.setValue(new Double(ed.getActualSize()));
            } else {
                if (ed.getNativeFontName() != null) {
                    trueTypeFont.setSelectedItem(ed.getNativeFontName());
                    trueTypeFontSizeOption.setSelectedIndex(ed.getSizeSetting());
                    trueTypeFontSizeValue.setValue(new Double(ed.getActualSize()));
                }
            }
        }
        return;
    }
    if (attr.indexOf("bgImage") > -1) {
        highlightTab(0);
        updateBackgroundAttribute();
        for (int iter = 0; iter < imagesCombo.getModel().getSize(); iter++) {
            String name = (String) imagesCombo.getModel().getElementAt(iter);
            if (value == resources.getImage(name)) {
                imagesCombo.setSelectedItem(name);
                return;
            }
        }
        return;
    }
    if (attr.indexOf("transparency") > -1) {
        highlightTab(1);
        deriveTransparency.setSelected(false);
        transparencyValue.setEnabled(true);
        transparencyValue.setValue(Integer.valueOf((String) value));
        return;
    }
    if (attr.indexOf("padding") > -1) {
        highlightTab(3);
        derivePadding.setSelected(false);
        paddingBottom.setEnabled(true);
        paddingTop.setEnabled(true);
        paddingLeft.setEnabled(true);
        paddingRight.setEnabled(true);
        paddingBottomUnit.setEnabled(true);
        paddingTopUnit.setEnabled(true);
        paddingLeftUnit.setEnabled(true);
        paddingRightUnit.setEnabled(true);
        StringTokenizer tokenizer = new StringTokenizer((String) value, ", ");
        paddingTop.setValue(Float.parseFloat(tokenizer.nextToken()));
        paddingBottom.setValue(Float.parseFloat(tokenizer.nextToken()));
        paddingLeft.setValue(Float.parseFloat(tokenizer.nextToken()));
        paddingRight.setValue(Float.parseFloat(tokenizer.nextToken()));
        return;
    }
    if (attr.indexOf("padUnit") > -1) {
        byte[] padUnit = (byte[]) value;
        paddingBottomUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.BOTTOM]);
        paddingTopUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.TOP]);
        paddingLeftUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.LEFT]);
        paddingRightUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.RIGHT]);
        return;
    }
    if (attr.indexOf("margin") > -1) {
        highlightTab(4);
        deriveMargin.setSelected(false);
        marginBottom.setEnabled(true);
        marginTop.setEnabled(true);
        marginLeft.setEnabled(true);
        marginRight.setEnabled(true);
        marginBottomUnit.setEnabled(true);
        marginTopUnit.setEnabled(true);
        marginLeftUnit.setEnabled(true);
        marginRightUnit.setEnabled(true);
        StringTokenizer tokenizer = new StringTokenizer((String) value, ", ");
        marginTop.setValue(Float.parseFloat(tokenizer.nextToken()));
        marginBottom.setValue(Float.parseFloat(tokenizer.nextToken()));
        marginLeft.setValue(Float.parseFloat(tokenizer.nextToken()));
        marginRight.setValue(Float.parseFloat(tokenizer.nextToken()));
        return;
    }
    if (attr.indexOf("marUnit") > -1) {
        byte[] padUnit = (byte[]) value;
        marginBottomUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.BOTTOM]);
        marginTopUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.TOP]);
        marginLeftUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.LEFT]);
        marginRightUnit.setSelectedIndex(padUnit[com.codename1.ui.Component.RIGHT]);
        return;
    }
    if (attr.indexOf("bgType") > -1) {
        highlightTab(0);
        updateBackgroundAttribute();
        byte bgType = ((Byte) value).byteValue();
        for (int iter = 0; iter < BACKGROUND_VALUES.length; iter++) {
            if (bgType == BACKGROUND_VALUES[iter]) {
                backgroundType.setSelectedIndex(iter);
                break;
            }
        }
        return;
    }
    if (attr.indexOf("bgGradient") > -1) {
        highlightTab(0);
        updateBackgroundAttribute();
        Object[] gradient = (Object[]) value;
        gradientStartColor.setText(Integer.toHexString(((Number) gradient[0]).intValue()));
        gradientEndColor.setText(Integer.toHexString(((Number) gradient[1]).intValue()));
        if (gradient.length > 2) {
            gradientX.setValue(new Double(((Number) gradient[2]).doubleValue()));
            gradientY.setValue(new Double(((Number) gradient[3]).doubleValue()));
            if (gradient.length > 4) {
                gradientSize.setValue(new Double(((Number) gradient[4]).doubleValue()));
            }
        }
        return;
    }
}
Also used : CodenameOneComponentWrapper(com.codename1.ui.resource.util.CodenameOneComponentWrapper) EditorTTFFont(com.codename1.ui.EditorTTFFont) EditorFont(com.codename1.ui.EditorFont) Font(com.codename1.ui.Font) EditorTTFFont(com.codename1.ui.EditorTTFFont) StringTokenizer(java.util.StringTokenizer) Border(com.codename1.ui.plaf.Border)

Example 14 with Name

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

the class AddThemeEntry method imageBorderWizardActionPerformed.

// GEN-LAST:event_deriveTextDecorationActionPerformed
private void imageBorderWizardActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_imageBorderWizardActionPerformed
    deriveBorder.setSelected(false);
    ImageBorderWizardTabbedPane iw = new ImageBorderWizardTabbedPane(resources, themeName);
    String name = (String) componentName.getSelectedItem();
    String uiid;
    if (prefix == null || prefix.length() == 0) {
        uiid = name + ".border";
    } else {
        uiid = name + "." + prefix + "border";
    }
    iw.addToAppliesToList(uiid);
    JDialog dlg = new JDialog(SwingUtilities.windowForComponent(this));
    dlg.setLayout(new java.awt.BorderLayout());
    dlg.add(java.awt.BorderLayout.CENTER, iw);
    dlg.pack();
    dlg.setLocationRelativeTo(this);
    dlg.setModal(true);
    dlg.setVisible(true);
    Border b = (Border) resources.getTheme(themeName).get(uiid);
    if (b != null) {
        currentBorder = b;
        ((CodenameOneComponentWrapper) borderLabel).getCodenameOneComponent().getStyle().setBorder(b);
        borderLabel.repaint();
    }
}
Also used : CodenameOneComponentWrapper(com.codename1.ui.resource.util.CodenameOneComponentWrapper) BorderLayout(java.awt.BorderLayout) Border(com.codename1.ui.plaf.Border) JDialog(javax.swing.JDialog)

Example 15 with Name

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

the class AddThemeEntry method addNewImageActionPerformed.

// GEN-LAST:event_imagesComboActionPerformed
private void addNewImageActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_addNewImageActionPerformed
    AddResourceDialog addResource = new AddResourceDialog(resources, AddResourceDialog.IMAGE, false);
    if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(this, addResource, "Select Name", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) {
        addResource.addResource(resources, null);
        initImagesCombo();
    }
}
Also used : AddResourceDialog(com.codename1.designer.AddResourceDialog)

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