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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
/*
* This file is part of THESIAS
* Copyright (C) 2004-2020 David-Alexandre Trégouët, Valérie Garelle
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.datatransfer.*;
import java.util.*;
import javax.swing.JDialog;
import java.io.*;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.Dimension;
class ParamTable extends JPanel{
public JTable table;
public ParamTableModel tableModel;
int nMax;
private JScrollPane paramScrollPane;
public ParamTable() {
super(new GridLayout(1,1));
tableModel = new ParamTableModel(1,4);
table = new JTable(tableModel);
table.setPreferredScrollableViewportSize(new Dimension(157, 97));
table.setDragEnabled(true);
JTableHeader tHeader;
tHeader = table.getTableHeader();
Color saumon = new Color( 255, 204, 153 );
tHeader.setBackground(saumon);
Dimension dim = new Dimension( 157, 97);
paramScrollPane = new JScrollPane(table);
paramScrollPane.setSize(dim);
nMax = 0;
add(paramScrollPane);
setBorder(BorderFactory.createEmptyBorder(13,0,0,0));
}
public String serializeData(){
String fileName = "para.txt";
FileWriter fwData;
StringBuffer sBuf = new StringBuffer();
try
{
int imax = 4;
System.out.println(fileName);
fwData = new FileWriter(fileName);
sBuf.append(nMax + "\r\n");
for( int i = 0; i < nMax ; i++)
{
sBuf.append(tableModel.data[i][0] + " " + tableModel.data[i][1]);
if( ((Boolean)tableModel.data[i][2]).booleanValue() )
sBuf.append(" 1");
else
sBuf.append(" 0");
if( ((Boolean)tableModel.data[i][3]).booleanValue() )
sBuf.append(" 1");
else
sBuf.append(" 0");
sBuf.append("\r\n");
}
fwData.write(sBuf.toString(), 0 , sBuf.toString().length());
fwData.close();
}
catch (IOException ee)
{
System.out.println(ee.toString());
}
return sBuf.toString();
}
public void importData(){
nMax = 0;
String fileName = "para.txt";
try
{
FileReader s;
int i = 0;
s = new FileReader(fileName);
BufferedReader b = new BufferedReader(s);
String content;
content = b.readLine();
int nbLine = Integer.parseInt(content);
tableModel = null;
tableModel = new ParamTableModel(nbLine,4);
table.setModel(tableModel);
double d;
for( int k = 0 ; k < nMax ;k ++){
tableModel.data[k][0] = new String();
tableModel.data[k][1] = new String();
tableModel.data[k][2] = new Boolean(false);
tableModel.data[k][3] = new Boolean(false);
}
while( content != null )
{
content = b.readLine();
if ( content == null)
break;
StringTokenizer st = new StringTokenizer(content);
if (st.countTokens() < 2)
break;
tableModel.data[i][0] = st.nextToken();
tableModel.data[i][1] = st.nextToken();
d = Double.parseDouble(st.nextToken() );
if ( d < 0.5 )
tableModel.data[i][2] = new Boolean(false);
else
tableModel.data[i][2] = new Boolean(true);
d = Double.parseDouble(st.nextToken() );
if ( d < 0.5 )
tableModel.data[i][3] = new Boolean(false);
else
tableModel.data[i][3] = new Boolean(true);
i++;
}
nMax = i;
b.close();
s.close();
}
catch ( IOException eIO )
{
System.out.println(eIO.toString());
}
}
public void setParamTableEnabled(boolean state)
{
paramScrollPane.setEnabled(state);
table.setEnabled(state);
}
public void reinitParamTable(){
tableModel = null;
tableModel = new ParamTableModel(1,4);
table.setModel(tableModel);
}
}
class ParamTableModel extends AbstractTableModel
{
int rows, cols;
private String[] columnNames = {"N","Freq","Effect"};
public Object[][] data;
public ParamTableModel( int row, int col){
rows = row;
cols = col;
int i, j ;
data = new Object[rows][cols];
for( i =0 ; i < rows ; i++){
for (j = 0 ; j < cols -2 ; j++ )
{
data[i][j] = new String();
}
for( ; j < cols ; j++)
data[i][j] = new Boolean(false);
}
}
public void resetData()
{
for( int i =0 ; i < rows ; i++)
for (int j = 0 ; j < cols ; j++ )
{
data[i][j] = new String();
}
}
public void initData(Object d[][], int a, int b)
{
for( int i = 0 ; i < a ; i++)
for (int j = 0 ; j < b ; j++ )
{
data[i][j] = (String)d[i][j];
}
}
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
if( data == null)
return null;
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
if( col == 0 || col == 1 )
return false;
return true;
}
public void setValueAt(Object value, int row, int col) {
data[row][col] = value;
fireTableCellUpdated(row, col);
}
};
|