[Schmitzm-commits] r2284 - in trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3: . gui

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Mon Mar 25 22:07:57 CET 2013


Author: mojays
Date: 2013-03-25 22:07:57 +0100 (Mon, 25 Mar 2013)
New Revision: 2284

Modified:
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/GUIUtil.java
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3Tag2FilenameParserPanel.java
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagFieldSequencePanel.java
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/StringConversionDialog.java
   trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/StringConversionPanel.java
Log:
ID3TagUtil: BugFix in handling year
GUI building methods in GUIUtil replaced by generic GUIBuilder

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-03-25 21:03:58 UTC (rev 2283)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/ID3TagUtil.java	2013-03-25 21:07:57 UTC (rev 2284)
@@ -335,7 +335,7 @@
       case YEAR:  Integer year = null;
                   if ( tag instanceof ID3V1Tag ) {
                     String yearStr = ((ID3V1Tag)tag).getYear();
-                    year =  (yearStr != null) ? Integer.parseInt(yearStr) : null;
+                    year =  !StringUtils.isBlank(yearStr) ? Integer.parseInt(yearStr) : null;
                   }
                   if ( tag instanceof ID3V2Tag )
                     year = getYear((ID3V2Tag)tag);
@@ -354,6 +354,23 @@
   }
 
   /**
+   * Returns a basic field from ID3-Tag regardless of the ID3Tag version.
+   * @param field field to determine
+   * @param format {@link NumberFormat} to encode year or track number (can be {@code null})
+   * @param tags ID3-Tags to determine the field from (first tag which contains the
+   *             information is taken)
+   * @return {@code null} if field is not provided for any tag
+   */
+  public static String getID3TagField(ID3TagField field, NumberFormat format, ID3Tag... tags) {
+    for (ID3Tag tag : tags) {
+      String value = getID3TagField(tag, field, format);
+      if ( value != null )
+        return value;
+    }
+    return null;
+  }
+
+  /**
    * Sets the title of an ID3 v2 tag. If {@code null} value is given, the
    * header is removed from tag.
    * @param tag tag to modify

Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/GUIUtil.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/GUIUtil.java	2013-03-25 21:03:58 UTC (rev 2283)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/GUIUtil.java	2013-03-25 21:07:57 UTC (rev 2284)
@@ -52,55 +52,55 @@
 public class GUIUtil {
   private static final Logger LOGGER = LangUtil.createLogger(GUIUtil.class);
 
-  /** Font for comment labels in the frames. */
-  public static final Font FONT_COMMENT_LABEL = SwingUtil.DEFAULT_FONT
-      .deriveFont(Font.ITALIC).deriveFont( SwingUtil.DEFAULT_FONT.getSize()-1f );
-  /** Font for header labels in the frames. */
-  public static final Font FONT_HEADER_LABEL = SwingUtil.DEFAULT_FONT
-        .deriveFont(Font.BOLD);
-  /** Font for section labels in the frames. */
-  public static final Font FONT_SECTION_LABEL = SwingUtil.DEFAULT_FONT
-        .deriveFont(Font.BOLD).deriveFont( SwingUtil.DEFAULT_FONT.getSize()+1f );
-  /** Color for section labels in the frames. */
-  public static final Color COLOR_SECTION_LABEL = new Color(0,51,153); // dark blue
-
-  /**
-  * Creates a {@link JLabel} styled as header label in
-  * {@link KontaktInformationPanel}.
-  */
-  public static JLabel createHeaderLabel(String caption) {
-    JLabel label = new JLabel(caption);
-    label.setFont(FONT_HEADER_LABEL);
-    return label;
-  }
-  
-  /**
-  * Creates a {@link JLabel} styled as header label in
-  * {@link KontaktInformationPanel}.
-  */
-  public static JLabel createSectionLabel(String caption) {
-    JLabel label = new JLabel(caption);
-    label.setFont(FONT_SECTION_LABEL);
-    label.setForeground(COLOR_SECTION_LABEL);
-    return label;
-  }
-
-  /**
-  * Creates a {@link JLabel} styled to show a comment in
-  * {@link KontaktInformationPanel}.
-  */
-  public static JLabel createCommentLabel(String caption) {
-    JLabel label = new JLabel(caption);
-    label.setFont(FONT_COMMENT_LABEL);
-    return label;
-  }
-  
-  /**
-  * Creates a {@link JLabel} styled to show normal (read-only) content in
-  * {@link KontaktInformationPanel}.
-  */
-  public static JLabel createContentLabel(String caption) {
-    JLabel label = new JLabel(caption);
-    return label;
-  }
+//  /** Font for comment labels in the frames. */
+//  public static final Font FONT_COMMENT_LABEL = SwingUtil.DEFAULT_FONT
+//      .deriveFont(Font.ITALIC).deriveFont( SwingUtil.DEFAULT_FONT.getSize()-1f );
+//  /** Font for header labels in the frames. */
+//  public static final Font FONT_HEADER_LABEL = SwingUtil.DEFAULT_FONT
+//        .deriveFont(Font.BOLD);
+//  /** Font for section labels in the frames. */
+//  public static final Font FONT_SECTION_LABEL = SwingUtil.DEFAULT_FONT
+//        .deriveFont(Font.BOLD).deriveFont( SwingUtil.DEFAULT_FONT.getSize()+1f );
+//  /** Color for section labels in the frames. */
+//  public static final Color COLOR_SECTION_LABEL = new Color(0,51,153); // dark blue
+//
+//  /**
+//  * Creates a {@link JLabel} styled as header label in
+//  * {@link KontaktInformationPanel}.
+//  */
+//  public static JLabel createHeaderLabel(String caption) {
+//    JLabel label = new JLabel(caption);
+//    label.setFont(FONT_HEADER_LABEL);
+//    return label;
+//  }
+//  
+//  /**
+//  * Creates a {@link JLabel} styled as header label in
+//  * {@link KontaktInformationPanel}.
+//  */
+//  public static JLabel createSectionLabel(String caption) {
+//    JLabel label = new JLabel(caption);
+//    label.setFont(FONT_SECTION_LABEL);
+//    label.setForeground(COLOR_SECTION_LABEL);
+//    return label;
+//  }
+//
+//  /**
+//  * Creates a {@link JLabel} styled to show a comment in
+//  * {@link KontaktInformationPanel}.
+//  */
+//  public static JLabel createCommentLabel(String caption) {
+//    JLabel label = new JLabel(caption);
+//    label.setFont(FONT_COMMENT_LABEL);
+//    return label;
+//  }
+//  
+//  /**
+//  * Creates a {@link JLabel} styled to show normal (read-only) content in
+//  * {@link KontaktInformationPanel}.
+//  */
+//  public static JLabel createContentLabel(String caption) {
+//    JLabel label = new JLabel(caption);
+//    return label;
+//  }
 }

Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3Tag2FilenameParserPanel.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3Tag2FilenameParserPanel.java	2013-03-25 21:03:58 UTC (rev 2283)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3Tag2FilenameParserPanel.java	2013-03-25 21:07:57 UTC (rev 2284)
@@ -48,6 +48,7 @@
 
 import de.schmitzm.mp3.id3.ID3TagUtil;
 import de.schmitzm.mp3.id3.io.ID3Tag2FilenameParser;
