Package interfaz.alterna

Source Code of interfaz.alterna.MapaVista

/*
* MapaVista.java
*
* Created on 27/07/2010, 08:36:26 PM
*/
package interfaz.alterna;

import baseconocimiento.utilidades.Mapeo;
import interfaz.utilidades.Pizarra;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import modelo.Barrio;
import modelo.Localidad;
import modelo.Mapa;

/**
*
* @author UNL
*/
public class MapaVista extends javax.swing.JDialog {

    private Mapa mapaDatos;
    private DefaultTableModel modeloTabla;
    private Vector data;
    private ArrayList<Localidad> localidad;
    private ArrayList<Barrio> conexiones;
    private Pizarra pizarra;

    /** Creates new form MapaVista */
    public MapaVista(java.awt.Frame parent, boolean modal, Mapa mapa) {
        super(parent, modal);
        initComponents();
        this.mapaDatos = mapa;
        this.modeloTabla = new DefaultTableModel(crearTablaDatos(), crearEncabezadosTabla());
        this.tablaCoordenadas.setModel(modeloTabla);

        seleccionUsuario();
        cargarAnimacion();
        this.pack();
    }

    public void cargarAnimacion() {
        this.pizarra = new Pizarra(this.mapaDatos);
        jPanelPizarraPanel.setLayout(new BorderLayout());
        jPanelPizarraPanel.setSize(700, 500);
        jPanelPizarraPanel.setPreferredSize(new Dimension(700, 500));
        jPanelPizarraPanel.add(this.pizarra, BorderLayout.CENTER);
    }

    public Vector crearTablaDatos() {
        data = new Vector();
        ArrayList<Localidad> localidades = this.mapaDatos.getLocalidades();
        Vector fila;
        for (Localidad localidad : localidades) {
            fila = new Vector();
            fila.add(localidad.getBarrio().getId());
            fila.add(localidad.getBarrio().getDenominacion());
            fila.add(localidad.getBarrio().getCoordenadaX());
            fila.add(localidad.getBarrio().getCoordenadaY());
            data.add(fila);
        }
        return data;
    }

    public Vector crearEncabezadosTabla() {
        Vector cabecera = new Vector();
        cabecera.add("Id");
        cabecera.add("Denominación");
        cabecera.add("X");
        cabecera.add("Y");
        return cabecera;
    }

    public ArrayList<Integer> extraerIndicesVecinosCajaTexto() {
        ArrayList<Integer> indices = new ArrayList<Integer>();
        String vecinosString = conexionpunto.getText();
        //String indicesVecinosString= conexionpunto.getText();
        for (int i = 0; i < vecinosString.length(); i++) {
            String vecinosStringAgregar = String.valueOf(vecinosString.charAt(i));
            System.out.println("Elemento: " + vecinosStringAgregar);
            if (!vecinosStringAgregar.equals(",")) {
                indices.add(Integer.parseInt(vecinosStringAgregar));
            }
        }
        System.out.println("INDICES-------------------------------");
        for (Integer integer : indices) {
            System.out.println(integer);
        }
        System.out.println("--------------------------------------");
        return indices;
    }

    public ArrayList<Barrio> crearListaBarrios(ArrayList<Integer> indices) {
        ArrayList<Localidad> localidades = this.mapaDatos.getLocalidades();
        ArrayList<Barrio> vecinos = new ArrayList<Barrio>();

        for (Integer indice : indices) {
            for (Localidad localidadExtraida : localidades) {
                if (localidadExtraida.getBarrio().getId() == indice) {
                    vecinos.add(localidadExtraida.getBarrio());
                }
            }
        }
        return vecinos;
    }

