use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class BytecodeMethod method appendMethodC.
public void appendMethodC(StringBuilder b) {
if (nativeMethod) {
return;
}
appendCMethodPrefix(b, "");
b.append(" {\n");
if (eliminated) {
if (returnType.isVoid()) {
b.append(" return;\n}\n\n");
} else {
b.append(" return 0;\n}\n\n");
}
return;
}
b.append(declaration);
boolean hasInstructions = true;
if (optimizerOn) {
hasInstructions = optimize();
}
if (hasInstructions) {
Set<String> added = new HashSet<String>();
for (LocalVariable lv : localVariables) {
String variableName = lv.getQualifier() + "locals_" + lv.getIndex() + "_";
if (!added.contains(variableName) && lv.getQualifier() != 'o') {
added.add(variableName);
b.append(" volatile ");
switch(lv.getQualifier()) {
case 'i':
b.append("JAVA_INT");
break;
case 'l':
b.append("JAVA_LONG");
break;
case 'f':
b.append("JAVA_FLOAT");
break;
case 'd':
b.append("JAVA_DOUBLE");
break;
}
b.append(" ").append(lv.getQualifier()).append("locals_").append(lv.getIndex()).append("_ = 0; /* ").append(lv.getOrigName()).append(" */\n");
}
}
if (staticMethod) {
if (methodName.equals("__CLINIT__")) {
b.append(" DEFINE_METHOD_STACK(");
} else {
b.append(" __STATIC_INITIALIZER_");
b.append(clsName.replace('/', '_').replace('$', '_'));
b.append("(threadStateData);\n DEFINE_METHOD_STACK(");
}
} else {
b.append(" DEFINE_INSTANCE_METHOD_STACK(");
}
b.append(maxStack);
b.append(", ");
b.append(maxLocals);
b.append(", 0, ");
b.append(Parser.addToConstantPool(clsName));
b.append(", ");
b.append(Parser.addToConstantPool(methodName));
b.append(");\n");
int startOffset = 0;
if (synchronizedMethod) {
if (staticMethod) {
b.append(" monitorEnterBlock(threadStateData, (JAVA_OBJECT)&class__");
b.append(clsName);
b.append(");\n");
} else {
b.append(" monitorEnterBlock(threadStateData, __cn1ThisObject);\n");
}
}
if (!staticMethod) {
b.append(" locals[0].data.o = __cn1ThisObject; locals[0].type = CN1_TYPE_OBJECT; ");
startOffset++;
}
int localsOffset = startOffset;
for (int iter = 0; iter < arguments.size(); iter++) {
ByteCodeMethodArg arg = arguments.get(iter);
if (arg.getQualifier() == 'o') {
b.append(" locals[");
b.append(localsOffset);
b.append("].data.");
b.append(arg.getQualifier());
b.append(" = __cn1Arg");
b.append(iter + 1);
b.append(";\n");
b.append(" locals[");
b.append(localsOffset);
b.append("].type = CN1_TYPE_OBJECT;\n");
} else {
b.append(" ");
if (!hasLocalVariableWithIndex(arg.getQualifier(), localsOffset)) {
switch(arg.getQualifier()) {
case 'i':
b.append("JAVA_INT");
break;
case 'f':
b.append("JAVA_FLOAT");
break;
case 'd':
b.append("JAVA_DOUBLE");
break;
case 'l':
b.append("JAVA_LONG");
break;
default:
b.append("JAVA_INT");
break;
}
b.append(" ");
}
b.append(arg.getQualifier());
b.append("locals_");
b.append(localsOffset);
b.append("_");
b.append(" = __cn1Arg");
b.append(iter + 1);
b.append(";\n");
}
// For now we'll still allocate space for locals that we're not using
// so we keep the indexes the same for objects.
localsOffset++;
if (arg.isDoubleOrLong()) {
localsOffset++;
}
}
} else {
if (synchronizedMethod) {
if (staticMethod) {
b.append(" monitorEnterBlock(threadStateData, (JAVA_OBJECT)&class__");
b.append(clsName);
b.append(");\n");
} else {
b.append(" monitorEnterBlock(threadStateData, __cn1ThisObject);\n");
}
}
}
BasicInstruction.setSynchronizedMethod(synchronizedMethod, staticMethod, clsName);
TryCatch.reset();
BasicInstruction.setHasInstructions(hasInstructions);
for (Instruction i : instructions) {
i.setMaxes(maxStack, maxLocals);
i.appendInstruction(b, instructions);
}
if (instructions.size() == 0) {
if (returnType.isVoid()) {
b.append(" return;\n}\n\n");
} else {
b.append(" return 0;\n}\n\n");
}
return;
}
Instruction inst = instructions.get(instructions.size() - 1);
int lastInstruction = inst.getOpcode();
if (lastInstruction == -1 || inst instanceof LabelInstruction) {
if (instructions.size() > 2) {
inst = instructions.get(instructions.size() - 2);
lastInstruction = inst.getOpcode();
}
}
if (lastInstruction == Opcodes.RETURN || lastInstruction == Opcodes.ARETURN || lastInstruction == Opcodes.IRETURN || lastInstruction == Opcodes.LRETURN || lastInstruction == Opcodes.FRETURN || lastInstruction == Opcodes.DRETURN || lastInstruction == -1) {
b.append("}\n\n");
} else {
if (returnType.isVoid()) {
b.append(" return;\n}\n\n");
} else {
b.append(" return 0;\n}\n\n");
}
}
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class ScatterChart method drawSeries.
/**
* The graphical representation of a series.
*
* @param canvas the canvas to paint to
* @param paint the paint to be used for drawing
* @param points the array of points to be used for drawing the series
* @param seriesRenderer the series renderer
* @param yAxisValue the minimum value of the y axis
* @param seriesIndex the index of the series currently being drawn
* @param startIndex the start index of the rendering points
*/
@Override
public void drawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer renderer, float yAxisValue, int seriesIndex, int startIndex) {
paint.setColor(renderer.getColor());
final float stroke = paint.getStrokeWidth();
if (renderer.isFillPoints()) {
paint.setStyle(Style.FILL);
} else {
paint.setStrokeWidth(renderer.getPointStrokeWidth());
paint.setStyle(Style.STROKE);
}
int length = points.size();
// switch on ENUM's generates reflection code that screws up J2ME
PointStyle ps = renderer.getPointStyle();
if (ps == PointStyle.X) {
paint.setStrokeWidth(renderer.getPointStrokeWidth());
for (int i = 0; i < length; i += 2) {
drawX(canvas, paint, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.CIRCLE) {
for (int i = 0; i < length; i += 2) {
drawCircle(canvas, paint, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.TRIANGLE) {
float[] path = new float[6];
for (int i = 0; i < length; i += 2) {
drawTriangle(canvas, paint, path, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.SQUARE) {
for (int i = 0; i < length; i += 2) {
drawSquare(canvas, paint, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.DIAMOND) {
float[] path = new float[8];
for (int i = 0; i < length; i += 2) {
drawDiamond(canvas, paint, path, points.get(i), points.get(i + 1));
}
} else {
if (ps == PointStyle.POINT) {
for (int i = 0; i < length; i += 2) {
canvas.drawPoint(points.get(i), points.get(i + 1), paint);
}
}
}
}
}
}
}
/*switch (renderer.getPointStyle()) {
case X:
paint.setStrokeWidth(renderer.getPointStrokeWidth());
for (int i = 0; i < length; i += 2) {
drawX(canvas, paint, points.get(i), points.get(i + 1));
}
break;
case CIRCLE:
for (int i = 0; i < length; i += 2) {
drawCircle(canvas, paint, points.get(i), points.get(i + 1));
}
break;
case TRIANGLE:
float[] path = new float[6];
for (int i = 0; i < length; i += 2) {
drawTriangle(canvas, paint, path, points.get(i), points.get(i + 1));
}
break;
case SQUARE:
for (int i = 0; i < length; i += 2) {
drawSquare(canvas, paint, points.get(i), points.get(i + 1));
}
break;
case DIAMOND:
path = new float[8];
for (int i = 0; i < length; i += 2) {
drawDiamond(canvas, paint, path, points.get(i), points.get(i + 1));
}
break;
case POINT:
for (int i = 0; i < length; i += 2) {
canvas.drawPoint(points.get(i), points.get(i + 1), paint);
}
break;
}*/
paint.setStrokeWidth(stroke);
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class InteractionDialog method disposeTo.
private void disposeTo(int direction, final Runnable onFinish) {
disposed = true;
final Container p = getParent();
if (p != null) {
final Form f = p.getComponentForm();
if (f != null) {
switch(direction) {
case Component.LEFT:
setX(-getWidth());
break;
case Component.TOP:
setY(-getHeight());
break;
case Component.RIGHT:
setX(Display.getInstance().getDisplayWidth());
break;
case Component.BOTTOM:
setY(Display.getInstance().getDisplayHeight());
break;
}
if (animateShow) {
p.animateUnlayout(getUIManager().getThemeConstant("interactionDialogSpeedInt", 400), 255, new Runnable() {
public void run() {
if (p.getParent() != null) {
Container pp = getLayeredPane(f);
remove();
p.remove();
pp.removeAll();
pp.revalidate();
cleanupLayer(f);
}
if (onFinish != null) {
onFinish.run();
}
}
});
} else {
p.revalidate();
Container pp = getLayeredPane(f);
remove();
p.remove();
pp.removeAll();
pp.revalidate();
if (onFinish != null) {
onFinish.run();
}
}
} else {
remove();
if (onFinish != null) {
onFinish.run();
}
}
}
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class LineChart method drawSeries.
/**
* The graphical representation of a series.
*
* @param canvas the canvas to paint to
* @param paint the paint to be used for drawing
* @param points the array of points to be used for drawing the series
* @param seriesRenderer the series renderer
* @param yAxisValue the minimum value of the y axis
* @param seriesIndex the index of the series currently being drawn
* @param startIndex the start index of the rendering points
*/
@Override
public void drawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer renderer, float yAxisValue, int seriesIndex, int startIndex) {
float lineWidth = paint.getStrokeWidth();
paint.setStrokeWidth(renderer.getLineWidth());
final FillOutsideLine[] fillOutsideLine = renderer.getFillOutsideLine();
for (FillOutsideLine fill : fillOutsideLine) {
if (fill.getType() != FillOutsideLine.Type.NONE) {
paint.setColor(fill.getColor());
// TODO: find a way to do area charts without duplicating data
List<Float> fillPoints = new ArrayList<Float>();
int[] range = fill.getFillRange();
if (range == null) {
fillPoints.addAll(points);
} else {
if (points.size() > range[0] * 2 && points.size() > range[1] * 2) {
fillPoints.addAll(points.subList(range[0] * 2, range[1] * 2));
}
}
final float referencePoint;
// switch on ENUM's generates reflection code that screws up J2ME
FillOutsideLine.Type tt = fill.getType();
if (tt == FillOutsideLine.Type.BOUNDS_ALL || tt == FillOutsideLine.Type.BOUNDS_BELOW || tt == FillOutsideLine.Type.BOUNDS_ABOVE) {
referencePoint = yAxisValue;
} else {
if (tt == FillOutsideLine.Type.BELOW) {
referencePoint = canvas.getHeight();
} else {
if (tt == FillOutsideLine.Type.ABOVE) {
referencePoint = 0;
} else {
throw new RuntimeException("You have added a new type of filling but have not implemented.");
}
}
}
/*switch (fill.getType()) {
case BOUNDS_ALL:
referencePoint = yAxisValue;
break;
case BOUNDS_BELOW:
referencePoint = yAxisValue;
break;
case BOUNDS_ABOVE:
referencePoint = yAxisValue;
break;
case BELOW:
referencePoint = canvas.getHeight();
break;
case ABOVE:
referencePoint = 0;
break;
default:
throw new RuntimeException(
"You have added a new type of filling but have not implemented.");
}*/
if (fill.getType() == FillOutsideLine.Type.BOUNDS_ABOVE || fill.getType() == FillOutsideLine.Type.BOUNDS_BELOW) {
List<Float> boundsPoints = new ArrayList<Float>();
boolean add = false;
int length = fillPoints.size();
if (length > 0 && fill.getType() == FillOutsideLine.Type.BOUNDS_ABOVE && fillPoints.get(1) < referencePoint || fill.getType() == FillOutsideLine.Type.BOUNDS_BELOW && fillPoints.get(1) > referencePoint) {
boundsPoints.add(fillPoints.get(0));
boundsPoints.add(fillPoints.get(1));
add = true;
}
for (int i = 3; i < length; i += 2) {
float prevValue = fillPoints.get(i - 2);
float value = fillPoints.get(i);
if (prevValue < referencePoint && value > referencePoint || prevValue > referencePoint && value < referencePoint) {
float prevX = fillPoints.get(i - 3);
float x = fillPoints.get(i - 1);
boundsPoints.add(prevX + (x - prevX) * (referencePoint - prevValue) / (value - prevValue));
boundsPoints.add(referencePoint);
if (fill.getType() == FillOutsideLine.Type.BOUNDS_ABOVE && value > referencePoint || fill.getType() == FillOutsideLine.Type.BOUNDS_BELOW && value < referencePoint) {
i += 2;
add = false;
} else {
boundsPoints.add(x);
boundsPoints.add(value);
add = true;
}
} else {
if (add || fill.getType() == FillOutsideLine.Type.BOUNDS_ABOVE && value < referencePoint || fill.getType() == FillOutsideLine.Type.BOUNDS_BELOW && value > referencePoint) {
boundsPoints.add(fillPoints.get(i - 1));
boundsPoints.add(value);
}
}
}
fillPoints.clear();
fillPoints.addAll(boundsPoints);
}
int length = fillPoints.size();
if (length > 0) {
fillPoints.set(0, fillPoints.get(0) + 1);
fillPoints.add(fillPoints.get(length - 2));
fillPoints.add(referencePoint);
fillPoints.add(fillPoints.get(0));
fillPoints.add(fillPoints.get(length + 1));
for (int i = 0; i < length + 4; i += 2) {
if (fillPoints.get(i + 1) < 0) {
fillPoints.set(i + 1, 0f);
}
}
paint.setStyle(Style.FILL);
drawPath(canvas, fillPoints, paint, true);
}
}
}
paint.setColor(renderer.getColor());
paint.setStyle(Style.STROKE);
drawPath(canvas, points, paint, false);
paint.setStrokeWidth(lineWidth);
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class TableLayout method placeComponent.
/**
* Places the component/constraint in the proper alignment within the cell whose bounds are given
*/
private void placeComponent(boolean rtl, Constraint con, int x, int y, int width, int height) {
con.parent.setX(x);
con.parent.setY(y);
con.parent.setWidth(width);
con.parent.setHeight(height);
Dimension pref = con.parent.getPreferredSize();
int pWidth = pref.getWidth();
int pHeight = pref.getHeight();
if (pWidth < width) {
int d = (width - pWidth);
int a = con.align;
if (rtl) {
switch(a) {
case Component.LEFT:
a = Component.RIGHT;
break;
case Component.RIGHT:
a = Component.LEFT;
break;
}
}
switch(a) {
case Component.LEFT:
con.parent.setX(x);
con.parent.setWidth(width - d);
break;
case Component.RIGHT:
con.parent.setX(x + d);
con.parent.setWidth(width - d);
break;
case Component.CENTER:
con.parent.setX(x + d / 2);
con.parent.setWidth(width - d);
break;
}
}
if (pHeight < height) {
int d = (height - pHeight);
switch(con.valign) {
case Component.TOP:
con.parent.setY(y);
con.parent.setHeight(height - d);
break;
case Component.BOTTOM:
con.parent.setY(y + d);
con.parent.setHeight(height - d);
break;
case Component.CENTER:
con.parent.setY(y + d / 2);
con.parent.setHeight(height - d);
break;
}
}
}
Aggregations