• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Is there anyway of overriding the default signal for PopupMenus

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MouseEvent#isPopupTrigger() returns true on right clicks.
 
Kieran Murray
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I managed to solve the problem.

Thanks for your help.

Kind regards,

The Apprentice
 
Marshal
Posts: 80636
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 80636
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kieran Murray:
Dear Ranchhands,

I have highlighted the relevant code. . .

Thank you
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic