GeoSoft API

no.geosoft.cc.graphics
Class GScene

Object
  extended byGObject
      extended byGScene
All Implemented Interfaces:
GStyleListener

public class GScene
extends GObject

The GScene is the link between a GWindow and the graphics objects.

The GScene defines the viewport and the world extent and holds device-to-world transformation objects. The scene is itself a graphics object (GObject) and as such it may contain geometry.

Typical usage:

    // Creating a window
    GWindow window = new GWindow (Color.WHITE);

    // Creating a scene within the window
    GScene scene = new GScene (window);
    scene.setWorldExtent (0.0, 0.0, 1000.0, 1000.0);
 
Setting world extent is optional. If unset it will have the same extent (in floating point coordinates) as the device.

When geometry is specified (in GSegments), coordinates are specified in either device coordinates or in world coordinates. Integer coordinates are assumed to be device relative, while floating point coordinates are taken to be world extent relative.

Author:
GeoSoft

Field Summary
 
Fields inherited from class GObject
ANNOTATION_INVISIBLE, ANNOTATION_VISIBLE, DATA_INVISIBLE, DATA_VISIBLE, INVISIBLE, SYMBOLS_INVISIBLE, SYMBOLS_VISIBLE, VISIBLE, WIDGETS_INVISIBLE, WIDGETS_VISIBLE
 
Constructor Summary
GScene(GWindow window)
          Create a nameless scene within the specified window.
GScene(GWindow window, String name)
          Create a scene within the specified window.
 
Method Summary
 GScene getScene()
          Return the scene of this GObject.
 GTransformer getTransformer()
          Return the transformation object of this scene.
 GViewport getViewport()
          Return current viewport.
 GWindow getWindow()
          Return the window of this scene.
 GWorldExtent getWorldExtent()
          Return current world extent.
 void installScrollHandler(Adjustable hScrollBar, Adjustable vScrollBar)
          Instruct this scene to update and respond to the specified scrollbars during zoom.
 void pan(int dx, int dy)
          Pan a specific device distance.
 void setViewport(int x0, int y0, int width, int height)
          Set viewport to a rectangular area of the screen.
 void setViewport(int x0, int y0, int x1, int y1, int x2, int y2)
          Set viewport for this scene.
 void setWorldExtent(double[] w0, double[] w1, double[] w2)
          Set world extent of this scene.
 void setWorldExtent(double x0, double y0, double width, double height)
          A convenience method for specifying a orthogonal world extent in the Z=0 plane.
 void shouldWorldExtentFitViewport(boolean shouldWorldExtentFitViewport)
          Specify wether world extent should always fit the viewport (i.e. have same aspect ratio) during resize.
 void shouldZoomOnResize(boolean shouldZoomOnResize)
          Specified if one should zoom on resize.
 void unzoom()
          Unzoom.
 void zoom(double zoomFactor)
          Zoom a specified amount around center of viewport.
 void zoom(double[] w0, double[] w1, double[] w2)
          Zoom into a specified world area.
 void zoom(int x, int y, double zoomFactor)
          Zoom a specific amount using specified point as fixed.
 void zoom(int x0, int y0, int x1, int y1)
          Zoom into a specific device area.
 
Methods inherited from class GObject
add, add, addSegment, back, backward, behind, draw, find, find, find, find, findAll, findAll, findAllInside, findInside, findSegment, findSegment, findSegment, findSegmentInside, findSegments, findSegments, findSegmentsInside, forward, front, getChild, getChildren, getName, getNChildren, getNSegments, getObjectBehind, getObjectInFront, getParent, getSegment, getSegment, getSegments, getStyle, getUserData, getVisibility, inFrontOf, isInBack, isInFront, redraw, refresh, remove, remove, removeAll, removeSegment, removeSegment, removeSegments, removeSegments, removeSegments, reposition, setName, setStyle, setUserData, setVisibility, styleChanged, toBack, toFront, toString
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GScene

public GScene(GWindow window,
              String name)
Create a scene within the specified window. For most practical purposes a window will contain one scene only.

A default viewport will be established covering the entire window. This is appropriate in most cases.

A default world-extent will be established with coordinates equal to the window device extent. This may be sufficient in many cases if object geometry is specified in device coordinates.

Parameters:
window - Window to attach this scene to.
name - Name of this scene.

GScene

public GScene(GWindow window)
Create a nameless scene within the specified window.

Parameters:
window - Window to acttach this scene to.
Method Detail

getScene

public GScene getScene()
Return the scene of this GObject. At this level the scene is this object.

Overrides:
getScene in class GObject
Returns:
The scene of this GObject.

getWindow

public GWindow getWindow()
Return the window of this scene. A scene is always attached to a window, a GObject is not necesserily.

Overrides:
getWindow in class GObject
Returns:
Window of this scene.

getTransformer

public GTransformer getTransformer()
Return the transformation object of this scene. The transformer object can be used for client-side world-to-device and device-to-world coordinate transformations.

Overrides:
getTransformer in class GObject
Returns:
Current transformation object of this scene.

shouldZoomOnResize

public void shouldZoomOnResize(boolean shouldZoomOnResize)
Specified if one should zoom on resize. Set to true, the current image will change size (i.e. zoomed). Set to false the current image will be the same size and one will possibley see more or less instead. Default is true.

