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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
| package ihm;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
//import javax.swing.TableModel;
/**
* this class descibe the "data's array" frame
* @author
* Created on 12 oct. 2004
* @version 1.0.0
* @since 1.0.0
* TODO :
*/
public class CTableData extends JFrame {
private MyTableModel monModel;
//les tableaux de donnees imaging et classification
private JTable tableDonnee1;
//les tableaux de donnees imaging et classification
private JTable tableDonnee2;
//les scroll pane qui les contiennent
private JScrollPane scrollDonnee1;
//les scroll pane qui les contiennent
private JScrollPane scrollDonnee2;
//la taille de la fenetre
private Dimension tailleFenetre = new Dimension(800,350);
private String[][] data;
private int width = 20;
private String[] names = { "Label", "Value ", "Value (hexa)" };
/**
* Constructor. creation of the window which contains the data tables for the images displayed
* @param application The application that this window depends to.
*/
public CTableData(CApplication application){
//creation et parametrage de la fenetre
this.setTitle("Data window");
//la fenetre n'est pas fermable, seulement iconifiable
//(le bouton Quit de la functionWindow permet de fermer l'application)
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.setResizable(true);
this.setSize(tailleFenetre.height,tailleFenetre.width);
this.setLocation(application.getWidth(),0);
this.getContentPane().setBackground(new Color(236,233,216));
this.getContentPane().setLayout(null);
//creation d'un tableau de donnes vide
data = new String[78][3];
//monModel = new MyTableModel()
//creation des JTable et des JScrollPane
try{
tableDonnee1 = new JTable(data,names);
tableDonnee1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tableDonnee2 = new JTable(data,names);
tableDonnee2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollDonnee1 = new JScrollPane(tableDonnee1);
scrollDonnee2 = new JScrollPane(tableDonnee2);
System.out.println(" - Creation Array Data Frame : Ok");
} catch (Exception e) {System.out.println(" - Creation Array Data Frame : Echec");}
//ajout de ces elements a la fenetre
getContentPane().add(scrollDonnee1);
//getContentPane().add(scrollDonnee2);
scrollDonnee1.setBounds(12,12,300,300);
//scrollDonnee2.setBounds(12,324,300,300);
}
/**
* Reset the imaging data table (used before a new image request)
*/
public void viderTabl() {
//on vire l'element present dans la fenetre
getContentPane().removeAll();
//et on en cree un nouveau, vide
data = new String[78][3];
tableDonnee1 = new JTable(data, names);
//tableDonnee1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollDonnee1 = new JScrollPane(tableDonnee1);
getContentPane().add(scrollDonnee1);
scrollDonnee1.setBounds(12,12,300,300);
this.repaint();
}
/**
* Insert datas into one of the two data tables of the window.
* @param s The String array of datas to be imported.
* @param i The data table to fill : i=1 -> imaging, i=2 -> classification.
*/
public void setData(String[][] s, int i){
//i=1 -> imaging
if(i==1){
try {
//transfert du tableau s dans le tableau data, en enlevant la 1ere ligne
//(code de l'iamge recue)
for(int j=1;j<s.length;j++) {
for(int k=0;k<3;k++){
// on traite les deux premieres colonnes
if(k!=2) {
data[j-1][k] = s[j][k];
// on recupere la longueur max des String inserer
if((width < s[j][k].length()) && (k==0)) {
width = s[j][k].length();
}
}else {//cas de la colonne pour les valeurs en HEXA
data[j-1][k] = Integer.toHexString(Float.floatToIntBits(
Float.valueOf(s[j][k-1]).floatValue()
));
}
}
}
//mise a jour de la JTable et du JScrollPane
tableDonnee1 = new JTable(data, names);
tableDonnee1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumn column = null;
for (int z = 0; z < 3; z++) {
column = tableDonnee1.getColumnModel().getColumn(z);
if (z == 0) {
column.setPreferredWidth(200); //sport column is bigger
column.setMaxWidth(200);
column.setMinWidth(200);
} else {
column.setPreferredWidth(15);
column.setMaxWidth(15);
column.setMinWidth(15);
}
}
scrollDonnee1 = new JScrollPane(tableDonnee1);
getContentPane().add(scrollDonnee1);
scrollDonnee1.setBounds(12,12,300,300);
} catch(Exception e) {
e.printStackTrace(System.out);}
}
//i=2 -> classification, meme methode
else if(i==2){
try {
getContentPane().remove(scrollDonnee2);
for(int j=1;j<s.length;j++) {
for(int k=0;k<3;k++) {
// on traite les deux premieres colonnes
if(k!=2) {
data[j-1][k] = s[j][k];
// on recupere la longueur max des String inserer
if((width < s[j][k].length()) && (k==0)) {
width = s[j][k].length();
}
}else {//cas de la colonne pour les valeurs en HEXA
data[j-1][k] = Integer.toHexString(Float.floatToIntBits(
Float.valueOf(s[j][k-1]).floatValue()
));
}
}
}
tableDonnee2 = new JTable(s, names);
scrollDonnee2 = new JScrollPane(tableDonnee2);
getContentPane().add(scrollDonnee2);
scrollDonnee2.setBounds(12,324,300,300);
this.repaint();
} catch(Exception e) {
e.printStackTrace(System.out);}
}
}
} |
Partager