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
| package fr.free.cdmrail;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
//import javafx.stage.Modality.APPLICATION_MODAL;
// Les fenêtres et dialogues diverses
public class CdmWindows {
/*
* ++++++++++++++++++++ Définition des éléments de la fenêtre ASSISTANT CDM-Rail ++++++++++++++++++++
*/
// Offset entre les ID des éléments successifs
private final short ASSISTANT_OFFSET_ID = 1;
// ID du premier élément de la fenêtre ASSISTANT CDM-Rail
private final short ASSISTANT_FIRST = 1000;
// ID des éléments de la fenêtre ASSISTANT_OFFSET_ID
public final short ASSISTANT_FLAG_FR = ASSISTANT_FIRST;
public final short ASSISTANT_SELECT_OPERATION = ASSISTANT_FLAG_FR + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_FLAG_EN = ASSISTANT_SELECT_OPERATION + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_RUN_DEMO = ASSISTANT_FLAG_EN + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_DRAWING_TUTO = ASSISTANT_RUN_DEMO + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_SHOW_TRACK_CAT = ASSISTANT_DRAWING_TUTO + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_START_NEW_LAYOUT = ASSISTANT_SHOW_TRACK_CAT + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_OPEN_LAYOUT = ASSISTANT_START_NEW_LAYOUT + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_READ_GENERAL_OVERVIEW = ASSISTANT_OPEN_LAYOUT + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_READ_USER_GUIDE = ASSISTANT_READ_GENERAL_OVERVIEW + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_CLOSE_ASSISTANT = ASSISTANT_READ_USER_GUIDE + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_NOT_DISPLAY = ASSISTANT_CLOSE_ASSISTANT + ASSISTANT_OFFSET_ID;
public final short ASSISTANT_EXIT_CDMRAIL = ASSISTANT_NOT_DISPLAY + ASSISTANT_OFFSET_ID;
// Largeur de la fenêtre ASSISTANT
private final double ASSISTANT_WIDTH = 380;
// Marges
private final double ASSISTANT_PADDING = 10;
// Espacement des éléments dans un HBox ou un VBox
private final double ASSISTANT_SPACING_HVBOX = 10;
// Les éléments modifiables de la fenêtre
// La fenêtre ASSISTANT
private Stage cdmAssistantStage = new Stage();
// Label entre les deux drapeaux
private Label selectOperationLabel = new Label();
// Bouton Lancer une démo
private Button runDemoButton = new Button();
// Bouton Didacticiels
private Button drawingTutoButton = new Button();
// Bouton Afficher catalogue de voies
private Button showTrackCatButton = new Button();
// Bouton Nouveau réseau
private Button startNewLayoutButtonButton = new Button();
// Bouton Ouvrir un réseau
private Button openLayoutButton = new Button();
// Bouton Présentation générale
private Button readGeneralOverviewButton = new Button();
// Bouton Guide d'utilisation
private Button readUserGuideButton = new Button();
// Bouton Fermer l'assistant
private Button closeAssistantButton = new Button();
// Case à cocher Ne pas afficher l'assistant au démarrage
private CheckBox notDisplayAssistantCheckBox = new CheckBox();
// Bouton Quitter CDM-Rail
private Button exitCdmRailButton = new Button();
// Retourne l'état affichage de l'ASSISTANT
// true si coché
public boolean getAssistantDisplayState() {
return !notDisplayAssistantCheckBox.isSelected();
}
// Positionne l'état affichage de l'ASSISTANT
// true pour le cocher
public void setAssistantDisplayState(boolean theState) {
notDisplayAssistantCheckBox.setSelected(theState);
}
// Retourne la fenêtre (Stage) de l'ASSISTANT
public Stage getCdmAssistantStage() {
return cdmAssistantStage;
}
// Création de la fenêtre ASSISTANT
// theTitle : titre de la fenêtre assistant
public void cdmAssistant() {
// Largeur de la fenêtre
cdmAssistantStage.setWidth(ASSISTANT_WIDTH);
// ---------- Zone avec les deux drapeaux
HBox topZone = new HBox();
// Taille de la zone
topZone.setPrefWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Espace entre les éléments
topZone.setSpacing(ASSISTANT_SPACING_HVBOX);
// Les marges
topZone.setPadding(new Insets(ASSISTANT_PADDING));
// Eléments de la zone
// Crée le bouton drapeau Français
Button frenchFlagButton = new Button();
// Ajoute l'image au bouton
frenchFlagButton.setGraphic(CdmImages.LoadImage("/Icons/ico_fr_flag.bmp"));
// Pas de marges
frenchFlagButton.setPadding(new Insets(0));
// Associe une action
frenchFlagButton.setOnAction(e -> CdmWindowsEvents.assistantButtonAction(ASSISTANT_FLAG_FR));
// Ajout du bouton
topZone.getChildren().add(frenchFlagButton);
// Largeur du label
selectOperationLabel.setPrefWidth(270);
// Alignement du texte
selectOperationLabel.setAlignment(javafx.geometry.Pos.CENTER);
// Ajout du Label
topZone.getChildren().add(selectOperationLabel);
// Crée le bouton drapeau English
Button englishFlagButton = new Button();
// Ajoute l'image au bouton
englishFlagButton.setGraphic(CdmImages.LoadImage("/Icons/ico_en_flag.bmp"));
// Pas de marges
englishFlagButton.setPadding(new Insets(0));
// Associe une action
englishFlagButton.setOnAction(e -> CdmWindowsEvents.assistantButtonAction(ASSISTANT_FLAG_EN));
// Ajout du bouton
topZone.getChildren().add(englishFlagButton);
// Alignement des éléments
topZone.setAlignment(javafx.geometry.Pos.CENTER);
// ---------- Zone avec les éléments entre la zone des drapeaux et la case à cocher
VBox middleTopZone = new VBox();
// Espace entre les éléments
middleTopZone.setSpacing(ASSISTANT_SPACING_HVBOX);
// Les marges
middleTopZone.setPadding(new Insets(ASSISTANT_PADDING));
// Taille du bouton Lancer une démo
runDemoButton.setMaxWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Ajout du bouton Lancer une démo
middleTopZone.getChildren().add(runDemoButton);
// Taille du bouton Didacticiels
drawingTutoButton.setMaxWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Ajout du bouton Didacticiels
middleTopZone.getChildren().add(drawingTutoButton);
// Taille du bouton Afficher catalogue des voies
showTrackCatButton.setMaxWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Ajout du bouton Afficher catalogue de voies
middleTopZone.getChildren().add(showTrackCatButton);
// Taille du bouton Nouveau réseau
startNewLayoutButtonButton.setMaxWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Ajout du bouton Nouveau réseau
middleTopZone.getChildren().add(startNewLayoutButtonButton);
// Taille du bouton Ouvrir un réseau
openLayoutButton.setMaxWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Ajout du bouton Ouvrir un réseau
middleTopZone.getChildren().add(openLayoutButton);
// Taille du bouton Présentation générale
readGeneralOverviewButton.setMaxWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Ajout du bouton Présentation générale
middleTopZone.getChildren().add(readGeneralOverviewButton);
// Taille du bouton Guide d'utilisation
readUserGuideButton.setMaxWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Ajout du bouton Guide d'utilisation
middleTopZone.getChildren().add(readUserGuideButton);
// Taille du bouton Fermer l'assistant
closeAssistantButton.setMaxWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Ajout du bouton Fermer l'assistant
middleTopZone.getChildren().add(closeAssistantButton);
// Associe une action
closeAssistantButton.setOnAction(e -> CdmWindowsEvents.assistantButtonAction(ASSISTANT_CLOSE_ASSISTANT));
// Alignement des éléments
middleTopZone.setAlignment(javafx.geometry.Pos.CENTER);
// ---------- Zone avec la case à cocher
VBox middleBottomZone = new VBox();
// Espace entre les éléments
middleBottomZone.setSpacing(ASSISTANT_SPACING_HVBOX);
// Les marges
middleBottomZone.setPadding(new Insets(ASSISTANT_PADDING));
// Par défaut la case à cocher n'est pas sélectionnée
// Ajout de la case à cocher
middleBottomZone.getChildren().add(notDisplayAssistantCheckBox);
// Associe une action
notDisplayAssistantCheckBox.setOnAction(e -> CdmWindowsEvents.assistantButtonAction(ASSISTANT_NOT_DISPLAY));
// Alignement des éléments
middleBottomZone.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
// Zone avec le bouton Quitter
VBox bottomZone = new VBox();
// Les marges
bottomZone.setPadding(new Insets(ASSISTANT_PADDING));
// Eléments de la zone
// Taille du bouton Quitter CDM-Rail
exitCdmRailButton.setMaxWidth(ASSISTANT_WIDTH - 2 * ASSISTANT_PADDING);
// Ajout du bouton Quitter CDM-Rail
bottomZone.getChildren().add(exitCdmRailButton);
// Associe une action
exitCdmRailButton.setOnAction(e -> CdmWindowsEvents.assistantButtonAction(ASSISTANT_EXIT_CDMRAIL));
// Alignement des éléments
bottomZone.setAlignment(javafx.geometry.Pos.CENTER);
// La fenêtre de l'assistant
// Noeud racine (Root Node) de la Scene,
VBox cdmAssistantRoot = new VBox(topZone, middleTopZone, middleBottomZone, bottomZone);
// Les marges
cdmAssistantRoot.setPadding(new Insets(ASSISTANT_PADDING));
// La Scene associée
Scene cdmAssistantScene = new Scene(cdmAssistantRoot);
cdmAssistantStage.setScene(cdmAssistantScene);
// Pour empécher le redimensionnement
cdmAssistantStage.setResizable(false);
// Pour empêcher sa fermeture par l'icône de fermeture
cdmAssistantStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
event.consume();
}
});
// Met à jour les textes en fonction de la langue
setLangueOfAssistant();
// Pour rester dans l'assistant
cdmAssistantStage.initModality(APPLICATION_MODAL);
// L'application principale reste en attente de la fermenture de l'assistant
cdmAssistantStage.showAndWait();
}
// Maj de la langue des libellés des de l'ASSISTANT
public void setLangueOfAssistant() {
// Titre de la fenêtre
cdmAssistantStage.setTitle(CdmGlobal.isFrenchLanguage() ? "ASSISTANT CDM-Rail" : "CDM-Rail ASSISTANT");
// Texte du bouton Exit CDM-Rail
exitCdmRailButton.setText(CdmGlobal.isFrenchLanguage() ? "Quitter CDM-Rail" : "Exit CDM-Rail");
// Texte du Label entre les deux drapeaux
selectOperationLabel.setText(CdmGlobal.isFrenchLanguage() ? "CHOISIR UNE OPERATION CI-DESSOUS" : "SELECT AN OPERATION BELOW");
// Bouton Lancer une démo
runDemoButton.setText(CdmGlobal.isFrenchLanguage() ? "Lancer une démo (exemple) de simulation" : "Run simulation demo");
// Bouton Didacticiels
drawingTutoButton.setText(CdmGlobal.isFrenchLanguage() ? "Didacticiels (videos) de dessin" : "Drawing tutorial");
// Bouton Afficher catalogue de voies
showTrackCatButton.setText(CdmGlobal.isFrenchLanguage() ? "Afficher les catalogues de voies" : "Show track catalogs");
// Bouton Nouveau réseau
startNewLayoutButtonButton.setText(CdmGlobal.isFrenchLanguage() ? "Démarrer le dessin d'un nouveau réseau" : "Start a new layout");
// Bouton Ouvrir un réseau
openLayoutButton.setText(CdmGlobal.isFrenchLanguage() ? "Ouvrir un réseau déjà existant" : "Open an already existing layout");
// Bouton Présentation générale
readGeneralOverviewButton.setText(CdmGlobal.isFrenchLanguage() ? "Lire la présentation générale (Aide->Présentation)" : "Read the general overview (Help->Overview)");
// Bouton Guide d'utilisation
readUserGuideButton.setText(CdmGlobal.isFrenchLanguage() ? "Lire le guide d'utilisation (Aide->Guide d'utilisation)" : "Read the user guide (Help->User guide)");
// Case à cocher Ne pas afficher l'assistant au démarrage
notDisplayAssistantCheckBox.setText(CdmGlobal.isFrenchLanguage() ? "Ne pas afficher l'assistant au démarrage" : "Do not display assistant on start");
// Bouton Fermer l'assistant
closeAssistantButton.setText(CdmGlobal.isFrenchLanguage() ? "Fermer l'assistant, et revenir au menu standard" : "Close assistant, and return to standard menu");
}
} |
Partager