package jp.ac.kyutech.mns.ist;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import jp.ac.kyutech.mns.ist.sheetmap.SeatmapController;
import edu.umd.cs.piccolo.PCamera;
import edu.umd.cs.piccolo.activities.PActivity;
import edu.umd.cs.piccolo.util.PBounds;
public class LayoutBySeat extends LayoutAbstract{
SeatmapController sc;
public LayoutBySeat(PCamera cam, SeatmapController sc){
super(cam);
setSeatmapController(sc);
}
public void setSeatmapController(SeatmapController sc){
this.sc = sc;
}
public ArrayList<PActivity> move(ArrayList<LayoutContent> cnt){
Rectangle2D maximumDim = maxContent(cnt);
if (maximumDim == null) return null;
int msec = 1000;
double x,y,w,h, xgap = 0, ygap = 0;
w = maximumDim.getWidth();
h = maximumDim.getHeight();
//tempAfterLayoutBounds
ArrayList<PActivity> palist = new ArrayList<PActivity>();
PBounds returnPB = null;
int outagepos = 0;//場所が入力されていない筆記の配置場所
matrix.removeAll();
for(LayoutContent pn: cnt){
// if (!pn.hasContent()) continue;
Point pos = sc.getPointByLayoutContent(pn);
PActivity pa;
PBounds aPB = new PBounds(pn.getFullBounds());
if (pos == null) {
x = outagepos*(w+xgap);
y = -1.2*(h+ygap);
matrix.put(outagepos,-1,pn);
} else {
x = pos.x*(w+xgap);
y = pos.y*(h+ygap);
matrix.put(pos.x,pos.y,pn);
}
pa = pn.animateToPositionScaleRotation(x, y, 1, 0, msec);
aPB.setOrigin(x,y);
palist.add(pa);
if (returnPB == null) returnPB = aPB; else returnPB.add(aPB);
}
return palist;
}
public PBounds contentregion(LayoutTarget target){
ArrayList<LayoutContent> cnt = target.getLayoutContents();
Rectangle2D maximumDim = maxContent(cnt);
// int msec = 1000;
if (maximumDim == null) return null;
double x,y,w,h, xgap = 0, ygap = 0;
w = maximumDim.getWidth();
h = maximumDim.getHeight();
//tempAfterLayoutBounds
// ArrayList<PActivity> palist = new ArrayList<PActivity>();
PBounds returnPB = null;
int outagepos = 0;//場所が入力されていない筆記の配置場所
for(LayoutContent pn: cnt){
// if (!pn.hasContent()) continue;
Point pos = sc.getPointByLayoutContent(pn);
// PActivity pa;
PBounds aPB = new PBounds(pn.getFullBounds());
if (pos == null) {
x = outagepos*(w+xgap);
y = -1.2*(h+ygap);
} else {
x = pos.x*(w+xgap);
y = pos.y*(h+ygap);
}
// pa = pn.animateToPositionScaleRotation(x, y, 1, 0, msec);
aPB.setOrigin(x,y);
// palist.add(pa);
if (returnPB == null) returnPB = aPB; else returnPB.add(aPB);
}
return returnPB;
}
}