SHARE
TWEET

Untitled

a guest May 12th, 2014 1 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package be.wout.listeners;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Point;
  5. import java.awt.event.MouseEvent;
  6. import java.awt.event.MouseListener;
  7. import java.awt.event.MouseMotionListener;
  8. import java.util.List;
  9.  
  10. import be.wout.draw.DrawPanel;
  11. import be.wout.draw.shapes.Circle;
  12. import be.wout.draw.shapes.Line;
  13. import be.wout.draw.shapes.Pencil;
  14. import be.wout.draw.shapes.Rubber;
  15. import be.wout.draw.shapes.Shape;
  16. import be.wout.draw.shapes.Rectangle;
  17. import be.wout.staticThings.StaticVars;
  18.  
  19. public class DrawPanelListener implements MouseListener, MouseMotionListener
  20. {
  21.  
  22.         private DrawPanel panel;
  23.         private Shape drawShape;
  24.  
  25.         public DrawPanelListener(DrawPanel dp)
  26.         {
  27.                 panel = dp;
  28.         }
  29.  
  30.         public void mouseClicked(MouseEvent e)
  31.         {
  32.  
  33.         }
  34.  
  35.         public void mouseEntered(MouseEvent e)
  36.         {
  37.  
  38.         }
  39.  
  40.         public void mouseExited(MouseEvent e)
  41.         {
  42.  
  43.         }
  44.  
  45.         public void mousePressed(MouseEvent e)
  46.         {
  47.                 drawShape = getTmpShape(e.getX(), e.getY(), 2, 2);
  48.                 panel.setTmpShape(drawShape);
  49.  
  50.  
  51.         }
  52.  
  53.         public void mouseReleased(MouseEvent e)
  54.         {
  55.                 drawShape.setX2(e.getX());
  56.                 drawShape.setY2(e.getY());
  57.  
  58.                 List<Shape> shapes = panel.getShapes();
  59.                 shapes.add(drawShape);
  60.                 panel.setTmpShape(null);
  61.                 panel.setShapes(shapes);
  62.                 drawShape = null;
  63.  
  64.                 // panel.repaint();
  65.         }
  66.  
  67.         public void mouseDragged(MouseEvent e)
  68.         {
  69.                 if (drawShape instanceof Pencil)
  70.                 {
  71.                         ((Pencil) drawShape).addPoint(new Point(e.getX(), e.getY()));
  72.                 }
  73.                 else if (drawShape instanceof Rubber)
  74.                 {
  75.                         ((Rubber) drawShape).addPoint(new Point(e.getX(), e.getY()));
  76.                 }
  77.                 else
  78.                 {
  79.                         drawShape.setX2(e.getX());
  80.                         drawShape.setY2(e.getY());
  81.                 }
  82.                 panel.setTmpShape(drawShape);
  83.                 panel.repaint();
  84.         }
  85.  
  86.         public void mouseMoved(MouseEvent e)
  87.         {
  88.  
  89.         }
  90.  
  91.         private Shape getTmpShape(int x, int y, int x2, int y2)
  92.         {
  93.                 switch (StaticVars.shapeType)
  94.                 {
  95.                 case "Rectangle":
  96.                         return new Rectangle(x, y, x2, y2, StaticVars.shapeColor);
  97.                 case "Circle":
  98.                         return new Circle(x, y, x2, y2, StaticVars.shapeColor);
  99.                 case "Pencil":
  100.                         return new Pencil(x, y, x2, y2, StaticVars.shapeColor);
  101.                 case "Line":
  102.                         return new Line(x, y, x2, y2, StaticVars.shapeColor);
  103.                 case "Rubber":
  104.                         return new Rubber(x,y,x2, y2, Color.WHITE);
  105.                 default:
  106.                         return new Rectangle(x, y, x2, y2, StaticVars.shapeColor);
  107.                 }
  108.         }
  109.  
  110. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top