Search in sources :

Example 11 with Border

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

the class Import9Patch method create9Patch.

// GEN-LAST:event_okButtonActionPerformed
private void create9Patch(List<BufferedImage> biList, List<Integer> densities) {
    List<com.codename1.ui.EncodedImage> topLeftCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> topRightCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> bottomLeftCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> bottomRightCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> centerCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> topImageCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> bottomImageCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> leftImageCodenameOne = new ArrayList<EncodedImage>();
    List<com.codename1.ui.EncodedImage> rightImageCodenameOne = new ArrayList<EncodedImage>();
    for (BufferedImage bi : biList) {
        int left = 0;
        for (int x = 0; x < bi.getWidth(); x++) {
            int pixel = bi.getRGB(x, 0);
            if ((pixel & 0xff000000) == 0xff000000) {
                break;
            }
            left++;
        }
        int right = 0;
        for (int x = bi.getWidth() - 1; x > 0; x--) {
            int pixel = bi.getRGB(x, 0);
            if ((pixel & 0xff000000) == 0xff000000) {
                break;
            }
            right++;
        }
        int top = 0;
        for (int y = 0; y < bi.getHeight(); y++) {
            int pixel = bi.getRGB(0, y);
            if ((pixel & 0xff000000) == 0xff000000) {
                break;
            }
            top++;
        }
        int bottom = 0;
        for (int y = bi.getHeight() - 1; y > 0; y--) {
            int pixel = bi.getRGB(0, y);
            if ((pixel & 0xff000000) == 0xff000000) {
                break;
            }
            bottom++;
        }
        bi = bi.getSubimage(1, 1, bi.getWidth() - 2, bi.getHeight() - 2);
        top--;
        bottom--;
        left--;
        right--;
        BufferedImage topLeft = bi.getSubimage(0, 0, left, top);
        BufferedImage topRight = bi.getSubimage(bi.getWidth() - right, 0, right, top);
        BufferedImage bottomLeft = bi.getSubimage(0, bi.getHeight() - bottom, left, bottom);
        BufferedImage bottomRight = bi.getSubimage(bi.getWidth() - right, bi.getHeight() - bottom, right, bottom);
        BufferedImage center = bi.getSubimage(left, top, bi.getWidth() - right - left, bi.getHeight() - bottom - top);
        BufferedImage topImage = bi.getSubimage(left, 0, bi.getWidth() - left - right, top);
        BufferedImage bottomImage = bi.getSubimage(left, bi.getHeight() - bottom, bi.getWidth() - left - right, bottom);
        BufferedImage leftImage = bi.getSubimage(0, top, left, bi.getHeight() - top - bottom);
        BufferedImage rightImage = bi.getSubimage(bi.getWidth() - right, top, right, bi.getHeight() - top - bottom);
        topLeftCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(topLeft)));
        topRightCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(topRight)));
        bottomLeftCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(bottomLeft)));
        bottomRightCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(bottomRight)));
        centerCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(center)));
        topImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(topImage)));
        bottomImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(bottomImage)));
        leftImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(leftImage)));
        rightImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(rightImage)));
    }
    String prefix = (String) uiidCombo.getSelectedItem() + ".";
    switch(styleState.getSelectedIndex()) {
        case 1:
            prefix += "sel#";
            break;
        case 2:
            prefix += "press#";
            break;
        case 3:
            prefix += "dis#";
            break;
    }
    com.codename1.ui.EncodedImage topLeftCodenameOneE = storeImage(topLeftCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage topRightCodenameOneE = storeImage(topRightCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage bottomLeftCodenameOneE = storeImage(bottomLeftCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage bottomRightCodenameOneE = storeImage(bottomRightCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage centerCodenameOneE = storeImage(centerCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage topImageCodenameOneE = storeImage(topImageCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage bottomImageCodenameOneE = storeImage(bottomImageCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage leftImageCodenameOneE = storeImage(leftImageCodenameOne, densities, prefix + " ");
    com.codename1.ui.EncodedImage rightImageCodenameOneE = storeImage(rightImageCodenameOne, densities, prefix + " ");
    com.codename1.ui.plaf.Border b = com.codename1.ui.plaf.Border.createImageScaledBorder(topImageCodenameOneE, bottomImageCodenameOneE, leftImageCodenameOneE, rightImageCodenameOneE, topLeftCodenameOneE, topRightCodenameOneE, bottomLeftCodenameOneE, bottomRightCodenameOneE, centerCodenameOneE);
    Hashtable newTheme = new Hashtable(res.getTheme(theme));
    newTheme.put(prefix + "border", b);
    res.setTheme(theme, newTheme);
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage) EncodedImage(com.codename1.ui.EncodedImage)

Example 12 with Border

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

the class ImageBorderCuttingWizard method generate.

// GEN-LAST:event_multiImageComboActionPerformed
public void generate() {
    if (applies.getAppliesTo().getModel().getSize() == 0) {
        JOptionPane.showMessageDialog(this, "You haven't selected components to apply this border to!\nPlease go to the apply tab and ADD component types/styles", "No Components Selected", JOptionPane.ERROR_MESSAGE);
        return;
    }
    BufferedImage img = wiz.getImage();
    BufferedImage buff = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D bg2d = buff.createGraphics();
    bg2d.drawImage(img.getSubimage(get(cropLeft), get(cropTop), img.getWidth() - get(cropLeft) - get(cropRight), img.getHeight() - get(cropTop) - get(cropBottom)), get(cropLeft), get(cropTop), null);
    bg2d.dispose();
    img = buff;
    BufferedImage topLeft = img.getSubimage(0, 0, get(left), get(top));
    BufferedImage topRight = img.getSubimage(img.getWidth() - get(right), 0, get(right), get(top));
    BufferedImage bottomLeft = img.getSubimage(0, img.getHeight() - get(bottom), get(left), get(bottom));
    BufferedImage bottomRight = img.getSubimage(img.getWidth() - get(right), img.getHeight() - get(bottom), get(right), get(bottom));
    BufferedImage center = img.getSubimage(get(left), get(top), img.getWidth() - get(right) - get(left), img.getHeight() - get(bottom) - get(top));
    BufferedImage topImage = img.getSubimage(get(left), 0, img.getWidth() - get(left) - get(right), get(top));
    BufferedImage bottomImage = img.getSubimage(get(left), img.getHeight() - get(bottom), img.getWidth() - get(left) - get(right), get(bottom));
    BufferedImage leftImage = img.getSubimage(0, get(top), get(left), img.getHeight() - get(top) - get(bottom));
    BufferedImage rightImage = img.getSubimage(img.getWidth() - get(right), get(top), get(right), img.getHeight() - get(top) - get(bottom));
    // optimize the size of the center/top/left/bottom/right images which is a HUGE performance deterant
    if (center.getWidth() < 10 || center.getHeight() < 10) {
        center = ImageTools.getScaledInstance(center, Math.max(20, center.getWidth()), Math.max(20, center.getHeight()));
        topImage = ImageTools.getScaledInstance(topImage, Math.max(20, topImage.getWidth()), topImage.getHeight());
        leftImage = ImageTools.getScaledInstance(leftImage, leftImage.getWidth(), Math.max(20, leftImage.getHeight()));
        rightImage = ImageTools.getScaledInstance(rightImage, rightImage.getWidth(), Math.max(20, rightImage.getHeight()));
        bottomImage = ImageTools.getScaledInstance(bottomImage, Math.max(20, bottomImage.getWidth()), bottomImage.getHeight());
    }
    com.codename1.ui.EncodedImage topLeftCodenameOne = com.codename1.ui.EncodedImage.create(toPng(topLeft));
    com.codename1.ui.EncodedImage topRightCodenameOne = com.codename1.ui.EncodedImage.create(toPng(topRight));
    com.codename1.ui.EncodedImage bottomLeftCodenameOne = com.codename1.ui.EncodedImage.create(toPng(bottomLeft));
    com.codename1.ui.EncodedImage bottomRightCodenameOne = com.codename1.ui.EncodedImage.create(toPng(bottomRight));
    com.codename1.ui.EncodedImage centerCodenameOne = com.codename1.ui.EncodedImage.create(toPng(center));
    com.codename1.ui.EncodedImage topImageCodenameOne = com.codename1.ui.EncodedImage.create(toPng(topImage));
    com.codename1.ui.EncodedImage bottomImageCodenameOne = com.codename1.ui.EncodedImage.create(toPng(bottomImage));
    com.codename1.ui.EncodedImage leftImageCodenameOne = com.codename1.ui.EncodedImage.create(toPng(leftImage));
    com.codename1.ui.EncodedImage rightImageCodenameOne = com.codename1.ui.EncodedImage.create(toPng(rightImage));
    String prefix = (String) applies.getAppliesTo().getModel().getElementAt(0);
    topLeftCodenameOne = storeImage(topLeftCodenameOne, prefix + "TopL");
    topRightCodenameOne = storeImage(topRightCodenameOne, prefix + "TopR");
    bottomLeftCodenameOne = storeImage(bottomLeftCodenameOne, prefix + "BottomL");
    bottomRightCodenameOne = storeImage(bottomRightCodenameOne, prefix + "BottomR");
    centerCodenameOne = storeImage(centerCodenameOne, prefix + "Center");
    topImageCodenameOne = storeImage(topImageCodenameOne, prefix + "Top");
    bottomImageCodenameOne = storeImage(bottomImageCodenameOne, prefix + "Bottom");
    leftImageCodenameOne = storeImage(leftImageCodenameOne, prefix + "Left");
    rightImageCodenameOne = storeImage(rightImageCodenameOne, prefix + "Right");
    com.codename1.ui.plaf.Border b = com.codename1.ui.plaf.Border.createImageBorder(topImageCodenameOne, bottomImageCodenameOne, leftImageCodenameOne, rightImageCodenameOne, topLeftCodenameOne, topRightCodenameOne, bottomLeftCodenameOne, bottomRightCodenameOne, centerCodenameOne);
    Hashtable newTheme = new Hashtable(res.getTheme(theme));
    for (int i = 0; i < applies.getAppliesTo().getModel().getSize(); i++) {
        newTheme.put(applies.getAppliesTo().getModel().getElementAt(i), b);
    }
    ((DefaultListModel) applies.getAppliesTo().getModel()).removeAllElements();
    res.setTheme(theme, newTheme);
}
Also used : Hashtable(java.util.Hashtable) DefaultListModel(javax.swing.DefaultListModel) EncodedImage(com.codename1.ui.EncodedImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 13 with Border

use of com.codename1.ui.plaf.Border 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)

Example 14 with Border

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

the class InteractionDialog method showPopupDialog.

/**
 * A popup dialog is shown with the context of a component and  its selection, it is disposed seamlessly if the back button is pressed
 * or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
 * dialog has the PopupDialog style by default.
 *
 * @param rect the screen rectangle to which the popup should point
 */
public void showPopupDialog(Rectangle rect) {
    disposed = false;
    if (getUIID().equals("Dialog")) {
        setUIID("PopupDialog");
        if (getTitleComponent().getUIID().equals("DialogTitle")) {
            getTitleComponent().setUIID("PopupDialogTitle");
        }
        getContentPane().setUIID("PopupContentPane");
    }
    Component contentPane = getContentPane();
    Label title = getTitleComponent();
    UIManager manager = getUIManager();
    String dialogTitle = title.getText();
    // preferred size logic of the dialog won't work with large title borders
    if ((dialogTitle != null || dialogTitle.length() == 0) && manager.isThemeConstant("hideEmptyTitleBool", false)) {
        boolean b = getTitle().length() > 0;
        titleArea.setVisible(b);
        getTitleComponent().setVisible(b);
        if (!b && manager.isThemeConstant("shrinkPopupTitleBool", true)) {
            getTitleComponent().setPreferredSize(new Dimension(0, 0));
            getTitleComponent().getStyle().setBorder(null);
            titleArea.setPreferredSize(new Dimension(0, 0));
            if (getContentPane().getClientProperty("$ENLARGED_POP") == null) {
                getContentPane().putClientProperty("$ENLARGED_POP", Boolean.TRUE);
                int cpPaddingTop = getContentPane().getStyle().getPaddingTop();
                int titlePT = getTitleComponent().getStyle().getPaddingTop();
                byte[] pu = getContentPane().getStyle().getPaddingUnit();
                if (pu == null) {
                    pu = new byte[4];
                }
                pu[0] = Style.UNIT_TYPE_PIXELS;
                getContentPane().getStyle().setPaddingUnit(pu);
                int pop = Display.getInstance().convertToPixels(manager.getThemeConstant("popupNoTitleAddPaddingInt", 1), false);
                getContentPane().getStyle().setPadding(TOP, pop + cpPaddingTop + titlePT);
            }
        }
    }
    // allows a text area to recalculate its preferred size if embedded within a dialog
    revalidate();
    Style contentPaneStyle = getStyle();
    boolean restoreArrow = false;
    if (manager.isThemeConstant(getUIID() + "ArrowBool", false)) {
        Image t = manager.getThemeImageConstant(getUIID() + "ArrowTopImage");
        Image b = manager.getThemeImageConstant(getUIID() + "ArrowBottomImage");
        Image l = manager.getThemeImageConstant(getUIID() + "ArrowLeftImage");
        Image r = manager.getThemeImageConstant(getUIID() + "ArrowRightImage");
        Border border = contentPaneStyle.getBorder();
        if (border != null) {
            border.setImageBorderSpecialTile(t, b, l, r, rect);
            restoreArrow = true;
        }
    }
    calcPreferredSize();
    int prefHeight = getPreferredH();
    int prefWidth = getPreferredW();
    if (contentPaneStyle.getBorder() != null) {
        prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
        prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
    }
    Form f = Display.getInstance().getCurrent();
    int availableHeight = getLayeredPane(f).getParent().getHeight();
    int availableWidth = getLayeredPane(f).getParent().getWidth();
    int width = Math.min(availableWidth, prefWidth);
    int x = 0;
    int y = 0;
    boolean showPortrait = Display.getInstance().isPortrait();
    // if we don't have enough space then disregard device orientation
    if (showPortrait) {
        if (availableHeight < (availableWidth - rect.getWidth()) / 2) {
            showPortrait = false;
        }
    } else {
        if (availableHeight / 2 > availableWidth - rect.getWidth()) {
            showPortrait = true;
        }
    }
    if (showPortrait) {
        if (width < availableWidth) {
            int idealX = rect.getX() - width / 2 + rect.getSize().getWidth() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealX > 0) {
                // if the idealX is too far to the right just align to the right
                if (idealX + width > availableWidth) {
                    x = availableWidth - width;
                } else {
                    x = idealX;
                }
            }
        }
        if (rect.getY() < availableHeight / 2) {
            // popup downwards
            y = rect.getY();
            int height = Math.min(prefHeight, availableHeight - y);
            show(y, Math.max(0, availableHeight - height - y), x, Math.max(0, availableWidth - width - x));
        } else {
            // popup upwards
            int height = Math.min(prefHeight, rect.getY() - getLayeredPane(f).getAbsoluteY());
            y = rect.getY() - height - getLayeredPane(f).getAbsoluteY();
            show(y, Math.max(0, getLayeredPane(f).getComponentForm().getHeight() - rect.getY()), x, Math.max(0, availableWidth - width - x));
        }
    } else {
        int height = Math.min(prefHeight, availableHeight);
        if (height < availableHeight) {
            int idealY = rect.getY() - height / 2 + rect.getSize().getHeight() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealY > 0) {
                // if the idealY is too far up just align to the top
                if (idealY + height > availableHeight) {
                    y = availableHeight - height;
                } else {
                    y = idealY;
                }
            }
        }
        if (prefWidth > rect.getX()) {
            // popup right
            x = rect.getX() + rect.getSize().getWidth();
            if (x + prefWidth > availableWidth) {
                x = availableWidth - prefWidth;
            }
            width = Math.min(prefWidth, availableWidth - x);
            show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
        } else {
            // popup left
            width = Math.min(prefWidth, availableWidth - (availableWidth - rect.getX()));
            x = rect.getX() - width;
            show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
        }
    }
/*if(restoreArrow) {
            contentPaneStyle.getBorder().clearImageBorderSpecialTile();
        }*/
}
Also used : Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component) Image(com.codename1.ui.Image) Border(com.codename1.ui.plaf.Border)

Example 15 with Border

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

the class Component method deinitializeImpl.

/**
 * Cleansup the initialization flags in the hierachy, notice that paint calls might
 * still occur after deinitilization mostly to perform transitions etc.
 * <p>However interactivity, animation and event tracking code can and probably
 * should be removed by this method.
 */
void deinitializeImpl() {
    if (isInitialized()) {
        hideNativeOverlay();
        paintLockRelease();
        setInitialized(false);
        setDirtyRegion(null);
        Style stl = getStyle();
        Image i = stl.getBgImage();
        if (i != null) {
            i.unlock();
        } else {
            Border b = stl.getBorder();
            if (b != null) {
                b.unlock();
            }
        }
        Painter p = stl.getBgPainter();
        if (p instanceof BGPainter) {
            ((BGPainter) p).radialCache = null;
        }
        deinitialize();
    }
}
Also used : Style(com.codename1.ui.plaf.Style) 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