Source code: entagged/gui/tageditor/ID3InfoPanel.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;
23 import entagged.common.*;
24 import entagged.formats.mp3.*;
25 import entagged.gui.*;
26 import entagged.gui.tageditor.dialogs.*;
27 import java.awt.*;
28 import java.awt.event.*;
29 import java.text.DecimalFormat;
30 import java.util.Vector;
31 import javax.swing.*;
32 import javax.swing.border.*;
33
34
35 /**
36 * Creates the Bottom panel of the main windows contains all operations
37 * realtive to the current showing album/selected file $Id: ID3InfoPanel.java,v
38 * 1.6 2003/10/01 20:25:17 kikidonk Exp $
39 *
40 * @author Raphael Slinckx (KiKiDonK)
41 * @version v0.03
42 */
43 public class ID3InfoPanel extends JPanel {
44
45 /** ID3v1 Panel */
46 private JPanel ID3v1TagInfos;
47 /** ID3v2 Panel */
48 private JPanel ID3v2TagInfos;
49 /** ID3v2 Advanced button */
50 private JButton advancedButton;
51 /** Textfields concerning ID3v2 displyed in the ID3v2 Panel */
52 private JTextField artistF, albumF, titleF, trackF, genreF, yearF, commentF;
53 /** Textfields concerning ID3v2 displyed in the ID3v1 Panel */
54 private JTextField artistFv1, albumFv1, titleFv1, trackFv1, yearFv1, commentFv1;
55 /** Various Labels */
56 private JLabel artistL, albumL, titleL, trackL, genreL, yearL, commentL;
57 /** Various Labels */
58 private JLabel artistLv1, albumLv1, titleLv1, trackLv1, genreLv1, yearLv1, commentLv1;
59 /** Copy from ID3v1 Button */
60 private JButton copyFromV1Button;
61 /** Copy from ID3v2 Button */
62 private JButton copyFromV2Button;
63 /** ID3v1 Genre combo box */
64 private JComboBox genreFv1;
65 /** Save buttons for ID3 tags */
66 private JButton saveButton, saveButtonv1;
67 /**
68 * Vector containing the selected MP3 in the table (used because of the mutlti
69 * selection)
70 */
71 private Vector selectedMP3;
72 /**
73 * Vector containing the track numbers of the corresponding selected MP3 (MP3
74 * itself could be used, but information isn't secure)
75 */
76 private Vector selectedMP3TrackNb;
77 /** Parent Tag Editor Frame */
78 private TagEditorFrame tagEditorFrame;
79
80
81 /**
82 * Build the Panel
83 *
84 * @param tagEditorFrame Parent Tag Editor Frame
85 */
86 public ID3InfoPanel( TagEditorFrame tagEditorFrame ) {
87 this.tagEditorFrame = tagEditorFrame;
88 selectedMP3 = new Vector();
89 selectedMP3TrackNb = new Vector();
90
91 //V2 tag***********************************
92 artistL = new JLabel( Entagged.langage.getProperty( "common.tag.artist" ) );
93 albumL = new JLabel( Entagged.langage.getProperty( "common.tag.album" ) );
94 titleL = new JLabel( Entagged.langage.getProperty( "common.tag.title" ) );
95 trackL = new JLabel( Entagged.langage.getProperty( "common.tag.track" ) );
96 genreL = new JLabel( Entagged.langage.getProperty( "common.tag.genre" ) );
97 yearL = new JLabel( Entagged.langage.getProperty( "common.tag.year" ) );
98 commentL = new JLabel( Entagged.langage.getProperty( "common.tag.comment" ) );
99
100 artistF = new JTextField();
101 albumF = new JTextField();
102 titleF = new JTextField();
103 trackF = new JTextField();
104 genreF = new JTextField();
105 yearF = new JTextField();
106 commentF = new JTextField();
107
108 saveButton = new JButton( Entagged.langage.getProperty( "common.dialog.save" ) );
109 saveButton.addActionListener( new SaveButtonListener( SaveButtonListener.ID3v2 ) );
110 advancedButton = new JButton( Entagged.langage.getProperty( "common.dialog.advanced" ) );
111 advancedButton.addActionListener( new AdvancedButtonListener() );
112 advancedButton.setEnabled( false );
113 copyFromV1Button = new JButton( Entagged.langage.getProperty( "id3infopanel.copyfromid3v1" ) );
114 copyFromV1Button.addActionListener( new CopyFromV1ButtonListener() );
115 //*******************************************
116
117
118 //V1 tag*************************************
119 artistLv1 = new JLabel( Entagged.langage.getProperty( "common.tag.artist" ) );
120 albumLv1 = new JLabel( Entagged.langage.getProperty( "common.tag.album" ) );
121 titleLv1 = new JLabel( Entagged.langage.getProperty( "common.tag.title" ) );
122 trackLv1 = new JLabel( Entagged.langage.getProperty( "common.tag.track" ) );
123 genreLv1 = new JLabel( Entagged.langage.getProperty( "common.tag.genre" ) );
124 yearLv1 = new JLabel( Entagged.langage.getProperty( "common.tag.year" ) );
125 commentLv1 = new JLabel( Entagged.langage.getProperty( "common.tag.comment" ) );
126
127 artistFv1 = new JTextField();
128 albumFv1 = new JTextField();
129 titleFv1 = new JTextField();
130 trackFv1 = new JTextField();
131 genreFv1 = new JComboBox( Utils.genres );
132 genreFv1.setSelectedIndex( Integer.parseInt( Utils.EMPTY_INDEX ) );
133 yearFv1 = new JTextField();
134 commentFv1 = new JTextField();
135
136 saveButtonv1 = new JButton( Entagged.langage.getProperty( "common.dialog.save" ) );
137 saveButtonv1.addActionListener( new SaveButtonListener( SaveButtonListener.ID3v1 ) );
138 copyFromV2Button = new JButton( Entagged.langage.getProperty( "id3infopanel.copyfromid3v2" ) );
139 copyFromV2Button.addActionListener( new CopyFromV2ButtonListener() );
140 //*********************************************
141
142 //V2 Container Panel and layout********
143 createID3v2TagInfoPanel();
144
145 //V1 Container Panel and layout********
146 createID3v1TagInfoPanel();
147
148 //Create Borders**************************
149 Border ID3Border = BorderFactory.createEtchedBorder();
150 TitledBorder ID3v2TitledBorder = BorderFactory.createTitledBorder( ID3Border, Entagged.langage.getProperty( "id3infopanel.bordertitle_id3v2" ), TitledBorder.LEFT, TitledBorder.TOP );
151 ID3v2TagInfos.setBorder( ID3v2TitledBorder );
152
153 TitledBorder ID3v1TitledBorder = BorderFactory.createTitledBorder( ID3Border, Entagged.langage.getProperty( "id3infopanel.bordertitle_id3v1" ), TitledBorder.LEFT, TitledBorder.TOP );
154 ID3v1TagInfos.setBorder( ID3v1TitledBorder );
155 //****************************************
156
157
158 //Put the 2 idv1 and idv2 panels in a temp Panel*********
159 JPanel cont = new JPanel();
160 cont.setLayout( new GridLayout( 1, 2 ) );
161 cont.add( ID3v2TagInfos );
162 cont.add( ID3v1TagInfos );
163 //***********************************************************
164
165 //Layout the bottom space***********************************
166 this.setLayout( new BorderLayout() );
167 this.add( cont, "Center" );
168 //**********************************************************
169 }
170
171
172 /**
173 * get the selected mp3's vector containing the selected mp3files
174 *
175 * @return The selectedMP3 Vector
176 */
177 public Vector getSelectedMP3() {
178 return this.selectedMP3;
179 }
180
181
182 /**
183 * get the selected mp3's vector containing the selected mp3files real
184 * (alphabetical) track numbers
185 *
186 * @return The selectedMP3TrackNb Vector
187 */
188 public Vector getSelectedMP3TrackNb() {
189 return this.selectedMP3TrackNb;
190 }
191
192
193 /**
194 * This method is used whenever a mp3 file is added to the selection, it
195 * updates the fields of the id3 tags and eventually put a "Varies" text if
196 * needed
197 *
198 * @param mp3 the mp3 that is added
199 * @param trackNb the track number of this mp3
200 */
201 public void add( MP3File mp3, int trackNb ) {
202 selectedMP3.add( mp3 );
203 selectedMP3TrackNb.add( new Integer( trackNb ) );
204
205 if ( selectedMP3.size() == 1 )
206 advancedButton.setEnabled( true );
207 else
208 advancedButton.setEnabled( false );
209
210 ID3v2Tag tag = mp3.getID3v2Tag();
211 ID3v1Tag tagv1 = mp3.getID3v1Tag();
212
213 //V2 Tag
214 //Artist Processing************************************************************
215 String artist;
216 if ( tag.getArtist() == null )
217 artist = "";
218 else
219 artist = tag.getArtist();
220 if ( !artist.equals( artistF.getText() ) && !artistF.getText().equals( "" ) )
221 artistF.setText( Utils.VARIES );
222 else
223 artistF.setText( artist );
224
225 //Album Processing
226 String album;
227 if ( tag.getAlbum() == null )
228 album = "";
229 else
230 album = tag.getAlbum();
231 if ( !album.equals( albumF.getText() ) && !albumF.getText().equals( "" ) )
232 albumF.setText( Utils.VARIES );
233 else
234 albumF.setText( album );
235
236 //Title Processing
237 String title;
238 if ( tag.getTitle() == null )
239 title = "";
240 else
241 title = tag.getTitle();
242 if ( !title.equals( titleF.getText() ) && !titleF.getText().equals( "" ) )
243 titleF.setText( Utils.VARIES );
244 else
245 titleF.setText( title );
246
247 //Track nb processing
248 String tracknb;
249 if ( tag.getTrackNumber() == null )
250 tracknb = "";
251 else
252 tracknb = tag.getTrackNumber();
253 if ( !tracknb.equals( trackF.getText() ) && !trackF.getText().equals( "" ) )
254 trackF.setText( Utils.VARIES );
255 else
256 trackF.setText( tracknb );
257
258 //Genre Procesing
259 String genre;
260 if ( tag.getGenre() == null )
261 genre = "";
262 else
263 genre = tag.getGenre();
264 if ( !genre.equals( genreF.getText() ) && !genreF.getText().equals( "" ) )
265 genreF.setText( Utils.VARIES );
266 else
267 genreF.setText( genre );
268
269 //Comment Processing
270 String comment;
271 if ( tag.getPrintableComment() == null )
272 comment = "";
273 else
274 comment = tag.getPrintableComment();
275 if ( !comment.equals( commentF.getText() ) && !commentF.getText().equals( "" ) )
276 commentF.setText( Utils.VARIES );
277 else
278 commentF.setText( comment );
279
280 //Year Processing
281 String year;
282 if ( tag.getYear() == null )
283 year = "";
284 else
285 year = tag.getYear();
286 if ( !year.equals( yearF.getText() ) && !yearF.getText().equals( "" ) )
287 yearF.setText( Utils.VARIES );
288 else
289 yearF.setText( year );
290 //***********************************************************************************
291
292 //V1 Tag*****************************************************************************
293 //Artist Processing
294 if ( !tagv1.getArtist().equals( artistFv1.getText() ) && !artistFv1.getText().equals( "" ) )
295 artistFv1.setText( Utils.VARIES );
296 else
297 artistFv1.setText( tagv1.getArtist() );
298
299 //Album Processing
300 if ( !tagv1.getAlbum().equals( albumFv1.getText() ) && !albumFv1.getText().equals( "" ) )
301 albumFv1.setText( Utils.VARIES );
302 else
303 albumFv1.setText( tagv1.getAlbum() );
304 //albumF.setText(tag.get());
305
306 //titleF.setText(tag.getTitle());
307 if ( !tagv1.getTitle().equals( titleFv1.getText() ) && !titleFv1.getText().equals( "" ) )
308 titleFv1.setText( Utils.VARIES );
309 else
310 titleFv1.setText( tagv1.getTitle() );
311
312 //Track nb processing
313 //trackF.setText(tag.getTrackNumber());
314 if ( !tagv1.getTrackNumber().equals( trackFv1.getText() ) && !trackFv1.getText().equals( "" ) )
315 trackFv1.setText( Utils.VARIES );
316 else
317 trackFv1.setText( tagv1.getTrackNumber() );
318
319 //Genre Procesing
320 //genreF.setText(tag.getGenre());
321 if ( tagv1.getGenreIndexString().equals( "-1" ) )
322 genreFv1.setSelectedItem( Utils.EMPTY );
323 else
324 if ( !tagv1.getGenreIndexString().equals( Integer.toString( genreFv1.getSelectedIndex() ) ) && !( Integer.toString( genreFv1.getSelectedIndex() ) ).equals( Utils.EMPTY_INDEX ) )
325 genreFv1.setSelectedItem( Utils.VARIES );
326 else
327 genreFv1.setSelectedIndex( Integer.parseInt( tagv1.getGenreIndexString() ) );
328
329 //Comment Processing
330 //commentF.setText(tag.getComment());
331 if ( !tagv1.getComment().equals( commentFv1.getText() ) && !commentFv1.getText().equals( "" ) )
332 commentFv1.setText( Utils.VARIES );
333 else
334 commentFv1.setText( tagv1.getComment() );
335
336 //Year Processing
337 //yearF.setText(tag.getYear());
338 if ( !tagv1.getYear().equals( yearFv1.getText() ) && !yearFv1.getText().equals( "" ) )
339 yearFv1.setText( Utils.VARIES );
340 else
341 yearFv1.setText( tagv1.getYear() );
342 //***********************************************************************************
343 }
344
345
346 /** Cleans the ID3Info Panel (textfileds...) */
347 public void clean() {
348 this.artistF.setText( "" );
349 this.albumF.setText( "" );
350 this.titleF.setText( "" );
351 this.trackF.setText( "" );
352 this.genreF.setText( "" );
353 this.yearF.setText( "" );
354 this.commentF.setText( "" );
355 this.artistFv1.setText( "" );
356 this.albumFv1.setText( "" );
357 this.titleFv1.setText( "" );
358 this.trackFv1.setText( "" );
359 this.yearFv1.setText( "" );
360 this.commentFv1.setText( "" );
361 this.genreFv1.setSelectedIndex( Integer.parseInt( Utils.EMPTY_INDEX ) );
362 this.selectedMP3.removeAllElements();
363 this.selectedMP3TrackNb.removeAllElements();
364 }
365
366
367 /** Creates id3v1 fileds etc */
368 private void createID3v1TagInfoPanel() {
369 this.ID3v1TagInfos = new JPanel();
370 GridBagLayout gbl = new GridBagLayout();
371
372 GridBagConstraints gbc = new GridBagConstraints();
373 gbc.insets = new Insets( 2, 1, 2, 1 );
374 gbc.weightx = 1;
375 gbc.weighty = 1;
376
377 this.ID3v1TagInfos.setLayout( gbl );
378
379 gbc.gridx = 0;
380 gbc.gridy = 0;
381 gbc.anchor = GridBagConstraints.EAST;
382 gbl.setConstraints( this.artistLv1, gbc );
383 this.ID3v1TagInfos.add( this.artistLv1 );
384
385 gbc.gridx = 0;
386 gbc.gridy = 1;
387 gbl.setConstraints( this.albumLv1, gbc );
388 this.ID3v1TagInfos.add( this.albumLv1 );
389
390 gbc.gridx = 0;
391 gbc.gridy = 2;
392 gbl.setConstraints( this.titleLv1, gbc );
393 this.ID3v1TagInfos.add( this.titleLv1 );
394
395 gbc.gridx = 0;
396 gbc.gridy = 3;
397 gbl.setConstraints( this.trackLv1, gbc );
398 this.ID3v1TagInfos.add( this.trackLv1 );
399
400 gbc.gridx = 0;
401 gbc.gridy = 4;
402 gbl.setConstraints( this.commentLv1, gbc );
403 this.ID3v1TagInfos.add( this.commentLv1 );
404
405 gbc.gridx = 0;
406 gbc.gridy = 5;
407 gbl.setConstraints( this.genreLv1, gbc );
408 this.ID3v1TagInfos.add( this.genreLv1 );
409
410 gbc.gridx = 0;
411 gbc.gridy = 7;
412 gbc.gridwidth = 4;
413 gbc.fill = GridBagConstraints.HORIZONTAL;
414 gbl.setConstraints( this.saveButtonv1, gbc );
415 this.ID3v1TagInfos.add( this.saveButtonv1 );
416
417 gbc.gridx = 1;
418 gbc.gridy = 0;
419 gbc.gridwidth = 3;
420 gbc.anchor = GridBagConstraints.WEST;
421 gbl.setConstraints( this.artistFv1, gbc );
422 this.ID3v1TagInfos.add( this.artistFv1 );
423
424 gbc.gridx = 1;
425 gbc.gridy = 1;
426 gbc.gridwidth = 3;
427 gbl.setConstraints( this.albumFv1, gbc );
428 this.ID3v1TagInfos.add( this.albumFv1 );
429
430 gbc.gridx = 1;
431 gbc.gridy = 2;
432 gbc.gridwidth = 3;
433 gbl.setConstraints( this.titleFv1, gbc );
434 this.ID3v1TagInfos.add( this.titleFv1 );
435
436 gbc.gridx = 1;
437 gbc.gridy = 3;
438 gbc.gridwidth = 1;
439 gbl.setConstraints( this.trackFv1, gbc );
440 this.ID3v1TagInfos.add( this.trackFv1 );
441
442 gbc.gridx = 1;
443 gbc.gridy = 4;
444 gbc.gridwidth = 3;
445 gbl.setConstraints( this.commentFv1, gbc );
446 this.ID3v1TagInfos.add( this.commentFv1 );
447
448 gbc.gridx = 1;
449 gbc.gridy = 5;
450 gbc.gridwidth = 3;
451 gbl.setConstraints( this.genreFv1, gbc );
452 this.ID3v1TagInfos.add( this.genreFv1 );
453
454 gbc.gridx = 2;
455 gbc.gridy = 3;
456 gbc.gridwidth = 1;
457 gbc.anchor = GridBagConstraints.EAST;
458 gbc.fill = GridBagConstraints.NONE;
459 gbl.setConstraints( this.yearLv1, gbc );
460 this.ID3v1TagInfos.add( this.yearLv1 );
461
462 gbc.gridx = 3;
463 gbc.gridy = 3;
464 gbc.gridwidth = 1;
465 gbc.anchor = GridBagConstraints.WEST;
466 gbc.fill = GridBagConstraints.HORIZONTAL;
467 gbl.setConstraints( this.yearFv1, gbc );
468 this.ID3v1TagInfos.add( this.yearFv1 );
469
470 gbc.gridx = 0;
471 gbc.gridy = 6;
472 gbc.gridwidth = 4;
473 gbc.anchor = GridBagConstraints.CENTER;
474 gbc.fill = GridBagConstraints.NONE;
475 gbl.setConstraints( this.copyFromV2Button, gbc );
476 this.ID3v1TagInfos.add( this.copyFromV2Button );
477 }
478
479
480 /** Creates id3v2 fields */
481 private void createID3v2TagInfoPanel() {
482 this.ID3v2TagInfos = new JPanel();
483 GridBagLayout gbl = new GridBagLayout();
484
485 GridBagConstraints gbc = new GridBagConstraints();
486 gbc.insets = new Insets( 2, 1, 2, 1 );
487 gbc.weightx = 1;
488 gbc.weighty = 1;
489
490 this.ID3v2TagInfos.setLayout( gbl );
491
492 gbc.gridx = 0;
493 gbc.gridy = 0;
494 gbc.anchor = GridBagConstraints.EAST;
495 gbl.setConstraints( this.artistL, gbc );
496 this.ID3v2TagInfos.add( this.artistL );
497
498 gbc.gridx = 0;
499 gbc.gridy = 1;
500 gbl.setConstraints( this.albumL, gbc );
501 this.ID3v2TagInfos.add( this.albumL );
502
503 gbc.gridx = 0;
504 gbc.gridy = 2;
505 gbl.setConstraints( this.titleL, gbc );
506 this.ID3v2TagInfos.add( this.titleL );
507
508 gbc.gridx = 0;
509 gbc.gridy = 3;
510 gbl.setConstraints( this.trackL, gbc );
511 this.ID3v2TagInfos.add( this.trackL );
512
513 gbc.gridx = 0;
514 gbc.gridy = 4;
515 gbl.setConstraints( this.commentL, gbc );
516 this.ID3v2TagInfos.add( this.commentL );
517
518 gbc.gridx = 0;
519 gbc.gridy = 5;
520 gbl.setConstraints( this.genreL, gbc );
521 this.ID3v2TagInfos.add( this.genreL );
522
523 gbc.gridx = 0;
524 gbc.gridy = 7;
525 gbc.gridwidth = 2;
526 gbc.fill = GridBagConstraints.HORIZONTAL;
527 gbl.setConstraints( this.saveButton, gbc );
528 this.ID3v2TagInfos.add( this.saveButton );
529
530 gbc.gridx = 1;
531 gbc.gridy = 0;
532 gbc.gridwidth = 3;
533 gbc.anchor = GridBagConstraints.WEST;
534 gbl.setConstraints( this.artistF, gbc );
535 this.ID3v2TagInfos.add( this.artistF );
536
537 gbc.gridx = 1;
538 gbc.gridy = 1;
539 gbc.gridwidth = 3;
540 gbl.setConstraints( this.albumF, gbc );
541 this.ID3v2TagInfos.add( this.albumF );
542
543 gbc.gridx = 1;
544 gbc.gridy = 2;
545 gbc.gridwidth = 3;
546 gbl.setConstraints( this.titleF, gbc );
547 this.ID3v2TagInfos.add( this.titleF );
548
549 gbc.gridx = 1;
550 gbc.gridy = 3;
551 gbc.gridwidth = 1;
552 gbl.setConstraints( this.trackF, gbc );
553 this.ID3v2TagInfos.add( this.trackF );
554
555 gbc.gridx = 1;
556 gbc.gridy = 4;
557 gbc.gridwidth = 3;
558 gbl.setConstraints( this.commentF, gbc );
559 this.ID3v2TagInfos.add( this.commentF );
560
561 gbc.gridx = 1;
562 gbc.gridy = 5;
563 gbc.gridwidth = 3;
564 gbl.setConstraints( this.genreF, gbc );
565 this.ID3v2TagInfos.add( this.genreF );
566
567 gbc.gridx = 2;
568 gbc.gridy = 3;
569 gbc.gridwidth = 1;
570 gbc.anchor = GridBagConstraints.EAST;
571 gbc.fill = GridBagConstraints.NONE;
572 gbl.setConstraints( this.yearL, gbc );
573 this.ID3v2TagInfos.add( this.yearL );
574
575 gbc.gridx = 2;
576 gbc.gridy = 7;
577 gbc.gridwidth = 2;
578 gbc.anchor = GridBagConstraints.WEST;
579 gbc.fill = GridBagConstraints.HORIZONTAL;
580 gbl.setConstraints( this.advancedButton, gbc );
581 this.ID3v2TagInfos.add( this.advancedButton );
582
583 gbc.gridx = 3;
584 gbc.gridy = 3;
585 gbc.gridwidth = 1;
586 gbl.setConstraints( this.yearF, gbc );
587 this.ID3v2TagInfos.add( this.yearF );
588
589 gbc.gridx = 0;
590 gbc.gridy = 6;
591 gbc.gridwidth = 4;
592 gbc.anchor = GridBagConstraints.CENTER;
593 gbc.fill = GridBagConstraints.NONE;
594 gbl.setConstraints( this.copyFromV1Button, gbc );
595 this.ID3v2TagInfos.add( this.copyFromV1Button );
596 }
597
598
599 /**
600 * This listens for an event on the advanced button in id3v2 panel and shows a
601 * dialog allowing to add custom fields
602 *
603 * @author Raphael Slinckx (KiKiDonK)
604 * @version v0.03
605 */
606 private class AdvancedButtonListener implements ActionListener {
607 /**
608 * opens the dialog allowing to add custom id3v2 fields and their contents
609 *
610 * @param e the event
611 */
612 public void actionPerformed( ActionEvent e ) {
613 AdvancedID3v2Dialog advanced = new AdvancedID3v2Dialog( ID3InfoPanel.this.tagEditorFrame );
614 advanced.setVisible( true );
615 }
616 }
617
618
619 /**
620 * This listens for an event on the copy button in id3v2 panel and copy the
621 * data in id3v1 panel
622 *
623 * @author Raphael Slinckx (KiKiDonK)
624 * @version v0.03
625 */
626 private class CopyFromV1ButtonListener implements ActionListener {
627 /**
628 * Copy fields values in id3v1 fields into id3v2 fields
629 *
630 * @param e the event
631 */
632 public void actionPerformed( ActionEvent e ) {
633 String[] fields = Utils.STANDARD_ID3_FIELDS;
634 String[] contents = new String[7];
635
636 for ( int i = 0; i < selectedMP3.size(); i++ ) {
637 contents[0] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v1Tag().getTitle();
638 contents[1] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v1Tag().getArtist();
639 contents[2] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v1Tag().getAlbum();
640 contents[3] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v1Tag().getYear();
641 contents[4] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v1Tag().getComment();
642 contents[5] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v1Tag().getTrackNumber();
643 contents[6] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v1Tag().getGenre();
644
645 ID3v2Tag tagV2 = new ID3v2Tag( fields, contents );
646 ID3Writer id3w = new ID3Writer();
647 id3w.write( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ), null, tagV2 );
648 tagEditorFrame.getMP3AlbumTableModel().updateMP3Track( ( (Integer)ID3InfoPanel.this.selectedMP3TrackNb.get( i ) ).intValue() );
649 }
650
651 artistF.setText( artistFv1.getText() );
652 albumF.setText( albumFv1.getText() );
653 titleF.setText( titleFv1.getText() );
654 trackF.setText( trackFv1.getText() );
655 if ( genreFv1.getSelectedIndex() != Integer.parseInt( Utils.EMPTY_INDEX ) )
656 genreF.setText( (String)genreFv1.getSelectedItem() );
657 else
658 genreF.setText( "" );
659 yearF.setText( yearFv1.getText() );
660 commentF.setText( commentFv1.getText() );
661 }
662 }
663
664
665 /**
666 * This listens for an event on the copy button in id3v1 panel and copy the
667 * data in id3v2 panel
668 *
669 * @author Raphael Slinckx (KiKiDonK)
670 * @version v0.03
671 */
672 private class CopyFromV2ButtonListener implements ActionListener {
673 /**
674 * Copy fields values in id3v2 fields into id3v1 fields
675 *
676 * @param e the event
677 */
678 public void actionPerformed( ActionEvent e ) {
679 String[] contents = new String[7];
680
681 for ( int i = 0; i < selectedMP3.size(); i++ ) {
682 contents[0] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v2Tag().getTitle();
683 contents[1] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v2Tag().getArtist();
684 contents[2] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v2Tag().getAlbum();
685 contents[3] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v2Tag().getYear();
686 contents[4] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v2Tag().getPrintableComment();
687 contents[5] = ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v2Tag().getTrackNumber();
688 contents[6] = Utils.translateGenre( ( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ) ).getID3v2Tag().getGenre() );
689
690 ID3v1Tag tagV1 = new ID3v1Tag( contents );
691 ID3Writer id3w = new ID3Writer();
692 id3w.write( (MP3File)ID3InfoPanel.this.selectedMP3.get( i ), tagV1, null );
693 tagEditorFrame.getMP3AlbumTableModel().updateMP3Track( ( (Integer)ID3InfoPanel.this.selectedMP3TrackNb.get( i ) ).intValue() );
694 }
695
696 artistFv1.setText( artistF.getText() );
697 albumFv1.setText( albumF.getText() );
698 titleFv1.setText( titleF.getText() );
699 trackFv1.setText( trackF.getText() );
700 genreFv1.setSelectedIndex( Integer.parseInt( Utils.translateGenre( genreF.getText() ) ) );
701 yearFv1.setText( yearF.getText() );
702 commentFv1.setText( commentF.getText() );
703 }
704 }
705
706
707 /**
708 * This class listens for events on the save buttons for both id3v1 and id3v2
709 * tags
710 *
711 * @author Raphael Slinckx (KiKiDonK)
712 * @version v0.03
713 */
714 private class SaveButtonListener implements ActionListener {
715
716 /** ID3 tag versions to wich this listener is bound */
717 private int currentID3Version;
718
719 /** Constant to choose id3v1 listening */
720 public final static int ID3v1 = 1;
721
722 /** Constant to choose id3v2 listening */
723 public final static int ID3v2 = 2;
724
725
726 /**
727 * Constructs a new Listener bound to the specified ID3Version (see
728 * constants) !! MAYBE this can be changed in a more elegant way !!
729 *
730 * @param ID3Version the constant holding the ID3 version to wich listener
731 * is bound
732 */
733 public SaveButtonListener( int ID3Version ) {
734 currentID3Version = ID3Version;
735 }
736
737
738 /**
739 * Saves id3v1 or id3v2 tags
740 *
741 * @param e the event
742 */
743 public void actionPerformed( ActionEvent e ) {
744 if ( currentID3Version == ID3v1 )
745 saveID3v1Tag();
746 else
747 saveID3v2Tag();
748 }
749
750
751 /** Saves the id3v1 tag with the corresponding fields data */
752 private void saveID3v1Tag() {
753 //Get ID3v2 data in the Text Fields**********
754 int size = ID3InfoPanel.this.selectedMP3.size();
755 MP3File[] toTag = new MP3File[size];
756 for ( int j = 0; j < size; j++ ) {
757 String title = ID3InfoPanel.this.titleFv1.getText();
758 String artist = ID3InfoPanel.this.artistFv1.getText();
759 String album = ID3InfoPanel.this.albumFv1.getText();
760 String year = ID3InfoPanel.this.yearFv1.getText();
761 String comment = ID3InfoPanel.this.commentFv1.getText();
762 String track = ID3InfoPanel.this.trackFv1.getText();
763 String genre = Integer.toString( ID3InfoPanel.this.genreFv1.getSelectedIndex() );
764
765 title = ( title.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v1Tag().getTitle() : title;
766 artist = ( artist.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v1Tag().getArtist() : artist;
767 album = ( album.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v1Tag().getAlbum() : album;
768 year = ( year.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v1Tag().getYear() : year;
769 comment = ( comment.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v1Tag().getComment() : comment;
770 track = ( track.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v1Tag().getTrackNumber() : track;
771 genre = ( genre.equals( Utils.VARIES_INDEX ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v1Tag().getGenreIndexString() : genre;
772 genre = ( genre.equals( Utils.EMPTY_INDEX ) ) ? Utils.FFGenre : genre;
773 String[] content = {title, artist, album, year, comment, track, genre};
774
775 ID3v1Tag tagV1 = new ID3v1Tag( content );
776 ID3Writer id3w = new ID3Writer();
777 id3w.write( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ), tagV1, null );
778 tagEditorFrame.getMP3AlbumTableModel().updateMP3Track( ( (Integer)ID3InfoPanel.this.selectedMP3TrackNb.get( j ) ).intValue() );
779 }
780
781 }
782
783
784 /** Saves the id3v2 tag with the corresponding fields data */
785 private void saveID3v2Tag() {
786 //Get ID3v2 data in the Text Fields**********
787 int size = ID3InfoPanel.this.selectedMP3.size();
788 MP3File[] toTag = new MP3File[size];
789 for ( int j = 0; j < size; j++ ) {
790 String[] fields = Utils.STANDARD_ID3_FIELDS;
791
792 String title = ID3InfoPanel.this.titleF.getText();
793 String artist = ID3InfoPanel.this.artistF.getText();
794 String album = ID3InfoPanel.this.albumF.getText();
795 String year = ID3InfoPanel.this.yearF.getText();
796 String comment = ID3InfoPanel.this.commentF.getText();
797
798 String track = ID3InfoPanel.this.trackF.getText();
799 String genre = ID3InfoPanel.this.genreF.getText();
800
801 title = ( title.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v2Tag().getTitle() : title;
802 artist = ( artist.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v2Tag().getArtist() : artist;
803 album = ( album.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v2Tag().getAlbum() : album;
804 year = ( year.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v2Tag().getYear() : year;
805 comment = ( comment.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v2Tag().getPrintableComment() : comment;
806 track = ( track.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v2Tag().getTrackNumber() : track;
807 genre = ( genre.equals( Utils.VARIES ) ) ? ( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ) ).getID3v2Tag().getGenre() : genre;
808
809 //track = Utils.formatTrackNumber( ((Integer)ID3InfoPanel.this.selectedMP3TrackNb.get( j)).intValue() , ID3InfoPanel.this.tagEditorFrame.getMP3AlbumTableModel().getMP3Album().getTotalTracks(), Entagged.guiPrefs.get( "tageditor.singletrackformat", "00" ), Entagged.guiPrefs.get( "tageditor.totaltrackformat", "00" ), Entagged.guiPrefs.get( "tageditor.trackpattern", "%1" ) );
810 String[] content = {title, artist, album, year, comment, track, genre};
811
812 ID3v2Tag tagV2 = new ID3v2Tag( fields, content );
813 ID3Writer id3w = new ID3Writer();
814 id3w.write( (MP3File)ID3InfoPanel.this.selectedMP3.get( j ), null, tagV2 );
815 tagEditorFrame.getMP3AlbumTableModel().updateMP3Track( ( (Integer)ID3InfoPanel.this.selectedMP3TrackNb.get( j ) ).intValue() );
816 }
817 }
818 }
819 }
820