Example usage for javax.swing JMenuItem addActionListener

List of usage examples for javax.swing JMenuItem addActionListener

Introduction

In this page you can find the example usage for javax.swing JMenuItem addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:direccion.Reportes.java

public Reportes() {

    String titulo = "Reportes";
    jFrame = new JFrame(titulo);
    jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    jFrame.setSize(800, 600);//  w  w  w .  j  av  a2  s  .  co  m

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screenSize.width / 2) - (jFrame.getSize().width / 2);
    int y = (screenSize.height / 2) - (jFrame.getSize().height / 2);
    jFrame.setLocation(x, y);

    JLabel etiqueta = new JLabel("Reportes");
    etiqueta.setBounds(300, 25, 200, 50);
    etiqueta.setFont(new Font("Verdana", Font.BOLD, 30));
    etiqueta.setForeground(Color.BLACK);

    JMenuBar jMenuBar = new JMenuBar();

    JMenu acceso = new JMenu("Acceso a");
    JMenu ayuda = new JMenu("Ayuda");

    JMenuItem rec_hum = new JMenuItem("Recursos Humanos");
    JMenuItem conta = new JMenuItem("Contabilidad");
    JMenuItem ventas = new JMenuItem("Ventas");
    JMenuItem compras = new JMenuItem("Compras");
    JMenuItem inventario = new JMenuItem("Inventario");

    JMenuItem acerca_de = new JMenuItem("Acerca de");
    acerca_de.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "Ayuda", "Ayuda", 3);
        }
    });

    acceso.add(rec_hum);
    acceso.add(conta);
    acceso.add(ventas);
    acceso.add(compras);
    acceso.add(inventario);

    ayuda.add(acerca_de);

    jMenuBar.add(acceso);
    jMenuBar.add(ayuda);

    JCalendar cal1 = new JCalendar();
    cal1.setBounds(250, 150, 400, 300);
    JCalendarCombo cal2 = new JCalendarCombo();
    cal2.setBounds(250, 150, 400, 300);

    String reportes[] = { "Mantenimiento", "Compras", "Ventas", "Inventario", "Contabilidad",
            "Recursos Humanos" };
    JComboBox combobox = new JComboBox(reportes);
    combobox.setBounds(300, 100, 150, 30);

    JLabel calendario = new JLabel("Fecha de Operacin:");
    calendario.setBounds(60, 150, 150, 30);

    JButton aceptar = new JButton("Aceptar");
    aceptar.setBounds(50, 200, 150, 30);
    aceptar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (combobox.getSelectedIndex() == 0) {

                datos_mantenimiento.setValue("Recursos Humanos", d_mant_rh);
                datos_mantenimiento.setValue("Contabilidad", d_mant_cont);
                datos_mantenimiento.setValue("Ventas", d_mant_vent);
                datos_mantenimiento.setValue("Compras", d_mant_comp);
                datos_mantenimiento.setValue("Inventario", d_mant_inv);
                datos_mantenimiento.setValue("Mantenimiento", d_mant_mant);

                Grafica = ChartFactory.createPieChart3D("Mantenimiento", datos_mantenimiento, true, true, true);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Mantenimiento.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Mantenimiento");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Mantenimiento.xls");
                        Cell celda;

                        String[] titulos = { "Recursos Humanos", "Contabilidad", "Ventas", "Compras",
                                "Inventario", "Mantenimiento" };
                        Double[] datos = { d_mant_rh, d_mant_cont, d_mant_vent, d_mant_comp, d_mant_inv,
                                d_mant_mant };

                        int i;
                        for (i = 0; i < titulos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos[i]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 1) {

                datos_compras.setValue("Nomina", d_comp_nom);
                datos_compras.setValue("Compras", d_comp_comp);
                datos_compras.setValue("Gastos Fijos", d_comp_gf);
                datos_compras.setValue("Gastos Variables", d_comp_gv);
                datos_compras.setValue("Gastos Otros", d_comp_go);

                Grafica = ChartFactory.createPieChart3D("Compras", datos_compras, true, true, true);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Compras.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        menu.setVisible(false);
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(850, 850);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Compras");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Compras.xls");
                        Cell celda;

                        String[] titulos = { "Nomina", "Compras", "Gastos Fijos", "Gastos Variables",
                                "Gastos Otros" };
                        Double[] datos = { d_comp_nom, d_comp_comp, d_comp_gf, d_comp_gv, d_comp_go };

                        int i;
                        for (i = 0; i < titulos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos[i]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 2) {

                datos_ventas.addValue(d_vent_s1_lu, "Semana 1", "Lunes");
                datos_ventas.addValue(d_vent_s1_ma, "Semana 1", "Martes");
                datos_ventas.addValue(d_vent_s1_mi, "Semana 1", "Mircoles");
                datos_ventas.addValue(d_vent_s1_ju, "Semana 1", "Jueves");
                datos_ventas.addValue(d_vent_s1_vi, "Semana 1", "Viernes");
                datos_ventas.addValue(d_vent_s1_sa, "Semana 1", "Sbado");
                datos_ventas.addValue(d_vent_s1_do, "Semana 1", "Domingo");

                datos_ventas.addValue(d_vent_s2_lu, "Semana 2", "Lunes");
                datos_ventas.addValue(d_vent_s2_ma, "Semana 2", "Martes");
                datos_ventas.addValue(d_vent_s2_mi, "Semana 2", "Mircoles");
                datos_ventas.addValue(d_vent_s2_ju, "Semana 2", "Jueves");
                datos_ventas.addValue(d_vent_s2_vi, "Semana 2", "Viernes");
                datos_ventas.addValue(d_vent_s2_sa, "Semana 2", "Sbado");
                datos_ventas.addValue(d_vent_s2_do, "Semana 2", "Domingo");

                Grafica = ChartFactory.createLineChart3D("Ventas", "Das", "Ingresos", datos_ventas,
                        PlotOrientation.VERTICAL, true, true, false);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Ventas.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Ventas");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Ventas.xls");
                        Cell celda;

                        String[] titulos1 = { "S1 lunes", "S1 martes", "S1 miercoles", "S1 jueves",
                                "S1 viernes", "S1 sabado", "S1 domingo" };
                        String[] titulos2 = { "S2 lunes", "S2 martes", "S2 miercoles", "S2 jueves",
                                "S2 viernes", "S2 sabado", "S2 domingo" };
                        Double[] datos1 = { d_vent_s1_lu, d_vent_s1_ma, d_vent_s1_mi, d_vent_s1_ju,
                                d_vent_s1_vi, d_vent_s1_sa, d_vent_s1_do };
                        Double[] datos2 = { d_vent_s2_lu, d_vent_s2_ma, d_vent_s2_mi, d_vent_s2_ju,
                                d_vent_s2_vi, d_vent_s2_sa, d_vent_s2_do };

                        int i, j;
                        for (i = 0; i < titulos1.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos1[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos1.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos1[i]);
                        }
                        fila = sheet.createRow(3);
                        for (j = 0; j < titulos2.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(titulos2[j]);
                        }
                        fila = sheet.createRow(4);
                        for (j = 0; j < datos2.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(datos2[j]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 3) {

                datos_inventario.setValue("Producto 1", d_inv_p1);
                datos_inventario.setValue("Producto 2", d_inv_p2);
                datos_inventario.setValue("Producto 3", d_inv_p3);
                datos_inventario.setValue("Producto 4", d_inv_p4);
                datos_inventario.setValue("Producto 5", d_inv_p5);

                Grafica = ChartFactory.createPieChart3D("Inventario", datos_inventario, true, true, true);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Inventario.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Inventario");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Inventario.xls");
                        Cell celda;

                        String[] titulos = { "Producto 1", "Producto 2", "Prroducto 3", "Producto 4",
                                "Producto 5" };
                        Double[] datos = { d_inv_p1, d_inv_p2, d_inv_p3, d_inv_p4, d_inv_p5 };

                        int i;
                        for (i = 0; i < titulos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(titulos[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < datos.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(datos[i]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 4) {

                datos_contabilidad.addValue(d_cont_e_lu, "Entradas", "Lunes");
                datos_contabilidad.addValue(d_cont_e_ma, "Entradas", "Martes");
                datos_contabilidad.addValue(d_cont_e_mi, "Entradas", "Mircoles");
                datos_contabilidad.addValue(d_cont_e_ju, "Entradas", "Jueves");
                datos_contabilidad.addValue(d_cont_e_vi, "Entradas", "Viernes");
                datos_contabilidad.addValue(d_cont_e_sa, "Entradas", "Sbado");
                datos_contabilidad.addValue(d_cont_e_do, "Entradas", "Domingo");

                datos_contabilidad.addValue(d_cont_s_lu, "Salidas", "Lunes");
                datos_contabilidad.addValue(d_cont_s_ma, "Salidas", "Martes");
                datos_contabilidad.addValue(d_cont_s_mi, "Salidas", "Mircoles");
                datos_contabilidad.addValue(d_cont_s_ju, "Salidas", "Jueves");
                datos_contabilidad.addValue(d_cont_s_vi, "Salidas", "Viernes");
                datos_contabilidad.addValue(d_cont_s_sa, "Salidas", "Sbado");
                datos_contabilidad.addValue(d_cont_s_do, "Salidas", "Domingo");

                datos_contabilidad.addValue(d_cont_u_lu, "Utilidades", "Lunes");
                datos_contabilidad.addValue(d_cont_u_ma, "Utilidades", "Martes");
                datos_contabilidad.addValue(d_cont_u_mi, "Utilidades", "Mircoles");
                datos_contabilidad.addValue(d_cont_u_ju, "Utilidades", "Jueves");
                datos_contabilidad.addValue(d_cont_u_vi, "Utilidades", "Viernes");
                datos_contabilidad.addValue(d_cont_u_sa, "Utilidades", "Sbado");
                datos_contabilidad.addValue(d_cont_u_do, "Utilidades", "Domingo");

                Grafica = ChartFactory.createLineChart3D("Contabilidad", "Das", "Ingresos",
                        datos_contabilidad, PlotOrientation.VERTICAL, true, true, false);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Contabilidad.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Contabilidad");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Contabilidad.xls");
                        Cell celda;

                        String[] t_ent = { "E lunes", "E martes", "E miercoles", "E jueves", "E viernes",
                                "E sabado", "E domingo" };
                        String[] t_sal = { "S lunes", "S martes", "S miercoles", "S jueves", "S viernes",
                                "S sabado", "S domingo" };
                        String[] t_uti = { "U lunes", "U martes", "U miercoles", "U jueves", "U viernes",
                                "U sabado", "U domingo" };
                        Double[] d_ent = { d_cont_e_lu, d_cont_e_ma, d_cont_e_mi, d_cont_e_ju, d_cont_e_vi,
                                d_cont_e_sa, d_cont_e_do };
                        Double[] d_sal = { d_cont_s_lu, d_cont_s_ma, d_cont_s_mi, d_cont_s_ju, d_cont_s_vi,
                                d_cont_s_sa, d_cont_s_do };
                        Double[] d_uti = { d_cont_u_lu, d_cont_u_ma, d_cont_u_mi, d_cont_u_ju, d_cont_u_vi,
                                d_cont_u_sa, d_cont_u_do };

                        int i, j, k;
                        for (i = 0; i < t_ent.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(t_ent[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < d_ent.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(d_ent[i]);
                        }
                        fila = sheet.createRow(3);
                        for (j = 0; j < t_sal.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(t_sal[j]);
                        }
                        fila = sheet.createRow(4);
                        for (j = 0; j < d_sal.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(d_sal[j]);
                        }
                        fila = sheet.createRow(6);
                        for (k = 0; k < t_uti.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(t_uti[k]);
                        }
                        fila = sheet.createRow(7);
                        for (k = 0; k < d_uti.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(d_uti[k]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
            if (combobox.getSelectedIndex() == 5) {

                datos_rec_hum.addValue(d_rh_a_lu, "Asistencias", "Lunes");
                datos_rec_hum.addValue(d_rh_a_ma, "Asistencias", "Martes");
                datos_rec_hum.addValue(d_rh_a_mi, "Asistencias", "Mircoles");
                datos_rec_hum.addValue(d_rh_a_ju, "Asistencias", "Jueves");
                datos_rec_hum.addValue(d_rh_a_vi, "Asistencias", "Viernes");
                datos_rec_hum.addValue(d_rh_a_sa, "Asistencias", "Sbado");
                datos_rec_hum.addValue(d_rh_a_do, "Asistencias", "Domingo");

                datos_rec_hum.addValue(d_rh_r_lu, "Retardos", "Lunes");
                datos_rec_hum.addValue(d_rh_r_ma, "Retardos", "Martes");
                datos_rec_hum.addValue(d_rh_r_mi, "Retardos", "Mircoles");
                datos_rec_hum.addValue(d_rh_r_ju, "Retardos", "Jueves");
                datos_rec_hum.addValue(d_rh_r_vi, "Retardos", "Viernes");
                datos_rec_hum.addValue(d_rh_r_sa, "Retardos", "Sbado");
                datos_rec_hum.addValue(d_rh_r_do, "Retardos", "Domingo");

                datos_rec_hum.addValue(d_rh_f_lu, "Faltas", "Lunes");
                datos_rec_hum.addValue(d_rh_f_ma, "Faltas", "Martes");
                datos_rec_hum.addValue(d_rh_f_mi, "Faltas", "Mircoles");
                datos_rec_hum.addValue(d_rh_f_ju, "Faltas", "Jueves");
                datos_rec_hum.addValue(d_rh_f_vi, "Faltas", "Viernes");
                datos_rec_hum.addValue(d_rh_f_sa, "Faltas", "Sbado");
                datos_rec_hum.addValue(d_rh_f_do, "Faltas", "Domingo");

                Grafica = ChartFactory.createBarChart3D("Recursos Humanos", "Das", "Nmero de Empleados",
                        datos_rec_hum, PlotOrientation.VERTICAL, true, true, false);

                ChartPanel panel_grafica = new ChartPanel(Grafica);
                JFrame frame_grafica = new JFrame("Grfico");

                JMenuBar menu = new JMenuBar();
                JMenu archivo = new JMenu("Archivo");
                JMenuItem guardar = new JMenuItem("Guardar como reporte...");
                guardar.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Document document = new Document();
                        PdfWriter writer = null;
                        try {
                            writer = PdfWriter.getInstance(document,
                                    new FileOutputStream("Grfico Recursos Humanos.pdf"));
                        } catch (DocumentException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (FileNotFoundException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        document.open();
                        PdfContentByte cb = writer.getDirectContent();
                        PdfTemplate tp = cb.createTemplate(450, 450);
                        Graphics2D g2 = tp.createGraphicsShapes(450, 450);
                        menu.setVisible(false);
                        frame_grafica.print(g2);
                        menu.setVisible(true);
                        g2.dispose();
                        cb.addTemplate(tp, 30, 400);
                        document.close();

                        HSSFWorkbook workbook = new HSSFWorkbook();
                        HSSFSheet sheet = workbook.createSheet("Reporte de Recursos Humanos");

                        Row fila = sheet.createRow(0);
                        File archivo = new File("Reporte de Recursos Humanos.xls");
                        Cell celda;

                        String[] t_asi = { "A lunes", "A martes", "A miercoles", "A jueves", "A viernes",
                                "A sabado", "A domingo" };
                        String[] t_ret = { "R lunes", "R martes", "R miercoles", "R jueves", "R viernes",
                                "R sabado", "R domingo" };
                        String[] t_fal = { "F lunes", "F martes", "F miercoles", "F jueves", "F viernes",
                                "F sabado", "F domingo" };
                        int[] d_asi = { d_rh_a_lu, d_rh_a_ma, d_rh_a_mi, d_rh_a_ju, d_rh_a_vi, d_rh_a_sa,
                                d_rh_a_do };
                        int[] d_ret = { d_rh_r_lu, d_rh_r_ma, d_rh_r_mi, d_rh_r_ju, d_rh_r_vi, d_rh_r_sa,
                                d_rh_r_do };
                        int[] d_fal = { d_rh_f_lu, d_rh_r_ma, d_rh_r_mi, d_rh_r_ju, d_rh_r_vi, d_rh_r_sa,
                                d_rh_r_do };

                        int i, j, k;
                        for (i = 0; i < t_asi.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(t_asi[i]);
                        }
                        fila = sheet.createRow(1);
                        for (i = 0; i < d_asi.length; i++) {
                            celda = fila.createCell(i);
                            celda.setCellValue(d_asi[i]);
                        }
                        fila = sheet.createRow(3);
                        for (j = 0; j < t_ret.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(t_ret[j]);
                        }
                        fila = sheet.createRow(4);
                        for (j = 0; j < d_ret.length; j++) {
                            celda = fila.createCell(j);
                            celda.setCellValue(d_ret[j]);
                        }
                        fila = sheet.createRow(6);
                        for (k = 0; k < t_fal.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(t_fal[k]);
                        }
                        fila = sheet.createRow(7);
                        for (k = 0; k < d_fal.length; k++) {
                            celda = fila.createCell(k);
                            celda.setCellValue(d_fal[k]);
                        }
                        try {
                            FileOutputStream out = new FileOutputStream(archivo);
                            workbook.write(out);
                            out.close();
                            System.out.println("Archivo creado exitosamente!");
                        } catch (IOException ex) {
                            System.out.println("Error de escritura");
                            ex.printStackTrace();
                        }
                    }
                });
                archivo.add(guardar);
                menu.add(archivo);
                frame_grafica.getContentPane().add(panel_grafica);
                frame_grafica.setBounds(60, 60, 450, 400);
                frame_grafica.setJMenuBar(menu);
                frame_grafica.setVisible(true);
                frame_grafica.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            }
        }
    });

    jPanel = new JPanel();
    jPanel.setLayout(null);

    jPanel.add(cal1);
    jPanel.add(cal2);
    jPanel.add(etiqueta);
    jPanel.add(combobox);
    jPanel.add(calendario);
    jPanel.add(aceptar);
    jFrame.setJMenuBar(jMenuBar);
    jFrame.add(jPanel);

    jFrame.setVisible(true);
}

From source file:edu.clemson.cs.nestbed.client.gui.ConfigManagerFrame.java

private final JMenu buildProgramMenu() {
    final JMenu menu = new JMenu("Program");
    final JMenuItem uploadProgram = new JMenuItem("Upload Program");
    final JMenuItem deleteProgram = new JMenuItem("Delete Program");
    final JMenuItem configureAll = new JMenuItem("Configure All Motes");
    final JMenuItem unconfigureAll = new JMenuItem("Unconfigure All " + "Motes");

    uploadProgram.addActionListener(new UploadProgramActionListener());
    menu.add(uploadProgram);//  www  .j a va2  s  . co m

    deleteProgram.addActionListener(new DeleteProgramActionListener());
    menu.add(deleteProgram);

    menu.add(new JSeparator());

    configureAll.addActionListener(new ConfigureAllActionListener());
    menu.add(configureAll);

    unconfigureAll.addActionListener(new UnconfigureAllActionListener());
    menu.add(unconfigureAll);

    menu.addMenuListener(new ProgramMenuListener(deleteProgram));

    return menu;
}

From source file:com.choicemaker.cm.modelmaker.gui.utils.HistoChartPanel.java

public HistoChartPanel(final JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom,
        boolean tooltips, final ModelMaker modelMaker) {
    super(chart, properties, save, print, zoom, tooltips);
    this.modelMaker = modelMaker;
    // horizontal zoom doesn't work, by setting false we don't get bogus menu item
    //      setHorizontalZoom(false);
    //      setVerticalZoom(true);
    final JCheckBoxMenuItem logYScale = new JCheckBoxMenuItem(
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.test.logscale.y"));
    logYScale.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            CategoryPlot p = (CategoryPlot) chart.getPlot();
            Axis oldAxis = p.getRangeAxis();
            if (logYScale.isSelected()) {
                LogarithmicAxis yAxis = new LogarithmicAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs"));
                yAxis.setStrictValuesFlag(false);
                p.setRangeAxis(yAxis);//  w w w. java2  s  .c o m
            } else {
                p.setRangeAxis(new NumberAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs")));
            }
            oldAxis.setPlot(null);
            chartChanged(new ChartChangeEvent(this));
        }
    });
    JPopupMenu popup = getPopupMenu();
    popup.addSeparator();
    popup.add(logYScale);
    popup.addSeparator();
    select = new JMenu("Select");
    final JMenuItem all = new JMenuItem("All");
    select.add(all);
    final JMenuItem cmDiffer = new JMenuItem("Human marked differ");
    select.add(cmDiffer);
    final JMenuItem cmHold = new JMenuItem("Human marked hold");
    select.add(cmHold);
    final JMenuItem cmMatch = new JMenuItem("Human marked match");
    select.add(cmMatch);
    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
            filter.reset();
            filter.setFromPercentage(rangeFrom);
            filter.setToPercentage(rangeTo);
            Object src = ev.getSource();
            if (src != all) {
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                if (src == cmDiffer) {
                    b[Decision.DIFFER.toInt()] = true;
                } else if (src == cmHold) {
                    b[Decision.HOLD.toInt()] = true;
                } else if (src == cmMatch) {
                    b[Decision.MATCH.toInt()] = true;
                }
                filter.setHumanDecision(b);
            }
            modelMaker.filterMarkedRecordPairList();
        }
    };
    all.addActionListener(l);
    cmDiffer.addActionListener(l);
    cmHold.addActionListener(l);
    cmMatch.addActionListener(l);
    popup.add(select);
    addChartMouseListener(new ChartMouseListener() {
        public void chartMouseClicked(ChartMouseEvent evt) {
            ChartEntity e = evt.getEntity();
            if (e instanceof CategoryItemEntity) {
                CategoryItemEntity c = (CategoryItemEntity) e;
                int cat = c.getCategoryIndex();
                HistoCategoryDataset data = (HistoCategoryDataset) ((CategoryPlot) getChart().getPlot())
                        .getDataset();
                int len = data.getColumnCount();
                float step = 1f / len;
                rangeFrom = cat * step;
                rangeTo = rangeFrom + step;
                ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
                filter.reset();
                filter.setFromPercentage(rangeFrom);
                filter.setToPercentage(rangeTo);
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                int series = c.getSeries();
                if (data.isIncludeHolds() && series != 0) {
                    if (series == 1) {
                        series = 2;
                    } else {
                        series = 1;
                    }
                }
                b[series] = true;
                filter.setHumanDecision(b);
                modelMaker.filterMarkedRecordPairList();

            }
        }

        public void chartMouseMoved(ChartMouseEvent arg0) {
        }
    });
}

