01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package javax.swing.plaf.synth;
19:
20: import java.awt.Color;
21: import java.awt.Font;
22:
23: import javax.swing.JButton;
24:
25: import junit.framework.TestCase;
26:
27: public class SynthContextTest extends TestCase {
28:
29: private static final SynthStyle ss = new SynthStyle() {
30: @Override
31: @SuppressWarnings("unused")//$NON-NLS-1$
32: protected Font getFontForState(SynthContext context) {
33: return null;
34: }
35:
36: @Override
37: @SuppressWarnings("unused")//$NON-NLS-1$
38: protected Color getColorForState(SynthContext context,
39: ColorType type) {
40: return Color.RED;
41: }
42: };
43:
44: private static final String BUTTON_NAME = "testJButton"; //$NON-NLS-1$
45:
46: private static final JButton testButton = new JButton(BUTTON_NAME);
47:
48: private static final SynthContext sc = new SynthContext(testButton,
49: Region.BUTTON, ss, SynthConstants.ENABLED);
50:
51: public static void testFields() {
52: assertSame(Region.BUTTON, sc.getRegion());
53: assertSame(ss, sc.getStyle());
54: assertSame(Color.RED, sc.getStyle().getColorForState(sc, null));
55: assertTrue(sc.getComponentState() == SynthConstants.ENABLED);
56: assertSame(testButton, sc.getComponent());
57: }
58:
59: public static void testStates() {
60:
61: assertTrue(SynthContext.isEnabled(sc.getComponentState()));
62: sc.setState(SynthConstants.DISABLED);
63: assertFalse(SynthConstants.ENABLED == sc.getComponentState());
64: assertFalse(SynthContext.isEnabled(sc.getComponentState()));
65: assertTrue(SynthContext.isDisabled(sc.getComponentState()));
66:
67: sc.gainState(SynthConstants.DISABLED);
68: assertTrue(SynthConstants.DISABLED == sc.getComponentState());
69:
70: sc.gainState(SynthConstants.FOCUSED);
71: assertTrue(SynthContext.isDisabled(sc.getComponentState()));
72: assertTrue(SynthContext.isFocused(sc.getComponentState()));
73:
74: assertFalse(SynthContext.isMouseOver(sc.getComponentState()));
75: sc.lossState(SynthConstants.MOUSE_OVER);
76: assertFalse(SynthContext.isMouseOver(sc.getComponentState()));
77:
78: sc.lossState(SynthConstants.FOCUSED);
79: assertFalse(SynthContext.isFocused(sc.getComponentState()));
80:
81: sc.setState(SynthConstants.ENABLED);
82: assertTrue(SynthContext.isEnabled(sc.getComponentState()));
83:
84: }
85:
86: }
|