001 ///////////////////////////////////////////////// 002 //This file is part of Sears project. 003 //Subtitle Editor And Re-Synch 004 //A tool to easily modify and resynch movies subtitles. 005 ///////////////////////////////////////////////// 006 //This program is free software; 007 //you can redistribute it and/or modify it under the terms 008 //of the GNU General Public License 009 //as published by the Free Software Foundation; 010 //either version 2 of the License, or (at your option) any later version. 011 ///////////////////////////////////////////////// 012 //Sears project is available under sourceforge 013 //at adress: http://sourceforge.net/projects/sears/ 014 //Copyright (C) 2005 Booba Skaya 015 //Mail: booba.skaya@gmail.com 016 ///////////////////////////////////////////////// 017 018 package sears.tools.eawt; 019 020 import java.awt.EventQueue; 021 import java.io.File; 022 023 import sears.gui.MainWindow; 024 025 /** 026 * This class will implement com.apple.eawt.ApplicationListener interface 027 */ 028 public class SearsApplicationListener extends ApplicationAdapter { 029 // the ApplicationEvent handle 030 private ApplicationEventWrapper ew = null; 031 private MainWindow mainWindow; 032 033 /** 034 * Construct a new instance 035 * @throws NullPointerException if frame is null 036 */ 037 public SearsApplicationListener() { 038 ew = new ApplicationEventWrapper(); 039 // constructs the main window: 040 mainWindow = new MainWindow(); 041 } 042 043 /* 044 * (non-Javadoc) 045 * @see sears.tools.eawt.ApplicationAdapter#handleAbout(java.lang.Object) 046 */ 047 public void handleAbout(Object event) { 048 // we disable the defaut about dialog: 049 ew.applicationEventObject(event); 050 ew.setHandled(true); 051 // and we call the sears aboout dialog: 052 mainWindow.aboutAction(); 053 } 054 055 /* 056 * (non-Javadoc) 057 * @see sears.tools.eawt.ApplicationAdapter#handleOpenApplication(java.lang.Object) 058 */ 059 public void handleOpenApplication(Object event) { 060 handleOpenFile(event); 061 Runnable mainWindowVisible = new Runnable() { 062 public void run() { 063 mainWindow.setVisible(true); 064 } 065 }; 066 // THREAD-SAFE, put the setVisible method in the SWING "event dispatching thread" 067 EventQueue.invokeLater(mainWindowVisible); 068 ew.setHandled(true); 069 } 070 071 /* 072 * (non-Javadoc) 073 * @see sears.tools.eawt.ApplicationAdapter#handleOpenFile(java.lang.Object) 074 */ 075 public void handleOpenFile(Object event) { 076 // we get back the full path of the file: 077 ew.applicationEventObject(event); 078 String subtitleFilePath = ew.getFilename(); 079 // just in case of: 080 if(subtitleFilePath != null){ 081 mainWindow.openFile(new File(subtitleFilePath)); 082 } 083 } 084 085 /* 086 * (non-Javadoc) 087 * @see sears.tools.eawt.ApplicationAdapter#handlePreferences(java.lang.Object) 088 */ 089 public void handlePreferences(Object event) { 090 // we call the sears preference dialog: options 091 mainWindow.optionsAction(); 092 093 } 094 095 /* 096 * (non-Javadoc) 097 * @see sears.tools.eawt.ApplicationAdapter#handleQuit(java.lang.Object) 098 */ 099 public void handleQuit(Object arg0) { 100 mainWindow.quitAction(); 101 102 } 103 }