From source file:com.isencia.passerelle.hmi.HMIBase.java

/**
 * Constructs a default menu.//from   ww w.j a  v  a  2s  .c  o m
 * <ul>
 * <li>If the menuItems set is null, all default items are created.
 * <li>If the set is not null, only the menu items whose names are in there
 * are shown
 * </ul>
 * For an overview of the names, check HMIMessages.MENU_...
 * 
 * @param menuItemsToShow
 * @param menuItemsToHide
 * @return
 */
public JMenuBar createDefaultMenu(final Set<String> menuItemsToShow, final Set<String> menuItemsToHide) {
    final JMenuBar menuBar = new JMenuBar();

    final JMenu fileMenu = new JMenu(HMIMessages.getString(HMIMessages.MENU_FILE));
    fileMenu.setMnemonic(HMIMessages.getString(HMIMessages.MENU_FILE + HMIMessages.KEY).charAt(0));

    if (showThing(HMIMessages.MENU_TEMPLATES, menuItemsToShow, menuItemsToHide)) {
        final JMenu templatesSubMenu = new JMenu(HMIMessages.getString(HMIMessages.MENU_TEMPLATES));
        final Iterator itr = hmiModelsDef.getModels().keySet().iterator();

        final List<String> orderedList = new ArrayList<String>();
        while (itr.hasNext()) {
            final String modelKey = (String) itr.next();
            final String labelKey = modelKey; // HMIMessages.getString(modelKey);
            orderedList.add(labelKey);
        }
        Collections.sort(orderedList);

        for (int i = 0; i < orderedList.size(); i++) {
            try {
                // JMenuItem templateMenuItem = new
                // JMenuItem(HMIMessages.getString(HMIMessages.MENU_TEMPLATES)
                // + " " + HMIMessages.getString(modelKey));
                final JMenuItem templateMenuItem = new JMenuItem(HMIMessages.getString(orderedList.get(i)));
                templateMenuItem.addActionListener(new TemplateModelOpener(orderedList.get(i)));
                templatesSubMenu.add(templateMenuItem);
            } catch (final Exception e1) {
                e1.printStackTrace();
                logger.error("", e1);
            }
        }
        fileMenu.add(templatesSubMenu);

        StateMachine.getInstance().registerActionForState(StateMachine.READY, HMIMessages.MENU_TEMPLATES,
                templatesSubMenu);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, HMIMessages.MENU_TEMPLATES,
                templatesSubMenu);

    }

    if (showModelGraph) {
        if (showThing(HMIMessages.MENU_NEW, menuItemsToShow, menuItemsToHide)) {
            if (modelCreatorAction == null) {
                modelCreatorAction = new ModelCreator(this);
            }
            fileMenu.add(modelCreatorAction);
            // final JMenuItem fileNewMenuItem = new JMenuItem(HMIMessages
            // .getString(HMIMessages.MENU_NEW), HMIMessages.getString(
            // HMIMessages.MENU_NEW + HMIMessages.KEY).charAt(0));
            // fileNewMenuItem.setAccelerator(KeyStroke.getKeyStroke(
            // KeyEvent.VK_N, InputEvent.CTRL_MASK));
            // fileNewMenuItem.addActionListener(new ModelCreator());
            // fileMenu.add(fileNewMenuItem);

            // StateMachine.getInstance().registerActionForState(
            // StateMachine.READY, HMIMessages.MENU_NEW, fileNewMenuItem);
            // StateMachine.getInstance().registerActionForState(
            // StateMachine.MODEL_OPEN, HMIMessages.MENU_NEW,
            // fileNewMenuItem);
        }
    }

    if (showThing(HMIMessages.MENU_OPEN, menuItemsToShow, menuItemsToHide)) {
        final JMenuItem fileOpenMenuItem = new JMenuItem(HMIMessages.getString(HMIMessages.MENU_OPEN),
                HMIMessages.getString(HMIMessages.MENU_OPEN + HMIMessages.KEY).charAt(0));
        fileOpenMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
        fileOpenMenuItem.addActionListener(new ModelOpener());
        fileMenu.add(fileOpenMenuItem);

        StateMachine.getInstance().registerActionForState(StateMachine.READY, HMIMessages.MENU_OPEN,
                fileOpenMenuItem);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, HMIMessages.MENU_OPEN,
                fileOpenMenuItem);
    }

    if (showThing(HMIMessages.MENU_CLOSE, menuItemsToShow, menuItemsToHide)) {
        final JMenuItem fileCloseMenuItem = new JMenuItem(HMIMessages.getString(HMIMessages.MENU_CLOSE),
                HMIMessages.getString(HMIMessages.MENU_CLOSE + HMIMessages.KEY).charAt(0));
        fileCloseMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
        fileCloseMenuItem.addActionListener(new ModelCloser());
        fileMenu.add(fileCloseMenuItem);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, HMIMessages.MENU_CLOSE,
                fileCloseMenuItem);
    }
    if (showThing(HMIMessages.MENU_SAVE, menuItemsToShow, menuItemsToHide)) {
        fileMenu.add(new JSeparator());
        if (saveAction == null) {
            saveAction = new SaveAction(this);
        }
        fileMenu.add(saveAction);
        // StateMachine.getInstance().registerActionForState(
        // StateMachine.MODEL_OPEN, HMIMessages.MENU_SAVE, save);
    }
    if (showThing(HMIMessages.MENU_SAVEAS, menuItemsToShow, menuItemsToHide)) {
        if (saveAsAction == null) {
            saveAsAction = new SaveAsAction(this);
        }
        fileMenu.add(saveAsAction);
        // StateMachine.getInstance().registerActionForState(
        // StateMachine.MODEL_OPEN, HMIMessages.MENU_SAVEAS, save);
    }
    if (showThing(HMIMessages.MENU_EXIT, menuItemsToShow, menuItemsToHide)) {
        final JMenuItem exitMenuItem = new JMenuItem(HMIMessages.getString(HMIMessages.MENU_EXIT),
                HMIMessages.getString(HMIMessages.MENU_EXIT + HMIMessages.KEY).charAt(0));
        exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
        exitMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
                if (logger.isTraceEnabled()) {
                    logger.trace("Exit action - entry"); //$NON-NLS-1$
                }

                logger.info(HMIMessages.getString(HMIMessages.INFO_EXIT));
                // DBA to be validating...
                // Application which use HMIBase needs to call exit
                // treatment before exiting
                exitApplication();

                if (logger.isTraceEnabled()) {
                    logger.trace("Exit action - exit"); //$NON-NLS-1$
                }

                System.exit(0);
            }
        });
        fileMenu.add(new JSeparator());
        fileMenu.add(exitMenuItem);

        StateMachine.getInstance().registerActionForState(StateMachine.READY, HMIMessages.MENU_EXIT,
                exitMenuItem);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, HMIMessages.MENU_EXIT,
                exitMenuItem);
    }

    final JMenu runMenu = new JMenu(HMIMessages.getString(HMIMessages.MENU_RUN));
    runMenu.setMnemonic(HMIMessages.getString(HMIMessages.MENU_RUN + HMIMessages.KEY).charAt(0));

    if (showThing(HMIMessages.MENU_EXECUTE, menuItemsToShow, menuItemsToHide)) {
        if (modelExecutor == null) {
            modelExecutor = new ModelExecutor(this);
        }
        final JMenuItem runExecuteMenuItem = new JMenuItem(modelExecutor);
        runMenu.add(runExecuteMenuItem);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, HMIMessages.MENU_EXECUTE,
                modelExecutor);
    }
    if (showThing(HMIMessages.MENU_STOP, menuItemsToShow, menuItemsToHide)) {
        if (modelStopper == null) {
            modelStopper = new ModelStopper(this);
        }
        final JMenuItem stopExecuteMenuItem = new JMenuItem(modelStopper);
        runMenu.add(stopExecuteMenuItem);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_EXECUTING, HMIMessages.MENU_STOP,
                modelStopper);
    }
    if (showThing(HMIMessages.MENU_INTERACTIVE_ERRORHANDLING, menuItemsToShow, menuItemsToHide)) {
        final JMenuItem interactiveErrorCtrlMenuItem = new JCheckBoxMenuItem(
                HMIMessages.getString(HMIMessages.MENU_INTERACTIVE_ERRORHANDLING));
        interactiveErrorCtrlMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
                interactiveErrorControl = ((JCheckBoxMenuItem) e.getSource()).getState();
            }

        });
        runMenu.add(new JSeparator());
        runMenu.add(interactiveErrorCtrlMenuItem);
    }

    final JMenu graphMenu = new JMenu(HMIMessages.getString(HMIMessages.MENU_GRAPH));
    graphMenu.setMnemonic(HMIMessages.getString(HMIMessages.MENU_GRAPH + HMIMessages.KEY).charAt(0));

    // if (showThing(HMIMessages.MENU_SHOW, menuItemsToShow,
    // menuItemsToHide)) {
    // JMenuItem graphViewMenuItem = new
    // JCheckBoxMenuItem(HMIMessages.getString(HMIMessages.MENU_SHOW));
    // graphMenu.add(graphViewMenuItem);
    //
    // graphViewMenuItem.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // if (logger.isTraceEnabled()) {
    //                  logger.trace("Graph Show action - entry"); //$NON-NLS-1$
    // }
    // boolean showGraph = ((JCheckBoxMenuItem) e.getSource()).getState();
    // if(showGraph) {
    // applyFieldValuesToParameters();
    // clearModelForms();
    // showModelGraph(HMIBase.this.currentModel.getName());
    // } else {
    // clearModelGraphs();
    // showModelForm(HMIBase.this.currentModel.getName());
    // }
    // if (logger.isTraceEnabled()) {
    //                  logger.trace("Graph Show action - exit"); //$NON-NLS-1$
    // }
    // }
    //
    //
    // });
    // }
    if (showThing(HMIMessages.MENU_ANIMATE, menuItemsToShow, menuItemsToHide)) {
        final JMenuItem animateGraphViewMenuItem = new JCheckBoxMenuItem(
                HMIMessages.getString(HMIMessages.MENU_ANIMATE));
        animateGraphViewMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent e) {
                animateModelExecution = ((JCheckBoxMenuItem) e.getSource()).getState();
            }

        });
        graphMenu.add(new JSeparator());
        graphMenu.add(animateGraphViewMenuItem);
    }

    if (fileMenu.getMenuComponentCount() > 0) {
        menuBar.add(fileMenu);
    }
    if (runMenu.getMenuComponentCount() > 0) {
        menuBar.add(runMenu);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, HMIMessages.MENU_RUN,
                runMenu);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_EXECUTING, HMIMessages.MENU_RUN,
                runMenu);
    }
    if (graphMenu.getMenuComponentCount() > 0) {
        menuBar.add(graphMenu);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, HMIMessages.MENU_GRAPH,
                graphMenu);
        StateMachine.getInstance().registerActionForState(StateMachine.MODEL_EXECUTING, HMIMessages.MENU_GRAPH,
                graphMenu);
    }

    final JMenu monitoringMenu = new JMenu(HMIMessages.getString(HMIMessages.MENU_MONITORING));
    monitoringMenu.setMnemonic(HMIMessages.getString(HMIMessages.MENU_MONITORING + HMIMessages.KEY).charAt(0));
    if (showThing(HMIMessages.MENU_TRACING, menuItemsToShow, menuItemsToHide)) {
        final JMenuItem traceMenuItem = new JMenuItem(HMIMessages.getString(HMIMessages.MENU_TRACING),
                HMIMessages.getString(HMIMessages.MENU_TRACING + HMIMessages.KEY).charAt(0));
        traceMenuItem.addActionListener(new TraceDialogOpener());
        monitoringMenu.add(traceMenuItem);
    }

    if (monitoringMenu.getMenuComponentCount() > 0) {
        menuBar.add(monitoringMenu);
    }

    StateMachine.getInstance().compile();
    StateMachine.getInstance().transitionTo(StateMachine.READY);
    return menuBar;
}

