|
List Info
Thread: JSVGScrollPanel problems and updating while dragging
|
|
| JSVGScrollPanel problems and updating
while dragging |

|
2006-12-04 14:07:27 |
Hello
I still new to batik and svg and have a bit trouble with the
ScrollPane ... first it took me as newbie a long time
figuring out that a svgdocument created with SVGGraphics2D
does not seem to give the right bounding box neither set a
viewBox ... I understand that it does not set a vieBox but
what should be the problem with the BBox?
The next thing is that when I zoom in (via
setRenderingTransformation in JSVGCanvas) the sliders
doesn't seem set correctly only after I drag the vertical
slider all the way down it works ... am I missing something
that I need to set/check again?
And my last question, since the ScrollPane doesn't update
during dragging (to speed things up I guess? but I need that
for my application), I thought I just add that behaviour via
SBListeners which call some kind of update procedure but it
seems that there is no way to add SBListerns ... am I really
supposed to derive a new class for that?
Any tips how to create that behaviour?
thx & cu
ernii
--
"Ein Herz für Kinder" - Ihre Spende hilft! Aktion:
www.deutschlandsegelt.de
Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen
America's Cup-Yacht!
------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help xmlgraphics.apache.org
|
|
| JSVGScrollPanel problems and updating
while dragging |

|
2006-12-04 23:37:15 |
Hi Ernst,
"Ernst Müller" <ernii_23 gmx.net> wrote on
12/04/2006 09:07:27 AM:
> I still new to batik and svg and have a bit trouble
with the ScrollPane
...
> first it took me as newbie a long time figuring out
that a svgdocument
created
> with SVGGraphics2D does not seem to give the right
bounding box neither
set a
> viewBox ... I understand that it does not set a vieBox
but what should
be the
> problem with the BBox?
You can set the width/height on the SVGGraphics2D with:
SVGGraphics2D.setSVGCanvasSize(Dimension d);
> The next thing is that when I zoom in (via
setRenderingTransformation in
> JSVGCanvas) the sliders doesn't seem set correctly only
after I drag the
> vertical slider all the way down it works ... am I
missing something
that I
> need to set/check again?
There was a problem in this area in the 1.6 release I
think it's
fixed in SVN.
> And my last question, since the ScrollPane doesn't
update during
dragging (to
> speed things up I guess?
Yes, rendering complex SVG's can take a long time. Since
we
can't control this we use the last finished rendering until
the
user decides on the new view.
> but I need that for my application), I thought I just
> add that behavior via SBListeners which call some kind
of update
procedure
> but it seems that there is no way to add SBListerns ...
am I really
supposed
> to derive a new class for that?
Probably, I don't really have a problem with adding get
functions for
the SB instances, it just hasn't been needed to date.
> Any tips how to create that behavior?
This is very hard to do. Since the rendering is async
you need
a fair amount of tracking logic so that the paintTransform
and the
renderingTransform don't step on each other.
------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help xmlgraphics.apache.org
|
|
| JSVGScrollPanel problems and updating
while dragging |

