use of com.codename1.charts.models.Point in project CodenameOne by codenameone.
the class DefaultLookAndFeel method drawTextField.
/**
* {@inheritDoc}
*/
public void drawTextField(Graphics g, TextArea ta) {
setFG(g, ta);
// display ******** if it is a password field
String displayText = getTextFieldString(ta);
Style style = ta.getStyle();
int x = 0;
// ta.getCursorX();
int cursorCharPosition = ta.getCursorPosition();
Font f = style.getFont();
int cursorX = 0;
int xPos = 0;
int align = reverseAlignForBidi(ta);
int displayX = 0;
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;
}
if (ta.isSingleLineTextArea()) {
// there is currently no support for CENTER aligned text fields
if (align == Component.LEFT) {
if (cursorCharPosition > 0) {
cursorCharPosition = Math.min(displayText.length(), cursorCharPosition);
xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos;
// no point in showing the input mode when there is only one input mode...
if (inputModeWidth > 0 && ta.getInputModeOrder() != null && ta.getInputModeOrder().length == 1) {
inputModeWidth = 0;
}
if (ta.isEnableInputScroll()) {
if (ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL())) {
if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2) {
x = ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2 - xPos - 1;
}
}
}
}
displayX = ta.getX() + x + style.getPaddingLeft(ta.isRTL());
} else {
x = 0;
cursorX = getTextFieldCursorX(ta);
int baseX = ta.getX() + style.getPaddingLeftNoRTL() + inputModeWidth;
int endX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL();
if (cursorX < baseX) {
x = baseX - cursorX;
} else {
if (cursorX > endX) {
x = endX - cursorX;
}
}
displayX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL() - style.getPaddingLeftNoRTL() - f.stringWidth(displayText) + x;
}
int cx = g.getClipX();
int cy = g.getClipY();
int cw = g.getClipWidth();
int ch = g.getClipHeight();
int clipx = ta.getX() + style.getPaddingLeft(ta.isRTL());
int clipw = ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - style.getPaddingRight(ta.isRTL());
// g.pushClip();
g.clipRect(clipx, cy, clipw, ch);
switch(ta.getVerticalAlignment()) {
case Component.BOTTOM:
g.drawString(displayText, displayX, ta.getY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight(), style.getTextDecoration());
break;
case Component.CENTER:
g.drawString(displayText, displayX, ta.getY() + ta.getHeight() / 2 - f.getHeight() / 2, style.getTextDecoration());
break;
default:
g.drawString(displayText, displayX, ta.getY() + style.getPaddingTop(), style.getTextDecoration());
break;
}
g.setClip(cx, cy, cw, ch);
// g.popClip();
} else {
drawTextArea(g, ta);
}
// no point in showing the input mode when there is only one input mode...
if (inputModeWidth > 0 && ta.getInputModeOrder() != null && ta.getInputModeOrder().length > 1) {
if (ta.handlesInput() && ta.getWidth() / 2 > inputModeWidth) {
int drawXPos = ta.getX() + style.getPaddingLeft(ta.isRTL());
if ((!ta.isRTL() && style.getAlignment() == Component.LEFT) || (ta.isRTL() && style.getAlignment() == Component.RIGHT)) {
drawXPos = drawXPos + ta.getWidth() - inputModeWidth - style.getPaddingRightNoRTL() - style.getPaddingLeftNoRTL();
}
g.setColor(style.getFgColor());
int inputIndicatorY = ta.getY() + ta.getScrollY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight();
g.fillRect(drawXPos, inputIndicatorY, inputModeWidth, f.getHeight(), (byte) 140);
g.setColor(style.getBgColor());
g.drawString(inputMode, drawXPos, inputIndicatorY);
}
}
}
use of com.codename1.charts.models.Point 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.charts.models.Point in project CodenameOne by codenameone.
the class ArrowLinesLayer method paintSegment.
/**
* Paints arrows on each segment. arrowSegmentLength decides how many
* arrows will be on each segment.
* @param g
* @param segment
* @param tile
*/
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
super.paintSegment(g, segment, tile);
int pointsNo = segment.length;
for (int i = 1; i < pointsNo; i++) {
Coord start = segment[i - 1];
Coord end = segment[i];
Point s = tile.pointPosition(start);
Point e = tile.pointPosition(end);
int noOfSegments = calculateLength(s, e) / arrowSegmentLength;
if (noOfSegments == 0 && calculateLength(s, e) > minArrowSementLength) {
noOfSegments = 1;
}
for (int j = 1; j <= noOfSegments; j++) {
if (j == 1) {
double div = 1.0 / noOfSegments;
drawArrow(g, new Point(s.getX(), s.getY()), new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))));
} else if (j == noOfSegments) {
double div = (noOfSegments - 1) / (noOfSegments * 1.0);
drawArrow(g, new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))), new Point(e.getX(), e.getY()));
} else {
double div = ((j - 1) * 1.0) / noOfSegments;
double div2 = (j * 1.0) / noOfSegments;
drawArrow(g, new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))), new Point((int) (div2 * e.getX() + s.getX() * (1 - div2)), (int) (div2 * e.getY() + s.getY() * (1 - div2))));
}
}
}
}
use of com.codename1.charts.models.Point in project CodenameOne by codenameone.
the class LinesLayer method paintSegment.
/**
* Paint a segment.
*
* @param g a Graphics Object to paint on
* @param segment array of Coord to draw a Line.
* @param tile
*/
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
int pointsNo = segment.length;
for (int i = 1; i < pointsNo; i++) {
Coord start = (Coord) segment[i - 1];
Coord end = (Coord) segment[i];
Point s = tile.pointPosition(start);
Point e = tile.pointPosition(end);
g.drawLine(s.getX(), s.getY(), e.getX(), e.getY());
// lame & simple way to make line thicker
g.drawLine(s.getX() - 1, s.getY(), e.getX() - 1, e.getY());
g.drawLine(s.getX() + 1, s.getY(), e.getX() + 1, e.getY());
g.drawLine(s.getX(), s.getY() - 1, e.getX(), e.getY() - 1);
g.drawLine(s.getX(), s.getY() + 1, e.getX(), e.getY() + 1);
}
}
use of com.codename1.charts.models.Point in project CodenameOne by codenameone.
the class PointsLayer method addPoint.
/**
* Adds a point to the PointsLayer
*
* @param point a point to add
*/
public void addPoint(PointLayer point) {
Image pointIcon = point.getIcon();
if (pointIcon == null) {
point.setIcon(icon);
}
if (!point.isProjected()) {
Coord c = getProjection().fromWGS84(point);
point.setLatitude(c.getLatitude());
point.setLongitude(c.getLongitude());
point.setProjected(true);
}
points.addElement(point);
}
Aggregations