package br.uff.ic.gems.peixeespadacliente.gui; import br.uff.ic.gems.peixeespadacliente.model.agent.LocalManagerAgent; import br.uff.ic.oceano.core.exception.ServiceException; import br.uff.ic.gems.peixeespadacliente.service.ClientService; import br.uff.ic.oceano.peixeespada.model.Agent; import java.beans.PropertyVetoException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import javax.swing.JOptionPane; /** * * @author Heliomar */ public class JScheduling extends javax.swing.JInternalFrame { private ClientService clientServer = new ClientService(); /** Creates new form Scheduling */ public JScheduling() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); dateInit = new javax.swing.JFormattedTextField(); dateEnd = new javax.swing.JFormattedTextField(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); passUserOcean = new javax.swing.JPasswordField(); txtUserOcean = new javax.swing.JTextField(); jSeparator1 = new javax.swing.JSeparator(); jPanel2 = new javax.swing.JPanel(); btnScheduling = new javax.swing.JButton(); btnCancel = new javax.swing.JButton(); setClosable(true); setTitle("Scheduling the idle time"); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Scheduling Information")); jLabel1.setText("Choose the initial time"); jLabel2.setText("Choose the final time"); dateInit.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm")))); dateInit.setValue(new Date(System.currentTimeMillis()+90000)); dateEnd.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm")))); dateEnd.setValue(new Date(System.currentTimeMillis()+43200000+90000)); jLabel3.setText("Oceano's login"); jLabel4.setText("Oceano's password"); passUserOcean.setText("kannkann"); txtUserOcean.setText("kann"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jLabel1) .addComponent(jLabel4)) .addGap(18, 18, 18) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(passUserOcean, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE) .addComponent(txtUserOcean, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE) .addComponent(dateEnd, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE) .addComponent(dateInit, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)))) .addContainerGap()) .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(dateInit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(dateEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(5, 5, 5) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(txtUserOcean, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(passUserOcean, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel4)))) ); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Actions")); btnScheduling.setText("Schedule"); btnScheduling.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSchedulingActionPerformed(evt); } }); btnCancel.setText("Cancel"); btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCancelActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(btnScheduling) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE) .addComponent(btnCancel) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnScheduling) .addComponent(btnCancel)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void btnSchedulingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSchedulingActionPerformed // TODO add your handling code here: SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm"); boolean error = false; Date localDateInitial = null; Date localDateEnd = null; try { localDateInitial = sdf.parse(dateInit.getText()); } catch (ParseException ex) { JOptionPane.showMessageDialog(this, "["+dateInit.getText() +"] is inválid\nFormat: dd/MM/yyyy HH:mm\nex. 23/12/2010 18:40", "Invalid initial date", JOptionPane.ERROR_MESSAGE); error = true; } try { localDateEnd = sdf.parse(dateEnd.getText()); } catch (ParseException ex) { JOptionPane.showMessageDialog(this, "["+dateEnd.getText() +"] is inválid\nFormat: dd/MM/yyyy HH:mm\nex. 23/12/2010 18:40", "Invalid end date", JOptionPane.ERROR_MESSAGE); error = true; } if(!error){ try { // scheduling // clientServer.validateSchedulingRequest(localDateInitial, localDateEnd); LocalManagerAgent agentPeixeEspada = LocalManagerAgent.create(localDateInitial, localDateEnd, txtUserOcean.getText(), new String(passUserOcean.getPassword())); List<Agent> orchestratorAgents = clientServer.getOrchestratorAgents(agentPeixeEspada); addChooseAgentToDesktop(new JChooseOrchestratorAgent(orchestratorAgents, this, agentPeixeEspada)); } catch (ServiceException ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Validation error", JOptionPane.ERROR_MESSAGE); } } }//GEN-LAST:event_btnSchedulingActionPerformed private void addChooseAgentToDesktop(JChooseOrchestratorAgent chooseOrchestratorAgents){ chooseOrchestratorAgents.setVisible(true); java.awt.Dimension screenSize = this.getParent().getSize(); int widthInternal = chooseOrchestratorAgents.getSize().width; int heightInternal = chooseOrchestratorAgents.getSize().height; chooseOrchestratorAgents.setBounds((screenSize.width - widthInternal) / 2, (screenSize.height - heightInternal) / 2, widthInternal, heightInternal); this.getParent().add(chooseOrchestratorAgents); try { chooseOrchestratorAgents.setSelected(true); } catch (PropertyVetoException ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed // TODO add your handling code here: dispose(); }//GEN-LAST:event_btnCancelActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCancel; private javax.swing.JButton btnScheduling; private javax.swing.JFormattedTextField dateEnd; private javax.swing.JFormattedTextField dateInit; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JSeparator jSeparator1; private javax.swing.JPasswordField passUserOcean; private javax.swing.JTextField txtUserOcean; // End of variables declaration//GEN-END:variables }