~motu-torrent/azureus/upstream-stable

« back to all changes in this revision

Viewing changes to org/gudy/azureus2/ui/swt/views/tableitems/files/FileExtensionItem.java

  • Committer: John Dong
  • Date: 2007-10-22 04:54:13 UTC
  • Revision ID: john.dong@gmail.com-20071022045413-3ovb11u82rrcokxx
Commit 3.0.3.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2004, 2005, 2006 Aelitis SAS, All rights Reserved
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details ( see the LICENSE file ).
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program; if not, write to the Free Software
15
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 *
17
 
 * AELITIS, SAS au capital de 46,603.30 euros,
18
 
 * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
19
 
 */
20
 
 
21
 
package org.gudy.azureus2.ui.swt.views.tableitems.files;
22
 
 
23
 
import org.gudy.azureus2.plugins.ui.tables.*;
24
 
import org.gudy.azureus2.core3.disk.DiskManagerFileInfo;
25
 
import org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn;
26
 
 
27
 
public class FileExtensionItem
28
 
       extends CoreTableColumn 
29
 
       implements TableCellRefreshListener
30
 
{
31
 
  
32
 
  /** Default Constructor */
33
 
  public FileExtensionItem() {
34
 
    super("fileext", ALIGN_LEAD, POSITION_INVISIBLE, 50, TableManager.TABLE_TORRENT_FILES);
35
 
  }
36
 
 
37
 
  public void refresh(TableCell cell) {
38
 
    DiskManagerFileInfo fileInfo = (DiskManagerFileInfo)cell.getDataSource();
39
 
    cell.setText(determineFileExt(fileInfo));
40
 
  }
41
 
  
42
 
  private static String determineFileExt(DiskManagerFileInfo fileInfo) {
43
 
        String name = (fileInfo == null) ? "" : fileInfo.getFile(true).getName();
44
 
        int dot_position = name.lastIndexOf(".");
45
 
        if (dot_position == -1) {return "";}
46
 
        return name.substring(dot_position+1);
47
 
  }
48
 
        
49
 
}
 
1
/*
 
2
 * Copyright (C) 2004, 2005, 2006 Aelitis SAS, All rights Reserved
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details ( see the LICENSE file ).
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program; if not, write to the Free Software
 
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 *
 
17
 * AELITIS, SAS au capital de 46,603.30 euros,
 
18
 * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
 
19
 */
 
20
 
 
21
package org.gudy.azureus2.ui.swt.views.tableitems.files;
 
22
 
 
23
import org.gudy.azureus2.plugins.ui.tables.*;
 
24
import org.gudy.azureus2.core3.disk.DiskManagerFileInfo;
 
25
import org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn;
 
26
 
 
27
public class FileExtensionItem
 
28
       extends CoreTableColumn 
 
29
       implements TableCellRefreshListener
 
30
{
 
31
  
 
32
  /** Default Constructor */
 
33
  public FileExtensionItem() {
 
34
    super("fileext", ALIGN_LEAD, POSITION_INVISIBLE, 50, TableManager.TABLE_TORRENT_FILES);
 
35
    setMinWidthAuto(true);
 
36
  }
 
37
 
 
38
  public void refresh(TableCell cell) {
 
39
    DiskManagerFileInfo fileInfo = (DiskManagerFileInfo)cell.getDataSource();
 
40
    cell.setText(determineFileExt(fileInfo));
 
41
  }
 
42
  
 
43
  private static String determineFileExt(DiskManagerFileInfo fileInfo) {
 
44
        String name = (fileInfo == null) ? "" : fileInfo.getFile(true).getName();
 
45
        int dot_position = name.lastIndexOf(".");
 
46
        if (dot_position == -1) {return "";}
 
47
        return name.substring(dot_position+1);
 
48
  }
 
49
        
 
50
}