Hi Beni,
thanks for your quick response and updating of the code.
The NullPointerException I get when I use something like this (Line 46).
package com.test;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.menu.SingleCDockableListMenuPiece;
import bibliothek.gui.dock.common.perspective.CControlPerspective;
import bibliothek.gui.dock.common.perspective.CGridPerspective;
import bibliothek.gui.dock.common.perspective.CPerspective;
import bibliothek.gui.dock.common.perspective.SingleCDockablePerspective;
import bibliothek.gui.dock.facile.menu.RootMenuPiece;
public class Dock27 {
public static void main( String[] args ){
/* A frame and control... */
JFrame frame = new JFrame( "Test" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setBounds( 20, 20, 300, 300 );
CControl control = new CControl( frame );
frame.add( control.getContentArea() );
/* We just add the dockables right now, so we don't have to care about automatic removal of placeholders */
control.addDockable( create( "a", "A" ) );
control.addDockable( create( "b", "B" ) );
control.addDockable( create( "c", "C" ) );
control.addDockable( create( "d", "D" ) );
/* Start building a perspective... */
CControlPerspective controlPerspective = control.getPerspectives();
CPerspective layout = controlPerspective.createEmptyPerspective();
SingleCDockablePerspective dockableA = new SingleCDockablePerspective( "a" );
SingleCDockablePerspective dockableB = new SingleCDockablePerspective( "b" );
SingleCDockablePerspective dockableC = new SingleCDockablePerspective( "c" );
SingleCDockablePerspective dockableD = new SingleCDockablePerspective( "d" );
/* Adding the dockables at their place */
CGridPerspective center = layout.getContentArea().getCenter();
center.gridAdd( 0, 0, 1, 1, dockableA );
center.gridAdd( 0, 1, 1, 1, dockableB );
center.gridAdd( 1, 0, 1, 1, dockableC);
// center.gridAdd( 1, 1, 1, 1, dockableD );
center.gridPlaceholder( 1, 1, 1, 1, dockableD );
center.gridDeploy();
/* Now we remove the dockables we do not want to show up */
// dockableA.remove();
// dockableB.remove();
// dockableC.remove();
// dockableD.remove();
/* Cleaning up the layout */
// layout.shrink();
/* Applying the layout */
controlPerspective.setPerspective( layout, true );
/* And we add a menu that allows us to make the invisible dockables visible again */
JMenuBar menuBar = new JMenuBar();
RootMenuPiece menu = new RootMenuPiece( "Panels", false, new SingleCDockableListMenuPiece( control ) );
menuBar.add( menu.getMenu() );
frame.setJMenuBar( menuBar );
frame.setVisible( true );
}
private static DefaultSingleCDockable create( String id, String title ){
DefaultSingleCDockable dockable = new DefaultSingleCDockable( id, title );
dockable.setCloseable( true );
return dockable;
}
}
I still do not know why this is not allowed. I do not know how to use Placeholders in CPerspective.
I tried to use the 1.1.1p8b, but I got a NullPointerException, when I called CControlPerspective#getPerspective(String name). Unfortunately I can not reproduce this error in a simple example. But I will paste the error log:
Caused by: java.lang.NullPointerException
at bibliothek.gui.dock.common.intern.station.CommonDockStationFactory.layoutPerspective(CommonDockStationFactory.java:217)
at bibliothek.gui.dock.common.intern.station.CommonDockStationFactory.layoutPerspective(CommonDockStationFactory.java:65)
at bibliothek.gui.dock.frontend.RegisteringDockFactory.layoutPerspective(RegisteringDockFactory.java:139)
at bibliothek.gui.dock.frontend.RegisteringDockFactory.layoutPerspective(RegisteringDockFactory.java:51)
at bibliothek.gui.dock.layout.PredefinedDockSituation$PreloadFactory.layoutPerspective(PredefinedDockSituation.java:740)
at bibliothek.gui.dock.layout.PredefinedDockSituation$PreloadFactory.layoutPerspective(PredefinedDockSituation.java:567)
at bibliothek.gui.dock.perspective.Perspective.convert(Perspective.java:255)
at bibliothek.gui.dock.common.perspective.CControlPerspective.convert(CControlPerspective.java:456)
at bibliothek.gui.dock.common.perspective.CControlPerspective.getPerspective(CControlPerspective.java:136)
at com.mevisco.mpc.statisticsviewer.StatisticsViewer.initPerspectives(StatisticsViewer.java:296)
at com.mevisco.application.gui.swing.DockableFrameApplication.initGUI(DockableFrameApplication.java:76)
at com.mevisco.mpc.statisticsviewer.StatisticsViewer.initGUI(StatisticsViewer.java:207)
at com.mevisco.application.Application$2.run(Application.java:598)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Another problem, is the menu. I implemented a available docks menu myself using CControlListener, but I think the invisiable dock is not added to the CDockCOntrol so it does not appear in the menu. If I try to use SingleCDockableListMenuPiece in my apllication it is totally empty. Probably I initialize the menu before the layout is set up.
I do not stick to CPerspective concept. What I liked was the factory concept. But at the moment our application is small, so it will not be the problem not to use factories for now. But this could change and I want to find a future proof concept.
Do you have any better suggestions. How to set this up? We have some docks, that are known at compile time (this is what I implement know). Some docks will be only known at runtime, depending on the configuration. The configuration could change during the runtime. But it will rarely. Should I use for this purpose Single or MultiCDockables? All the docks will contain some life statistics. So the user does not have a real editor. It is just visualization.