Search in sources :

Example 1 with CodenameOneComponentWrapper

use of com.codename1.ui.resource.util.CodenameOneComponentWrapper 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 2 with CodenameOneComponentWrapper

use of com.codename1.ui.resource.util.CodenameOneComponentWrapper 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 3 with CodenameOneComponentWrapper

use of com.codename1.ui.resource.util.CodenameOneComponentWrapper in project CodenameOne by codenameone.

the class BorderEditor method updateBorder.

private void updateBorder(boolean updateEnabled) {
    if (updateEnabled) {
        okButton.setEnabled(true);
        for (JComponent c : comboSelectionEnabled[0]) {
            c.setEnabled(false);
        }
        if (borderType.getSelectedIndex() > 1) {
            List<JComponent> colorElements = colorComponents;
            if (borderType.getSelectedIndex() == 6 && !imageMode.isSelected()) {
                colorElements = new ArrayList<JComponent>();
            } else {
                if (borderType.getSelectedIndex() < 6 && !themeColors.isSelected()) {
                    colorElements = new ArrayList<JComponent>();
                } else {
                    if (borderType.getSelectedIndex() > 6) {
                        colorElements = new ArrayList<JComponent>();
                    }
                }
            }
            for (JComponent c : comboSelectionEnabled[borderType.getSelectedIndex()]) {
                // if colors arrive from the theme then don't enable any color related element
                c.setEnabled(!colorElements.contains(c));
            }
        }
    }
    if (borderType.getSelectedIndex() == borderType.getItemCount() - 2) {
        // we need to use a special case because a theme with no images will have a different offset for the border
        currentBorder = RoundBorder.create().color(getColor(backgroundColor)).opacity(((Number) opacity.getValue()).intValue()).rectangle(isRectangle.isSelected()).shadowBlur(((Number) shadowBlur.getValue()).floatValue()).shadowOpacity(((Number) shadowOpacity.getValue()).intValue()).shadowSpread(((Number) shadowSpread.getValue()).intValue()).shadowX(((Number) shadowX.getValue()).floatValue()).shadowY(((Number) shadowY.getValue()).floatValue()).stroke(((Number) strokeThickness.getValue()).floatValue(), strokeMillimeter.isSelected()).strokeColor(getColor(strokeColor)).strokeOpacity(((Number) strokeOpacity.getValue()).intValue());
    } else {
        if (borderType.getSelectedIndex() == borderType.getItemCount() - 1) {
            // we need to use a special case because a theme with no images will have a different offset for the border
            currentBorder = RoundRectBorder.create().shadowBlur(((Number) rrShadowBlur.getValue()).floatValue()).shadowOpacity(((Number) rrShadowOpacity.getValue()).intValue()).shadowSpread(((Number) rrShadowSpread.getValue()).floatValue()).shadowX(((Number) rrShadowX.getValue()).floatValue()).shadowY(((Number) rrShadowY.getValue()).floatValue()).stroke(((Number) rrStrokeThickness.getValue()).floatValue(), rrStrokeMillimeter.isSelected()).strokeColor(getColor(rrStrokeColor)).strokeOpacity(((Number) rrStrokeOpacity.getValue()).intValue()).bezierCorners(rrBezier.isSelected()).cornerRadius(((Number) rrRadius.getValue()).floatValue()).bottomOnlyMode(rrMode.getSelectedIndex() == 1).topOnlyMode(rrMode.getSelectedIndex() == 2);
        } else {
            switch(borderType.getSelectedIndex()) {
                case 0:
                    // null border
                    currentBorder = null;
                    break;
                case 1:
                    // empty border
                    currentBorder = Border.getEmpty();
                    break;
                case 2:
                    // bevel border
                    if (themeColors.isSelected()) {
                        if (raisedBorder.isSelected()) {
                            currentBorder = Border.createBevelRaised();
                        } else {
                            currentBorder = Border.createBevelLowered();
                        }
                    } else {
                        if (raisedBorder.isSelected()) {
                            currentBorder = Border.createBevelRaised(getColor(highlightColor), getColor(secondaryHighlightColor), getColor(shadowColor), getColor(secondaryShadowColor));
                        } else {
                            currentBorder = Border.createBevelLowered(getColor(highlightColor), getColor(secondaryHighlightColor), getColor(shadowColor), getColor(secondaryShadowColor));
                        }
                    }
                    break;
                case 3:
                    // etched border
                    if (themeColors.isSelected()) {
                        if (raisedBorder.isSelected()) {
                            currentBorder = Border.createEtchedRaised();
                        } else {
                            currentBorder = Border.createEtchedLowered();
                        }
                    } else {
                        if (raisedBorder.isSelected()) {
                            currentBorder = Border.createEtchedRaised(getColor(highlightColor), getColor(shadowColor));
                        } else {
                            currentBorder = Border.createEtchedLowered(getColor(highlightColor), getColor(shadowColor));
                        }
                    }
                    break;
                case 7:
                    {
                        // this is a theme with no images
                        if (borderType.getItemCount() < 8) {
                            break;
                        }
                        // image border
                        Image c = getButtonImageBorderIcon(this.center);
                        if (imageMode.isSelected()) {
                            currentBorder = Border.createImageBorder(getButtonImageBorderIconNotNull(top), getButtonImageBorderIconNotNull(topLeft), c);
                        } else {
                            currentBorder = Border.createImageBorder(getButtonImageBorderIconNotNull(top), getButtonImageBorderIconNotNull(bottom), getButtonImageBorderIconNotNull(left), getButtonImageBorderIconNotNull(right), getButtonImageBorderIconNotNull(topLeft), getButtonImageBorderIconNotNull(topRight), getButtonImageBorderIconNotNull(bottomLeft), getButtonImageBorderIconNotNull(bottomRight), c);
                        }
                        break;
                    }
                case 8:
                    {
                        Image c = getButtonImageBorderIcon(this.center);
                        currentBorder = Border.createHorizonalImageBorder(getButtonImageBorderIconNotNull(left), getButtonImageBorderIconNotNull(right), c);
                        break;
                    }
                case 9:
                    {
                        Image c = getButtonImageBorderIcon(this.center);
                        currentBorder = Border.createVerticalImageBorder(getButtonImageBorderIconNotNull(top), getButtonImageBorderIconNotNull(bottom), c);
                        break;
                    }
                case 4:
                    // line border
                    if (thicknessMillimeters.isSelected()) {
                        if (themeColors.isSelected()) {
                            currentBorder = Border.createLineBorder(((Number) thickness.getValue()).floatValue());
                        } else {
                            currentBorder = Border.createLineBorder(((Number) thickness.getValue()).floatValue(), getColor(lineColor));
                        }
                    } else {
                        if (themeColors.isSelected()) {
                            currentBorder = Border.createLineBorder(((Number) thickness.getValue()).intValue());
                        } else {
                            currentBorder = Border.createLineBorder(((Number) thickness.getValue()).intValue(), getColor(lineColor));
                        }
                    }
                    break;
                case 5:
                    // underline border
                    if (thicknessMillimeters.isSelected()) {
                        if (themeColors.isSelected()) {
                            currentBorder = Border.createUndelineBorder(((Number) thickness.getValue()).floatValue());
                        } else {
                            currentBorder = Border.createUnderlineBorder(((Number) thickness.getValue()).floatValue(), getColor(lineColor));
                        }
                    } else {
                        if (themeColors.isSelected()) {
                            currentBorder = Border.createUndelineBorder(((Number) thickness.getValue()).intValue());
                        } else {
                            currentBorder = Border.createUnderlineBorder(((Number) thickness.getValue()).intValue(), getColor(lineColor));
                        }
                    }
                    break;
                case 6:
                    // rounded border
                    if (themeColors.isSelected()) {
                        currentBorder = Border.createRoundBorder(((Number) arcWidth.getValue()).intValue(), ((Number) arcHeight.getValue()).intValue());
                    } else {
                        currentBorder = Border.createRoundBorder(((Number) arcWidth.getValue()).intValue(), ((Number) arcHeight.getValue()).intValue(), getColor(lineColor));
                    }
                    break;
            }
        }
    }
    final CodenameOneComponentWrapper w = (CodenameOneComponentWrapper) imageBorderPreview;
    final Border finalBorder = currentBorder;
    final Button b = (Button) w.getCodenameOneComponent();
    Display.getInstance().callSerially(new Runnable() {

        @Override
        public void run() {
            b.clearClientProperties();
            b.setPreferredSize(new com.codename1.ui.geom.Dimension(200, 100));
            b.getAllStyles().setPadding(20, 20, 20, 20);
            b.getAllStyles().setBorder(finalBorder);
            b.getParent().revalidate();
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    w.revalidate();
                }
            });
        }
    });
}
Also used : CodenameOneComponentWrapper(com.codename1.ui.resource.util.CodenameOneComponentWrapper) JComponent(javax.swing.JComponent) Image(com.codename1.ui.Image) Button(com.codename1.ui.Button) JButton(javax.swing.JButton) RoundRectBorder(com.codename1.ui.plaf.RoundRectBorder) RoundBorder(com.codename1.ui.plaf.RoundBorder) Border(com.codename1.ui.plaf.Border)

Aggregations

Border (com.codename1.ui.plaf.Border)3 CodenameOneComponentWrapper (com.codename1.ui.resource.util.CodenameOneComponentWrapper)3 Button (com.codename1.ui.Button)1 EditorFont (com.codename1.ui.EditorFont)1 EditorTTFFont (com.codename1.ui.EditorTTFFont)1 Font (com.codename1.ui.Font)1 Image (com.codename1.ui.Image)1 RoundBorder (com.codename1.ui.plaf.RoundBorder)1 RoundRectBorder (com.codename1.ui.plaf.RoundRectBorder)1 BorderLayout (java.awt.BorderLayout)1 StringTokenizer (java.util.StringTokenizer)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 JDialog (javax.swing.JDialog)1