All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class vt.cs.widgets.RadarPane

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----vt.cs.widgets.RadarPane

public class RadarPane
extends Panel
implements Serializable, ViewWindowParent

RadarPane - This is a scrollable panel; a drop-in replacement of java.awt.ScrollPane and implements the same methods as java.awt.ScrollPane. RadarPane only works in Java 1.1 or better.

RadarPane is available for download at http://simon.cs.vt.edu/~begolej/download/RadarPane.jar

Contact James "Bo" Begole, begolej@vt.edu, for bugs fixes and enhancement requests.

Related Work

RadarPane in use: Tell me (begolej@vt.edu) about your use of RadarPane.


Using RadarPane

RadarPane includes a radar view of an embedded component, which is a scaled down image of the entire embedded component. The figure below shows RadarPane. The scroll pane is on the left and the radar view on the right.

Navigate by using the scroll bars or by using the radar view window. To navigate using the window, click in the window. If, you click outside the viewport rectangel, or click with the right mouse button, the scroll pane will move so that it is centered on your click. If you click inside the viewport rectangle, the viewport will move relative to your moves, until you release the mouse.

The radar view window may be hidden and displayed by clicking the checkbox in the lower right of the scroll pane (See figure above). The radar view component may be detached from the radar view window. If the radar view is detached, no radar view window or checkbox will appear.


Adding RadarPane to a Program

RadarPane has the same API as java.awt.ScrollPane. To use it, add() a java.awt.Component to a RadarPane object. The component will usually be a java.awt.Panel that contains other components. The applet pictured above with source code may be found at http://simon.cs.vt.edu/~begolej/applets/RadarPaneTest/

Here is a sample:

 import java.awt.*;
 import java.applet.*;
 import vt.cs.widgets.*;
 public class RadarPaneTest extends Applet {
   RadarPane scroller;
   public RadarPaneTest() {
     setLayout(new BorderLayout());
     scroller = new RadarPane(RadarPane.SCROLLBARS_AS_NEEDED);
     scroller.add(new ButtonPanel());
     add("Center", scroller);
   }
 }
 class ButtonPanel extends Panel {
   ButtonPanel() {
     setLayout(new FlowLayout(FlowLayout.CENTER, 20, 30));
     for (int i=0; i<50; i++) 
         add(new Button("Button "+i));
     resize(getPreferredSize());
   }
   public Dimension getMinimumSize() {
     return new Dimension(500, 500);
   }
   public Dimension getPreferredSize() {
     return getMinimumSize();
   }
 }
 

Embedding java.awt.Panel Objects

One warning with a workaround. RadarPane uses the Component.printAll() method to get an image of the embedded component. If the component is a Container, the printAll() method will print all of the children of that container, but not the containter itself. For example, if you embed a Panel that overrides the paint() or update() methods to paint on itself, those graphics will not appear in the radar view. The workaround is to override the Container.print() method of your panel with the following:
   public void print(Graphics g) {
     super.print(g);
     paint(g);
   }
 

Hits since Feb 01, 1997:

Version:
$Revision: 1.23 $
Author:
James Begole

Variable Index

 o clientPanel
The panel which embeds the client of this RadarPane.
 o hAdjustable
The horizontal Adjustable (scrollbar)
 o radarToggle
The selector that toggles the view of the radarView.
 o radarView
The radar view component.
 o radarViewAttached
Indicates wether the radar view is attached to the radarViewWindow.
 o radarViewWindow
The window that displays the radar view.
 o scrollbarDisplayPolicy
Specifies under what conditions to display the scrollbars.
 o SCROLLBARS_ALWAYS
Specifies that horizontal/vertical scrollbars should always be shown regardless of the respective sizes of the scrollpane and child.
 o SCROLLBARS_AS_NEEDED
Specifies that horizontal/vertical scrollbar should be shown only when the size of the child exceeds the size of the scrollpane in the horizontal/vertical dimension.
 o SCROLLBARS_NEVER
Specifies that horizontal/vertical scrollbars should never be shown regardless of the respective sizes of the scrollpane and child.
 o vAdjustable
The vertical Adjustable (scrollbar)

Constructor Index

 o RadarPane()
Create a new RadarPane container with a scrollbar display policy of "as needed".
 o RadarPane(int)
