jview
Class JHiddenComponent

java.lang.Object
  extended by jview.JHiddenComponent

public class JHiddenComponent
extends Object

This class helps in adding a button or other components to a frame that disappears from view until the mouse moves over it. It is not using internal frames (to spare the window decoration), but manipulates the layered pane in a RootPaneContainer. This layered pane is assumed to have no layout manager (default case). The following steps are necessary to add (in the example a button) as a hiding component to a top-level window.


Nested Class Summary
private static class JHiddenComponent.ComponentHidden
           
private static class JHiddenComponent.MouseHidden
           
private static class JHiddenComponent.WindowHidden
           
 
Constructor Summary
JHiddenComponent()
           
 
Method Summary
static void addHidingComponent(Component c, RootPaneContainer frame, double panew, double paneh, double compw, double comph, boolean follow)
          This method adds a (prepared) hiding component to a RootPaneContainer, i.e.
static void addHidingComponent(Component c, RootPaneContainer frame, int gridbag, boolean follow)
          This method adds a (prepared) hiding component to a RootPaneContainer, i.e.
static void ensureHidingComponent(Component c, Window w)
          This method is only necessary to keep a hiding component hidden if the main frame is shown.
private static Point getUpLeft(Dimension pane, Dimension comp, double panew, double paneh, double compw, double comph)
          From four alignment parameters and the size of the frame plus the size of the component, we infer the position where the upper left corner of the hidden component should be.
private static Dimension inferSize(Component c)
          Tries to infer the size of the component.
static void main(String[] arg)
           
static void prepareHidingComponent(Component c)
          This method is called to prepare a component for hiding-until-mouse-over capablitities.
static void prepareHidingComponent(Component c, int mod)
          This method is called to prepare a component for hiding-until-mouse-over capablitities.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JHiddenComponent

public JHiddenComponent()
Method Detail

prepareHidingComponent

public static void prepareHidingComponent(Component c)
This method is called to prepare a component for hiding-until-mouse-over capablitities. It should be called only once during the life-cycle of the component.


prepareHidingComponent

public static void prepareHidingComponent(Component c,
                                          int mod)
This method is called to prepare a component for hiding-until-mouse-over capablitities. It should be called only once during the life-cycle of the component.


addHidingComponent

public static void addHidingComponent(Component c,
                                      RootPaneContainer frame,
                                      int gridbag,
                                      boolean follow)
This method adds a (prepared) hiding component to a RootPaneContainer, i.e. a frame, window, dialog or applet. It may be a bug, but on display the hidden component might still get visible, unless an appropriate window listener is attached to the frame/dialog/window using #ensureComponentHiding.

To support generic placements, the anchor-constants in GridBagConstraints for absolute values are supported (CENTER plus compass directions). If invalid, center is used.


addHidingComponent

public static void addHidingComponent(Component c,
                                      RootPaneContainer frame,
                                      double panew,
                                      double paneh,
                                      double compw,
                                      double comph,
                                      boolean follow)
This method adds a (prepared) hiding component to a RootPaneContainer, i.e. a frame, window, dialog or applet. It may be a bug, but on display the hidden component might still get visible, unless an appropriate window listener is attached to the frame/dialog/window using #ensureComponentHiding.

To support generic placements, the four placement indicators are used to deduce the upper left corner (UL). A placement in the center would thus require 0.5, 0.5, -0.5, -0.5.

Parameters:
panew - pane width*this=UL x coordinate.
paneh - pane height*this=UL y coordinate.
compw - component width*this: added to UL x (negative allowed).
comph - component height*this: added to UL y (negative allowed).

getUpLeft

private static Point getUpLeft(Dimension pane,
                               Dimension comp,
                               double panew,
                               double paneh,
                               double compw,
                               double comph)
From four alignment parameters and the size of the frame plus the size of the component, we infer the position where the upper left corner of the hidden component should be.


inferSize

private static Dimension inferSize(Component c)
Tries to infer the size of the component. First look at getSize, then try getPreferredSize, is this is inconvenient (<0).


ensureHidingComponent

public static void ensureHidingComponent(Component c,
                                         Window w)
This method is only necessary to keep a hiding component hidden if the main frame is shown.


main

public static void main(String[] arg)
                 throws Exception
Throws:
Exception