001/* 002 * Copyright (c) 2005 Peter Palotas, Fredrik Johansson, Einar Pehrson, 003 * Sebastian Kekkonen, Lars Magnus Lang, Malin Johansson and Sofia Nilsson 004 * 005 * This file is part of 006 * CleanSheets Extension for Assertions 007 * 008 * CleanSheets Extension for Assertions 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 Assertions 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 Assertions; if not, write to the 020 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 021 * Boston, MA 02111-1307 USA 022 */ 023package csheets.ext.assertion.ui; 024 025import javax.swing.Icon; 026import javax.swing.ImageIcon; 027import javax.swing.JComponent; 028import javax.swing.JToolBar; 029 030import csheets.ext.assertion.AssertionExtension; 031import csheets.ui.ctrl.UIController; 032import csheets.ui.ext.CellDecorator; 033import csheets.ui.ext.UIExtension; 034 035/** 036 * The user interface extension for assertions. 037 * @author Einar Pehrson 038 */ 039public class AssertionUIExtension extends UIExtension { 040 041 /** The icon to display with the extension's name */ 042 private Icon icon; 043 044 /** A cell decorator that visualizes assertions on cells */ 045 private CellDecorator cellDecorator; 046 047 /** A toolbar that visualizes assertions on cells */ 048 private AssertionToolBar toolBar; 049 050 /** A side bar that provides editing of assertions */ 051 private JComponent sideBar; 052 053 /** 054 * Creates a new user interface extension for assertions. 055 * @param extension the extension for which components are provided 056 * @param uiController the user interface controller 057 */ 058 public AssertionUIExtension(AssertionExtension extension, UIController uiController) { 059 super(extension, uiController); 060 } 061 062 /** 063 * Returns an icon to display with the extension's name. 064 * @return an icon with an interval 065 */ 066 public Icon getIcon() { 067 if (icon == null) 068 icon = new ImageIcon( 069 AssertionExtension.class.getResource("res/img/logo.gif")); 070 return icon; 071 } 072 073 /** 074 * Returns a cell decorator that visualizes assertions on cells. 075 * @return decorator for assertable cells 076 */ 077 public CellDecorator getCellDecorator() { 078 if (cellDecorator == null) 079 cellDecorator = new AssertableCellDecorator(); 080 return cellDecorator; 081 } 082 083 /** 084 * Returns a toolbar that visualizes assertions on cells. 085 * @return a JToolBar component 086 */ 087 public JToolBar getToolBar() { 088 if (toolBar == null) { 089 toolBar = new AssertionToolBar(); 090 uiController.addSelectionListener(toolBar); 091 } 092 return toolBar; 093 } 094 095 /** 096 * Returns a side bar that provides editing of assertions. 097 * @return a side bar 098 */ 099 public JComponent getSideBar() { 100 if (sideBar == null) 101 sideBar = new AssertionPanel(uiController); 102 return sideBar; 103 } 104}