/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* LoaderFrame.java
*
* Created on 16-Aug-2011, 09:48:24
*/
package com.oracle.demo.ops.shipment.notifier;
import com.oracle.demo.ops.domain.Shipment;
import com.tangosol.net.NamedCache;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
/**
* @author cmlee
*/
public class LoaderFrame
extends javax.swing.JFrame
implements ActionListener,
Runnable
{
/**
* Creates new form LoaderFrame
*/
public LoaderFrame()
{
initComponents();
cancelButton.addActionListener(this);
okayButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == okayButton)
{
SwingUtilities.invokeLater(this);
return;
}
setVisible(false);
dispose();
}
@Override
public void run()
{
final int max = (Integer) shipmentSize.getValue();
final Map<Integer, Shipment> shipments = new HashMap<Integer, Shipment>();
shipmentProgress.setMinimum(1);
shipmentProgress.setMaximum(max);
shipmentProgress.setValue(0);
shipmentProgress.setStringPainted(true);
for(int i = 0; i<max; i++)
{
shipmentProgress.setString(String.format("Generating %1$d of %2$d ...", i, max));
shipmentProgress.setValue(i);
Shipment s = Utility.randomShipment();
shipments.put(s.getId(), s);
}
shipmentProgress.setIndeterminate(true);
shipmentProgress.setString("Populating caches...");
//This is not strictly correct because we should be using JPA to populate the caches
//TODO later
NamedCache cache = Utility.getCache(Constants.SHIPMENT_CACHE);
cache.putAll(shipments);
//
JOptionPane.showMessageDialog(this, "Done! Generated and loaded "+max+" Shipment(s)");
setVisible(false);
dispose();
}
/**
* 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();
shipmentSize = new javax.swing.JSpinner();
shipmentProgress = new javax.swing.JProgressBar();
okayButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Shipment Loader");
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jLabel1.setText("Number of Shipment to load:");
shipmentSize.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), null, null, Integer.valueOf(1)));
shipmentProgress.setToolTipText("Progress");
shipmentProgress.setStringPainted(true);
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(shipmentProgress, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(shipmentSize, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(shipmentSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(shipmentProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(21, Short.MAX_VALUE))
);
//modified by jeff
URL imageResource = getClass().getResource("/com/oracle/demo/ops/shipment/notifier/tick.png");
ImageIcon icon = new javax.swing.ImageIcon(imageResource);
okayButton.setIcon(icon); // NOI18N
okayButton.setText("Okay");
cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/oracle/demo/ops/shipment/notifier/cross.png"))); // NOI18N
cancelButton.setText("Cancel");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(232, Short.MAX_VALUE)
.addComponent(cancelButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(okayButton)
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]{cancelButton, okayButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(okayButton)
.addComponent(cancelButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @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(LoaderFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch(InstantiationException ex)
{
java.util.logging.Logger.getLogger(LoaderFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch(IllegalAccessException ex)
{
java.util.logging.Logger.getLogger(LoaderFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch(javax.swing.UnsupportedLookAndFeelException ex)
{
java.util.logging.Logger.getLogger(LoaderFrame.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 LoaderFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton okayButton;
private javax.swing.JProgressBar shipmentProgress;
private javax.swing.JSpinner shipmentSize;
// End of variables declaration//GEN-END:variables
}