Perspective Eclipse like

Hello,

Is there a way to manage perspective like in Eclipse.
I need two ContentArea displayed in a tabbed pane for switching between it.

Thanks for advance.

I’m not sure if I understood you correctly, but I think this can be solved with the layout-mechanism. More precisly, with the method “CControl.save( String )” and “CControl.load( String )”.

For a perspecive “x”:

  1. You would first need to setup the perspective.
  2. Then call save( x ).
  3. If the user wants perspecive x you’d call “load( x )”.

If you store the layout in a file, then the perspectives would be stored as well.

Hello,

Ha, Beni comme back !

I speak about perspective like in eclipse, cf picture.
In fact I need to made the same things, with an invert tab (tab round shape to the left instead of right).

Thanks.

I wrote a little application which behaves similar to the Eclipse-perspectives.

Some things I’d like to add:

  • To build the initial setup of the perspectives you need real Dockable objects.
  • The current layout of a perspective gets stored when another perspective is selected.
  • Perspectives are stored in a file
  • Given some more buttons the user could easily add his/her own perspectives. If you are interested in that feature: also have a look at CControl.delete and CControl.layouts.
  • Everything that is on a working-area is not affected by a change of the perspective. Dockables that belong to a working-area but are minimized, maximized or externalized are put back on their working-area when the perspective changes.

And:

  • The ShapedGradientPainter paints these curves that are in Ecilpse. It can’t paint the inverse curve, but you could adapt the code…

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CLocation;
import bibliothek.gui.dock.common.CWorkingArea;
import bibliothek.gui.dock.common.DefaultMultipleCDockable;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.EmptyMultipleCDockableFactory;
import bibliothek.gui.dock.common.MultipleCDockable;
import bibliothek.gui.dock.common.MultipleCDockableFactory;
import bibliothek.gui.dock.common.MultipleCDockableLayout;
import bibliothek.gui.dock.common.SingleCDockable;
import bibliothek.gui.dock.common.CContentArea.Corner;
import bibliothek.gui.dock.common.intern.CDockable;

public class Dock8 extends JFrame{
	public static void main( String[] args ){
		Dock8 dock = new Dock8();
		dock.setBounds( 20, 20, 400, 400 );
		dock.setVisible( true );
	}
	
	private CDockable history;
	private CDockable outline;
	private CDockable fileA;
	private CDockable fileB;
	
	private CWorkingArea area;
	
	private CControl control;
	
	private String perspective = null;
	
	private MultipleCDockableFactory<MultipleCDockable, MultipleCDockableLayout> factory = 
		new EmptyMultipleCDockableFactory<MultipleCDockable>(){
		@Override
		public MultipleCDockable createDockable(){
			return new DefaultMultipleCDockable( this, "File" );
		}
	};
	
	public Dock8(){
		setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
		addWindowListener( new WindowAdapter(){
			@Override
			public void windowClosing( WindowEvent e ){
				try{
					control.writeXML( new File( "layout.xml" ) );
				}
				catch( IOException e1 ){
					e1.printStackTrace();
				}
				dispose();
			}
		});
		
		control = new CControl( this );
		
		// lazy loading, need to add the content area first!
		add( control.getContentArea() );
		
		control.addMultipleDockableFactory( "files", factory );
		
		area = control.createWorkingArea( "area" );
		
		history = createSingle( "Histroy" );
		outline = createSingle( "Outline" );
		
		fileA = createFile();
		fileB = createFile();
		
		try{
			control.readXML( new File( "layout.xml" ) );
		}
		catch( IOException e ){
			// well, then create a default-layout
			buildDebug();
			buildJava();
			
			// The position of children of a Working-Area is not stored in perspectives,
			// make sure they are visible.
			fileA.setLocation( CLocation.working( area ) );
			fileA.setVisible( true );
			
			fileB.setLocation( CLocation.working( area ).south( 0.4 ) );
			fileB.setVisible( true );
			
			control.load( "Java" );
		}
				
		JPanel buttons = new JPanel( new GridLayout( 1, 2 ));
		buttons.add( createPerspectiveButton( "Java" ) );
		buttons.add( createPerspectiveButton( "Debug" ) );
		
		add( control.getContentArea() );
		control.getContentArea().setCornerComponent( buttons, Corner.NORTH_EAST, true );
	}
	
	private void buildDebug(){
		area.setLocation( CLocation.base().normal() );
		area.setVisible( true );
		
		fileA.setLocation( CLocation.working( area ) );
		fileA.setVisible( true );
		
		fileB.setLocation( CLocation.working( area ).stack( 1 ) );
		fileB.setVisible( true );
		
		outline.setLocation( CLocation.base().normalEast( 0.25 ) );
		outline.setVisible( true );
		
		history.setLocation( CLocation.base().normalSouth( 0.25 ) );
		history.setVisible( true );
		
		control.save( "Debug" );
		
		fileA.setVisible( false );
		fileB.setVisible( false );
		
		// BUG: causes an error >:-/
		// area.setVisible( false );
		outline.setVisible( false );
		history.setVisible( false );
	}
	
