bibliothek.gui.dock.common.intern.station.CommonDockStationLayout Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docking-frames-common Show documentation
Show all versions of docking-frames-common Show documentation
DockingFrames is an open source Java Swing docking framework, licenced under LGPL 2.1.
This is the same distribution as the original distribution (http://www.docking-frames.org/), only reinstalled in maven
/*
* Bibliothek - DockingFrames
* Library built on Java/Swing, allows the user to "drag and drop"
* panels containing any Swing-Component the developer likes to add.
*
* Copyright (C) 2011 Benjamin Sigg
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Benjamin Sigg
* [email protected]
* CH - Switzerland
*/
package bibliothek.gui.dock.common.intern.station;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import bibliothek.gui.dock.DockFactory;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CStation;
import bibliothek.gui.dock.layout.DockLayout;
import bibliothek.gui.dock.layout.DockLayoutInfo;
import bibliothek.gui.dock.station.support.PlaceholderStrategy;
import bibliothek.util.xml.XElement;
/**
* Information about the layout of a {@link CommonDockStation}, used by the {@link CommonDockStationFactory}
* to store and load the layout.
* @author Benjamin Sigg
*/
public class CommonDockStationLayout {
/** The unique identifier of the {@link CommonDockStation} */
private String id;
/** Whether the {@link CStation} is a {@link CControl#isRootStation(CStation) root station}*/
private boolean root;
/** The unique identifier of the {@link DockFactory} that is used to read or apply the layout */
private String factoryId;
/** The actual layout information */
private DockLayoutInfo layout = new DockLayoutInfo();
/**
* Creates a new layout.
* @param id the unique identifier of the described {@link CommonDockStation}, might be null
* @param root whether the {@link CStation} is a root station
* @param factoryId the unique identifier of the {@link DockFactory} that is used to read or write the actual
* layout
* @param layout the layout that was loaded by the factory factoryId
*/
public CommonDockStationLayout( String id, boolean root, String factoryId, DockLayout> layout ){
if( factoryId == null ){
throw new IllegalArgumentException( "factoryId must not be null" );
}
this.id = id;
this.root = root;
this.factoryId = factoryId;
if( layout != null ){
this.layout.setData( layout );
}
}
/**
* Creates a new layout.
* @param id the unique identifier of the described {@link CommonDockStation}, might be null
* @param root whether the {@link CStation} is a root station
* @param factoryId the unique identifier of the {@link DockFactory} that is used to read or write the actual
* layout
* @param layout the layout that might be loaded by the factory factoryId
*/
public CommonDockStationLayout( String id, boolean root, String factoryId, byte[] layout ){
if( factoryId == null ){
throw new IllegalArgumentException( "factoryId must not be null" );
}
this.id = id;
this.root = root;
this.factoryId = factoryId;
if( layout != null ){
this.layout.setData( layout );
}
}
/**
* Creates a new layout.
* @param id the unique identifier of the described {@link CommonDockStation}, might be null
* @param root whether the {@link CStation} is a root station
* @param factoryId the unique identifier of the {@link DockFactory} that is used to read or write the actual
* layout
* @param layout the layout that might be loaded by the factory factoryId
*/
public CommonDockStationLayout( String id, boolean root, String factoryId, XElement layout ){
if( factoryId == null ){
throw new IllegalArgumentException( "factoryId must not be null" );
}
this.id = id;
this.root = root;
this.factoryId = factoryId;
if( layout != null ){
this.layout.setData( layout );
}
}
/**
* Updates the contents of the internal {@link DockLayoutInfo} using factory
to read
* a byte array or an {@link XElement}.
* @param factory the factory used to read the layout
* @param placeholders the placeholders that may be used
*/
public void updateLayout( DockFactory, ?, Object> factory, PlaceholderStrategy placeholders ){
try{
Object data = null;
switch( layout.getKind() ){
case BYTE:
data = factory.read( new DataInputStream( new ByteArrayInputStream( layout.getDataByte() ) ), placeholders );
break;
case XML:
data = factory.read( layout.getDataXML(), placeholders );
break;
}
if( data != null ){
layout.setData( new DockLayout