From source file:es.darkhogg.hazelnutt.EditorFrame.java

private void updateRecentFiles() {
    // Clean/*from   ww w.  j  a  v  a  2 s .c  o m*/
    menuRecentFiles.removeAll();

    // Remove while recentFiles > N
    while (recentFiles.size() >= 8) {
        recentFiles.removeLast();
    }

    // Add every menu item
    if (recentFiles != null) {
        for (String str : recentFiles) {
            final JMenuItem mi = new JMenuItem(str);
            menuRecentFiles.add(mi);
            mi.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    String fileName = mi.getText();
                    actionOpenRom(fileName);
                }
            });
        }
    }
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

private JMenuBar initMenuBar() {
    JMenuBar menubar = new JMenuBar();
    {/* w  w w. ja v  a  2  s .  c  om*/
        JMenu menu = new JMenu("Synchronisation");
        {
            JMenuItem m = new JMenuItem("Kurse auswhlen");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    chooseCourses();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Automatische Synchronisation");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    showAutoSyncSettings();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Neue Dateien zeigen");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    showNewFiles();
                }
            });
            menu.add(m);
        }
        menubar.add(menu);
    }
    {
        JMenu menu = new JMenu("Einstellungen");
        {
            JMenuItem m = new JMenuItem("Speicherpfad ndern");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    changeBaseDir();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Speicherpfad ffnen");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openBaseDir();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Maximale Dateigre ndern");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    changeMaxFileSize();
                }
            });
            menu.add(m);
        }
        {
            final JCheckBoxMenuItem menuitem = new JCheckBoxMenuItem(
                    "Benachrichtigungen im Systemtray anzeigen");
            menuitem.setSelected(iliasProperties.isShowNotifications());
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    iliasProperties.setShowNotifications(!iliasProperties.isShowNotifications());
                    saveProperties(iliasProperties);
                    menuitem.setSelected(iliasProperties.isShowNotifications());
                }
            });
            menu.add(menuitem);
        }
        {
            menu.add(new JSeparator());
        }
        {
            JMenuItem m = new JMenuItem("Design ndern");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    changeLookAndFeel();
                }
            });
            menu.add(m);
        }
        {
            menu.add(new JSeparator());
        }
        {
            JMenuItem m = new JMenuItem("Server einstellen");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    chooseServer();
                }
            });
            menu.add(m);
        }
        menubar.add(menu);
    }
    {
        JMenu menu = new JMenu("Hilfe");
        {
            JMenuItem m = new JMenuItem("Fehler melden, Feedback geben");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openFeedbackPage();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Webseite");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openWebsite();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Android App");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openAndroidWebsite();
                }
            });
            menu.add(m);
        }
        {
            JMenuItem m = new JMenuItem("Info");
            m.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    showInfo();
                }
            });
            menu.add(m);
        }
        menubar.add(menu);
    }
    return menubar;
}

