Package ui.misc.files

Source Code of ui.misc.files.MultiNamedFileTableModel

package ui.misc.files;


import java.util.ArrayList;
import java.util.Collection;

import javax.swing.table.AbstractTableModel;

import misc.measure.FileSize;

import common.files.FileDigest;
import common.files.MultiNamedFile;
import common.files.SerializableFile;


public class MultiNamedFileTableModel extends AbstractTableModel
{
  private static final long serialVersionUID = 2790981558921029088L;

  private static final String[] HEADINGS =
  {
    "ID", "Name", "Size", "Hash"
  };

  private static final Class<?>[] COLUMN_CLASSES =
  {
    Integer.class, MultiNamedFile.class, FileSize.class, FileDigest.class
  };

  private ArrayList<MultiNamedFile> entries;

  public MultiNamedFileTableModel()
  {
    entries = new ArrayList<MultiNamedFile>();
  }

  public String getColumnName(int column)
  {
    return HEADINGS[column];
  }

  public Class<?> getColumnClass(int column)
  {
    return COLUMN_CLASSES[column];
  }

  public int getColumnCount()
  {
    return HEADINGS.length;
  }

  public synchronized int getRowCount()
  {
    return entries.size();
  }

  public synchronized boolean isCellEditable(int row, int col)
  {
    if (col != 1)
    {
      return false;
    }
    else
    {
      return entries.get(row).getNumberOfNames() > 1;
    }
  }

  public synchronized Object getValueAt(int row, int column)
  {
    if (row >= entries.size()) // ebbene si, puo' capitare
    {
      return null;
    }

    switch (column)
    {
      case 0:
        return new Integer(row);
      case 1:
        return entries.get(row);
      case 2:
        return new FileSize(entries.get(row).getLength());
      case 3:
        return entries.get(row).getHashData();
    }
    return null;
  }

  public synchronized void add(MultiNamedFile file)
  {
    if (entries.contains(file))
    {
      entries.get(entries.indexOf(file)).addNames(file.getNames());
    }
    else
    {
      entries.add(file);
    }
    fireTableDataChanged();
  }

  public synchronized void remove(SerializableFile file)
  {
    if (entries.remove(file))
    {
      fireTableDataChanged();
    }
  }

  public void update()
  {
    fireTableDataChanged();
  }

  public synchronized void clear()
  {
    entries.clear();
    fireTableDataChanged();
  }

  protected Collection<MultiNamedFile> getEntries()
  {
    return entries;
  }

}
TOP

Related Classes of ui.misc.files.MultiNamedFileTableModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.