001 /*
002 * Copyright (c) 2005 Jens Schou, Staffan Gustafsson, Björn Lanneskog,
003 * Einar Pehrson and Sebastian Kekkonen
004 *
005 * This file is part of
006 * CleanSheets Extension for Test Cases
007 *
008 * CleanSheets Extension for Test Cases is free software; you can
009 * redistribute it and/or modify it under the terms of the GNU General Public
010 * License as published by the Free Software Foundation; either version 2 of
011 * the License, or (at your option) any later version.
012 *
013 * CleanSheets Extension for Test Cases is distributed in the hope that
014 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
015 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016 * See the GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with CleanSheets Extension for Test Cases; if not, write to the
020 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
021 * Boston, MA 02111-1307 USA
022 */
023 package csheets.ext.test.ui;
024
025 import java.awt.GridLayout;
026
027 import javax.swing.BorderFactory;
028 import javax.swing.Icon;
029 import javax.swing.ImageIcon;
030 import javax.swing.JComponent;
031 import javax.swing.JPanel;
032 import javax.swing.JToolBar;
033 import javax.swing.border.TitledBorder;
034
035 import csheets.ext.test.TestExtension;
036 import csheets.ui.ctrl.UIController;
037 import csheets.ui.ext.CellDecorator;
038 import csheets.ui.ext.UIExtension;
039
040 /**
041 * The user interface extension for tests.
042 * @author Einar Pehrson
043 */
044 public class TestUIExtension extends UIExtension {
045
046 /** The icon to display with the extension's name */
047 private Icon icon;
048
049 /** A cell decorator that visualizes test cases for cells */
050 private CellDecorator cellDecorator;
051
052 /** A toolbar that visualizes cell and spreadsheet testedness */
053 private TestToolBar toolBar;
054
055 /** A side bar that provides editing of test cases and test case parameters */
056 private JComponent sideBar;
057
058 /**
059 * Creates a new user interface extension for tests.
060 * @param extension the extension for which components are provided
061 * @param uiController the user interface controller
062 */
063 public TestUIExtension(TestExtension extension, UIController uiController) {
064 super(extension, uiController);
065 }
066
067 /**
068 * Returns an icon to display with the extension's name.
069 * @return an icon with a testing pad
070 */
071 public Icon getIcon() {
072 if (icon == null)
073 icon = new ImageIcon(
074 TestExtension.class.getResource("res/img/logo.gif"));
075 return icon;
076 }
077
078 /**
079 * Returns a cell decorator that visualizes test cases for cells.
080 * @return decorator for testable cells
081 */
082 public CellDecorator getCellDecorator() {
083 if (cellDecorator == null)
084 cellDecorator = new TestableCellDecorator();
085 return cellDecorator;
086 }
087
088 /**
089 * Returns a toolbar that visualizes cell and spreadsheet testedness.
090 * @return a JToolBar component
091 */
092 public JToolBar getToolBar() {
093 if (toolBar == null) {
094 toolBar = new TestToolBar();
095 uiController.addSelectionListener(toolBar);
096 }
097 return toolBar;
098 }
099
100 /**
101 * Returns a side bar that provides editing of test cases and test case
102 * parameters.
103 * @return a side bar
104 */
105 public JComponent getSideBar() {
106 if (sideBar == null) {
107 // Creates and configures components
108 TestCasePanel testCasePanel = new TestCasePanel(uiController);
109 TestCaseParamPanel testCaseParamPanel = new TestCaseParamPanel(uiController);
110 uiController.addSelectionListener(testCasePanel);
111 uiController.addSelectionListener(testCaseParamPanel);
112
113 // Adds borders
114 TitledBorder border = BorderFactory.createTitledBorder("Test Cases");
115 border.setTitleJustification(TitledBorder.CENTER);
116 testCasePanel.setBorder(border);
117 border = BorderFactory.createTitledBorder("Test Case Parameters");
118 border.setTitleJustification(TitledBorder.CENTER);
119 testCaseParamPanel.setBorder(border);
120
121 // Creates side bar
122 sideBar = new JPanel(new GridLayout(2, 1));
123 sideBar.add(testCaseParamPanel);
124 sideBar.add(testCasePanel);
125 sideBar.setName(TestExtension.NAME);
126 }
127 return sideBar;
128 }
129 }