From source file:net.sf.jabref.openoffice.OpenOfficePanel.java

private void showSettingsPopup() {
    JPopupMenu menu = new JPopupMenu();
    final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem(
            Localization.lang("Automatically sync bibliography when inserting citations"),
            Globals.prefs.getBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING));
    final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in the active tab only"));
    final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in all open databases"));
    final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(useActiveBase);//  w w w  . j ava 2s .  c  o  m
    bg.add(useAllBases);
    if (Globals.prefs.getBoolean(JabRefPreferences.USE_ALL_OPEN_BASES)) {
        useAllBases.setSelected(true);
    } else {
        useActiveBase.setSelected(true);
    }

    autoSync.addActionListener(
            e -> Globals.prefs.putBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING, autoSync.isSelected()));

    useAllBases.addActionListener(
            e -> Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, useAllBases.isSelected()));

    useActiveBase.addActionListener(
            e -> Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, !useActiveBase.isSelected()));

    clearConnectionSettings.addActionListener(e -> {

        Globals.prefs.clear(JabRefPreferences.OO_PATH);
        Globals.prefs.clear(JabRefPreferences.OO_EXECUTABLE_PATH);
        Globals.prefs.clear(JabRefPreferences.OO_JARS_PATH);
        frame.output(Localization.lang("Cleared connection settings."));

    });

    menu.add(autoSync);
    menu.addSeparator();
    menu.add(useActiveBase);
    menu.add(useAllBases);
    menu.addSeparator();
    menu.add(clearConnectionSettings);
    menu.show(settingsB, 0, settingsB.getHeight());
}

