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

Quick Search    Search Deep

Source code: entagged/gui/tageditor/models/ID3FramesTableModel.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.models;
23  import entagged.common.*;
24  import entagged.formats.mp3.*;
25  import entagged.gui.*;
26  import entagged.gui.tageditor.*;
27  import java.io.*;
28  import java.util.*;
29  
30  import javax.swing.table.*;
31  
32  
33  /**
34   *  Model of the table showing the id3v2 frames and their contents to allow
35   *  advanced editing $Id: ID3FramesTableModel.java,v 1.1 2003/09/22 14:44:29
36   *  kikidonk Exp $
37   *
38   * @author     Raphael Slinckx (KiKiDonK)
39   * @version    v0.04
40   */
41  public class ID3FramesTableModel extends AbstractTableModel {
42  
43    /**  The column titles */
44    private String[] colTitles = {Entagged.langage.getProperty( "id3framestablemodel.frame" ),
45      Entagged.langage.getProperty( "id3framestablemodel.description" ),
46      Entagged.langage.getProperty( "id3framestablemodel.content" )};
47    /**  The hashtable containing all the allowed id3v2 frames */
48    private Hashtable framesDict;
49    /**
50     *  Double array containing the frame name, the frame description, and the
51     *  frame content
52     */
53    private String[][] tableContents;
54  
55    /**  Parent Tag Editor frame */
56    private TagEditorFrame tagEditorFrame;
57  
58  
59    /**
60     *  Creates the new table model, read the file "resources/id3frames" extracts
61     *  all the valid frames, read the selected MP3File's ID3v2 Tag and fill the
62     *  corresponding cells
63     *
64     * @param  tagEditorFrame  Description of the Parameter
65     */
66    public ID3FramesTableModel( TagEditorFrame tagEditorFrame ) {
67      this.tagEditorFrame = tagEditorFrame;
68      framesDict = new Hashtable();
69      try {
70      String filename = Entagged.langage.getProperty( "id3framestablemodel.frames_file" );
71      FileReader fr = new FileReader( Utils.RESOURCES_PATH + filename );
72      BufferedReader br = new BufferedReader( fr );
73      String currentLine;
74      int line = 0;
75  
76        while ( ( currentLine = br.readLine() ) != null )
77          if ( currentLine.substring( 0, 1 ).equals( "#" ) )
78            continue;
79          else
80            line++;
81  
82        br.close();
83        fr = new FileReader( Utils.RESOURCES_PATH + filename );
84        br = new BufferedReader( fr );
85  
86        tableContents = new String[line][3];
87        line = 0;
88        while ( ( currentLine = br.readLine() ) != null )
89          if ( currentLine.substring( 0, 1 ).equals( "#" ) )
90            continue;
91          else {
92            tableContents[line][0] = currentLine.substring( 0, 4 );
93            tableContents[line][1] = currentLine.substring( 5 );
94          Object content = ( (MP3File)tagEditorFrame.getID3InfoPanel().getSelectedMP3().get( 0 ) ).getID3v2Tag().get( tableContents[line][0] );
95            if ( content != null ) {
96              if ( tableContents[line][0].equals( "COMM" ) )
97                tableContents[line][2] = ( (String)content ).substring( 4 );
98              else
99                tableContents[line][2] = (String)content;
100           }
101           else
102             tableContents[line][2] = "";
103           framesDict.put( tableContents[line][0], tableContents[line][2] );
104           line++;
105         }
106 
107       br.close();
108     } catch ( IOException e ) {
109       e.printStackTrace();
110     }
111   }
112 
113 
114   /**
115    *  Sets the value at the given coordinate
116    *
117    * @param  value  the new value
118    * @param  row    the row
119    * @param  col    the column
120    */
121   public void setValueAt( Object value, int row, int col ) {
122     tableContents[row][col] = (String)value;
123     fireTableCellUpdated( row, col );
124   }
125 
126 
127   /**
128    *  Returns the column class at the given index
129    *
130    * @param  c  the column index
131    * @return    the Class of this column (always String)
132    */
133   public Class getColumnClass( int c ) {
134     return String.class;
135   }
136 
137 
138   /**
139    *  Gets the columnCount attribute of the ID3FramesTableModel object
140    *
141    * @return    The columnCount value
142    */
143   public int getColumnCount() {
144     return colTitles.length;
145   }
146 
147 
148   /**
149    *  Gets the columnName attribute of the ID3FramesTableModel object
150    *
151    * @param  col  column
152    * @return      The columnName value
153    */
154   public String getColumnName( int col ) {
155     return colTitles[col];
156   }
157 
158 
159   /**
160    *  Gets the iD3FramesContent attribute of the ID3FramesTableModel object
161    *
162    * @return    The iD3FramesContent value
163    */
164   public String[][] getID3FramesContent() {
165     return tableContents;
166   }
167 
168 
169   /**
170    *  Gets the rowCount attribute of the ID3FramesTableModel object
171    *
172    * @return    The rowCount value
173    */
174   public int getRowCount() {
175     return tableContents.length;
176   }
177 
178 
179   /**
180    *  Gets the value at the given coordinate
181    *
182    * @param  row  the row
183    * @param  col  the column
184    * @return      the String at this coordinate
185    */
186   public Object getValueAt( int row, int col ) {
187     return tableContents[row][col];
188   }
189 
190 
191   /**
192    *  Return the editable state of the given cell. Only the last column is
193    *  editable
194    *
195    * @param  row  the row
196    * @param  col  the column
197    * @return      Is the cell editable ?
198    */
199   public boolean isCellEditable( int row, int col ) {
200     if ( col == 2 )
201       return true;
202     else
203       return false;
204   }
205 }
206