Parameters:
shouldZoomOnResize - True if world extent should be unchanged on resize, false otherwise.

shouldWorldExtentFitViewport

public void shouldWorldExtentFitViewport(boolean shouldWorldExtentFitViewport)
Specify wether world extent should always fit the viewport (i.e. have same aspect ratio) during resize. Default is true.

Parameters:
shouldWorldExtentFitViewport - True if the world extent should fit the viewport, false otherwise.

setViewport

public void setViewport(int x0,
                        int y0,
                        int x1,
                        int y1,
                        int x2,
                        int y2)
Set viewport for this scene. The viewport is specified in device coordinates. The layout is as follows:

     x0,y0 o-------o  x1,y1
           |
           |
           |
     x2,y2 o

 
It is thus possible to create a skewed viewport, which may be handy in some situations.

If the viewport is not set by a client, it will fit the canvas and adjust to it during resize. If it is set by client, it will stay fixed and not adjusted on resize.


setViewport

public void setViewport(int x0,
                        int y0,
                        int width,
                        int height)
Set viewport to a rectangular area of the screen. The viewport layout is as follows:

             width
     x0,y0 o-------o
           |
    height |
           |
           o

 

Parameters:
x0 - X coordinate of upper left corner of viewport.
y0 - Y coordinate of upper left corner of viewport.
width - Width of viewport.
height - Height of viewport.

getViewport

public GViewport getViewport()
Return current viewport.

Returns:
Current viewport of this scene.

setWorldExtent

public void setWorldExtent(double[] w0,
                           double[] w1,
                           double[] w2)
Set world extent of this scene. The layout is as follows:
        w2 o 
           |
           |
           |
        w0 o-------o w1
 
Thus w2 is mapped to viewport (x0,y0), w0 is mapped to (x2,y2) and w1 is mapped to lower right corner of viewport.

w0,w1 and w2 are three dimensions, and the world extent can thus be any plane in a 3D space, and the plane may be skewed.

Parameters:
w0 - Point 0 of the new world extent [x,y,z].
w1 - Point 1 of the new world extent [x,y,z].
w2 - Point 2 of the new world extent [x,y,z].

setWorldExtent

public void setWorldExtent(double x0,
                           double y0,
                           double width,
                           double height)
A convenience method for specifying a orthogonal world extent in the Z=0 plane. The layout is as follows:
           o 
           |
    height |
           |
     x0,y0 o-------o
             width

 

Parameters:
x0 - X coordinate of world extent origin.
y0 - Y coordinate of world extent origin.
width - Width of world extent.
height - Height of world extent.

getWorldExtent

public GWorldExtent getWorldExtent()
Return current world extent. The current world extent may differ the initial world extent due to zooming and window resizing.

Returns:
Current world extent.

zoom

public void zoom(double zoomFactor)
Zoom a specified amount around center of viewport.

Parameters:
zoomFactor - Zoom factor. Zoom in with factor < 1.0 and out with factor > 1.0.

zoom

public void zoom(int x,
                 int y,
                 double zoomFactor)
Zoom a specific amount using specified point as fixed.

Parameters:
x - X coordinate of fixed point during zoom.
y - Y coordinate of fixed point during zoom.
zoomFactor - Zoom factor.

zoom

public void zoom(int x0,
                 int y0,
                 int x1,
                 int y1)
Zoom into a specific device area.

Parameters:
x0 - X value of first corner of zoom rectangle.
y0 - Y value of first corner of zoom rectangle.
x1 - X value of second corner of zoom rectangle.
y1 - Y value of second corner of zoom rectangle.

zoom

public void zoom(double[] w0,
                 double[] w1,
                 double[] w2)
Zoom into a specified world area.

Parameters:
w0 - First world coordinate of zoom area [x,y,z].
w1 - Second world coordinate of zoom area [x,y,z].
w2 - Third world coordinate of zoom area [x,y,z].

unzoom

public void unzoom()
Unzoom. Unzooming sets the current world extent back to the initial world extent as specified by the client application by setWorldExtent().


pan

public void pan(int dx,
                int dy)
Pan a specific device distance.

Parameters:
dx - Distance to pan in x direction.
dy - Distance to pan in y direction.

installScrollHandler

public void installScrollHandler(Adjustable hScrollBar,
                                 Adjustable vScrollBar)
Instruct this scene to update and respond to the specified scrollbars during zoom.

NOTE I: The client application is responsible for laying out the scrollbars in the AWT/Swing GUI. The scrollbars should have no access listeneres nor logic added, as this is controlled by the GScene through the internal GScrollHandler object.

NOTE II: Do not put the graphics panel in a JScrollPane and use the JScrollPane scrollbars as input to this method, as a JScrollPane contains scroll logic that interfer with the internal GScene logic. The correct approach is to create horizontal and vertical JScrollBar explicitly.

Specifying both horizontal and vertical scrollbar as null turns off scroll handling in this scene.

Parameters:
hScrollBar - Horizontal scrollbar (or null if a horizontal scrollbar is not used).

GeoSoft API

Copyright © 2004 - Geotechnical Software Services     geosoft.no