+import de.schmitzm.swing.GUIBuilder;
 import de.schmitzm.swing.JPanel;
 import de.schmitzm.swing.JToggleButtonLabel;
 import de.schmitzm.swing.LimitedDocument;
@@ -106,16 +107,16 @@
     spaces.setSelected(true);
     spaces.addActionListener(this);
     this.spacesCaption = new JToggleButtonLabel(spaces,ID3TagUtil.R("ID3Tag2FilenameParserPanel.spaces"));
-    this.numberFormatDesc = GUIUtil.createHeaderLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat"));
+    this.numberFormatDesc = GUIBuilder.INST.createHeaderLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat"));
     this.trackNoFormat = new JTextField("");
-    this.trackNoFormatCaption = GUIUtil.createContentLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat.trackNo"));
-    this.trackNoFormatExample = GUIUtil.createCommentLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat.trackNo.example"));
+    this.trackNoFormatCaption = GUIBuilder.INST.createContentLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat.trackNo"));
+    this.trackNoFormatExample = GUIBuilder.INST.createCommentLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat.trackNo.example"));
     this.yearFormat = new JTextField("");
-    this.yearFormatCaption = GUIUtil.createContentLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat.year"));
-    this.yearFormatExample = GUIUtil.createCommentLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat.year.example"));
+    this.yearFormatCaption = GUIBuilder.INST.createContentLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat.year"));
+    this.yearFormatExample = GUIBuilder.INST.createCommentLabel(ID3TagUtil.R("ID3Tag2FilenameParserPanel.numberFormat.year.example"));
     
     
-    this.preview = GUIUtil.createCommentLabel("");
+    this.preview = GUIBuilder.INST.createCommentLabel("");
     preview.setFont( preview.getFont().deriveFont( Font.BOLD+Font.ITALIC ) );
     
     add(delimCaption,"aligny center");

Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagFieldSequencePanel.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagFieldSequencePanel.java	2013-03-25 21:03:58 UTC (rev 2283)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagFieldSequencePanel.java	2013-03-25 21:07:57 UTC (rev 2284)
@@ -45,6 +45,7 @@
 import de.schmitzm.mp3.id3.ID3TagField;
 import de.schmitzm.mp3.id3.ID3TagUtil;
 import de.schmitzm.mp3.id3.io.ID3Tag2FilenameParser;
