public class PaintPanel extends Canvas {
private int pointCount = 0;
private Point points[] = new Point[10000];
private Color color = new Color (0,0,0);
public static List<Shape> myShapes = new ArrayList<Shape>();
public static List<Stroke> myShapesStrokes = new ArrayList<Stroke>();
public static List<Color> myShapesColors = new ArrayList<Color> ();
public PaintPanel() {
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
repaint();
}
});
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
color = Animator.fillColor;
for (int i = 0; i<myShapes.size(); i++){
g2d.setStroke(myShapesStrokes.get(i));
g2d.setColor(color);
g2d.draw(myShapes.get(i));
}
g2d.setStroke(new BasicStroke(Animator.stroke));
if (Animator.dashed){
float dashes[] = { 10 };
if(Animator.roundEdge == true){
g2d.setStroke( new BasicStroke(Animator.stroke, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10, dashes, 0 ) );
}
else{
g2d.setStroke( new BasicStroke(Animator.stroke, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 10, dashes, 0 ) );
}
}
else {
if (Animator.roundEdge == true){
g2d.setStroke( new BasicStroke(Animator.stroke, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND) );
}
else{
g2d.setStroke( new BasicStroke(Animator.stroke, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND) );
}
}
Animator.draw= false;
switch (Animator.panelIndex)//1 pen, 2 eraser, 3 line, 4 curve, 5 circle,6 rectangle, 7 star, 8 clear
{
case 1:
break;
case 2:
g2d.setColor(new Color (255,255,255));
g2d.drawRect(getMousePosition().x, getMousePosition().y, Animator.width, Animator.hight);
break;
case 3:
g2d.drawLine(getMousePosition().x - Animator.width/2, getMousePosition().y, getMousePosition().x + Animator.width/2, getMousePosition().y );
myShapes.add(new Line2D.Double(getMousePosition().x - Animator.width/2, getMousePosition().y, getMousePosition().x + Animator.width, getMousePosition().y ));
myShapesStrokes.add(g2d.getStroke());
break;
case 4:
g2d.drawArc(getMousePosition().x, getMousePosition().y, Animator.width, Animator.width, 15, 45);
myShapes.add(new Arc2D.Double(getMousePosition().x, getMousePosition().y, Animator.width, Animator.width, 15, 45,Arc2D.PIE));
myShapesStrokes.add(g2d.getStroke());
break;
case 5:
g2d.drawOval(getMousePosition().x - Animator.width/2, getMousePosition().y - Animator.hight/2, Animator.width, Animator.hight);
myShapes.add(new Ellipse2D.Double(getMousePosition().x - Animator.width/2, getMousePosition().y - Animator.hight/2, Animator.width, Animator.hight));
myShapesStrokes.add(g2d.getStroke());
break;
case 6:
color = Animator.fillColor;
g2d.setBackground(color);
g2d.drawRect(getMousePosition().x - Animator.width /2, getMousePosition().y - Animator.hight/2, Animator.width, Animator.hight);
myShapes.add(new Rectangle2D.Double(getMousePosition().x - Animator.width/2, getMousePosition().y - Animator.hight/2, Animator.width, Animator.hight));
myShapesStrokes.add(g2d.getStroke());
break;
case 7:
GSegment star = new GSegment();
GStyle starStyle = new GStyle();
starStyle.setForegroundColor (Animator.fillColor);
starStyle.setBackgroundColor (Animator.strokeColor);
starStyle.setLineWidth (Animator.stroke);
star.setStyle (starStyle);
star.setGeometry (Geometry.createStar (Animator.hight,Animator.hight, Animator.width, getMousePosition().x, Animator.points ));
Shape s = (Shape) star;
myShapes.add(s);
myShapesStrokes.add(g2d.getStroke());
g2d.draw(s);
break;
case 8:
g2d.clearRect(getX(), getY(), getWidth(), getHeight());
break;
default:
break;
};
}
}