	private void buildJava(){
		area.setLocation( CLocation.base().normal() );
		area.setVisible( true );
		
		fileA.setLocation( CLocation.working( area ) );
		fileA.setVisible( true );
		
		fileB.setLocation( CLocation.working( area ).south( 0.5 ) );
		fileB.setVisible( true );
		
		outline.setLocation( CLocation.base().normalWest( 0.25 ) );
		outline.setVisible( true );
		
		history.setLocation( CLocation.base().normalWest( 0.25 ).stack() );
		history.setVisible( true );
		
		control.save( "Java" );
		
		fileA.setVisible( false );
		fileB.setVisible( false );
		outline.setVisible( false );
		history.setVisible( false );
	}
	
	private CDockable createSingle( String title ){
		SingleCDockable dockable = new DefaultSingleCDockable( title, title );
		control.add( dockable );
		return dockable;
	}
	
	private CDockable createFile(){
		DefaultMultipleCDockable dockable = new DefaultMultipleCDockable( factory, "File" );
		dockable.setRemoveOnClose( false );
		area.add( dockable );
		return dockable;
	}
	
	private JButton createPerspectiveButton( final String name ){
		JButton button = new JButton( name );
		button.addActionListener( new ActionListener(){
			@Override
			public void actionPerformed( ActionEvent e ){
				if( perspective != null ){
					control.save( perspective );
				}
				perspective = name;
				control.load( name );
			}
		});
		return button;
	}
}

Who is the Best ?
Thanks Beni !
That’s exactly what i want to do.
I just need to make a shape to group the two perspective buttons like in eclipse.
What exactly do the control.save() function ? A file is create physically or only in memory ?
the Debug perspective doesn’t keep the state of dockables in it when you come-back from an other perspective as the java perspective. Is it intentionnal ?

Thanks a lot.
With that i’m sure that we use your framework for our project.
The first delivery if for april. Let’s go !

save() stores the layout in memory. The current Dockables are transformed into an intermediate format. If the application stops then this intermediate format gets written into the “layout.xml”.

I’ll check the other thing with the Debug-Perspective once I’m at home. It should work (if my memory is not totally screwed up…), you are sure you are looking at the history, outline and working-area? The fileA and fileB are intentionally normalized and their location on the working-area does not change. That’s because children of a working-area often represent things (like files) that might not be available the next time when the perspective is loaded, hence they are ignored.

I can’t reproduce the error with the Debug-perspective, maybe we are not talking about the same problem…

Oups, I think i’m tired or perhaps at the first launch…
It’s work now.
Forget.

Thanks

Hello,

I copied the sourcecode and tried to compile it. But at compile time i get the following error:

	at bibliothek.gui.dock.station.support.PlaceholderList$Entry.move(Unknown Source)
	at bibliothek.gui.dock.station.support.PlaceholderList$SubList.move(Unknown Source)
	at bibliothek.gui.dock.StackDockStation.move(Unknown Source)
	at bibliothek.gui.dock.StackDockStation.move(Unknown Source)
	at bibliothek.gui.dock.SplitDockStation.dropOver(Unknown Source)
	at bibliothek.gui.dock.SplitDockStation.drop(Unknown Source)
	at bibliothek.gui.dock.SplitDockStation.access$900(Unknown Source)
	at bibliothek.gui.dock.SplitDockStation$6.drop(Unknown Source)
	at bibliothek.gui.dock.station.split.Leaf.insert(Unknown Source)
	at bibliothek.gui.dock.station.split.Node.insert(Unknown Source)
	at bibliothek.gui.dock.station.split.Node.insert(Unknown Source)
	at bibliothek.gui.dock.station.split.Node.insert(Unknown Source)
	at bibliothek.gui.dock.station.split.Root.insert(Unknown Source)
	at bibliothek.gui.dock.SplitDockStation.drop(Unknown Source)
	at bibliothek.gui.dock.SplitDockStation.drop(Unknown Source)
	at bibliothek.gui.dock.common.mode.station.CSplitDockStationHandle$Normal.setLocation(Unknown Source)
	at bibliothek.gui.dock.facile.mode.DefaultLocationMode.runApply(Unknown Source)
	at bibliothek.gui.dock.facile.mode.AbstractLocationMode.apply(Unknown Source)
	at bibliothek.gui.dock.facile.mode.AbstractLocationMode.apply(Unknown Source)
	at bibliothek.gui.dock.support.mode.ModeManager$3.run(Unknown Source)
	at bibliothek.gui.dock.support.mode.ModeManager.runTransaction(Unknown Source)
	at bibliothek.gui.dock.support.mode.ModeManager.runTransaction(Unknown Source)
	at bibliothek.gui.dock.support.mode.ModeManager.apply(Unknown Source)
	at bibliothek.gui.dock.support.mode.ModeManager.apply(Unknown Source)
	at bibliothek.gui.dock.support.mode.ModeManager.apply(Unknown Source)
	at bibliothek.gui.dock.common.mode.CLocationModeManager.setLocation(Unknown Source)
	at bibliothek.gui.dock.common.CControl$Access.show(Unknown Source)
	at bibliothek.gui.dock.common.intern.AbstractCDockable.setVisible(Unknown Source)
	at dock.Dock8.buildJava(Dock8.java:152)
	at dock.Dock8.<init>(Dock8.java:90)
	at dock.Dock8.main(Dock8.java:30)

what does it mean?

greetings
ExPörT

I’ll have to let the program run, but it looks like a bug in the framework.

It really was a bug in the framework, an index was not checked properly leading to this complaint. I’ll have an update uploaded in 1 hour.