From source file:velocitekProStartAnalyzer.MainWindow.java

private void initialize() {
    JDBCPointDao jdbcPointDao = new JDBCPointDao();
    //SQLiteDB.createNewDatabase(dbName);
    jdbcPointDao.getConnection(dbName);/*from  w  w  w  .jav a 2 s . co  m*/
    SQLiteDB.createNewTable(dbName);

    frame = new JFrame();
    frame.setBounds(1, 1, 1280, 720);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.getContentPane().setLayout(new BorderLayout(0, 0));
    setScrollTable(new JScrollPane());
    frame.getContentPane().add(copyrightLabel, BorderLayout.PAGE_END);
    btnPanel = new JPanel();
    frame.getContentPane().add(btnPanel, BorderLayout.NORTH);

    frame.addWindowStateListener(new WindowStateListener() {
        @Override
        public void windowStateChanged(WindowEvent event) {
            boolean isMaximized = isMaximized(event.getNewState());
            boolean wasMaximized = isMaximized(event.getOldState());

            if (isMaximized && !wasMaximized) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        defaultSize();
                    }
                });
            } else if (wasMaximized && !isMaximized) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        defaultSize();
                    }
                });
            }
        }
    });

    ReadXMLFile readXmlFile = new ReadXMLFile();

    btnLoadRouteData = new JButton("Reload");
    btnPanel.add(btnLoadRouteData);
    if (getFilePath() == null) {
        btnLoadRouteData.setEnabled(false);
    }
    btnLoadRouteData.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            readXmlFile.ReadXmlFile(getFilePath());
            loadDataFromDB();
        }
    });

    btnPanel.add(btnShowFileDialogButton);

    tableContainer = new JScrollPane(pointTable);
    frame.getContentPane().add(tableContainer, BorderLayout.SOUTH);
    graphMapSplitPanel = new JSplitPane();
    tableGraphMapSplitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    graphMapSplitPanel.setResizeWeight(.5d);
    frame.getContentPane().add(tableGraphMapSplitPanel, BorderLayout.CENTER);
    JPanel dataAnalysisPanel = new JPanel();
    dataAnalysisPanel.add(dataAnalysisLabel);
    JPanel tableContainerPanel = new JPanel(new BorderLayout());
    tableContainerPanel.add(dataAnalysisPanel, BorderLayout.NORTH);
    tableContainerPanel.add(tableContainer);

    tableGraphMapSplitPanel.setTopComponent(graphMapSplitPanel);
    tableGraphMapSplitPanel.setBottomComponent(tableContainerPanel);

    graphMapSplitPanel.setLeftComponent(graphPanel);
    //mapPanel.setVisible(true);
    graphMapSplitPanel.setRightComponent(mapPanel);

    btnPanel.add(statusLabel);
    statusLabel.setVisible(true);
    //frame.add(statusLabel);

    openFile();
    loadDataFromDB();

    pointTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent event) {
            if (!JDBCPointDao.points.isEmpty()) {
                getMapPanel().map().removeAllMapMarkers();
                for (int pointTableID : pointTable.getSelectedRows()) {
                    MapMarkerDot mapPoint = new MapMarkerDot(null, null,
                            (double) pointTable.getValueAt(pointTableID, 4),
                            (double) pointTable.getValueAt(pointTableID, 5));
                    if (!getMapPanel().map().getMapMarkerList().contains(mapPoint)) {
                        getMapPanel().map().addMapMarker(mapPoint);
                    }
                    // mapPanel.map().setDisplayToFitMapMarkers();
                }
                int index = 0;
                for (int pointTableID : pointTable.getSelectedRows()) {
                    index = pointTableID;
                }
                Double x = Double.valueOf(pointTable.getValueAt(index, 0).toString());
                Double y = Double.valueOf(pointTable.getValueAt(index, 3).toString());

                //int test2 = (int) pointTable.getValueAt(pointTable.getSelectedRow(), 3);

                xCrosshair.setValue(x);
                yCrosshair.setValue(y);

            }
        }

    });

    popup = new JPopupMenu();

    btnDeleteSelected = new JMenuItem("Delete Selected");
    popup.add(btnDeleteSelected);
    btnDeleteSelected.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            deleteSelected();
            loadDataFromDB();
        }
    });

    btnDeleteAllButNotSelected = new JMenuItem("Set Selected as New Database");
    popup.add(btnDeleteAllButNotSelected);
    btnDeleteAllButNotSelected.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            deleteAllButNotSelected();
            loadDataFromDB();
            setStartFinishMapMarkers();
        }
    });

    btnSetStartTime = new JMenuItem("Set Race Time");
    popup.add(btnSetStartTime);

    btnSetStartTime.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                JDBCPointDao.pointsOld.clear();
                JDBCPointDao.pointsOld.addAll(JDBCPointDao.points);
                setStartTime(showSetStartTimeDialog());
                loadDataFromDB();
                setEndTime(showSetEndTimeDialog());
                loadDataFromDB();
                setStartFinishMapMarkers();
            } catch (NullPointerException exception) {
                return;
            }

        }
    });

    btnSetStartFinishMapMarkers = new JMenuItem("Show Start Finish");
    popup.add(btnSetStartFinishMapMarkers);
    popup.addSeparator();
    btnSetStartFinishMapMarkers.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setStartFinishMapMarkers();
        }
    });

    btnMenuSaveSubmenu.add(btnSaveChartAsPng);
    btnSaveMapAsPng = new JMenuItem("Save Map as PNG");
    btnMenuSaveSubmenu.add(btnSaveMapAsPng);
    btnSaveTableAsPng = new JMenuItem("Save Table as PNG");
    btnMenuSaveSubmenu.add(btnSaveTableAsPng);
    btnMenuSaveSubmenu.add(btnSaveMapAsPng);
    btnMenuSaveSubmenu.addSeparator();
    btnMenuSaveSubmenu.add(btnSaveAsVCCForChart);
    if (JDBCPointDao.points.isEmpty()) {
        btnSaveAsVCC.setEnabled(false);
        btnSaveAsVCCForChart.setEnabled(false);
    }
    btnBackData = new JMenuItem("Back");
    popup.add(btnBackData);
    popup.addSeparator();

    if (JDBCPointDao.pointsOld.isEmpty()) {
        btnBackData.setEnabled(false);
    }

    JMenuItem btnResizeWindow = new JMenuItem("Resize Windows");
    popup.add(btnResizeWindow);
    popup.addSeparator();
    btnResizeWindow.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                defaultSize();
            } catch (NullPointerException exception) {
                return;
            }

        }
    });
    popup.add(btnMenuSaveSubmenu);
    popup.addSeparator();
    popup.add(btnAbout);

    btnAbout.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(frame,
                    "Velocitek Prostart Analyser v.1.4 - Copyright (C) 2017 Maciej Jdrzejko"
                            + "\n\nThis program is free software: you can redistribute it and/or modify"
                            + "\nit under the terms of the GNU General Public License as published by "
                            + "\nthe Free Software Foundation, either version 3 of the License, or"
                            + "\n(at your option) any later version."
                            + "\n\nThis program is distributed in the hope that it will be useful,"
                            + "\nbut WITHOUT ANY WARRANTY; without even the implied warranty of"
                            + "\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
                            + "\nGNU General Public License for more details."
                            + "\n\nYou should have received a copy of the GNU General Public License"
                            + "\nalong with this program.  If not, see http://www.gnu.org/licenses/ ");
        }
    });

    btnResetSpeedChart.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            loadDataFromDB();
        }
    });

    btnMedianSpeedChart.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int howManyTimes = selectHowManyTimes();
            for (int i = 0; i < howManyTimes; i++) {
                int iterator = 1;
                JDBCPointDao.dataSet.removeAllSeries();
                JDBCPointDao.speedTimeSeries.clear();
                for (Double medianSpeed : dataAnalysis.getMedianForChart()) {
                    JDBCPointDao.speedTimeSeries.add(iterator, medianSpeed);
                    iterator++;
                }
                JDBCPointDao.dataSet.addSeries(JDBCPointDao.speedTimeSeries);
                createChartPanel();

            }
        }
    });

    btnAvgSpeedChart.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int howManyTimes = selectHowManyTimes();
            for (int i = 0; i < howManyTimes; i++) {
                int iterator = 1;
                JDBCPointDao.dataSet.removeAllSeries();
                JDBCPointDao.speedTimeSeries.clear();
                for (Double avgSpeed : dataAnalysis.getAvgSpeedForChart()) {
                    JDBCPointDao.speedTimeSeries.add(iterator, avgSpeed);
                    iterator++;
                }
                JDBCPointDao.dataSet.addSeries(JDBCPointDao.speedTimeSeries);
                createChartPanel();
            }
        }
    });

    //Add listener to components that can bring up popup menus.

    frame.addMouseListener(popupListener);
    graphMapSplitPanel.addMouseListener(popupListener);
    tableContainer.addMouseListener(popupListener);
    pointTable.addMouseListener(popupListener);
    mapPanel.addMouseListener(popupListener);
    saveMapAsPng(mapPanel);
    saveTableAsPng(tableContainer);

    saveNewVCC();
    backData();

}

