List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION
int OK_CANCEL_OPTION
To view the source code for javax.swing JOptionPane OK_CANCEL_OPTION.
Click Source Link
showConfirmDialog
. From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java
/** * This method initializes jTableCollectors * /* www.j ava 2 s . co m*/ * @return javax.swing.JTable */ private JTable getJTableCollectors() { if (jTableCollectors == null) { jTableCollectors = new JTable(new CollectorTableModel()); // Note: When setting the values, the table column editor needs to be reset there, as the model is replaced. //JTextField field = new JTextField(); FilteringAgentJComboBox field = new FilteringAgentJComboBox(); //field.setInputVerifier(MetadataRetriever.getInputVerifier(Collector.class, "CollectorName", field)); //jTableCollectors.getColumnModel().getColumn(0).setCellEditor(new PicklistTableCellEditor(field, true)); jTableCollectors.getColumnModel().getColumn(0).setCellEditor(new ComboBoxCellEditor(field)); jTableCollectors.setRowHeight(jTableCollectors.getRowHeight() + 4); jTableCollectors.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent e) { thisPane.setStateToDirty(); } }); jTableCollectors.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnCollsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupCollectors.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnCollsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupCollectors.show(e.getComponent(), e.getX(), e.getY()); } } }); jPopupCollectors = new JPopupMenu(); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { log.debug(clickedOnCollsRow); if (clickedOnCollsRow >= 0) { int ok = JOptionPane.showConfirmDialog(thisPane, "Delete the selected collector?", "Delete Collector", JOptionPane.OK_CANCEL_OPTION); if (ok == JOptionPane.OK_OPTION) { log.debug("deleting collectors row " + clickedOnCollsRow); ((CollectorTableModel) jTableCollectors.getModel()).deleteRow(clickedOnCollsRow); setStateToDirty(); } else { log.debug("collector row delete canceled by user."); } } else { JOptionPane.showMessageDialog(thisPane, "Unable to select row to delete. Try empting the value and pressing Save."); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisPane, "Failed to delete a collector row. " + ex.getMessage()); } } }); jPopupCollectors.add(mntmDeleteRow); } return jTableCollectors; }
From source file:com.nikonhacker.gui.EmulatorUI.java
private void openChipOptionsDialog(final int chip) { // ------------------------ Disassembly options JPanel disassemblyOptionsPanel = new JPanel(new MigLayout("", "[left,grow][left,grow]")); // Prepare sample code area final RSyntaxTextArea listingArea = new RSyntaxTextArea(20, 90); SourceCodeFrame.prepareAreaFormat(chip, listingArea); final List<JCheckBox> outputOptionsCheckBoxes = new ArrayList<JCheckBox>(); ActionListener areaRefresherListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { Set<OutputOption> sampleOptions = EnumSet.noneOf(OutputOption.class); dumpOptionCheckboxes(outputOptionsCheckBoxes, sampleOptions); int baseAddress = framework.getPlatform(chip).getCpuState().getResetAddress(); int lastAddress = baseAddress; Memory sampleMemory = new DebuggableMemory(false); sampleMemory.map(baseAddress, 0x100, true, true, true); StringWriter writer = new StringWriter(); Disassembler disassembler; if (chip == Constants.CHIP_FR) { sampleMemory.store16(lastAddress, 0x1781); // PUSH RP lastAddress += 2;/*from w w w. j a v a2 s . co m*/ sampleMemory.store16(lastAddress, 0x8FFE); // PUSH (FP,AC,R12,R11,R10,R9,R8) lastAddress += 2; sampleMemory.store16(lastAddress, 0x83EF); // ANDCCR #0xEF lastAddress += 2; sampleMemory.store16(lastAddress, 0x9F80); // LDI:32 #0x68000000,R0 lastAddress += 2; sampleMemory.store16(lastAddress, 0x6800); lastAddress += 2; sampleMemory.store16(lastAddress, 0x0000); lastAddress += 2; sampleMemory.store16(lastAddress, 0x2031); // LD @(FP,0x00C),R1 lastAddress += 2; sampleMemory.store16(lastAddress, 0xB581); // LSL #24,R1 lastAddress += 2; sampleMemory.store16(lastAddress, 0x1A40); // DMOVB R13,@0x40 lastAddress += 2; sampleMemory.store16(lastAddress, 0x9310); // ORCCR #0x10 lastAddress += 2; sampleMemory.store16(lastAddress, 0x8D7F); // POP (R8,R9,R10,R11,R12,AC,FP) lastAddress += 2; sampleMemory.store16(lastAddress, 0x0781); // POP RP lastAddress += 2; disassembler = new Dfr(); disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore disassembler.setOutputFileName(null); disassembler.processOptions(new String[] { "-m", "0x" + Format.asHex(baseAddress, 8) + "-0x" + Format.asHex(lastAddress, 8) + "=CODE" }); } else { sampleMemory.store32(lastAddress, 0x340B0001); // li $t3, 0x0001 lastAddress += 4; sampleMemory.store32(lastAddress, 0x17600006); // bnez $k1, 0xBFC00020 lastAddress += 4; sampleMemory.store32(lastAddress, 0x00000000); // nop lastAddress += 4; sampleMemory.store32(lastAddress, 0x54400006); // bnezl $t4, 0xBFC00028 lastAddress += 4; sampleMemory.store32(lastAddress, 0x3C0C0000); // ?lui $t4, 0x0000 lastAddress += 4; int baseAddress16 = lastAddress; int lastAddress16 = baseAddress16; sampleMemory.store32(lastAddress16, 0xF70064F6); // save $ra,$s0,$s1,$s2-$s7,$fp, 0x30 lastAddress16 += 4; sampleMemory.store16(lastAddress16, 0x6500); // nop lastAddress16 += 2; sampleMemory.store32(lastAddress16, 0xF7006476); // restore $ra,$s0,$s1,$s2-$s7,$fp, 0x30 lastAddress16 += 4; sampleMemory.store16(lastAddress16, 0xE8A0); // ret lastAddress16 += 2; disassembler = new Dtx(); disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore disassembler.setOutputFileName(null); disassembler.processOptions(new String[] { "-m", "0x" + Format.asHex(baseAddress, 8) + "-0x" + Format.asHex(lastAddress, 8) + "=CODE:32", "-m", "0x" + Format.asHex(baseAddress16, 8) + "-0x" + Format.asHex(lastAddress16, 8) + "=CODE:16" }); } disassembler.setOutputOptions(sampleOptions); disassembler.setMemory(sampleMemory); disassembler.initialize(); disassembler.setOutWriter(writer); disassembler.disassembleMemRanges(); disassembler.cleanup(); listingArea.setText(""); listingArea.append(writer.toString()); listingArea.setCaretPosition(0); } catch (Exception ex) { ex.printStackTrace(); } } }; int i = 1; for (OutputOption outputOption : OutputOption.allFormatOptions) { JCheckBox checkBox = makeOutputOptionCheckBox(chip, outputOption, prefs.getOutputOptions(chip), false); if (checkBox != null) { outputOptionsCheckBoxes.add(checkBox); disassemblyOptionsPanel.add(checkBox, (i % 2 == 0) ? "wrap" : ""); checkBox.addActionListener(areaRefresherListener); i++; } } if (i % 2 == 0) { disassemblyOptionsPanel.add(new JLabel(), "wrap"); } // Force a refresh areaRefresherListener.actionPerformed(new ActionEvent(outputOptionsCheckBoxes.get(0), 0, "")); // disassemblyOptionsPanel.add(new JLabel("Sample output:", SwingConstants.LEADING), "gapbottom 1, span, split 2, aligny center"); // disassemblyOptionsPanel.add(new JSeparator(), "span 2,wrap"); disassemblyOptionsPanel.add(new JSeparator(), "span 2, gapleft rel, growx, wrap"); disassemblyOptionsPanel.add(new JLabel("Sample output:"), "span 2,wrap"); disassemblyOptionsPanel.add(new JScrollPane(listingArea), "span 2,wrap"); disassemblyOptionsPanel.add(new JLabel("Tip: hover over the option checkboxes for help"), "span 2, center, wrap"); // ------------------------ Emulation options JPanel emulationOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT)); emulationOptionsPanel.add(new JLabel()); JLabel warningLabel = new JLabel( "NOTE: these options only take effect after reloading the firmware (or performing a 'Stop and reset')"); warningLabel.setBackground(Color.RED); warningLabel.setOpaque(true); warningLabel.setForeground(Color.WHITE); warningLabel.setHorizontalAlignment(SwingConstants.CENTER); emulationOptionsPanel.add(warningLabel); emulationOptionsPanel.add(new JLabel()); final JCheckBox writeProtectFirmwareCheckBox = new JCheckBox("Write-protect firmware"); writeProtectFirmwareCheckBox.setSelected(prefs.isFirmwareWriteProtected(chip)); emulationOptionsPanel.add(writeProtectFirmwareCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, any attempt to write to the loaded firmware area will result in an Emulator error. This can help trap spurious writes")); final JCheckBox dmaSynchronousCheckBox = new JCheckBox("Make DMA synchronous"); dmaSynchronousCheckBox.setSelected(prefs.isDmaSynchronous(chip)); emulationOptionsPanel.add(dmaSynchronousCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, DMA operations will be performed immediately, pausing the CPU. Otherwise they are performed in a separate thread.")); final JCheckBox autoEnableTimersCheckBox = new JCheckBox("Auto enable timers"); autoEnableTimersCheckBox.setSelected(prefs.isAutoEnableTimers(chip)); emulationOptionsPanel.add(autoEnableTimersCheckBox); emulationOptionsPanel .add(new JLabel("If checked, timers will be automatically enabled upon reset or firmware load.")); // Log memory messages final JCheckBox logMemoryMessagesCheckBox = new JCheckBox("Log memory messages"); logMemoryMessagesCheckBox.setSelected(prefs.isLogMemoryMessages(chip)); emulationOptionsPanel.add(logMemoryMessagesCheckBox); emulationOptionsPanel .add(new JLabel("If checked, messages related to memory will be logged to the console.")); // Log serial messages final JCheckBox logSerialMessagesCheckBox = new JCheckBox("Log serial messages"); logSerialMessagesCheckBox.setSelected(prefs.isLogSerialMessages(chip)); emulationOptionsPanel.add(logSerialMessagesCheckBox); emulationOptionsPanel.add( new JLabel("If checked, messages related to serial interfaces will be logged to the console.")); // Log register messages final JCheckBox logRegisterMessagesCheckBox = new JCheckBox("Log register messages"); logRegisterMessagesCheckBox.setSelected(prefs.isLogRegisterMessages(chip)); emulationOptionsPanel.add(logRegisterMessagesCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, warnings related to unimplemented register addresses will be logged to the console.")); // Log pin messages final JCheckBox logPinMessagesCheckBox = new JCheckBox("Log pin messages"); logPinMessagesCheckBox.setSelected(prefs.isLogPinMessages(chip)); emulationOptionsPanel.add(logPinMessagesCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, warnings related to unimplemented I/O pins will be logged to the console.")); emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL)); // Alt mode upon Debug JPanel altDebugPanel = new JPanel(new FlowLayout()); Object[] altDebugMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray(); final JComboBox altModeForDebugCombo = new JComboBox(new DefaultComboBoxModel(altDebugMode)); for (int j = 0; j < altDebugMode.length; j++) { if (altDebugMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponDebug(chip))) { altModeForDebugCombo.setSelectedIndex(j); } } altDebugPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip] + " runs in sync Debug: ")); altDebugPanel.add(altModeForDebugCombo); emulationOptionsPanel.add(altDebugPanel); emulationOptionsPanel .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip] + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Debug mode")); // Alt mode upon Step JPanel altStepPanel = new JPanel(new FlowLayout()); Object[] altStepMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray(); final JComboBox altModeForStepCombo = new JComboBox(new DefaultComboBoxModel(altStepMode)); for (int j = 0; j < altStepMode.length; j++) { if (altStepMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponStep(chip))) { altModeForStepCombo.setSelectedIndex(j); } } altStepPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip] + " runs in sync Step: ")); altStepPanel.add(altModeForStepCombo); emulationOptionsPanel.add(altStepPanel); emulationOptionsPanel .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip] + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Step mode")); // ------------------------ Prepare tabbed pane JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Disassembly Options", null, disassemblyOptionsPanel); tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Emulation Options", null, emulationOptionsPanel); if (chip == Constants.CHIP_TX) { JPanel chipSpecificOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT)); chipSpecificOptionsPanel.add(new JLabel("Eeprom status upon startup:")); ActionListener eepromInitializationRadioActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { prefs.setEepromInitMode(Prefs.EepromInitMode.valueOf(e.getActionCommand())); } }; JRadioButton blank = new JRadioButton("Blank"); blank.setActionCommand(Prefs.EepromInitMode.BLANK.name()); blank.addActionListener(eepromInitializationRadioActionListener); if (Prefs.EepromInitMode.BLANK.equals(prefs.getEepromInitMode())) blank.setSelected(true); JRadioButton persistent = new JRadioButton("Persistent across sessions"); persistent.setActionCommand(Prefs.EepromInitMode.PERSISTENT.name()); persistent.addActionListener(eepromInitializationRadioActionListener); if (Prefs.EepromInitMode.PERSISTENT.equals(prefs.getEepromInitMode())) persistent.setSelected(true); JRadioButton lastLoaded = new JRadioButton("Last Loaded"); lastLoaded.setActionCommand(Prefs.EepromInitMode.LAST_LOADED.name()); lastLoaded.addActionListener(eepromInitializationRadioActionListener); if (Prefs.EepromInitMode.LAST_LOADED.equals(prefs.getEepromInitMode())) lastLoaded.setSelected(true); ButtonGroup group = new ButtonGroup(); group.add(blank); group.add(persistent); group.add(lastLoaded); chipSpecificOptionsPanel.add(blank); chipSpecificOptionsPanel.add(persistent); chipSpecificOptionsPanel.add(lastLoaded); chipSpecificOptionsPanel.add(new JLabel("Front panel type:")); final JComboBox frontPanelNameCombo = new JComboBox(new String[] { "D5100_small", "D5100_large" }); if (prefs.getFrontPanelName() != null) { frontPanelNameCombo.setSelectedItem(prefs.getFrontPanelName()); } frontPanelNameCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { prefs.setFrontPanelName((String) frontPanelNameCombo.getSelectedItem()); } }); chipSpecificOptionsPanel.add(frontPanelNameCombo); emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL)); tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " specific options", null, chipSpecificOptionsPanel); } // ------------------------ Show it if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, tabbedPane, Constants.CHIP_LABEL[chip] + " options", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.DEFAULT_OPTION)) { // save output options dumpOptionCheckboxes(outputOptionsCheckBoxes, prefs.getOutputOptions(chip)); // apply TxCPUState.initRegisterLabels(prefs.getOutputOptions(chip)); // save other prefs prefs.setFirmwareWriteProtected(chip, writeProtectFirmwareCheckBox.isSelected()); prefs.setDmaSynchronous(chip, dmaSynchronousCheckBox.isSelected()); prefs.setAutoEnableTimers(chip, autoEnableTimersCheckBox.isSelected()); prefs.setLogRegisterMessages(chip, logRegisterMessagesCheckBox.isSelected()); prefs.setLogSerialMessages(chip, logSerialMessagesCheckBox.isSelected()); prefs.setLogPinMessages(chip, logPinMessagesCheckBox.isSelected()); prefs.setLogMemoryMessages(chip, logMemoryMessagesCheckBox.isSelected()); prefs.setAltExecutionModeForSyncedCpuUponDebug(chip, (EmulationFramework.ExecutionMode) altModeForDebugCombo.getSelectedItem()); prefs.setAltExecutionModeForSyncedCpuUponStep(chip, (EmulationFramework.ExecutionMode) altModeForStepCombo.getSelectedItem()); } }
From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java
private JTable getJTableSpecimenParts() { if (jTableSpecimenParts == null) { try {// ww w. j a v a 2 s. c o m jTableSpecimenParts = new JTable(new SpecimenPartsTableModel(specimen.getSpecimenParts())); jTableSpecimenParts.getColumnModel().getColumn(0).setPreferredWidth(90); } catch (NullPointerException e) { jTableSpecimenParts = new JTable(new SpecimenPartsTableModel()); jTableSpecimenParts.getColumnModel().getColumn(0).setPreferredWidth(90); } setSpecimenPartsTableCellEditors(); log.debug(specimen.getSpecimenParts().size()); jTableSpecimenParts.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnPartsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupSpecimenParts.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnPartsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupSpecimenParts.show(e.getComponent(), e.getX(), e.getY()); } } }); jPopupSpecimenParts = new JPopupMenu(); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (clickedOnPartsRow >= 0) { int ok = JOptionPane.showConfirmDialog(thisPane, "Delete the selected preparation?", "Delete Preparation", JOptionPane.OK_CANCEL_OPTION); if (ok == JOptionPane.OK_OPTION) { log.debug("deleting parts row " + clickedOnPartsRow); ((SpecimenPartsTableModel) jTableSpecimenParts.getModel()) .deleteRow(clickedOnPartsRow); setStateToDirty(); } else { log.debug("parts row delete canceled by user."); } } else { JOptionPane.showMessageDialog(thisPane, "Unable to select row to delete."); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisPane, "Failed to delete a part attribute row. " + ex.getMessage()); } } }); jPopupSpecimenParts.add(mntmDeleteRow); } return jTableSpecimenParts; }
From source file:edu.harvard.mcz.imagecapture.SpecimenDetailsViewPane.java
/** * This method initializes jTable /*from w w w .j a v a2 s . co m*/ * * @return javax.swing.JTable */ private JTable getJTable() { if (jTableNumbers == null) { jTableNumbers = new JTable(new NumberTableModel()); JComboBox<String> jComboNumberTypes = new JComboBox<String>(); jComboNumberTypes.setModel(new DefaultComboBoxModel<String>(NumberLifeCycle.getDistinctTypes())); jComboNumberTypes.setEditable(true); TableColumn typeColumn = jTableNumbers.getColumnModel().getColumn(NumberTableModel.COLUMN_TYPE); DefaultCellEditor comboBoxEditor = new DefaultCellEditor(jComboNumberTypes); //TODO: enable autocomplete for numbertypes picklist. //AutoCompleteDecorator.decorate((JComboBox) comboBoxEditor.getComponent()); typeColumn.setCellEditor(comboBoxEditor); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for pick list of number types."); typeColumn.setCellRenderer(renderer); jTableNumbers.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent e) { thisPane.setStateToDirty(); } }); jTableNumbers.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnNumsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupNumbers.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnNumsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupNumbers.show(e.getComponent(), e.getX(), e.getY()); } } }); jPopupNumbers = new JPopupMenu(); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (clickedOnNumsRow >= 0) { int ok = JOptionPane.showConfirmDialog(thisPane, "Delete the selected number?", "Delete Number", JOptionPane.OK_CANCEL_OPTION); if (ok == JOptionPane.OK_OPTION) { log.debug("deleting numbers row " + clickedOnNumsRow); ((NumberTableModel) jTableNumbers.getModel()).deleteRow(clickedOnNumsRow); setStateToDirty(); } else { log.debug("number row delete canceled by user."); } } else { JOptionPane.showMessageDialog(thisPane, "Unable to select row to delete. Try empting number and type and pressing Save."); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisPane, "Failed to delete a number row. " + ex.getMessage()); } } }); jPopupNumbers.add(mntmDeleteRow); } return jTableNumbers; }
From source file:CSSDFarm.UserInterface.java
private void btnAddFieldStationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddFieldStationActionPerformed JTextField id = new JTextField(); JTextField name = new JTextField(); //Space is needed to expand dialog JLabel verified = new JLabel(" "); JButton okButton = new JButton("Ok"); JButton cancelButton = new JButton("Cancel"); okButton.setEnabled(false);// ww w. j a v a 2 s .c om okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { String idText = id.getText(); String nameText = name.getText(); addFieldStation(id.getText(), name.getText()); JOptionPane.getRootFrame().dispose(); listUserStations.setSelectedValue(server.getFieldStation(idText), false); } }); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { JOptionPane.getRootFrame().dispose(); } }); id.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent key) { boolean theid = id.getText().equals(""); boolean thename = name.getText().equals(""); if (server.verifyFieldStation(id.getText()) && !theid && !thename) { verified.setText(" Verified"); verified.setForeground(new Color(0, 102, 0)); okButton.setEnabled(true); } else { verified.setText(" Not Verified"); verified.setForeground(Color.RED); okButton.setEnabled(false); } } }); name.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent key) { boolean theid = id.getText().equals(""); boolean thename = name.getText().equals(""); if (server.verifyFieldStation(id.getText()) && !theid && !thename) { verified.setText(" Verified"); verified.setForeground(new Color(0, 102, 0)); okButton.setEnabled(true); } else { verified.setText(" Not Verified"); verified.setForeground(Color.RED); okButton.setEnabled(false); } } }); Object[] message = { "Field Station ID:", id, "Field Station Name:", name, verified }; int inputFields = JOptionPane.showOptionDialog(null, message, "Add Field Station", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { okButton, cancelButton }, null); if (inputFields == JOptionPane.OK_OPTION) { System.out.print("Added Field Station!"); } }
From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java
private void btnMachineDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMachineDeleteActionPerformed // TODO add your handling code here: int result = JOptionPane.showConfirmDialog(this, "Are you sure to delete this item", "Warning", JOptionPane.OK_CANCEL_OPTION); if (result == 0) { Machine currentMachine = ((ComboBoxItem<Machine>) this.cbMachine.getSelectedItem()).getItem(); if ("- Select -".equals(currentMachine.getMachineNo())) { return; }/*www. j av a2 s . c o m*/ this.machineService.DeleteEntity(currentMachine.getId()); this.UpdateTabMachine(0); } }
From source file:interfaces.InterfazPrincipal.java
private void botonGuardarFacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarFacturaActionPerformed // TODO add your handling code here: String id_cliente = jTextField_Factura_Cliente_Id.getText(); if (id_cliente.equals("") || valorActualFactura.equals("0.0")) { JOptionPane.showMessageDialog(this, "Por favor indique el monto de la factura o ingrese los productos a ella"); } else {// w w w. j a va 2 s. co m //System.err.println("Numero de filas" + TablaDeFacturaProducto.getRowCount()); ArrayList<String> lineaCodigoProductos = new ArrayList<String>(); ArrayList<String> lineaUnidadesProductos = new ArrayList<String>(); ArrayList<String> lineaMontoProductos = new ArrayList<String>(); double monto = 0d; try { double pago = Double.parseDouble( (String) JOptionPane.showInputDialog("Ingrese por favor el monto pagado por el cliente")); while (pago < 0.0) { pago = Double.parseDouble((String) JOptionPane.showInputDialog( "El pago debe ser positivo \nIngrese por favor el monto pagado por el cliente")); } double prestamo = Double.parseDouble(valorActualPrestamo.getText()); double montoFactura = Double.parseDouble(valorActualFactura.getText()); while (montoFactura - pago < 0.0) { pago = Double.parseDouble((String) JOptionPane.showInputDialog( "El pago no debe ser superior al monto de la factura \nIngrese por favor el monto pagado por el cliente")); } if (prestamo - montoFactura <= 0.0) { int opcion = JOptionPane.showConfirmDialog(this, "Con este prstamo el cliente excede su limite de prestamos. \n Desea continuar?", "Mensaje del sistema", JOptionPane.YES_NO_OPTION); if (opcion != JOptionPane.YES_OPTION) { return; } } for (int i = 0; i < TablaDeFacturaProducto.getRowCount(); i++) { /* * Fila 0: ID producto * Fila 4: Cantidad */ String ProductoId = String.valueOf(TablaDeFacturaProducto.getValueAt(i, 0)); lineaCodigoProductos.add(ProductoId); int numeroUnidades = Integer.parseInt(String.valueOf(TablaDeFacturaProducto.getValueAt(i, 4))); String unidades = String.valueOf(numeroUnidades); lineaUnidadesProductos.add(unidades); double valorUnitario = Double .parseDouble(String.valueOf(TablaDeFacturaProducto.getValueAt(i, 5))); double valorProductoTotal = numeroUnidades * valorUnitario; lineaMontoProductos.add(String.valueOf(valorProductoTotal)); monto += valorProductoTotal; } if (TablaDeFacturaProducto.getRowCount() == 0) { monto = Double.parseDouble(valorActualFactura.getText()); } String estado = ""; if (monto == pago) { estado = "pagado"; } else { estado = "fiado"; } ControladorFactura controladorFactura = new ControladorFactura(); //String[] selection = {"cliente_id", "fecha", "estado", "identificacionCliente"}; Calendar calendario = Calendar.getInstance(); String dia = Integer.toString(calendario.get(Calendar.DATE)); String mes = Integer.toString(calendario.get(Calendar.MONTH)) + 1; String annio = Integer.toString(calendario.get(Calendar.YEAR)); Date date = new Date(); DateFormat hourFormat = new SimpleDateFormat("HH:mm:ss"); String hora = hourFormat.format(date); String fecha = annio + "-" + mes + "-" + dia + " " + hora; String[] selection = { id_cliente, fecha, estado, String.valueOf(monto) }; ArrayList<String[]> facturaActual = controladorFactura.insertFactura(selection); //Ingresar productos if (TablaDeFacturaProducto.getRowCount() > 0) { ControladorFactura_Productos controladorFactura_Productos = new ControladorFactura_Productos(); for (int i = 0; i < lineaCodigoProductos.size(); i++) { // String [] selection = {"factura_id","producto_id","unidades","precio"}; String[] insertarLineaProducto = { facturaActual.get(0)[0], lineaCodigoProductos.get(i), lineaUnidadesProductos.get(i), lineaMontoProductos.get(i) }; controladorFactura_Productos.insertFactura_Productos(insertarLineaProducto); } } //Ingresar flujo factura ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); // String [] selection = {"factura_id","tipo_flujo","fecha","identificacionCliente"}; String value[] = { facturaActual.get(0)[0], "abono", fecha, String.valueOf(pago) }; controladorFlujoFactura.insertFlujo_Factura(value); String value2[] = { facturaActual.get(0)[0], "deuda", fecha, String.valueOf(monto) }; controladorFlujoFactura.insertFlujo_Factura(value2); botonEstablecerMontoFactura.setEnabled(false); botonAgregarProducto.setEnabled(false); botonGuardarFactura.setEnabled(false); jTextField_Factura_Cliente_Id.setText(""); DefaultTableModel modeloTabla = (DefaultTableModel) TablaDeFacturaProducto.getModel(); for (int i = 0; i < modeloTabla.getRowCount(); i++) { modeloTabla.removeRow(i); } modeloTabla.setRowCount(0); TablaDeFacturaProducto.setModel(modeloTabla); Object opciones[] = { "Cerrar", "Imprimir", "Guardar en disco" }; GenerarFactura generarFactura = new GenerarFactura(); int opcion = JOptionPane.showOptionDialog(this, "Se ha guardado la factura con xito\nQue desea hacer?", "Elija una opcin", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opciones, null); switch (opcion) { case 1: generarFactura.imprimirFactura(Integer.parseInt(facturaActual.get(0)[0]), this); break; case 2: PDDocument documento = generarFactura.crearFactura(Integer.parseInt(facturaActual.get(0)[0]), this); JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivo PDF", "pdf", "text"); fc.setFileFilter(filter); fc.showSaveDialog(this); if (fc.getSelectedFile() != null) { File selectedFile = fc.getSelectedFile(); try { documento.save(selectedFile + ".pdf"); JOptionPane.showMessageDialog(this, "El archivo ha sido guardado en disco"); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "EL Archivo no se puede leer!"); } } break; default: break; } nombreClienteCrearFactura.setText(""); IdentificacionClienteBuscarFactura.setText(""); valorActualPrestamo.setText(""); jTextField_Factura_Cliente_Id.setText(""); jTextField_Factura_Producto_Nombre.setText(""); jTextField_Factura_Producto_Descripcion.setText(""); valorMontoFactura.setText(""); valorActualFactura.setText("0.0"); valorActualPrestamo.setText("0.0"); botonGuardarFactura.setEnabled(false); botonEstablecerMontoFactura.setEnabled(false); botonAgregarProducto.setEnabled(false); } catch (Exception e) { } } }
From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java
private void btnPolymerDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPolymerDeleteActionPerformed int result = JOptionPane.showConfirmDialog(this, "Are you sure to delete this item", "Warning", JOptionPane.OK_CANCEL_OPTION); if (result == 0) { Polymer currentPolymer = ((ComboBoxItem<Polymer>) this.cbPolymer.getSelectedItem()).getItem(); if ("- Select -".equals(currentPolymer.getCompany())) { return; }/*from w ww . j av a 2 s . c o m*/ this.polymerService.DeleteEntity(currentPolymer.getId()); this.UpdateTabPolymer(0); } }
From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java
private void btnAdditiveDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdditiveDeleteActionPerformed int result = JOptionPane.showConfirmDialog(this, "Are you sure to delete this item", "Warning", JOptionPane.OK_CANCEL_OPTION); if (result == 0) { Additive currentAdditive = ((ComboBoxItem<Additive>) this.cbAdditive.getSelectedItem()).getItem(); if ("- Select -".equals(currentAdditive.getCompany())) { return; }/* w w w . j ava 2 s .c o m*/ this.additiveService.DeleteEntity(currentAdditive.getId()); this.UpdateTabAdditive(0); } }
From source file:com.cch.aj.entryrecorder.frame.SettingsJFrame.java
private void btnMouldDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMouldDeleteActionPerformed int result = JOptionPane.showConfirmDialog(this, "Are you sure to delete this item", "Warning", JOptionPane.OK_CANCEL_OPTION); if (result == 0) { Mould currentMould = ((ComboBoxItem<Mould>) this.cbMould.getSelectedItem()).getItem(); if ("- Select -".equals(currentMould.getCode())) { return; }/*from w w w .java 2 s . c o m*/ this.mouldService.DeleteEntity(currentMould.getId()); this.UpdateTabMould(0); } }