List of usage examples for javax.swing JDialog setVisible
public void setVisible(boolean b)
From source file:interfaces.InterfazPrincipal.java
private void botonAgregarProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarProductoActionPerformed String nombre = jTextField_Factura_Producto_Nombre.getText(); String descripcion = jTextField_Factura_Producto_Descripcion.getText(); ControladorProducto controladorPro = new ControladorProducto(); String restriccion = ""; boolean encounter = true; if (!nombre.equals("")) { if (encounter) { encounter = false;/*from w ww . j av a 2 s .co m*/ restriccion = " where "; } else { restriccion += " OR "; } restriccion += " nombre like '%" + nombre + "%'"; } if (!descripcion.equals("")) { if (encounter) { encounter = false; restriccion = " where "; } else { restriccion += " OR "; } restriccion += " descripcion like '%" + descripcion + "%'"; } ArrayList<Productos> listaDeProductos = controladorPro.getProducto(restriccion); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(600, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Buscar Producto"); c.gridx = 0; c.gridy = 0; c.gridwidth = 6; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); final JTable table = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Numero"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); modeloTabla.addColumn("Descripcion"); modeloTabla.addColumn("Unidades Disponibles"); modeloTabla.addColumn("Precio"); //LLenar tabla for (int i = 0; i < listaDeProductos.size(); i++) { Object[] data = { "1", "2", "3", "4", "5", "6" }; data[0] = (i + 1); data[1] = listaDeProductos.get(i).getProductoId(); data[2] = listaDeProductos.get(i).getNombre(); data[3] = listaDeProductos.get(i).getDescripcion(); data[4] = listaDeProductos.get(i).getUnidadesDisponibles(); data[5] = listaDeProductos.get(i).getPrecio(); modeloTabla.addRow(data); } table.setModel(modeloTabla); table.getColumn("Numero").setMinWidth(50); table.getColumn("Identificacin").setMinWidth(50); table.getColumn("Nombre").setMinWidth(110); table.getColumn("Descripcion").setMinWidth(110); table.getColumn("Unidades Disponibles").setMinWidth(40); table.getColumn("Precio").setMinWidth(110); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(320, 150)); //final JTable table = new JTable(row, col); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { //jTextField_Factura_Cliente_Id.setText(table.getValueAt(table.getSelectedRow(), 1).toString()); //System.out.println(table.getValueAt(table.getSelectedRow(), 3).toString()); DefaultTableModel modelo = (DefaultTableModel) TablaDeFacturaProducto.getModel(); Object[] fila = new Object[7]; fila[0] = table.getValueAt(table.getSelectedRow(), 0).toString(); fila[1] = table.getValueAt(table.getSelectedRow(), 1).toString(); fila[2] = table.getValueAt(table.getSelectedRow(), 2).toString(); fila[3] = table.getValueAt(table.getSelectedRow(), 3).toString(); //fila[4] = table.getValueAt(table.getSelectedRow(), 4).toString(); fila[4] = (String) JOptionPane.showInputDialog("Ingrese el nmero de unidades que va a vender"); fila[5] = table.getValueAt(table.getSelectedRow(), 5).toString(); Double valorProducto = Double.parseDouble((String) fila[5]); String valorActualProducto = String.valueOf(Double.parseDouble(valorActualFactura.getText()) + Double.parseDouble((String) fila[4]) * valorProducto); valorActualFactura.setText(valorActualProducto); fila[6] = Double.parseDouble((String) fila[4]) * valorProducto; modelo.addRow(fila); //modelo.getColumnName(4). /*TablaDeFacturaProducto.setModel(modelo); TablaDeFacturaProducto.getColumnClass(4). ;*/ dialogoEditar.dispose(); } }); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 200; panelDialogo.add(scroll, c); //panelDialogo.add(table, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void tablaUsuariosDelSistemaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaUsuariosDelSistemaMouseClicked // TODO add your handling code here: String opcionHabilitar = "Habilitar"; String nombreUsuario = String .valueOf(tablaUsuariosDelSistema.getValueAt(tablaUsuariosDelSistema.getSelectedRow(), 0)); String estado = String .valueOf(tablaUsuariosDelSistema.getValueAt(tablaUsuariosDelSistema.getSelectedRow(), 2)); if (estado.equals("Habilitado")) { opcionHabilitar = "Deshabilitar"; }/*ww w . j a va2 s. c o m*/ Object[] opciones = { "Cancelar", "Editar", opcionHabilitar }; final ControladorUsuarios controladorUsuarios = new ControladorUsuarios(); final Usuarios usuarioSelecionado = controladorUsuarios.obtenerUsuario(nombreUsuario); if (nombreUsuario.equals("admin") || nombreUsuario.equals(JTextFieldnombreDeUsuario.getText())) { JOptionPane.showMessageDialog(this, "No se puede editarse a si mismo o el usuario administrador del sistema", "Mensaje del sistema", JOptionPane.WARNING_MESSAGE); } else { int opcionElegida = JOptionPane.showOptionDialog(this, "Por favor elija una opcin", "Editar cliente", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones, null); switch (opcionElegida) { case 1: final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar usuario"); dialogoEditar.setSize(400, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar clientes"); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.insets = new Insets(15, 10, 40, 0); c.ipadx = 0; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 0; JLabel editarNombreClienteDialogo = new JLabel("Login:"); panelDialogo.add(editarNombreClienteDialogo, c); final JTextField valorEditarNombreClienteDialogo = new JTextField(); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); valorEditarNombreClienteDialogo.setText(usuarioSelecionado.getLogin()); panelDialogo.add(valorEditarNombreClienteDialogo, c); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); JLabel editarPasswordClienteDialogo = new JLabel("Contrasea:"); panelDialogo.add(editarPasswordClienteDialogo, c); final JTextField valoreditarPasswordClienteDialogo = new JTextField(); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); panelDialogo.add(valoreditarPasswordClienteDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.ipadx = 0; c.insets = new Insets(0, 5, 10, 0); JLabel mensajeEditarPassword = new JLabel( "Si no desea editar la contrasea deje este espacio en blanco:"); panelDialogo.add(mensajeEditarPassword, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 1; c.ipadx = 0; c.insets = new Insets(0, 15, 10, 15); JButton botonGuardarClienteDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 1; c.gridy = 4; c.gridwidth = 1; c.insets = new Insets(0, 15, 10, 15); c.ipadx = 0; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String nombreUsuario = valorEditarNombreClienteDialogo.getText(); usuarioSelecionado.setLogin(nombreUsuario); if (!valoreditarPasswordClienteDialogo.getText().equals("")) { usuarioSelecionado.setPassword(valoreditarPasswordClienteDialogo.getText()); } controladorUsuarios.modificarUsuario(usuarioSelecionado.getUser_id(), usuarioSelecionado.getLogin(), usuarioSelecionado.getPassword()); JOptionPane.showMessageDialog(dialogoEditar, "Se ha modificado el usuario con xito", "Mensaje del sistema", JOptionPane.INFORMATION_MESSAGE); generarTablaUsuarios(); dialogoEditar.dispose(); } }); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); break; case 2: if (estado.equals("Habilitado")) { usuarioSelecionado.setStatus('i'); } else { usuarioSelecionado.setStatus('e'); } controladorUsuarios.modificarEstadoUsuario(usuarioSelecionado); JOptionPane.showMessageDialog(this, "Se ha cambiado el estado del usuario", "Mensaje del sistema", JOptionPane.INFORMATION_MESSAGE); generarTablaUsuarios(); break; default: break; } } // TODO add your handling code here: }
From source file:com.tascape.qa.th.android.driver.App.java
/** * The method starts a GUI to let an user inspect element tree and take screenshot when the user is interacting * with the app-under-test manually. Please make sure to set timeout long enough for manual interaction. * * @param timeoutMinutes timeout in minutes to fail the manual steps * * @throws Exception if case of error// www . j ava 2 s . c om */ public void interactManually(int timeoutMinutes) throws Exception { LOG.info("Start manual UI interaction"); long end = System.currentTimeMillis() + timeoutMinutes * 60000L; AtomicBoolean visible = new AtomicBoolean(true); AtomicBoolean pass = new AtomicBoolean(false); String tName = Thread.currentThread().getName() + "m"; SwingUtilities.invokeLater(() -> { JDialog jd = new JDialog((JFrame) null, "Manual Device UI Interaction - " + device.getProductDetail()); jd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); JPanel jpContent = new JPanel(new BorderLayout()); jd.setContentPane(jpContent); jpContent.setPreferredSize(new Dimension(1088, 828)); jpContent.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel jpInfo = new JPanel(); jpContent.add(jpInfo, BorderLayout.PAGE_START); jpInfo.setLayout(new BorderLayout()); { JButton jb = new JButton("PASS"); jb.setForeground(Color.green.darker()); jb.setFont(jb.getFont().deriveFont(Font.BOLD)); jpInfo.add(jb, BorderLayout.LINE_START); jb.addActionListener(event -> { pass.set(true); jd.dispose(); visible.set(false); }); } { JButton jb = new JButton("FAIL"); jb.setForeground(Color.red); jb.setFont(jb.getFont().deriveFont(Font.BOLD)); jpInfo.add(jb, BorderLayout.LINE_END); jb.addActionListener(event -> { pass.set(false); jd.dispose(); visible.set(false); }); } JLabel jlTimeout = new JLabel("xxx seconds left", SwingConstants.CENTER); jpInfo.add(jlTimeout, BorderLayout.CENTER); jpInfo.add(jlTimeout, BorderLayout.CENTER); new SwingWorker<Long, Long>() { @Override protected Long doInBackground() throws Exception { while (System.currentTimeMillis() < end) { Thread.sleep(1000); long left = (end - System.currentTimeMillis()) / 1000; this.publish(left); } return 0L; } @Override protected void process(List<Long> chunks) { Long l = chunks.get(chunks.size() - 1); jlTimeout.setText(l + " seconds left"); if (l < 850) { jlTimeout.setForeground(Color.red); } } }.execute(); JPanel jpResponse = new JPanel(new BorderLayout()); JPanel jpProgress = new JPanel(new BorderLayout()); jpResponse.add(jpProgress, BorderLayout.PAGE_START); JTextArea jtaJson = new JTextArea(); jtaJson.setEditable(false); jtaJson.setTabSize(4); Font font = jtaJson.getFont(); jtaJson.setFont(new Font("Courier New", font.getStyle(), font.getSize())); JTree jtView = new JTree(); JTabbedPane jtp = new JTabbedPane(); jtp.add("tree", new JScrollPane(jtView)); jtp.add("json", new JScrollPane(jtaJson)); jpResponse.add(jtp, BorderLayout.CENTER); JPanel jpScreen = new JPanel(); jpScreen.setMinimumSize(new Dimension(200, 200)); jpScreen.setLayout(new BoxLayout(jpScreen, BoxLayout.PAGE_AXIS)); JScrollPane jsp1 = new JScrollPane(jpScreen); jpResponse.add(jsp1, BorderLayout.LINE_START); JPanel jpJs = new JPanel(new BorderLayout()); JTextArea jtaJs = new JTextArea(); jpJs.add(new JScrollPane(jtaJs), BorderLayout.CENTER); JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jpResponse, jpJs); jSplitPane.setResizeWeight(0.88); jpContent.add(jSplitPane, BorderLayout.CENTER); JPanel jpLog = new JPanel(); jpLog.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); jpLog.setLayout(new BoxLayout(jpLog, BoxLayout.LINE_AXIS)); JCheckBox jcbTap = new JCheckBox("Enable Click", null, false); jpLog.add(jcbTap); jpLog.add(Box.createHorizontalStrut(8)); JButton jbLogUi = new JButton("Log Screen"); jpResponse.add(jpLog, BorderLayout.PAGE_END); { jpLog.add(jbLogUi); jbLogUi.addActionListener((ActionEvent event) -> { jtaJson.setText("waiting for screenshot..."); Thread t = new Thread(tName) { @Override public void run() { LOG.debug("\n\n"); try { WindowHierarchy wh = device.loadWindowHierarchy(); jtView.setModel(getModel(wh)); jtaJson.setText(""); jtaJson.append(wh.root.toJson().toString(2)); jtaJson.append("\n"); File png = device.takeDeviceScreenshot(); BufferedImage image = ImageIO.read(png); int w = device.getDisplayWidth(); int h = device.getDisplayHeight(); BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = resizedImg.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(image, 0, 0, w, h, null); g2.dispose(); JLabel jLabel = new JLabel(new ImageIcon(resizedImg)); jpScreen.removeAll(); jsp1.setPreferredSize(new Dimension(w + 30, h)); jpScreen.add(jLabel); jLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { LOG.debug("clicked at {},{}", e.getPoint().getX(), e.getPoint().getY()); if (jcbTap.isSelected()) { device.click(e.getPoint().x, e.getPoint().y); device.waitForIdle(); jbLogUi.doClick(); } } }); } catch (Exception ex) { LOG.error("Cannot log screen", ex); jtaJson.append("Cannot log screen"); } jtaJson.append("\n\n\n"); LOG.debug("\n\n"); jd.setSize(jd.getBounds().width + 1, jd.getBounds().height + 1); jd.setSize(jd.getBounds().width - 1, jd.getBounds().height - 1); } }; t.start(); }); } jpLog.add(Box.createHorizontalStrut(38)); { JButton jbLogMsg = new JButton("Log Message"); jpLog.add(jbLogMsg); JTextField jtMsg = new JTextField(10); jpLog.add(jtMsg); jtMsg.addFocusListener(new FocusListener() { @Override public void focusLost(final FocusEvent pE) { } @Override public void focusGained(final FocusEvent pE) { jtMsg.selectAll(); } }); jtMsg.addKeyListener(new KeyAdapter() { @Override public void keyPressed(java.awt.event.KeyEvent e) { if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) { jbLogMsg.doClick(); } } }); jbLogMsg.addActionListener(event -> { Thread t = new Thread(tName) { @Override public void run() { String msg = jtMsg.getText(); if (StringUtils.isNotBlank(msg)) { LOG.info("{}", msg); jtMsg.selectAll(); } } }; t.start(); try { t.join(); } catch (InterruptedException ex) { LOG.error("Cannot take screenshot", ex); } jtMsg.requestFocus(); }); } jpLog.add(Box.createHorizontalStrut(38)); { JButton jbClear = new JButton("Clear"); jpLog.add(jbClear); jbClear.addActionListener(event -> { jtaJson.setText(""); }); } JPanel jpAction = new JPanel(); jpContent.add(jpAction, BorderLayout.PAGE_END); jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS)); jpJs.add(jpAction, BorderLayout.PAGE_END); jd.pack(); jd.setVisible(true); jd.setLocationRelativeTo(null); jbLogUi.doClick(); }); while (visible.get()) { if (System.currentTimeMillis() > end) { LOG.error("Manual UI interaction timeout"); break; } Thread.sleep(500); } if (pass.get()) { LOG.info("Manual UI Interaction returns PASS"); } else { Assert.fail("Manual UI Interaction returns FAIL"); } }
From source file:atlas.kingj.roi.FrmMain.java
private void OpenAll() { ResetStatusLabel();/*from w w w.j av a2s . c o m*/ formReady = false; jobFormReady = false; fc = new OpenSaveFileChooser(); fc.setFileFilter(new OBJfilter(3)); fc.type = 1; JOptionPane pane = new JOptionPane( "Opening a previous configuration will erase all current settings.\nAre you sure you want to proceed?"); Object[] options = new String[] { "Yes", "No" }; pane.setOptions(options); JDialog dialog = pane.createDialog(new JFrame(), "Confirm"); dialog.setVisible(true); Object obj = pane.getValue(); if (obj != null && obj.equals(options[0])) { int returnVal = fc.showOpenDialog(frmTitanRoiCalculator); if (returnVal == JFileChooser.APPROVE_OPTION) { SaveFile save; File file = fc.getSelectedFile(); try { FileInputStream fin = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fin); save = (SaveFile) ois.readObject(); ois.close(); // Don't want to change the save settings in any way boolean temp1 = environment.SaveOnClose; String temp2 = environment.SaveFileName; environment = save.getEnvironment(); environment.SaveOnClose = temp1; environment.SaveFileName = temp2; listModel = (DefaultListModel) save.getMachineList(); RoiData.setSize(listModel.getSize()); listMachines.setModel(listModel); jobModel = (DefaultListModel) save.getJobList(); listJobs.setModel(jobModel); listJobsAvail.setModel(jobModel); listCompare.setModel(listModel); listCompareRoi.setModel(listModel); listCompare.setSelectedIndices(save.getSelection()); machNames = save.getMachNames(); jobNames = save.getJobNames(); RoiData = (ROIData) save.getRoiData().clone(); if (metric != environment.getUnits()) { ChangeUnits(); rdbtnmntmImperial.setSelected(true); } chckbxSimulateScheduleStart.setSelected(!environment.StartStopTimes); scheduleModel.clear(); environment.Unlocked = false; if (environment.getSchedule() == null) environment.setSchedule(new JobSchedule()); else { int size = environment.getSchedule().getSize(); for (int i = 0; i < size; ++i) { scheduleModel.addElement(environment.getSchedule().getJob(i)); } btnRemoveJob.setEnabled(true); btnUpSchedule.setEnabled(true); btnViewSchedule.setEnabled(true); btnClearSchedule.setEnabled(true); if (size > 0) listSchedule.setSelectedIndex(0); } formReady = false; UpdateForm(); if (listModel.size() > 0) { listMachines.setSelectedIndex(0); formReady = true; } if (jobModel.size() > 0) { listJobs.setSelectedIndex(0); jobFormReady = true; } UpdateJobForm(); // Update environment initialising = true; chckbxSimulateScheduleStart.setSelected(!environment.StartStopTimes); txtShiftLength.setText(Double.toString(roundTwoDecimals(environment.HrsPerShift))); txtShiftCount.setText( Double.toString(roundTwoDecimals(environment.HrsPerDay / environment.HrsPerShift))); txtDaysYear.setText( Double.toString(roundTwoDecimals(environment.HrsPerYear / environment.HrsPerDay))); initialising = false; UpdateShifts(); // Update ROI form txtsellingprice.setText(Double.toString(roundTwoDecimals( (metric ? save.RoiData.sellingprice : Core.TonToTonne(save.RoiData.sellingprice))))); txtcontribution.setText(Double.toString(roundTwoDecimals(save.RoiData.contribution * 100))); lblvalueadded.setText( "" + formatDecimal((metric ? save.RoiData.value : Core.TonToTonne(save.RoiData.value))) + (metric ? " / tonne" : " / ton")); txtenergycost.setText(Double.toString(roundTwoDecimals(save.RoiData.energycost))); txtwastesavedflags.setText(Double.toString(roundTwoDecimals( (metric ? save.RoiData.wastesavedflag : Core.MToFt(save.RoiData.wastesavedflag))))); txtwastesavedguide.setText(Double.toString(roundTwoDecimals( (metric ? save.RoiData.wastesavedguide : Core.MToFt(save.RoiData.wastesavedguide))))); UpdateAnalysis(); UpdateROI(); ShowMessageSuccess("File loaded successfully."); } catch (ClassCastException e1) { ShowMessage("Save-all file required, not found."); } catch (ClassNotFoundException e1) { ShowMessage("File load error."); } catch (FileNotFoundException e1) { ShowMessage("File not found."); } catch (Exception e1) { ShowMessage("File load error."); } finally { if (!(listModel.getSize() == 0)) formReady = true; if (!(jobModel.getSize() == 0)) jobFormReady = true; } } } }
From source file:interfaces.InterfazPrincipal.java
private void botonBuscarClienteCrearFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonBuscarClienteCrearFacturaActionPerformed String nombre = nombreClienteCrearFactura.getText(); String identificacion = IdentificacionClienteBuscarFactura.getText(); ControladorCliente controladorCliente = new ControladorCliente(); try {/* www. j a va2 s .co m*/ int id = 0; if (!identificacion.equals("")) { id = Integer.parseInt(identificacion); } ArrayList<Cliente> listaClientes = controladorCliente.obtenerClientes(nombre, id); if (listaClientes.isEmpty()) { mensajesBusquedaClientesFactura.setText("La busqueda no arrojo resultados"); return; } final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Buscar clientes"); dialogoEditar.setSize(600, 310); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Buscar Cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); /*Vector col = new Vector(); col.add("1"); col.add("2"); col.add("3"); col.add("4"); Vector row = new Vector(); for (int i = 0; i < listaClientes.size(); i++) { Cliente cliente = listaClientes.get(i); Vector temp = new Vector(); temp.add((i + 1) + ""); temp.add(cliente.getNombre()); temp.add(cliente.getCliente_id() + ""); temp.add(cliente.getMonto_prestamo() + ""); System.out.println("info" + cliente.getNombre() + "," + cliente.getMonto_prestamo()); row.add(temp); } final JTable table = new JTable(row, col); */ final JTable table = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Numero"); modeloTabla.addColumn("Identificacin"); modeloTabla.addColumn("Nombre"); modeloTabla.addColumn("Monto Prestamo"); //LLenar tabla for (int i = 0; i < listaClientes.size(); i++) { Object[] data = { "1", "2", "3", "4" }; data[0] = (i + 1); data[1] = listaClientes.get(i).getCliente_id(); data[2] = listaClientes.get(i).getNombre(); data[3] = listaClientes.get(i).getMonto_prestamo(); modeloTabla.addRow(data); } table.setModel(modeloTabla); table.getColumn("Numero").setMinWidth(50); table.getColumn("Identificacin").setMinWidth(50); table.getColumn("Nombre").setMinWidth(110); table.getColumn("Monto Prestamo").setMinWidth(110); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(320, 150)); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { jTextField_Factura_Cliente_Id.setText(table.getValueAt(table.getSelectedRow(), 1).toString()); String identificacion = table.getValueAt(table.getSelectedRow(), 3).toString(); ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); //SELECT * FROM Flujo_Factura where factura_id in (select factura_id from Factura where cliente_id = 1130614506); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(identificacion) + " and estado=\"fiado\") order by factura_id"); double pago = 0.0; for (int i = 0; i < flujosCliente.size(); i++) { String[] datos = flujosCliente.get(i); Object[] rowData = { datos[1], datos[2], datos[3], datos[4] }; if (datos[2].equals("deuda")) { pago += Double.parseDouble(datos[4]); } else { pago -= Double.parseDouble(datos[4]); } } nombreClienteCrearFactura.setText(table.getValueAt(table.getSelectedRow(), 2).toString()); IdentificacionClienteBuscarFactura .setText(table.getValueAt(table.getSelectedRow(), 1).toString()); double montoPrestamo = Double .parseDouble(table.getValueAt(table.getSelectedRow(), 3).toString()); Double totalDisponible = montoPrestamo - pago; valorActualPrestamo.setText(String.valueOf(totalDisponible)); //System.out.println(table.getValueAt(table.getSelectedRow(), 3).toString()); botonAgregarProducto.setEnabled(true); botonGuardarFactura.setEnabled(true); botonEstablecerMontoFactura.setEnabled(true); dialogoEditar.dispose(); } }); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 200; //panelDialogo.add(table, c); panelDialogo.add(scroll, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); } catch (Exception e) { mensajesBusquedaClientesFactura.setText("La identificacion debe ser un numero"); } }
From source file:interfaces.InterfazPrincipal.java
private void TablaDeProductosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeProductosMouseClicked // TODO add your handling code here: int fila = TablaDeProductos.getSelectedRow(); final int identificacion = (int) TablaDeProductos.getValueAt(fila, 1); final ControladorProducto controladorP = new ControladorProducto(); ArrayList<Productos> listaProductos = controladorP.getProducto(" where producto_id = " + identificacion); final Productos productoActual = listaProductos.get(0); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar clientes"); dialogoEditar.setSize(600, 310);/*w w w . jav a 2 s . com*/ dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar producto"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; JLabel editarNombreClienteDialogo = new JLabel("Nombre:"); panelDialogo.add(editarNombreClienteDialogo, c); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarNombreClienteDialogo = new JTextField(); valorEditarNombreClienteDialogo.setText(productoActual.getNombre()); panelDialogo.add(valorEditarNombreClienteDialogo, c); final JTextField valorEditarUnidadesProductoDialogo = new JTextField(); valorEditarUnidadesProductoDialogo.setText(String.valueOf(productoActual.getUnidadesDisponibles())); panelDialogo.add(valorEditarUnidadesProductoDialogo, c); c.gridx = 2; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 15, 10, 0); JLabel editarTelefonoClienteDialogo = new JLabel("Precio"); panelDialogo.add(editarTelefonoClienteDialogo, c); c.gridx = 3; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 0, 10, 0); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarCelularClienteDialogo = new JLabel("Descripcion:"); panelDialogo.add(editarCelularClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarDescripcionProductoDialogo = new JTextField(); valorEditarDescripcionProductoDialogo.setText(productoActual.getDescripcion()); panelDialogo.add(valorEditarDescripcionProductoDialogo, c); c.gridx = 2; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarMontoClienteDialogo = new JLabel("Unidades"); panelDialogo.add(editarMontoClienteDialogo, c); c.gridx = 3; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarPrecioProductoDialogo = new JTextField(); valorEditarPrecioProductoDialogo.setText(productoActual.getPrecio() + ""); panelDialogo.add(valorEditarPrecioProductoDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarCodigoBarrasProyecto = new JLabel("Cdigo de barras:"); panelDialogo.add(editarCodigoBarrasProyecto, c); c.gridx = 1; c.gridy = 3; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorCodigoDeBarras = new JTextField(); valorCodigoDeBarras.setText(productoActual.getCodigoBarras()); panelDialogo.add(valorCodigoDeBarras, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 2; c.ipadx = 100; c.insets = new Insets(15, 40, 0, 0); JButton botonGuardarProductoDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarProductoDialogo, c); c.gridx = 2; c.gridy = 4; c.gridwidth = 2; c.insets = new Insets(15, 40, 0, 0); c.ipadx = 100; JButton botonCerrarProductoDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarProductoDialogo, c); dialogoEditar.add(panelDialogo); botonCerrarProductoDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarProductoDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String[] selection = { "nombre", "descripcion", "unidades", "precio", "codigoBarras" }; String[] value = { valorEditarNombreClienteDialogo.getText(), valorEditarDescripcionProductoDialogo.getText(), valorEditarUnidadesProductoDialogo.getText(), valorEditarPrecioProductoDialogo.getText(), valorCodigoDeBarras.getText() }; String[] type_value = { "varchar", "varchar", "int", "double", "varchar" }; String restriction = " where producto_id = " + identificacion; controladorP.updateProduct(selection, value, type_value, restriction); JOptionPane.showMessageDialog(dialogoEditar, "Se ha editado el producto xitosamente"); dialogoEditar.dispose(); //Refrescar busqueda actual jButton2ActionPerformed(null); } catch (Exception event) { JOptionPane.showMessageDialog(dialogoEditar, "El valor del monto debe ser numrico"); } } }); dialogoEditar.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void TablaDeClientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaDeClientesMouseClicked // TODO add your handling code here: int fila = TablaDeClientes.getSelectedRow(); int identificacion = (int) TablaDeClientes.getValueAt(fila, 0); final ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaClientes = controladorCliente.obtenerClientes("", identificacion); final Cliente clienteActual = listaClientes.get(0); final JDialog dialogoEditar = new JDialog(this); dialogoEditar.setTitle("Editar clientes"); dialogoEditar.setSize(600, 310);/*from w ww . j a v a 2 s .co m*/ dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; JLabel editarTextoPrincipalDialogo = new JLabel("Editar clientes"); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.insets = new Insets(15, 200, 40, 0); c.ipadx = 100; Font textoGrande = new Font("Arial", 1, 18); editarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(editarTextoPrincipalDialogo, c); c.insets = new Insets(0, 5, 10, 0); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; JLabel editarNombreClienteDialogo = new JLabel("Nombre:"); panelDialogo.add(editarNombreClienteDialogo, c); c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarNombreClienteDialogo = new JTextField(); valorEditarNombreClienteDialogo.setText(clienteActual.getNombre()); panelDialogo.add(valorEditarNombreClienteDialogo, c); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarCelularClienteDialogo = new JLabel("Celular:"); panelDialogo.add(editarCelularClienteDialogo, c); c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarCelularClienteDialogo = new JTextField(); valorEditarCelularClienteDialogo.setText(clienteActual.getNumero_celular()); panelDialogo.add(valorEditarCelularClienteDialogo, c); c.gridx = 2; c.gridy = 2; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 5, 10, 0); JLabel editarMontoClienteDialogo = new JLabel("Monto a prestar:"); panelDialogo.add(editarMontoClienteDialogo, c); c.gridx = 3; c.gridy = 2; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 15, 10, 15); final JTextField valorEditarMontoClienteDialogo = new JTextField(); valorEditarMontoClienteDialogo.setText(String.valueOf(clienteActual.getMonto_prestamo())); panelDialogo.add(valorEditarMontoClienteDialogo, c); c.gridx = 2; c.gridy = 1; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 15, 10, 0); JLabel editarTelefonoClienteDialogo = new JLabel("Telefono:"); panelDialogo.add(editarTelefonoClienteDialogo, c); c.gridx = 3; c.gridy = 1; c.gridwidth = 1; c.ipadx = 100; c.insets = new Insets(0, 0, 10, 0); final JTextField valorEditarTelefonoClienteDialogo = new JTextField(); valorEditarTelefonoClienteDialogo.setText(clienteActual.getNumero_telefono()); panelDialogo.add(valorEditarTelefonoClienteDialogo, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.ipadx = 40; c.insets = new Insets(0, 0, 10, 0); JLabel editarAddressClienteDialogo = new JLabel("Direccin:"); panelDialogo.add(editarAddressClienteDialogo, c); c.gridx = 1; c.gridy = 3; c.gridwidth = 3; c.ipadx = 400; c.insets = new Insets(0, 15, 10, 0); final JTextField valorEditarAddressClienteDialogo = new JTextField(); valorEditarAddressClienteDialogo.setText(clienteActual.getDireccion()); panelDialogo.add(valorEditarAddressClienteDialogo, c); c.gridx = 0; c.gridy = 4; c.gridwidth = 2; c.ipadx = 100; c.insets = new Insets(15, 40, 0, 0); JButton botonGuardarClienteDialogo = new JButton("Guardar"); panelDialogo.add(botonGuardarClienteDialogo, c); c.gridx = 2; c.gridy = 4; c.gridwidth = 2; c.insets = new Insets(15, 40, 0, 0); c.ipadx = 100; JButton botonCerrarClienteDialogo = new JButton("Cancelar"); panelDialogo.add(botonCerrarClienteDialogo, c); dialogoEditar.add(panelDialogo); botonCerrarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); botonGuardarClienteDialogo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { clienteActual.setDireccion(valorEditarAddressClienteDialogo.getText()); clienteActual.setMonto_prestamo(Double.parseDouble(valorEditarMontoClienteDialogo.getText())); clienteActual.setNombre(valorEditarNombreClienteDialogo.getText()); clienteActual.setNumero_celular(valorEditarCelularClienteDialogo.getText()); clienteActual.setNumero_telefono(valorEditarTelefonoClienteDialogo.getText()); controladorCliente.editarCliente(clienteActual); JOptionPane.showMessageDialog(dialogoEditar, "Se ha editado el cliente xitosamente"); dialogoEditar.dispose(); //Refrescar busqueda actual String nombreCliente = nombreClienteBusqueda.getText(); int identificacionClienteInt = 0; ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaDeClientes = controladorCliente.obtenerClientes(nombreCliente, identificacionClienteInt); //Agregar filas DefaultTableModel modelo = (DefaultTableModel) TablaDeClientes.getModel(); for (int i = 0; i < modelo.getRowCount(); i++) { modelo.removeRow(i); } modelo.setRowCount(0); for (int i = 0; i < listaDeClientes.size(); i++) { Cliente cliente = listaDeClientes.get(i); Object[] fila = new Object[4]; fila[0] = cliente.getCliente_id(); fila[1] = cliente.getNombre(); fila[2] = cliente.getMonto_prestamo(); //button.setText("<HTML>Click the <FONT color=\"#000099\"><U>link "+i+"</U></FONT>"+ " to go to the Java website.</HTML>"); fila[3] = "Editar"; modelo.addRow(fila); } TablaDeClientes.setModel(modelo); } catch (Exception event) { JOptionPane.showMessageDialog(dialogoEditar, "El valor del monto debe ser numrico"); } } }); dialogoEditar.setVisible(true); /*Action mostrarMensaje; mostrarMensaje = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); ((DefaultTableModel) table.getModel()).removeRow(modelRow); } }; ButtonColumn buttonColumn = new ButtonColumn(TablaDeClientes, mostrarMensaje, 3); buttonColumn.setMnemonic(KeyEvent.VK_E);*/ }
From source file:userinterface.properties.GUIGraphHandler.java
public void plotNewFunction() { JDialog dialog; JRadioButton radio2d, radio3d, newGraph, existingGraph; JTextField functionField, seriesName; JButton ok, cancel;/*from www . j av a2 s .c o m*/ JComboBox<String> chartOptions; JLabel example; //init all the fields of the dialog dialog = new JDialog(GUIPrism.getGUI()); radio2d = new JRadioButton("2D"); radio3d = new JRadioButton("3D"); newGraph = new JRadioButton("New Graph"); existingGraph = new JRadioButton("Exisiting"); chartOptions = new JComboBox<String>(); functionField = new JTextField(); ok = new JButton("Plot"); cancel = new JButton("Cancel"); seriesName = new JTextField(); example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>"); example.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { example.setCursor(new Cursor(Cursor.HAND_CURSOR)); example.setForeground(Color.BLUE); } @Override public void mouseExited(MouseEvent e) { example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); example.setForeground(Color.BLACK); } @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (radio2d.isSelected()) { functionField.setText("x/2 + 5"); } else { functionField.setText("x+y+5"); } functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15)); functionField.setForeground(Color.BLACK); } } }); //set dialog properties dialog.setSize(400, 350); dialog.setTitle("Plot a new function"); dialog.setModal(true); dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS)); dialog.setLocationRelativeTo(GUIPrism.getGUI()); //add every component to their dedicated panels JPanel graphTypePanel = new JPanel(new FlowLayout()); graphTypePanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type")); graphTypePanel.add(radio2d); graphTypePanel.add(radio3d); JPanel functionFieldPanel = new JPanel(new BorderLayout()); functionFieldPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function")); functionFieldPanel.add(functionField, BorderLayout.CENTER); functionFieldPanel.add(example, BorderLayout.SOUTH); JPanel chartSelectPanel = new JPanel(); chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS)); chartSelectPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to")); JPanel radioPlotPanel = new JPanel(new FlowLayout()); radioPlotPanel.add(newGraph); radioPlotPanel.add(existingGraph); JPanel chartOptionsPanel = new JPanel(new FlowLayout()); chartOptionsPanel.add(chartOptions); chartSelectPanel.add(radioPlotPanel); chartSelectPanel.add(chartOptionsPanel); JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomControlPanel.add(ok); bottomControlPanel.add(cancel); JPanel seriesNamePanel = new JPanel(new BorderLayout()); seriesNamePanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name")); seriesNamePanel.add(seriesName, BorderLayout.CENTER); // add all the panels to the dialog dialog.add(graphTypePanel); dialog.add(functionFieldPanel); dialog.add(chartSelectPanel); dialog.add(seriesNamePanel); dialog.add(bottomControlPanel); // do all the enables and set properties radio2d.setSelected(true); newGraph.setSelected(true); chartOptions.setEnabled(false); functionField.setText("Add function expression here...."); functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15)); functionField.setForeground(Color.GRAY); seriesName.setText("New function"); ok.setMnemonic('P'); cancel.setMnemonic('C'); example.setToolTipText("click to try out"); ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); cancel.getActionMap().put("cancel", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); boolean found = false; for (int i = 0; i < theTabs.getTabCount(); i++) { if (theTabs.getComponentAt(i) instanceof Graph) { chartOptions.addItem(getGraphName(i)); found = true; } } if (!found) { existingGraph.setEnabled(false); chartOptions.setEnabled(false); } //add all the action listeners radio2d.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (radio2d.isSelected()) { radio3d.setSelected(false); if (chartOptions.getItemCount() > 0) { existingGraph.setEnabled(true); chartOptions.setEnabled(true); } example.setText( "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>"); } } }); radio3d.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (radio3d.isSelected()) { radio2d.setSelected(false); newGraph.setSelected(true); existingGraph.setEnabled(false); chartOptions.setEnabled(false); example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>"); } } }); newGraph.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (newGraph.isSelected()) { existingGraph.setSelected(false); chartOptions.setEnabled(false); } } }); existingGraph.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (existingGraph.isSelected()) { newGraph.setSelected(false); chartOptions.setEnabled(true); } } }); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String function = functionField.getText(); Expression expr = null; try { expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function); expr = (Expression) expr.accept(new ASTTraverseModify() { @Override public Object visit(ExpressionIdent e) throws PrismLangException { return new ExpressionConstant(e.getName(), TypeDouble.getInstance()); } }); expr.typeCheck(); expr.semanticCheck(); } catch (PrismLangException e1) { // for copying style JLabel label = new JLabel(); // html content in our case the error we want to show JEditorPane ep = new JEditorPane("text/html", "<html> There was an error parsing the function. To read about what built-in" + " functions are supported <br>and some more information on the functions, visit " + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>." + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>"); // handle link events ep.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { try { Desktop.getDesktop().browse(e.getURL().toURI()); } catch (IOException | URISyntaxException e1) { e1.printStackTrace(); } } } }); ep.setEditable(false); ep.setBackground(label.getBackground()); // show the error dialog JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE); return; } if (radio2d.isSelected()) { ParametricGraph graph = null; if (newGraph.isSelected()) { graph = new ParametricGraph(""); } else { for (int i = 0; i < theTabs.getComponentCount(); i++) { if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) { graph = (ParametricGraph) theTabs.getComponent(i); } } } dialog.dispose(); defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true); } else if (radio3d.isSelected()) { try { expr = (Expression) expr.accept(new ASTTraverseModify() { @Override public Object visit(ExpressionIdent e) throws PrismLangException { return new ExpressionConstant(e.getName(), TypeDouble.getInstance()); } }); expr.semanticCheck(); expr.typeCheck(); } catch (PrismLangException e1) { e1.printStackTrace(); } if (expr.getAllConstants().size() < 2) { JOptionPane.showMessageDialog(dialog, "There are not enough variables in the function to plot a 3D chart!", "Error", JOptionPane.ERROR_MESSAGE); return; } // its always a new graph ParametricGraph3D graph = new ParametricGraph3D(expr); dialog.dispose(); defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false); } dialog.dispose(); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); // we will show info about the function when field is out of focus functionField.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { if (!functionField.getText().equals("")) { return; } functionField.setText("Add function expression here...."); functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15)); functionField.setForeground(Color.GRAY); } @Override public void focusGained(FocusEvent e) { if (!functionField.getText().equals("Add function expression here....")) { return; } functionField.setForeground(Color.BLACK); functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15)); functionField.setText(""); } }); // show the dialog dialog.setVisible(true); }
From source file:interfaces.InterfazPrincipal.java
private void botonGenerarReporteClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGenerarReporteClienteActionPerformed // TODO add your handling code here: try {/* w w w.j av a 2s . c om*/ if (clienteReporteClienteFechaFinal.getSelectedDate().getTime() .compareTo(clienteReporteClienteFechaInicial.getSelectedDate().getTime()) < 0) { JOptionPane.showMessageDialog(this, "La fecha final debe ser posterior al dia de inicio"); } else { final ArrayList<Integer> listaIDFlujos = new ArrayList<>(); final JDialog dialogoEditar = new JDialog(); dialogoEditar.setTitle("Reporte cliente"); dialogoEditar.setSize(350, 610); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); //c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Informe cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.insets = new Insets(10, 45, 10, 10); Font textoGrande = new Font("Arial", 1, 18); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Factura"); modeloTabla.addColumn("Tipo Flujo"); modeloTabla.addColumn("Fecha"); modeloTabla.addColumn("Valor"); //Llenar tabla ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(jTextFieldIdentificacionClienteReporte.getText()) + ") order by factura_id"); // {"flujo_id","factura_id","tipo_flujo","fecha","valor"}; ArrayList<Calendar> fechasFlujos = new ArrayList<>(); for (int i = 0; i < flujosCliente.size(); i++) { String fila[] = new String[4]; String[] objeto = flujosCliente.get(i); fila[0] = objeto[1]; fila[1] = objeto[2]; fila[2] = objeto[3]; fila[3] = objeto[4]; //Filtrar, mirar las fechas String[] partirEspacios = objeto[3].split("\\s"); //El primer string es la fecha sin hora //Ahora esparamos por - String[] tomarAgeMesDia = partirEspacios[0].split("-"); //Realizar filtro int ageConsulta = Integer.parseInt(tomarAgeMesDia[0]); int mesConsulta = Integer.parseInt(tomarAgeMesDia[1]); int diaConsulta = Integer.parseInt(tomarAgeMesDia[2]); //Obtenemos dias, mes y ao de la consulta //Inicial int anioInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.YEAR); int mesInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.MONTH) + 1; int diaInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.DAY_OF_MONTH); //Final int anioFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.YEAR); int mesFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.MONTH) + 1; int diaFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.DAY_OF_MONTH); //Construir fechas Calendar fechaDeLaBD = new GregorianCalendar(ageConsulta, mesConsulta, diaConsulta); //Set year, month, day) Calendar fechaInicialRango = new GregorianCalendar(anioInicial, mesInicial, diaInicial); Calendar fechaFinalRango = new GregorianCalendar(anioFinal, mesFinal, diaFinal); if (fechaDeLaBD.compareTo(fechaInicialRango) <= 0 && fechaDeLaBD.compareTo(fechaFinalRango) >= 0) { fechasFlujos.add(fechaDeLaBD); modeloTabla.addRow(fila); } } if (modeloTabla.getRowCount() > 0) { tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("Factura").setMinWidth(80); tablaDialogo.getColumn("Tipo Flujo").setMinWidth(80); tablaDialogo.getColumn("Fecha").setMinWidth(90); tablaDialogo.getColumn("Valor").setMinWidth(80); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(330, 150)); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.insets = new Insets(0, 0, 0, 0); panelDialogo.add(scroll, c); TimeSeries localTimeSeries = new TimeSeries("Compras del cliente en el periodo"); Map listaAbonos = new HashMap(); for (int i = 0; i < modeloTabla.getRowCount(); i++) { listaIDFlujos.add(Integer.parseInt(flujosCliente.get(i)[0])); if (modeloTabla.getValueAt(i, 1).equals("abono")) { Calendar fechaFlujo = fechasFlujos.get(i); double valor = Double.parseDouble(String.valueOf(modeloTabla.getValueAt(i, 3))); int anoDato = fechaFlujo.get(Calendar.YEAR); int mesDato = fechaFlujo.get(Calendar.MONTH) + 1; int diaDato = fechaFlujo.get(Calendar.DAY_OF_MONTH); Day FechaDato = new Day(diaDato, mesDato, anoDato); if (listaAbonos.get(FechaDato) != null) { double valorAbono = (double) listaAbonos.get(FechaDato); listaAbonos.remove(FechaDato); listaAbonos.put(FechaDato, valorAbono + valor); } else { listaAbonos.put(FechaDato, valor); } } } Double maximo = 0.0; Iterator iterator = listaAbonos.keySet().iterator(); while (iterator.hasNext()) { Day key = (Day) iterator.next(); Double value = (double) listaAbonos.get(key); maximo = Math.max(maximo, value); localTimeSeries.add(key, value); } //localTimeSeries.add(); TimeSeriesCollection datos = new TimeSeriesCollection(localTimeSeries); JFreeChart chart = ChartFactory.createTimeSeriesChart("Compras del cliente en el periodo", // Title "Tiempo", // x-axis Label "Total ($)", // y-axis Label datos, // Dataset true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); /*Altering the graph */ XYPlot plot = (XYPlot) chart.getPlot(); plot.setAxisOffset(new RectangleInsets(5.0, 10.0, 10.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setRange(new Range(0, maximo * 1.2)); Font font = new Font("Dialog", Font.PLAIN, 9); numberAxis.setTickLabelFont(font); numberAxis.setLabelFont(font); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy")); axis.setAutoTickUnitSelection(false); axis.setVerticalTickLabels(true); axis.setTickLabelFont(font); axis.setLabelFont(font); LegendTitle leyendaChart = chart.getLegend(); leyendaChart.setItemFont(font); Font fontTitulo = new Font("Dialog", Font.BOLD, 12); TextTitle tituloChart = chart.getTitle(); tituloChart.setFont(fontTitulo); ChartPanel CP = new ChartPanel(chart); Dimension D = new Dimension(330, 300); CP.setPreferredSize(D); CP.setVisible(true); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.insets = new Insets(10, 0, 0, 0); panelDialogo.add(CP, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(10, 30, 0, 0); JButton botonCerrar = new JButton("Cerrar"); botonCerrar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); panelDialogo.add(botonCerrar, c); JButton botonGenerarPDF = new JButton("Guardar archivo"); botonGenerarPDF.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReporteFlujosCliente reporteFlujosCliente = new ReporteFlujosCliente(); reporteFlujosCliente.guardarDocumentoDialogo(dialogoEditar, listaIDFlujos, Integer.parseInt(jTextFieldIdentificacionClienteReporte.getText()), clienteReporteClienteFechaInicial.getSelectedDate(), clienteReporteClienteFechaFinal.getSelectedDate()); } }); c.insets = new Insets(10, 100, 0, 0); panelDialogo.add(botonGenerarPDF, c); JButton botonImprimir = new JButton("Imprimir"); botonImprimir.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReporteFlujosCliente reporteFlujosCliente = new ReporteFlujosCliente(); reporteFlujosCliente.imprimirFlujo(listaIDFlujos, Integer.parseInt(jTextFieldIdentificacionClienteReporte.getText()), clienteReporteClienteFechaInicial.getSelectedDate(), clienteReporteClienteFechaFinal.getSelectedDate()); } }); c.insets = new Insets(10, 230, 0, 0); panelDialogo.add(botonImprimir, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); } else { JOptionPane.showMessageDialog(this, "El cliente no registra movimientos en el rango de fechas seleccionado"); } } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Debe seleccionar un da inicial y final de fechas"); } }
From source file:userinterface.properties.GUIGraphHandler.java
public void defineConstantsAndPlot(Expression expr, JPanel graph, String seriesName, Boolean isNewGraph, boolean is2D) { JDialog dialog; JButton ok, cancel;//w w w.j av a2s.c o m JScrollPane scrollPane; ConstantPickerList constantList; JComboBox<String> xAxis, yAxis; //init everything dialog = new JDialog(GUIPrism.getGUI()); dialog.setTitle("Define constants and select axes"); dialog.setSize(500, 400); dialog.setLocationRelativeTo(GUIPrism.getGUI()); dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS)); dialog.setModal(true); constantList = new ConstantPickerList(); scrollPane = new JScrollPane(constantList); xAxis = new JComboBox<String>(); yAxis = new JComboBox<String>(); ok = new JButton("Ok"); ok.setMnemonic('O'); cancel = new JButton("Cancel"); cancel.setMnemonic('C'); //add all components to their dedicated panels JPanel exprPanel = new JPanel(new FlowLayout()); exprPanel.setBorder(new TitledBorder("Function")); exprPanel.add(new JLabel(expr.toString())); JPanel axisPanel = new JPanel(); axisPanel.setBorder(new TitledBorder("Select axis constants")); axisPanel.setLayout(new BoxLayout(axisPanel, BoxLayout.Y_AXIS)); JPanel xAxisPanel = new JPanel(new FlowLayout()); xAxisPanel.add(new JLabel("X axis:")); xAxisPanel.add(xAxis); JPanel yAxisPanel = new JPanel(new FlowLayout()); yAxisPanel.add(new JLabel("Y axis:")); yAxisPanel.add(yAxis); axisPanel.add(xAxisPanel); axisPanel.add(yAxisPanel); JPanel constantPanel = new JPanel(new BorderLayout()); constantPanel.setBorder(new TitledBorder("Please define the following constants")); constantPanel.add(scrollPane, BorderLayout.CENTER); constantPanel.add(new ConstantHeader(), BorderLayout.NORTH); JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomPanel.add(ok); bottomPanel.add(cancel); //fill the axes components for (int i = 0; i < expr.getAllConstants().size(); i++) { xAxis.addItem(expr.getAllConstants().get(i)); if (!is2D) yAxis.addItem(expr.getAllConstants().get(i)); } if (!is2D) { yAxis.setSelectedIndex(1); } //fill the constants table for (int i = 0; i < expr.getAllConstants().size(); i++) { ConstantLine line = new ConstantLine(expr.getAllConstants().get(i), TypeDouble.getInstance()); constantList.addConstant(line); if (!is2D) { if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } //do enables if (is2D) { yAxis.setEnabled(false); } ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); cancel.getActionMap().put("cancel", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); //add action listeners xAxis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (is2D) { return; } String item = xAxis.getSelectedItem().toString(); if (item.equals(yAxis.getSelectedItem().toString())) { int index = yAxis.getSelectedIndex(); if (index != yAxis.getItemCount() - 1) { yAxis.setSelectedIndex(++index); } else { yAxis.setSelectedIndex(--index); } } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } }); yAxis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String item = yAxis.getSelectedItem().toString(); if (item.equals(xAxis.getSelectedItem().toString())) { int index = xAxis.getSelectedIndex(); if (index != xAxis.getItemCount() - 1) { xAxis.setSelectedIndex(++index); } else { xAxis.setSelectedIndex(--index); } } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } }); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { constantList.checkValid(); } catch (PrismException e2) { JOptionPane.showMessageDialog(dialog, "<html> One or more of the defined constants are invalid. <br><br> <font color=red>Error: </font>" + e2.getMessage() + "</html>", "Parse Error", JOptionPane.ERROR_MESSAGE); return; } if (is2D) { // it will always be a parametric graph in 2d case ParametricGraph pGraph = (ParametricGraph) graph; ConstantLine xAxisConstant = constantList.getConstantLine(xAxis.getSelectedItem().toString()); if (xAxisConstant == null) { //should never happen JOptionPane.showMessageDialog(dialog, "The selected axis is invalid.", "Error", JOptionPane.ERROR_MESSAGE); return; } double xStartValue = Double.parseDouble(xAxisConstant.getStartValue()); double xEndValue = Double.parseDouble(xAxisConstant.getEndValue()); double xStepValue = Double.parseDouble(xAxisConstant.getStepValue()); int seriesCount = 0; for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString())) { seriesCount++; } else { seriesCount += line.getTotalNumOfValues(); } } // if there will be too many series to be plotted, ask the user if they are sure they know what they are doing if (seriesCount > 10) { int res = JOptionPane.showConfirmDialog(dialog, "This configuration will create " + seriesCount + " series. Continue?", "Confirm", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return; } } Values singleValuesGlobal = new Values(); //add the single values to a global values list for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getTotalNumOfValues() == 1) { double singleValue = Double.parseDouble(line.getSingleValue()); singleValuesGlobal.addValue(line.getName(), singleValue); } } // we just have one variable so we can plot directly if (constantList.getNumConstants() == 1 || singleValuesGlobal.getNumValues() == constantList.getNumConstants() - 1) { SeriesKey key = pGraph.addSeries(seriesName); pGraph.hideShape(key); pGraph.getXAxisSettings().setHeading(xAxis.getSelectedItem().toString()); pGraph.getYAxisSettings().setHeading("function"); for (double x = xStartValue; x <= xEndValue; x += xStepValue) { double ans = -1; Values vals = new Values(); vals.addValue(xAxis.getSelectedItem().toString(), x); for (int ii = 0; ii < singleValuesGlobal.getNumValues(); ii++) { try { vals.addValue(singleValuesGlobal.getName(ii), singleValuesGlobal.getDoubleValue(ii)); } catch (PrismLangException e1) { e1.printStackTrace(); } } try { ans = expr.evaluateDouble(vals); } catch (PrismLangException e1) { e1.printStackTrace(); } pGraph.addPointToSeries(key, new PrismXYDataItem(x, ans)); } if (isNewGraph) { addGraph(pGraph); } dialog.dispose(); return; } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line == xAxisConstant || singleValuesGlobal.contains(line.getName())) { continue; } double lineStart = Double.parseDouble(line.getStartValue()); double lineEnd = Double.parseDouble(line.getEndValue()); double lineStep = Double.parseDouble(line.getStepValue()); for (double j = lineStart; j < lineEnd; j += lineStep) { SeriesKey key = pGraph.addSeries(seriesName); pGraph.hideShape(key); for (double x = xStartValue; x <= xEndValue; x += xStepValue) { double ans = -1; Values vals = new Values(); vals.addValue(xAxis.getSelectedItem().toString(), x); vals.addValue(line.getName(), j); for (int ii = 0; ii < singleValuesGlobal.getNumValues(); ii++) { try { vals.addValue(singleValuesGlobal.getName(ii), singleValuesGlobal.getDoubleValue(ii)); } catch (PrismLangException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } for (int ii = 0; ii < constantList.getNumConstants(); ii++) { if (constantList.getConstantLine(ii) == xAxisConstant || singleValuesGlobal .contains(constantList.getConstantLine(ii).getName()) || constantList.getConstantLine(ii) == line) { continue; } ConstantLine temp = constantList.getConstantLine(ii); double val = Double.parseDouble(temp.getStartValue()); vals.addValue(temp.getName(), val); } try { ans = expr.evaluateDouble(vals); } catch (PrismLangException e1) { e1.printStackTrace(); } pGraph.addPointToSeries(key, new PrismXYDataItem(x, ans)); } } } if (isNewGraph) { addGraph(graph); } } else { // this will always be a parametric graph for the 3d case ParametricGraph3D pGraph = (ParametricGraph3D) graph; //add the graph to the gui addGraph(pGraph); //Get the constants we want to put on the x and y axis ConstantLine xAxisConstant = constantList.getConstantLine(xAxis.getSelectedItem().toString()); ConstantLine yAxisConstant = constantList.getConstantLine(yAxis.getSelectedItem().toString()); //add the single values to a global values list Values singleValuesGlobal = new Values(); for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getTotalNumOfValues() == 1) { double singleValue = Double.parseDouble(line.getSingleValue()); singleValuesGlobal.addValue(line.getName(), singleValue); } } pGraph.setGlobalValues(singleValuesGlobal); pGraph.setAxisConstants(xAxis.getSelectedItem().toString(), yAxis.getSelectedItem().toString()); pGraph.setBounds(xAxisConstant.getStartValue(), xAxisConstant.getEndValue(), yAxisConstant.getStartValue(), yAxisConstant.getEndValue()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { //plot the graph pGraph.plot(expr.toString(), xAxis.getSelectedItem().toString(), "Function", yAxis.getSelectedItem().toString()); //calculate the sampling rates from the step sizes as given by the user int xSamples = (int) ((Double.parseDouble(xAxisConstant.getEndValue()) - Double.parseDouble(xAxisConstant.getStartValue())) / Double.parseDouble(xAxisConstant.getStepValue())); int ySamples = (int) ((Double.parseDouble(xAxisConstant.getEndValue()) - Double.parseDouble(xAxisConstant.getStartValue())) / Double.parseDouble(xAxisConstant.getStepValue())); pGraph.setSamplingRates(xSamples, ySamples); } }); } dialog.dispose(); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); //add everything to the dialog show the dialog dialog.add(exprPanel); dialog.add(axisPanel); dialog.add(constantPanel); dialog.add(bottomPanel); dialog.setVisible(true); }