[Schmitzm-commits] r2358 - in trunk: schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3 schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Wed Jul 17 23:57:52 CEST 2013


Author: mojays
Date: 2013-07-17 23:57:52 +0200 (Wed, 17 Jul 2013)
New Revision: 2358

Added:
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AudioCDInformationFrame.java
Modified:
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagField.java
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java
   trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle.properties
   trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle_de.properties
Log:
ID3TagField extended with "AudioCD" (only for ID3v2; TXXX frame used for AudioCD information, e.g. serial number)

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2013-07-12 21:40:49 UTC (rev 2357)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2013-07-17 21:57:52 UTC (rev 2358)
@@ -321,8 +321,8 @@
 ListMaintainancePanel.action.moveDown=Runter
 ListMaintainancePanel.action.moveDown.desc=Ausgew\u00e4hlte Elemente in der Liste nach unten/hinten verschieben
 
-AbstractMutableListPanel.action.add=Hinzufügen
+AbstractMutableListPanel.action.add=Hinzuf\u00fcgen
 AbstractMutableListPanel.action.remove=Entfernen
-AbstractMutableListPanel.action.remove.conf.title=Löschen...
-AbstractMutableListPanel.action.remove.conf.mess=Alle ${0} ausgewählten Elemente werden gelöscht. Aktion fortsetzen?
-AbstractMutableListPanel.action.remove.err.mess=Keine Datensätze ausgewählt!
+AbstractMutableListPanel.action.remove.conf.title=L\u00f6schen...
+AbstractMutableListPanel.action.remove.conf.mess=Alle ${0} ausgew\u00e4hlten Elemente werden gel\u00f6scht. Aktion fortsetzen?
+AbstractMutableListPanel.action.remove.err.mess=Keine Datens\u00e4tze ausgew\u00e4hlt!

Added: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AudioCDInformationFrame.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AudioCDInformationFrame.java	                        (rev 0)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/AudioCDInformationFrame.java	2013-07-17 21:57:52 UTC (rev 2358)
@@ -0,0 +1,111 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.mp3.id3;
+
+import org.apache.commons.lang.StringUtils;
+import org.blinkenlights.jid3.ID3Exception;
+import org.blinkenlights.jid3.v2.MCDIID3V2Frame;
+import org.blinkenlights.jid3.v2.TXXXTextInformationID3V2Frame;
+
+/**
+ * User defined frame which is used to hold AudioCD information.
+ * Instead if the super class {@link TXXXTextInformationID3V2Frame} this 
+ * implementation allows {@code null} information!
+ * @author Martin O.J. Schmitz
+ */
+public class AudioCDInformationFrame extends TXXXTextInformationID3V2Frame {
+  /** Static ID used as description for the frame. */
+  public static final String FRAME_ID = "AUDIOCD";
+  /** Static identifier used to indicate empty information. */ 
+  public static final String EMPTY_INFO = "<AUDIOCD empty>";
+  
+
+  /**
+   * Creates a frame.
+   */
+  public AudioCDInformationFrame(String info) throws ID3Exception {
+    super(FRAME_ID, EMPTY_INFO);
+    setAudioCDInformation(info);
+  }
+
+  /**
+   * Creates an empty frame.
+   */
+  public AudioCDInformationFrame() throws ID3Exception {
+    this((String)null);
+  }
+  
+  /**
+   * Creates a frame.
+   */
+  public AudioCDInformationFrame(TXXXTextInformationID3V2Frame frame) throws ID3Exception {
+    this(frame.getInformation());
+  }
+  
+  /**
+   * Returns the audio CD information.
+   */
+  @Override
+  public String getInformation() {
+    String info = super.getInformation();
+    if ( EMPTY_INFO.equals(info) )
+      return null;
+    return info;
+  }
+
+  /**
+   * Returns the audio CD information. Alias for {@link #getInformation()}.
+   */
+  public String getAudioCDInformation() {
+    return getInformation();
+ }
+
+  /**
+   * Sets the frame information. The parameter {@code desc} is ignored.
+   * Always the static id {@link #FRAME_ID} is used!
+   */
+  @Override
+  public void setDescriptionAndInformation(String desc, String info) throws ID3Exception {
+    if ( StringUtils.isBlank(info) )
+      info = EMPTY_INFO;
+    super.setDescriptionAndInformation(FRAME_ID, info);
+  }
+
+  /**
+   * Sets the audio CD information. Alias for
+   * {@link #setDescriptionAndInformation(String, String) setDescriptionAndInformation(..., info)}.
+   */
+  public void setAudioCDInformation(String info) throws ID3Exception {
+    if ( StringUtils.isBlank(info) )
+      info = EMPTY_INFO;
+    setDescriptionAndInformation(FRAME_ID, info);
+  }
+
+}

Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagField.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagField.java	2013-07-12 21:40:49 UTC (rev 2357)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagField.java	2013-07-17 21:57:52 UTC (rev 2358)
@@ -27,7 +27,9 @@
   /** Genre */
   GENRE,
   /** Comment for file. */