Create a new RadarPane container.
 o RadarPane(ScrollPane)
Create a new RadarPane container from an existing ScrollPane.

Method Index

 o add(Component)
Adds the specified component to this scroll pane container.
 o addImpl(Component, Object, int)
Adds the specified component to this container at the specified index.
 o addNotify()
Overriden to attach the radar view component when this RadarPane is added to something.
 o attachRadarView()
Displays the radar view window and the radar view checkbox.
 o detachRadarView()
Gets the radar view Component.
 o getHAdjustable()
Returns the Adjustable object which represents the state of the horizontal scrollbar.
 o getHScrollbarHeight()
Returns the height that would be occupied by a horizontal scrollbar, which is independent of whether it is currently displayed by the scroll pane or not.
 o getMinimumSize()
Sets minimum size to Dimension(200, 200), unless the size is explicitly set to be less.
 o getPreferredSize()
Sets the preferred size to call getMinimumSize
 o getRadarView()
Gets the radar view Component.
 o getScaler()
Returns the object which is responsible for scaling the component contained within the RadarPane, if such an object has been registered with the setScaler method.
 o getScrollbarDisplayPolicy()
Returns the display policy for the scrollbars.
 o getScrollPosition()
Returns the current x,y position within the child which is displayed at the 0,0 location of the scrolled panel's view port.
 o getVAdjustable()
Returns the Adjustable object which represents the state of the vertical scrollbar.
 o getViewportSize()
Returns the current size of the scroll pane's view port.
 o getVScrollbarWidth()
Returns the width that would be occupied by a vertical scrollbar, which is independent of whether it is currently displayed by the scroll pane or not.
 o handleEvent(Event)
Handles scroll bar and radar view events that move the embedded client component.
 o hideViewWindow()
Hides the radar view window.
 o invalidate()
Overriden to also invalidate the radar view component.
 o paint(Graphics)
Draws the RadarPane and calls repaint on the radar view component.
 o paramString()
 o removeNotify()
Overriden to detach the radar view component when this RadarPane is removed from something.
 o setBounds(int, int, int, int)
Reshapes the Component to the specified bounding box.
 o setClientChanged(boolean)
Sets or clears the clientChanged flag.
 o setLayout(LayoutManager)
Sets the layout manager for this container.
 o setScaler(Scalable)
Sets an object to be used for scaling the contents of the RadarPane.
 o setScrollPosition(int, int)
Scrolls to the specified position within the child component.
 o setScrollPosition(Point)
Scrolls to the specified position within the child component.
 o update(Graphics)
Calls paint(g) without first clearing the component background.
 o validate()
Overriden to also validate the radar view component and its parent.

Variables

 o SCROLLBARS_AS_NEEDED
 public static final int SCROLLBARS_AS_NEEDED
Specifies that horizontal/vertical scrollbar should be shown only when the size of the child exceeds the size of the scrollpane in the horizontal/vertical dimension. Note that when both scrollbars are not shown, the radar view window is hidden and the radar view checkbox is also not shown. If a developer wants the radar view to display when both scrollbars are not shown, s/he should detach the radar view and embed it in another AWT container.

 o SCROLLBARS_ALWAYS
 public static final int SCROLLBARS_ALWAYS
Specifies that horizontal/vertical scrollbars should always be shown regardless of the respective sizes of the scrollpane and child.

 o SCROLLBARS_NEVER
 public static final int SCROLLBARS_NEVER
Specifies that horizontal/vertical scrollbars should never be shown regardless of the respective sizes of the scrollpane and child. The radar view checkbox will not be displayed. This mode is more useful here in RadarPane than in ScrollPane, since users may still navigate the viewport using the radar view.

 o scrollbarDisplayPolicy
 protected int scrollbarDisplayPolicy
Specifies under what conditions to display the scrollbars. One of: SCROLLBARS_AS_NEEDED, SCROLLBARS_ALWAYS, SCROLLBARS_NEVER. The default is SCROLLBARS_AS_NEEDED.

 o vAdjustable
 protected Scrollbar vAdjustable
The vertical Adjustable (scrollbar)

 o hAdjustable
 protected Scrollbar hAdjustable
The horizontal Adjustable (scrollbar)

 o clientPanel
 protected RadarPaneClientPanel clientPanel
