List Info

Thread: JSVGScrollPanel problems and updating while dragging




JSVGScrollPanel problems and updating while dragging
user name
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-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

JSVGScrollPanel problems and updating while dragging
user name
2006-12-04 23:37:15
Hi Ernst,

"Ernst Müller" <ernii_23gmx.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-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

JSVGScrollPanel problems and updating while dragging
user name
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.&nbsp; 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&nbsp;"fit width" or "fit to page".&nbsp; To do this I needed a way to get the size of the viewable area. ; (Kinda like the JViewport size).&nbsp; This is complicated by the fact that the scrollbars cannot currently be set to always visible


public class DJSVGScrollPane extends JSVGScrollPane {
 
 private Point zoomPoint;
 
&nbsp;public DJSVGScrollPane(JSVGCanvas canvas) {
 &nbsp;super(canvas);
&nbsp; canvas.addGVTTreeRendererListener( new RendererListener() );
 &nbsp;addMouseWheelListener( new MouseWheelListener() {
 &nbsp; public void mouseWheelMoved(MouseWheelEvent e) {
 &nbsp;  vertical.setValue(vertical.getValue() + (10 * e.getWheelRotation()));
 &nbsp; }
 &nbsp; 
&nbsp; });
 }
 public JScrollBar getHorizontalScrollBar() {
 &nbsp;return horizontal;
 }
 public JScrollBar getVerticalScrollBar() {
 &nbsp;return vertical;
 }
&nbsp;public Dimension getMaximumViewableArea() {
 &nbsp;//We have to use the bounds of the enter pane and subtract the scrollbar sizes.&nbsp; We can't use the bounds of the canvas since
&nbsp; //the scroll bars may not be visible, yet might need to be when we are done.
&nbsp; Rectangle rect = getBounds();
 &nbsp;Dimension rval = new Dimension(rect.width,rect.height);
 &nbsp;rval.width -= vertical.getWidth();
 &nbsp;rval.height -= horizontal.getHeight();
 &nbsp;return rval;
&nbsp;}
 private Dimension getViewportSize() {
 &nbsp;Dimension rval = null;
&nbsp; Component[] comps = getComponents();
&nbsp; for (int i = 0; i < comps.length; i++) {
 &nbsp; if (comps[i] instanceof JSVGCanvas) {
 &nbsp; &nbsp;Rectangle rect = comps[i].getBounds();
 &nbsp; &nbsp;rval = new Dimension(rect.width,rect.height);
 &nbsp;  break;
 &nbsp; }
  ;}
 &nbsp;return rval;
&nbsp;}

 public Rectangle getCurrentSection() {
 &nbsp;int x = horizontal.getValue();
 &nbsp;int y = vertical.getValue();
 &nbsp;Dimension d = getViewportSize();
&nbsp; int width = d.width;
&nbsp; int height = d.height;
  ;return new Rectangle(x,y,width,height);
&nbsp;}
 ;public void setScale(double newScale, Point newCenter) {
 &nbsp;AffineTransform currentTransform = canvas.getRenderingTransform();
 &nbsp;double currentScale = currentTransform.getScaleX(); //We also scale X and Y together, so just getting X here is sufficient
 &nbsp;double relativeScale = newScale / currentScale;
  
&nbsp; AffineTransform newTransform = AffineTransform.getScaleInstance(newScale,newScale);
  ;
 &nbsp;Rectangle currRect = getCurrentSection();
  ;if (newCenter == null) {
 &nbsp; //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
&nbsp; &nbsp;int newX;
&nbsp; &nbsp;if (currRect.x == 0)
   ; newX = 0;
 &nbsp; else
 &nbsp; &nbsp;newX = currRect.x + currRect.width / 2;
   ;int newY;
&nbsp; &nbsp;if (currRect.y == 0)
   ; newY = 0;
 &nbsp; else
 &nbsp; &nbsp;newY = currRect.y + currRect.height / 2;
   ;//set p to be center of displayed area
&nbsp; &nbsp;newCenter = new Point(newX,newY);
&nbsp; }
 &nbsp;else {
 &nbsp; newCenter.x += currRect.x;
 &nbsp; newCenter.y += currRect.y;
 &nbsp;}
 ; int halfOfViewWidth = currRect.width / 2;
 &nbsp;int halfOfViewHeight = currRect.height / 2;
  int newX = (int)Math.max(0, (newCenter.x * relativeScale - halfOfViewWidth));
&nbsp; int newY = (int)Math.max(0, (newCenter.y * relativeScale - halfOfViewHeight));
&nbsp; zoomPoint = new Point(newX, newY);
&nbsp; canvas.setRenderingTransform(newTransform);
&nbsp; reset();
&nbsp;}
 ;private final class RendererListener implements GVTTreeRendererListener {
 &nbsp;public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
 &nbsp;}
&nbsp; public void gvtRenderingStarted(GVTTreeRendererEvent e) {
 &nbsp; resizeScrollBars();
&nbsp; &nbsp;if (zoomPoint != null) {
 &nbsp; &nbsp;if (zoomPoint.x > getHorizontalScrollBar().getMaximum())
&nbsp; &nbsp; &nbsp;zoomPoint.x = getHorizontalScrollBar().getMaximum();
&nbsp; &nbsp; if (zoomPoint.y > getVerticalScrollBar().getMaximum())
 ; &nbsp; &nbsp;zoomPoint.y = getVerticalScrollBar().getMaximum();
 ; &nbsp; getHorizontalScrollBar().setValue(zoomPoint.x);
 &nbsp; &nbsp;getVerticalScrollBar().setValue(zoomPoint.y);
   ;}
 &nbsp;}
 ; public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
 &nbsp; zoomPoint = null;
&nbsp; }
&nbsp; public void gvtRenderingCancelled(GVTTreeRendererEvent e) {
 &nbsp;}
&nbsp; public void gvtRenderingFailed(GVTTreeRendererEvent e) {
 &nbsp;}
&nbsp;}
}

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )