2016-06-20 13:25:01 -04:00
|
|
|
package cl.cromer.estructuras;
|
|
|
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.fxml.FXMLLoader;
|
|
|
|
import javafx.fxml.Initializable;
|
|
|
|
import javafx.scene.Parent;
|
|
|
|
import javafx.scene.Scene;
|
2016-06-29 00:33:19 -04:00
|
|
|
import javafx.scene.control.ButtonBar;
|
|
|
|
import javafx.scene.control.ButtonType;
|
|
|
|
import javafx.scene.control.Dialog;
|
|
|
|
import javafx.scene.control.MenuBar;
|
2016-06-20 13:25:01 -04:00
|
|
|
import javafx.scene.layout.VBox;
|
|
|
|
import javafx.stage.Stage;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
2016-06-26 23:34:33 -04:00
|
|
|
import static cl.cromer.estructuras.ListaEnlazadaTipos.SIMPLE;
|
|
|
|
|
2016-06-20 13:25:01 -04:00
|
|
|
/**
|
|
|
|
* Controlar las acciones cuando una opción es elegido en el menu.
|
|
|
|
*/
|
|
|
|
public class MenuController extends VBox implements Initializable {
|
|
|
|
/**
|
|
|
|
* La barra del menu.
|
|
|
|
*/
|
2016-06-29 00:33:19 -04:00
|
|
|
@FXML
|
|
|
|
private MenuBar menuBar;
|
2016-06-20 13:25:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Los idiomas.
|
|
|
|
*/
|
|
|
|
private ResourceBundle resourceBundle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inicialicar el menu con el idioma.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
|
|
|
* @param location URL: Tiene URL de FXML en uso.
|
2016-06-20 13:25:01 -04:00
|
|
|
* @param resourceBundle: Tiene los idiomas.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void initialize(URL location, ResourceBundle resourceBundle) {
|
|
|
|
this.resourceBundle = resourceBundle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Array Simple.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuArraySimple() {
|
2016-06-23 21:31:27 -04:00
|
|
|
ArrayTipos arrayTipos = new ArrayTipos(ArrayTipos.SIMPLE);
|
2016-06-20 13:25:01 -04:00
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloArraySimple"),
|
|
|
|
"/cl/cromer/estructuras/fxml/array.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css",
|
|
|
|
arrayTipos
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Array Ordenado.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuArrayOrdenado() {
|
2016-06-23 21:31:27 -04:00
|
|
|
ArrayTipos arrayTipos = new ArrayTipos(ArrayTipos.ORDENADO);
|
2016-06-20 13:25:01 -04:00
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloArrayOrdenado"),
|
|
|
|
"/cl/cromer/estructuras/fxml/array.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css",
|
|
|
|
arrayTipos
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Burbuja.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuBurbuja() {
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloBurbuja"),
|
|
|
|
"/cl/cromer/estructuras/fxml/burbuja.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css"
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Inserción.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuInsercion() {
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloInsercion"),
|
|
|
|
"/cl/cromer/estructuras/fxml/insercion.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css"
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Selecion.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuSeleccion() {
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloSeleccion"),
|
|
|
|
"/cl/cromer/estructuras/fxml/seleccion.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css"
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-21 21:49:31 -04:00
|
|
|
* Click en Shell.
|
2016-06-20 13:25:01 -04:00
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuShell() {
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloShell"),
|
|
|
|
"/cl/cromer/estructuras/fxml/shell.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css"
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-21 20:15:19 -04:00
|
|
|
/**
|
2016-06-21 21:49:31 -04:00
|
|
|
* Click en Quick.
|
2016-06-21 20:15:19 -04:00
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuQuick() {
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloQuick"),
|
|
|
|
"/cl/cromer/estructuras/fxml/quick.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css"
|
2016-06-21 21:49:31 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Merge.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuMerge() {
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloMerge"),
|
|
|
|
"/cl/cromer/estructuras/fxml/merge.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css"
|
2016-06-21 20:15:19 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-23 21:31:27 -04:00
|
|
|
/**
|
|
|
|
* Click en Lista Enlazada Simple.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuListaEnlazadaSimple() {
|
2016-06-26 23:34:33 -04:00
|
|
|
ListaEnlazadaTipos listaEnlazadaTipos = new ListaEnlazadaTipos(SIMPLE);
|
2016-06-23 21:31:27 -04:00
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloListaEnlazadaSimple"),
|
|
|
|
"/cl/cromer/estructuras/fxml/listaEnlazada.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css",
|
|
|
|
listaEnlazadaTipos
|
2016-06-26 13:03:04 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Lista Enlazada Circular.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuListaEnlazadaCircular() {
|
|
|
|
ListaEnlazadaTipos listaEnlazadaTipos = new ListaEnlazadaTipos(ListaEnlazadaTipos.CIRCULAR);
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloListaEnlazadaCircular"),
|
|
|
|
"/cl/cromer/estructuras/fxml/listaEnlazada.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css",
|
|
|
|
listaEnlazadaTipos
|
2016-06-26 13:03:04 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Lista Enlazada Doble.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuListaEnlazadaDoble() {
|
|
|
|
ListaEnlazadaTipos listaEnlazadaTipos = new ListaEnlazadaTipos(ListaEnlazadaTipos.DOBLEMENTE_ENLAZADA);
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloListaEnlazadaDoble"),
|
|
|
|
"/cl/cromer/estructuras/fxml/listaEnlazada.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css",
|
|
|
|
listaEnlazadaTipos
|
2016-06-23 21:31:27 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-20 13:25:01 -04:00
|
|
|
/**
|
|
|
|
* Click en Pila.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuPila() {
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloPila"),
|
|
|
|
"/cl/cromer/estructuras/fxml/pila.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css"
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Cola.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuCola() {
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
resourceBundle.getString("tituloCola"),
|
|
|
|
"/cl/cromer/estructuras/fxml/cola.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css"
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-07-02 15:22:16 -04:00
|
|
|
/**
|
|
|
|
* Click en Hash Table.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuHashTable() {
|
|
|
|
loadStage(
|
|
|
|
resourceBundle.getString("tituloTablaHash"),
|
|
|
|
"/cl/cromer/estructuras/fxml/hashTable.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-20 13:25:01 -04:00
|
|
|
/**
|
|
|
|
* Click en Ingles.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuIngles() {
|
|
|
|
ButtonType botonCambiar = new ButtonType(resourceBundle.getString("cambiar"), ButtonBar.ButtonData.OK_DONE);
|
|
|
|
ButtonType botonCancelar = new ButtonType(resourceBundle.getString("cancelar"), ButtonBar.ButtonData.CANCEL_CLOSE);
|
|
|
|
Dialog<ButtonType> dialog = new Dialog<>();
|
|
|
|
dialog.setTitle(resourceBundle.getString("cambiarIdioma"));
|
|
|
|
dialog.setContentText(resourceBundle.getString("cambiarIdiomaMensaje"));
|
|
|
|
dialog.getDialogPane().getButtonTypes().add(botonCancelar);
|
|
|
|
dialog.getDialogPane().getButtonTypes().add(botonCambiar);
|
|
|
|
dialog.getDialogPane().setPrefSize(400, 120);
|
2016-06-29 00:11:24 -04:00
|
|
|
Main.setIcon(dialog, getClass());
|
2016-06-20 13:25:01 -04:00
|
|
|
|
|
|
|
Optional<ButtonType> result = dialog.showAndWait();
|
|
|
|
if (result.isPresent() && result.get() == botonCambiar) {
|
|
|
|
// Si hace click en cambiar, cambiar el idioma y reiniciar.
|
|
|
|
Locale locale = new Locale("en", "EN");
|
|
|
|
ResourceBundle resourceBundle = ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale);
|
|
|
|
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
"/cl/cromer/estructuras/fxml/main.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css",
|
|
|
|
resourceBundle
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Español.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuEspanol() {
|
|
|
|
ButtonType botonCambiar = new ButtonType(resourceBundle.getString("cambiar"), ButtonBar.ButtonData.OK_DONE);
|
|
|
|
ButtonType botonCancelar = new ButtonType(resourceBundle.getString("cancelar"), ButtonBar.ButtonData.CANCEL_CLOSE);
|
|
|
|
Dialog<ButtonType> dialog = new Dialog<>();
|
|
|
|
dialog.setTitle(resourceBundle.getString("cambiarIdioma"));
|
|
|
|
dialog.setContentText(resourceBundle.getString("cambiarIdiomaMensaje"));
|
|
|
|
dialog.getDialogPane().getButtonTypes().add(botonCancelar);
|
|
|
|
dialog.getDialogPane().getButtonTypes().add(botonCambiar);
|
|
|
|
dialog.getDialogPane().setPrefSize(400, 120);
|
2016-06-29 00:11:24 -04:00
|
|
|
Main.setIcon(dialog, getClass());
|
2016-06-20 13:25:01 -04:00
|
|
|
|
|
|
|
Optional<ButtonType> result = dialog.showAndWait();
|
|
|
|
if (result.isPresent() && result.get() == botonCambiar) {
|
|
|
|
// Si hace click en cambiar, cambiar el idioma y reiniciar.
|
|
|
|
Locale locale = new Locale("es", "ES");
|
|
|
|
ResourceBundle resourceBundle = ResourceBundle.getBundle("cl.cromer.estructuras.bundles.Idioma", locale);
|
|
|
|
|
|
|
|
loadStage(
|
2016-06-29 00:33:19 -04:00
|
|
|
"/cl/cromer/estructuras/fxml/main.fxml",
|
|
|
|
"/cl/cromer/estructuras/css/style.css",
|
|
|
|
resourceBundle
|
2016-06-20 13:25:01 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click en Acerca.
|
|
|
|
*/
|
|
|
|
@FXML
|
|
|
|
protected void menuAcerca() {
|
|
|
|
ButtonType botonCerrar = new ButtonType(resourceBundle.getString("cerrar"), ButtonBar.ButtonData.OK_DONE);
|
|
|
|
Dialog<String> dialog = new Dialog<>();
|
|
|
|
dialog.setTitle(resourceBundle.getString("acerca"));
|
|
|
|
dialog.setContentText(resourceBundle.getString("credito"));
|
|
|
|
dialog.getDialogPane().getButtonTypes().add(botonCerrar);
|
2016-06-29 00:11:24 -04:00
|
|
|
Main.setIcon(dialog, getClass());
|
2016-06-20 13:25:01 -04:00
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cargar el fxml, css y titulo.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
2016-06-20 13:25:01 -04:00
|
|
|
* @param title String: El titulo de la escena.
|
2016-06-29 00:33:19 -04:00
|
|
|
* @param fxml String: El archivo de fxml.
|
|
|
|
* @param css String: El archivo de css.
|
2016-06-20 13:25:01 -04:00
|
|
|
*/
|
|
|
|
private void loadStage(String title, String fxml, String css) {
|
|
|
|
Scene scene = menuBar.getScene();
|
|
|
|
Stage stage = (Stage) scene.getWindow();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Parent parent = FXMLLoader.load(getClass().getResource(fxml), resourceBundle);
|
|
|
|
scene.setRoot(parent);
|
|
|
|
}
|
|
|
|
catch (IOException exception) {
|
|
|
|
// Este error es fatal, hay que cerrar la aplicación.
|
|
|
|
Logs.log(Level.SEVERE, "No se pudo abrir el archivo de fxml.");
|
|
|
|
stage.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
scene.getStylesheets().add(css);
|
|
|
|
stage.setScene(scene);
|
|
|
|
stage.setTitle(resourceBundle.getString("titulo") + " - " + title);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cargar el fxml y css.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
|
|
|
* @param fxml String: El archivo de fxml.
|
|
|
|
* @param css String: El archivo de css.
|
2016-06-21 20:15:19 -04:00
|
|
|
* @param resourceBundle ResourceBundle: El idioma nuevo para cambiarlo.
|
2016-06-20 13:25:01 -04:00
|
|
|
*/
|
|
|
|
private void loadStage(String fxml, String css, ResourceBundle resourceBundle) {
|
|
|
|
Scene scene = menuBar.getScene();
|
|
|
|
Stage stage = (Stage) scene.getWindow();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Parent parent = FXMLLoader.load(getClass().getResource(fxml), resourceBundle);
|
|
|
|
scene.setRoot(parent);
|
|
|
|
}
|
|
|
|
catch (IOException exception) {
|
|
|
|
// Este error es fatal, hay que cerrar la aplicación.
|
|
|
|
Logs.log(Level.SEVERE, "No se pudo abrir el archivo de fxml.");
|
|
|
|
stage.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
scene.getStylesheets().add(css);
|
|
|
|
stage.setScene(scene);
|
|
|
|
stage.setTitle(resourceBundle.getString("titulo"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cargar el fxml, css y titulo.
|
2016-06-29 00:33:19 -04:00
|
|
|
*
|
|
|
|
* @param title String: El titulo de la escena.
|
|
|
|
* @param fxml String: El archivo de fxml.
|
|
|
|
* @param css String: El archivo de css.
|
2016-06-21 20:15:19 -04:00
|
|
|
* @param object Object: El objeto a pasar a la nueva escena.
|
2016-06-20 13:25:01 -04:00
|
|
|
*/
|
|
|
|
private void loadStage(String title, String fxml, String css, Object object) {
|
|
|
|
Scene scene = menuBar.getScene();
|
|
|
|
Stage stage = (Stage) scene.getWindow();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Parent parent = FXMLLoader.load(getClass().getResource(fxml), resourceBundle);
|
|
|
|
scene.setRoot(parent);
|
|
|
|
}
|
|
|
|
catch (IOException exception) {
|
|
|
|
// Este error es fatal, hay que cerrar la aplicación.
|
|
|
|
Logs.log(Level.SEVERE, "No se pudo abrir el archivo de fxml.");
|
|
|
|
stage.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
scene.getStylesheets().add(css);
|
|
|
|
scene.setUserData(object);
|
|
|
|
stage.setScene(scene);
|
|
|
|
stage.setTitle(resourceBundle.getString("titulo") + " - " + title);
|
|
|
|
}
|
|
|
|
}
|