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 16, 2024
1 parent aefe144 commit e86b9ef
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ public String toString() {
return sb.toString();
}

public JPanel as_Jpanel() {
return new PanelDrawer(this).as_panel();
public PanelDrawer as_drawer() {
return new PanelDrawer(this);
}

private class PanelDrawer {
final JPanel panel = new JPanel(new GridBagLayout());
public class PanelDrawer {
final AbstractCola<T> cola;
final JLabel front_surplus = new JLabel();
final JLabel frente_item = new JLabel();
Expand All @@ -115,6 +114,26 @@ private class PanelDrawer {
*/
PanelDrawer(AbstractCola<T> cola) {
this.cola = cola;
}

public int frente() {
return this.cola.frente;
}

public int cola() {
return this.cola.cola;
}

public int longitud() {
return this.cola.longitud;
}

public int capacity() {
return this.cola.capacity();
}

public JPanel as_panel() {
JPanel panel = new JPanel(new GridBagLayout());
var c = new GridBagConstraints(0, 0, 1, 5, 0, 0, GridBagConstraints.CENTER, 0, new Insets(5, 5, 5, 5), 0,
0);
panel.add(front_surplus, c);
Expand All @@ -126,30 +145,30 @@ private class PanelDrawer {
panel.add(cola_item, c);
c.gridy = 4;
panel.add(cola_surplus, c);
}

JPanel as_panel() {
int frente = this.cola.frente;
int cola = this.cola.cola;
int capacidad = this.cola.capacity();
int longitud = this.cola.longitud;

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

if (frente > cola)
wrapped(frente, cola, capacidad, longitud);
wrapped();
else
aligned(frente, cola, capacidad, longitud);
aligned();

// ******************************************
return this.panel;
return panel;
}

/**
* llamado cuando frente (donde se retira de la fila) es menor o igual que el
* indice de la cola
*/
void aligned(int frente, int cola, int capacidad, int longitud) {
public void aligned() {
int frente = this.frente();
int cola = this.cola();
int capacidad = this.capacity();
int longitud = this.longitud();

if (frente > 0)
this.front_surplus.setText("[" + (frente - 1) + "]");
Expand Down Expand Up @@ -181,7 +200,12 @@ void aligned(int frente, int cola, int capacidad, int longitud) {
* llamado cuando frente (donde se retira de la fila) es mayor que el indice de
* la cola
*/
void wrapped(int frente, int cola, int capacidad, int longitud) {
public void wrapped() {

int frente = this.frente();
int cola = this.cola();
int capacidad = this.capacity();
int longitud = this.longitud();

this.front_surplus.setText("(" + frente + ")");

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/utp/clsEstructuraDatos/laboratorio_3/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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.*;

Expand All @@ -34,6 +33,7 @@ class ColasApp {
final JButton btn_mostrar = new JButton("Mostrar");
final JPanel panel_cola = new JPanel();
final JFrame frame = new JFrame(LABORATORIO);
AbstractCola<Integer>.PanelDrawer drawer;
AbstractCola<Integer> cola;

static int COLA_CIRCULAR = 0;
Expand Down Expand Up @@ -166,6 +166,10 @@ public void send_command(CMD command) {
case Pack() -> {
this.try_pack();
}
case Redraw() -> {

this.try_pack();
}
case CrearCola(int capacidad_cola) -> {
// TODO: Descomentar
// int cola = prompt_colas_type();
Expand All @@ -179,7 +183,9 @@ case CrearCola(int capacidad_cola) -> {
this.cola.capacity());
this.btn_crear_cola.setText(new_text);
switch_buttons(true);

this.drawer = this.cola.as_drawer();
this.panel_cola.removeAll();
this.panel_cola.add(drawer.as_panel());
this.send_command(new Redraw());
this.try_pack();
}
Expand Down

0 comments on commit e86b9ef

Please sign in to comment.