001 /** 002 * iFish - An iRiver iHP jukebox database creation tool 003 * 004 * Copyright (C) 2009 Richard "Shred" Körber 005 * http://ifish.shredzone.org 006 * 007 * This program 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 3 of the License, or 010 * (at your option) any later version. 011 * 012 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. 019 */ 020 package net.shredzone.ifish.actions; 021 022 import net.shredzone.ifish.*; 023 import net.shredzone.jshred.swing.*; 024 import java.util.prefs.Preferences; 025 import java.awt.event.*; 026 import javax.swing.*; 027 028 /** 029 * The basic class for all IFish actions. The action is executed 030 * synchronously with in the GUI thread, so it is rather meant to be 031 * used for actions that either take very little time to execute, or 032 * for actions which open a modal dialog. 033 * 034 * @author Richard Körber <dev@shredzone.de> 035 * @version $Id: IFishAction.java 291 2009-04-28 21:29:27Z shred $ 036 */ 037 public abstract class IFishAction extends AbstractAction { 038 private static final long serialVersionUID = -6298189249175337399L; 039 protected final IFishPane fish; 040 protected final IFishPrefs prefs; 041 042 /** 043 * Create a new, synchronous Action. Event processing will be stopped 044 * during execution, which also means that there is no GUI update. If 045 * you do not fancy this, you should have a look at AsyncIFishAction. 046 * 047 * @param fish IFishPane this action belongs to 048 * @param name Action Name 049 * @param icon Action Icon or null 050 * @param tip Action Tooltip or null 051 * @param accel Accelerator Key or null 052 */ 053 public IFishAction( IFishPane fish, String name, Icon icon, String tip, KeyStroke accel ) { 054 this.fish = fish; 055 this.prefs = fish.getPrefs(); 056 SwingUtils.setMenuKey( this, name ); 057 if( icon!=null ) 058 putValue( Action.SMALL_ICON, icon ); 059 if( tip!=null ) 060 putValue( Action.SHORT_DESCRIPTION, tip ); 061 if( accel!=null ) 062 putValue( Action.ACCELERATOR_KEY, accel ); 063 } 064 065 /** 066 * The action has been invoked from a button, menu item etc. 067 * 068 * @param e ActionEvent 069 */ 070 @Override 071 public void actionPerformed( ActionEvent e ) { 072 perform(); 073 } 074 075 /** 076 * You can use this method if you want to invoke the action directly 077 * from your current application code. 078 */ 079 public void perform() { 080 action(); 081 } 082 083 /** 084 * The action implementation itself. Overwrite this method with your 085 * desired action. You do not need to care for threading, locking 086 * etc. Anyhow keep in mind that for AsyncIFishActions, this method 087 * is actually running in a separate thread. 088 */ 089 protected abstract void action(); 090 091 } 092