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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
|
public class AddEditStatistiquesCriteresAjoutVoyageDialog extends JPanel implements ChangeListener {
private static final long serialVersionUID = 1L;
public final static int ACCEPT_OPTION = 0;
public final static int CANCEL_OPTION = 1;
public final static String TEXT_ADD_TITLE = "Ajouter des voyages";
public final static String TEXT_ADD_SUBTITLE = "Ajout des voyages statistiques";
private final static String TEXT_GARE_VALIDATE_TOOLTIPS = "Double cliquer pour effacer";
private final static String TEXT_GARE_ERROR_TOOLTIPS = "Aucune gare séléctionnée";
private int returnValue;
private JSpinner nombreASelectionnerField;
private JLabel infoLabel;
private JPanel infoAreaPane;
private JTextField libelleClientOrigineField;
private JTextField libelleClientDestinataireField;
private JTextField codeUicOrigineField;
private JTextField codeUicDestinationField;
private JTextField codeGareOrigineField;
private JTextField codeGareDestinationField;
private JTextField codeLieuOrigineField;
private JTextField codeLieuDestinationField;
private JTextField libelleOrigineField;
private JTextField libelleDestinationField;
private JFormattedTextField debutPeriodeStatistiqueField;
private JFormattedTextField finPeriodeStatistiqueField;
private JFormattedTextField debutPeriodeOperationnelleField;
private JFormattedTextField finPeriodeOperationnelleField;
private AcceptAction acceptAction;
private CancelAction cancelAction;
private Action searchOrigineAction;
private Action searchDestinationAction;
private JDialogModel dialog;
private JTextArea infoArea;
private ILieu origine;
private ILieu destination;
private JRemoveLabel removeOrigineLabel;
private JRemoveLabel removeDestinationLabel;
private SpinnerNumberModel model;
public AddEditStatistiquesCriteresAjoutVoyageDialog() {
super(new BorderLayout());
initActions();
initComponents();
initComponentsAnnotations();
initEventHandling();
dialog = null;
this.add(buildContents(), BorderLayout.CENTER);
}
private void initActions() {
acceptAction = new AcceptAction();
cancelAction = new CancelAction();
searchOrigineAction = new SearchOrigineAction();
searchDestinationAction = new SearchDestinationAction();
}
private JPanel buildContents() {
FormLayout layout = new FormLayout("fill:default:grow",
"max(14dlu;pref), 6dlu, pref, 3dlu, pref");
PanelBuilder builder = new PanelBuilder(layout);
builder.setDefaultDialogBorder();
CellConstraints cc = new CellConstraints();
builder.add(buildInfoAreaPane(), cc.xy(1, 1));
builder.addSeparator("Informations", cc.xy(1, 3));
builder.add(buildEditorPanel(), cc.xy(1, 5));
return builder.getPanel();
}
private void initComponents() {
libelleClientOrigineField = new JTextField();
libelleClientDestinataireField = new JTextField();
codeUicOrigineField = new JTextField();
codeUicOrigineField.addActionListener(searchOrigineAction);
codeUicDestinationField = new JTextField();
codeUicDestinationField.addActionListener(searchDestinationAction);
codeGareOrigineField = new JTextField();
codeGareOrigineField.addActionListener(searchOrigineAction);
codeGareDestinationField = new JTextField();
codeGareDestinationField.addActionListener(searchDestinationAction);
codeLieuOrigineField = new JTextField();
codeLieuOrigineField.addActionListener(searchOrigineAction);
codeLieuDestinationField = new JTextField();
codeLieuDestinationField.addActionListener(searchDestinationAction);
libelleOrigineField = new JTextField();
libelleOrigineField.setEditable(false);
libelleDestinationField = new JTextField();
libelleDestinationField.setEditable(false);
debutPeriodeOperationnelleField = SwingComponentFactory
.createDateField(false, false);
finPeriodeOperationnelleField = SwingComponentFactory.createDateField(
false, false);
debutPeriodeStatistiqueField = SwingComponentFactory.createDateField(
false, false);
finPeriodeStatistiqueField = SwingComponentFactory.createDateField(
false, false);
model = new SpinnerNumberModel(1, 1,
1000, 1);
nombreASelectionnerField = new JSpinner(model);
nombreASelectionnerField.addChangeListener(this);
removeOrigineLabel = new JRemoveLabel();
removeOrigineLabel.addActionListener(new RemoveOrigineActionListener());
removeDestinationLabel = new JRemoveLabel();
removeDestinationLabel
.addActionListener(new RemoveDestinationActionListener());
}
private void initComponentsAnnotations() {
}
private void initEventHandling() {
}
private JPanel buildInfoAreaPane() {
infoLabel = new JLabel(ValidationResultViewFactory.getInfoIcon());
infoArea = new JTextArea(1, 38);
infoArea.setEditable(false);
infoArea.setOpaque(false);
FormLayout layout = new FormLayout("pref, 2dlu, default", "pref");
PanelBuilder builder = new PanelBuilder(layout);
CellConstraints cc = new CellConstraints();
builder.add(infoLabel, cc.xy(1, 1));
builder.add(infoArea, cc.xy(3, 1));
infoAreaPane = builder.getPanel();
infoAreaPane.setVisible(false);
return infoAreaPane;
}
/**
* affichage des components
*
* @return JComponent
*/
private JComponent buildEditorPanel() {
FormLayout layout = new FormLayout(
"RIGHT:MAX(40DLU;PREF):NONE,FILL:4DLU:NONE,FILL:21DLU:NONE,FILL:4DLU:NONE,FILL:50DLU:NONE,FILL:4DLU:NONE,FILL:50DLU:NONE,FILL:3DLU:NONE,RIGHT:MAX(40DLU;PREF):NONE,FILL:4DLU:NONE,FILL:21DLU:NONE,FILL:4DLU:NONE,FILL:20DLU:NONE,FILL:4DLU:NONE,FILL:26DLU:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0)",
"CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,FILL:DEFAULT:NONE");
PanelBuilder builder = new PanelBuilder(layout);
CellConstraints cc = new CellConstraints();
builder.add(libelleClientOrigineField, cc.xyw(3, 1, 3));
builder.addLabel("Libelle client origine", cc.xy(1, 1));
builder.addLabel("Lieu origine", cc.xy(1, 3));
builder.addLabel("Lieu destination", cc.xy(1, 5));
builder.addLabel("Début période statistique", cc.xy(1, 7));
builder.add(codeUicOrigineField, cc.xy(3, 3));
builder.add(codeUicDestinationField, cc.xy(3, 5));
builder.add(codeGareOrigineField, cc.xy(5, 3));
builder.add(codeGareDestinationField, cc.xy(5, 5));
builder.add(codeLieuOrigineField, cc.xy(7, 3));
builder.add(codeLieuDestinationField, cc.xy(7, 5));
builder.add(libelleOrigineField, cc.xyw(9, 3, 3));
builder.add(libelleDestinationField, cc.xyw(9, 5, 3));
builder.add(new JButton(searchOrigineAction), cc.xy(13, 3));
builder.add(new JButton(searchDestinationAction), cc.xy(13, 5));
builder.addLabel("Libelle client destinataire", cc.xywh(7, 1, 3, 1,
CellConstraints.RIGHT, CellConstraints.DEFAULT));
builder.add(libelleClientDestinataireField, cc.xyw(11, 1, 5));
builder.addLabel("Fin période statistique", cc.xywh(7, 7, 3, 1,
CellConstraints.RIGHT, CellConstraints.DEFAULT));
builder.add(debutPeriodeStatistiqueField, cc.xyw(3, 7, 3));
builder.add(finPeriodeStatistiqueField, cc.xywh(11, 7, 5, 1));
builder.add(debutPeriodeOperationnelleField, cc.xywh(3, 9, 3, 1));
builder.add(removeOrigineLabel, cc.xy(15, 3));
builder.add(removeDestinationLabel, cc.xy(15, 5));
builder.addLabel("Nombre à séléctionner*", cc.xy(1, 11));
builder.addLabel("Début période opérationnelle", cc.xy(1, 9));
builder.addLabel("Fin période opérationnelle", cc.xywh(7, 9, 3, 1,
CellConstraints.RIGHT, CellConstraints.DEFAULT));
builder.add(finPeriodeOperationnelleField, cc.xywh(11, 9, 5, 1));
builder.add(nombreASelectionnerField, cc.xywh(3, 11, 3, 1));
return builder.getPanel();
}
public int showDialog() {
return showDialog(null, null, null, null, null, null, 0);
}
public int showDialog(ILieu origine, ILieu destination,
String clientOrigine, String clientDestinataire, Date debutPeriode,
Date finPeriode, int nombreAPiocher) {
if (origine != null) {
setOrigine(origine);
} else {
removeOrigine();
}
if (destination != null) {
setDestination(destination);
} else {
removeDestination();
}
if (debutPeriode != null) {
debutPeriodeOperationnelleField.setValue(debutPeriode.getTime());
} else {
debutPeriodeOperationnelleField.setValue(null);
}
if (finPeriode != null) {
finPeriodeOperationnelleField.setValue(finPeriode.getTime());
} else {
finPeriodeOperationnelleField.setValue(null);
}
if (clientOrigine != null) {
libelleClientOrigineField.setText(clientOrigine);
} else {
libelleClientOrigineField.setText(null);
}
if (clientDestinataire != null) {
libelleClientDestinataireField.setText(clientDestinataire);
} else {
libelleClientDestinataireField.setText(null);
}
nombreASelectionnerField.setValue(nombreAPiocher);
dialog = new JDialogModel(TEXT_ADD_TITLE, TEXT_ADD_SUBTITLE, this,
new Action[] { acceptAction, cancelAction }, cancelAction);
dialog.setResizable(true);
dialog.showDialog();
dialog.dispose();
return returnValue;
}
public ILieu getSelectedLieuOrigine() {
return origine;
}
public ILieu getSelectedLieuDestination() {
return destination;
}
private void setOrigine(ILieu lieu) {
origine = lieu;
codeUicOrigineField.setText(lieu.getCodeUic());
codeGareOrigineField.setText(lieu.getCodeGare());
codeLieuOrigineField.setText(lieu.getCodeLieu());
libelleOrigineField.setText(lieu.getLibelle());
updateOrigine();
}
private void updateOrigine() {
if (libelleOrigineField.getText().equals("")) {
removeOrigineLabel.showErrorIcon(TEXT_GARE_ERROR_TOOLTIPS);
} else {
removeOrigineLabel.showValidateIcon(TEXT_GARE_VALIDATE_TOOLTIPS);
}
}
private void removeOrigine() {
origine = null;
codeUicOrigineField.setText(null);
codeGareOrigineField.setText(null);
codeLieuOrigineField.setText(null);
libelleOrigineField.setText(null);
updateOrigine();
}
private void setDestination(ILieu lieu) {
destination = lieu;
codeUicDestinationField.setText(lieu.getCodeUic());
codeGareDestinationField.setText(lieu.getCodeGare());
codeLieuDestinationField.setText(lieu.getCodeLieu());
libelleDestinationField.setText(lieu.getLibelle());
updateDestination();
}
private void updateDestination() {
if (libelleDestinationField.getText().equals("")) {
removeDestinationLabel.showErrorIcon(TEXT_GARE_ERROR_TOOLTIPS);
} else {
removeDestinationLabel
.showValidateIcon(TEXT_GARE_VALIDATE_TOOLTIPS);
}
}
private void removeDestination() {
destination = null;
codeUicDestinationField.setText(null);
codeGareDestinationField.setText(null);
codeLieuDestinationField.setText(null);
libelleDestinationField.setText(null);
updateDestination();
}
private final class AcceptAction extends AbstractAcceptAction {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
returnValue = ACCEPT_OPTION;
dialog.closeDialog();
}
}
private final class CancelAction extends AbstractCancelAction {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
returnValue = CANCEL_OPTION;
dialog.closeDialog();
}
}
private final class SearchOrigineAction extends AbstractSearchAction {
private static final long serialVersionUID = 4737192950769837825L;
public void actionPerformed(ActionEvent e) {
boolean search = !codeUicOrigineField.getText().equals("")
|| !codeGareOrigineField.getText().equals("")
|| !codeLieuOrigineField.getText().equals("");
SearchLieuDialog dialog = new SearchLieuDialog();
if (dialog.showDialog(codeUicOrigineField.getText(),
codeGareOrigineField.getText(), codeLieuOrigineField
.getText(), search) == SearchLieuDialog.ACCEPT_OPTION) {
setOrigine(dialog.getSelectedLieu());
}
}
}
private final class SearchDestinationAction extends AbstractSearchAction {
private static final long serialVersionUID = -8357761103552614035L;
public void actionPerformed(ActionEvent e) {
boolean search = !codeUicDestinationField.getText().equals("")
|| !codeGareDestinationField.getText().equals("")
|| !codeLieuDestinationField.getText().equals("");
SearchLieuDialog dialog = new SearchLieuDialog();
if (dialog.showDialog(codeUicDestinationField.getText(),
codeGareDestinationField.getText(),
codeLieuDestinationField.getText(), search) == SearchLieuDialog.ACCEPT_OPTION) {
setDestination(dialog.getSelectedLieu());
}
}
}
private final class RemoveOrigineActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
removeOrigine();
}
}
private final class RemoveDestinationActionListener implements
ActionListener {
public void actionPerformed(ActionEvent e) {
removeDestination();
}
}
// @SuppressWarnings("unused")
// private final class ValidationNombreAPiocherActionListener implements
// ActionListener {
//
// public void actionPerformed(ActionEvent e) {
//
// AddEditStatistiquesCriteresAjoutVoyageDialog dialog = new
// AddEditStatistiquesCriteresAjoutVoyageDialog();
//
// if (dialog.getNombreAPiocher() > 1000)
// nombreASelectionnerField.setValue(1000);
// }
// }
public int getNombreAPiocher() {
return (Integer) nombreASelectionnerField.getValue();
}
public String getLibelleClientOrigine() {
return libelleClientOrigineField.getText();
}
public String getLibelleClientDestination() {
return libelleClientDestinataireField.getText();
}
public Date getDebutPeriode() {
Date toDate = (Date) debutPeriodeStatistiqueField.getValue();
return toDate;
}
public Date getFinPeriode() {
Date toDate = (Date) finPeriodeStatistiqueField.getValue();
return toDate;
}
public void stateChanged(ChangeEvent ce) {
int valeur =model.getNumber().intValue();
if (valeur > 1000){
nombreASelectionnerField.setValue(1000);
System.out
.println("Attention: vous ne pouvez pas dépasser 1000 ajout ");
}
else{
}
}
//
// public SpinnerModel getModel() {
// return model;
// }
//
// private final class MySpinner implements SpinnerModel {
//
// public void addChangeListener(ChangeListener l) {
// ChangeEvent ce;
// l.stateChanged();
//
// }
//
// public Object getNextValue() {
// return null;
// }
//
// public Object getPreviousValue() {
// return null;
// }
//
// public Object getValue() {
//
// return nombreASelectionnerField.getValue();
// }
//
// public void removeChangeListener(ChangeListener l) {
//
// }
//
// public void setValue(Object value) {
// nombreASelectionnerField.setValue(value);
//
// }
//
// } |
Partager