Search in sources :

Example 56 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class Dialog method showPackedImpl.

/**
 * Convenience method to show a dialog sized to match its content.
 *
 * @param position one of the values from the BorderLayout class e.g. BorderLayout.CENTER, BorderLayout.NORTH etc.
 * @param modal whether the dialog should be modal or modaless
 * @return the command selected if the dialog is modal and disposed via a command
 */
private Command showPackedImpl(String position, boolean modal, boolean stretch) {
    if (getTitle() == null) {
        setTitle("");
    }
    this.position = position;
    int height = Display.getInstance().getDisplayHeight();
    int width = Display.getInstance().getDisplayWidth();
    if (top > -1) {
        refreshTheme();
    }
    Component contentPane = super.getContentPane();
    Component title = super.getTitleComponent();
    // preferred size logic of the dialog won't work with large title borders
    if (dialogTitle != null && getUIManager().isThemeConstant("hideEmptyTitleBool", false)) {
        boolean b = getTitle().length() > 0;
        getTitleArea().setVisible(b);
        getTitleComponent().setVisible(b);
    }
    Style contentPaneStyle = getDialogStyle();
    int menuHeight = calcMenuHeight();
    // allows a text area to recalculate its preferred size if embedded within a dialog
    revalidate();
    int prefHeight = contentPane.getPreferredH();
    int prefWidth = contentPane.getPreferredW();
    prefWidth = Math.min(prefWidth, width);
    if (contentPaneStyle.getBorder() != null) {
        prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
        prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
    }
    height = height - menuHeight - title.getPreferredH();
    int topBottom = Math.max(0, (height - prefHeight) / 2);
    int leftRight = Math.max(0, (width - prefWidth) / 2);
    if (position.equals(BorderLayout.CENTER)) {
        show(topBottom, topBottom, leftRight, leftRight, true, modal);
        return lastCommandPressed;
    }
    if (position.equals(BorderLayout.EAST)) {
        if (stretch) {
            show(0, 0, Math.max(0, width - prefWidth), 0, true, modal);
        } else {
            show(topBottom, topBottom, Math.max(0, width - prefWidth), 0, true, modal);
        }
        return lastCommandPressed;
    }
    if (position.equals(BorderLayout.WEST)) {
        if (stretch) {
            show(0, 0, 0, Math.max(0, width - prefWidth), true, modal);
        } else {
            show(topBottom, topBottom, 0, Math.max(0, width - prefWidth), true, modal);
        }
        return lastCommandPressed;
    }
    if (position.equals(BorderLayout.NORTH)) {
        if (stretch) {
            show(0, Math.max(0, height - prefHeight), 0, 0, true, modal);
        } else {
            show(0, Math.max(0, height - prefHeight), leftRight, leftRight, true, modal);
        }
        return lastCommandPressed;
    }
    if (position.equals(BorderLayout.SOUTH)) {
        if (stretch) {
            show(Math.max(0, height - prefHeight), 0, 0, 0, true, modal);
        } else {
            show(Math.max(0, height - prefHeight), 0, leftRight, leftRight, true, modal);
        }
        return lastCommandPressed;
    }
    throw new IllegalArgumentException("Unknown position: " + position);
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 57 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class HTMLComponent method handleImage.

/**
 * Handles the IMG tag. This includes calculating its size (if available), applying any links/accesskeys and adding it to the download queue
 *
 * @param imgElement the IMG element
 * @param align th current alignment
 * @param cmd The submit command of a form, used only for INPUT type="image"
 */
private void handleImage(HTMLElement imgElement, int align, Command cmd) {
    String imageUrl = imgElement.getAttributeById(HTMLElement.ATTR_SRC);
    Label imgLabel = null;
    if (imageUrl != null) {
        String alignStr = imgElement.getAttributeById(HTMLElement.ATTR_ALIGN);
        // Image width and height
        int iWidth = calcSize(getWidth(), imgElement.getAttributeById(HTMLElement.ATTR_WIDTH), 0, false);
        int iHeight = calcSize(getHeight(), imgElement.getAttributeById(HTMLElement.ATTR_HEIGHT), 0, false);
        // Whitespace on the image sides (i.e. Margins)
        int hspace = getInt(imgElement.getAttributeById(HTMLElement.ATTR_HSPACE));
        int vspace = getInt(imgElement.getAttributeById(HTMLElement.ATTR_VSPACE));
        int totalWidth = iWidth + hspace * 2;
        if ((FIXED_WIDTH) && (x + totalWidth >= width)) {
            newLine(align);
        }
        // Alternative image text, shown until image is loaded.
        String altText = imgElement.getAttributeById(HTMLElement.ATTR_ALT);
        String imageMap = imgElement.getAttributeById(HTMLElement.ATTR_USEMAP);
        if (link != null) {
            // This image is inside an A tag with HREF attribute
            imgLabel = new HTMLLink(altText, link, this, mainLink, false);
            if (mainLink == null) {
                mainLink = (HTMLLink) imgLabel;
            }
            if (accesskey != '\0') {
                // accessKeys.put(new Integer(accesskey), imgLabel);
                addAccessKey(accesskey, imgLabel, false);
            }
            if (!PROCESS_HTML_MP1_ONLY) {
                ((HTMLLink) imgLabel).isMap = (imgElement.getAttributeById(HTMLElement.ATTR_ISMAP) != null);
            }
        } else if (cmd != null) {
            // Special case of an image submit button
            imgLabel = new Button(cmd);
            if ((altText != null) && (!altText.equals(""))) {
                imgLabel.setText(altText);
            }
            if (firstFocusable == null) {
                firstFocusable = imgLabel;
            }
        } else if (imageMap != null) {
            // Image Map
            imgLabel = new HTMLImageMap(this);
            if (imageMapComponents == null) {
                imageMapComponents = new Hashtable();
            }
            if (imageMap.startsWith("#")) {
                // Image map are denoted by # and then the map name (But we also tolerate if map is specified without #)
                imageMap = imageMap.substring(1);
            }
            imageMapComponents.put(imageMap, imgLabel);
            if ((imageMapData != null) && (imageMapData.containsKey(imageMap))) {
                ImageMapData data = (ImageMapData) imageMapData.get(imageMap);
                ((HTMLImageMap) imgLabel).mapData = data;
            }
        } else {
            imgLabel = new Label(altText);
        }
        if ((iWidth != 0) || (iHeight != 0)) {
            // reserve space while loading image if either width or height are specified, otherwise we don't know how much to reserve
            iWidth += imgLabel.getStyle().getPadding(Component.LEFT) + imgLabel.getStyle().getPadding(Component.RIGHT);
            iHeight += imgLabel.getStyle().getPadding(Component.TOP) + imgLabel.getStyle().getPadding(Component.BOTTOM);
            imgLabel.setPreferredSize(new Dimension(iWidth, iHeight));
        } else {
            // If no space is reserved, make a minimal text, otherwise Codename One won't calculate the size right after the image loads
            if ((imgLabel.getText() == null) || (imgLabel.getText().equals(""))) {
                imgLabel.setText(" ");
            }
        }
        // It is important that the padding of the image component itself will be all 0
        // This is because when the image is loaded, its preferred size is checked to see if its width/height were preset by the width/height attribute
        imgLabel.getSelectedStyle().setPadding(0, 0, 0, 0);
        imgLabel.getUnselectedStyle().setPadding(0, 0, 0, 0);
        imgLabel.getSelectedStyle().setFont(font.getFont());
        imgLabel.getUnselectedStyle().setFont(font.getFont());
        int borderSize = getInt(imgElement.getAttributeById(HTMLElement.ATTR_BORDER));
        if (borderSize != 0) {
            imgLabel.putClientProperty(CLIENT_PROPERTY_IMG_BORDER, new Integer(borderSize));
        } else {
            borderSize = 1;
        }
        imgLabel.getUnselectedStyle().setBorder(Border.createLineBorder(borderSize));
        imgLabel.getSelectedStyle().setBorder(Border.createLineBorder(borderSize));
        imgLabel.getUnselectedStyle().setBgTransparency(0);
        imgLabel.getSelectedStyle().setBgTransparency(0);
        Container imgCont = new Container(new BorderLayout());
        imgCont.addComponent(BorderLayout.CENTER, imgLabel);
        imgCont.getSelectedStyle().setMargin(vspace, vspace, hspace, hspace);
        imgCont.getUnselectedStyle().setMargin(vspace, vspace, hspace, hspace);
        curLine.addComponent(imgCont);
        x += totalWidth;
        // Alignment
        imgLabel.setAlignment(getHorizAlign(alignStr, align, false));
        imgLabel.setVerticalAlignment(getVertAlign(alignStr, Component.CENTER));
        if (showImages) {
            if (docInfo != null) {
                imageUrl = docInfo.convertURL(imageUrl);
                threadQueue.add(imgLabel, imageUrl);
            } else {
                if (DocumentInfo.isAbsoluteURL(imageUrl)) {
                    threadQueue.add(imgLabel, imageUrl);
                } else {
                    if (htmlCallback != null) {
                        htmlCallback.parsingError(HTMLCallback.ERROR_NO_BASE_URL, imgElement.getTagName(), imgElement.getAttributeName(new Integer(HTMLElement.ATTR_SRC)), imageUrl, "Ignoring Image file referred in an IMG tag (" + imageUrl + "), since page was set by setBody/setHTML/setDOM so there's no way to access relative URLs");
                    }
                }
            }
        }
        if (loadCSS) {
            imgElement.setAssociatedComponents(imgCont);
        }
    }
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Button(com.codename1.ui.Button) RadioButton(com.codename1.ui.RadioButton) Hashtable(java.util.Hashtable) Label(com.codename1.ui.Label) Dimension(com.codename1.ui.geom.Dimension)

Example 58 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class MenuBar method unInstallMenuBar.

/**
 * Removes the MenuBar from the parent Form
 */
protected void unInstallMenuBar() {
    parent.removeComponentFromForm(this);
    Container t = getTitleAreaContainer();
    BorderLayout titleLayout = (BorderLayout) t.getLayout();
    titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
    Component l = getTitleComponent();
    t.removeAll();
    if (l.getParent() != null) {
        l.getParent().removeComponent(l);
    }
    t.addComponent(BorderLayout.CENTER, l);
    initTitleBarStatus();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 59 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class Toolbar method addComponentToSideMenu.

/**
 * Adds a Component to the side navigation menu. The Component is added to
 * the navigation menu and the command gets the events once the Component is
 * being pressed.
 *
 * @param cmp c Component to be added to the menu
 * @param cmd a Command to handle the events
 */
public void addComponentToSideMenu(Component cmp, Command cmd) {
    checkIfInitialized();
    if (permanentSideMenu) {
        constructPermanentSideMenu();
        Container cnt = new Container(new BorderLayout());
        cnt.addComponent(BorderLayout.CENTER, cmp);
        Button btn = new Button(cmd);
        btn.setParent(cnt);
        cnt.setLeadComponent(btn);
        addComponentToSideMenu(permanentSideMenuContainer, cnt);
    } else {
        if (onTopSideMenu) {
            constructOnTopSideMenu();
            Container cnt = new Container(new BorderLayout());
            cnt.addComponent(BorderLayout.CENTER, cmp);
            Button btn = new Button(cmd);
            btn.setParent(cnt);
            cnt.setLeadComponent(btn);
            addComponentToSideMenu(permanentSideMenuContainer, cnt);
        } else {
            cmd.putClientProperty(SideMenuBar.COMMAND_SIDE_COMPONENT, cmp);
            cmd.putClientProperty(SideMenuBar.COMMAND_ACTIONABLE, Boolean.TRUE);
            sideMenu.addCommand(cmd);
            sideMenu.installMenuBar();
        }
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 60 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class Toolbar method showOverflowMenu.

/*
     * A Overflow Menu is implemented as a dialog, this method allows you to 
     * override the dialog display in order to customize the dialog menu in 
     * various ways
     * 
     * @param menu a dialog containing Overflow Menu options that can be 
     * customized
     * @return the command selected by the user in the dialog
     */
protected Command showOverflowMenu(Dialog menu) {
    Form parent = sideMenu.getParentForm();
    int height;
    int marginLeft;
    int marginRight = 0;
    Container dialogContentPane = menu.getDialogComponent();
    marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
    marginLeft = Math.max(0, marginLeft);
    if (parent.getSoftButtonCount() > 1) {
        height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
    } else {
        height = parent.getHeight() - dialogContentPane.getPreferredH();
    }
    height = Math.max(0, height);
    int th = getHeight();
    Transition transitionIn;
    Transition transitionOut;
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
        transitionIn = lf.getDefaultMenuTransitionIn();
        if (transitionIn instanceof BubbleTransition) {
            ((BubbleTransition) transitionIn).setComponentName("OverflowButton");
        }
        transitionOut = lf.getDefaultMenuTransitionOut();
    } else {
        transitionIn = CommonTransitions.createEmpty();
        transitionOut = CommonTransitions.createEmpty();
    }
    menu.setTransitionInAnimator(transitionIn);
    menu.setTransitionOutAnimator(transitionOut);
    if (isRTL()) {
        marginRight = marginLeft;
        marginLeft = 0;
    }
    int tint = parent.getTintColor();
    parent.setTintColor(0x00FFFFFF);
    parent.tint = false;
    boolean showBelowTitle = manager.isThemeConstant("showMenuBelowTitleBool", true);
    int topPadding = 0;
    Component statusBar = ((BorderLayout) getLayout()).getNorth();
    if (statusBar != null) {
        topPadding = statusBar.getAbsoluteY() + statusBar.getHeight();
    }
    if (showBelowTitle) {
        topPadding = th;
    }
    Command r = menu.show(topPadding, Math.max(topPadding, height - topPadding), marginLeft, marginRight, true);
    parent.setTintColor(tint);
    return r;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Transition(com.codename1.ui.animations.Transition) BubbleTransition(com.codename1.ui.animations.BubbleTransition) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel) BubbleTransition(com.codename1.ui.animations.BubbleTransition)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)64 ActionEvent (com.codename1.ui.events.ActionEvent)27 Container (com.codename1.ui.Container)21 Form (com.codename1.ui.Form)18 ActionListener (com.codename1.ui.events.ActionListener)18 Component (com.codename1.ui.Component)15 BoxLayout (com.codename1.ui.layouts.BoxLayout)14 Label (com.codename1.ui.Label)12 Button (com.codename1.ui.Button)10 IOException (java.io.IOException)9 Dialog (com.codename1.ui.Dialog)8 Hashtable (java.util.Hashtable)8 Command (com.codename1.ui.Command)6 TextArea (com.codename1.ui.TextArea)6 FlowLayout (com.codename1.ui.layouts.FlowLayout)6 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Vector (java.util.Vector)6 RadioButton (com.codename1.ui.RadioButton)5 Animation (com.codename1.ui.animations.Animation)4 Style (com.codename1.ui.plaf.Style)4