-  COMMENT;
+  COMMENT,
+  /** Audio CD information from MCDI frame (only ID3v2). */
+  AUDIOCD;
   
   /**
    * Returns a title for ID3-Tag field.
@@ -49,6 +51,7 @@
       case GENRE: return ID3TagUtil.R("ID3Tag.Genre");
       case YEAR: return ID3TagUtil.R("ID3Tag.Year");
       case COMMENT: return ID3TagUtil.R("ID3Tag.Comment");
+      case AUDIOCD: return ID3TagUtil.R("ID3Tag.AudioCD");
     }
     throw new UnsupportedOperationException("Unknown enum: "+field);
   }

Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java	2013-07-12 21:40:49 UTC (rev 2357)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java	2013-07-17 21:57:52 UTC (rev 2358)
@@ -43,6 +43,8 @@
 import org.blinkenlights.jid3.v2.ContentType;
 import org.blinkenlights.jid3.v2.ID3V2Tag;
 import org.blinkenlights.jid3.v2.ID3V2_3_0Tag;
+import org.blinkenlights.jid3.v2.MCDIID3V2Frame;
+import org.blinkenlights.jid3.v2.TXXXTextInformationID3V2Frame;
 
 import de.schmitzm.lang.LangUtil;
 import de.schmitzm.lang.ResourceProvider;
@@ -282,6 +284,31 @@
   
   
   /**
+   * Returns the content of the MCDI frame of the ID3v2 tag.
+   * @return {@code null} if given tag is not {@link ID3V2_3_0Tag}
+   */
+  public static String getAudioCDInformation(ID3V2Tag tag) {
+    if ( !(tag instanceof ID3V2_3_0Tag) )
+      return null;
+    AudioCDInformationFrame audioCDFrame = null;
+    for (TXXXTextInformationID3V2Frame frame : ((ID3V2_3_0Tag)tag).getTXXXTextInformationFrames()) {
+      if ( frame instanceof AudioCDInformationFrame ) {
+        audioCDFrame = (AudioCDInformationFrame)frame;
+        break;
+      }
+      if ( AudioCDInformationFrame.FRAME_ID.equals(frame.getDescription()) )
+        try {
+          audioCDFrame = new AudioCDInformationFrame(frame);
+          break;
+        } catch (ID3Exception e) {
+        }
+    }
+    if ( audioCDFrame == null )
+      return null;
+    return audioCDFrame.getAudioCDInformation();
+  }
+  
+  /**
    * Returns a basic field from ID3-Tag regardless of the ID3Tag version.
    * @param tag ID3-Tag to determine the field from
    * @param field field to determine
@@ -351,7 +378,9 @@
                       return ((ID3V1Tag)tag).getComment();
                     if ( tag instanceof ID3V2Tag )
                       return ((ID3V2Tag)tag).getComment();
-      break;
+      case AUDIOCD: if ( tag instanceof ID3V2_3_0Tag )
+                      return getAudioCDInformation( (ID3V2_3_0Tag)tag );
+                    return null;
     }
     return null;
   }
@@ -499,6 +528,21 @@
     else
       tag.setComment(value);
   }
+  
+  /**
+   * Sets the MCDI frame of the ID3v2 tag.
+   * @param tag
+   * @param info
+   * @throws ID3Exception if given tag is not {@link ID3V2_3_0Tag}
+   */
+  public static void setAudioCDInformation(ID3V2Tag tag, String info) throws ID3Exception {
+    if ( info != null && !(tag instanceof ID3V2_3_0Tag) )
+      throw new ID3Exception("ID3 tag does not support audio CD information: "+LangUtil.getSimpleClassName(tag));
+    ID3V2_3_0Tag id3v2 = (ID3V2_3_0Tag)tag;
+    id3v2.removeTXXXTextInformationFrame( AudioCDInformationFrame.FRAME_ID );
+    if ( !StringUtils.isBlank(info) )
+      id3v2.addTXXXTextInformationFrame( new AudioCDInformationFrame(info) );
+  }
 
   /**
    * Sets a basic field from ID3-Tag regardless of the ID3Tag version.
@@ -548,7 +592,10 @@
                       ((ID3V1Tag)tag).setComment(value);
                     if ( tag instanceof ID3V2Tag )
                       setComment((ID3V2Tag)tag, value);
-      break;
+                    break;
+      case AUDIOCD: if ( tag instanceof ID3V2_3_0Tag )
+                      setAudioCDInformation((ID3V2Tag) tag, value);
+                    break;
     }
   }
 
@@ -613,7 +660,8 @@
    * Creates a new ID3 Tag v2.3.0 instance.
    */
   public static ID3V2_3_0Tag createID3V2_3_0() throws ID3Exception {
-    return new ID3V2_3_0Tag();
+    ID3V2_3_0Tag tag = new ID3V2_3_0Tag();
+    return tag;
   }
   
   /**

Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java	2013-07-12 21:40:49 UTC (rev 2357)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java	2013-07-17 21:57:52 UTC (rev 2358)
@@ -50,6 +50,9 @@
   protected BooleanInputOption totalTracksCheckbox;
   protected ManualInputOption.Integer totalTracks;
 
+  protected BooleanInputOption audioCDInfoCheckbox;
+  protected ManualInputOption.Text audioCDInfo;
+
   /**
    * Creates a new panel.
    */
