Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: entagged/gui/tageditor/listeners/FreeDBButtonListener.java


1   /*
2    *  ********************************************************************   **
3    *  Copyright notice                                                       **
4    *  **                                     **
5    *  (c) 2003 Entagged Developpement Team                           **
6    *  http://www.sourceforge.net/projects/entagged                           **
7    *  **                                     **
8    *  All rights reserved                                                    **
9    *  **                                     **
10   *  This script is part of the Entagged project. The Entagged          **
11   *  project is free software; you can redistribute it and/or modify        **
12   *  it under the terms of the GNU General Public License as published by   **
13   *  the Free Software Foundation; either version 2 of the License, or      **
14   *  (at your option) any later version.                                    **
15   *  **                                     **
16   *  The GNU General Public License can be found at                         **
17   *  http://www.gnu.org/copyleft/gpl.html.                                  **
18   *  **                                     **
19   *  This copyright notice MUST APPEAR in all copies of the file!           **
20   *  ********************************************************************
21   */
22  package entagged.gui.tageditor.listeners;
23  
24  import entagged.formats.mp3.*;
25  import entagged.freedb.*;
26  import entagged.gui.*;
27  import entagged.gui.tageditor.*;
28  import entagged.gui.tageditor.dialogs.*;
29  import java.awt.event.*;
30  
31  
32  /**
33   *  This listens to an event on the freedb button on the main screen. It opens a
34   *  freedb dialog allowing to rename the files of the current album according to
35   *  the database $Id: FreeDBButtonListener.java,v 1.1 2003/09/22 14:44:29
36   *  kikidonk Exp $
37   *
38   * @author     Raphael Slinckx (KiKiDonK)
39   * @version    v0.03
40   */
41  public class FreeDBButtonListener implements ActionListener {
42  
43    /**  The current MP3 Album (shown in the table) */
44    private MP3Album currentAlbum;
45  
46    /**  Parent Tag Editor */
47    private TagEditorFrame tagEditorFrame;
48  
49  
50    /**
51     *  Constructor for the FreeDBButtonListener object
52     *
53     * @param  tagEditorFrame  Parent Tag Editor Frame
54     */
55    public FreeDBButtonListener( TagEditorFrame tagEditorFrame ) {
56      this.tagEditorFrame = tagEditorFrame;
57    }
58  
59  
60    /**
61     *  Perform a freedb connection retreive all the available data and build the
62     *  dialog
63     *
64     * @param  e  the event
65     */
66    public void actionPerformed( ActionEvent e ) {
67      currentAlbum = tagEditorFrame.getMP3AlbumTableModel().getMP3Album();
68  
69    FreeDBIDCalculator fdbidc = new FreeDBIDCalculator();
70    FreeDBConnection fdbc = new FreeDBConnection();
71    String answer = fdbc.query( fdbidc.getCommand( currentAlbum ) );
72    FreeDBQueryResult[] fdbqr = FreeDBParser.readQueryAnswer( answer );
73      if ( fdbqr != null ) {
74        System.out.println( Entagged.langage.getProperty( "freedbdialog.searchsuccessful" ).replaceAll( "%1", new Integer( fdbqr.length ).toString() ) );
75        System.out.println( "\t" + Entagged.langage.getProperty( "freedbdialog.readingresults" ) );
76      FreeDBReadResult[] fdbrr = new FreeDBReadResult[fdbqr.length];
77        for ( int h = 0; h < fdbqr.length; h++ ) {
78          answer = fdbc.query( fdbqr[h].getCommand() );
79          fdbrr[h] = FreeDBParser.readReadAnswer( answer );
80          System.out.println( "\t" + Entagged.langage.getProperty( "freedbdialog.resultof" ).replaceAll( "%1", new Integer( h + 1 ).toString() ).replaceAll( "%2", new Integer( fdbqr.length ).toString() ).replaceAll( "%3", new Integer( ( h + 1 ) * 100 / fdbqr.length ).toString() ) );
81        }
82  
83      //Display the dialog containing the informations
84      FreeDBDialog dialog = new FreeDBDialog( tagEditorFrame, fdbrr );
85        dialog.setVisible( true );
86      }
87      else
88        System.out.println( Entagged.langage.getProperty( "freedbdialog.noresult" ) );
89    }
90  }
91