Search in sources :

Example 46 with Style

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

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icons above) to the given component using the
 * styling of the label</p>
 * <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
 * @param l a multibutton
 * @param icon one of the MATERIAL_* icons
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(MultiButton l, char icon, float size) {
    if (Font.isTrueTypeFileSupported()) {
        Style s = new Style(l.getUnselectedStyle());
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        l.setIcon(FontImage.create("" + icon, s));
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 47 with Style

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

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icons above) to the given component using the
 * styling of the label</p>
 * <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
 * @param l a SpanButton
 * @param icon one of the MATERIAL_* icons
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(SpanButton l, char icon, float size) {
    if (Font.isTrueTypeFileSupported()) {
        Style s = new Style(l.getUnselectedStyle());
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        l.setIcon(FontImage.create("" + icon, s));
        Style sel = l.getSelectedStyle();
        Style pre = l.getPressedStyle();
        Style dis = l.getDisabledStyle();
        if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
            sel = new Style(sel);
            sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
            l.setRolloverIcon(FontImage.create("" + icon, sel));
        }
        if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
            pre = new Style(pre);
            pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
            l.setPressedIcon(FontImage.create("" + icon, pre));
        }
        if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
            dis = new Style(dis);
            dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
            l.setDisabledIcon(FontImage.create("" + icon, dis));
        }
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 48 with Style

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

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icon constants) to the given command using the
 * given UIID. Notice that the pressed/selected &amp; disabled states will be set appropriately.</p>
 *
 * @param c a command
 * @param icon one of the MATERIAL_* icons
 * @param uiid the UIID for the command (e.g. TitleCommand)
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(Command c, char icon, String uiid, float size) {
    if (Font.isTrueTypeFileSupported()) {
        UIManager uim = UIManager.getInstance();
        Style s = uim.getComponentStyle(uiid);
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        c.setIcon(FontImage.create("" + icon, s));
        Style sel = uim.getComponentSelectedStyle(uiid);
        Style pre = uim.getComponentCustomStyle(uiid, "press");
        Style dis = uim.getComponentCustomStyle(uiid, "dis");
        ;
        if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
            sel = new Style(sel);
            sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
            c.setRolloverIcon(FontImage.create("" + icon, sel));
        }
        if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
            pre = new Style(pre);
            pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
            c.setPressedIcon(FontImage.create("" + icon, pre));
        }
        if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
            dis = new Style(dis);
            dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
            c.setDisabledIcon(FontImage.create("" + icon, dis));
        }
    }
}
Also used : UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style)

Example 49 with Style

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

the class Form method showModal.

/**
 * This method shows the form as a modal alert allowing us to produce a behavior
 * of an alert/dialog box. This method will block the calling thread even if the
 * calling thread is the EDT. Notice that this method will not release the block
 * until dispose is called even if show() from another form is called!
 * <p>Modal dialogs Allow the forms "content" to "hang in mid air" this is especially useful for
 * dialogs where you would want the underlying form to "peek" from behind the
 * form.
 *
 * @param top space in pixels between the top of the screen and the form
 * @param bottom space in pixels between the bottom of the screen and the form
 * @param left space in pixels between the left of the screen and the form
 * @param right space in pixels between the right of the screen and the form
 * @param includeTitle whether the title should hang in the top of the screen or
 * be glued onto the content pane
 * @param modal indictes if this is a modal or modeless dialog true for modal dialogs
 */
void showModal(int top, int bottom, int left, int right, boolean includeTitle, boolean modal, boolean reverse) {
    Display.getInstance().flushEdt();
    if (previousForm == null) {
        previousForm = Display.getInstance().getCurrent();
        // special case for application opening with a dialog before any form is shown
        if (previousForm == null) {
            previousForm = new Form();
            previousForm.show();
        } else {
            if (previousForm instanceof Dialog) {
                Dialog previousDialog = (Dialog) previousForm;
                if (previousDialog.isDisposed()) {
                    previousForm = Display.getInstance().getCurrentUpcoming();
                }
            }
        }
    }
    previousForm.tint = true;
    Painter p = getStyle().getBgPainter();
    if (top > 0 || bottom > 0 || left > 0 || right > 0) {
        if (!title.isVisible()) {
            includeTitle = false;
        }
        Style titleStyle = title.getStyle();
        titleStyle.removeListeners();
        Style contentStyle = contentPane.getUnselectedStyle();
        contentStyle.removeListeners();
        if (includeTitle) {
            titleStyle.setMargin(Component.TOP, top, false);
            titleStyle.setMargin(Component.BOTTOM, 0, false);
            titleStyle.setMargin(Component.LEFT, left, false);
            titleStyle.setMargin(Component.RIGHT, right, false);
            contentStyle.setMargin(Component.TOP, 0, false);
            contentStyle.setMargin(Component.BOTTOM, bottom, false);
            contentStyle.setMargin(Component.LEFT, left, false);
            contentStyle.setMargin(Component.RIGHT, right, false);
        } else {
            titleStyle.setMargin(Component.TOP, 0, false);
            titleStyle.setMargin(Component.BOTTOM, 0, false);
            titleStyle.setMargin(Component.LEFT, 0, false);
            titleStyle.setMargin(Component.RIGHT, 0, false);
            contentStyle.setMargin(Component.TOP, top, false);
            contentStyle.setMargin(Component.BOTTOM, bottom, false);
            contentStyle.setMargin(Component.LEFT, left, false);
            contentStyle.setMargin(Component.RIGHT, right, false);
        }
        titleStyle.setMarginUnit(null);
        contentStyle.setMarginUnit(null);
        initDialogBgPainter(p, previousForm);
        revalidate();
    }
    initFocused();
    if (getTransitionOutAnimator() == null && getTransitionInAnimator() == null) {
        initLaf(getUIManager());
    }
    initComponentImpl();
    Display.getInstance().setCurrent(this, reverse);
    onShow();
    if (modal) {
        // called to display a dialog and wait for modality
        Display.getInstance().invokeAndBlock(new RunnableWrapper(this, p, reverse));
        // if the virtual keyboard was opend by the dialog close it
        Display.getInstance().setShowVirtualKeyboard(false);
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 50 with Style

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

the class Label method getAvaliableSpaceForText.

int getAvaliableSpaceForText() {
    Style style = getStyle();
    int textSpaceW = getWidth() - style.getHorizontalPadding();
    Image icon = getIconFromState();
    if (icon != null && (getTextPosition() == Label.RIGHT || getTextPosition() == Label.LEFT)) {
        textSpaceW = textSpaceW - icon.getWidth();
    }
    return textSpaceW;
}
Also used : Style(com.codename1.ui.plaf.Style)

Aggregations

Style (com.codename1.ui.plaf.Style)103 Dimension (com.codename1.ui.geom.Dimension)28 Component (com.codename1.ui.Component)25 Image (com.codename1.ui.Image)20 Rectangle (com.codename1.ui.geom.Rectangle)13 Container (com.codename1.ui.Container)11 Font (com.codename1.ui.Font)11 FontImage (com.codename1.ui.FontImage)11 Border (com.codename1.ui.plaf.Border)8 Form (com.codename1.ui.Form)6 Label (com.codename1.ui.Label)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 IOException (java.io.IOException)6 UIManager (com.codename1.ui.plaf.UIManager)5 Vector (java.util.Vector)5 Dialog (com.codename1.ui.Dialog)4 EncodedImage (com.codename1.ui.EncodedImage)4 Graphics (com.codename1.ui.Graphics)4 TextArea (com.codename1.ui.TextArea)4 SpanButton (com.codename1.components.SpanButton)3