public static void writeRotationStyles( final XmlWriter writer, final ElementStyleSheet style ) throws IOException { if ( writer == null ) { throw new NullPointerException(); } if ( style == null ) { throw new NullPointerException(); } final AttributeList bandStyleAtts = new AttributeList(); if ( style.isLocalKey( TextStyleKeys.TEXT_ROTATION ) ) { final Object value = style.getStyleProperty( TextStyleKeys.TEXT_ROTATION ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "rotation", value.toString() ); } if ( bandStyleAtts.isEmpty() == false ) { writer.writeTag( BundleNamespaces.STYLE, "rotation-styles", bandStyleAtts, XmlWriterSupport.CLOSE ); } } }
if ( style.isLocalKey( BandStyleKeys.REPEAT_HEADER ) ) { final boolean value = style.getBooleanStyleProperty( BandStyleKeys.REPEAT_HEADER ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "repeat", String.valueOf( value ) ); if ( style.isLocalKey( BandStyleKeys.DISPLAY_ON_FIRSTPAGE ) ) { final boolean value = style.getBooleanStyleProperty( BandStyleKeys.DISPLAY_ON_FIRSTPAGE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "display-on-first-page", String.valueOf( value ) ); if ( style.isLocalKey( BandStyleKeys.DISPLAY_ON_LASTPAGE ) ) { final boolean value = style.getBooleanStyleProperty( BandStyleKeys.DISPLAY_ON_LASTPAGE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "display-on-last-page", String.valueOf( value ) ); if ( style.isLocalKey( BandStyleKeys.STICKY ) ) { final boolean value = style.getBooleanStyleProperty( BandStyleKeys.STICKY ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "sticky", String.valueOf( value ) ); if ( style.isLocalKey( BandStyleKeys.FIXED_POSITION ) ) { final double value = style.getDoubleStyleProperty( BandStyleKeys.FIXED_POSITION, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "fixed-position", formatLength( value ) );
if ( style.isLocalKey( BandStyleKeys.COMPUTED_SHEETNAME ) ) { final String value = (String) style.getStyleProperty( BandStyleKeys.COMPUTED_SHEETNAME ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "computed-sheetname", value ); if ( style.isLocalKey( BandStyleKeys.BOOKMARK ) ) { final String value = (String) style.getStyleProperty( BandStyleKeys.BOOKMARK ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "bookmark", value ); if ( style.isLocalKey( BandStyleKeys.PAGEBREAK_BEFORE ) ) { final boolean value = style.getBooleanStyleProperty( BandStyleKeys.PAGEBREAK_BEFORE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "pagebreak-before", String.valueOf( value ) ); if ( style.isLocalKey( BandStyleKeys.PAGEBREAK_AFTER ) ) { final boolean value = style.getBooleanStyleProperty( BandStyleKeys.PAGEBREAK_AFTER ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "pagebreak-after", String.valueOf( value ) ); if ( style.isLocalKey( BandStyleKeys.LAYOUT ) ) { final String value = (String) style.getStyleProperty( BandStyleKeys.LAYOUT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "layout", String.valueOf( value ) ); if ( style.isLocalKey( BandStyleKeys.TABLE_LAYOUT ) ) { try { final TableLayout value = (TableLayout) style.getStyleProperty( BandStyleKeys.TABLE_LAYOUT );
if ( style.isLocalKey( TextStyleKeys.FONT ) ) { final String value = (String) style.getStyleProperty( TextStyleKeys.FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "font-face", value ); if ( style.isLocalKey( TextStyleKeys.BOLD ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.BOLD ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "bold", String.valueOf( value ) ); if ( style.isLocalKey( TextStyleKeys.ITALIC ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.ITALIC ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "italic", String.valueOf( value ) ); if ( style.isLocalKey( TextStyleKeys.EMBEDDED_FONT ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.EMBEDDED_FONT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "embedded", String.valueOf( value ) ); if ( style.isLocalKey( TextStyleKeys.UNDERLINED ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.UNDERLINED ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "underline", String.valueOf( value ) ); if ( style.isLocalKey( TextStyleKeys.STRIKETHROUGH ) ) { final boolean value = style.getBooleanStyleProperty( TextStyleKeys.STRIKETHROUGH ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "strikethrough", String.valueOf( value ) ); if ( style.isLocalKey( ElementStyleKeys.EXCEL_WRAP_TEXT ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.EXCEL_WRAP_TEXT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "excel-text-wrapping", String.valueOf( value ) ); if ( style.isLocalKey( ElementStyleKeys.EXCEL_INDENTION ) ) {
if ( style.isLocalKey( ElementStyleKeys.DRAW_SHAPE ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.DRAW_SHAPE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "draw-shape", String.valueOf( value ) ); if ( style.isLocalKey( ElementStyleKeys.FILL_SHAPE ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.FILL_SHAPE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "fill-shape", String.valueOf( value ) ); if ( style.isLocalKey( ElementStyleKeys.SCALE ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.SCALE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "scale", String.valueOf( value ) ); if ( style.isLocalKey( ElementStyleKeys.KEEP_ASPECT_RATIO ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.KEEP_ASPECT_RATIO ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "keep-aspect-ratio", String.valueOf( value ) ); if ( style.isLocalKey( ElementStyleKeys.DYNAMIC_HEIGHT ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.DYNAMIC_HEIGHT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "dynamic-height", String.valueOf( value ) ); if ( style.isLocalKey( ElementStyleKeys.PAINT ) ) { final Color value = (Color) style.getStyleProperty( ElementStyleKeys.PAINT ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "color", ColorValueConverter.colorToString( value ) ); if ( style.isLocalKey( ElementStyleKeys.FILL_COLOR ) ) { final Color value = (Color) style.getStyleProperty( ElementStyleKeys.FILL_COLOR ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "fill-color", ColorValueConverter.colorToString( value ) ); if ( style.isLocalKey( ElementStyleKeys.EXCEL_DATA_FORMAT_STRING ) ) {
if ( style.isLocalKey( ElementStyleKeys.POS_X ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.POS_X, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "x", formatLength( value ) ); if ( style.isLocalKey( ElementStyleKeys.POS_Y ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.POS_Y, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "y", formatLength( value ) ); if ( style.isLocalKey( ElementStyleKeys.MIN_WIDTH ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.MIN_WIDTH, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "min-width", formatLength( value ) ); if ( style.isLocalKey( ElementStyleKeys.MIN_HEIGHT ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.MIN_HEIGHT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "min-height", formatLength( value ) ); if ( style.isLocalKey( ElementStyleKeys.WIDTH ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.WIDTH, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "width", formatLength( value ) ); if ( style.isLocalKey( ElementStyleKeys.HEIGHT ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.HEIGHT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "height", formatLength( value ) ); if ( style.isLocalKey( ElementStyleKeys.MAX_WIDTH ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.MAX_WIDTH, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "max-width", formatLength( value ) ); if ( style.isLocalKey( ElementStyleKeys.MAX_HEIGHT ) ) {
if ( style.isLocalKey( ElementStyleKeys.ANCHOR_NAME ) ) { final String value = (String) style.getStyleProperty( ElementStyleKeys.ANCHOR_NAME ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "anchor-name", value ); if ( style.isLocalKey( ElementStyleKeys.HREF_TARGET ) ) { final String value = (String) style.getStyleProperty( ElementStyleKeys.HREF_TARGET ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "href-target", value ); if ( style.isLocalKey( ElementStyleKeys.HREF_TITLE ) ) { final String value = (String) style.getStyleProperty( ElementStyleKeys.HREF_TITLE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "href-title", value ); if ( style.isLocalKey( ElementStyleKeys.HREF_WINDOW ) ) { final String value = (String) style.getStyleProperty( ElementStyleKeys.HREF_WINDOW ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "href-window", value ); if ( style.isLocalKey( ElementStyleKeys.BOX_SIZING ) ) { final BoxSizing value = (BoxSizing) style.getStyleProperty( ElementStyleKeys.BOX_SIZING ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "box-sizing", value.toString() ); if ( style.isLocalKey( ElementStyleKeys.VISIBLE ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.VISIBLE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "visible", String.valueOf( value ) ); if ( style.isLocalKey( ElementStyleKeys.INVISIBLE_CONSUMES_SPACE ) ) { final boolean value = style.getBooleanStyleProperty( ElementStyleKeys.INVISIBLE_CONSUMES_SPACE ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "invisible-consumes-space", String.valueOf( value ) ); if ( style.isLocalKey( ElementStyleKeys.WIDOWS ) ) {
@Test public void isLocalKey_KeyIsTreatedAsLocal_AfterBeingSetExplicitly() { List<StyleKey> keys = StyleKey.getDefinedStyleKeysList(); StyleKey key1 = keys.get( 0 ); StyleKey key2 = keys.get( 1 ); ElementStyleSheet sheet = new ElementStyleSheet(); sheet.setStyleProperty( key1, valueFor( key1 ) ); assertTrue( "First key was set, should be 'local'", sheet.isLocalKey( key1 ) ); assertFalse( "Second key was not set, should not be 'local'", sheet.isLocalKey( key2 ) ); }
public void setStyleProperty( final StyleKey key, final Object value ) { final long l = getChangeTracker(); final Object oldValue; if ( super.isLocalKey( key ) ) { oldValue = super.getStyleProperty( key ); } else { oldValue = null; } super.setStyleProperty( key, value ); if ( l != getChangeTracker() ) { element.notifyNodePropertiesChanged( new StyleChange( key, oldValue, value ) ); } } }
@Test public void isLocalKey_OnIntactSheet() { List<StyleKey> keys = StyleKey.getDefinedStyleKeysList(); StyleKey key = keys.get( 0 ); ElementStyleSheet sheet = new ElementStyleSheet(); assertFalse( "Non-changed sheet has no 'local' keys", sheet.isLocalKey( key ) ); }
if ( style.isLocalKey( ElementStyleKeys.BACKGROUND_COLOR ) ) { final Color value = (Color) style.getStyleProperty( ElementStyleKeys.BACKGROUND_COLOR ); bandStyleAtts if ( style.isLocalKey( ElementStyleKeys.PADDING_TOP ) && style.isLocalKey( ElementStyleKeys.PADDING_LEFT ) && style.isLocalKey( ElementStyleKeys.PADDING_BOTTOM ) && style.isLocalKey( ElementStyleKeys.PADDING_RIGHT ) ) { final double paddingTop = style.getDoubleStyleProperty( ElementStyleKeys.PADDING_TOP, 0 ); final double paddingLeft = style.getDoubleStyleProperty( ElementStyleKeys.PADDING_LEFT, 0 ); if ( style.isLocalKey( ElementStyleKeys.PADDING_TOP ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.PADDING_TOP, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "padding-top", absoluteLengthFormat.format( value ) ); if ( style.isLocalKey( ElementStyleKeys.PADDING_LEFT ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.PADDING_LEFT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "padding-left", absoluteLengthFormat.format( value ) ); if ( style.isLocalKey( ElementStyleKeys.PADDING_BOTTOM ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.PADDING_BOTTOM, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "padding-bottom", absoluteLengthFormat.format( value ) ); if ( style.isLocalKey( ElementStyleKeys.PADDING_RIGHT ) ) { final double value = style.getDoubleStyleProperty( ElementStyleKeys.PADDING_RIGHT, 0 ); bandStyleAtts.setAttribute( BundleNamespaces.STYLE, "padding-right", absoluteLengthFormat.format( value ) ); if ( style.isLocalKey( ElementStyleKeys.BORDER_TOP_WIDTH ) && style.isLocalKey( ElementStyleKeys.BORDER_LEFT_WIDTH ) && style.isLocalKey( ElementStyleKeys.BORDER_BOTTOM_WIDTH ) && style.isLocalKey( ElementStyleKeys.BORDER_RIGHT_WIDTH ) ) { final double top = style.getDoubleStyleProperty( ElementStyleKeys.BORDER_TOP_WIDTH, 0 );
@Test public void isLocalKey_ReturnsFalse_OnUnknownIdentifier() throws Exception { List<StyleKey> before = StyleKey.getDefinedStyleKeysList(); StyleKey key = before.get( 0 ); ElementStyleSheet sheet = new ElementStyleSheet(); sheet.setStyleProperty( key, valueFor( key ) ); final String keyName = "testKey_isLocalKey_ReturnsFalse_OnUnknownIdentifier"; //noinspection deprecation StyleKey syntheticKey = StyleKey.addTestKey( keyName, String.class, false, false ); testKeys.add( syntheticKey ); List<StyleKey> after = StyleKey.getDefinedStyleKeysList(); assertEquals( "The test syntheticKey should have been added", before.size() + 1, after.size() ); assertFalse( "Unknown keys are ignored", sheet.isLocalKey( syntheticKey ) ); }
@Test public void addAll() { List<StyleKey> keys = StyleKey.getDefinedStyleKeysList(); ElementStyleSheet sheet = new ElementStyleSheet(); setEverySecondKey( sheet, keys ); ElementStyleSheet another = new ElementStyleSheet(); another.addAll( sheet ); assertEverySecondKey( another, keys ); for ( int i = 0; i < keys.size(); i += 2 ) { StyleKey key = keys.get( i ); assertTrue( "addAll() adds properties as local", another.isLocalKey( key ) ); } }
@Test public void addInherited_ElementSheet() { List<StyleKey> keys = StyleKey.getDefinedStyleKeysList(); ElementStyleSheet sheet = new ElementStyleSheet(); setEveryInheritableKey( sheet, keys ); ElementStyleSheet another = new ElementStyleSheet(); another.addInherited( sheet ); for ( int i = 0; i < keys.size(); i++ ) { StyleKey key = keys.get( i ); if ( key.isInheritable() ) { Object property = another.getStyleProperty( key ); assertEquals( String.format( "Key[%d]: %s", i, key.name ), defaultValues.get( key.getValueType() ), property ); assertFalse( "addInherited() doesn't add properties as local", another.isLocalKey( key ) ); } } }
private void testAmountMod4IsN( int n ) { final int toAdd = 4 - ( defaultKeysAmount % 4 ) + n; for ( int i = 0; i < toAdd; i++ ) { //noinspection deprecation StyleKey syntheticKey = StyleKey.addTestKey( "syntheticKey_" + i, String.class, false, false ); testKeys.add( syntheticKey ); } assertEquals( "Default key list's size % 4 should be equal " + ( n % 4 ), n % 4, StyleKey.getDefinedStyleKeysList().size() % 4 ); ElementStyleSheet sheet = new ElementStyleSheet(); for ( StyleKey key : testKeys ) { sheet.setStyleProperty( key, key.name ); } for ( StyleKey key : testKeys ) { assertEquals( key.name, sheet.getStyleProperty( key ) ); assertTrue( sheet.isLocalKey( key ) ); } } }
@Test public void addInherited_SimpleSheet() { List<StyleKey> keys = StyleKey.getDefinedStyleKeysList(); ElementStyleSheet sheet = new ElementStyleSheet(); setEveryInheritableKey( sheet, keys ); SimpleStyleSheet simpleStyleSheet = new SimpleStyleSheet( new ElementStyleSheet() ); sheet.addInherited( simpleStyleSheet ); for ( int i = 0; i < keys.size(); i++ ) { StyleKey key = keys.get( i ); if ( key.isInheritable() ) { Object property = sheet.getStyleProperty( key ); assertNull( "Previous values should be overriden", property ); assertFalse( "addInherited() doesn't add properties as local", sheet.isLocalKey( key ) ); } } }
@Test public void setStyleProperty_NullValuesAreTreatedAsAbsent() { List<StyleKey> keys = StyleKey.getDefinedStyleKeysList(); StyleKey key = keys.get( 0 ); ElementStyleSheet sheet = new ElementStyleSheet(); sheet.setStyleProperty( key, valueFor( key ) ); sheet.setStyleProperty( key, null ); assertEquals( valueFor( key ), sheet.getStyleProperty( key, valueFor( key ) ) ); assertFalse( sheet.isLocalKey( key ) ); }
@Test public void copyFrom_OnChangedSheet() { List<StyleKey> keys = StyleKey.getDefinedStyleKeysList(); ElementStyleSheet sheet = new ElementStyleSheet(); setEverySecondKey( sheet, keys ); ElementStyleSheet another = new ElementStyleSheet(); another.copyFrom( sheet ); assertEquals( sheet.getModificationCount(), another.getModificationCount() ); assertEquals( sheet.getChangeTrackerHash(), another.getChangeTrackerHash() ); assertEverySecondKey( another, keys ); for ( int i = 0; i < keys.size(); i += 2 ) { StyleKey key = keys.get( i ); assertTrue( another.isLocalKey( key ) ); } }
@Test public void clone_DiscardsCacheEntries() { StyleKey key = null; List<StyleKey> keysList = StyleKey.getDefinedStyleKeysList(); for ( StyleKey styleKey : keysList ) { if ( styleKey.isInheritable() ) { key = styleKey; break; } } assumeFalse( key == null ); ElementStyleSheet parent = new ElementStyleSheet(); parent.setStyleProperty( key, valueFor( key ) ); ElementStyleSheet sheet = new ElementStyleSheet(); sheet.addInherited( parent ); assertEquals( valueFor( key ), sheet.getStyleProperty( key ) ); assertFalse( "Cached key should not be marked as local", sheet.isLocalKey( key ) ); ElementStyleSheet clone = sheet.clone(); assertNull( clone.getStyleProperty( key ) ); }