/* * Demoiselle Framework * Copyright (C) 2013 SERPRO * ---------------------------------------------------------------------------- * This file is part of Demoiselle Framework. * * Demoiselle Framework is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License version 3 * along with this program; if not, see <http://www.gnu.org/licenses/> * or write to the Free Software Foundation, Inc., 51 Franklin Street, * Fifth Floor, Boston, MA 02110-1301, USA. * ---------------------------------------------------------------------------- * Este arquivo é parte do Framework Demoiselle. * * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação * do Software Livre (FSF). * * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português * para maiores detalhes. * * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> * ou escreva para a Fundação do Software Livre (FSF) Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. */ package demoisellebehave.serpro.treino.ui; import demoisellebehave.serpro.treino.dao.Obra; import demoisellebehave.serpro.treino.dao.ObraDAO; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JOptionPane; /** * * @author SUPST */ public class JFrameLance extends javax.swing.JFrame { private static final long serialVersionUID = 1L; private DecimalFormat formatDecimal = new DecimalFormat("###.0"); private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); private static JFrameLance instance = new JFrameLance(); private Obra obra; private JFrameLance() { initComponents(); UICommons.centraliza(this); } public static JFrameLance getInstance() { return instance; } // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); lbNomeObra = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); lbVencedor = new javax.swing.JLabel(); txtNovoValor = new javax.swing.JTextField(); txtNovoPrazo = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); btEnviarLance = new javax.swing.JButton(); btCancelar = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Enviar Lance"); jLabel1.setText("Obra:"); lbNomeObra.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N lbNomeObra.setText("[Nome da Obra]"); jLabel3.setText("Atual Vencedor:"); lbVencedor.setFont(new java.awt.Font("DejaVu Sans", 1, 13)); // NOI18N lbVencedor.setText("[Atual Vencedor]"); jLabel5.setText("Novo Valor:"); jLabel6.setText("Novo Prazo:"); btEnviarLance.setText("Enviar Lance"); btEnviarLance.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btEnviarLanceActionPerformed(evt); } }); btCancelar.setText("Cancelar"); btCancelar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btCancelarActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(btEnviarLance, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent(jLabel5) .addComponent(jLabel6) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lbNomeObra) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(lbVencedor) .addComponent(txtNovoValor, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE) .addComponent(txtNovoPrazo))))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(lbNomeObra)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(lbVencedor)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtNovoValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtNovoPrazo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btEnviarLance) .addComponent(btCancelar)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed this.setVisible(false); }//GEN-LAST:event_btCancelarActionPerformed private void btEnviarLanceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEnviarLanceActionPerformed try { Double novoValor = formatDecimal.parse(txtNovoValor.getText()).doubleValue(); if (novoValor.compareTo(this.obra.getValor()) >= 0) { JOptionPane.showMessageDialog(this, "Proposta recusada. Motivo: Valor não aceito!", "Erro", JOptionPane.ERROR_MESSAGE); return; } Date novoPrazo = dateFormat.parse(txtNovoPrazo.getText()); if (novoPrazo.compareTo(this.obra.getPrazo()) >= 0) { JOptionPane.showMessageDialog(this, "Proposta recusada. Motivo: Prazo não aceito!", "Erro", JOptionPane.ERROR_MESSAGE); return; } obra.setPrazo(novoPrazo); obra.setValor(novoValor); obra.setVencedor(JFrameLogin.getUser().getLogin()); (new ObraDAO()).merge(obra); JOptionPane.showMessageDialog(this, "Proposta Aceita!!!", "Confirmação", JOptionPane.INFORMATION_MESSAGE); JFrameListaObras.getInstance().atualizarLista(); this.setVisible(false); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_btEnviarLanceActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(JFrameLance.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(JFrameLance.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(JFrameLance.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(JFrameLance.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new JFrameLance().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btCancelar; private javax.swing.JButton btEnviarLance; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel lbNomeObra; private javax.swing.JLabel lbVencedor; private javax.swing.JTextField txtNovoPrazo; private javax.swing.JTextField txtNovoValor; // End of variables declaration//GEN-END:variables void setObra(Obra obra) { this.obra = obra; this.lbNomeObra.setText(obra.getNome()); this.lbVencedor.setText(obra.getVencedor()); this.txtNovoPrazo.setText(dateFormat.format(obra.getPrazo())); this.txtNovoValor.setText(formatDecimal.format(obra.getValor())); } }