|
2006-12-05 15:57:21 |
|
|
While we are talking about changes to JSVGScrollPane, I made a
subclass to implement some changes that I found necessary. Also, I think
it would be great if there were methods like the JScrollPane's scroll bar
policies, however this doesn't look to feasible via a subclass.
I don’t
know the best way to do this, so I am just going to paste my working file into
this message. The main things I needed were to support:
- Zooming in, center the part of the canvas I want centered when the zoom is
completed
- Enabling "fit width" or "fit to page". To do this I needed
a way to get the size of the viewable area. (Kinda like the JViewport
size). This is complicated by the fact that the scrollbars cannot
currently be set to always visible
public class DJSVGScrollPane extends JSVGScrollPane
{ private Point zoomPoint; public
DJSVGScrollPane(JSVGCanvas canvas)
{ super(canvas); canvas.addGVTTreeRendererListener(
new RendererListener() ); addMouseWheelListener( new
MouseWheelListener() { public void
mouseWheelMoved(MouseWheelEvent e)
{ vertical.setValue(vertical.getValue() + (10 *
e.getWheelRotation())); } }); } public
JScrollBar getHorizontalScrollBar() { return
horizontal; } public JScrollBar getVerticalScrollBar()
{ return vertical; } public Dimension
getMaximumViewableArea() { //We have to use the bounds of the
enter pane and subtract the scrollbar sizes. We can't use the bounds of
the canvas since //the scroll bars may not be visible, yet might
need to be when we are done. Rectangle rect =
getBounds(); Dimension rval = new
Dimension(rect.width,rect.height); rval.width -=
vertical.getWidth(); rval.height -=
horizontal.getHeight(); return rval; } private
Dimension getViewportSize() { Dimension rval =
null; Component[] comps = getComponents(); for
(int i = 0; i < comps.length; i++) { if (comps[i]
instanceof JSVGCanvas) { Rectangle rect =
comps[i].getBounds(); rval = new
Dimension(rect.width,rect.height); break; } } return
rval; }
public Rectangle
getCurrentSection() { int x =
horizontal.getValue(); int y =
vertical.getValue(); Dimension d =
getViewportSize(); int width = d.width; int height
= d.height; return new
Rectangle(x,y,width,height); } public void setScale(double
newScale, Point newCenter) { AffineTransform currentTransform =
canvas.getRenderingTransform(); double currentScale =
currentTransform.getScaleX(); //We also scale X and Y together, so just getting
X here is sufficient double relativeScale = newScale /
currentScale; AffineTransform newTransform =
AffineTransform.getScaleInstance(newScale,newScale); Rectangle
currRect = getCurrentSection(); if (newCenter == null)
{ //If the scroll bars are adjusted (non-zero values), then
we want to center the view. If not, then we want them to stay
there int newX; if (currRect.x ==
0) newX = 0; else
newX = currRect.x + currRect.width /
2; int newY; if (currRect.y ==
0) newY = 0; else
newY = currRect.y + currRect.height /
2; //set p to be center of displayed
area newCenter = new
Point(newX,newY); } else
{ newCenter.x +=
currRect.x; newCenter.y +=
currRect.y; } int halfOfViewWidth = currRect.width
/ 2; int halfOfViewHeight = currRect.height /
2; int newX = (int)Math.max(0, (newCenter.x * relativeScale -
halfOfViewWidth)); int newY = (int)Math.max(0, (newCenter.y *
relativeScale - halfOfViewHeight)); zoomPoint = new Point(newX,
newY); canvas.setRenderingTransform(newTransform); reset(); } private
final class RendererListener implements GVTTreeRendererListener
{ public void gvtRenderingPrepare(GVTTreeRendererEvent e)
{ } public void
gvtRenderingStarted(GVTTreeRendererEvent e)
{ resizeScrollBars(); if (zoomPoint !=
null) { if (zoomPoint.x >
getHorizontalScrollBar().getMaximum()) zoomPoint.x
= getHorizontalScrollBar().getMaximum(); if
(zoomPoint.y >
getVerticalScrollBar().getMaximum()) zoomPoint.y
=
getVerticalScrollBar().getMaximum(); getHorizontalScrollBar().setValue(zoomPoint.x); getVerticalScrollBar().setValue(zoomPoint.y); } } public
void gvtRenderingCompleted(GVTTreeRendererEvent e)
{ zoomPoint = null; } public
void gvtRenderingCancelled(GVTTreeRendererEvent e)
{ } public void
gvtRenderingFailed(GVTTreeRendererEvent e)
{ } } }
--------------------------------------------------------------------- To
unsubscribe, e-mail: batik-users-unsubscribe xmlgraphics.apache.org For
additional commands, e-mail:
batik-users-help xmlgraphics.apache.org
|
[1-3]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|