Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. public AnimationPanel() {
  2. // remove these lines
  3. // Insets insets = getInsets();
  4. // int marginWidth = getWidth() - insets.left - insets.right;
  5. // int marginHeight = getHeight() - insets.top - insets.bottom;
  6. // s = new MovingRectangle(10, 10, currentWidth, currentHeight, marginWidth, marginHeight, currentPath);
  7. //
  8. popup = new JPopupMenu(); //create the popup menu
  9. makePopupMenu();
  10.  
  11. // add the mouse event to handle popup menu and create new shape
  12. addMouseListener( new MouseAdapter() {
  13. public void mousePressed(MouseEvent e) {
  14. maybeShowPopup(e);
  15. }
  16.  
  17. public void mouseReleased(MouseEvent e) {
  18. maybeShowPopup(e);
  19. }
  20.  
  21. private void maybeShowPopup(MouseEvent e) {
  22. if (e.isPopupTrigger()) {
  23. popup.show(e.getComponent(), e.getX(), e.getY());
  24. }
  25. }
  26. public void mouseClicked( MouseEvent e ) {
  27. if (animationThread != null) { // if the animation has started, then
  28. boolean found = false;
  29. for (MovingShape sh : s) {
  30. if ( sh.contains( e.getPoint()) ) { // if the mousepoint is within a shape, then set the shape to be selected/deselected
  31. found = true;
  32. sh.setSelected( ! sh.isSelected() );
  33. }
  34. }
  35. if (! found) createNewShape(e.getX(), e.getY()); // if the mousepoint is not within a shape, then create a new one according to the mouse position
  36. }
  37. }
  38. });
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement