Newer
Older
PureATN_M / src / main / java / cit / PureATN / Stroke.java
@motoki miura motoki miura on 10 May 2022 1 KB first
package cit.PureATN;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Date;

public class Stroke {
	transient ArrayList<IPoint> points;
	String date;
	String time;
	long start_epoch;
	transient int prex = -1, prey = -1;
	int[][] stroke;
	int count;
	int duration;
	transient PenUser penuser;
	public Stroke(PenUser _pu){
		penuser = _pu;
		date = DPenReceiver.sdfdate.format(new Date());
		time = DPenReceiver.sdftime.format(new Date());
		
		start_epoch = System.currentTimeMillis();	
	}
	public void add(int x, int y){
		if (x != prex || y!= prey){
			if (points == null) {
				points = new ArrayList<IPoint>();
				points.add(new IPoint(x,y));
			} else {
				points.add(new IPoint(x,y));
				penuser.send(prex,prey,x,y);
				Note.theapp.repaint();
			}
		}
		prex = x; prey = y;
	}
	public void draw(Graphics g){
		IPoint p0 = points.get(0);
		for(int i=1;i<points.size();i++){
			IPoint p1 = points.get(i);
			g.drawLine(p0.x1, p0.y1, p1.x1, p1.y1);
			p0 = p1;
		}
	}
	// build stroke
	public void finish(){
		stroke = new int[points.size()][];
		for(int i=0;i<points.size();i++){
			stroke[i] = points.get(i).toIntAry(start_epoch);
		}
		count = points.size();
		duration = stroke[points.size()-1][2];
	}
}