From source file:net.nikr.eve.jeveasset.gui.tabs.tracker.TrackerTab.java

public TrackerTab(Program program) {
    super(program, TabsTracker.get().title(), Images.TOOL_TRACKER.getIcon(), true);

    filterDialog = new TrackerFilterDialog(program);

    jPopupMenu = new JPopupMenu();
    jPopupMenu.addPopupMenuListener(listener);

    JMenuItem jMenuItem;
    jMenuItem = new JMenuItem(TabsTracker.get().edit(), Images.EDIT_EDIT.getIcon());
    jMenuItem.setActionCommand(TrackerAction.EDIT.name());
    jMenuItem.addActionListener(listener);
    jPopupMenu.add(jMenuItem);/*from  ww w  . ja  v  a2 s . com*/

    jMenuItem = new JMenuItem(TabsTracker.get().delete(), Images.EDIT_DELETE.getIcon());
    jMenuItem.setActionCommand(TrackerAction.DELETE.name());
    jMenuItem.addActionListener(listener);
    jPopupMenu.add(jMenuItem);

    JMenuInfo.createDefault(jPopupMenu);

    jIskValue = new JMenuItem();
    jIskValue.setEnabled(false);
    jIskValue.setForeground(Color.BLACK);
    jIskValue.setHorizontalAlignment(SwingConstants.RIGHT);
    jIskValue.setDisabledIcon(Images.TOOL_VALUES.getIcon());
    jPopupMenu.add(jIskValue);

    jDateValue = new JMenuItem();
    jDateValue.setEnabled(false);
    jDateValue.setForeground(Color.BLACK);
    jDateValue.setHorizontalAlignment(SwingConstants.RIGHT);
    jPopupMenu.add(jDateValue);

    jEditDialog = new JTrackerEditDialog(program);

    jSelectionDialog = new JSelectionDialog(program);

    JSeparator jDateSeparator = new JSeparator();

    jQuickDate = new JComboBox<QuickDate>(QuickDate.values());
    jQuickDate.setActionCommand(TrackerAction.QUICK_DATE.name());
    jQuickDate.addActionListener(listener);

    JLabel jFromLabel = new JLabel(TabsTracker.get().from());
    jFrom = createDateChooser();

    JLabel jToLabel = new JLabel(TabsTracker.get().to());
    jTo = createDateChooser();

    jAll = new JCheckBox(General.get().all());
    jAll.setSelected(true);
    jAll.setActionCommand(TrackerAction.ALL.name());
    jAll.addActionListener(listener);
    jAll.setFont(new Font(jAll.getFont().getName(), Font.ITALIC, jAll.getFont().getSize()));

    jTotal = new JCheckBox(TabsTracker.get().total());
    jTotal.setSelected(true);
    jTotal.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jTotal.addActionListener(listener);

    jWalletBalance = new JCheckBox(TabsTracker.get().walletBalance());
    jWalletBalance.setSelected(true);
    jWalletBalance.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jWalletBalance.addActionListener(listener);

    jWalletBalanceFilters = new JButton(Images.LOC_INCLUDE.getIcon());
    jWalletBalanceFilters.setActionCommand(TrackerAction.FILTER_WALLET_BALANCE.name());
    jWalletBalanceFilters.addActionListener(listener);

    jAssets = new JCheckBox(TabsTracker.get().assets());
    jAssets.setSelected(true);
    jAssets.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jAssets.addActionListener(listener);

    jAssetsFilters = new JButton(Images.LOC_INCLUDE.getIcon());
    jAssetsFilters.setActionCommand(TrackerAction.FILTER_ASSETS.name());
    jAssetsFilters.addActionListener(listener);

    jSellOrders = new JCheckBox(TabsTracker.get().sellOrders());
    jSellOrders.setSelected(true);
    jSellOrders.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jSellOrders.addActionListener(listener);

    jEscrows = new JCheckBox(TabsTracker.get().escrows());
    jEscrows.setSelected(true);
    jEscrows.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jEscrows.addActionListener(listener);

    jEscrowsToCover = new JCheckBox(TabsTracker.get().escrowsToCover());
    jEscrowsToCover.setSelected(true);
    jEscrowsToCover.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jEscrowsToCover.addActionListener(listener);

    jManufacturing = new JCheckBox(TabsTracker.get().manufacturing());
    jManufacturing.setSelected(true);
    jManufacturing.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jManufacturing.addActionListener(listener);

    jContractCollateral = new JCheckBox(TabsTracker.get().contractCollateral());
    jContractCollateral.setSelected(true);
    jContractCollateral.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jContractCollateral.addActionListener(listener);

    jContractValue = new JCheckBox(TabsTracker.get().contractValue());
    jContractValue.setSelected(true);
    jContractValue.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jContractValue.addActionListener(listener);

    JSeparator jOwnersSeparator = new JSeparator();

    jAllProfiles = new JCheckBox(TabsTracker.get().allProfiles());
    jAllProfiles.setActionCommand(TrackerAction.PROFILE.name());
    jAllProfiles.addActionListener(listener);

    jOwners = new JMultiSelectionList<String>();
    jOwners.getSelectionModel().addListSelectionListener(listener);
    JScrollPane jOwnersScroll = new JScrollPane(jOwners);

    JLabel jHelp = new JLabel(TabsTracker.get().help());
    jHelp.setIcon(Images.MISC_HELP.getIcon());

    JLabel jNoFilter = new JLabel(TabsTracker.get().helpLegacyData());
    jNoFilter.setIcon(new ShapeIcon(NO_FILTER));

    JLabel jFilter = new JLabel(TabsTracker.get().helpNewData());
    jFilter.setIcon(new ShapeIcon(FILTER_AND_DEFAULT));

    JDropDownButton jSettings = new JDropDownButton(Images.DIALOG_SETTINGS.getIcon());

    jIncludeZero = new JCheckBoxMenuItem(TabsTracker.get().includeZero());
    jIncludeZero.setSelected(true);
    jIncludeZero.setActionCommand(TrackerAction.INCLUDE_ZERO.name());
    jIncludeZero.addActionListener(listener);
    jSettings.add(jIncludeZero);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setDateFormatOverride(dateFormat);
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setAutoTickUnitSelection(true);
    domainAxis.setAutoRange(true);
    domainAxis.setTickLabelFont(jFromLabel.getFont());

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRange(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    rangeAxis.setTickLabelFont(jFromLabel.getFont());

    //XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, new XYLineAndShapeRenderer(true, true));
    render = new MyRender();
    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, render);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.getRenderer()
            .setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: {2} ({1})", dateFormat, iskFormat));
    plot.setDomainCrosshairLockedOnData(true);
    plot.setDomainCrosshairStroke(new BasicStroke(1));
    plot.setDomainCrosshairPaint(Color.BLACK);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(false);

    jNextChart = new JFreeChart(plot);
    jNextChart.setAntiAlias(true);
    jNextChart.setBackgroundPaint(jPanel.getBackground());
    jNextChart.addProgressListener(null);
    jNextChart.getLegend().setItemFont(jFrom.getFont());

    jChartPanel = new ChartPanel(jNextChart);
    jChartPanel.addMouseListener(listener);
    jChartPanel.setDomainZoomable(false);
    jChartPanel.setRangeZoomable(false);
    jChartPanel.setPopupMenu(null);
    jChartPanel.addChartMouseListener(listener);
    jChartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    jChartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    jChartPanel.setMinimumDrawWidth(10);
    jChartPanel.setMinimumDrawHeight(10);

    int AssetsGapWidth = PANEL_WIDTH - jAssets.getPreferredSize().width
            - jAssetsFilters.getPreferredSize().width;
    if (AssetsGapWidth < 0) {
        AssetsGapWidth = 0;
    }
    int WalletGapWidth = PANEL_WIDTH - jWalletBalance.getPreferredSize().width
            - jWalletBalanceFilters.getPreferredSize().width;
    if (WalletGapWidth < 0) {
        WalletGapWidth = 0;
    }

    layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup()
            .addGroup(layout.createSequentialGroup().addComponent(jHelp).addGap(20).addComponent(jNoFilter)
                    .addGap(20).addComponent(jFilter).addGap(20, 20, Integer.MAX_VALUE).addComponent(jSettings)
                    .addGap(6))
            .addComponent(jChartPanel)).addGroup(
                    layout.createParallelGroup().addComponent(jQuickDate, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup()
                                            .addComponent(jFromLabel, LABEL_WIDTH, LABEL_WIDTH, LABEL_WIDTH)
                                            .addComponent(jToLabel, LABEL_WIDTH, LABEL_WIDTH, LABEL_WIDTH))
                                    .addGap(0)
                                    .addGroup(layout.createParallelGroup()
                                            .addComponent(jFrom, PANEL_WIDTH - LABEL_WIDTH,
                                                    PANEL_WIDTH - LABEL_WIDTH, PANEL_WIDTH - LABEL_WIDTH)
                                            .addComponent(jTo, PANEL_WIDTH - LABEL_WIDTH,
                                                    PANEL_WIDTH - LABEL_WIDTH, PANEL_WIDTH - LABEL_WIDTH)))
                            .addComponent(jDateSeparator, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jAll, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jTotal, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addGroup(layout.createSequentialGroup().addComponent(jWalletBalance)
                                    .addGap(0, 0, WalletGapWidth).addComponent(jWalletBalanceFilters))
                            .addGroup(layout.createSequentialGroup().addComponent(jAssets)
                                    .addGap(0, 0, AssetsGapWidth).addComponent(jAssetsFilters))
                            .addComponent(jSellOrders, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jEscrows, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jEscrowsToCover, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jManufacturing, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jContractCollateral, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jContractValue, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jOwnersSeparator, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jAllProfiles, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jOwnersScroll, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)));
    layout.setVerticalGroup(layout.createParallelGroup()
            .addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup()
                    .addComponent(jHelp, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jNoFilter, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jFilter, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jSettings, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight()))
                    .addComponent(jChartPanel))
            .addGroup(layout.createSequentialGroup()
                    .addComponent(jQuickDate, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addGroup(layout.createParallelGroup()
                            .addComponent(jFromLabel, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight())
                            .addComponent(jFrom, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight()))
                    .addGroup(layout.createParallelGroup()
                            .addComponent(jToLabel, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight())
                            .addComponent(jTo, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight()))
                    .addComponent(jDateSeparator, 3, 3, 3)
                    .addComponent(jAll, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jTotal, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addGroup(layout.createParallelGroup()
                            .addComponent(jWalletBalance, Program.getButtonsHeight(),
                                    Program.getButtonsHeight(), Program.getButtonsHeight())
                            .addComponent(jWalletBalanceFilters, Program.getButtonsHeight(),
                                    Program.getButtonsHeight(), Program.getButtonsHeight()))
                    .addGroup(layout.createParallelGroup()
                            .addComponent(jAssets, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight())
                            .addComponent(jAssetsFilters, Program.getButtonsHeight(),
                                    Program.getButtonsHeight(), Program.getButtonsHeight()))
                    .addComponent(jSellOrders, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jEscrows, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jEscrowsToCover, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jManufacturing, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jContractCollateral, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jContractValue, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jOwnersSeparator, 3, 3, 3)
                    .addComponent(jAllProfiles, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jOwnersScroll, 70, 70, Integer.MAX_VALUE)));
}

