/*
 * @(#)FileSystemModel.java
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 2001 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDcreator.java for details.
 */

import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;

class FileSystemModel
		extends DefaultTreeModel
		implements TreeTableModel {
	protected static final Class types[] = {
		TreeTableModel.class,
		String.class};

	public FileSystemModel(TreeNode root, boolean asksAllowsChildren) {
		super(root, asksAllowsChildren);
	}

	public int getColumnCount() {
		if (Mode.audioCD())
			return 2;
		else
			return 2;
	}

	public String getColumnName(int column) {
		if (Mode.audioCD()) {
//			if (column == 0)
//				return "";
			if (column == 1)
				return CDcreator.i18n("MWLength");
//			column--;
		}
		if (column == 0)
			return CDcreator.i18n("MWName");
		else
			return CDcreator.i18n("MWSize");
	}

	public Class getColumnClass(int column) {
/*		if (Mode.audioCD()) {
			if (column == 0)
				return Integer.class;
			column--;
		}
*/		return types[column];
	}

	public Object getValueAt(Object node, int column) {
/*		if (Mode.audioCD()) {
			if (column == 0)
				return new Integer(1);
			column--;
		}
*/
		if (column == 0)
			return ((DirTreeNode)node).toString();
		else
		{
			long n = ((CDNode)node).getSize();
			if (Mode.audioCD()) {
				String str = String.valueOf(n % 60);
				if (str.length() < 2)
					str = "0" + str;
				n /= 60;
				str = n + ":" + str;
//				if (str.length() < 5)
//					str = "0" + str;
				return str;
			}
			else {
				n /= 1024;
				if (n < 1024)
					return n + " KB";
				return new java.text.DecimalFormat(".#")
					.format(n / 1024.0) + " MB";
//				return java.text.NumberFormat
//					.getNumberInstance().format(n / 1024) + " KB";
			}
		}
	}

	public boolean isCellEditable(Object node, int column) {
/*		if (Mode.audioCD()) {
			if (column == 0)
				return false;
			column--;
		}
*/		return types[column] == TreeTableModel.class;
	}

	public void setValueAt(Object aValue, Object node, int column) {
	}
}
