analisis_proyecto1.Ventana_principal.java Source code

Java tutorial

Introduction

Here is the source code for analisis_proyecto1.Ventana_principal.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package analisis_proyecto1;

import edu.uci.ics.jung.algorithms.layout.TreeLayout;
import edu.uci.ics.jung.graph.DelegateTree;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import edu.uci.ics.jung.visualization.RenderContext;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Paint;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.awt.image.ImageObserver;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import org.apache.commons.collections15.Transformer;
import org.jfree.chart.ChartPanel;

/**
 *
 * @author alecx
 */
public class Ventana_principal extends javax.swing.JFrame {

    /**
     * Creates new form Ventana_principal
     */
    public Ventana_principal() {
        initComponents();
        this.pack();
        this.setSize(785, 381);
        this.HeapSort.pack();
        this.HeapSort.setSize(674, 220);
        this.par_cercano.setSize(736, 279);
        this.heap.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        this.puntos_cercanos.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        HeapSort = new javax.swing.JDialog();
        jLabel4 = new javax.swing.JLabel();
        numbers = new javax.swing.JSpinner();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        simulacion_heap = new javax.swing.JDialog();
        par_cercano = new javax.swing.JDialog();
        jLabel8 = new javax.swing.JLabel();
        coor_y = new javax.swing.JSpinner();
        coor_x = new javax.swing.JSpinner();
        jLabel9 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();

        HeapSort.getContentPane().setLayout(null);

        jLabel4.setFont(new java.awt.Font("Consolas", 1, 18)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(240, 240, 240));
        jLabel4.setText("Agregar elementos del arreglo");
        HeapSort.getContentPane().add(jLabel4);
        jLabel4.setBounds(70, 30, 300, 46);

        numbers.setModel(new javax.swing.SpinnerNumberModel());
        HeapSort.getContentPane().add(numbers);
        numbers.setBounds(390, 30, 56, 38);

        jButton3.setText("Agregar");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });
        HeapSort.getContentPane().add(jButton3);
        jButton3.setBounds(250, 120, 104, 40);

        jButton4.setText("Continuar");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });
        HeapSort.getContentPane().add(jButton4);
        jButton4.setBounds(380, 120, 87, 40);

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/image2.png"))); // NOI18N
        HeapSort.getContentPane().add(jLabel6);
        jLabel6.setBounds(0, -310, 1070, 530);

        javax.swing.GroupLayout simulacion_heapLayout = new javax.swing.GroupLayout(
                simulacion_heap.getContentPane());
        simulacion_heap.getContentPane().setLayout(simulacion_heapLayout);
        simulacion_heapLayout.setHorizontalGroup(simulacion_heapLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 804, Short.MAX_VALUE));
        simulacion_heapLayout.setVerticalGroup(simulacion_heapLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 439, Short.MAX_VALUE));

        par_cercano.getContentPane().setLayout(null);

        jLabel8.setFont(new java.awt.Font("Consolas", 1, 18)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(240, 240, 240));
        jLabel8.setText("Ingrese la coordenada X y Y de cada punto:");
        par_cercano.getContentPane().add(jLabel8);
        jLabel8.setBounds(140, 0, 430, 60);
        par_cercano.getContentPane().add(coor_y);
        coor_y.setBounds(350, 90, 60, 40);
        par_cercano.getContentPane().add(coor_x);
        coor_x.setBounds(260, 90, 60, 40);

        jLabel9.setFont(new java.awt.Font("Consolas", 1, 18)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(240, 240, 240));
        jLabel9.setText("X");
        par_cercano.getContentPane().add(jLabel9);
        jLabel9.setBounds(290, 60, 40, 30);

        jButton6.setFont(new java.awt.Font("Consolas", 1, 18)); // NOI18N
        jButton6.setText("Continuar");
        jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton6MouseClicked(evt);
            }
        });
        par_cercano.getContentPane().add(jButton6);
        jButton6.setBounds(330, 180, 130, 40);

        jLabel10.setFont(new java.awt.Font("Consolas", 1, 18)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(240, 240, 240));
        jLabel10.setText("Y");
        par_cercano.getContentPane().add(jLabel10);
        jLabel10.setBounds(370, 60, 20, 30);

        jButton5.setFont(new java.awt.Font("Consolas", 1, 18)); // NOI18N
        jButton5.setText("Agregar");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton5MouseClicked(evt);
            }
        });
        par_cercano.getContentPane().add(jButton5);
        jButton5.setBounds(180, 180, 110, 40);

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/image2.png"))); // NOI18N
        par_cercano.getContentPane().add(jLabel7);
        jLabel7.setBounds(-560, -330, 1390, 610);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("Consolas", 1, 36)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(240, 240, 240));
        jLabel1.setText("Analisis de Lagoritmos");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(10, 20, 500, 41);

        jLabel2.setFont(new java.awt.Font("Consolas", 1, 18)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(240, 240, 240));
        jLabel2.setText("Laurenn Alecxandra Cruz Vargas");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(20, 80, 410, 37);

        jLabel3.setFont(new java.awt.Font("Consolas", 1, 18)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(240, 240, 240));
        jLabel3.setText("11211190");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(120, 120, 136, 30);

        jButton1.setText("HeapSort");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(350, 160, 130, 42);

        jButton2.setText("Par mas cercano");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(350, 250, 130, 50);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/lines-of-code.jpg"))); // NOI18N
        getContentPane().add(jLabel5);
        jLabel5.setBounds(-70, 0, 860, 380);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        this.HeapSort.setModal(true);
        this.HeapSort.pack();
        this.HeapSort.setSize(674, 220);

        this.HeapSort.setVisible(true);
    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        int size = this.heap_sort_numbers.size();
        boolean repetido = num_repetido((int) this.numbers.getValue());
        if (repetido == true) {
            JOptionPane.showMessageDialog(null, "Ese numero ya esta en la lista, no se aceptan numeros repetidos");
        } else {
            this.heap_sort_numbers.add((int) this.numbers.getValue());
            if (this.heap_sort_numbers.size() == (size + 1)) {
                JOptionPane.showMessageDialog(null, "Se ha agregado un numero a la lista");
            }

        }

    }//GEN-LAST:event_jButton3MouseClicked
     //--------------------------------HeapSort------------------------------------

    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked
        //Generando el arreglo visual de numeros

        this.HeapSort.setVisible(false);
        heap.setTitle("Laurenn Alecxandra Cruz| 11211190");
        heap.setSize(900, 500);
        heap.setVisible(true);
        JLabel titulo = new JLabel("Arreglo Inicial: ");
        titulo.setFont(new Font("Consolas", Font.BOLD, 14));
        Panelarreglo.add(titulo);
        this.panelgenera.setForeground(Color.cyan);

        JButton[] arreglo = new JButton[this.heap_sort_numbers.size()];
        for (int i = 0; i < this.heap_sort_numbers.size(); i++) {
            arreglo[i] = new JButton();
            arreglo[i].setText(Integer.toString(this.heap_sort_numbers.get(i)));
            arreglo[i].setBackground(Color.GREEN);
            Panelarreglo.add(arreglo[i]);
        }

        int[] array = new int[this.heap_sort_numbers.size()];

        //convierte ArreyList a arreglo
        for (int i = 0; i < this.heap_sort_numbers.size(); i++) {
            array[i] = this.heap_sort_numbers.get(i);
        }

        //LLamado a la funcion Heapsort
        Heapsort ordenamiento = new Heapsort(array);
        ordenamiento.ordenar();
        this.arboles = ordenamiento.getArbolesDelegate();
        //Visualizacion del arbol

        //---------------------Antes----------------------
        JButton preview = new JButton("Antes");
        preview.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int x = IncrementarIndice(1);

                if (x >= 0) {
                    if (vs != null) {
                        PanelArbol.remove(vs);
                    }
                    //-----------Dibujar arbol---------
                    vs = new BasicVisualizationServer<String, String>(
                            new TreeLayout<String, String>(arboles.get(x)), new Dimension(300, 300));
                    Transformer<String, Paint> vertexPaint = new Transformer<String, Paint>() {
                        public Paint transform(String i) {
                            return Color.GREEN;
                        }
                    };

                    RenderContext<String, String> renderContext = vs.getRenderContext();
                    renderContext.setVertexFillPaintTransformer(vertexPaint);
                    Transformer<String, String> transformer = new ToStringLabeller<String>();
                    renderContext.setEdgeLabelTransformer(transformer);
                    Transformer<String, String> vertexTransformer = new ToStringLabeller<String>();
                    renderContext.setVertexLabelTransformer(vertexTransformer);
                    vs.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
                    PanelArbol.add(vs);
                    PanelArbol.updateUI();

                } else {
                    indice = 0;
                }

            }
        });

        //-------------------Despues------------------------
        JButton next = new JButton("Siguiente");
        next.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int x = IncrementarIndice(0);

                if (x < arboles.size()) {
                    if (vs != null) {
                        PanelArbol.remove(vs);
                    }
                    //-----------Dibujar arbol---------
                    vs = new BasicVisualizationServer<String, String>(
                            new TreeLayout<String, String>(arboles.get(x)), new Dimension(250, 250));
                    Transformer<String, Paint> vertexPaint = new Transformer<String, Paint>() {
                        public Paint transform(String i) {
                            return Color.GREEN;
                        }
                    };

                    RenderContext<String, String> renderContext = vs.getRenderContext();
                    renderContext.setVertexFillPaintTransformer(vertexPaint);
                    Transformer<String, String> transformer = new ToStringLabeller<String>();
                    renderContext.setEdgeLabelTransformer(transformer);
                    Transformer<String, String> vertexTransformer = new ToStringLabeller<String>();
                    renderContext.setVertexLabelTransformer(vertexTransformer);
                    vs.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
                    PanelArbol.add(vs);
                    PanelArbol.updateUI();
                    heap.repaint();

                } else {
                    indice = arboles.size() - 1;
                }

            }
        });

        //---------------Terminar accion--------------------------
        JButton terminar = new JButton("Salir");
        terminar.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                heap_sort_numbers = new ArrayList();
                arboles = new ArrayList();
                indice = -1;
                PanelArbol = new JPanel();
                grid = new GridLayout(2, 0);
                flow = new FlowLayout();
                panelgenera = new JPanel(grid);
                Panelarreglo = new JPanel(flow);

                heap.dispose();
                HeapSort.dispose();
                heap = new JFrame();
                heap.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

            }
        });

        next.setBackground(Color.BLUE);
        preview.setBackground(Color.BLUE);
        terminar.setBackground(Color.BLUE);
        Panelarreglo.add(preview);
        Panelarreglo.add(next);
        Panelarreglo.add(terminar);

        this.panelgenera.add(Panelarreglo);
        this.panelgenera.add(PanelArbol);
        this.heap.add(panelgenera);
        heap.repaint();
        paintComponents(getGraphics());

        this.heap.setVisible(true);

    }//GEN-LAST:event_jButton4MouseClicked

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
        this.par_cercano.setVisible(true);

    }//GEN-LAST:event_jButton2MouseClicked

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MouseClicked
        int size = this.puntos.size();
        boolean rep = puntos_repetidos((int) this.coor_x.getValue(), (int) this.coor_y.getValue());

        if (rep == true) {
            JOptionPane.showMessageDialog(null, "El punto ya esta en la lista, no se aceptan repetidos");

        } else {
            this.puntos.add(new puntos((int) this.coor_x.getValue(), (int) this.coor_y.getValue()));
            if ((size + 1) == this.puntos.size()) {
                JOptionPane.showMessageDialog(null, "Se ha agregado el punto");
            }
        }
    }//GEN-LAST:event_jButton5MouseClicked

    //------------------------Par de puntos mas cercanos------------------------------------
    private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton6MouseClicked
        /*puntos.add(new puntos(2, 3));
          puntos.add(new puntos(12, 30));
          puntos.add(new puntos(40, 50));
          puntos.add(new puntos(5, 1));
          puntos.add(new puntos(3, 14));
          puntos.add(new puntos(20, 4));
          puntos.add(new puntos(1, 10));
          puntos.add(new puntos(20, 24));
          puntos.add(new puntos(10, 3));
          puntos.add(new puntos(12, 3));
          puntos.add(new puntos(7, 3));
          puntos.add(new puntos(21, 7));
          puntos.add(new puntos(10, 7));
          puntos.add(new puntos(15, 1));
          puntos.add(new puntos(9, 5));
          puntos.add(new puntos(24, 5));
          puntos.add(new puntos(30, 6));
          puntos.add(new puntos(38, 60));*/
        if (puntos.size() == 1) {
            JOptionPane.showMessageDialog(null, "Solo existe un punto");
        } else {

            puntos[] general1 = convertir();
            puntos[] general2 = convertir();
            puntos[] Px = sortx(general1);
            puntos[] Py = sorty(general2);
            this.ParMasCercano = new cerca(puntos);
            distancia = this.ParMasCercano.mas_cerca(Px, Py, general1.length);
            medianas = this.ParMasCercano.getMedianas();
            bitacora = this.ParMasCercano.getBitacora();
            grafica.createDataset(puntos, null, 0);
            //----Panel Inicial-------------------------------
            actual = grafica.generar_panel(null, 0);

            //---------Boton Siguiente------------------------
            JButton next = new JButton("Siguiente");
            next.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    indicem++;
                    indicep++;
                    if (indicem < medianas.size()) {
                        panelpuntos.remove(actual);
                        if (indicep < bitacora.size()) {
                            grafica.createDataset(puntos, bitacora.get(indicep).getArreglo(), 0);
                        }
                        actual = grafica.generar_panel(medianas, indicem);
                        panelpuntos.add(actual);
                        panelpuntos.updateUI();
                    } else if (indicem == medianas.size()) {
                        grafica.createDataset(puntos, distancia.getPuntos(), 1);
                        panelpuntos.remove(actual);
                        actual = grafica.generar_panel(medianas, indicem - 1);
                        panelpuntos.add(actual);
                        panelpuntos.updateUI();
                        String resp = "El par de puntos mas cercanos son:" + '\n';
                        resp += "(" + distancia.getPuntos()[0].getX() + "," + distancia.getPuntos()[0].getY() + ")";
                        resp += ",";
                        resp += "(" + distancia.getPuntos()[1].getX() + "," + distancia.getPuntos()[1].getY() + ")"
                                + '\n';
                        resp += "Distancia:" + distancia.getDistancia();
                        JOptionPane.showMessageDialog(null, resp);
                    } else {
                        indicem = medianas.size() - 1;
                        indicep = bitacora.size() - 1;
                    }

                }
            });

            //-----------Boton Antes-----------------
            JButton prev = new JButton("Antes");
            prev.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    indicem--;
                    indicep--;
                    if (indicem >= 0) {
                        panelpuntos.remove(actual);
                        if (indicep >= 0) {
                            grafica.createDataset(puntos, bitacora.get(indicep).getArreglo(), 0);
                        }
                        actual = grafica.generar_panel(medianas, indicem);
                        panelpuntos.add(actual);
                        panelpuntos.updateUI();

                    } else {
                        indicem = 0;
                        indicep = 0;
                    }

                }
            });
            //------------------------Ultima Accion------------------
            JButton terminar = new JButton("Salir");
            terminar.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    puntos_cercanos.dispose();
                    par_cercano.dispose();
                    puntos = new ArrayList();
                    medianas = new ArrayList();
                    bitacora = new ArrayList();
                    indice = -1;
                    indicem = -1;
                    indicep = -1;
                    panelpuntos = new JPanel(gridp);
                    panel_botones = new JPanel(flowp);
                    puntos_cercanos = new JFrame();
                    puntos_cercanos.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

                }
            });

            this.panel_botones.add(prev);
            this.panel_botones.add(next);
            this.panel_botones.add(terminar);
            this.panelpuntos.add(this.panel_botones);
            panelpuntos.add(actual);
            this.puntos_cercanos.add(this.panelpuntos);
            this.puntos_cercanos.repaint();
            this.puntos_cercanos.pack();
            this.puntos_cercanos.setVisible(true);

        }
    }//GEN-LAST:event_jButton6MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Ventana_principal.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Ventana_principal.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Ventana_principal.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Ventana_principal.class.getName())
                    .log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Ventana_principal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog HeapSort;
    private javax.swing.JSpinner coor_x;
    private javax.swing.JSpinner coor_y;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JSpinner numbers;
    private javax.swing.JDialog par_cercano;
    private javax.swing.JDialog simulacion_heap;
    // End of variables declaration//GEN-END:variables
    ArrayList<Integer> heap_sort_numbers = new ArrayList();
    ArrayList<puntos> puntos = new ArrayList();
    ArrayList<DelegateTree<String, String>> arboles = new ArrayList();
    ArrayList<Integer> medianas = new ArrayList();
    ArrayList<bitacora_puntos> bitacora = new ArrayList();
    BasicVisualizationServer<String, String> vs;
    GridLayout gridp = new GridLayout(2, 0);
    chart grafica = new chart();
    int indice = -1;
    int indicem = -1;
    int indicep = -1;
    puntos_cercanos distancia;
    JFrame heap = new JFrame();
    JFrame puntos_cercanos = new JFrame();
    JPanel PanelArbol = new JPanel();
    FlowLayout flowp = new FlowLayout();
    JPanel panelpuntos = new JPanel(gridp);
    JPanel panel_botones = new JPanel(flowp);
    GridLayout grid = new GridLayout(2, 0);
    FlowLayout flow = new FlowLayout();
    JPanel panelgenera = new JPanel(grid);
    JPanel Panelarreglo = new JPanel(flow);
    cerca ParMasCercano;
    ChartPanel actual;

    private int IncrementarIndice(int band) {
        //0->adelante
        //1->atras
        if (band == 0) {
            this.indice++;

        } else {
            this.indice--;
        }

        return this.indice;

    }

    private boolean num_repetido(int x) {
        //true, si hay repetido
        //false, no hay repetido
        boolean repetido = false;
        for (int i = 0; i < this.heap_sort_numbers.size(); i++) {
            if (this.heap_sort_numbers.get(i) == x) {
                repetido = true;
                break;
            }
        }
        return repetido;
    }

    private puntos[] sortx(puntos[] puntos) {
        for (int i = 0; i < puntos.length - 1; i++) {
            int minimo = i;
            for (int j = i + 1; j < puntos.length; j++) {
                if (puntos[j].getX() < puntos[minimo].getX()) {
                    minimo = j;
                }

            }
            if (i != minimo) {
                puntos temp = puntos[i];
                puntos[i] = puntos[minimo];
                puntos[minimo] = temp;
            }
        }
        return puntos;
    }

    private puntos[] sorty(puntos[] puntos) {
        for (int i = 0; i < puntos.length - 1; i++) {
            int minimo = i;
            for (int j = i + 1; j < puntos.length; j++) {
                if (puntos[j].getY() < puntos[minimo].getY()) {
                    minimo = j;
                }

            }
            if (i != minimo) {
                puntos temp = puntos[i];
                puntos[i] = puntos[minimo];
                puntos[minimo] = temp;
            }
        }
        return puntos;
    }

    private puntos[] convertir() {
        puntos[] x = new puntos[puntos.size()];
        for (int i = 0; i < puntos.size(); i++) {
            x[i] = puntos.get(i);
        }
        return x;
    }

    private boolean puntos_repetidos(int x, int y) {
        boolean repetido = false;
        for (int i = 0; i < this.puntos.size(); i++) {
            if ((this.puntos.get(i).getX() == x) && (this.puntos.get(i).getY() == y)) {
                repetido = true;
                break;
            }
        }
        return repetido;
    }
}