package net.xoetrope.swing.docking;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import javax.swing.JPanel;
import org.jdesktop.swingx.MultiSplitLayout;
import org.jdesktop.swingx.JXMultiSplitPane;
/**
* The XCardPanel class manages two views of the docking panels, a MultiSplitPane
* view and a zoomed in view showing just a single docking panel. The views are
* swapped by invoking the <code>swapViews( XDockable )</code> method, passing the dockable object as a
* reference.
* <p>Copyright: Xoetrope Ltd. (c) 2003-2006<br>
* License: see license.txt</p>
* $Revision: 1.2 $
*/
public class XCardPanel extends JPanel
{
private JPanel zoomPanel;
private JXMultiSplitPane multiSplitPane;
private CardLayout cardManager;
private XDockable zoomedDockable;
/**
* Create a new XCardPanel for the specified MultiSplitPane. The MultiSplitPane
* will be shown initially
* @param msp the initial MultiSplitPane
*/
public XCardPanel( JXMultiSplitPane msp )
{
setLayout( cardManager = new CardLayout());
multiSplitPane = msp;
zoomPanel = new JPanel();
zoomPanel.setLayout( new BorderLayout());
add( zoomPanel, "ZoomPane" );
add( multiSplitPane, "MultiSplitPane" );
cardManager.show( this, "MultiSplitPane" );
}
/**
* Toogle the zoom view of the dockable panel.
* @param dockable the dockable object containing the XDockingPanel instance
* that is to be zoomed/shown
*/
public void swapViews( XDockable dockable )
{
MultiSplitLayout multiSplitLayout = (MultiSplitLayout)multiSplitPane.getLayout();
if ( !zoomPanel.isVisible()) {
// If the name is non null the dividers are also removed
multiSplitLayout.setRemoveDividers( false );
zoomPanel.add( dockable.dockedContainer, BorderLayout.CENTER );
cardManager.show( this, "ZoomPane" );
dockable.dockedContainer.setVisible( true );
zoomedDockable = dockable;
}
else {
// Reset the panel name
multiSplitLayout.setRemoveDividers( true );
multiSplitPane.add( dockable.dockedContainer, dockable.dockedContainer.getConstraint() );
cardManager.show( this, "MultiSplitPane" );
zoomedDockable = null;
}
revalidate();
}
/**
* Restore the zoom view of the dockable panel to its normal setup. If the
* view is not zoomed then this method has no effect.
*/
public XDockingPanel restoreViews()
{
if ( zoomPanel.isVisible()) {
MultiSplitLayout multiSplitLayout = (MultiSplitLayout)multiSplitPane.getLayout();
XDockingPanel dockedContainer = null;
if ( zoomPanel.getComponentCount() > 0 ) {
dockedContainer = ((XDockingPanel)zoomPanel.getComponent( 0 ));
// Reset the panel name
multiSplitLayout.setRemoveDividers( true );
multiSplitPane.add( dockedContainer, dockedContainer.getConstraint() );
}
cardManager.show( this, "MultiSplitPane" );
if ( zoomedDockable != null )
zoomedDockable.header.setZoomState( zoomedDockable.header.ZOOM );
return dockedContainer;
}
revalidate();
return null;
}
/**
* Is the docking panel zoomed
* @return true if the panel is zoomed
*/
public boolean isZoomed()
{
return zoomPanel.isVisible();
}
/**
* Get the zoomed dockable
* @return the zoomed XDockable
*/
public XDockable getDockable()
{
return zoomedDockable;
}
}