public class CustomDesktopManager extends DefaultDesktopManager
DefaultDesktopManager
to create a new DesktopManger able to manage the position
of every new JInternalFrame
frame positioned inside a JDesktopPane
(in our case
represented by the contentArea
area).
When we want to find the best position for a new JInternalFrame
frame inside a JDesktopPane
area,
we can ask to the CustomDesktopManager
of that area to find it, calling its positionFrame(JInternalFrame)
method and passing to it the internal frame to position.
This method first tries to put the frame in the first empty space in the diagonal that goes from NW to SE, either at the end of the pile of the already opened frames or in one space between them left free from a frame that has been closed or moved out from its original position.
If the method is not able to find any free space on this way, due to the end of free space on the main window, it positions the internal frame on the centre of the area, over all the other internal frames.
DefaultDesktopManager
,
JInternalFrame
,
JDesktopPane
,
Serialized FormModifier and Type | Field and Description |
---|---|
private static long |
serialVersionUID
Auto-Generated Serial Version UID for this class.
|
Constructor and Description |
---|
CustomDesktopManager()
Constructor for this class.
|
Modifier and Type | Method and Description |
---|---|
private Point |
firstFreePosition(Point startingPoint,
Dimension containerSize,
JInternalFrame[] allInternalFrames,
JInternalFrame targetInternalFrame)
This method tries to find a place, defined by a NW corner point,
in the container area, defined by its size, where there are no other
internal frames and there is enough space to place the target internal frame.
|
void |
positionFrame(JInternalFrame f)
This method tries to find the best position for a
JInternalFrame
inside itsJDesktopPane and to set its location if there is any free
space on the area (otherwise the internal frame get positioned on the default
position by the application, over all the other frames). |
activateFrame, beginDraggingFrame, beginResizingFrame, closeFrame, deactivateFrame, deiconifyFrame, dragFrame, endDraggingFrame, endResizingFrame, getBoundsForIconOf, getPreviousBounds, iconifyFrame, maximizeFrame, minimizeFrame, openFrame, removeIconFor, resizeFrame, setBoundsForFrame, setPreviousBounds, setWasIcon, wasIcon
private static final long serialVersionUID
public CustomDesktopManager()
public void positionFrame(JInternalFrame f)
JInternalFrame
inside itsJDesktopPane
and to set its location if there is any free
space on the area (otherwise the internal frame get positioned on the default
position by the application, over all the other frames).f
- the internal frame to positionJInternalFrame
,
JDesktopPane
private Point firstFreePosition(Point startingPoint, Dimension containerSize, JInternalFrame[] allInternalFrames, JInternalFrame targetInternalFrame)
Starting from a given starting point, this method checks if there is already an internal frame in that position. If that position is free, it returns that point as the first free one found. Otherwise, if there is already an internal frame in that position, the method checks a new point defined by an offset added to the last checked point.
The method continues on this way until either it finds a free point to return or it reaches the bounds of the container and so there is no more space to check.
startingPoint
- starting point where to start searchingcontainerSize
- size of the container where to research free spaceallInternalFrames
- all the internal frames in the containertargetInternalFrame
- the target internal frame to position