package gafetes; import gafetes.util.Misc; import java.awt.event.*; import java.awt.*; import javax.swing.event.*; import javax.swing.*; import java.sql.*; public class SelectEmpresa extends javax.swing.JDialog { public void configureListeners() { MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { //int index = lista.locationToIndex(e.getPoint()); nextstep(); } } }; lista.addMouseListener(mouseListener); InputMap im = lista.getInputMap(JComponent.WHEN_FOCUSED); im.put(KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), "actionName"); ActionMap am = lista.getActionMap(); am.put("actionName", new AbstractAction("actionName") { public void actionPerformed(ActionEvent evt) { nextstep(); } } ); lista.setInputMap(JComponent.WHEN_FOCUSED, im); lista.setActionMap(am); okButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed( java.awt.event.ActionEvent event ) { nextstep(); } }); cancelButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed( java.awt.event.ActionEvent event ) { closeDialog(); } }); } private void nextstep() { if(lista.getSelectedIndex() < 0){ javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(), "Seleccione un elemento de la lista", "Aviso", javax.swing.JOptionPane.INFORMATION_MESSAGE); return; } gafetes.beans.Template temp = (gafetes.beans.Template)lista.getModel().getElementAt(lista.getSelectedIndex()); template.setId(temp.getId()) ; template.setNombre(temp.getNombre()) ; template.setRuta(temp.getRuta()) ; System.out.println("El template que selecciono es el sig." + template.getId()+ " Nombre:"+ template.getNombre() + " Direccion:"+template.getRuta()); dispose(); // BuscarDialog bd = new BuscarDialog( Application.getparentFrame(), true,lista.getSelectedIndex(), articulo, 0); // Misc.centerFrame(bd); // bd.show(); } private void closeDialog( ) { dispose(); } public SelectEmpresa(java.awt.Frame parent, boolean modal, gafetes.beans.Template template) { super(parent, modal); this.template = template; owner = this; initComponents(); configureListeners(); DefaultListModel v = (DefaultListModel)gafetes.business.SqlHelper.getListaTemplates(); lista.setModel(v); Misc.centerFrame( owner ); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents setTitle("SELECCIONE LA EMPRESA"); codigoField = new javax.swing.JTextField(); mainPanel = new javax.swing.JPanel(); northPanel = new javax.swing.JPanel(); eastPanel = new javax.swing.JPanel(); westPanel = new javax.swing.JPanel(); southPanel = new javax.swing.JPanel(); okButton = new javax.swing.JButton(); okiButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); centerPanel = new javax.swing.JPanel(); optionScrollPane = new javax.swing.JScrollPane(); // scrollPane = new javax.swing.JScrollPane(); lista = new javax.swing.JList(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); mainPanel.setLayout(new java.awt.BorderLayout()); mainPanel.add(northPanel, java.awt.BorderLayout.NORTH); mainPanel.add(eastPanel, java.awt.BorderLayout.EAST); mainPanel.add(westPanel, java.awt.BorderLayout.WEST); okButton.setText("Aceptar"); southPanel.add(okButton); cancelButton.setText("Cancelar"); southPanel.add(cancelButton); mainPanel.add(southPanel, java.awt.BorderLayout.SOUTH); centerPanel.setLayout(new java.awt.BorderLayout()); centerPanel.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED)); centerPanel.setPreferredSize(new java.awt.Dimension(300, 150)); lista.setModel(new javax.swing.AbstractListModel() { String[] strings = { "ANDREA", "IMPULS", "TERRA" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); lista.setSelectedIndex(0); optionScrollPane.setViewportView(lista); centerPanel.add(optionScrollPane, java.awt.BorderLayout.CENTER); mainPanel.add(centerPanel, java.awt.BorderLayout.CENTER); getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); pack(); }//GEN-END:initComponents public static void main(String args[]) { new SelectEmpresa(new javax.swing.JFrame(), true, new gafetes.beans.Template()).setVisible(true); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; private javax.swing.JPanel centerPanel; private javax.swing.JPanel eastPanel; private javax.swing.JPanel mainPanel; private javax.swing.JScrollPane optionScrollPane; private javax.swing.JList lista; // private javax.swing.JScrollPane scrollPane1; // private javax.swing.JList lista; private javax.swing.JTextField codigoField; private javax.swing.JPanel northPanel; private javax.swing.JButton okButton; private javax.swing.JButton okiButton; private javax.swing.JPanel southPanel; private javax.swing.JPanel westPanel; // End of variables declaration//GEN-END:variables //DBMySQL db = new DBMySQL(); private javax.swing.JDialog owner; private gafetes.beans.Template template; }