Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package views; import Authentication.LogOut; import java.awt.Rectangle; import java.util.ArrayList; import java.util.Date; import javax.swing.table.DefaultTableModel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.Dataset; import org.jfree.data.general.DefaultPieDataset; import projectBuilder.Project; import projectManagementSystem.ProjectManagementGlobalSession; import projectState.ProjectStatus; import projectState.State; import userActions.ClientActions; /** * * @author Daryl */ public class Client_Home extends javax.swing.JPanel { /** * Creates new form Client_Home */ ClientActions clientActions; DefaultTableModel model; public Client_Home() { initComponents(); this.clientActions = new ClientActions(); populateProjects(); // drawCharts(); } /** * 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() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); homeButton = new javax.swing.JButton(); logoutButton = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); projectListTable = new javax.swing.JTable(); jLabel3 = new javax.swing.JLabel(); setBackground(new java.awt.Color(255, 255, 255)); setPreferredSize(new java.awt.Dimension(900, 600)); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/flpm_2.PNG"))); // NOI18N jLabel2.setText("User : Client on database: FLPM"); homeButton.setText("Home"); homeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { homeButtonActionPerformed(evt); } }); logoutButton.setText("Log Out"); logoutButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logoutButtonActionPerformed(evt); } }); projectListTable.setAutoCreateRowSorter(true); projectListTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Project Id", "Project Name", "Project Status", "Faculty Id" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class }; boolean[] canEdit = new boolean[] { false, false, false, false }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); projectListTable.setShowHorizontalLines(false); projectListTable.setShowVerticalLines(false); jScrollPane1.setViewportView(projectListTable); jLabel3.setText("Please contact the faculty for more details. "); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane1) .addGroup(layout.createSequentialGroup() .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 454, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(27, 27, 27) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(homeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(31, 31, 31) .addComponent(logoutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(16, 16, 16))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(homeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(logoutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(18, 18, 18) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(42, 42, 42) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE) .addContainerGap(243, Short.MAX_VALUE))); }// </editor-fold>//GEN-END:initComponents private void logoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutButtonActionPerformed LogOut logout = new LogOut(); logout.logOut(); }//GEN-LAST:event_logoutButtonActionPerformed private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_homeButtonActionPerformed ProjectManagementGlobalSession.centralPanel.removeAll(); ProjectManagementGlobalSession.centralPanel.add(new Client_Home()); ProjectManagementGlobalSession.centralPanel.updateUI(); }//GEN-LAST:event_homeButtonActionPerformed private void populateProjects() { ArrayList projectsList = this.clientActions.fetchProject(); model = (DefaultTableModel) projectListTable.getModel(); ProjectStatus projectStatus = new ProjectStatus(); Date date = new Date(); Project project = null; for (int i = 0; i < projectsList.size(); i++) { project = (Project) projectsList.get(i); State state = projectStatus.findProjectStatus(project); String[] str = { project.getProjectId(), project.getProjectName(), state.printState(), project.getFacultyId() }; model.insertRow(model.getRowCount(), str); } } /*private void drawCharts(){ ArrayList projectsList = this.clientActions.fetchProject(); Date date = new Date(); for(int i=0;i<projectsList.size();i++){ Project project = (Project) projectsList.get(i); if(date.before(project.getEndDate()) && date.after(project.getStartDate())){ DefaultPieDataset dataset = new DefaultPieDataset(); int comp = date.getDate()-project.getStartDate().getDate(); dataset.setValue("Completed",comp); int pending = project.getEndDate().getDate()-date.getDate(); dataset.setValue("Pending",pending); JFreeChart projectStatusChart = ChartFactory.createPieChart(project.getProjectName(), dataset,true,true,true); PiePlot piePlot = (PiePlot)projectStatusChart.getPlot(); ChartPanel chartPanel = new ChartPanel(projectStatusChart); Rectangle rectangle = new Rectangle(300, 300); chartPanel.setBounds(rectangle); chartPanel.setSize(250,250); chartPanel.setVisible(true); int c = 0; while(c<10){ c+=1; projectPieChartsPanel.add(chartPanel); } projectPieChartsPanel.updateUI(); } } }*/ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton homeButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JButton logoutButton; private javax.swing.JTable projectListTable; // End of variables declaration//GEN-END:variables }