Package com.oracle.demo.ops.shipment.notifier

Source Code of com.oracle.demo.ops.shipment.notifier.QueryResultFrame

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* QueryResultFrame.java
*
* Created on 16-Aug-2011, 12:48:56
*/
package com.oracle.demo.ops.shipment.notifier;

import com.oracle.demo.ops.domain.Shipment;
import com.tangosol.net.NamedCache;
import com.tangosol.util.Filter;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* @author cmlee
*/
public class QueryResultFrame extends javax.swing.JFrame implements ActionListener, Runnable
{

  private final Filter filter;
  private final boolean continious;
  private final NamedCache cache;

  /**
   * Creates new form QueryResultFrame
   */
  public QueryResultFrame(NamedCache c, Filter f, boolean cont)
  {
    String icon;
    initComponents();
    filter = f;
    continious = cont;
    cache = c;
    closeButton.addActionListener(this);
    query.setText(f.toString());
    if(cont)
    {
      try
      {
        queryType.setIcon(new ImageIcon(Utility.load(Constants.LINK)));
        queryType.setToolTipText("Continious query");
      }
      catch(IOException ex)
      {
        Logger.getLogger(QueryResultFrame.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }

  @Override
  public void setVisible(boolean b)
  {
    super.setVisible(b);
    if(b)
    {
      new Thread(this).start();
    }
  }

  @Override
  public void actionPerformed(ActionEvent e)
  {
    setVisible(false);
    dispose();
  }

  @Override
  public void run()
  {
    Set result = cache.entrySet(filter);
    countLabel.setText("Count: "+result.size());
    for(Object obj : result)
    {
      Map.Entry entry = (Map.Entry) obj;
      Shipment s = (Shipment) entry.getValue();
      resultArea.append(String.format("External refid: %1$10s, Parcels: %2$03d, Shipping: %3$s"
          , s.getExternalReferenceId(), s.getParcels().size(), s.getShippingServiceName()));
      resultArea.append("\n");
    }
  }

  /**
   * 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();
    queryType = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    resultArea = new javax.swing.JTextArea();
    closeButton = new javax.swing.JButton();
    countLabel = new javax.swing.JLabel();
    query = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Query Result");

    queryType.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/oracle/demo/ops/shipment/notifier/link_break.png"))); // NOI18N
    queryType.setText(" ");
    queryType.setToolTipText("Non continious query");

    resultArea.setColumns(20);
    resultArea.setEditable(false);
    resultArea.setRows(5);
    jScrollPane1.setViewportView(resultArea);

    closeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/oracle/demo/ops/shipment/notifier/cross.png"))); // NOI18N
    closeButton.setText("Close");

    countLabel.setText("Count:");

    query.setEditable(false);

    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(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 626, Short.MAX_VALUE)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addComponent(query, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(queryType, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(countLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 517, Short.MAX_VALUE)
                .addComponent(closeButton)))
            .addContainerGap())
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(queryType)
                .addComponent(query, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(closeButton)
                .addComponent(countLabel))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    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)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 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(QueryResultFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    catch(InstantiationException ex)
    {
      java.util.logging.Logger.getLogger(QueryResultFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    catch(IllegalAccessException ex)
    {
      java.util.logging.Logger.getLogger(QueryResultFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    catch(javax.swing.UnsupportedLookAndFeelException ex)
    {
      java.util.logging.Logger.getLogger(QueryResultFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton closeButton;
  private javax.swing.JLabel countLabel;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JTextField query;
  private javax.swing.JLabel queryType;
  private javax.swing.JTextArea resultArea;
  // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of com.oracle.demo.ops.shipment.notifier.QueryResultFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.