Index: src/test/api/java/common/javax/swing/plaf/synth/ColorTypeTest.java =================================================================== --- src/test/api/java/common/javax/swing/plaf/synth/ColorTypeTest.java (revision 0) +++ src/test/api/java/common/javax/swing/plaf/synth/ColorTypeTest.java (revision 0) @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import junit.framework.TestCase; + +public class ColorTypeTest extends TestCase { + + private final static String NAME_1 = "test1"; //$NON-NLS-1$ + + private final static String NAME_2 = "test2"; //$NON-NLS-1$ + + public static void testColorTypes() { + assertNotSame(ColorType.BACKGROUND, ColorType.FOREGROUND); + + ColorType testCT = new ColorType(NAME_1) { + // Empty class - all is inherited + }; + + ColorType testCT2 = new ColorType(NAME_2) { + // Empty class - all is inherited + }; + assertEquals(NAME_1, testCT.toString()); + assertEquals(NAME_2, testCT2.toString()); + assertFalse(ColorType.BACKGROUND.getID() == testCT.getID()); + assertFalse(testCT2.getID() == testCT.getID()); + assertTrue(testCT.getID() == testCT.getID()); + assertSame(ColorType.calculateColorType("BACKGROUND"), //$NON-NLS-1$ + ColorType.BACKGROUND); + assertSame(ColorType.calculateColorType("FOREGROUND"), //$NON-NLS-1$ + ColorType.FOREGROUND); + assertSame(ColorType.calculateColorType("FOCUS"), ColorType.FOCUS); //$NON-NLS-1$ + assertSame(ColorType.calculateColorType("TEXT_BACKGROUND"), //$NON-NLS-1$ + ColorType.TEXT_BACKGROUND); + assertSame(ColorType.calculateColorType("TEXT_FOREGROUND"), //$NON-NLS-1$ + ColorType.TEXT_FOREGROUND); + + } +} Index: src/test/api/java/common/javax/swing/plaf/synth/RegionTest.java =================================================================== --- src/test/api/java/common/javax/swing/plaf/synth/RegionTest.java (revision 0) +++ src/test/api/java/common/javax/swing/plaf/synth/RegionTest.java (revision 0) @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import junit.framework.TestCase; + +public class RegionTest extends TestCase { + + private static final String NAME = "test"; //$NON-NLS-1$ + + private static final String UI = "testUI"; //$NON-NLS-1$ + + private static final Region r = new Region(NAME, UI, false); + + public static void testFields() { + assertEquals(NAME, r.getName()); + assertFalse(r.isSubregion()); + } + + public static void testRegionLookupMethods() { + assertSame(r, Region.getRegionFromName(NAME)); + assertSame(r, Region.getRegionFromUIID(UI)); + } +} Index: src/test/api/java/common/javax/swing/plaf/synth/SynthStyleTest.java =================================================================== --- src/test/api/java/common/javax/swing/plaf/synth/SynthStyleTest.java (revision 0) +++ src/test/api/java/common/javax/swing/plaf/synth/SynthStyleTest.java (revision 0) @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Insets; + +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; + +import junit.framework.TestCase; + +public class SynthStyleTest extends TestCase { + + static final String ICON_KEY = "TestIcon"; //$NON-NLS-1$ + + static final String STRING_KEY = "TestString"; //$NON-NLS-1$ + + static final String INT_KEY = "TestInteger"; //$NON-NLS-1$ + + static final String BOOLEAN_KEY = "TestBoolean"; //$NON-NLS-1$ + + static final Icon ICON_VALUE = new ImageIcon("test"); //$NON-NLS-1$ + + static final String STRING_VALUE = "test"; //$NON-NLS-1$ + + @SuppressWarnings("boxing") + static final Integer INT_VALUE = Integer.MAX_VALUE; //$NON-NLS-1$ + + @SuppressWarnings("boxing") + static final Boolean BOOLEAN_VALUE = true; //$NON-NLS-1$ + + static final Color COLOR_VALUE = Color.GREEN; + + static final Font FONT_VALUE = new Font("Times", Font.BOLD, 15); //$NON-NLS-1$ + + private static JLabel currentComponent = new JLabel("Test_component"); //$NON-NLS-1$ + + private static SynthStyle currentStyle = new SynthStyleForTest(); + + private static SynthContext currentContext = new SynthContext( + currentComponent, Region.LABEL, currentStyle, + SynthConstants.ENABLED); + + /* + * Test method for 'javax.swing.plaf.synth.SynthStyle.get(SynthContext, + * Object)' + */ + public void testGet() { + assertEquals(currentStyle.get(currentContext, ICON_KEY), ICON_VALUE); + assertEquals(currentStyle.get(currentContext, INT_KEY), INT_VALUE); + assertEquals(currentStyle.get(currentContext, STRING_KEY), STRING_VALUE); + assertEquals(currentStyle.get(currentContext, BOOLEAN_KEY), + BOOLEAN_VALUE); + } + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthStyle.getBoolean(SynthContext, Object, + * boolean)' + */ + public void testGetBoolean() { + assertTrue(currentStyle.getBoolean(currentContext, BOOLEAN_KEY, true)); + assertTrue(currentStyle.getBoolean(currentContext, BOOLEAN_KEY, false)); + assertTrue(currentStyle.getBoolean(currentContext, + "Not_found_boolean", true)); //$NON-NLS-1$ + assertFalse(currentStyle.getBoolean(currentContext, + "Not_found_boolean", false)); //$NON-NLS-1$ + } + + /* + * Test method for 'javax.swing.plaf.synth.SynthStyle.getColor(SynthContext, + * ColorType)' + */ + public void testGetColor() { + currentComponent.setBackground(Color.RED); + assertEquals(currentStyle + .getColor(currentContext, ColorType.BACKGROUND), Color.RED); + } + + /* + * Test method for 'javax.swing.plaf.synth.SynthStyle.getFont(SynthContext)' + */ + public void testGetFont() { + Font newFont = new Font("Dialog", Font.BOLD, 15); //$NON-NLS-1$ + currentComponent.setFont(newFont); + assertEquals(currentStyle.getFont(currentContext), newFont); + } + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthStyle.getInsets(SynthContext, Insets)' + */ + public void testGetInsets() { + Insets insets = new Insets(1, 2, 3, 4); + currentStyle.getInsets(currentContext, insets); + assertTrue((insets.top == 0) && (insets.left == 0) + && (insets.right == 0) && (insets.bottom == 0)); + } + + /* + * Test method for 'javax.swing.plaf.synth.SynthStyle.getInt(SynthContext, + * Object, int)' + */ + @SuppressWarnings("boxing") + public void testGetInt() { + assertTrue(currentStyle.getInt(currentContext, INT_KEY, INT_VALUE - 1) == INT_VALUE); + assertTrue(currentStyle.getInt(currentContext, + "KEY_NOT_FOUND", INT_VALUE - 1) == INT_VALUE - 1); //$NON-NLS-1$ + } + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthStyle.getString(SynthContext, Object, + * String)' + */ + public void testGetString() { + String anotherString = "KEY_NOT_FOUND"; //$NON-NLS-1$ + assertEquals(currentStyle.getString(currentContext, STRING_KEY, + anotherString), STRING_VALUE); + assertEquals(currentStyle.getString(currentContext, anotherString, + anotherString), anotherString); + } + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthStyle.isOpaque(SynthContext)' + */ + public void testIsOpaque() { + assertTrue(currentStyle.isOpaque(currentContext)); + } + + private static class SynthStyleForTest extends SynthStyle { + + SynthStyleForTest() { + addProperty(ICON_KEY, ICON_VALUE); + addProperty(STRING_KEY, STRING_VALUE); + addProperty(INT_KEY, INT_VALUE); + addProperty(BOOLEAN_KEY, BOOLEAN_VALUE); + } + + @Override + @SuppressWarnings("unused") + protected Font getFontForState(SynthContext context) { + return FONT_VALUE; + } + + @Override + @SuppressWarnings("unused") + protected Color getColorForState(SynthContext context, ColorType type) { + return COLOR_VALUE; + } + + public void addProperty(String key, Object value) { + propertiesMap.put(key, value); + } + } + +} Index: src/test/api/java/common/javax/swing/plaf/synth/SynthLookAndFeelTest.java =================================================================== --- src/test/api/java/common/javax/swing/plaf/synth/SynthLookAndFeelTest.java (revision 0) +++ src/test/api/java/common/javax/swing/plaf/synth/SynthLookAndFeelTest.java (revision 0) @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.plaf.ComponentUI; + +import junit.framework.TestCase; + +public class SynthLookAndFeelTest extends TestCase { + + SynthLookAndFeel laf = new SynthLookAndFeel(); + + JLabel l = new JLabel(); + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthLookAndFeel.isNativeLookAndFeel()' + */ + public void testIsNativeLookAndFeel() { + assertFalse(laf.isNativeLookAndFeel()); + } + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthLookAndFeel.isSupportedLookAndFeel()' + */ + public void testIsSupportedLookAndFeel() { + assertTrue(laf.isSupportedLookAndFeel()); + } + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthLookAndFeel.getStyleFactory()' + */ + public void testGetStyleFactory() { + SynthStyleFactory sf = new SynthStyleFactory() { + @Override + @SuppressWarnings("unused") + public SynthStyle getStyle(JComponent c, Region id) { + return null; + } + }; + SynthLookAndFeel.setStyleFactory(sf); + assertSame(sf, SynthLookAndFeel.getStyleFactory()); + } + +// /* +// * Test method for +// * 'javax.swing.plaf.synth.SynthLookAndFeel.createUI(JComponent)' +// */ +// public void testCreateUI() { +// l.setEnabled(false); +// ComponentUI labelUI = SynthLookAndFeel.createUI(l); +// assertTrue(labelUI instanceof SynthUI); +// assertTrue(labelUI instanceof SynthLabelUI); +// assertTrue(((SynthLabelUI) labelUI).getLabelState(l) == SynthConstants.DISABLED); +// } + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthLookAndFeel.updateStyles(Component)' + */ + public void testUpdateStyles() { + // TODO: + } + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthLookAndFeel.getRegion(JComponent)' + */ + public void testGetRegion() { + assertSame(Region.LABEL, SynthLookAndFeel.getRegion(l)); + } + + /* + * Test method for 'javax.swing.plaf.synth.SynthLookAndFeel.getName()' + */ + public void testGetName() { + assertEquals("Synth Look and Feel", laf.getName()); //$NON-NLS-1$ + } + + /* + * Test method for 'javax.swing.plaf.synth.SynthLookAndFeel.getID()' + */ + public void testGetID() { + assertEquals("Synth", laf.getID()); //$NON-NLS-1$ + } + + /* + * Test method for + * 'javax.swing.plaf.synth.SynthLookAndFeel.shouldUpdateStyleOnAncestorChanged()' + */ + public void testShouldUpdateStyleOnAncestorChanged() { + assertFalse(laf.shouldUpdateStyleOnAncestorChanged()); + } + +} Index: src/test/api/java/common/javax/swing/plaf/synth/SynthContextTest.java =================================================================== --- src/test/api/java/common/javax/swing/plaf/synth/SynthContextTest.java (revision 0) +++ src/test/api/java/common/javax/swing/plaf/synth/SynthContextTest.java (revision 0) @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import java.awt.Color; +import java.awt.Font; + +import javax.swing.JButton; + +import junit.framework.TestCase; + +public class SynthContextTest extends TestCase { + + private static final SynthStyle ss = new SynthStyle() { + @Override + @SuppressWarnings("unused")//$NON-NLS-1$ + protected Font getFontForState(SynthContext context) { + return null; + } + + @Override + @SuppressWarnings("unused")//$NON-NLS-1$ + protected Color getColorForState(SynthContext context, ColorType type) { + return Color.RED; + } + }; + + private static final String BUTTON_NAME = "testJButton"; //$NON-NLS-1$ + + private static final JButton testButton = new JButton(BUTTON_NAME); + + private static final SynthContext sc = new SynthContext(testButton, + Region.BUTTON, ss, SynthConstants.ENABLED); + + public static void testFields() { + assertSame(Region.BUTTON, sc.getRegion()); + assertSame(ss, sc.getStyle()); + assertSame(Color.RED, sc.getStyle().getColorForState(sc, null)); + assertTrue(sc.getComponentState() == SynthConstants.ENABLED); + assertSame(testButton, sc.getComponent()); + } + + public static void testStates() { + + assertTrue(SynthContext.isEnabled(sc.getComponentState())); + sc.setState(SynthConstants.DISABLED); + assertFalse(SynthConstants.ENABLED == sc.getComponentState()); + assertFalse(SynthContext.isEnabled(sc.getComponentState())); + assertTrue(SynthContext.isDisabled(sc.getComponentState())); + + sc.gainState(SynthConstants.DISABLED); + assertTrue(SynthConstants.DISABLED == sc.getComponentState()); + + sc.gainState(SynthConstants.FOCUSED); + assertTrue(SynthContext.isDisabled(sc.getComponentState())); + assertTrue(SynthContext.isFocused(sc.getComponentState())); + + assertFalse(SynthContext.isMouseOver(sc.getComponentState())); + sc.lossState(SynthConstants.MOUSE_OVER); + assertFalse(SynthContext.isMouseOver(sc.getComponentState())); + + sc.lossState(SynthConstants.FOCUSED); + assertFalse(SynthContext.isFocused(sc.getComponentState())); + + sc.setState(SynthConstants.ENABLED); + assertTrue(SynthContext.isEnabled(sc.getComponentState())); + + } + +}