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 Vadim L. Bogdanov
019: * @version $Revision$
020: */package javax.swing.plaf.basic;
021:
022: import java.beans.PropertyVetoException;
023: import javax.swing.AbstractAction;
024: import javax.swing.Action;
025: import javax.swing.JButton;
026: import javax.swing.JDesktopPane;
027: import javax.swing.JFrame;
028: import javax.swing.JInternalFrame;
029: import javax.swing.SwingTestCase;
030:
031: public class BasicDesktopPaneUIActionsTest extends SwingTestCase {
032: private JFrame frame;
033:
034: private JDesktopPane desktop;
035:
036: private JInternalFrame iframe1;
037:
038: private JInternalFrame iframe2;
039:
040: private BasicDesktopPaneUI ui;
041:
042: public BasicDesktopPaneUIActionsTest(final String name) {
043: super (name);
044: }
045:
046: @Override
047: protected void setUp() throws Exception {
048: super .setUp();
049: frame = new JFrame();
050: desktop = new JDesktopPane();
051: ui = new BasicDesktopPaneUI();
052: desktop.setUI(ui);
053: iframe1 = new JInternalFrame("", true, true, true, true);
054: desktop.add(iframe1);
055: iframe2 = new JInternalFrame("", true, true, true, true);
056: desktop.add(iframe2);
057: frame.getContentPane().add(desktop);
058: desktop.setSelectedFrame(iframe1);
059: }
060:
061: @Override
062: protected void tearDown() throws Exception {
063: super .tearDown();
064: frame.dispose();
065: }
066:
067: public void testNavigateAction() {
068: if (!isHarmony()) {
069: return;
070: }
071: frame.setVisible(true);
072: class MyButton extends JButton {
073: private static final long serialVersionUID = 1L;
074:
075: public boolean requestedFocus;
076:
077: @Override
078: public void requestFocus() {
079: requestedFocus = true;
080: super .requestFocus();
081: }
082: }
083: MyButton b1 = new MyButton();
084: MyButton b2 = new MyButton();
085: frame.getContentPane().add(b1, 0);
086: frame.getContentPane().add(b2, 2);
087: AbstractAction action = ui.new NavigateAction();
088: action.putValue(Action.NAME, "navigateNext");
089: b1.requestedFocus = false;
090: action.actionPerformed(null);
091: assertTrue(b1.requestedFocus);
092: action.putValue(Action.NAME, "navigatePrevious");
093: b2.requestedFocus = false;
094: action.actionPerformed(null);
095: assertTrue(b2.requestedFocus);
096: }
097:
098: public void testCloseAction() {
099: AbstractAction action = ui.new CloseAction();
100: action.actionPerformed(null);
101: assertTrue(desktop.getSelectedFrame().isClosed());
102: }
103:
104: public void testMaximizeAction() {
105: AbstractAction action = ui.new MaximizeAction();
106: action.actionPerformed(null);
107: assertTrue(desktop.getSelectedFrame().isMaximum());
108: }
109:
110: public void testMinimizeAction() {
111: AbstractAction action = ui.new MinimizeAction();
112: action.actionPerformed(null);
113: assertTrue(desktop.getSelectedFrame().isIcon());
114: }
115:
116: public void testOpenAction() throws PropertyVetoException {
117: AbstractAction action = ui.new OpenAction();
118: desktop.getSelectedFrame().setMaximum(true);
119: action.actionPerformed(null);
120: assertFalse(desktop.getSelectedFrame().isMaximum());
121: desktop.getSelectedFrame().setIcon(true);
122: action.actionPerformed(null);
123: assertFalse(desktop.getSelectedFrame().isIcon());
124: }
125: }
|