@@ -42,14 +42,12 @@ public class Main extends Sorts {
42
42
private final Panel panelVisorMemoria = new Panel ();
43
43
// COMBOBOX
44
44
private final JComboBox <String > comboBoxTipoSort = new JComboBox <String >(nombreAlgoritmos );
45
- // private JComboBox<String> comboBoxTipoSort = new JComboBox<String>();
46
-
47
45
// JLABEL
48
46
private final JLabel lblTitleAlgoritmo = new JLabel ("Algoritmo de ordenacion" );
49
47
private final JLabel lblTitle = new JLabel ("Panel de control" );
50
48
private JLabel lblNumeroBarras = new JLabel ("Numero de barras" );
51
49
private JLabel lblRetardo = new JLabel ("Retardo: 1 ms" );
52
- private static JLabel lblTiempo = new JLabel ("Tiempo: 0 s 0 ms" );
50
+ private static JLabel lblTiempo = new JLabel ("Tiempo: 0 m 0 s 0 ms" );
53
51
private static JLabel lblMemoriaUsada = new JLabel ("Memoria usada: 0 MB" );
54
52
private static JLabel lblMemoriaMax = new JLabel ("Memoria maxima: 0 MB" );
55
53
private static JLabel lblMemoriaLibre = new JLabel ("Memoria libre: 0 MB" );
@@ -84,6 +82,7 @@ public static void main(String[] args) {
84
82
} catch (Exception e ) {
85
83
}
86
84
}
85
+ // ---------------------------------------------------------------------------------------------
87
86
88
87
public Main () {
89
88
}
@@ -99,6 +98,7 @@ public Main() {
99
98
Main (Sorts sorts ) {
100
99
this .sorts = sorts ;
101
100
}
101
+ // ---------------------------------------------------------------------------------------------
102
102
103
103
public void main () {
104
104
initialize ();
@@ -108,11 +108,12 @@ public void main() {
108
108
getPanelBarras ().add (barras );
109
109
barras .setLayout (null );
110
110
getPanelBarras ().setVisible (true );
111
- frame .setTitle ("Visualizador de prdenacion de matrices" );
111
+ frame .setTitle ("Visualizador de ordenacion de matrices" );
112
112
frame .setResizable (false );
113
113
frame .setVisible (true );
114
114
sorting ();
115
115
}
116
+ // ---------------------------------------------------------------------------------------------
116
117
117
118
private void initialize () {
118
119
final Color BLACK_SECUNDARIO = new Color (15 , 15 , 15 );
@@ -359,6 +360,7 @@ public void actionPerformed(ActionEvent e) {
359
360
lblTitle .setFont (new Font ("Arial" , Font .BOLD , 18 ));
360
361
panelMenu .add (lblTitle );
361
362
}
363
+ // ---------------------------------------------------------------------------------------------
362
364
363
365
/**
364
366
* Seleccion se cada uno de los metodos de ordenacion.
@@ -415,6 +417,7 @@ public void sorting() {
415
417
reinicio ();
416
418
pausa ();
417
419
}
420
+ // ---------------------------------------------------------------------------------------------
418
421
419
422
/**
420
423
* Pinta los textos debidamente actualizados en funcion del metodo de
@@ -426,6 +429,7 @@ public void textos() {
426
429
calcularTiempo ();
427
430
calcularMemoria ();
428
431
}
432
+ // ---------------------------------------------------------------------------------------------
429
433
430
434
/**
431
435
* Calcula la memoria y cambia los labels correspondientes.
@@ -436,24 +440,37 @@ public void calcularMemoria() {
436
440
lblMemoriaLibre .setText ("Memoria libre: " + memoria .libre + " MB" );
437
441
lblMemoriaUsada .setText ("Memoria usada: " + memoria .usada + " MB" );
438
442
}
443
+ // ---------------------------------------------------------------------------------------------
439
444
440
445
/**
441
446
* Tiempo usado para en la ejecucion entre el inicio y final de un algoritmo de
442
447
* ordenacion.
443
448
*/
444
- private int calcSegundos (int tiempo ) {
445
- return (int ) (tiempo / 1000 );
449
+ private int calcMin (int tiempo ) {
450
+ int min = tiempo ;
451
+ min = (min / 1000 ) / 60 ;
452
+ return min ;
453
+
454
+ }
455
+
456
+ private int calcSeg (int tiempo ) {
457
+ int seg = tiempo ;
458
+ seg = (seg / 1000 ) - (60 * calcMin (seg ));
459
+ return seg ;
446
460
}
447
461
448
- private int calcMilisegundos (int tiempo ) {
449
- tiempo = tiempo - (1000 * calcSegundos ((int ) tiempo ));
450
- return tiempo ;
462
+ private int calcMil (int tiempo ) {
463
+ int mil = tiempo ;
464
+ mil = mil - (1000 * (mil / 1000 ));
465
+ return mil ;
451
466
}
452
467
453
468
public void calcularTiempo () {
454
469
tiempo = fin - inicio ;
455
- lblTiempo .setText ("Tiempo: " + calcSegundos ((int ) tiempo ) + " s " + calcMilisegundos ((int ) tiempo ) + " ms" );
470
+ lblTiempo .setText ("Tiempo: " + calcMin ((int ) tiempo ) + " m " + calcSeg ((int ) tiempo ) + " s "
471
+ + calcMil ((int ) tiempo ) + " ms" );
456
472
}
473
+ // ---------------------------------------------------------------------------------------------
457
474
458
475
/**
459
476
* Reinicia algunas variables y textos despues de terminar un sort.
@@ -465,6 +482,7 @@ public void reinicio() {
465
482
memoria = new Memoria (0 );
466
483
Delay .n = sliderRetardo .getValue ();
467
484
}
485
+ // ---------------------------------------------------------------------------------------------
468
486
469
487
/**
470
488
* Mantiene un cicuito cerrado para la seleccion del Sort evitando que el
@@ -479,6 +497,7 @@ public void pausa() {
479
497
}
480
498
sorting ();
481
499
}
500
+ // ---------------------------------------------------------------------------------------------
482
501
483
502
/**
484
503
* Obtiene el tamaño seleccionado en el menu y cambia el tamaño de las barras
@@ -491,6 +510,7 @@ public void cambioNumBarras() {
491
510
barras .barras ();
492
511
barras .repaint ();
493
512
}
513
+ // ---------------------------------------------------------------------------------------------
494
514
495
515
/**
496
516
* Cambio el retardo o lentitud con la que se sejecuta la animacion de la
@@ -501,25 +521,44 @@ public void cambioRetardo() {
501
521
Delay .delay ();
502
522
lblRetardo .setText ("Retardo: " + Delay .n + " ms" );
503
523
}
524
+ // ---------------------------------------------------------------------------------------------
504
525
526
+ /**
527
+ * La clase SliderNumBarasPersonalizado agrega valores a un Slider para
528
+ * personalizar la forma de mostrar los distintos valores. En concreto agrega
529
+ * valores en base 2 del binario.
530
+ */
505
531
class SliderNumBarasPersonalizado {
506
532
533
+ /**
534
+ * Convierte un numero entero en un String.
535
+ *
536
+ * @param n la n indica el exponente por el cual se calcula.
537
+ * @return the string
538
+ */
507
539
private String convertirIntToString (int n ) {
508
540
final int base = 2 ;
509
541
String valor = String .valueOf ((int ) Math .pow (base , n ));
510
542
return valor ;
511
543
}
512
544
545
+ /**
546
+ * Establece los valores em funcion de la cantidad recividad por parametro.
547
+ *
548
+ * @param n la n es el numero de valores agreados.
549
+ * @return un hashtable con los valores agregados en base 2.
550
+ */
513
551
public Hashtable <Integer , JLabel > establecerValoresSlider (int n ) {
514
- Hashtable <Integer , JLabel > position = new Hashtable <Integer , JLabel >();
552
+ Hashtable <Integer , JLabel > posiciones = new Hashtable <Integer , JLabel >();
515
553
JLabel lblLabel ;
516
554
for (int i = 0 ; i <= n ; i ++) {
517
- position .put (i , lblLabel = new JLabel (convertirIntToString (i )));
555
+ posiciones .put (i , lblLabel = new JLabel (convertirIntToString (i )));
518
556
lblLabel .setForeground (Color .WHITE );
519
557
}
520
- return position ;
558
+ return posiciones ;
521
559
}
522
560
}
561
+ // ---------------------------------------------------------------------------------------------
523
562
524
563
public static JLabel getLblAccesos () {
525
564
return lblAccesos ;
0 commit comments