PageRenderTime 59ms CodeModel.GetById 43ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/org/mt4j/test/css/SelectorIntegrationTest.java

http://mt4j.googlecode.com/
Java | 149 lines | 100 code | 36 blank | 13 comment | 4 complexity | 3ac272c5e0fb30fccc0aa166eb3f1666 MD5 | raw file
  1package org.mt4j.test.css;
  2
  3import java.util.List;
  4
  5import org.junit.Test;
  6import org.mt4j.MTApplication;
  7import org.mt4j.components.MTCanvas;
  8import org.mt4j.components.MTComponent;
  9import org.mt4j.components.TransformSpace;
 10import org.mt4j.components.css.parser.CSSParserConnection;
 11import org.mt4j.components.css.style.CSSStyle;
 12import org.mt4j.components.visibleComponents.shapes.MTEllipse;
 13import org.mt4j.components.visibleComponents.shapes.MTLine;
 14import org.mt4j.components.visibleComponents.shapes.MTRectangle;
 15import org.mt4j.components.visibleComponents.widgets.MTTextArea;
 16import org.mt4j.sceneManagement.Iscene;
 17import org.mt4j.test.AbstractWindowTestcase;
 18import org.mt4j.test.testUtil.DummyScene;
 19import org.mt4j.test.testUtil.TestRunnable;
 20import org.mt4j.util.MTColor;
 21import org.mt4j.util.math.Vector3D;
 22
 23
 24
 25public class SelectorIntegrationTest extends AbstractWindowTestcase {
 26	private MTComponent parent;
 27	private MTApplication app;
 28	private Iscene scene;
 29	CSSParserConnection pc;
 30	List<CSSStyle> styles;
 31	MTColor w = new MTColor(255,255,255,255);
 32	
 33	@Override
 34	public void inStartUp(MTApplication app) {
 35		this.app = app;
 36		//Add a scene to the mt application
 37		this.scene = new DummyScene(app, "Dummy Scene");
 38		app.addScene(scene);
 39		
 40		//Set up components
 41		parent = new MTComponent(app);
 42		getCanvas().addChild(parent);
 43		
 44		app.getCssStyleManager().loadStyles("junit/integrationtest.css");
 45		app.getCssStyleManager().setGloballyEnabled(true);
 46	}
 47	
 48	public MTCanvas getCanvas(){
 49		return this.scene.getCanvas();
 50	}
 51	
 52
 53	
 54	@Test
 55	public void testDirectStyleSheets() {
 56		MTRectangle r = new MTRectangle(app,0,0,100, 100);
 57		//r.enableCSS();
 58		getCanvas().addChild(r);
 59		assertTrue(r.getFillColor().equals(MTColor.GREEN));
 60	}
 61	
 62	@Test
 63	public void testClassSelector() {
 64		MTEllipse e = new MTEllipse(app, new Vector3D(500,500), 50, 50);
 65		//e.enableCSS();
 66		getCanvas().addChild(e);
 67		assertTrue(e.getFillColor().equals(MTColor.WHITE));
 68	}
 69	
 70	@Test
 71	public void testUniversalSelector() {
 72		MTLine l = new MTLine(app, 100,100, 200,200);
 73		//l.enableCSS();
 74		getCanvas().addChild(l);
 75		MTEllipse e = new MTEllipse(app, new Vector3D(500,500), 50, 50);
 76		//e.enableCSS();
 77		getCanvas().addChild(e);
 78		assertTrue(l.getStrokeColor().equals(MTColor.BLUE));
 79		assertTrue(e.getStrokeColor().equals(MTColor.BLUE));
 80	}
 81	
 82	
 83	@Test
 84	public void testCascadingSelectors() {
 85		this.runTest(new TestRunnable() {
 86			@Override
 87			public void runMTTestCode() {
 88				MTRectangle r1 = new MTRectangle(app,100,100,100, 100);
 89				MTRectangle r2 = new MTRectangle(app,100,100,100, 100);
 90				MTRectangle r3 = new MTRectangle(app,100,100,100, 100);
 91				//r1.enableCSS(); r2.enableCSS(); r3.enableCSS();
 92				
 93				MTEllipse e = new MTEllipse(app, new Vector3D(200,200), 50,50);
 94				//e.enableCSS();
 95				
 96				
 97				MTTextArea ta = new MTTextArea(app);
 98				MTTextArea t2 = new MTTextArea(app);
 99				
100				//ta.enableCSS(); t2.enableCSS();
101				
102				getCanvas().addChild(r1);
103				getCanvas().addChild(r2);
104				
105				r1.addChild(ta);
106				r2.addChild(e);
107				e.addChild(r3);
108				e.addChild(t2);
109
110				//ta.applyStyleSheet();
111
112				//t2.applyStyleSheet();
113
114				//r3.applyStyleSheet();
115				
116				assertTrue(ta.getFillColor().equals(MTColor.LIME));
117				assertTrue(r3.getFillColor().equals(MTColor.GREY));
118				assertTrue(t2.getFillColor().equals(MTColor.BLUE));
119			}
120		});
121			
122		
123	}
124	
125	@Test
126	public void testSizes() {
127		MTRectangle r1 = new MTRectangle(app,100,100,100, 100);
128		MTRectangle r2 = new MTRectangle(app,100,100,100, 100);
129		MTRectangle r3 = new MTRectangle(app,100,100,100, 100);
130		//r1.enableCSS(); r2.enableCSS(); r3.enableCSS();
131		
132		r1.setCSSID("widthtest");
133		r2.setCSSID("heighttest");
134		r3.setCSSID("sizetest");
135		
136		getCanvas().addChild(r1);
137		getCanvas().addChild(r2);
138		getCanvas().addChild(r3);
139
140		assertTrue(r1.getWidthXY(TransformSpace.RELATIVE_TO_PARENT) == 90f);
141		assertTrue(r2.getHeightXY(TransformSpace.RELATIVE_TO_PARENT) == 110f);
142		
143		
144		assertTrue(r3.getWidthXY(TransformSpace.RELATIVE_TO_PARENT) == 120f);
145		assertTrue(r3.getHeightXY(TransformSpace.RELATIVE_TO_PARENT) == 450f);
146	}
147	
148
149}