+import de.schmitzm.swing.GUIBuilder;
 import de.schmitzm.swing.JPanel;
 import de.schmitzm.swing.ListMaintainancePanel;
 import de.schmitzm.swing.dnd.JListTransferHandler;
@@ -68,7 +69,7 @@
   public ID3TagFieldSequencePanel() {
     super( new MigLayout("wrap 2","0[grow][grow]0","0[top]") );
     
-    fieldSequenceCaption = GUIUtil.createHeaderLabel( ID3TagUtil.R("ID3TagFieldSequencePanel.fields.sequence")+":");
+    fieldSequenceCaption = GUIBuilder.INST.createHeaderLabel( ID3TagUtil.R("ID3TagFieldSequencePanel.fields.sequence")+":");
     fieldSequence = new ListMaintainancePanel<ID3TagField>(true, true, false, true) {
       @Override
       protected ID3TagField[] createNewElements() {
@@ -101,7 +102,7 @@
     fieldSequence.getList().setCellRenderer(ID3TagFieldCellRenderer.DEFAULT);
     fieldSequence.getList().setSelectionMode( ListSelectionModel.SINGLE_INTERVAL_SELECTION );
 
-    availableFieldsCaption = GUIUtil.createHeaderLabel( ID3TagUtil.R("ID3TagFieldSequencePanel.fields.available")+":");
+    availableFieldsCaption = GUIBuilder.INST.createHeaderLabel( ID3TagUtil.R("ID3TagFieldSequencePanel.fields.available")+":");
     availableFields = new ListMaintainancePanel<ID3TagField>(false,false,false,false);
     availableFields.getList().setCellRenderer(ID3TagFieldCellRenderer.DEFAULT);
     availableFields.getList().addListSelectionListener( fieldSequence );

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-03-25 21:03:58 UTC (rev 2283)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/ID3TagV2Panel.java	2013-03-25 21:07:57 UTC (rev 2284)
@@ -37,6 +37,7 @@
 
 import de.schmitzm.mp3.id3.ID3TagField;
 import de.schmitzm.mp3.id3.ID3TagUtil;
+import de.schmitzm.swing.GUIBuilder;
 import de.schmitzm.swing.input.BooleanInputOption;
 import de.schmitzm.swing.input.ManualInputOption;
 
@@ -57,7 +58,7 @@
     // initialize genre
     genre.setSelectionObjects( ID3TagUtil.ALL_GENRE_ID3V2, ID3TagUtil.ALL_GENRE_TITLES_ID3V2);
     
-    totalTracksCaption = GUIUtil.createContentLabel(ID3TagUtil.R("ID3Tag.of"));
+    totalTracksCaption = GUIBuilder.INST.createContentLabel(ID3TagUtil.R("ID3Tag.of"));
     totalTracks = new ManualInputOption.Integer(null);
     totalTracksCheckbox = new BooleanInputOption(null, false);
     totalTracksCheckbox.connectInputOptions(true,totalTracks);

Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/StringConversionDialog.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/StringConversionDialog.java	2013-03-25 21:03:58 UTC (rev 2283)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/StringConversionDialog.java	2013-03-25 21:07:57 UTC (rev 2284)
@@ -38,6 +38,7 @@
 
 import net.miginfocom.swing.MigLayout;
 import de.schmitzm.mp3.id3.ID3TagUtil;
+import de.schmitzm.swing.GUIBuilder;
 import de.schmitzm.swing.JPanel;
 import de.schmitzm.swing.OkCancelDialog;
 import de.schmitzm.swing.SwingUtil;
@@ -93,7 +94,7 @@
     setPreferredSize( new Dimension(550,370) );
     
     this.mainPanel = new JPanel( new MigLayout("wrap 1","[grow]","top") );
-    this.desc = GUIUtil.createCommentLabel( ID3TagUtil.R("StringConversionDialog.desc") );
+    this.desc = GUIBuilder.INST.createCommentLabel( ID3TagUtil.R("StringConversionDialog.desc") );
     this.conversionPanel = new StringConversionPanel();
     conversionPanel.addActionListener(this);
     

Modified: trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/StringConversionPanel.java
===================================================================
--- trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/StringConversionPanel.java	2013-03-25 21:03:58 UTC (rev 2283)
+++ trunk/schmitzm-mp3/src/main/java/de/schmitzm/mp3/id3/gui/StringConversionPanel.java	2013-03-25 21:07:57 UTC (rev 2284)
@@ -42,6 +42,7 @@
 import de.schmitzm.lang.LangUtil;
 import de.schmitzm.mp3.id3.ID3TagUtil;
 import de.schmitzm.swing.ButtonGroup;
+import de.schmitzm.swing.GUIBuilder;
 import de.schmitzm.swing.JPanel;
 
 /**
@@ -75,11 +76,11 @@
   public StringConversionPanel(Frame owner) {
     super(new MigLayout("wrap 1","0[grow]0","[]0[][]0[][]0[]") );
  
-    this.regexReplaceCaption = GUIUtil.createHeaderLabel( ID3TagUtil.R("StringConversionPanel.RegexPanel.desc") );
+    this.regexReplaceCaption = GUIBuilder.INST.createHeaderLabel( ID3TagUtil.R("StringConversionPanel.RegexPanel.desc") );
     this.regexPanel = new RegexPanel();
-    this.caseCaption = GUIUtil.createHeaderLabel( ID3TagUtil.R("StringConversionPanel.CasePanel.desc") );
+    this.caseCaption = GUIBuilder.INST.createHeaderLabel( ID3TagUtil.R("StringConversionPanel.CasePanel.desc") );
     this.casePanel = new CasePanel();
-    this.umlautsCaption = GUIUtil.createHeaderLabel( ID3TagUtil.R("StringConversionPanel.UmlautsPanel.desc") );
+    this.umlautsCaption = GUIBuilder.INST.createHeaderLabel( ID3TagUtil.R("StringConversionPanel.UmlautsPanel.desc") );
     this.umlautsPanel = new UmlautsPanel();
     
     add(regexReplaceCaption,"");
@@ -222,7 +223,7 @@
       super( new MigLayout("wrap 5","0[][][grow][][grow]0","top") );
 
       this.regexReplace = new JCheckBox( ID3TagUtil.R("StringConversionPanel.RegexPanel") );
-      this.regexCaption = GUIUtil.createContentLabel(ID3TagUtil.R("StringConversionPanel.RegexPanel.pattern") );
+      this.regexCaption = GUIBuilder.INST.createContentLabel(ID3TagUtil.R("StringConversionPanel.RegexPanel.pattern") );
       this.regex = new JTextField();
       this.replaceCaption = new JButton( ID3TagUtil.R("StringConversionPanel.RegexPanel.replace") ); //GUIUtil.createContentLabel( GUIUtil.R("FilenameConversionDialog.regex.replace") );
       this.replace = new JTextField();



More information about the Schmitzm-commits mailing list