001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Anton Avtamonov
019: * @version $Revision$
020: */package javax.swing.plaf.metal;
021:
022: import java.awt.ComponentOrientation;
023: import javax.swing.CellRendererPane;
024: import javax.swing.Icon;
025: import javax.swing.ImageIcon;
026: import javax.swing.JComboBox;
027: import javax.swing.JList;
028: import javax.swing.SwingTestCase;
029:
030: public class MetalComboBoxButtonTest extends SwingTestCase {
031: private MetalComboBoxButton button;
032:
033: public MetalComboBoxButtonTest(final String name) {
034: super (name);
035: }
036:
037: @Override
038: protected void setUp() throws Exception {
039: button = new MetalComboBoxButton(new JComboBox(), null, null,
040: null);
041: }
042:
043: @Override
044: protected void tearDown() throws Exception {
045: button = null;
046: }
047:
048: public void testMetalComboBoxButton() throws Exception {
049: assertNotNull(button.comboBox);
050: assertNull(button.comboIcon);
051: assertNull(button.listBox);
052: assertNull(button.rendererPane);
053: assertFalse(button.isIconOnly());
054: JComboBox comboBox = new JComboBox();
055: Icon comboIcon = new ImageIcon();
056: CellRendererPane rendererPane = new CellRendererPane();
057: JList list = new JList();
058: button = new MetalComboBoxButton(comboBox, comboIcon,
059: rendererPane, list);
060: assertEquals(comboBox, button.comboBox);
061: assertEquals(comboIcon, button.comboIcon);
062: assertEquals(rendererPane, button.rendererPane);
063: assertEquals(list, button.listBox);
064: assertFalse(button.isIconOnly());
065: button = new MetalComboBoxButton(comboBox, comboIcon, true,
066: rendererPane, list);
067: assertEquals(comboBox, button.comboBox);
068: assertEquals(comboIcon, button.comboIcon);
069: assertEquals(rendererPane, button.rendererPane);
070: assertEquals(list, button.listBox);
071: assertTrue(button.isIconOnly());
072: comboBox
073: .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
074: button = new MetalComboBoxButton(comboBox, null, null, null);
075: assertTrue(button.getComponentOrientation().isLeftToRight());
076: comboBox
077: .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
078: assertTrue(button.getComponentOrientation().isLeftToRight());
079: }
080:
081: public void testGetSetComboBox() throws Exception {
082: JComboBox comboBox = new JComboBox();
083: button.setComboBox(comboBox);
084: assertEquals(comboBox, button.getComboBox());
085: assertEquals(comboBox, button.comboBox);
086: }
087:
088: public void testGetSetComboIcon() throws Exception {
089: Icon comboIcon = new ImageIcon();
090: button.setComboIcon(comboIcon);
091: assertEquals(comboIcon, button.getComboIcon());
092: assertEquals(comboIcon, button.comboIcon);
093: }
094:
095: public void testIsSetIconOnly() throws Exception {
096: assertFalse(button.isIconOnly());
097: button.setIconOnly(true);
098: assertTrue(button.isIconOnly());
099: button.setIconOnly(false);
100: assertFalse(button.isIconOnly());
101: }
102:
103: public void testIsFocusTraversable() throws Exception {
104: assertFalse(button.isFocusTraversable());
105: button.getComboBox().setEditable(true);
106: assertFalse(button.isFocusTraversable());
107: }
108:
109: public void testSetEnabled() throws Exception {
110: assertTrue(button.isEnabled());
111: button.setEnabled(false);
112: assertFalse(button.isEnabled());
113: JComboBox comboBox = new JComboBox();
114: comboBox.setEnabled(false);
115: button = new MetalComboBoxButton(comboBox, null, null, null);
116: assertFalse(button.isEnabled());
117: }
118:
119: public void testPaintComponent() throws Exception {
120: button.paintComponent(createTestGraphics());
121: }
122: }
|