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));
}
}
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));
}
}
}
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 & 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));
}
}
}
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);
}
}
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;
}
Aggregations