From source file:gda.gui.mca.McaGUI.java

private SimplePlot getSimplePlot() {
    if (simplePlot == null) {
        simplePlot = new SimplePlot();
        simplePlot.setYAxisLabel("Values");
        simplePlot.setTitle("MCA");
        /*/*w  ww. j  av  a 2s .  co  m*/
         * do not attempt to get calibration until the analyser is available getEnergyCalibration();
         */

        simplePlot.setXAxisLabel("Channel Number");

        simplePlot.setTrackPointer(true);
        JPopupMenu menu = simplePlot.getPopupMenu();
        JMenuItem item = new JMenuItem("Add Region Of Interest");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "To add a region of interest, please click on region low"
                        + " and region high channels\n" + "in the graph and set the index\n");
                regionClickCount = 0;
            }
        });

        JMenuItem calibitem = new JMenuItem("Calibrate Energy");
        /*
         * Comment out as calibration is to come from the analyser directly menu.add(calibitem);
         */
        calibitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    // regionClickCount = 0;
                    int[] data = (int[]) analyser.getData();
                    double[] dData = new double[data.length];
                    for (int i = 0; i < dData.length; i++) {
                        dData[i] = data[i];
                    }
                    if (energyCalibrationDialog == null) {
                        energyCalibrationDialog = new McaCalibrationPanel(
                                (EpicsMCARegionOfInterest[]) analyser.getRegionsOfInterest(), dData, mcaName);
                        energyCalibrationDialog.addIObserver(McaGUI.this);
                    }
                    energyCalibrationDialog.setVisible(true);
                } catch (DeviceException e1) {
                    logger.error("Exception: " + e1.getMessage());
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage());
                    ex.printStackTrace();
                }
            }

        });

        simplePlot.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent me) {
                // /////////System.out.println("Mouse clicked " +
                // me.getX() + " "
                // /////// + me.getY());
                SimpleDataCoordinate coordinates = simplePlot.convertMouseEvent(me);
                if (simplePlot.getScreenDataArea().contains(me.getX(), me.getY()) && regionClickCount == 0) {
                    regionLow = coordinates.toArray();
                    regionClickCount++;
                } else if (simplePlot.getScreenDataArea().contains(me.getX(), me.getY())
                        && regionClickCount == 1) {
                    regionHigh = coordinates.toArray();
                    regionClickCount++;

                    if (regionValid(regionLow[0], regionHigh[0])) {

                        final String s = (String) JOptionPane.showInputDialog(null,
                                "Please select the Region Index:\n", "Region Of Interest",
                                JOptionPane.PLAIN_MESSAGE, null, null, String.valueOf(getNextRegion()));
                        Thread t1 = uk.ac.gda.util.ThreadManager.getThread(new Runnable() {
                            @Override
                            public void run() {

                                try {

                                    if (s != null) {
                                        int rIndex = Integer.parseInt(s);
                                        EpicsMCARegionOfInterest[] epc = { new EpicsMCARegionOfInterest() };
                                        epc[0].setRegionLow(regionLow[0]);
                                        epc[0].setRegionHigh(regionHigh[0]);
                                        epc[0].setRegionIndex(rIndex);
                                        epc[0].setRegionName("region " + rIndex);
                                        analyser.setRegionsOfInterest(epc);

                                        addRegionMarkers(rIndex, regionLow[0], regionHigh[0]);
                                    }

                                } catch (DeviceException e) {
                                    logger.error("Unable to set the table values");
                                }

                            }

                        });
                        t1.start();
                    }
                }
            }

        });

        // TODO note that selectePlot cannot be changed runtime
        simplePlot.initializeLine(selectedPlot);
        simplePlot.setLineName(selectedPlot, getSelectedPlotString());
        simplePlot.setLineColor(selectedPlot, getSelectedPlotColor());
        simplePlot.setLineType(selectedPlot, "LineOnly");

    }
    return simplePlot;
}