/** * Shows that <code>StyleConstants</code> attributes are converted to * corresponding <code>CSS.Attribute</code> ones. */ public void testAddAttributes() { simple.addAttribute(StyleConstants.FontSize, new Integer(10)); simple.addAttribute(StyleConstants.Alignment, new Integer(StyleConstants.ALIGN_CENTER)); attr = ss.addAttributes(empty, simple); assertEquals(2, attr.getAttributeCount()); Enumeration names = attr.getAttributeNames(); boolean hasSize = false; boolean hasAlign = false; while (names.hasMoreElements()) { Object name = names.nextElement(); hasSize |= name == Attribute.FONT_SIZE; hasAlign |= name == Attribute.TEXT_ALIGN; } assertTrue(hasSize); assertTrue(hasAlign); assertTrue(attr instanceof SmallAttributeSet); assertSame(SmallAttributeSet.class, attr.getClass().getSuperclass()); }
/** * Removes 1 attribute from a set, and the set is converted to * SmallAttributeSet * */ public void testRemoveAttributeCollapse() { AttributeSet as = StyleContextTest.addAttribute(10); assertTrue(as instanceof SimpleAttributeSet); as = sc.removeAttribute(as, StyleContextTest.attr[0]); assertEquals(9, as.getAttributeCount()); assertTrue(as instanceof SmallAttributeSet); }
/** * Removes the last attribute from a set. */ public void testRemoveAttributeFromOne() { AttributeSet as = StyleContextTest.addAttribute(1); as = sc.removeAttribute(as, StyleContextTest.attr[0]); assertEquals(0, as.getAttributeCount()); if (!BasicSwingTestCase.isHarmony()) { assertTrue(as instanceof SmallAttributeSet); } else { assertSame(as, sc.getEmptySet()); } }
/** * Removes one attribute from a set. The resulting set should become * SmallAttributeSet. */ public void testRemoveAttributesEnumSmall() { AttributeSet as = StyleContextTest.addAttribute(10); assertTrue(as instanceof SimpleAttributeSet); // Remove one element AttributeSet test = sc.removeAttributes(as, new AttributeNameEnumeration(1)); assertEquals(9, test.getAttributeCount()); if (BasicSwingTestCase.isHarmony()) { assertTrue(test instanceof SmallAttributeSet); } }
/** * Removes one attribute from a set. The resulting set should become * SmallAttributeSet. */ public void testRemoveAttributesSetSmall() { AttributeSet as = StyleContextTest.addAttribute(10); assertTrue(as instanceof SimpleAttributeSet); // Remove one element AttributeSet test = sc.removeAttributes(as, StyleContextTest.addAttribute(1)); assertEquals(9, test.getAttributeCount()); if (BasicSwingTestCase.isHarmony()) { assertTrue(test instanceof SmallAttributeSet); } }
public void testAddAttributesNine() { AttributeSet as1 = StyleContextTest.addAttribute(5); AttributeSet as2 = StyleContextTest.addAttribute(null, 5, 4); AttributeSet test = sc.addAttributes(as1, as2); assertEquals(9, test.getAttributeCount()); assertTrue(test instanceof SmallAttributeSet); }
public void testAddAttributesNineAndNine() { AttributeSet as1 = StyleContextTest.addAttribute(9); AttributeSet as2 = StyleContextTest.addAttribute(9); AttributeSet test = sc.addAttributes(as1, as2); assertEquals(9, test.getAttributeCount()); if (!BasicSwingTestCase.isHarmony()) { assertTrue(test instanceof SimpleAttributeSet); } else { assertTrue(test instanceof SmallAttributeSet); } }
public void testAddAttributesNineFull() { AttributeSet as1 = StyleContextTest.addAttribute(8); AttributeSet as2 = StyleContextTest.addAttribute(9); AttributeSet test = sc.addAttributes(as1, as2); assertEquals(9, test.getAttributeCount()); if (!BasicSwingTestCase.isHarmony()) { assertTrue(test instanceof SimpleAttributeSet); } else { assertTrue(test instanceof SmallAttributeSet); } }
public void testAddAttributesWithoutCache() { AttributeSet as1 = StyleContextTest.addAttribute(5); AttributeSet as2 = StyleContextTest.addAttribute(null, 5, 3); as2 = sc.addAttribute(as2, StyleConstants.LineSpacing, new Float(0.5)); AttributeSet test = sc.addAttributes(as1, as2); assertEquals(9, test.getAttributeCount()); assertTrue(test instanceof SmallAttributeSet); }
@Override public SmallAttributeSet createSmallAttributeSet(final AttributeSet a) { if (attrSet == null) { // This condition is true in StyleContext's constructor return super.createSmallAttributeSet(a); } attrSet[count] = super.createSmallAttributeSet(a); return (SmallAttributeSet) attrSet[count++]; }
@Override protected void setUp() throws Exception { super.setUp(); sc = new StyleContext(); attrSet = sc.new SmallAttributeSet(as); as = attrSet; asWithResolver = sc.new SmallAttributeSet(asWithResolver); }
/** * Add nine attributes into a set, and try to add the tenth one * which is already in the set. */ public void testAddAttributeNineSameValue() { AttributeSet as = StyleContextTest.addAttribute(9); as = sc.addAttribute(as, StyleConstants.Bold, Boolean.TRUE); assertEquals(9, as.getAttributeCount()); if (!BasicSwingTestCase.isHarmony()) { assertTrue(as instanceof SimpleAttributeSet); } else { assertTrue(as instanceof SmallAttributeSet); } }
/** * Add four attributes into a set, but one of them is used twice, * so the returned attribute set should contain only three ones. */ public void testAddAttributeThreeSameKey() { AttributeSet as = StyleContextTest.addAttribute(3); as = sc.addAttribute(as, StyleConstants.Bold, Boolean.FALSE); assertEquals(3, as.getAttributeCount()); assertTrue(as instanceof SmallAttributeSet); }
/** * Shows that <code>StyleConstants.FontSize</code> is converted to * <code>CSS.Attribute.FONT_SIZE</code>. */ public void testAddAttribute() { attr = ss.addAttribute(empty, StyleConstants.FontSize, new Integer(10)); Enumeration names = attr.getAttributeNames(); Object name = names.nextElement(); assertSame(Attribute.FONT_SIZE, name); assertFalse(names.hasMoreElements()); assertTrue(attr instanceof SmallAttributeSet); assertSame(SmallAttributeSet.class, attr.getClass().getSuperclass()); }
/** * Shows that attribute is stored <em>AS IS</em> if there's no * <code>CSS</code> equivalent to <code>StyleConstants</code> attribute. */ public void testAddAttributeNoCSS() { attr = ss.addAttribute(empty, StyleConstants.BidiLevel, new Integer(0)); assertEquals(1, attr.getAttributeCount()); Enumeration names = attr.getAttributeNames(); Object name = names.nextElement(); assertSame(StyleConstants.BidiLevel, name); assertFalse(names.hasMoreElements()); assertTrue(attr instanceof SmallAttributeSet); assertSame(SmallAttributeSet.class, attr.getClass().getSuperclass()); }
public void testCreateSmallAttributeSet() { final Object value = new Integer(12); simple.addAttribute(StyleConstants.FontSize, value); attr = ss.createSmallAttributeSet(simple); assertTrue(attr instanceof SmallAttributeSet); assertNotSame(SmallAttributeSet.class, attr.getClass()); assertEquals(1, attr.getAttributeCount()); assertSame(value, attr.getAttribute(StyleConstants.FontSize)); assertNull(attr.getAttribute(Attribute.FONT_SIZE)); }