use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.
the class DefaultLookAndFeel method getTextFieldCursorX.
/**
* Calculates the position of the text field cursor within the string
*/
private int getTextFieldCursorX(TextArea ta) {
Style style = ta.getStyle();
Font f = style.getFont();
// display ******** if it is a password field
String displayText = getTextFieldString(ta);
String inputMode = ta.getInputMode();
int inputModeWidth = f.stringWidth(inputMode);
// QWERTY devices don't quite have an input mode hide it also when we have a VK
if (ta.isQwertyInput() || Display.getInstance().isVirtualKeyboardShowing()) {
inputMode = "";
inputModeWidth = 0;
}
int xPos = 0;
int cursorCharPosition = ta.getCursorX();
int cursorX = 0;
int x = 0;
if (reverseAlignForBidi(ta) == Component.RIGHT) {
if (Display.getInstance().isBidiAlgorithm()) {
// char[] dest = displayText.toCharArray();
cursorCharPosition = Display.getInstance().getCharLocation(displayText, cursorCharPosition - 1);
if (cursorCharPosition == -1) {
xPos = f.stringWidth(displayText);
} else {
displayText = Display.getInstance().convertBidiLogicalToVisual(displayText);
if (!isRTLOrWhitespace((displayText.charAt(cursorCharPosition)))) {
cursorCharPosition++;
}
xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
}
}
int displayX = ta.getX() + ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - f.stringWidth(displayText);
cursorX = displayX + xPos;
x = 0;
} else {
if (cursorCharPosition > 0) {
cursorCharPosition = Math.min(displayText.length(), cursorCharPosition);
xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
}
cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos;
if (ta.isSingleLineTextArea() && ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL())) {
if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL()) {
x = ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL() - xPos - 1;
}
}
}
return cursorX + x;
}
use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.
the class UIManager method parseStyle.
/**
* Creates a style by providing style strings in a specific format. This method allows for the use of inline styles
* to override the styles in {@link com.codename1.ui.Component}
* @param theme Theme used to retrieve images referenced in the style strings.
* @param id The style ID (UIID) to use to cache the style inside the theme.
* @param prefix Prefix to use for styles. Corresponds to the {@literal prefix} argument in {@link #getComponentStyleImpl(java.lang.String, boolean, java.lang.String)
* @param baseStyle The style class from which this new style should derive.
* @param selected True if this is for a selected style.
* @param styleString Array of style strings to be parsed. The format is {@literal key1:value1; key2:value2; etc...}. While this looks similar to CSS, it is important to note that it is NOT
* CSS. The keys and values correspond to the properties of {@link com.codename1.ui.plaf.Style} and their associated values.
* @return A style object representing the styles that were provided in the styleString.
*
* <h3>Example Usage</h3>
*
* {@code
* Style s = parseStyle(theme, "Button[MyCustomButton]", "", "Button", false,
* "fgColor:ff0000; font:18mm; border: 1px solid ff0000; bgType:none; padding: 3mm; margin: 1mm");
*
* // Create a 9-piece image border on the fly:
* Style s = parseStyle(theme, "Button[MyCustomButton]", "", "Button", false,
* "border:splicedImage /notes.png 0.3 0.4 0.3 0.4");
* // This splices the image found at /notes.png into 9 pieces. Splice insets are specified by the 4 floating point values
* // at the end of the border directive: [top] [right] [bottom] [left].
* }
*/
Style parseStyle(Resources theme, String id, String prefix, String baseStyle, boolean selected, String... styleString) {
String cacheKey = selected ? id + ".sel" : id + "." + prefix;
String originalId = id;
if (id == null || id.length() == 0) {
// if no id return the default style
id = "";
} else {
id = id + ".";
}
if (Arrays.toString(styleString).equals(parseCache().get(cacheKey)) && ((selected && selectedStyles.containsKey(id)) || (!selected && this.styles.containsKey(id)))) {
return getComponentStyleImpl(originalId, selected, prefix);
}
parseCache().put(cacheKey, Arrays.toString(styleString));
Style base = baseStyle != null ? getComponentStyleImpl(baseStyle, selected, prefix) : null;
Map<String, String> styles = new HashMap<String, String>();
for (String str : styleString) {
StyleParser.parseString(styles, str);
}
StyleInfo styleInfo = new StyleInfo(styles);
if (prefix != null && prefix.length() > 0) {
id += prefix;
}
if (themeProps == null) {
resetThemeProps(null);
}
if (baseStyle != null) {
themeProps.put(id + "derive", baseStyle);
} else {
themeProps.remove(id + "derive");
}
String val = null;
Integer bgColor = styleInfo.getBgColor();
if (bgColor != null) {
themeProps.put(id + Style.BG_COLOR, Integer.toHexString(bgColor));
} else {
themeProps.remove(id + Style.BG_COLOR);
}
Integer fgColor = styleInfo.getFgColor();
if (fgColor != null) {
themeProps.put(id + Style.FG_COLOR, Integer.toHexString(fgColor));
} else {
themeProps.remove(id + Style.FG_COLOR);
}
BorderInfo border = styleInfo.getBorder();
if (border != null) {
themeProps.put(id + Style.BORDER, border.createBorder(theme));
} else {
themeProps.remove(id + Style.BORDER);
}
Integer bgType = styleInfo.getBgType();
if (bgType != null) {
themeProps.put(id + Style.BACKGROUND_TYPE, bgType.byteValue());
} else {
themeProps.remove(id + Style.BACKGROUND_TYPE);
}
ImageInfo bgImage = styleInfo.getBgImage();
if (bgImage != null) {
themeProps.put(id + Style.BG_IMAGE, bgImage.getImage(theme));
} else {
themeProps.remove(id + Style.BG_IMAGE);
}
MarginInfo margin = styleInfo.getMargin();
if (margin != null) {
float[] marginArr = margin.createMargin(base);
themeProps.put(id + Style.MARGIN, marginArr[Component.TOP] + "," + marginArr[Component.BOTTOM] + "," + marginArr[Component.LEFT] + "," + marginArr[Component.RIGHT]);
byte[] unitArr = margin.createMarginUnit(base);
themeProps.put(id + Style.MARGIN_UNIT, new byte[] { unitArr[Component.TOP], unitArr[Component.BOTTOM], unitArr[Component.LEFT], unitArr[Component.RIGHT] });
} else {
themeProps.remove(id + Style.MARGIN);
themeProps.remove(id + Style.MARGIN_UNIT);
}
PaddingInfo padding = styleInfo.getPadding();
if (padding != null) {
float[] paddingArr = padding.createPadding(base);
themeProps.put(id + Style.PADDING, paddingArr[Component.TOP] + "," + paddingArr[Component.BOTTOM] + "," + paddingArr[Component.LEFT] + "," + paddingArr[Component.RIGHT]);
byte[] unitArr = padding.createPaddingUnit(base);
themeProps.put(id + Style.PADDING_UNIT, new byte[] { unitArr[Component.TOP], unitArr[Component.BOTTOM], unitArr[Component.LEFT], unitArr[Component.RIGHT] });
} else {
themeProps.remove(id + Style.PADDING);
themeProps.remove(id + Style.PADDING_UNIT);
}
Integer transparency = styleInfo.getTransparency();
if (transparency != null) {
themeProps.put(id + Style.TRANSPARENCY, String.valueOf(transparency.intValue()));
} else {
themeProps.remove(id + Style.TRANSPARENCY);
}
Integer opacity = styleInfo.getOpacity();
if (opacity != null) {
themeProps.put(id + Style.OPACITY, String.valueOf(opacity.intValue()));
} else {
themeProps.remove(id + Style.OPACITY);
}
Integer alignment = styleInfo.getAlignment();
if (alignment != null) {
themeProps.put(id + Style.ALIGNMENT, alignment);
} else {
themeProps.remove(id + Style.ALIGNMENT);
}
Integer textDecoration = styleInfo.getTextDecoration();
if (textDecoration != null) {
themeProps.put(id + Style.TEXT_DECORATION, textDecoration);
} else {
themeProps.remove(id + Style.TEXT_DECORATION);
}
FontInfo font = styleInfo.getFont();
if (font != null) {
themeProps.put(id + Style.FONT, font.createFont(base));
} else {
themeProps.remove(id + Style.FONT);
}
if (selected)
selectedStyles.remove(id);
else
this.styles.remove(id);
return getComponentStyleImpl(originalId, selected, prefix);
}
use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.
the class Spinner method calcPreferredSize.
/**
* {@inheritDoc}
*/
protected Dimension calcPreferredSize() {
int boxWidth = 0;
int verticalPadding = getStyle().getVerticalPadding();
int horizontalPadding = getStyle().getHorizontalPadding();
Object prototype = getRenderingPrototype();
int selectedHeight;
ListCellRenderer renderer = getRenderer();
Component cmp;
if (prototype != null) {
cmp = renderer.getListCellRendererComponent(this, prototype, 0, true);
} else {
if (getModel().getSize() > 0) {
cmp = renderer.getListCellRendererComponent(this, getModel().getItemAt(0), 0, true);
} else {
cmp = renderer.getListCellRendererComponent(this, null, 0, true);
}
}
selectedHeight = cmp.getPreferredH();
if (spinnerHandle != null) {
if (spinnerHandle.getHeight() > selectedHeight) {
selectedHeight = spinnerHandle.getHeight();
}
boxWidth += spinnerHandle.getWidth();
}
Dimension d;
if (Display.getInstance().isTouchScreenDevice()) {
if (ios7Mode) {
d = new Dimension(cmp.getPreferredW() + boxWidth + horizontalPadding, (selectedHeight * 8 + verticalPadding));
} else {
d = new Dimension(cmp.getPreferredW() + boxWidth + horizontalPadding, (selectedHeight * getUIManager().getThemeConstant("spinnerElementsInt", 3) + verticalPadding));
}
} else {
d = new Dimension(cmp.getPreferredW() + boxWidth + horizontalPadding, (selectedHeight + verticalPadding));
}
Style style = getStyle();
if (style.getBorder() != null) {
d.setWidth(Math.max(style.getBorder().getMinimumWidth(), d.getWidth()));
d.setHeight(Math.max(style.getBorder().getMinimumHeight(), d.getHeight()));
}
return d;
}
use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.
the class FlowLayout method moveComponents.
private void moveComponents(Container target, int x, int y, int width, int height, int rowStart, int rowEnd, int baseline) {
switch(orientation) {
case Component.CENTER:
// this will remove half of last gap
if (target.isRTL()) {
x -= (width) / 2;
} else {
x += (width) / 2;
}
break;
case Component.RIGHT:
if (!target.isRTL()) {
// this will remove the last gap
x += width;
} else {
x -= width;
}
break;
}
Style parentStyle = target.getStyle();
int parentPadding = parentStyle.getHorizontalPadding();
for (int i = rowStart; i < rowEnd; i++) {
Component m = target.getComponentAt(i);
Style style = m.getStyle();
int marginX = style.getMarginLeftNoRTL() + style.getMarginRightNoRTL();
if (m.getWidth() + marginX < target.getWidth() - parentPadding) {
m.setX(m.getX() + x);
}
int marginTop = style.getMarginTop();
switch(valign) {
case Component.BOTTOM:
if (vAlignByRow) {
m.setY(y + Math.max(marginTop, height - m.getHeight()) - style.getMarginBottom());
} else {
m.setY(y + Math.max(marginTop, target.getHeight() - m.getHeight()) - style.getMarginBottom());
}
break;
case Component.CENTER:
if (vAlignByRow) {
m.setY(y + Math.max(marginTop, (height - m.getHeight()) / 2));
} else {
m.setY(y + Math.max(marginTop, (target.getHeight() - m.getHeight()) / 2));
}
break;
case Component.BASELINE:
m.setY(y + Math.max(marginTop, baseline - m.getBaseline(m.getWidth(), m.getHeight())));
break;
default:
m.setY(y + marginTop);
break;
}
}
}
use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.
the class GridLayout method getPreferredSize.
/**
* {@inheritDoc}
*/
public Dimension getPreferredSize(Container parent) {
int width = 0;
int height = 0;
int numOfcomponents = parent.getComponentCount();
for (int i = 0; i < numOfcomponents; i++) {
Component cmp = parent.getComponentAt(i);
width = Math.max(width, cmp.getPreferredW() + cmp.getStyle().getMarginLeftNoRTL() + cmp.getStyle().getMarginRightNoRTL());
height = Math.max(height, cmp.getPreferredH() + cmp.getStyle().getMarginTop() + cmp.getStyle().getMarginBottom());
}
boolean landscapeMode = isLandscapeMode();
autoSizeCols(parent, parent.getWidth(), landscapeMode);
int rows, columns;
if (landscapeMode) {
rows = landscapeRows;
columns = landscapeColumns;
} else {
rows = portraitRows;
columns = portraitColumns;
}
if (columns > 1) {
width = width * columns;
}
if (rows > 1) {
if (numOfcomponents > rows * columns) {
// if there are more components than planned
height = height * (numOfcomponents / columns + (numOfcomponents % columns == 0 ? 0 : 1));
} else {
height = height * rows;
}
}
Style s = parent.getStyle();
return new Dimension(width + s.getHorizontalPadding(), height + s.getVerticalPadding());
}
Aggregations