use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class Component method internalPaintImpl.
void internalPaintImpl(Graphics g, boolean paintIntersects) {
g.clipRect(getX(), getY(), getWidth(), getHeight());
paintComponentBackground(g);
if (isScrollable()) {
if (refreshTask != null && (draggedMotionY == null || getClientProperty("$pullToRelease") != null)) {
paintPullToRefresh(g);
}
int scrollX = getScrollX();
int scrollY = getScrollY();
g.translate(-scrollX, -scrollY);
paint(g);
g.translate(scrollX, scrollY);
if (isScrollVisible) {
paintScrollbars(g);
}
} else {
paint(g);
}
if (isBorderPainted()) {
paintBorder(g);
}
// paint all the intersecting Components above the Component
if (paintIntersects && parent != null) {
paintIntersectingComponentsAbove(g);
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class SpinnerRenderer method paint.
@Override
public void paint(Graphics g) {
if (!iOS7Mode || perspective == FRONT_ANGLE) {
super.paint(g);
} else {
if (!isInClippingRegion(g)) {
return;
}
Style s = getStyle();
drawStringPerspectivePosition(g, getText(), getX() + s.getPaddingLeftNoRTL(), getY() + s.getPaddingTop());
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class Table method paintGlass.
/**
* {@inheritDoc}
*/
protected void paintGlass(Graphics g) {
if ((drawBorder) && (innerBorder != INNER_BORDERS_NONE)) {
int xPos = getAbsoluteX();
int yPos = getAbsoluteY();
g.translate(xPos, yPos);
int rows = model.getRowCount();
int cols = model.getColumnCount();
if (includeHeader) {
rows++;
}
g.setColor(getStyle().getFgColor());
TableLayout t = (TableLayout) getLayout();
int actualWidth = Math.max(getWidth(), getScrollDimension().getWidth());
int actualHeight = Math.max(getHeight(), getScrollDimension().getHeight());
if (// inner borders cols/rows are supported only in collapsed mode
(collapseBorder) || (innerBorder != INNER_BORDERS_ALL) || (t.hasHorizontalSpanning()) || (t.hasVerticalSpanning())) {
// TODO - We currently don't support separate borders for tables with spanned cells
if ((innerBorder == INNER_BORDERS_ALL) || (innerBorder == INNER_BORDERS_ROWS)) {
if (t.hasVerticalSpanning()) {
// the components other than the ones that are at the last column.
for (int cellRow = 0; cellRow < rows - 1; cellRow++) {
for (int cellColumn = 0; cellColumn < cols; cellColumn++) {
// if this isn't the last row
if (cellRow + t.getCellVerticalSpan(cellRow, cellColumn) - 1 != rows - 1) {
// if this is a spanned through cell we don't want to draw a line here
if (t.isCellSpannedThroughHorizontally(cellRow, cellColumn)) {
continue;
}
int x = t.getColumnPosition(cellColumn);
int y = t.getRowPosition(cellRow);
int rowHeight = t.getRowPosition(cellRow + t.getCellVerticalSpan(cellRow, cellColumn)) - y;
int columnWidth;
if (cellColumn < getModel().getColumnCount() - 1) {
columnWidth = t.getColumnPosition(cellColumn + 1) - x;
} else {
columnWidth = getWidth() - y;
}
if ((innerBorder != INNER_BORDERS_ROWS) || (shouldDrawInnerBorderAfterRow(cellRow))) {
g.drawLine(x, y + rowHeight, x + columnWidth, y + rowHeight);
}
}
}
}
} else {
// this is much faster since we don't need to check spanning
for (int row = 1; row < rows; row++) {
int y = t.getRowPosition(row);
if ((innerBorder != INNER_BORDERS_ROWS) || (shouldDrawInnerBorderAfterRow(row - 1))) {
g.drawLine(0, y, actualWidth, y);
}
// g.drawLine(0+2, y+2, actualWidth-2, y+2);
}
}
}
if ((innerBorder == INNER_BORDERS_ALL) || (innerBorder == INNER_BORDERS_COLS)) {
if (t.hasHorizontalSpanning()) {
// the components other than the ones that are at the last column.
for (int cellRow = 0; cellRow < rows; cellRow++) {
for (int cellColumn = 0; cellColumn < cols - 1; cellColumn++) {
// if this isn't the last column
if (cellColumn + t.getCellHorizontalSpan(cellRow, cellColumn) - 1 != cols - 1) {
// if this is a spanned through cell we don't want to draw a line here
if (t.isCellSpannedThroughVertically(cellRow, cellColumn)) {
continue;
}
int x = t.getColumnPosition(cellColumn);
int y = t.getRowPosition(cellRow);
int rowHeight;
int columnWidth = t.getColumnPosition(cellColumn + t.getCellHorizontalSpan(cellRow, cellColumn)) - x;
if (cellRow < getModel().getRowCount() - 1) {
rowHeight = t.getRowPosition(cellRow + 1) - y;
} else {
rowHeight = getHeight() - y;
}
g.drawLine(x + columnWidth, y, x + columnWidth, y + rowHeight);
}
if (t.getCellHorizontalSpan(cellRow, cellColumn) > 1) {
cellColumn += t.getCellHorizontalSpan(cellRow, cellColumn) - 1;
}
}
}
} else {
for (int col = 1; col < cols; col++) {
int x = t.getColumnPosition(col);
g.drawLine(x, 0, x, actualHeight);
// g.drawLine(x+2, 0+2, x+2, actualHeight-2);
}
}
}
} else {
// if ((!t.hasHorizontalSpanning()) && (!t.hasVerticalSpanning())) {
for (int row = 0; row < rows; row++) {
int y = t.getRowPosition(row);
int h;
if (row + 1 < rows) {
h = t.getRowPosition(row + 1) - y;
} else {
h = getY() + actualHeight - y - 2;
}
for (int col = 0; col < cols; col++) {
int x = t.getColumnPosition(col);
int w;
if (col + 1 < cols) {
w = t.getColumnPosition(col + 1) - x;
} else {
w = getX() + actualWidth - x - 2;
}
Component comp = t.getComponentAt(row, col);
if ((comp.isVisible()) && ((drawEmptyCellsBorder) || ((comp.getWidth() - comp.getStyle().getPaddingRightNoRTL() - comp.getStyle().getPaddingLeftNoRTL() > 0) && (comp.getHeight() - comp.getStyle().getPaddingTop() - comp.getStyle().getPaddingBottom() > 0)))) {
int rightMargin = comp.getStyle().getMarginRightNoRTL();
int bottomMargin = comp.getStyle().getMarginBottom();
if (col == 0) {
// Since the first cell includes margins from both sides (left/right) so the next cell location is farther away - but we don't want to paint the border up to it
rightMargin *= 2;
}
if (row == 0) {
bottomMargin *= 2;
}
g.drawRect(x + comp.getStyle().getMarginLeftNoRTL(), y + comp.getStyle().getMarginTop(), w - 2 - rightMargin, h - 2 - bottomMargin);
}
}
}
}
g.translate(-xPos, -yPos);
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class GameCanvasImplementation method captureVideo.
public void captureVideo(ActionListener response) {
captureResponse = response;
try {
final Form current = Display.getInstance().getCurrent();
final MMAPIPlayer player = MMAPIPlayer.createPlayer("capture://video", null);
RecordControl record = (RecordControl) player.nativePlayer.getControl("RecordControl");
if (record == null) {
player.cleanup();
throw new RuntimeException("Capture Video is not supported on this device");
}
final Form cam = new Form();
cam.setTransitionInAnimator(CommonTransitions.createEmpty());
cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
cam.setLayout(new BorderLayout());
cam.show();
MIDPVideoComponent video = new MIDPVideoComponent(player, canvas);
video.play();
video.setVisible(true);
cam.addComponent(BorderLayout.CENTER, video);
final Label time = new Label("0:00");
cam.addComponent(BorderLayout.SOUTH, time);
cam.revalidate();
ActionListener l = new ActionListener() {
boolean recording = false;
OutputStream out = null;
String videoPath = null;
RecordControl record;
public void actionPerformed(ActionEvent evt) {
if (!recording) {
record = (RecordControl) player.nativePlayer.getControl("RecordControl");
recording = true;
String type = record.getContentType();
String prefix = "";
if (type.endsWith("mpeg")) {
prefix = ".mpeg";
} else if (type.endsWith("4")) {
prefix = ".mp4";
} else if (type.endsWith("3gpp")) {
prefix = ".3gp";
} else if (type.endsWith("avi")) {
prefix = ".avi";
}
videoPath = getOutputMediaFile() + prefix;
try {
out = FileSystemStorage.getInstance().openOutputStream(videoPath);
record.setRecordStream(out);
record.startRecord();
cam.registerAnimated(new Animation() {
long current = System.currentTimeMillis();
long zero = current;
int sec = 0;
public boolean animate() {
long now = System.currentTimeMillis();
if (now - current > 1000) {
current = now;
sec++;
return true;
}
return false;
}
public void paint(Graphics g) {
String txt = sec / 60 + ":" + sec % 60;
time.setText(txt);
}
});
} catch (IOException ex) {
ex.printStackTrace();
System.out.println("failed to store video to " + videoPath);
} finally {
}
} else {
if (out != null) {
try {
record.stopRecord();
record.commit();
out.close();
player.cleanup();
} catch (Exception ex) {
ex.printStackTrace();
}
}
captureResponse.actionPerformed(new ActionEvent(videoPath));
current.showBack();
}
}
};
cam.addGameKeyListener(Display.GAME_FIRE, l);
cam.addPointerReleasedListener(l);
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException("failed to start camera");
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class BlackBerryImplementation method nativeEdit.
public void nativeEdit(final Component cmp, final int maxSize, final int constraint, String text, int keyCode) {
if (nativeEdit != null) {
finishEdit(true);
}
lightweightEdit = (TextArea) cmp;
if (keyCode > 0 && getKeyboardType() == Display.KEYBOARD_TYPE_QWERTY) {
// if this is a number
if ((constraint & TextArea.DECIMAL) == TextArea.DECIMAL || (constraint & TextArea.NUMERIC) == TextArea.NUMERIC || (constraint & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) {
if (keyCode == 119) {
text += "1";
} else if (keyCode == 101) {
text += "2";
} else if (keyCode == 114) {
text += "3";
} else if (keyCode == 115) {
text += "4";
} else if (keyCode == 100) {
text += "5";
} else if (keyCode == 102) {
text += "6";
} else if (keyCode == 122) {
text += "7";
} else if (keyCode == 120) {
text += "8";
} else if (keyCode == 99) {
text += "9";
}
} else {
text += ((char) keyCode);
}
lightweightEdit.setText(text);
}
class LightweightEdit implements Runnable, Animation {
public void run() {
long type = 0;
TextArea lightweightEditTmp = lightweightEdit;
if (lightweightEditTmp == null) {
return;
}
int constraint = lightweightEditTmp.getConstraint();
if ((constraint & TextArea.DECIMAL) == TextArea.DECIMAL) {
type = BasicEditField.FILTER_REAL_NUMERIC;
} else if ((constraint & TextArea.EMAILADDR) == TextArea.EMAILADDR) {
type = BasicEditField.FILTER_EMAIL;
} else if ((constraint & TextArea.NUMERIC) == TextArea.NUMERIC) {
type = BasicEditField.FILTER_NUMERIC;
}
if ((constraint & TextArea.PHONENUMBER) == TextArea.PHONENUMBER) {
type = BasicEditField.FILTER_PHONE;
}
if ((constraint & TextArea.NON_PREDICTIVE) == TextArea.NON_PREDICTIVE) {
type |= BasicEditField.NO_COMPLEX_INPUT;
}
if (lightweightEditTmp.isSingleLineTextArea()) {
type |= BasicEditField.NO_NEWLINE;
}
if ((constraint & TextArea.PASSWORD) == TextArea.PASSWORD) {
nativeEdit = new BBPasswordEditField(lightweightEditTmp, type, maxSize);
} else {
nativeEdit = new BBEditField(lightweightEditTmp, type, maxSize);
}
nativeEdit.setEditable(true);
Font f = nativeEdit.getFont();
if (f.getHeight() > lightweightEditTmp.getStyle().getFont().getHeight()) {
nativeEdit.setFont(f.derive(f.getStyle(), lightweightEditTmp.getStyle().getFont().getHeight()));
}
canvas.add(nativeEdit);
nativeEdit.setCursorPosition(lightweightEditTmp.getText().length());
try {
nativeEdit.setFocus();
} catch (Throwable t) {
// no idea why this throws an exception sometimes
// t.printStackTrace();
}
}
public boolean animate() {
BasicEditField ef = nativeEdit;
Component lw = lightweightEdit;
if (lw == null || lw.getComponentForm() != Display.getInstance().getCurrent()) {
Display.getInstance().getCurrent().deregisterAnimated(this);
finishEdit(false);
} else {
if (ef != null) {
if (ef.isDirty()) {
lw.repaint();
}
}
}
return false;
}
public void paint(com.codename1.ui.Graphics g) {
}
}
LightweightEdit lw = new LightweightEdit();
Display.getInstance().getCurrent().registerAnimated(lw);
Application.getApplication().invokeLater(lw);
}
Aggregations