@@ -63,11 +66,18 @@
     totalTracksCheckbox = new BooleanInputOption(null, false);
     totalTracksCheckbox.connectInputOptions(true,totalTracks);
     
+    audioCDInfo = new ManualInputOption.Text(null);
+    audioCDInfoCheckbox = new BooleanInputOption(ID3TagUtil.R("ID3Tag.AudioCD"), false);
+    audioCDInfoCheckbox.connectInputOptions(true,audioCDInfo);
+
     add(totalTracksCaption,"aligny center, cell 1 3, gap 7! 7!");
     add(totalTracksCheckbox,"cell 1 3");
     add(totalTracks,"cell 1 3, w 50");
-  }
 
+    add(audioCDInfoCheckbox,"");
+    add(audioCDInfo,"growx");
+}
+
   /**
    * Returns whether a tag fields is enabled.
    */
@@ -75,6 +85,7 @@
   public boolean isFieldEnabled(ID3TagField field) {
     switch (field) {
       case TOTALTRACKS: return totalTracksCheckbox.getValue();
+      case AUDIOCD:     return audioCDInfoCheckbox.getValue();
     }
     return super.isFieldEnabled(field);
   }
@@ -90,6 +101,8 @@
     super.clear(force);
     if ( force || totalTracksCheckbox.getValue() )
       totalTracks.setValue(null);
+    if ( force || audioCDInfoCheckbox.getValue() )
+      audioCDInfo.setValue(null);
   }
   
 
@@ -111,6 +124,7 @@
       year.setValue( null );
       genre.setValue( null );
       comment.setValue( null );
+      audioCDInfo.setValue( null );
       // TODO: add more ID3v2 options
       return;
     }
@@ -130,6 +144,8 @@
       genre.setSelectedDisplayItem( tag.getGenre() );
     if ( force || commentCheckbox.getValue() )
       comment.setValue( tag.getComment() );
+    if ( force || audioCDInfoCheckbox.getValue() )
+      audioCDInfo.setValue( ID3TagUtil.getAudioCDInformation(tag) );
     // TODO: add more ID3v2 options
   }
   
@@ -157,6 +173,8 @@
       ID3TagUtil.setGenre(tag, genre.getValue() == null ? null : ((Genre)genre.getValue()).toString());
     if ( commentCheckbox.getValue() )
       ID3TagUtil.setComment(tag, comment.getValue());
+    if ( audioCDInfoCheckbox.getValue() )
+      ID3TagUtil.setAudioCDInformation(tag, audioCDInfo.getValue());
     // TODO: add more ID3v2 options
   }
 
@@ -194,6 +212,8 @@
       tag2.setGenre( tag1.getGenre() );
     if ( commentCheckbox.getValue() )
       tag2.setComment( tag1.getComment() );
+    if ( audioCDInfoCheckbox.getValue() )
+      ID3TagUtil.setAudioCDInformation(tag2, ID3TagUtil.getAudioCDInformation(tag1));
     // TODO: add more ID3v2 options
   }
 }

Modified: trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle.properties
===================================================================
--- trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle.properties	2013-07-12 21:40:49 UTC (rev 2357)
+++ trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle.properties	2013-07-17 21:57:52 UTC (rev 2358)
@@ -40,6 +40,7 @@
 ID3Tag.Comment=Comment
 ID3Tag.TotalTracks=Total tracks
 ID3Tag.of=of
+ID3Tag.AudioCD=Audio CD
 
 ID3TagUtil.mp3filter.desc=mp3 files
 

Modified: trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle_de.properties	2013-07-12 21:40:49 UTC (rev 2357)
+++ trunk/schmitzm-mp3/src/main/resources/de/schmitzm/mp3/id3/resource/locales/ID3TagResourceBundle_de.properties	2013-07-17 21:57:52 UTC (rev 2358)
@@ -38,6 +38,7 @@
 ID3Tag.Comment=Kommentar
 ID3Tag.TotalTracks=Gesamt Tracks
 ID3Tag.of=von
+ID3Tag.AudioCD=Audio-CD
 
 ID3TagUtil.mp3filter.desc=mp3 Dateien
 



More information about the Schmitzm-commits mailing list