This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there anyway of overriding the default signal for PopupMenus

 
Kieran Murray
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Guys and Galls,

I am trying to implement the rotation of an object on a canvas. You guys have already helped me with setting up the objects on a canvas and it works fine now. The default for PopupMenus seems to be - on Windows anyway - to wait until the mouse is released. Is there any way to override this as I want the PopupMenu to show when the mouse is rightclicked.

Kind regards,

Apprentice
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MouseEvent#isPopupTrigger() returns true on right clicks.
 
Kieran Murray
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Maneesh,

I include the code and you will see what the problem is. The only mouse event that the method isPopupTrigger() responds to is mouseReleased.
The program presents two pop-up menus. One when the canvas is clicked and one when the object on the canvas is clicked. I am trying to achieve the rotating of the clicked object. I think my whole logic may be a little haywire.
I need to rotate the object around by dragging it.

Anyway - code below;

Main class Shaping




The Panel on which the objects are drawn



The MouseListener class - Path Wrangler2


Thanks

The Apprentice
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kieran Murray:

The default for PopupMenus seems to be - on Windows anyway - to wait until the mouse is released. Is there any way to override this as I want the PopupMenu to show when the mouse is rightclicked.


I am a bit confused here.
What exactly are you trying to do?

1) Show a popup on right click? Easiest way to do this is to use JComponent#setComponentPopupMenu(). This way you don't have to bother adding listeners, figuring out if the mouse event is a popup trigger and showing the popup.

2) ...show when the mouse is rightclicked. A "click" is technically a combination of a "press"+"release". Now if you want to show the popup on a "press" you can have your mouse listener call a JPopupMenu#show() on mousePressed.
 
Kieran Murray
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Maneesh,

Yes. I am not making quite clear what I am trying to do.
If I click on a object such as a Line with a right click I want a pop up menu to comeup which has a Popup MenuItem entitled "Rotate Object". When I click on this MeuuItem I want to then left click on the object and then drag it through a rotation.

The real problem for me is understaning the code in the Popup MenuItem ActionListener to do this.

If I set up a class for each piece of drawing - ie a class for a Line, a class for a particular shape then I presume that I can use the setComponentPopupMenu() on each of the instantiated classes.

Kind regards,

The Apprentice
 
Kieran Murray
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I managed to solve the problem.

Thanks for your help.

Kind regards,

The Apprentice
 
Campbell Ritchie
Sheriff
Pie
Posts: 47262
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kieran Murray:
Dear All,

I managed to solve the problem.
Well done

Please tell us how, for the next time anybody has such a problem.
 
Kieran Murray
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchhands,

I have highlighted the relevant code. The MyInterp class and PathWrangler2 class have been changed.

Windows it seems from my reading waits for the MouseReleased before the PopupMenu appears - it is just what it does - irritating but that is Windows - anyway some people use Windows.

When the PopupMenu appears I see the boolean - rotating - to true in the PathWrangler2 class through an ActionListener. This means that when someone next clicks on the object the MousePressed method moves to a certain snippet of the code and rotates the object.

The actual rotating code I took from a Sun forum and just used for my own ends.

I have highlighted the code added.


The Main class - no code changed here



MyInterp code 1 line of code added in the ActionListener lst 4



The code for PathWrangler2 where most of the changes have occured


The rotating does not work well if you do not click back on an object and it whirls too quickly.

Anyway.

Kind regards,

The Apprentice
 
Campbell Ritchie
Sheriff
Pie
Posts: 47262
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kieran Murray:
Dear Ranchhands,

I have highlighted the relevant code. . .
Thank you
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic