Ok, there is the Code that do the Switch between
both Views when user hits a Button:
public class PlaylistSpectrumPanel
extends JPanel implements Toogleable
{
private static Logger log = Logger.getLogger(PlaylistSpectrumPanel.class);
/**
* The Spectrum Panel
*/
private final SpectrumPanel spectrumPanel;
/**
* The Playlist Panel
*/
private final Playlist playlistPanel;
private boolean isSpectrumShown = true;
private ServerPanel serverPanel = new ServerPanel(new ServerTable());
private JComponent lastFileView = null;
private final AWTCanvasTest awtCanvas;
public PlaylistSpectrumPanel(AWTCanvasTest awtCanvas, SpectrumPanel spectrumPanel, Playlist playlistPanel)
{
super();
this.spectrumPanel = spectrumPanel;
this.playlistPanel = playlistPanel;
this.awtCanvas = awtCanvas;
setLayout(new BorderLayout());
add(awtCanvas, BorderLayout.CENTER);
lastFileView = playlistPanel;
System.out.println("awtCanvas.getPreferredSize():" + awtCanvas.getPreferredSize());
}
public void toogle()
{
toogleSpectrum();
}
/**
* Switch between Spectrum and Playlist view
*/
private final void toogleSpectrum()
{
if (isSpectrumShown)
{
//remove(spectrumPanel);
remove(awtCanvas);
add(lastFileView, BorderLayout.CENTER);
awtCanvas.donotShow();
}
else
{
remove(lastFileView);
switchView();
//add(spectrumPanel, BorderLayout.CENTER);
add(awtCanvas, BorderLayout.CENTER);
awtCanvas.showAgain();
}
isSpectrumShown = isSpectrumShown ? false : true;
revalidate();
updateUI();
}
private final void switchView()
{
if (lastFileView.equals(playlistPanel))
{
lastFileView = serverPanel;
}
else
{
lastFileView = playlistPanel;
}
System.out.println("New View:" + lastFileView);
}
}
Actual the SpectumPanel isnt used by this example,
AWTCanvasTest is the GLGear Test from LWJGL Examples (the heavyweight canvas), with this extension:
public void showAgain()
{
canvas0.setVisible(true);
canvas0.addNotify();
}
public void donotShow()
{
canvas0.setVisible(false);
canvas0.removeNotify();
}