1
package freeguide.plugins.program.freeguide.lib.fgspecific;
3
import freeguide.common.gui.ExecutorDialog;
5
import freeguide.common.lib.fgspecific.Application;
7
import freeguide.common.plugininterfaces.IModuleGrabber;
9
import freeguide.plugins.program.freeguide.FreeGuide;
10
import freeguide.plugins.program.freeguide.viewer.MainController;
12
import java.awt.event.ActionEvent;
13
import java.awt.event.ActionListener;
14
import java.awt.event.WindowAdapter;
15
import java.awt.event.WindowEvent;
17
import java.nio.channels.ClosedByInterruptException;
19
import java.util.Iterator;
20
import java.util.logging.Level;
22
import javax.swing.JButton;
23
import javax.swing.JDialog;
24
import javax.swing.JFrame;
25
import javax.swing.JProgressBar;
28
* Class for run specified grabber and display progress dialog.
30
* @author Alex Buloichik (alex73 at zaval.org)
32
public class GrabberController
34
protected ExecutorDialog progressDialog;
35
protected JProgressBar secondProgressBar;
36
protected boolean wasError;
37
protected Thread grabberThread;
40
* Show grabber dialog when grabbing running, or start grabbing in
43
* @param controller DOCUMENT ME!
45
public void activate( final MainController controller )
49
if( progressDialog != null )
52
progressDialog.bringToForeground( );
63
.finest( "start grabbing" );
68
controller.getApplicationFrame( ),
69
controller.mainFrame.getProgressBar( ),
71
.getForegroundButton( ) );
72
controller.viewer.onDataChanged( );
73
MainController.remindersReschedule( );
77
ex.printStackTrace( );
80
FreeGuide.log.finest( "stop grabbing" );
83
grabberThread.start( );
91
* @param owner DOCUMENT_ME!
92
* @param secondProgressBar DOCUMENT ME!
93
* @param foregroundButton DOCUMENT ME!
96
final JFrame owner, final JProgressBar secondProgressBar,
97
final JButton foregroundButton )
99
this.secondProgressBar = secondProgressBar;
104
progressDialog = new ExecutorDialog(
105
owner, secondProgressBar, foregroundButton );
106
progressDialog.setStepCount( 1 );
107
progressDialog.setStepNumber( 0 );
109
progressDialog.getCancelButton( ).addActionListener(
110
new ActionListener( )
112
public void actionPerformed( ActionEvent evt )
114
synchronized( GrabberController.this )
116
grabberThread.interrupt( );
118
// leave dialog when details open or was error
119
if( progressDialog != null )
121
progressDialog.dispose( );
122
progressDialog = null;
128
progressDialog.addWindowListener(
131
public void windowClosing( WindowEvent e )
133
if( !grabberThread.isAlive( ) )
135
if( progressDialog != null )
137
progressDialog.dispose( );
138
progressDialog = null;
149
progressDialog.setVisible( true );
153
if( MainController.config.activeGrabberIDs.size( ) == 0 )
156
progressDialog.showNoGrabberMessage( );
161
Iterator it = MainController.config.activeGrabberIDs
164
while( it.hasNext( ) )
166
String grabberID = (String)it.next( );
170
IModuleGrabber grabber =
171
(IModuleGrabber)PluginsManager.getModuleByID(
174
if( grabber == null )
176
FreeGuide.log.warning(
177
"There is no grabber " + grabberID );
183
if( Thread.interrupted( ) )
188
final StoragePipe pipe = new StoragePipe( );
190
wasError = !grabber.grabData(
191
progressDialog, progressDialog, pipe );
195
if( Thread.interrupted( ) )
200
catch( ClosedByInterruptException ex )
204
catch( InterruptedException ex )
208
catch( Throwable ex )
212
if( progressDialog != null )
214
if( ex instanceof Exception )
216
progressDialog.error(
217
"Error grab data by grabber '" + grabberID
218
+ "'", (Exception)ex );
222
progressDialog.error(
223
"Error grab data by grabber '" + grabberID
224
+ "': " + ex.getClass( ).getName( ) );
230
"Error grab data by grabber '" + grabberID, ex );
237
if( progressDialog != null )
241
if( !progressDialog.isLogVisible( ) )
243
progressDialog.dispose( );
244
progressDialog = null;
248
progressDialog.setDefaultCloseOperation(
249
JDialog.DISPOSE_ON_CLOSE );
250
progressDialog.setCloseLabel( );
251
progressDialog.setProgressMessage(
253
Application.getInstance( )
254
.getLocalizedMessage(
255
"ExecutionDialog.Finish.OK" ) );
256
progressDialog.bringToForeground( );
261
progressDialog.setDefaultCloseOperation(
262
JDialog.DISPOSE_ON_CLOSE );
263
progressDialog.setCloseLabel( );
264
progressDialog.setProgressMessage(
266
Application.getInstance( )
267
.getLocalizedMessage(
268
"ExecutionDialog.Finish.Error" ) );
269
progressDialog.bringToForeground( );
270
progressDialog.showDetails( );
275
if( progressDialog != null )
277
progressDialog.disableBackgroundButton( );