The panel which embeds the client of this RadarPane.

 o radarToggle
 protected Checkbox radarToggle
The selector that toggles the view of the radarView.

 o radarView
 protected RadarView radarView
The radar view component.

 o radarViewWindow
 protected ViewWindow radarViewWindow
The window that displays the radar view.

 o radarViewAttached
 protected boolean radarViewAttached
Indicates wether the radar view is attached to the radarViewWindow. true if the radar view is attached to the radarViewWindow. false otherwise.

Constructors

 o RadarPane
 public RadarPane()
Create a new RadarPane container with a scrollbar display policy of "as needed".

 o RadarPane
 public RadarPane(int scrollbarDisplayPolicy)
Create a new RadarPane container.

Parameters:
scrollbarDisplayPolicy - policy for when scrollbars should be shown
 o RadarPane
 public RadarPane(ScrollPane scrollPane)
Create a new RadarPane container from an existing ScrollPane.

Parameters:
scrollPane - the ScrollPane from which to construct this RadarPane. The RadarPane will have the same state as the scrollPane.

Methods

 o addImpl
 protected void addImpl(Component comp,
                        Object constraints,
                        int index)
Adds the specified component to this container at the specified index. Also notifies the layout manager to add the component to this container's layout using the specified constraints object.

This is overriden for RadarPane so that components are added only to the viewport region of the RadarPane.

This is the method to override if you want to track every add request to a container. An overriding method should usually include a call to super.addImpl(comp, constraints, index).

Parameters:
comp - the component to be added
constraints - an object expressing layout contraints for this component
index - the position in the container's list at which to insert the component. -1 means insert at the end.
Overrides:
addImpl in class Container
See Also:
remove, LayoutManager
 o add
 public Component add(Component comp)
Adds the specified component to this scroll pane container. If the scroll pane has an existing child component, that component is removed and the new one is added.

Parameters:
comp - the component to be added
Overrides:
add in class Container
 o detachRadarView
 public Component detachRadarView()
Gets the radar view Component. The radar view component gives a scaled down full view of the client component of this RadarPane and provides a navigation mechanism in addition to the scroll bars of this RadarPane. Use this, if you want the radar view window and the radar view checkbox to no longer exist. Otherwise, use getRadarView() .

Returns:
the radar view Component
See Also:
getRadarView
 o getRadarView
 public Component getRadarView()
Gets the radar view Component. The radar view component gives a scaled down full view of the client component of this RadarPane and provides a navigation mechanism in addition to the scroll bars of this RadarPane. Use this, if you want the radar view window and the radar radar view checkbox to continue to exist. Otherwise, use detachRadarView() .

Returns:
the radar view Component
See Also:
detachRadarView
 o attachRadarView
 public void attachRadarView()
Displays the radar view window and the radar view checkbox.

See Also:
detachRadarView
 o setLayout
 public final void setLayout(LayoutManager mgr)
Sets the layout manager for this container. This method is overridden to prevent the layout mgr from being set.

Parameters:
mgr - the specified layout manager
Overrides:
setLayout in class Container
 o getScrollbarDisplayPolicy
 public int getScrollbarDisplayPolicy()
Returns the display policy for the scrollbars.

Returns:
the display policy for the scrollbars
 o getViewportSize
 public Dimension getViewportSize()
Returns the current size of the scroll pane's view port.

Returns:
the size of the view port in pixels
 o getHScrollbarHeight
 public int getHScrollbarHeight()
Returns the height that would be occupied by a horizontal scrollbar, which is independent of whether it is currently displayed by the scroll pane or not.

Returns:
the height of a horizontal scrollbar in pixels
 o getVScrollbarWidth
 public int getVScrollbarWidth()
Returns the width that would be occupied by a vertical scrollbar, which is independent of whether it is currently displayed by the scroll pane or not.

Returns:
the width of a vertical scrollbar in pixels
 o getVAdjustable
 public Adjustable getVAdjustable()
Returns the Adjustable object which represents the state of the vertical scrollbar. If the scrollbar display policy is "never", this method returns null.

 o getHAdjustable
 public Adjustable getHAdjustable()
