package ctrend;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class ClusterForm extends javax.swing.JFrame {
FlowLayout layout=new FlowLayout();
DataSet ds;
ArrayList<String>coldata;
ClusterBean cbean;
public ClusterForm() {
initComponents();
ds=new DataSet();
coldata=ds.loadFields();
cmbColNames.removeAllItems();
for(int i=0;i<coldata.size();i++)
cmbColNames.addItem(coldata.get(i).toUpperCase());
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
cmbColNames = new javax.swing.JComboBox();
butSubmit = new javax.swing.JButton();
butShowTimePeriods = new javax.swing.JButton();
butShowGraph = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel1.setText("Select Time Related Field");
butSubmit.setText("Submit");
butSubmit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
butSubmitActionPerformed(evt);
}
});
butShowTimePeriods.setText("Show Time Periods");
butShowTimePeriods.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
butShowTimePeriodsActionPerformed(evt);
}
});
butShowGraph.setText("Show Graph");
butShowGraph.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
butShowGraphActionPerformed(evt);
}
});
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)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addContainerGap(745, Short.MAX_VALUE))
.addComponent(butSubmit)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(cmbColNames, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(762, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(butShowTimePeriods)
.addContainerGap(766, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(butShowGraph)
.addContainerGap(796, Short.MAX_VALUE))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbColNames, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(8, 8, 8)
.addComponent(butSubmit)
.addGap(15, 15, 15)
.addComponent(butShowTimePeriods)
.addGap(17, 17, 17)
.addComponent(butShowGraph)
.addContainerGap(70, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, 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()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(278, Short.MAX_VALUE))
);
pack();
}
private void butShowGraphActionPerformed(java.awt.event.ActionEvent evt) {
buildGraph();
GraphPanel.tp=cbean.tp;
System.out.println("TP SIZE:"+cbean.tp.size());
JFrame frm=new JFrame();
frm.setTitle("C-TREND Temporal Graph Model");
frm.setBackground(Color.black);
GraphPanel gp=new GraphPanel();
frm.add(gp);
frm.setSize(800,600);
frm.setVisible(true);
frm.setDefaultCloseOperation(frm.DISPOSE_ON_CLOSE);
}
private void butShowTimePeriodsActionPerformed(java.awt.event.ActionEvent evt) {
for(int i=0;i<cbean.tp.size();i++)
{
TimePeriod curtp=cbean.tp.get(i);
curtp.findMedioids();
curtp.showMedioids();
}
}
public void buildGraph()
{
int row,col;
col=100;
for(int i=0;i<cbean.tp.size();i++)
{
TimePeriod curtp=cbean.tp.get(i);
row=50;
for(int j=0;j<curtp.centroids.size();j++,row+=100)
{
DataObject curcentroid=curtp.centroids.get(j);
curcentroid.xc=col;
curcentroid.yc=row;
System.out.println(curcentroid.xc+","+curcentroid.yc);
}
col+=400;
}
}
private void butSubmitActionPerformed(java.awt.event.ActionEvent evt) {
try
{
DataSet ds=new DataSet();
int colidx=cmbColNames.getSelectedIndex();
System.out.println("Selected Idx:"+colidx);
ds.buildTables();
cbean=new ClusterBean();
cbean.buildClusters(colidx);
}catch(Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null,e.toString());
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ClusterForm().setVisible(true);
}
});
}
private javax.swing.JButton butShowGraph;
private javax.swing.JButton butShowTimePeriods;
private javax.swing.JButton butSubmit;
private javax.swing.JComboBox cmbColNames;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
}