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 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
package view;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.text.ParseException;
import java.util.EventObject;
import java.util.Observable;
import java.util.Observer;
import javax.swing.AbstractCellEditor;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.ListSelectionModel;
import javax.swing.border.Border;
import javax.swing.event.CellEditorListener;
import javax.swing.table.TableCellEditor;
import javax.swing.text.MaskFormatter;
import org.jdesktop.swingx.JXTable;
import controller.ActionFactory;
import controller.ChangedParametreAction;
import controller.DeleteParticipantAction;
import controller.InsertAction;
import controller.MyAbstractAction;
import controller.NewAction;
import controller.OpenAction;
import controller.QuitterAction;
import controller.SaveLocalAction;
import model.EncodeTableModel;
import model.CrossFacade;
import model.TableColumns;
public class Encode extends JFrame implements Observer{
private Font v = new Font("Arial", Font.PLAIN, 17);
private CrossFacade model;
private JFormattedTextField txtDistance;
private JTextField txtEncoder, txtCrossDate;
private EncodeTableModel encodeTableModel;
public Encode(CrossFacade model){
super("Encodage des résultats");
this.model = model;
setResizable(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel topPanel = new JPanel(new BorderLayout());
topPanel.add(menuBarPanel(), BorderLayout.NORTH);
topPanel.add(headerPanel(), BorderLayout.WEST);
add(topPanel, BorderLayout.NORTH);
add(crossListPanel(), BorderLayout.CENTER);
model.addObserver(this);
}
public JPanel menuBarPanel(){
JButton button;
MyAbstractAction c;
JPanel mnuBar = new JPanel(new FlowLayout(FlowLayout.LEFT));
mnuBar.setPreferredSize(new Dimension(330, 35));
JPanel commands = new JPanel(new FlowLayout(FlowLayout.LEFT, 3, 0));
button = new JButton();
c = (MyAbstractAction) ActionFactory.getInstance(model).getAction(NewAction.getCommandName());
button.setAction(c);
commands.add(button);
button = new JButton();
c = (MyAbstractAction) ActionFactory.getInstance(model).getAction(OpenAction.getCommandName());
button.setAction(c);
commands.add(button);
button = new JButton();
c = (MyAbstractAction) ActionFactory.getInstance(model).getAction(SaveLocalAction.getCommandName());
button.setAction(c);
commands.add(button);
button = new JButton();
c = (MyAbstractAction) ActionFactory.getInstance(model).getAction(ChangedParametreAction.getCommandName());
button.setAction(c);
commands.add(button);
button = new JButton();
c = new QuitterAction();
c.setObject(this);
button.setAction(c);
commands.add(button);
mnuBar.add(commands);
return mnuBar;
}
public JPanel headerPanel(){
JPanel headerPanel = new JPanel(null);
headerPanel.setPreferredSize(new Dimension(520, 110));
JLabel lblEncoder = new JLabel("Encoder");
lblEncoder.setFont(v);
lblEncoder.setBounds(5, 5, 110, 20);
headerPanel.add(lblEncoder);
JLabel lblCrossDate = new JLabel("Date du cross");
lblCrossDate.setFont(v);
lblCrossDate.setBounds(5, 32, 110, 20);
headerPanel.add(lblCrossDate);
JLabel lblDistance = new JLabel("Distance");
lblDistance.setFont(v);
lblDistance.setBounds(255, 32, 70, 20);
headerPanel.add(lblDistance);
JLabel lblDescription = new JLabel("Description");
lblDescription.setFont(v);
lblDescription.setBounds(5, 55, 110, 20);
headerPanel.add(lblDescription);
txtEncoder = new JTextField();
txtEncoder.setFont(v);
txtEncoder.setBounds(115, 0, 350, 25);
headerPanel.add(txtEncoder);
txtCrossDate = new JTextField();
txtCrossDate.setFont(v);
txtCrossDate.setBounds(115, 30, 100, 25);
headerPanel.add(txtCrossDate);
MaskFormatter maskDistance = new MaskFormatter();
try {
maskDistance.setMask("******");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
maskDistance.setValidCharacters("0123456789.,");
JFormattedTextField txtDistance = new JFormattedTextField(maskDistance);
txtDistance.setBounds(345, 30, 60, 25);
txtDistance.setFont(v);
headerPanel.add(txtDistance);
JTextArea txtDescription = new JTextArea();
txtDescription.setFont(v);
txtDescription.setBounds(115, 60, 350, 45);
headerPanel.add(txtDescription);
JComboBox cboUnit = new JComboBox();
cboUnit.setFont(v);
cboUnit.setBounds(405, 30, 59, 25);
headerPanel.add(cboUnit);
return headerPanel;
}
public JPanel crossListPanel(){
MyAbstractAction c;
Dimension cmdDimension = new Dimension(30, 25);
Border empty = BorderFactory.createEmptyBorder(3, 3, 3, 3);
Border etched = BorderFactory.createEtchedBorder();
Border compound = BorderFactory.createCompoundBorder(empty, etched);
JPanel crossList = new JPanel(new BorderLayout());
crossList.setSize(460, 130);
JPanel cmdsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 3, 0));
JButton cmdIns = new JButton();
c = (MyAbstractAction) ActionFactory.getInstance(model).getAction(InsertAction.getCommandName());
c.setEnabled(true);
cmdIns.setAction(c);
cmdIns.setSize(cmdDimension);
cmdsPanel.add(cmdIns);
JButton cmdSup = new JButton();
c = (MyAbstractAction) ActionFactory.getInstance(model).getAction(DeleteParticipantAction.getCommandName());
c.setEnabled(false);
cmdSup.setAction(c);
cmdSup.setSize(cmdDimension);
cmdsPanel.add(cmdSup);
crossList.add(cmdsPanel,BorderLayout.NORTH);
TableColumns crossColumns = new TableColumns();
crossColumns.addColumn("Matricule", 100);
crossColumns.addColumn("Chrono", 100);
crossColumns.addColumn("Commentaire", 385);
encodeTableModel = new EncodeTableModel(model, crossColumns);
JXTable tblCross = new JXTable(encodeTableModel);
tblCross.setColumnMargin(2);
tblCross.setSize(new Dimension(460, 300));
tblCross.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tblCross.setRowSelectionAllowed(true);
tblCross.setColumnSelectionAllowed(true);
tblCross.setCellSelectionEnabled(true);
tblCross.setAutoscrolls(true);
tblCross.setFillsViewportHeight(true);
tblCross.setDefaultEditor(Integer.class, new DefaultCellEditor(new JComboBox()));
JScrollPane scrollPane = new JScrollPane(tblCross);
scrollPane.setBorder(compound);
crossList.add(scrollPane, BorderLayout.CENTER);
return crossList;
}
public JTextField getTxtEncoder() {
return txtEncoder;
}
public void setTxtEncoder(JTextField txtEncoder) {
this.txtEncoder = txtEncoder;
}
public JTextField getTxtCrossDate() {
return txtCrossDate;
}
public void setTxtCrossDate(JTextField txtCrossDate) {
this.txtCrossDate = txtCrossDate;
}
public JTextField getTxtDistance() {
return txtDistance;
}
public void setTxtDistance(JFormattedTextField txtDistance) {
this.txtDistance = txtDistance;
}
@Override
public void update(Observable arg0, Object arg1) {
// TODO Auto-generated method stub
System.out.println("update");
encodeTableModel.refrech();
}
}
class StringEditor extends AbstractCellEditor implements TableCellEditor{
JFormattedTextField f;
public StringEditor() {
// TODO Auto-generated constructor stub
}
public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column){
System.out.println(row);
switch (column){
case 0:
MaskFormatter maskDistance = new MaskFormatter();
try {
maskDistance.setMask("******");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
maskDistance.setValidCharacters("0123456789.,");
f = new JFormattedTextField(maskDistance);
return f;
default :
return null;
}
}
public Object getCellEditorValue(){
return "rrrr";
}
public boolean stopCellEditing(){
return false;
}
@Override
public void addCellEditorListener(CellEditorListener arg0) {
// TODO Auto-generated method stub
}
@Override
public void cancelCellEditing() {
// TODO Auto-generated method stub
}
@Override
public boolean isCellEditable(EventObject arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public void removeCellEditorListener(CellEditorListener arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean shouldSelectCell(EventObject arg0) {
// TODO Auto-generated method stub
return false;
}
} |
Partager