public void setLocation( int childIndex, DockableProperty location ){ if( location != null ){ getChild( childIndex ).setLocation( location ); } }
@SuppressWarnings("unchecked") public PredefinedLayout getLayout( DockElement element, Map<Dockable, Integer> children ) { if( shouldLayout( element )){ String factoryId = UNKNOWN + PredefinedDockSituation.super.getID( element ); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ) throw new IllegalStateException( "Missing factory: " + factoryId ); Object data = factory.getLayout( element, children ); DockLayout<Object> layout = new DockLayout<Object>( factoryId, data ); return new PredefinedLayout( elementToString.get( element ), new DockLayoutInfo( layout )); } else{ return new PredefinedLayout( elementToString.get( element ), new DockLayoutInfo() ); } }
/** * Updates the contents of the internal {@link DockLayoutInfo} using <code>factory</code> 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<Object>( factory.getID(), data ) ); } } catch( IOException e ){ // since a ByteArrayInputStream never throws an IOException this should never happen throw new IllegalStateException( e ); } }
if( info.getKind() == DockLayoutInfo.Data.BYTE ){ try{ DataInputStream in = new DataInputStream( new ByteArrayInputStream( info.getDataByte() )); String result = in.readUTF(); in.close(); if( info.getKind() == DockLayoutInfo.Data.XML ){ return info.getDataXML().getString( "factory" ); if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ return info.getDataLayout().getFactoryID();
@SuppressWarnings("unchecked") public void estimateLocations( PredefinedLayout layout, LocationEstimationMap children ){ DockLayoutInfo delegate = layout.getDelegate(); if( delegate.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ String factoryId = delegate.getDataLayout().getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory != null ){ factory.estimateLocations( delegate.getDataLayout().getData(), children ); } } }
DockLayoutInfo original = info; if( info.getKind() == DockLayoutInfo.Data.BYTE ){ info = readEntry( info.getDataByte(), info.getPlaceholder() ); if( info != null && info.getKind() == DockLayoutInfo.Data.BYTE ){ info = original; else if( info.getKind() == DockLayoutInfo.Data.XML ){ info = readEntry( info.getDataXML() ); if( info != null && info.getKind() == DockLayoutInfo.Data.XML ){ info = original; if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ info = fillMissing( info ); info.setLocation( original.getLocation() );
@Override public PlaceholderListItem<Dockable> convert( ConvertedPlaceholderListItem item ){ int id = item.getInt( "id" ); int index = item.getInt( "index" ); Path placeholder = null; if( item.contains( "placeholder" )){ placeholder = new Path( item.getString( "placeholder" ) ); } StackDockProperty property = new StackDockProperty( index, placeholder ); children.getChild( id ).setLocation( property ); for( int i = 0, n = children.getSubChildCount( id ); i<n; i++ ){ DockLayoutInfo info = children.getSubChild( id, i ); info.setLocation( new StackDockProperty( index, info.getPlaceholder() ) ); } return null; } });
DockLayout<?> layout = info.getDataLayout(); if( layout != null ){ MultipleCDockable match = setting.findMatch( layout ); if( match != null ){ DockLayout<?> newLayout = new DockLayout<MultipleCDockable>( REPLACEMENT_FACTORY_ID, match ); DockLayoutInfo newInfo = new DockLayoutInfo( newLayout ); newInfo.setLocation( info.getLocation() ); info = newInfo;
Path placeholder = info.getPlaceholder(); out.writeBoolean( placeholder != null ); if( placeholder != null ){ if( info.getKind() == DockLayoutInfo.Data.BYTE ){ out.write( info.getDataByte() ); else if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ DockLayout<?> layout = info.getDataLayout(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( layout.getFactoryID() ); if( factory == null )
@Override protected DockLayoutInfo fillMissing( DockLayoutInfo info ) { DockLayout<?> layout = info.getDataLayout(); if( KNOWN.equals( layout.getFactoryID() )){ PredefinedLayout preloaded = (PredefinedLayout)layout.getData(); DockLayoutInfo delegate = preloaded.getDelegate(); DockLayoutInfo newDelegate = null; if( delegate.getKind() == DockLayoutInfo.Data.BYTE ){ newDelegate = fillMissingStream( preloaded ); } else if( delegate.getKind() == DockLayoutInfo.Data.XML ){ newDelegate = fillMissingXML( preloaded ); } if( newDelegate != null ){ info = new DockLayoutInfo( new DockLayout<PredefinedLayout>( KNOWN, new PredefinedLayout( preloaded.getPredefined(), newDelegate ))); } } return info; }
@SuppressWarnings("unchecked") public void write( PredefinedLayout layout, DataOutputStream out ) throws IOException { Version.write( out, Version.VERSION_1_0_7 ); DockLayoutInfo info = layout.getDelegate(); out.writeUTF( layout.getPredefined() ); if( info.getKind() == DockLayoutInfo.Data.BYTE ){ out.writeBoolean( true ); out.write( info.getDataByte() ); } else if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ out.writeBoolean( true ); DockLayout delegate = info.getDataLayout(); String factoryId = delegate.getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ) throw new IOException( "Missing factory: " + factoryId ); out.writeUTF( factoryId ); factory.write( delegate.getData(), out ); } else if( info.getKind() == DockLayoutInfo.Data.NULL ){ out.writeBoolean( false ); } else{ throw new IllegalArgumentException( "Cannot store information as byte[], it is not present as raw byte[] or in an understandable format" ); } }
@SuppressWarnings("unchecked") public void write( PredefinedLayout layout, XElement element ) { element.addElement( "replacement" ).addString( "id", layout.getPredefined() ); DockLayoutInfo info = layout.getDelegate(); if( info.getKind() == DockLayoutInfo.Data.XML ){ element.addElement( info.getDataXML() ); } else if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ DockLayout<?> delegate = layout.getDelegate().getDataLayout(); String factoryId = delegate.getFactoryID(); DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ) throw new XException( "Missing factory: " + factoryId ); XElement xdelegate = element.addElement( "delegate" ); xdelegate.addString( "id", factoryId ); factory.write( delegate.getData(), xdelegate ); } else if( info.getKind() == DockLayoutInfo.Data.NULL ){ // nothing to store } else{ throw new IllegalArgumentException( "Cannot store information as xml, it is neither present as raw xml nor in an understandable format" ); } }
public void writeCompositionXML( DockLayoutComposition composition, XElement element ){ DockLayoutInfo info = composition.getLayout(); if( info.getKind() == DockLayoutInfo.Data.XML ){ element.addElement( info.getDataXML() ); else if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ DockLayout<?> layout = info.getDataLayout(); Path placeholder = info.getPlaceholder(); if( placeholder != null ){ xfactory.addString( "placeholder", placeholder.toString() );
/** * Creates a new info * @param data the data of this info */ public DockLayoutInfo( DockLayout<?> data ){ setData( data ); }
private void fillMissing( String root, DockLayoutComposition composition, DockFactory<?,?,?> factory, String factoryId ){ DockLayoutInfo info = composition.getLayout(); if( info.getKind() == DockLayoutInfo.Data.DOCK_LAYOUT ){ if( info.getDataLayout().getFactoryID().equals( factoryId )){ DockableProperty location = info.getLocation(); if( location != null ){ DockFactory<DockElement,?,Object> normalizedFactory = (DockFactory<DockElement,?,Object>)factory; if( missingDockable.shouldCreate( normalizedFactory, info.getDataLayout().getData() ) ){ DockElement element = normalizedFactory.layout( info.getDataLayout().getData(), layoutChangeStrategy.getPlaceholderStrategy( new Internals() ) ); if( element != null ){ Dockable dockable = element.asDockable();
info = new DockLayoutInfo( new DockLayout<Object>( factoryId, data )); info.setPlaceholder( placeholder ); info = new DockLayoutInfo( entry ); info.setPlaceholder( placeholder ); info = new DockLayoutInfo( new DockLayout<Object>( factoryId, data ) ); info.setPlaceholder( placeholder );
/** * Gets the layout information that was produced the {@link DockFactory} with id {@link #getFactoryId()}. * @return the layout information or <code>null</code> if not present in object format */ public DockLayout<?> getLayout(){ return layout.getDataLayout(); } }
private void appendFirstOnEstimate( DockLayoutComposition composition, DockableProperty location ){ DockLayoutInfo info = composition.getLayout(); DockableProperty property = info.getLocation(); if( property != null ){ info.setLocation( DockUtilities.append( property, location ) ); } for( DockLayoutComposition child : composition.getChildren() ){ appendFirstOnEstimate( child, location ); } }
/** * Tries to read the xml data in <code>layout</code>. * @param layout the layout to read * @return either a new info or <code>null</code> if the data could * not be read */ @SuppressWarnings("unchecked") private DockLayoutInfo fillMissingXML( PredefinedLayout layout ){ XElement xdelegate = layout.getDelegate().getDataXML(); String factoryId = xdelegate.getString( "id" ); Object delegate = null; DockFactory<DockElement,?,Object> factory = (DockFactory<DockElement,?,Object>)getFactory( factoryId ); if( factory == null ){ DockFactory<?,?,BackupFactoryData<?>> backup = getBackup( factoryId ); if( backup != null ){ BackupFactoryData<Object> data = (BackupFactoryData<Object>)backup.read( xdelegate, getPlaceholderStrategy() ); if( data != null ) delegate = data.getData(); } } else{ delegate = factory.read( xdelegate, getPlaceholderStrategy() ); } if( delegate == null ){ return null; } return new DockLayoutInfo( new DockLayout<Object>( factoryId, delegate ) ); }
byte[] bytes = layout.getDelegate().getDataByte(); BackupFactoryData<Object> data = (BackupFactoryData<Object>)backup.read( in, getPlaceholderStrategy() ); if( data != null && data.getData() != null ){ info = new DockLayoutInfo( new DockLayout<Object>( factoryId, data.getData() )); Object delegate = factory.read( in, getPlaceholderStrategy() ); if( delegate != null ){ info = new DockLayoutInfo( new DockLayout<Object>( factoryId, delegate ));