001/* 002 * Copyright (c) 2005 Einar Pehrson <einar@pehrson.nu>. 003 * 004 * This file is part of 005 * CleanSheets - a spreadsheet application for the Java platform. 006 * 007 * CleanSheets is free software; you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published by 009 * the Free Software Foundation; either version 2 of the License, or 010 * (at your option) any later version. 011 * 012 * CleanSheets is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with CleanSheets; if not, write to the Free Software 019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 */ 021package csheets.ext.style.ui; 022 023import java.awt.event.ActionEvent; 024 025import csheets.core.Cell; 026import csheets.ext.style.StylableCell; 027import csheets.ext.style.StyleExtension; 028import csheets.ui.ctrl.FocusOwnerAction; 029import csheets.ui.ctrl.UIController; 030 031/** 032 * A style operation. 033 * @author Einar Pehrson 034 */ 035public abstract class StyleAction extends FocusOwnerAction { 036 037 /** The user interface controller */ 038 protected UIController uiController; 039 040 /** 041 * Creates a new style action. 042 * @param uiController the user interface controller 043 */ 044 public StyleAction(UIController uiController) { 045 this.uiController = uiController; 046 } 047 048 /** 049 * Applies the style to the selected cells in the focus owner table. 050 * @param event the event that was fired 051 */ 052 public void actionPerformed(ActionEvent event) { 053 if (focusOwner == null) 054 return; 055 056 // Aligns each selected cell 057 for (Cell[] row : focusOwner.getSelectedCells()) 058 for (Cell cell : row) { 059 StylableCell stylableCell = (StylableCell)cell.getExtension( 060 StyleExtension.NAME); 061 applyStyle(stylableCell); 062 } 063 064 uiController.setWorkbookModified(focusOwner.getSpreadsheet().getWorkbook()); 065 focusOwner.repaint(); 066 } 067 068 /** 069 * Applies the style to the given stylable cell 070 * @param cell the cell to which style should be applied 071 */ 072 protected abstract void applyStyle(StylableCell cell); 073}