Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Stage Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Laifsyn committed Jun 15, 2024
1 parent c7887c0 commit aefe144
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void aligned(int frente, int cola, int capacidad, int longitud) {
// ******************************************

if (cola < capacidad - 1)
this.cola_surplus.setText("[" + (cola + 1 - capacidad) + "]");
this.cola_surplus.setText("[+" + (capacidad - (cola + 1)) + "...]");
else
this.cola_surplus.setText("");
}
Expand Down Expand Up @@ -201,7 +201,7 @@ void wrapped(int frente, int cola, int capacidad, int longitud) {

// ******************************************

this.cola_surplus.setText("[" + (cola + 1 - capacidad) + "]");
this.cola_surplus.setText("[" + (capacidad - (cola + 1)) + "]");
}

}
Expand Down
108 changes: 88 additions & 20 deletions src/main/java/com/utp/clsEstructuraDatos/laboratorio_3/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import javax.management.RuntimeErrorException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.utp.clsEstructuraDatos.Estructuras.colas.AbstractCola;
import com.utp.clsEstructuraDatos.Estructuras.colas.ColaCircular;
import com.utp.clsEstructuraDatos.Estructuras.colas.ColaSimple;
import com.utp.clsEstructuraDatos.Estructuras.colas.AbstractCola.QueueDrawer;

import static com.utp.clsEstructuraDatos.laboratorio_3.ColasApp.CMD.*;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

public class Main {
public static void main(String[] args) {
Expand All @@ -31,48 +32,106 @@ class ColasApp {
final JButton btn_quitar = new JButton("Quitar");
final JButton btn_limpiar = new JButton("Limpiar");
final JButton btn_mostrar = new JButton("Mostrar");
final JPanel panel_cola = new JPanel();
final JFrame frame = new JFrame(LABORATORIO);
AbstractCola<Integer> cola;

static int COLA_CIRCULAR = 0;
static int COLA_SIMPLE = 1;

ColasApp() {}

public void run_app() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.setLayout(null);
frame.add(content());
frame.setVisible(true);
frame.pack();
this.send_command(null);
}

ColasApp() {
this.btn_crear_cola.addActionListener(e -> {
// TODO: Descomentar

// String input = JOptionPane.showInputDialog(frame, "Ingrese la capacidad de la
// cola", "Crear Cola",
// JOptionPane.QUESTION_MESSAGE);
// try {
// Integer.parseInt(input);
// } catch (NumberFormatException e1) {
// JOptionPane.showMessageDialog(frame, "Debe ingresar un número entero",
// "Error",
// JOptionPane.ERROR_MESSAGE);
// return;
// }
// int capacidad_cola = Integer.parseInt(input);
var capacidad_cola = 10;
this.send_command(new CrearCola(capacidad_cola));
});
this.btn_insertar.addActionListener(e -> {
String input = JOptionPane.showInputDialog(frame, "Ingrese el elemento a insertar", "Insertar",
JOptionPane.QUESTION_MESSAGE);
try {
Integer.parseInt(input);
} catch (NumberFormatException e1) {
JOptionPane.showMessageDialog(frame, "Debe ingresar un número entero", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
int elemento = Integer.parseInt(input);
this.send_command(new Insertar<>(elemento));
});
this.btn_quitar.addActionListener(e -> {
this.send_command(new Quitar());
});
this.btn_limpiar.addActionListener(e -> {
this.send_command(new Limpiar());
});
this.btn_mostrar.addActionListener(e -> {
this.send_command(new Mostrar());
});
}

JPanel content() {
JPanel content = new JPanel();
content.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints(0, 0, 2, 3, 0, 0, GridBagConstraints.CENTER, 0,
new Insets(5, 5, 5, 5), 0, 0);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.insets.set(2, 3, 2, 3);
c.gridx = 0;
c.gridy = 0;
content.add(buttons_panel(), c);

c.gridy = 1;
content.add(panel_cola, c);
return content;
}

JPanel buttons_panel() {
JPanel buttons_panel = new JPanel();
buttons_panel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.insets.set(2, 3, 2, 3);

c.gridwidth = 2;
content.add(this.btn_crear_cola, c);
buttons_panel.add(this.btn_crear_cola, c);

c.gridy = 1;
c.gridwidth = 1;
content.add(this.btn_insertar, c);
buttons_panel.add(this.btn_insertar, c);
c.gridx = 1;
content.add(this.btn_quitar, c);
buttons_panel.add(this.btn_quitar, c);

c.gridy = 2;
c.gridx = 0;
content.add(this.btn_limpiar, c);
buttons_panel.add(this.btn_limpiar, c);
c.gridx = 1;
content.add(this.btn_mostrar, c);
buttons_panel.add(this.btn_mostrar, c);

c.gridy = 3;
c.gridx = 0;


return content;
return buttons_panel;
}

// Packs the frame to the preferred size, updating if undersized
Expand Down Expand Up @@ -108,28 +167,36 @@ case Pack() -> {
this.try_pack();
}
case CrearCola(int capacidad_cola) -> {
int cola = prompt_colas_type();
if (cola == COLA_CIRCULAR) {
this.cola = new ColaCircular<>(capacidad_cola);
} else {
this.cola = new ColaSimple<>(capacidad_cola);
}
// TODO: Descomentar
// int cola = prompt_colas_type();
// if (cola == COLA_CIRCULAR) {
// this.cola = new ColaCircular<>(capacidad_cola);
// } else {
// this.cola = new ColaSimple<>(capacidad_cola);
// }
this.cola = new ColaCircular<>(10);
String new_text = String.format("[%s (c:%d)]Recrear Cola", this.cola.getClass().getSimpleName(),
this.cola.capacity());
this.btn_crear_cola.setText(new_text);
switch_buttons(true);

this.send_command(new Redraw());
this.try_pack();
}
case Insertar<Integer>(Integer elemento) -> {
this.cola.insertar(elemento);
this.send_command(new Redraw());
}
case Quitar() -> {
this.cola.quitar();
this.send_command(new Redraw());
}
case Limpiar() -> {
this.cola.limpiar();
this.send_command(new Redraw());
}
case Mostrar() -> {
throw new RuntimeErrorException(null, "Not Implemented");
JOptionPane.showMessageDialog(frame, this.cola.toString(), "Cola", JOptionPane.INFORMATION_MESSAGE);
}
case null -> {
}
Expand All @@ -151,6 +218,7 @@ public static record Insertar<T>(T elemento) implements CMD {}
public static record Quitar() implements CMD {}
public static record Limpiar() implements CMD {}
public static record Mostrar() implements CMD {}
public static record Redraw() implements CMD {}
// @formatter:on
}
}

0 comments on commit aefe144

Please sign in to comment.