/** * Gets the placeholder that is used for the {@link MultipleCDockable} with * unique identifier <code>id</code>. * @param id the unique identifer of a {@link MultipleCDockable} * @return the placeholder for that dockable */ public static Path getMultipleDockablePlaceholder( String id ){ return new Path( "dock", "multi", id ); }
private boolean contains( Path[] placeholders ){ for( Path path : placeholders ){ if( path.equals( placeholder )){ return true; } } return false; } });
public void write( Path layout, DataOutputStream out ) throws IOException{ out.writeByte( 0 ); if( layout == null ){ out.writeBoolean( false ); } else{ out.writeBoolean( true ); out.writeUTF( layout.toString() ); } }
/** * Tells whether the first segments of this {@link Path} matches * the segments of <code>path</code>. * @param path some other path * @return <code>true</code> if this path is either equal to <code>path</code> or * if this path starts with <code>path</code> */ public boolean startsWith( Path path ){ if( path.getSegmentCount() > getSegmentCount() ){ return false; } for( int i = 0, n = path.getSegmentCount(); i<n; i++ ){ if( !path.getSegment( i ).equals( getSegment( i ) )){ return false; } } return true; }
public void delete( Path path, int segment ){ if( segment == path.getSegmentCount() ){ delete( false ); } else if( children != null ){ String check = path.getSegment( segment ); for( TreeNode child : children ){ if( check.equals( child.getPath().getLastSegment() )){ child.delete( path, segment+1 ); break; } } } }
@Override public void setPlaceholders( ToolbarContainerDockStation station, PlaceholderMap map ){ if( !map.getFormat().equals( new Path( "dock.ToolbarContainerStation" ) ) ) { throw new IllegalArgumentException( "unknown format: " + map.getFormat() ); } if( map.getVersion() != 0 ) { throw new IllegalArgumentException( "unknown version: " + map.getVersion() ); } station.setPlaceholders( map.getMap( map.newKey( "content" ), "list" ) ); }
public TreeNode getNode( Path path, int segment ){ if( segment == path.getSegmentCount() ) return this; if( children == null ){ children = new ArrayList<TreeNode>(); } String check = path.getSegment( segment ); for( TreeNode child : children ){ if( check.equals( child.getPath().getLastSegment() )){ return child.getNode( path, segment+1 ); } } TreeNode child = new TreeNode( this, path.subPath( 0, segment+1 ) ); children.add( child ); fireNodeAdded( this, child ); return child.getNode( path, segment+1 ); }
@Override public int hashCode(){ final int prime = 31; int result = 1; result = prime * result + ((modeIdentifier == null) ? 0 : modeIdentifier.hashCode()); return result; }
/** * Placeholder that marks the last position where this {@link PlaceholderGrouping} did store something. The default implementation * always returns {@link #getPlaceholder() placeholder + "last"}, but subclasses may change the behavior. * @return the last location where something interesting happened */ protected Path getLastPlaceholder(){ return placeholder.append( "last" ); }
/** * Creates a new preference. * @param type the type of value this preference uses * @param path a unique path for this preference, all paths starting with * "dock" are reserved for this framework */ public DefaultPreference( Path type, Path path ){ if( type == null ) throw new IllegalArgumentException( "type must not be null" ); if( path == null ) throw new IllegalArgumentException( "path must not be null" ); if( path.getSegmentCount() == 0 ) throw new IllegalArgumentException( "the root path is not a valid path for a preference" ); this.type = type; this.path = path; }
/** * Gets the factory that creates bridges for <code>kind</code>. * @param kind some identifier for a type * @return the factory whose kind best matches <code>kind</code> or <code>null</code> */ public ColorBridgeFactory getBridgeFactory( Path kind ) { while( kind != null ){ ColorBridgeFactory factory = bridges.get( kind ); if( factory != null ) return factory; kind = kind.getParent(); } return null; } }
/** * Creates a new type. * @param key the key of this type, must not be <code>null</code>, must at least contain * one character, must not contain the character ".", must pass {@link Path#isValidPath(String)} */ public Type( String key ){ if( key == null ){ throw new IllegalArgumentException( "key must not be null" ); } if( key.length() == 0 ){ throw new IllegalArgumentException( "key must contain at least one character" ); } if( key.contains( "." )){ throw new IllegalArgumentException( "key must not contain the character '.'" ); } if( !Path.isValidPath( key )){ throw new IllegalArgumentException( "key not a valid path" ); } this.key = key; }
private Node getNode( Path path, boolean create, int segment ){ if( path.getSegmentCount() == segment ) return this; if( children == null ){ children = new ArrayList<Node>(); } String name = path.getSegment( segment ); for( Node child : children ){ if( name.equals( child.getName() )){ return child.getNode( path, create, segment+1 ); } } if( !create ) return null; Node result = new Node( name ); children.add( result ); return result.getNode( path, create, segment+1 ); } }
@Override public int hashCode(){ final int prime = 31; int result = 1; result = prime * result + ((modeIdentifier == null) ? 0 : modeIdentifier.hashCode()); return result; }
public Path combine( Path first, Path second ) { return first.append( second ); } };
/** * Adds a new factory to this storage, the factory will be responsible to * write or read some kind of preferences. If there is already a factory * for <code>type</code>, then the old factory will be replaced by * <code>factory</code> * @param type the type of values <code>factory</code> handles, this path * is most times just the name of some class. Node: there is a set of * standard paths defined in {@link Path} * @param factory the new factory */ public void addFactory( Path type, PreferenceFactory<?> factory ){ if( type == null ) throw new IllegalArgumentException( "type must not be null" ); if( factory == null ) throw new IllegalArgumentException( "factory must not be null" ); if( type.getSegmentCount() == 0 ) throw new IllegalArgumentException( "the root path is not a valid path for this metho" ); factories.put( type, factory ); }
/** * Searches a bridge that can be used for <code>path</code>. * @param path the kind of bridge that is searched. First a bridge for * <code>path</code> will be searched, then for the parent of <code>path</code>, * and so on... * @return the bridge or <code>null</code> */ protected B getBridgeFor( Path path ){ while( path != null ){ UIPriorityValue<B> bridge = bridges.get( path ); if( bridge == null ){ bridge = createBridge( path ); if( !isRemoveable( path, bridge )){ bridges.put( path, bridge ); } } if( bridge != null ){ B result = bridge.getValue(); if( result != null ) return result; } path = path.getParent(); } return null; }
/** * Creates a new type. * @param key the key of this type, must not be <code>null</code>, must at least contain * one character, must not contain the character ".", must pass {@link Path#isValidPath(String)} */ public Type( String key ){ if( key == null ){ throw new IllegalArgumentException( "key must not be null" ); } if( key.length() == 0 ){ throw new IllegalArgumentException( "key must contain at least one character" ); } if( key.contains( "." )){ throw new IllegalArgumentException( "key must not contain the character '.'" ); } if( !Path.isValidPath( key )){ throw new IllegalArgumentException( "key not a valid path" ); } this.key = key; }