/** * Iterate over the rules looking for a match based on the style sheet id. If found, we remove the old style sheet and * insert the new one in the same location. * * @param rule * @return true if the update happened. */ public boolean updateRule( final ElementStyleSheet rule ) { for ( int index = 0; index < getRuleCount(); index++ ) { final ElementStyleSheet styleDefinition = getRule( index ); if ( ( styleDefinition != null ) && ( styleDefinition.getId() == rule.getId() ) ) { removeRule( index ); addRule( index, rule ); return true; } } return false; }
@Test public void serialize_IntactSheet() throws Exception { ElementStyleSheet sheet = new ElementStyleSheet(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream( bos ); os.writeObject( sheet ); ObjectInputStream is = new ObjectInputStream( new ByteArrayInputStream( bos.toByteArray() ) ); ElementStyleSheet clone = (ElementStyleSheet) is.readObject(); assertNotSame( "IDs are generated each time", sheet.getId(), clone.getId() ); }
public void resolve( final ReportElement element, final ResolverStyleSheet resolverTarget ) { // add(element); resolverTarget.clear(); resolverTarget.setId( element.getStyle().getId() ); resolveParent( element, resolverTarget ); resolverTarget.addAll( element.getStyle() ); resolverTarget.addDefault( element.getDefaultStyleSheet() ); }
@Test public void derive_PreservingId() { List<StyleKey> keys = StyleKey.getDefinedStyleKeysList(); ElementStyleSheet sheet = new ElementStyleSheet(); setEverySecondKey( sheet, keys ); ElementStyleSheet clone = sheet.derive( true ); assertEquals( sheet.getId(), clone.getId() ); assertEverySecondKey( clone, keys ); }
@Test public void derive_DiscardingId() { List<StyleKey> keys = StyleKey.getDefinedStyleKeysList(); ElementStyleSheet sheet = new ElementStyleSheet(); setEverySecondKey( sheet, keys ); ElementStyleSheet clone = sheet.derive( false ); assertNotSame( sheet.getId(), clone.getId() ); assertEverySecondKey( clone, keys ); }
public void resolve( final ReportElement element, final ResolverStyleSheet resolverTarget ) { resolverTarget.clear(); resolverTarget.setId( element.getStyle().getId() ); // Stage 1a: Add the parent styles (but only the one marked as inheritable). // If our element has a parent, get the parent's style information // so we can "inherit" the styles that support that kind of thing simpleStyleResolver.resolveParent( element, resolverTarget ); // At this point, the parentStyle contains the "foundation" from which // the current element's style information will come.... // Stage 1b: Find all matching stylesheet styles for the given element. performSelectionStep( element, resolverTarget ); // Stage 2: Compute the 'specified' set of values. // Find all explicitly inherited styles and add them from the parent. // does not apply, we have no ability to specify an explicit INHERIT value. resolverTarget.addAll( element.getStyle() ); resolverTarget.addDefault( element.getDefaultStyleSheet() ); }