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 java.awt.event.ActionEvent; 023 import java.awt.event.KeyEvent; 024 025 import javax.swing.KeyStroke; 026 027 import net.shredzone.ifish.*; 028 import net.shredzone.ifish.i18n.L; 029 import net.shredzone.ifish.pool.ImgPool; 030 031 /** 032 * Quit the application. 033 * 034 * @author Richard Körber <dev@shredzone.de> 035 * @version $Id: QuitAction.java 291 2009-04-28 21:29:27Z shred $ 036 */ 037 public class QuitAction extends IFishAction { 038 private static final long serialVersionUID = 3760558689660187703L; 039 private Quittable quitter = null; 040 041 /** 042 * Create a new QuitAction. 043 * 044 * @param fish Related IFishPane 045 */ 046 public QuitAction( IFishPane fish ) { 047 super( 048 fish, 049 L.tr("action.quit"), 050 ImgPool.get("exit.png"), 051 L.tr("action.quit.tt"), 052 KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.CTRL_MASK ) 053 ); 054 } 055 056 public void setQuitter( Quittable quitter ) { 057 this.quitter = quitter; 058 } 059 060 /** 061 * The action implementation itself. Do not call directly. 062 */ 063 @Override 064 protected void action() { 065 if(! fish.confirmChanges() ) return; 066 067 if( quitter!=null ) { 068 quitter.quit(); 069 }else { 070 System.exit(0); // nothing else would take care for quitting 071 } 072 } 073 074 /*--------------------------------------------------------------------*/ 075 076 /** 077 * This interface is implemented by the class that takes care about 078 * closing the application. 079 */ 080 public static interface Quittable { 081 082 /** 083 * Close the application 084 */ 085 public void quit(); 086 087 } 088 089 } 090