Added color setting.

Fixed missing comments.
Added version number.
This commit is contained in:
Chris Cromer
2016-08-14 19:29:17 -03:00
parent 00ce26c8d2
commit af120fdd34
12 changed files with 581 additions and 372 deletions

View File

@@ -3,6 +3,7 @@ package cl.cromer.estructuras;
import javafx.scene.paint.Color;
import java.util.Random;
import java.util.prefs.Preferences;
/**
* Rotación y generación de colores.
@@ -46,6 +47,19 @@ public class Colores {
* Cambiar el color al siguinte. Si no hay, voler al primer.
*/
public void siguinteColor() {
int colorsToUse;
Preferences preferences = (Preferences) Main.stage.getUserData();
if (preferences != null) {
colorsToUse = preferences.getInt("colors", MAX_COLORS);
}
else {
colorsToUse = MAX_COLORS;
}
if (colorsToUse <= color) {
color = 0;
}
switch (color) {
case 1:
color = 2;

View File

@@ -0,0 +1,79 @@
package cl.cromer.estructuras;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.stage.Stage;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.prefs.Preferences;
/**
* Esta clase es para controlar la configuración.
*
* @author Chris Cromer
*/
public class ConfigController implements Initializable {
/**
* El color ComboBox.
*/
@FXML
private ComboBox<Integer> colors;
/**
* Donde está guardado los idiomas.
*/
private ResourceBundle resourceBundle;
/**
* Inicializar todos los datos y dibujar las graficas.
*
* @param location URL: El URL de fxml en uso.
* @param resourceBundle ResourceBundle: Tiene datos de idioma.
*/
@Override
public void initialize(URL location, ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
}
/**
* Guardar los colores maximo a usar.
*/
@FXML
protected void changeColor() {
Stage stage = (Stage) colors.getScene().getWindow();
Preferences preferences = (Preferences) stage.getScene().getUserData();
if (preferences != null) {
preferences.putInt("colors", colors.getValue());
}
}
/**
* Cerrar la venta de configuración.
*/
@FXML
protected void closeConfig() {
Stage stage = (Stage) colors.getScene().getWindow();
stage.close();
}
/**
* Este metodo es para el evento de windowshown.
*/
public void handleWindowShownEvent() {
Stage stage = (Stage) colors.getScene().getWindow();
Preferences preferences = (Preferences) stage.getScene().getUserData();
for (int i = 2; i <= Colores.MAX_COLORS; i++) {
colors.getItems().add(i);
}
if (preferences != null) {
colors.setValue(preferences.getInt("colors", Colores.MAX_COLORS));
}
else {
colors.setValue(Colores.MAX_COLORS);
}
}
}

View File

@@ -241,7 +241,7 @@ public class Grafo {
}
}
/*
/**
* JBoss, Home of Professional Open Source Copyright 2006, Red Hat Middleware
* LLC, and individual contributors by the @authors tag. See the copyright.txt
* in the distribution for a full listing of individual contributors.

View File

@@ -27,6 +27,12 @@ import java.util.prefs.Preferences;
* @version 1.0.2
*/
public class Main extends Application {
static public String VERSION = "1.0.2";
/**
* El stage pricipal
*/
static public Stage stage;
/**
* El logger.
*/
@@ -35,10 +41,11 @@ public class Main extends Application {
/**
* Crear el stage y la scene para la aplicación grafica.
*
* @param stage Stage: El primer stage donde va todas las cosas visuales.
* @param startStage Stage: El primer stage donde va todas las cosas visuales.
*/
@Override
public void start(Stage stage) {
public void start(Stage startStage) {
stage = startStage;
String idioma;
String idioma2;
Preferences preferences;

View File

@@ -9,8 +9,11 @@ import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.MenuBar;
import javafx.scene.image.Image;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import java.io.IOException;
import java.net.URL;
@@ -348,6 +351,47 @@ public class MenuController extends VBox implements Initializable {
}
}
/**
* Click en Configuración
*/
@FXML
protected void menuConfig() {
Preferences preferences = (Preferences) Main.stage.getUserData();
if (preferences != null) {
Stage configStage = new Stage();
configStage.initModality(Modality.WINDOW_MODAL);
// Main is the daddy
configStage.initOwner(Main.stage);
try {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("/cl/cromer/estructuras/fxml/config.fxml"));
fxmlLoader.setResources(this.resourceBundle);
Parent parent = fxmlLoader.load();
Scene scene = new Scene(parent);
scene.setUserData(preferences);
scene.getStylesheets().add("/cl/cromer/estructuras/css/main.css");
configStage.setScene(scene);
configStage.setTitle(this.resourceBundle.getString("config"));
configStage.getIcons().add(new Image(getClass().getResourceAsStream("/cl/cromer/estructuras/images/icon.png")));
final ConfigController configController = fxmlLoader.getController();
configStage.addEventHandler(WindowEvent.WINDOW_SHOWN, window -> configController.handleWindowShownEvent());
configStage.show();
}
catch (IOException exception) {
// Este error es fatal, hay que cerrar la aplicación.
Logs.log(Level.SEVERE, exception);
configStage.close();
}
}
else {
Main.mostrarError(resourceBundle.getString("configNotAvailable"), resourceBundle);
}
}
/**
* Click en Acerca.
*/
@@ -356,7 +400,7 @@ public class MenuController extends VBox implements Initializable {
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.setContentText(resourceBundle.getString("titulo") + " " + Main.VERSION + "\n\n" +resourceBundle.getString("credito"));
dialog.getDialogPane().getButtonTypes().add(botonCerrar);
dialog.getDialogPane().getScene().getWindow().sizeToScene();
Main.setIcon(dialog, getClass());

View File

@@ -4,9 +4,17 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* Esta clase es una colleción de palabaras que se puede mostrar al azar.
*
* @author Chris Cromer
*/
public class Palabras {
final private List<String> palabras;
/**
* Inicilizar la lista de palabras.
*/
public Palabras() {
palabras = new ArrayList<>();
palabras.add("hola");
@@ -57,6 +65,11 @@ public class Palabras {
palabras.add("no");
}
/**
* Devolver una palabra al azar.
*
* @return String: La palabra.
*/
public String getPalabra() {
Random random = new Random();
int numero = random.nextInt(palabras.size());

View File

@@ -51,6 +51,7 @@ ingles=English
espanol=Spanish
cambiarIdioma=Change Language
cambiarIdiomaMensaje=To change the language the program must be restarted.\n\nAre you sure you wish the restart?
config=Settings
ayuda=Help
acerca=About
credito=Made by Christopher Cromer(chris@cromer.cl)\nCivil Engineering in Computer Science\nUniversity of the B\u00EDo B\u00EDo
@@ -112,4 +113,8 @@ grafoNoNumero=Please input a numeric node number.
tablaHashLleno=Key not inserted because the hash table is full.
tablaHashLlaveExiste=Key already exists.
tablaHashNoEsta=Key does not exist.
tablaHashNoLlave=Please input a key and a numeric value.
tablaHashNoLlave=Please input a key and a numeric value.
configNotAvailable=Settings is not avilable in the web version.
configColores=Colors:
configGuardar=Save

View File

@@ -51,6 +51,7 @@ espanol=Espa\u00F1ol
cambiarIdioma=Cambiar Idioma
cambiarIdiomaMensaje=Para cambiar el idioma el programa debe reiniciarse.\n\nUsted est\u00E1 seguro que desea reiniciar?
ayuda=Ayuda
config=Configuraci\u00F3n
acerca=Acerca
credito=Construido por Christopher Cromer\nIngenier\u00EDa Civil en Inform\u00E1tica\nUniversidad del B\u00EDo B\u00EDo
cambiar=Cambiar
@@ -111,4 +112,8 @@ grafoNoNumero=Ingresar un nodo num\u00E9rico por favor.
tablaHashLleno=La llave no fue insertado porque la tabla hash est\u00E1 lleno.
tablaHashLlaveExiste=La llave ya existe.
tablaHashNoEsta=La llave no existe.
tablaHashNoLlave=Ingresar una llave y un valor num\u00E9rico por favor.
tablaHashNoLlave=Ingresar una llave y un valor num\u00E9rico por favor.
configNotAvailable=Configuraci\u00F3n no está disponible en la versi\u00F3n web.
configColores=Colores:
configGuardar=Guardar

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--<?import java.lang.String?>
<?import javafx.collections.FXCollections?>-->
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.control.Button?>
<?import javafx.geometry.Insets?>
<VBox xmlns:fx="http://javafx.com/fxml/1" prefWidth="200"
xmlns="http://javafx.com/javafx/8.0.92" fx:controller="cl.cromer.estructuras.ConfigController">
<padding>
<Insets top="10" bottom="10" left="10" right="10"/>
</padding>
<VBox spacing="10">
<HBox alignment="CENTER" VBox.vgrow="ALWAYS" spacing="10">
<Text text="%configColores"/>
<ComboBox fx:id="colors" prefWidth="55" onAction="#changeColor">
<items>
<!--<FXCollections fx:factory="observableArrayList">
<String fx:value="1" />
<String fx:value="2" />
<String fx:value="3" />
<String fx:value="4" />
<String fx:value="5" />
<String fx:value="6" />
<String fx:value="7" />
</FXCollections>-->
</items>
<!--<value>
<String fx:value="7" />
</value>-->
</ComboBox>
</HBox>
<VBox alignment="TOP_CENTER">
<Button text="%configGuardar" onAction="#closeConfig"/>
</VBox>
</VBox>
</VBox>

View File

@@ -43,6 +43,7 @@
<MenuItem onAction="#menuEspanol" text="%espanol"/>
</Menu>
<Menu text="%ayuda">
<MenuItem onAction="#menuConfig" text="%config"/>
<MenuItem onAction="#menuAcerca" text="%acerca"/>
</Menu>
</MenuBar>