    public String extraerIndicesVecinos(int idBarrioABurcar) {
        ArrayList<Localidad> localidades = this.mapaDatos.getLocalidades();
        ArrayList<Barrio> vecinos = new ArrayList<Barrio>();
        String indicesVecinos = "";
        for (Localidad localidadExtraida : localidades) {
            if (localidadExtraida.getBarrio().getId() == idBarrioABurcar) {
                System.out.println("id localidad extraida " + localidadExtraida.getBarrio().getId());
                vecinos = localidadExtraida.getVecinos();
                break;
            }
        }
        for (Barrio barrio : vecinos) {
            indicesVecinos += barrio.getId() + ",";
        }
        return indicesVecinos.substring(0, indicesVecinos.length() - 1);
    }

    private void seleccionUsuario() {
        ListSelectionModel fila = tablaCoordenadas.getSelectionModel();
        System.out.println("filaseleccionada: " + fila.toString());
        fila.addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                ListSelectionModel lis = (ListSelectionModel) e.getSource();

                if (lis.isSelectionEmpty()) {
                } else {
                    int seleccionfila = lis.getMinSelectionIndex();
                    Vector vectorDato = obtenerVector(seleccionfila);
                    numeroTxt.setText(vectorDato.get(0).toString());
                    denominacion1.setText(vectorDato.get(1).toString());
                    coordenadax.setText(vectorDato.get(2).toString());
                    coordenaday.setText(vectorDato.get(3).toString());
                    conexionpunto.setText(extraerIndicesVecinos(Integer.parseInt(numeroTxt.getText())));
                    // conexionpunto.setText(vectorDato.get(4).toString());
                }
            }
        });
    }

    private Vector obtenerVector(int posicion) {
        int contador = 0;
        for (Object object : data) {
            if (contador == posicion) {
                return (Vector) (object);
            }
            contador++;
        }
        return null;
    }

    /** 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() {

        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaCoordenadas = new javax.swing.JTable();
        jPanel7 = new javax.swing.JPanel();
        botoneditar = new javax.swing.JButton();
        botonnuevo = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        numeroTxt = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        conexionpunto = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        denominacion1 = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        coordenadax = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        coordenaday = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jButtonGuardar = new javax.swing.JButton();
        jPanelPizarraPanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Mapa Ciudad de Loja");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Coordenadas de Puntos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 204, 51))); // NOI18N

        tablaCoordenadas.setFont(new java.awt.Font("Tahoma", 0, 12));
        tablaCoordenadas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Numero", "Barrio", "X", "Y"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaCoordenadas.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tablaCoordenadasKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(tablaCoordenadas);

        jPanel7.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        botoneditar.setFont(new java.awt.Font("Tahoma", 1, 12));
        botoneditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Files-text.png"))); // NOI18N
        botoneditar.setText("EDITAR");
        botoneditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botoneditarActionPerformed(evt);
            }
        });

        botonnuevo.setFont(new java.awt.Font("Tahoma", 1, 12));
        botonnuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/pencil_32.png"))); // NOI18N
        botonnuevo.setText("NUEVO");
        botonnuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonnuevoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(82, Short.MAX_VALUE)
                .addComponent(botoneditar)
                .addGap(57, 57, 57)
                .addComponent(botonnuevo)
                .addGap(63, 63, 63))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonnuevo)
                    .addComponent(botoneditar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Ingresar Nuevo Punto", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 204, 51))); // NOI18N

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("Numero:");

        numeroTxt.setEditable(false);
        numeroTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numeroTxtActionPerformed(evt);
            }
        });
        numeroTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                numeroTxtKeyTyped(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel5.setText("Conexion de  Punto: (*)");

        conexionpunto.setEditable(false);
        conexionpunto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                conexionpuntoKeyTyped(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel6.setText("Denominacion: (*)");

        denominacion1.setEditable(false);
        denominacion1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                denominacion1ActionPerformed(evt);
            }
        });
        denominacion1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                denominacion1KeyTyped(evt);
            }
        });

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Coordenadas (*)", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("X :");

        coordenadax.setEditable(false);
        coordenadax.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                coordenadaxKeyTyped(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("Y :");

        coordenaday.setEditable(false);
        coordenaday.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                coordenadayActionPerformed(evt);
            }
        });
        coordenaday.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                coordenadayKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap(199, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(coordenadax, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(coordenaday, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(coordenaday, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(coordenadax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Ayuda.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(conexionpunto, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel6))
                        .addGap(65, 65, 65)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(numeroTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
                            .addComponent(denominacion1, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(numeroTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(denominacion1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(conexionpunto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButtonGuardar.setFont(new java.awt.Font("Tahoma", 1, 12));
        jButtonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Floppy.png"))); // NOI18N
        jButtonGuardar.setText("GUARDAR");
        jButtonGuardar.setEnabled(false);
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jButtonGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(110, 110, 110)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(176, Short.MAX_VALUE))
            .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelPizarraPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Barrios Centrales de la Ciudad de Loja", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 204, 0))); // NOI18N

        javax.swing.GroupLayout jPanelPizarraPanelLayout = new javax.swing.GroupLayout(jPanelPizarraPanel);
        jPanelPizarraPanel.setLayout(jPanelPizarraPanelLayout);
        jPanelPizarraPanelLayout.setHorizontalGroup(
            jPanelPizarraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 865, Short.MAX_VALUE)
        );
        jPanelPizarraPanelLayout.setVerticalGroup(
            jPanelPizarraPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 581, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jPanelPizarraPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelPizarraPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(19, 19, 19))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

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

    private void tablaCoordenadasKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tablaCoordenadasKeyPressed
        System.out.println("me he seleccionada");
}//GEN-LAST:event_tablaCoordenadasKeyPressed

    private void botoneditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botoneditarActionPerformed
        jButtonGuardar.setEnabled(true);
        habilitarZonaIngreso();
}//GEN-LAST:event_botoneditarActionPerformed
    private void deshabilitarZonaIngreso() {
        denominacion1.setEditable(false);
        coordenadax.setEditable(false);
        coordenaday.setEditable(false);
        conexionpunto.setEditable(false);
    }

    private void habilitarZonaIngreso() {
        denominacion1.setEditable(true);
        coordenadax.setEditable(true);
        coordenaday.setEditable(true);
        conexionpunto.setEditable(true);
    }

    private void formatearZonaIngreso() {
        coordenaday.setText("");
        coordenadax.setText("");
        denominacion1.setText("");
        conexionpunto.setText("");
        numeroTxt.setText("");
    }

    private void limpiarEspaciosVaciosZonaIngreso() {
        coordenaday.setText(coordenaday.getText().trim());
        coordenadax.setText(coordenadax.getText().trim());
        denominacion1.setText(denominacion1.getText().trim());
        conexionpunto.setText(conexionpunto.getText().trim());
    }
    private void botonnuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonnuevoActionPerformed
        habilitarZonaIngreso();
        formatearZonaIngreso();
        numeroTxt.setText(String.valueOf(this.mapaDatos.getLocalidades().size() + 1));
        jButtonGuardar.setEnabled(true);
}//GEN-LAST:event_botonnuevoActionPerformed
    public void addNuevaLocalidadAMapa() {
        Localidad nuevaLocalidad = new Localidad();
        Barrio nuevoBarrio = new Barrio(Integer.parseInt(numeroTxt.getText()), denominacion1.getText(), Integer.parseInt(coordenadax.getText()), Integer.parseInt(coordenaday.getText()));
        nuevaLocalidad.setBarrio(nuevoBarrio);
        nuevaLocalidad.setVecinos(crearListaBarrios(extraerIndicesVecinosCajaTexto()));
        this.mapaDatos.addLocalidad(nuevaLocalidad);
        this.pizarra.repaint();
        this.modeloTabla = new DefaultTableModel(crearTablaDatos(), crearEncabezadosTabla());
        this.tablaCoordenadas.setModel(modeloTabla);

    }

    private void numeroTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numeroTxtActionPerformed
        numeroTxt.setEditable(false);
        // TODO add your handling code here:
}//GEN-LAST:event_numeroTxtActionPerformed

    private void numeroTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroTxtKeyTyped
        if (Character.isLetter(evt.getKeyChar())) {
            evt.consume()// TODO add your handling code here:
        }
}//GEN-LAST:event_numeroTxtKeyTyped

        private void conexionpuntoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_conexionpuntoKeyTyped
            // TODO add your handling code here:
}//GEN-LAST:event_conexionpuntoKeyTyped

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

        private void denominacion1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_denominacion1KeyTyped
            // TODO add your handling code here:
}//GEN-LAST:event_denominacion1KeyTyped

        private void coordenadaxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_coordenadaxKeyTyped
            if (!Character.isDigit(evt.getKeyChar())) {
                JOptionPane.showMessageDialog(this, "Por favor ingrese sólo números", "ALERTA", JOptionPane.ERROR_MESSAGE);
                evt.consume();
            }
            if (evt.getKeyChar() == '.') {
                JOptionPane.showMessageDialog(this, "Por favor ingrese sólo números", "ALERTA", JOptionPane.ERROR_MESSAGE);
            }
}//GEN-LAST:event_coordenadaxKeyTyped

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

            private void coordenadayKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_coordenadayKeyTyped
                if (!Character.isDigit(evt.getKeyChar())) {
                    JOptionPane.showMessageDialog(this, "Por favor ingrese sólo números", "ALERTA", JOptionPane.ERROR_MESSAGE);
                    evt.consume();
                }
                if (evt.getKeyChar() == '.') {
                    JOptionPane.showMessageDialog(this, "Por favor ingrese sólo números", "ALERTA", JOptionPane.ERROR_MESSAGE);
                }
}//GEN-LAST:event_coordenadayKeyTyped
    private boolean verificarCamposLlenosZonaIngreso() {
        limpiarEspaciosVaciosZonaIngreso();
        boolean bandera = false;
        if (!denominacion1.getText().equals("")) {
            if (!coordenadax.getText().equals("")) {
                if (!coordenaday.getText().equals("")) {
                    if (!conexionpunto.getText().equals("")) {
                        bandera = true;
                    }
                }
            }
        }
        return bandera;
    }
            private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed
                jButtonGuardar.setEnabled(false);
                if (verificarCamposLlenosZonaIngreso() == true) {
                    int seleccion = JOptionPane.showConfirmDialog(this, "ESTA SEGURO QUE DESEA GUARDAR LOS ULTIMOS CAMBIO", "ALERTA", JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE);
                    System.out.println("seleccion: " + seleccion);
                    if (seleccion == 0) {
                        addNuevaLocalidadAMapa();
                    }
                } else {
                    JOptionPane.showMessageDialog(this, "No se pudo guardar debido a que existen campos obligatorios incompletos y/o vacios", "WARNING", JOptionPane.WARNING_MESSAGE);
                    deshabilitarZonaIngreso();
                }
                formatearZonaIngreso();
                deshabilitarZonaIngreso();

}//GEN-LAST:event_jButtonGuardarActionPerformed

            private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
                JOptionPane.showMessageDialog(this,"El formato para ingresar la conexion \n de Puntos es: Punto1,Punto2,Punto3 \n"
                    "Ejemplo: 3,5,6","AVISO",JOptionPane.INFORMATION_MESSAGE);
            }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                MapaVista dialog = new MapaVista(new javax.swing.JFrame(), true, new Mapa(1, "Mapa de Loja", new Mapeo().mapearLocalidades()));
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botoneditar;
    private javax.swing.JButton botonnuevo;
    private javax.swing.JTextField conexionpunto;
    private javax.swing.JTextField coordenadax;
    private javax.swing.JTextField coordenaday;
    private javax.swing.JTextField denominacion1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonGuardar;
    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.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanelPizarraPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField numeroTxt;
    private javax.swing.JTable tablaCoordenadas;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of interfaz.alterna.MapaVista

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.