Search in sources :

Example 31 with Border

use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.

the class ResourceEditorView method removeImageOrAnimation.

private void removeImageOrAnimation(String resourceToRemove) {
    Object resourceValue = loadedResources.getImage(resourceToRemove);
    if (!loadedResources.isOverrideMode()) {
        for (String themeName : loadedResources.getThemeResourceNames()) {
            Hashtable theme = loadedResources.getTheme(themeName);
            if (theme.values().contains(resourceValue)) {
                JOptionPane.showMessageDialog(mainPanel, "Image is in use by the theme" + "\nYou must remove it from the theme first", "Image In Use", JOptionPane.ERROR_MESSAGE);
                return;
            }
            // we need to check the existance of image borders to replace images there...
            for (Object v : theme.values()) {
                if (v instanceof Border) {
                    Border b = (Border) v;
                    // BORDER_TYPE_IMAGE
                    if (Accessor.getType(b) == 8) {
                        com.codename1.ui.Image[] images = Accessor.getImages(b);
                        for (int i = 0; i < images.length; i++) {
                            if (images[i] == resourceValue) {
                                JOptionPane.showMessageDialog(mainPanel, "Image is in use by the theme in a border" + "\nYou must remove it from the theme first", "Image In Use", JOptionPane.ERROR_MESSAGE);
                                return;
                            }
                        }
                    }
                }
            }
        }
        // check if a timeline is making use of said image and replace it
        for (String image : loadedResources.getImageResourceNames()) {
            com.codename1.ui.Image current = loadedResources.getImage(image);
            if (current instanceof com.codename1.ui.animations.Timeline) {
                com.codename1.ui.animations.Timeline time = (com.codename1.ui.animations.Timeline) current;
                for (int iter = 0; iter < time.getAnimationCount(); iter++) {
                    com.codename1.ui.animations.AnimationObject o = time.getAnimation(iter);
                    if (AnimationAccessor.getImage(o) == resourceValue) {
                        JOptionPane.showMessageDialog(mainPanel, "Image is in use by a timeline: " + image, "Image In Use", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            }
        }
        if (isInUse(loadedResources.getImage(resourceToRemove))) {
            JOptionPane.showMessageDialog(mainPanel, "Image is in use in the resource file", "Image In Use", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    removeSelection(resourceToRemove);
    imageList.refresh();
    imageListMain.refresh();
    imageListSVG.refresh();
    imageListMulti.refresh();
    imageListTimeline.refresh();
}
Also used : Hashtable(java.util.Hashtable) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage) Timeline(com.codename1.ui.animations.Timeline) Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) AnimationObject(com.codename1.ui.animations.AnimationObject) RoundRectBorder(com.codename1.ui.plaf.RoundRectBorder) RoundBorder(com.codename1.ui.plaf.RoundBorder) Border(com.codename1.ui.plaf.Border)

Example 32 with Border

use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.

the class ResourceEditorView method imageBorderWizardMenuItemActionPerformed.

// GEN-LAST:event_addImageTimelineActionPerformed
private void imageBorderWizardMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_imageBorderWizardMenuItemActionPerformed
    String themeName = null;
    if (selectedResource != null) {
        Object o = loadedResources.getResourceObject(selectedResource);
        if (!(o instanceof Hashtable)) {
            JOptionPane.showMessageDialog(mainPanel, "A theme must be selected to use this feature", "Image Border Wizard", JOptionPane.ERROR_MESSAGE);
            return;
        }
        themeName = selectedResource;
    }
    ImageBorderWizardTabbedPane iw = new ImageBorderWizardTabbedPane(loadedResources, themeName);
    JDialog dlg = new JDialog(SwingUtilities.windowForComponent(mainPanel), "Border Wizard");
    dlg.setLayout(new java.awt.BorderLayout());
    dlg.add(java.awt.BorderLayout.CENTER, iw);
    dlg.pack();
    dlg.setLocationRelativeTo(mainPanel);
    dlg.setModal(true);
    dlg.setVisible(true);
    setSelectedResource(selectedResource);
}
Also used : Hashtable(java.util.Hashtable) AnimationObject(com.codename1.ui.animations.AnimationObject) BorderLayout(java.awt.BorderLayout) JDialog(javax.swing.JDialog)

Example 33 with Border

use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.

the class ThemeEditor method findFlushingPropertyContrust.

/**
 * Returns a "contrasting" value for the property to flash, e.g. for a font,
 * return a differnet font or for a color return a ligher/darker color...
 */
private Object findFlushingPropertyContrust() {
    if (flashingProperty.indexOf("Color") > -1) {
        // flash to white or black depending on whether the color is closer to white
        int val = Integer.decode("0x" + originalFlashingPropertyValue);
        if (val > 0xf0f0f0) {
            return "000000";
        } else {
            return "ffffff";
        }
    }
    if (flashingProperty.indexOf("derive") > -1) {
        return "NoPropertyUIIDExists";
    }
    if (flashingProperty.indexOf("font") > -1) {
        // if this is not a bold font then just return a system bold font
        if ((((com.codename1.ui.Font) originalFlashingPropertyValue).getStyle() & com.codename1.ui.Font.STYLE_BOLD) != 0) {
            return com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_LARGE);
        }
        return com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_BOLD, com.codename1.ui.Font.SIZE_LARGE);
    }
    if (flashingProperty.indexOf("bgImage") > -1) {
        com.codename1.ui.Image i = (com.codename1.ui.Image) originalFlashingPropertyValue;
        return i.modifyAlpha((byte) 128);
    }
    if (flashingProperty.indexOf("transparency") > -1) {
        int v = Integer.parseInt((String) originalFlashingPropertyValue);
        if (v < 128) {
            return "255";
        } else {
            return "100";
        }
    }
    /*
         * if(flashingProperty.indexOf("scale") > -1) { return "false"; }
         */
    if (flashingProperty.indexOf("padding") > -1 || flashingProperty.indexOf("margin") > -1) {
        return "10,10,10,10";
    }
    if (flashingProperty.indexOf("border") > -1) {
        if (originalFlashingPropertyValue != null) {
            Border pressed = ((Border) originalFlashingPropertyValue).createPressedVersion();
            if (pressed != null) {
                return pressed;
            }
        }
        return Border.createBevelRaised();
    }
    if (flashingProperty.indexOf("bgType") > -1) {
        return originalFlashingPropertyValue;
    }
    if (flashingProperty.indexOf("bgGradient") > -1) {
        Object[] gradient = new Object[4];
        System.arraycopy(originalFlashingPropertyValue, 0, gradient, 0, 4);
        gradient[0] = ((Object[]) originalFlashingPropertyValue)[1];
        gradient[1] = ((Object[]) originalFlashingPropertyValue)[0];
        return gradient;
    }
    if (flashingProperty.indexOf("align") > -1 || flashingProperty.indexOf("textDecoration") > -1) {
        return originalFlashingPropertyValue;
    }
    throw new IllegalArgumentException("Unsupported property type: " + flashingProperty);
}
Also used : BufferedImage(java.awt.image.BufferedImage) Border(com.codename1.ui.plaf.Border)

Example 34 with Border

use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.

the class List method renderComponent.

/**
 * Renders the current component on the screen
 */
private void renderComponent(Graphics g, Component cmp, int x, int y, int width, int height) {
    Style s = cmp.getStyle();
    int left = s.getMarginLeft(isRTL());
    int top = s.getMarginTop();
    cmp.setWidth(width - left - s.getMarginRight(isRTL()));
    cmp.setHeight(height - top - s.getMarginBottom());
    cmp.setX(x + left);
    cmp.setY(y + top);
    int oX = g.getClipX();
    int oY = g.getClipY();
    int oWidth = g.getClipWidth();
    int oHeight = g.getClipHeight();
    // g.pushClip();
    g.clipRect(cmp.getX(), cmp.getY(), cmp.getWidth(), cmp.getHeight());
    cmp.paint(g);
    Border b = s.getBorder();
    if (b != null && !b.isBackgroundPainter()) {
        cmp.paintBorder(g);
    }
    g.setClip(oX, oY, oWidth, oHeight);
// g.popClip();
}
Also used : Style(com.codename1.ui.plaf.Style) Border(com.codename1.ui.plaf.Border)

Example 35 with Border

use of com.codename1.ui.plaf.Border in project CodenameOne by codenameone.

the class MenuBar method updateBackBorderToRTL.

private void updateBackBorderToRTL(Style s) {
    Border b = s.getBorder();
    if (b != null) {
        b = b.mirrorBorder();
        s.setBorder(b);
    }
}
Also used : Border(com.codename1.ui.plaf.Border)

Aggregations

Border (com.codename1.ui.plaf.Border)25 Hashtable (java.util.Hashtable)11 Image (com.codename1.ui.Image)9 AnimationObject (com.codename1.ui.animations.AnimationObject)9 RoundBorder (com.codename1.ui.plaf.RoundBorder)9 RoundRectBorder (com.codename1.ui.plaf.RoundRectBorder)9 EncodedImage (com.codename1.ui.EncodedImage)8 BufferedImage (java.awt.image.BufferedImage)7 Component (com.codename1.ui.Component)6 EditorTTFFont (com.codename1.ui.EditorTTFFont)5 EditorFont (com.codename1.ui.EditorFont)4 Font (com.codename1.ui.Font)4 Style (com.codename1.ui.plaf.Style)4 CodenameOneComponentWrapper (com.codename1.ui.resource.util.CodenameOneComponentWrapper)4 Container (com.codename1.ui.Container)3 Label (com.codename1.ui.Label)3 RGBImage (com.codename1.ui.RGBImage)3 Rectangle (com.codename1.ui.geom.Rectangle)3 BorderLayout (java.awt.BorderLayout)3 Button (com.codename1.ui.Button)2