I can get close; the JSVGCanvas isn't at 0, 0 screen coordinates. I have a JMenuBar on the top and a JToolBar on the left. Before drawing anything to the glass pane, I set the translate values of the glass pane accordingly. I can get an approximate solution with the view box transform of the JSVGCanvas. What gets thrown off is the above-mentioned translate values. I need to move x and y absolute pixels regardless of how the canvas is zoomed. Getting the view box transform of the JSVGCanvas seems to have the same result as constructing an AffineTransform from an SVGMatrix. So, in short:
- The bounding box is shifted "left" and "up" at 100% zoom. This is the width of the toolbar and the height of the menu bar. - If I add the translate x and y values AFTER the transform, I can make 100% zoom work. However... - When I zoom, the box is shifted "down" and "right" because I'm "over-shifting". I need a way to "transform" that extra width and height to the right scale. Michael Bishop -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, November 28, 2005 5:18 PM To: [email protected] Subject: RE: Element -> Bounding Box? Hi Michael, "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote on 11/28/2005 04:47:21 PM: > If I getScreenCTM from the "selected" element, I > get an SVGMatrix which is what I expect, looking back at the drag and > drop code. What I don't get is how to apply that matrix to either the > Graphics class responsible for drawing the SVGRect on the glass pane or > the actual SVGRect itself. You can either construct SVGPoint objects for the corners and use 'SVGPoint.matrixTransform(SVGMatrix mat)' or you can build an AWT AffineTransform from the SVGMatrix: A -> Scale X B -> Shear Y C -> Shear X D -> Scale Y E -> Translate X F -> Translate Y > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Monday, November 28, 2005 4:38 PM > To: [email protected] > Subject: RE: Element -> Bounding Box? > > Hi Michael, > > "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote on > > 11/28/2005 03:11:18 PM: > > > OK, yeah, that sounds complicated. To draw those circles, I have to > > know about all these points. And it is different based on the element > > type. Let's just stick with the basic bounding box. > > Well for 'path' there is getPathSegList which provides this > information fairly convieniently. You would still have to fake > something similar for other element types however. > > > I have a double problem. Remember how I'm using translations to move > > elements around the canvas? Translate information isn't stored in a > > bounding box, so when I draw a bounding box, I have to apply > translation > > information. Not terribly hard (I don't think). The second problem > is > > screen coordinates. I have to face the issue of drawing a bounding > box > > of a translated element on a zoomed canvas. This is like the opposite > > of drawing on a zoomed canvas. I have to tell the glass pane how to > > draw properly based on the state of the canvas, not render to the > canvas > > based on the glass pane. > > I think most of these issues can be solved fairly easily with the > 'e1.getTransformToElement(e2)' > call. This will give you the transformation from the local coordinate > system of 'e1' to the > local coordinate system of 'e2'. If you use your element to highlight > as > 'e1', the bbox is > given in the local coordinate system of 'e1'. Then I would use a 'g' > representing a > glass pane 'layer' as my 'e2'. You can then use the SVGMatrix methods > to > map the corners of the bbox to e2's coordinate system where you can > easily > construct a path. > > > What's the best approach of drawing a translated element to a zoomed > > in/out canvas? Which should be applied first? I'm just trying to > find > > a starting point for going down this trail. > > Well the easiest thing is to just make it part of your > document. If you want to draw it in say an Overlay you could > use getScreenCTM in place of getTransformToElement. > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > Sent: Monday, November 28, 2005 2:19 PM > > To: [email protected] > > Subject: RE: Element -> Bounding Box? > > > > Hi Michael, > > > > "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote > on > > > > 11/28/2005 02:12:25 PM: > > > > > OK, here's a slightly more complicated question. Is there a way to > > make > > > "points" on an element respond to a mouse event? > > > > No, you could create new geometry (say small circles) that sit on > top > > of the rect element's geometry. > > > > > Say I draw some kind of polygon. Then I "select" it, so I know > which > > > > > element it belongs to. Now I'd like to grab one of the points in the > > > > polygon and "move" that point, altering its shape. > > > > Adding the circles could be part of the 'highlighting'. > > > > > For example, taking a rectangle and dragging two of its points > > > to form a trapezoid. Is this possible with existing tools? > > > > Well this brings up another point which is that once you drag one > > of the point's it is no longer a rect so you will need to be able > > to generalize geometry 'on the fly'. > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > > Sent: Monday, November 28, 2005 1:24 PM > > > To: [email protected] > > > Subject: Re: Element -> Bounding Box? > > > > > > Hi Michael, > > > > > > Check out SVGLocatable.getBBox(). > > > > > > "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> > wrote > > on > > > > > > 11/28/2005 11:16:24 AM: > > > > > > > Is there a way to do this? Citing the old drag and drop approach, > I > > > can > > > > > > > select an Element by clicking on it. Now I'd like to "outline" > that > > > > > Element > > > > to show it's been selected. I see it can be done with other > > objects, > > > but is > > > > there a way to get from Element to bounding box? > > > > > > All of the SVG graphical elements (g, svg, rect, path, ellipse, > > text, > > > > > > use, etc) implement this interface. > > > Of course not every 'Element' implements this interface as even in > SVG > > > > > many do not have a > > > reasonable BBox (think gradient), and of course it's even harder to > > > imagine what one would return for > > > elements in other namespaces. > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: > [EMAIL PROTECTED] > > > For additional commands, e-mail: > > [EMAIL PROTECTED] > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
