[JAVA2D] How to make right click Action
i want to make action using right click or press.how can in mousePressed() recognize the right mouse button? waiting fo reply .. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] How to make right click Action
If you read the JavaDocs for MouseListener MouseEvent you will find your answer much more quickly than if you send an email to this list and wait for a response. One way to do this is use the MouseEvent object (that is an argument to your mousePressed() ) and call getButton() on that MouseEvent object. This will return an int that you can compare against the constants in MouseEvent (MouseEvent.BUTTON1, MouseEvent.BUTTON2, etc) to determine which button has changed state. -Original Message- From: Discussion list for Java 2D API [mailto:[EMAIL PROTECTED]]On Behalf Of Ayman El_Gharabawy Sent: Monday, November 25, 2002 4:04 AM To: [EMAIL PROTECTED] Subject: [JAVA2D] How to make right click Action i want to make action using right click or press.how can in mousePressed() recognize the right mouse button? waiting fo reply .. == = To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] How to make right click Action
javax.swing.SwingUtilities.isRightMouseButton(MouseEvent anEvent) Returns true if the mouse event specifies the right mouse button. Hope this helps :-) regards / vijayv - Original Message - From: Ayman El_Gharabawy [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, November 25, 2002 5:34 PM Subject: [JAVA2D] How to make right click Action i want to make action using right click or press.how can in mousePressed() recognize the right mouse button? waiting fo reply .. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] How to make right click Action
public void mousePressed(MouseEvent e) { super.mousePressed(e); if(e.isPopupTrigger()) { // put up your popup menu popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } See http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup - Original Message - From: Ayman El_Gharabawy [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, November 25, 2002 6:04 AM Subject: [JAVA2D] How to make right click Action i want to make action using right click or press.how can in mousePressed() recognize the right mouse button? waiting fo reply .. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
[JAVA2D] Tim Trenary/Boulder/IBM is out of the office.
I will be out of the office starting November 25, 2002 and will not return until December 2, 2002. I will respond to your message when I return. Have a great day! === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
[JAVA2D] General Path contraction/expansion algorithm
Hello, Does anyone know of an algorithm that can be used to 'expand' or 'contract' a general path? If the general path is viewed as a collection of connected line segments, what I think I need to do is to define a new set of line segments, each new segment parallel to one of the segments in the original set, then find the intersection points of the new segments and use these to define the 'expanded' or 'contracted' general path. Any suggestions welcome, Thank you, Ted Hill === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
[JAVA2D] Printing performance worse in 1.4.1_01 vs. 1.3
Has anyone noticed a deterioration in printing performance since JRE 1.3? We sell a document viewer. A customer reported that printing performance was much worse in 1.3.1_02 than 1.3, for both raster and vector files. I downloaded JRE 1.4.1_01, and found that spool sizes and print times were comparable to 1.3.1_02, and that both of these JRE's were in fact much worse compared to 1.3 when it comes to printing times and spool sizes for a number of files. For example, a vector file that printed in 45 s, spool size of 1.15 MB with JRE 1.3, blew up to 9.15 MB and took 13 minutes to print in 1.3.1_02, according to our customer! That's right, it took over 15 times as long to print, and the spool file size was 9 times bigger! I found a raster file that printed in 40 s and spooled to 11 MB in JRE 1.3, took 2.5 minutes to print, and 20.9 MB in 1.4.1_01. That's 4 times as long to print, and double the spool size! We are finding comparable differences on other printers and on different Windows operating systems (although as usual some printers are much better than others and the newer Win O/S's are better). Can someone from Sun please comment on this one? Thanks. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
[JAVA2D] Problem with BasicStroke and Graphics2D#scale on Mac OS X
Hi, I've run into what seems to be a pretty significant bug with Java2D on OS X. I couldn't find any mention of it in the archives of this list, so I'm curious about whether anyone else has ever run across it and what workarounds you might have used. This is not the only oddity I've experienced with Java2D on OS X, but it is the first one I've needed/been able to pin down with a test case. The problem is this: whenever the Graphics2D object used to paint a JPanel (or, presumably, any JComponent) has both a non-identity scale factor and a non-default BasicStroke applied to it, any shapes drawn to it willbe offset by some amount. The amount and direction of the offset appears to be proportional to the scale factor(s). It doesn't take a very large scale factor to displace the shape by a lot. On the other hand, the attributes of the stroke do not seem to affect the degree of displacement. (By non-default BasicStroke, I mean any BasicStroke that's not 1.0f wide with the JDK-default CAP and JOIN styles. It doesn't have to be the original Stroke object that came with the Graphics2D object, just an equivalently-constructed one.) If you remove either the scale or the BasicStroke, the other is applied to the shape with no problem. Some other variables I've tried: * If the source of the Graphics2D is a BufferedImage (instead of a JPanel), the problem doesn't occur. * The value of the rendering hint KEY_STROKE_CONTROL has no effect. I've attached a small test case that demonstrates the problem with different scale factors. I've tested it on OS X 10.2.2 using the included JDK (1.3.1) where the problem occurs, and on Windows 2000 with JDK 1.3.1_04 where the problem does not occur. (Not that it matters, but the test app is compiled under OS X.) I have worked around this problem by doing something like this: public void transformAndDrawTo(Graphics2D g2) { AffineTransform origTx = g2.getTransform(); g2.setTransform(new AffineTransform()); g2.draw(origTx.createTransformedShape(shape)); g2.setTransform(origTx); } Where shape is whatever Shape I want to draw. Of course, this has performance penalties (though not as much as I expected) and it ends up drawing something which does not exactly match what the natural method would have [this could be alleviated (but not fixed) by scaling the BasicStroke itself]. It works okay, but I wish I didn't have to do it. Anyone have any insights? Is there something I'm overlooking? I understand that this is almost certainly Apple's problem, since they maintain their own JDK for OS X. So if the answers to those two questions is no, the next question is: what is the best way to report JDK bugs to Apple? Thanks for reading that whole thing, Rhett Sutphin = | Rhett Sutphin | Research Assistant (Software) | Coordinated Laboratory for Computational Genomics | and the Center for Macular Degeneration | University of Iowa - Iowa City, IA 52242 - USA | 4111 MEBRF - email: [EMAIL PROTECTED] = package test.j2d; import java.awt.geom.*; import java.awt.*; import javax.swing.*; /** Test for weird BasicStroke-Graphics2D#scale interaction on OS X. It displays * a bunch of JPanels, each with a different pair of x,y scale factors. Each * contains two identical ellipses, one red and one blue. If the bug is not * present, the blue ellipses will be painted on top of the red ones. Otherwise, * the red ones will be visible and the blue ones will be offset or missing. * * @author rsutphin */ public class StrokeOffsetTest extends JPanel { DrawableThing thing; float xScale, yScale; boolean drawTransformed; public StrokeOffsetTest(float xScale, float yScale, boolean drawTransformed) { thing = new DrawableThing(); this.xScale = xScale; this.yScale = yScale; this.drawTransformed = drawTransformed; setBackground(Color.white); } public Dimension getPreferredSize() { return new Dimension(160, 160); } public Dimension getMaximumSize() { return getPreferredSize(); } public Dimension getMinimumSize() { return getPreferredSize(); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; AffineTransform origTx = g2.getTransform(); Shape origClip = g2.getClip(); g2.translate(60, 60); g2.scale(xScale, yScale); g2.setColor(Color.red); g2.setStroke(new BasicStroke(1.0f)); if (drawTransformed) thing.transformAndDrawTo(g2); else thing.drawTo(g2); g2.setColor(Color.blue); g2.setStroke(new BasicStroke(2.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); if (drawTransformed) thing.transformAndDrawTo(g2); else thing.drawTo(g2); g2.setTransform(origTx);
Re: [JAVA2D] Problem with BasicStroke and Graphics2D#scale on Mac OS X
Hi Rhett, In 1.2 we tried to deal with stroke/fill pixelization and alignment issues by specifying a user-space offest for strokes so that the typical behavior on a screen using standard bresenham algorithms for drawing lines and polygon borders would be closely approximated in a theoretical world of floating point coordinates and transforms. Unfortunately the concept of a user-space offset was untenable for many of the reasons that you seem to have stumbled upon with the Apple implementation. I'm pretty sure that their behavior is an approximation of what we had been doing for quite a while in some parts of our implementation (but not all). You may indeed have witnessed this same behavior in one of our older implementations if you had written your test case just the right way to trigger it. I believe we abandoned this concept in 1.3 (the release where we introduced the STROKE_CONTROL hints). Our implementation should be pretty consistent in that release and following, but Apple may not have noticed the change and updated their implementation to match. You might also try downloading their preview of 1.4 from the Apple site: http://developer.apple.com/java/ and see if the problem is still reproducible. If it is, you might want to submit this bug report to them so that they can update from the old user-space offset model of things to the new STROKE_CONTROL model... ...jim --On Monday, November 25, 2002 12:52 PM -0600 Rhett Sutphin [EMAIL PROTECTED] wrote: Hi, I've run into what seems to be a pretty significant bug with Java2D on OS X. I couldn't find any mention of it in the archives of this list, so I'm curious about whether anyone else has ever run across it and what workarounds you might have used. This is not the only oddity I've experienced with Java2D on OS X, but it is the first one I've needed/been able to pin down with a test case. The problem is this: whenever the Graphics2D object used to paint a JPanel (or, presumably, any JComponent) has both a non-identity scale factor and a non-default BasicStroke applied to it, any shapes drawn to it willbe offset by some amount. The amount and direction of the offset appears to be proportional to the scale factor(s). It doesn't take a very large scale factor to displace the shape by a lot. On the other hand, the attributes of the stroke do not seem to affect the degree of displacement. (By non-default BasicStroke, I mean any BasicStroke that's not 1.0f wide with the JDK-default CAP and JOIN styles. It doesn't have to be the original Stroke object that came with the Graphics2D object, just an equivalently-constructed one.) If you remove either the scale or the BasicStroke, the other is applied to the shape with no problem. Some other variables I've tried: * If the source of the Graphics2D is a BufferedImage (instead of a JPanel), the problem doesn't occur. * The value of the rendering hint KEY_STROKE_CONTROL has no effect. I've attached a small test case that demonstrates the problem with different scale factors. I've tested it on OS X 10.2.2 using the included JDK (1.3.1) where the problem occurs, and on Windows 2000 with JDK 1.3.1_04 where the problem does not occur. (Not that it matters, but the test app is compiled under OS X.) I have worked around this problem by doing something like this: public void transformAndDrawTo(Graphics2D g2) { AffineTransform origTx = g2.getTransform(); g2.setTransform(new AffineTransform()); g2.draw(origTx.createTransformedShape(shape)); g2.setTransform(origTx); } Where shape is whatever Shape I want to draw. Of course, this has performance penalties (though not as much as I expected) and it ends up drawing something which does not exactly match what the natural method would have [this could be alleviated (but not fixed) by scaling the BasicStroke itself]. It works okay, but I wish I didn't have to do it. Anyone have any insights? Is there something I'm overlooking? I understand that this is almost certainly Apple's problem, since they maintain their own JDK for OS X. So if the answers to those two questions is no, the next question is: what is the best way to report JDK bugs to Apple? Thanks for reading that whole thing, Rhett Sutphin = | Rhett Sutphin | Research Assistant (Software) | Coordinated Laboratory for Computational Genomics | and the Center for Macular Degeneration | University of Iowa - Iowa City, IA 52242 - USA | 4111 MEBRF - email: [EMAIL PROTECTED] = === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
[JAVA2D] STROKE_CONTROL
I am trying to draw a 2D polygon with a border stroke with a width of 2.0, but I want those 2.0 to go completely inside the polygon borderline, I mean, normallyhalf the line width goes outside and the other half goes inside, but I want to have it completely outside or completely inside, anyone know how I can get this effect? Thanks inadvance, Ramón Talavera
Re: [JAVA2D] STROKE_CONTROL
I don't think there is a flag you can set or something easy like that. You could double the stroke width and set up a clip to either mask off the inside or the outside of the shape you wish to outline. David Quoting Ramón Talavera [EMAIL PROTECTED]: I am trying to draw a 2D polygon with a border stroke with a width of 2.0, but I want those 2.0 to go completely inside the polygon borderline, I mean, normally half the line width goes outside and the other half goes inside, but I want to have it completely outside or completely inside, anyone know how I can get this effect? Thanks in advance, Ramón Talavera === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] STROKE_CONTROL
For an outside border that is quite easy, the mask way works fine. For an outside border things change, as I have to scale the main Polygon and draw it again to have the outside borderline: Problem: the polygon center, if it is a regular polygon the center of mass works fine, but if the polygon is non-convex then there are problems and many borders dissapear. ¿Any ideas? I can post images if you wish :). Thanks, Ramón Talavera - Original Message - From: Dave Kavanagh [EMAIL PROTECTED] To: Ramón Talavera [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Monday, November 25, 2002 11:12 PM Subject: Re: [JAVA2D] STROKE_CONTROL I don't think there is a flag you can set or something easy like that. You could double the stroke width and set up a clip to either mask off the inside or the outside of the shape you wish to outline. David Quoting Ramón Talavera [EMAIL PROTECTED]: I am trying to draw a 2D polygon with a border stroke with a width of 2.0, but I want those 2.0 to go completely inside the polygon borderline, I mean, normally half the line width goes outside and the other half goes inside, but I want to have it completely outside or completely inside, anyone know how I can get this effect? Thanks in advance, Ramón Talavera === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] STROKE_CONTROL
Hi Ramón, Use the Area class to either subtract or intersect the original shape with/from the outline created with BasicStroke.createStrokedShape(). Intersection will produce the inside part, subtract will produce the outside part. As far as non-convex polygons, you will probably find lots of cases where for a very convoluted self-intersecting or self-touching polygon and a very wide outline width there will be lots of visual anomalies which make the result look wrong because some part of the path overlapped in a way that wasn't intuitive. I believe the results will be correct, they just might be surprising (as with many things in geometry... ;-) ...jim --On Tuesday, November 26, 2002 12:11 AM +0100 Ramón Talavera [EMAIL PROTECTED] wrote: For an outside border that is quite easy, the mask way works fine. For an outside border things change, as I have to scale the main Polygon and draw it again to have the outside borderline: Problem: the polygon center, if it is a regular polygon the center of mass works fine, but if the polygon is non-convex then there are problems and many borders dissapear. ¿Any ideas? I can post images if you wish :). Thanks, Ramón Talavera - Original Message - From: Dave Kavanagh [EMAIL PROTECTED] To: Ramón Talavera [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Monday, November 25, 2002 11:12 PM Subject: Re: [JAVA2D] STROKE_CONTROL I don't think there is a flag you can set or something easy like that. You could double the stroke width and set up a clip to either mask off the inside or the outside of the shape you wish to outline. David Quoting Ramón Talavera [EMAIL PROTECTED]: I am trying to draw a 2D polygon with a border stroke with a width of 2.0, but I want those 2.0 to go completely inside the polygon borderline, I mean, normally half the line width goes outside and the other half goes inside, but I want to have it completely outside or completely inside, anyone know how I can get this effect? Thanks in advance, Ramón Talavera = == To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. ==To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.