Search in sources :

Example 56 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class LiveDemo method start.

public void start() {
    Form previewForm = new Form("Preview Theme");
    Toolbar tb = new Toolbar();
    previewForm.setToolbar(tb);
    tb.setTitle("Preview Theme");
    tb.addMaterialCommandToSideMenu("Side Command", FontImage.MATERIAL_HELP, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            ToastBar.showErrorMessage("Unmapped....");
        }
    });
    tb.addMaterialCommandToOverflowMenu("Overflow Command", FontImage.MATERIAL_HELP, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            ToastBar.showErrorMessage("Unmapped....");
        }
    });
    tb.addMaterialCommandToRightBar("", FontImage.MATERIAL_HELP, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            ToastBar.showErrorMessage("Unmapped....");
        }
    });
    previewForm.setLayout(new BorderLayout());
    Container first = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    first.addComponent(new Label("This is a Label"));
    first.addComponent(new Button("This is a Button"));
    MultiButton mb = new MultiButton("This is a MultiButton");
    mb.setTextLine2("Second line of text");
    FontImage.setMaterialIcon(mb, FontImage.MATERIAL_HELP);
    first.addComponent(mb);
    TextField txt = new TextField();
    txt.setHint("This is a TextField");
    first.addComponent(txt);
    first.addComponent(new CheckBox("This is a CheckBox"));
    RadioButton rb1 = new RadioButton("This is a Radio Button 1");
    rb1.setGroup("group");
    first.addComponent(rb1);
    RadioButton rb2 = new RadioButton("This is a Radio Button 2");
    rb2.setGroup("group");
    first.addComponent(rb2);
    final Slider s = new Slider();
    s.setText("50%");
    s.setProgress(50);
    s.setEditable(true);
    s.setRenderPercentageOnTop(true);
    first.addComponent(s);
    Button b1 = new Button("Show a Dialog");
    b1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            Dialog.show("Dialog Title", "Dialog Body", "Ok", "Cancel");
        }
    });
    first.addComponent(b1);
    previewForm.add(BorderLayout.CENTER, first);
    previewForm.show();
}
Also used : Slider(com.codename1.ui.Slider) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label) RadioButton(com.codename1.ui.RadioButton) Container(com.codename1.ui.Container) ActionListener(com.codename1.ui.events.ActionListener) BorderLayout(com.codename1.ui.layouts.BorderLayout) RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) CheckBox(com.codename1.ui.CheckBox) TextField(com.codename1.ui.TextField) MultiButton(com.codename1.components.MultiButton) Toolbar(com.codename1.ui.Toolbar)

Example 57 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class ResourceEditorView method addNewFontWizard.

/**
 * Invoked by the "..." button in the add theme entry dialog, allows us to add
 * a font on the fly while working on a theme
 */
public void addNewFontWizard() {
    AddResourceDialog addResource = new AddResourceDialog(loadedResources, AddResourceDialog.FONT);
    if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainPanel, addResource, "Add Font", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) {
        if (addResource.checkName(loadedResources)) {
            JOptionPane.showMessageDialog(mainPanel, "A resource with that name already exists", "Add Font", JOptionPane.ERROR_MESSAGE);
            addNewFontWizard();
            return;
        }
        // show the image editing dialog...
        FontEditor font = new FontEditor(loadedResources, new EditorFont(com.codename1.ui.Font.createSystemFont(com.codename1.ui.Font.FACE_SYSTEM, com.codename1.ui.Font.STYLE_PLAIN, com.codename1.ui.Font.SIZE_MEDIUM), null, "Arial-plain-12", true, RenderingHints.VALUE_TEXT_ANTIALIAS_ON, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,;:!/\\*()[]{}|#$%^&<>?'\"+- "), addResource.getResourceName());
        font.setFactoryCreation(true);
        if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(mainPanel, font, "Add Font", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) {
            loadedResources.setFont(addResource.getResourceName(), font.createFont());
        }
    }
}
Also used : EditorFont(com.codename1.ui.EditorFont)

Example 58 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class Dialog 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 c the context component which is used to position the dialog and can also be pointed at
 * @return the command that might have been triggered by the user within the dialog if commands are placed in the dialog
 */
public Command showPopupDialog(Component c) {
    Rectangle componentPos = c.getSelectedRect();
    componentPos.setX(componentPos.getX() - c.getScrollX());
    componentPos.setY(componentPos.getY() - c.getScrollY());
    return showPopupDialog(componentPos);
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 59 with Button

use of com.codename1.ui.Button 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 60 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class MenuBar method initMenuBar.

/**
 * Initialize the MenuBar
 *
 * @param parent the associated Form
 */
protected void initMenuBar(Form parent) {
    this.parent = parent;
    selectMenuItem = createMenuSelectCommand();
    cancelMenuItem = createMenuCancelCommand();
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    // don't minimize the app if it's a Dialog
    minimizeOnBack = manager.isThemeConstant("minimizeOnBackBool", true) && !(parent instanceof Dialog);
    hideEmptyCommands = manager.isThemeConstant("hideEmptyCommandsBool", false);
    menuStyle = manager.getComponentStyle("Menu");
    setUIID("SoftButton");
    menuCommand = new Command(manager.localize("menu", "Menu"), lf.getMenuIcons()[2]);
    // use the slide transition by default
    if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
        transitionIn = lf.getDefaultMenuTransitionIn();
        transitionOut = lf.getDefaultMenuTransitionOut();
    } else {
        transitionIn = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300, true);
        transitionOut = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300, true);
    }
    menuCellRenderer = lf.getMenuRenderer();
    int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
    thirdSoftButton = Display.getInstance().isThirdSoftButton();
    int commandBehavior = getCommandBehavior();
    if (softkeyCount > 1 && commandBehavior < Display.COMMAND_BEHAVIOR_BUTTON_BAR) {
        if (thirdSoftButton) {
            setLayout(new GridLayout(1, 3));
            soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[1];
            right = soft[2];
            if (parent.isRTL()) {
                right.setUIID("SoftButtonLeft");
                left.setUIID("SoftButtonRight");
                addComponent(right);
                addComponent(main);
                addComponent(left);
            } else {
                addComponent(left);
                addComponent(main);
                addComponent(right);
            }
            if (isReverseSoftButtons()) {
                Button b = soft[1];
                soft[1] = soft[2];
                soft[2] = b;
            }
        } else {
            setLayout(new GridLayout(1, 2));
            soft = new Button[] { createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[0];
            right = soft[1];
            if (parent.isRTL()) {
                right.setUIID("SoftButtonLeft");
                left.setUIID("SoftButtonRight");
                addComponent(right);
                addComponent(left);
            } else {
                addComponent(left);
                addComponent(right);
            }
            if (isReverseSoftButtons()) {
                Button b = soft[0];
                soft[0] = soft[1];
                soft[1] = b;
            }
        }
        // It doesn't make sense for softbuttons to have ... at the end
        for (int iter = 0; iter < soft.length; iter++) {
            soft[iter].setEndsWith3Points(false);
        }
    } else {
        // special case for touch screens we still want the 3 softbutton areas...
        if (thirdSoftButton) {
            setLayout(new GridLayout(1, 3));
            soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[1];
            right = soft[2];
            addComponent(left);
            addComponent(main);
            addComponent(right);
            if (isReverseSoftButtons()) {
                Button b = soft[1];
                soft[1] = soft[2];
                soft[2] = b;
            }
        } else {
            soft = new Button[] { createSoftButton("SoftButtonCenter") };
        }
    }
    softCommand = new Command[soft.length];
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel)

Aggregations

Button (com.codename1.ui.Button)31 BorderLayout (com.codename1.ui.layouts.BorderLayout)25 ActionEvent (com.codename1.ui.events.ActionEvent)21 Container (com.codename1.ui.Container)18 ActionListener (com.codename1.ui.events.ActionListener)17 Component (com.codename1.ui.Component)14 RadioButton (com.codename1.ui.RadioButton)14 Form (com.codename1.ui.Form)12 Label (com.codename1.ui.Label)11 BoxLayout (com.codename1.ui.layouts.BoxLayout)11 TextArea (com.codename1.ui.TextArea)10 Hashtable (java.util.Hashtable)9 Command (com.codename1.ui.Command)8 Image (com.codename1.ui.Image)8 TextField (com.codename1.ui.TextField)8 FlowLayout (com.codename1.ui.layouts.FlowLayout)8 GridLayout (com.codename1.ui.layouts.GridLayout)8 UIManager (com.codename1.ui.plaf.UIManager)8 CheckBox (com.codename1.ui.CheckBox)7 Style (com.codename1.ui.plaf.Style)7