1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
package appli.Interfaces.Historique;
import java.util.Vector;
import java.io.*;
import java.util.*;
import javax.swing.table.AbstractTableModel;
public class DataFileTableModel extends AbstractTableModel
{
private static final long serialVersionUID=42L;
static protected Vector <String> data; //données
//static protected Vector<String>data=new Vector<String>();
static protected Vector columnNames; //noms de colonnes
static protected String datafile; //nom du fichier de données
public boolean finScrutation=false;
public DataFileTableModel(String f)
{
datafile=f;
initVectors();
Thread thMAJ = new Thread()
{
public void run()
{
MAJ();
}
};
thMAJ.start();
}
public static void initVectors()
{
String aligne;
data=new Vector<String>();
// columnNames=new Vector();
try
{
FileInputStream fin = new FileInputStream(datafile);
BufferedReader br = new BufferedReader(new InputStreamReader(fin));
while((aligne=br.readLine())!=null)
{
StringTokenizer st2 = new StringTokenizer(aligne,";");
while(st2.hasMoreTokens()) data.addElement(st2.nextToken());
}
br.close();
fin.close();
}
catch(Exception e){ e.printStackTrace();}
}
public int getColumnCount()
{
String[] columnNames= {"Arrivée","Appel","Camions","Quais","Observations","Déchargement","Priorité"};
return columnNames.length;
}
public int getRowCount()
{
return data.size()/getColumnCount();
}
public String getColumnName(int columnIndex)
{
String[] columnNames= {"Arrivée","Appel","Camions","Quais","Observations","Déchargement","Priorité"};
return columnNames[columnIndex];
}
public boolean isCellEditable(int rowIndex,int columnIndex)
{
return false;
}
public Object getValueAt(int rowIndex,int columnIndex)
{
return (String)data.elementAt((rowIndex*getColumnCount())+columnIndex);
}
public void MAJ()
{
while(!finScrutation)
{
try
{
fireTableDataChanged();
Thread.sleep(1000);
}catch(Exception e)
{
System.exit(1);
}
}
}
/*
* Specification de la reaction lors de modification du contenu des cellules
* effectues par l'utilisateur
*/
public void setValueAt(Object aValue,int rowIndex,int columnIndex)
{
}
} |
Partager