Returns the Adjustable object which represents the state of the horizontal scrollbar. If the scrollbar display policy is "never", this method returns null.

 o setScrollPosition
 public void setScrollPosition(int x,
                               int y)
Scrolls to the specified position within the child component. A call to this method is only valid if the scroll pane contains a child and the specified position is within legal scrolling bounds of the child. Legal bounds are defined to be the rectangle: x = 0, y = 0, width = (child width - view port width), height = (child height - view port height). This is a convenience method which interfaces with the Adjustable objects which respresent the state of the scrollbars.

Parameters:
x - the x position to scroll to
y - the y position to scroll to
Throws: IllegalArgumentException
if specified coordinates are not within the legal scrolling bounds of the child component.
 o setScrollPosition
 public void setScrollPosition(Point p)
Scrolls to the specified position within the child component. A call to this method is only valid if the scroll pane contains a child and the specified position is within legal scrolling bounds of the child. Legal bounds are defined to be the rectangle: x = 0, y = 0, width = (child width - view port width), height = (child height - view port height). This is a convenience method which interfaces with the Adjustable objects which respresent the state of the scrollbars.

Parameters:
p - the Point representing the position to scroll to
Throws: IllegalArgumentException
if specified coordinates are not within the legal scrolling bounds of the child component.
 o getScrollPosition
 public Point getScrollPosition()
Returns the current x,y position within the child which is displayed at the 0,0 location of the scrolled panel's view port. This is a convenience method which interfaces with the adjustable objects which respresent the state of the scrollbars.

Returns:
the coordinate position for the current scroll position
 o handleEvent
 public boolean handleEvent(Event evt)
Handles scroll bar and radar view events that move the embedded client component.

Returns:
super.handleEvent(evt);
Overrides:
handleEvent in class Component
 o hideViewWindow
 public void hideViewWindow()
Hides the radar view window.

 o update
 public void update(Graphics g)
Calls paint(g) without first clearing the component background.

Overrides:
update in class Container
 o paint
 public void paint(Graphics g)
Draws the RadarPane and calls repaint on the radar view component.

Overrides:
paint in class Container
 o invalidate
 public void invalidate()
Overriden to also invalidate the radar view component.

Overrides:
invalidate in class Container
 o validate
 public void validate()
Overriden to also validate the radar view component and its parent.

Overrides:
validate in class Container
 o addNotify
 public void addNotify()
Overriden to attach the radar view component when this RadarPane is added to something.

Overrides:
addNotify in class Panel
 o removeNotify
 public void removeNotify()
Overriden to detach the radar view component when this RadarPane is removed from something.

Overrides:
removeNotify in class Container
 o getMinimumSize
 public Dimension getMinimumSize()
Sets minimum size to Dimension(200, 200), unless the size is explicitly set to be less.

Overrides:
getMinimumSize in class Container
See Also:
getPreferredSize
 o getPreferredSize
 public Dimension getPreferredSize()
Sets the preferred size to call getMinimumSize

Overrides:
getPreferredSize in class Container
See Also:
getMinimumSize
 o setScaler
 public void setScaler(Scalable scaler)
Sets an object to be used for scaling the contents of the RadarPane. If no scaler is set, a check is made to see if the component within the RadarPane implements Scalable. If it does not, then a snapshot of the contained component is taken and scaled.

Parameters:
scaler - An object which knows how to scale the component contained within the RadarPane
See Also:
getScaler
 o getScaler
 public Scalable getScaler()
Returns the object which is responsible for scaling the component contained within the RadarPane, if such an object has been registered with the setScaler method.

See Also:
setScaler
 o setBounds
 public void setBounds(int x,
                       int y,
                       int width,
                       int height)
Reshapes the Component to the specified bounding box. Overriden to notify the radar view that the view port has changed.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the component
height - the height of the component
Overrides:
setBounds in class Component
See Also:
getBounds, setLocation, setSize
 o paramString
 public String paramString()
Overrides:
paramString in class Container
 o setClientChanged
 public void setClientChanged(boolean value)
Sets or clears the clientChanged flag.

Parameters:
value - true causes radar view to get a new image of the embedded client. false clears the flag; radar view does nothing, unless flag was set previously and it has not yet obtained the new image. In which case, it will not get the new image.

All Packages  Class Hierarchy  This Package  Previous  Next  Index