use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class LazyValueC method readObjectArrayForListModel.
private Object[] readObjectArrayForListModel(DataInputStream in, Resources res) throws IOException {
Object[] elements = new Object[in.readInt()];
int elen = elements.length;
for (int iter = 0; iter < elen; iter++) {
switch(in.readByte()) {
case // String
1:
elements[iter] = in.readUTF();
break;
case // hashtable of Strings
2:
int hashSize = in.readInt();
Hashtable val = new Hashtable();
elements[iter] = val;
for (int i = 0; i < hashSize; i++) {
int type = in.readInt();
if (type == 1) {
// String
String key = in.readUTF();
Object value = in.readUTF();
if (key.equals("$navigation")) {
Command cmd = createCommandImpl((String) value, null, -1, (String) value, false, "");
cmd.putClientProperty(COMMAND_ACTION, (String) value);
value = cmd;
}
val.put(key, value);
} else {
val.put(in.readUTF(), res.getImage(in.readUTF()));
}
}
break;
}
}
return elements;
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class LazyValueC method postCreateComponents.
/**
* Invoked after the components were created to allow properties that require the entire
* tree to exist to update the component. This is useful for properties that point
* at other components.
*/
private void postCreateComponents(DataInputStream in, Container parent, Resources res) throws Exception {
// finds the component whose properties need to update
String name = in.readUTF();
Component lastComponent = null;
while (name.length() > 0) {
if (lastComponent == null || !lastComponent.getName().equals(name)) {
lastComponent = findByName(name, parent);
}
Component c = lastComponent;
int property = in.readInt();
modifyingProperty(c, property);
switch(property) {
case PROPERTY_COMMAND_LEGACY:
{
readCommand(in, c, parent, res, true);
break;
}
case PROPERTY_COMMAND:
{
readCommand(in, c, parent, res, false);
break;
}
case PROPERTY_LABEL_FOR:
c.setLabelForComponent((Label) findByName(in.readUTF(), parent));
break;
case PROPERTY_LEAD_COMPONENT:
((Container) c).setLeadComponent(findByName(in.readUTF(), parent));
break;
case PROPERTY_NEXT_FOCUS_UP:
c.setNextFocusUp(findByName(in.readUTF(), parent));
break;
case PROPERTY_NEXT_FOCUS_DOWN:
c.setNextFocusDown(findByName(in.readUTF(), parent));
break;
case PROPERTY_NEXT_FOCUS_LEFT:
c.setNextFocusLeft(findByName(in.readUTF(), parent));
break;
case PROPERTY_NEXT_FOCUS_RIGHT:
c.setNextFocusRight(findByName(in.readUTF(), parent));
break;
}
name = in.readUTF();
}
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class Spinner method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
super.paint(g);
if (spinnerHandle != null) {
Style s = getStyle();
g.drawImage(spinnerHandle, getX() + getWidth() - spinnerHandle.getWidth() - s.getHorizontalPadding(), getY() + s.getPaddingTop());
}
if (System.currentTimeMillis() - inputSkipDelay < lastKeyInteraction || quickType.isPendingCommit()) {
quickType.setWidth(Math.min(getWidth(), quickType.getPreferredW()));
quickType.setHeight(Math.min(getHeight(), quickType.getPreferredH()));
Style s = quickType.getStyle();
quickType.setY(getScrollY() + getY());
// positioning based on date/time
if (getRenderer() instanceof DateTimeRenderer) {
switch(currentInputAlign) {
case LEFT:
quickType.setX(getX());
break;
case RIGHT:
quickType.setX(getX() + quickType.getStyle().getFont().charWidth(TextArea.getWidestChar()) * 4 + s.getMarginRightNoRTL());
break;
default:
quickType.setX(getX() + quickType.getStyle().getFont().charWidth(TextArea.getWidestChar()) * 2 + s.getMarginLeftNoRTL());
break;
}
} else {
quickType.setX(getX());
}
quickType.paintComponent(g, true);
}
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class SpinnerNode method render.
// @Override
public void render(Graphics g) {
g.setColor(overlayStyle.getBgColor());
int alpha = g.getAlpha();
g.setAlpha(255);
g.fillRect(0, 0, (int) boundsInLocal.get().getWidth(), (int) boundsInLocal.get().getHeight());
g.setAlpha(alpha);
super.render(g);
int clipX = g.getClipX();
int clipY = g.getClipY();
int clipW = g.getClipWidth();
int clipH = g.getClipHeight();
Rectangle2D overlayRect = selectedRowOverlay.getBoundsInScene(new Rectangle2D());
double magnification = 1.35;
double oldScaleX = scaleX.get();
double oldScaleY = scaleY.get();
double oldTranslateX = translateX.get();
scaleX.set(oldScaleX * magnification);
scaleY.set(oldScaleY * magnification);
switch(getRowStyle().getAlignment()) {
case Component.LEFT:
translateX.set(oldTranslateX + boundsInLocal.get().getWidth() * (magnification - 1.0) / 2 / magnification);
break;
case Component.RIGHT:
translateX.set(oldTranslateX - boundsInLocal.get().getWidth() * (magnification - 1.0) / 2 / magnification);
break;
}
selectedRowOverlay.visible.set(false);
g.setClip((int) overlayRect.getX(), (int) overlayRect.getY() + 1, (int) overlayRect.getWidth(), (int) overlayRect.getHeight() - 2);
super.render(g);
selectedRowOverlay.visible.set(true);
g.setClip(clipX, clipY, clipW, clipH);
scaleX.set(oldScaleX);
scaleY.set(oldScaleY);
translateX.set(oldTranslateX);
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class TextPainter method paint.
/**
* Paints the text onto the provided graphics context.
* @param g The graphics to paint onto.
* @param bounds The bounding rect.
* @param node The node whose content we are painting.
*/
@Override
public void paint(Graphics g, Rectangle bounds, Node node) {
Style style = node.getStyle();
if (style == null) {
return;
}
Font font = style.getFont();
if (font == null) {
font = Font.getDefaultFont();
}
int textWidth = font.stringWidth(text);
int textHeight = font.getHeight();
int innerX = bounds.getX() + style.getPaddingLeft(false);
int innerY = bounds.getY() + style.getPaddingTop();
int innerW = bounds.getWidth() - style.getHorizontalPadding();
int innerH = bounds.getHeight() - style.getVerticalPadding();
int x = innerX;
int y = innerY;
switch(style.getAlignment()) {
case Component.CENTER:
x = innerX + innerW / 2 - textWidth / 2;
break;
case Component.RIGHT:
x = innerX + innerW - textWidth;
break;
}
switch(vAlign) {
case Component.CENTER:
y = innerY + innerH / 2 - textHeight / 2;
break;
case Component.BOTTOM:
y = innerY + innerH - textHeight;
break;
}
g.setFont(font);
g.setColor(style.getFgColor());
int alpha = g.concatenateAlpha(style.getFgAlpha());
g.drawString(text, x, y);
g.setAlpha(alpha);
}
Aggregations