vista.DestinosMasConsultados.java Source code

Java tutorial

Introduction

Here is the source code for vista.DestinosMasConsultados.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 vista;

import controlador.ControladorDestinosMasConsultados;
import controlador.ControladorSession;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;

/**
 *
 * @author Emiliano
 */
public class DestinosMasConsultados extends javax.swing.JFrame {

    /**
     * Creates new form DestinosMasConsultados
     */
    public DestinosMasConsultados() {
        initComponents();
        setIconImage(new ImageIcon(getClass().getResource("/recursos/logoTT.png")).getImage());
    }

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

        jLabel1 = new javax.swing.JLabel();
        txtFiltroDestinos = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaDestinos = new javax.swing.JTable();
        panelDestinosMasConsultados = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Destinos mas consultados");

        jLabel1.setText("Filtrar destino");

        txtFiltroDestinos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFiltroDestinosActionPerformed(evt);
            }
        });

        tablaDestinos.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Destino", "Cantidad de consultas" }) {
            boolean[] canEdit = new boolean[] { false, false };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jScrollPane1.setViewportView(tablaDestinos);
        if (tablaDestinos.getColumnModel().getColumnCount() > 0) {
            tablaDestinos.getColumnModel().getColumn(0).setResizable(false);
            tablaDestinos.getColumnModel().getColumn(0).setPreferredWidth(10);
            tablaDestinos.getColumnModel().getColumn(1).setPreferredWidth(1);
        }

        javax.swing.GroupLayout panelDestinosMasConsultadosLayout = new javax.swing.GroupLayout(
                panelDestinosMasConsultados);
        panelDestinosMasConsultados.setLayout(panelDestinosMasConsultadosLayout);
        panelDestinosMasConsultadosLayout.setHorizontalGroup(panelDestinosMasConsultadosLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
        panelDestinosMasConsultadosLayout.setVerticalGroup(panelDestinosMasConsultadosLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 314, Short.MAX_VALUE));

        jLabel2.setText("Destinos ms consultados");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(panelDestinosMasConsultados, 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, 705, Short.MAX_VALUE)
                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel1).addGap(18, 18, 18)
                                        .addComponent(txtFiltroDestinos, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                202, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel2)).addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1).addComponent(txtFiltroDestinos,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 150,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(panelDestinosMasConsultados, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

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

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel panelDestinosMasConsultados;
    private javax.swing.JTable tablaDestinos;
    private javax.swing.JTextField txtFiltroDestinos;
    // End of variables declaration//GEN-END:variables

    public JPanel getPanelDestinosMasConsultados() {
        return panelDestinosMasConsultados;
    }

    public JTable getTablaDestinos() {
        return tablaDestinos;
    }

    public JTextField getTxtFiltroDestinos() {
        return txtFiltroDestinos;
    }

    public void iniciaVista() {
        setLocationRelativeTo(null);
        setVisible(true);
    }

    public void imprimeError(Exception e) {
        JOptionPane.showMessageDialog(this, "Ocurrio una excepcin: " + e.getMessage(), "Informacin",
                JOptionPane.ERROR_MESSAGE);
    }

    public void setControlador(ControladorDestinosMasConsultados c) {
        this.txtFiltroDestinos.addKeyListener(c);
    }

    public void setControladorSession(ControladorSession c) {
        this.getContentPane().addMouseListener(c);
        this.getContentPane().addFocusListener(c);
    }

    public void iniciarGraficos(CategoryDataset dataset) {
        // create the chart...
        final JFreeChart chart = ChartFactory.createBarChart("Paises mas consultados", // chart title
                "Paises", // domain axis label
                "Cantidad de consultas", // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips?
                false // URLs?
        );

        // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        // get a reference to the plot for further customisation...
        final CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);

        // set the range axis to display integers only...
        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        // disable bar outlines...
        final BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);

        // set up gradient paints for series...
        final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
        final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
        final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
        renderer.setSeriesPaint(0, gp0);
        renderer.setSeriesPaint(1, gp1);
        renderer.setSeriesPaint(2, gp2);

        final CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

        ChartPanel chartFinal = new ChartPanel(chart);
        chartFinal.setSize(new Dimension(600, 400));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(panelDestinosMasConsultados);
        panelDestinosMasConsultados.setLayout(jPanel1Layout);
        jPanel1Layout
                .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                                .addContainerGap(0, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                        .addContainerGap(0, Short.MAX_VALUE)));

    }

}