Java tutorial
import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Font; import com.itextpdf.text.Font.FontFamily; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import java.awt.Desktop; import java.awt.Image; import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.rmi.RemoteException; import java.sql.Blob; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFileChooser; import javax.swing.table.DefaultTableModel; /* * 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. */ /** * * @author Kenneth */ public final class ILogbook extends javax.swing.JFrame { /** * Creates new form ILogbook */ private String dateChooserDate; private int row = -1; private int column = -1; private javax.swing.JTable source = null; private boolean mouseClick = false; protected TimerThread timerThread; protected UpdaterClass updaterClass; private NPRInterface client; private AdminImpl adminImpl; private Blob blob; private String user; private DefaultTableModel tableModel; private boolean isUpdateFromDateChooser = false; public ILogbook(NPRInterface client, String user) { initComponents(); this.client = client; this.user = user; logsTable.getTableHeader().setReorderingAllowed(Boolean.FALSE); profilePicPopup.add(adminList); profilePicPopup.add(editProfile); profilePicPopup.add(changePassword); profilePicPopup.add(logout); jPopupMenu1.add(sendMessage); jPopupMenu1.add(sendEMail); UserAdmin(); updaterMethod(); dateChooserDate = dateCombo.getText(); updaterClass = new UpdaterClass(updater); updaterClass.start(); timerThread = new TimerThread(time, date, day); timerThread.start(); } /** * 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() { chooser = new javax.swing.JFileChooser(); updater = new javax.swing.JTextField(); searchByButtons = new javax.swing.ButtonGroup(); jPopupMenu1 = new javax.swing.JPopupMenu(); sendMessage = new javax.swing.JMenuItem(); sendEMail = new javax.swing.JMenuItem(); profilePicPopup = new javax.swing.JPopupMenu(); editProfile = new javax.swing.JMenuItem(); changePassword = new javax.swing.JMenuItem(); logout = new javax.swing.JMenuItem(); adminList = new javax.swing.JMenuItem(); jLayeredPane1 = new javax.swing.JLayeredPane(); date = new javax.swing.JLabel(); day = new javax.swing.JLabel(); time = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); welcome = new javax.swing.JLabel(); profilePic = new javax.swing.JLabel(); home = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); dateCombo = new datechooser.beans.DateChooserCombo(); searchField = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); logsTable = new javax.swing.JTable(); jLabel6 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); chooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG); chooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY); updater.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { updaterCaretUpdate(evt); } }); sendMessage.setText("Send Text Message"); sendMessage.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sendMessageActionPerformed(evt); } }); sendEMail.setText("Send Email"); sendEMail.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sendEMailActionPerformed(evt); } }); editProfile.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N editProfile.setText("Edit Profile"); editProfile.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); editProfile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { editProfileActionPerformed(evt); } }); changePassword.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N changePassword.setText("Change Password"); changePassword.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); changePassword.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { changePasswordActionPerformed(evt); } }); logout.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N logout.setText("Logout"); logout.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); logout.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logoutActionPerformed(evt); } }); adminList.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N adminList.setText("List of Admins"); adminList.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); adminList.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { adminListActionPerformed(evt); } }); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("iLogbook"); setIconImage(new ImageIcon(getClass().getResource("icons/181NPR.png")).getImage()); setUndecorated(true); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); jLayeredPane1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); date.setFont(new java.awt.Font("Rondalo", 1, 18)); // NOI18N date.setForeground(new java.awt.Color(255, 255, 255)); date.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); date.setText("Jan 01, 2001"); jLayeredPane1.add(date, new org.netbeans.lib.awtextra.AbsoluteConstraints(760, 60, 180, -1)); day.setFont(new java.awt.Font("Rondalo", 1, 18)); // NOI18N day.setForeground(new java.awt.Color(255, 255, 255)); day.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); day.setText("Monday"); jLayeredPane1.add(day, new org.netbeans.lib.awtextra.AbsoluteConstraints(760, 80, 180, -1)); time.setFont(new java.awt.Font("Rondalo", 1, 24)); // NOI18N time.setForeground(new java.awt.Color(255, 255, 255)); time.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); time.setText("12:00 AM"); jLayeredPane1.add(time, new org.netbeans.lib.awtextra.AbsoluteConstraints(760, 100, 180, -1)); jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/ilogbook.png"))); // NOI18N jLayeredPane1.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 10, 360, -1)); welcome.setFont(new java.awt.Font("Rondalo", 1, 14)); // NOI18N welcome.setText("Welcome Admin (Name)!"); jLayeredPane1.add(welcome, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 10, -1, -1)); profilePic.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); profilePic.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); profilePic.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { profilePicMouseClicked(evt); } }); jLayeredPane1.add(profilePic, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 50, 50)); home.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); home.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Back.png"))); // NOI18N home.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); home.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { homeMouseClicked(evt); } }); jLayeredPane1.add(home, new org.netbeans.lib.awtextra.AbsoluteConstraints(900, 10, 40, -1)); jPanel1.setBackground(new java.awt.Color(255, 255, 255)); jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); dateCombo.setCurrentView(new datechooser.view.appearance.AppearancesList("Light", new datechooser.view.appearance.ViewAppearance("custom", new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), true, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 255), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(128, 128, 128), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(255, 0, 0), false, false, new datechooser.view.appearance.swing.ButtonPainter()), (datechooser.view.BackRenderer) null, false, true))); dateCombo.setNothingAllowed(false); dateCombo.setFormat(2); dateCombo.setFieldFont(new java.awt.Font("Rondalo", java.awt.Font.PLAIN, 12)); dateCombo.setBehavior(datechooser.model.multiple.MultyModelBehavior.SELECT_SINGLE); dateCombo.addCommitListener(new datechooser.events.CommitListener() { public void onCommit(datechooser.events.CommitEvent evt) { dateComboOnCommit(evt); } }); searchField.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N searchField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { searchFieldCaretUpdate(evt); } }); jLabel5.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N jLabel5.setText("Search"); logsTable.setAutoCreateRowSorter(true); logsTable.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N logsTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "ID", "NAME", "TIME", "STATUS" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.String.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]; } }); logsTable.setComponentPopupMenu(jPopupMenu1); logsTable.setRowSelectionAllowed(false); logsTable.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { logsTableMouseClicked(evt); } public void mousePressed(java.awt.event.MouseEvent evt) { logsTableMousePressed(evt); } public void mouseReleased(java.awt.event.MouseEvent evt) { logsTableMouseReleased(evt); } }); jScrollPane1.setViewportView(logsTable); if (logsTable.getColumnModel().getColumnCount() > 0) { logsTable.getColumnModel().getColumn(0).setResizable(false); logsTable.getColumnModel().getColumn(1).setResizable(false); logsTable.getColumnModel().getColumn(1).setPreferredWidth(300); logsTable.getColumnModel().getColumn(2).setResizable(false); logsTable.getColumnModel().getColumn(2).setPreferredWidth(30); logsTable.getColumnModel().getColumn(3).setResizable(false); logsTable.getColumnModel().getColumn(3).setPreferredWidth(30); } jLabel6.setFont(new java.awt.Font("Rondalo", 1, 18)); // NOI18N jLabel6.setText("Date:"); jButton1.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N jButton1.setText("Save to PDF"); jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(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) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(dateCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(324, 324, 324).addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent( searchField, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jButton1).addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel6).addComponent(dateCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(2, 2, 2) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(searchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton1) .addGap(20, 20, 20))); jLayeredPane1.add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 130, 920, 500)); jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/help.png"))); // NOI18N jLabel2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jLabel2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jLabel2MouseClicked(evt); } }); jLayeredPane1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 30, -1, -1)); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/2.jpg"))); // NOI18N jLabel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jLayeredPane1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLayeredPane1)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent( jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void logsTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_logsTableMouseClicked // TODO add your handling code here: // ArrayList<ResidentImpl> logs = new ArrayList<>(); // for(int i = 0; i < logsTable.getRowCount(); i++){ // ResidentImpl res = new ResidentImpl(); // res.setId(logsTable.getValueAt(i, 0).toString()); // res.setFullName(logsTable.getValueAt(i, 1).toString()); // res.setTime(logsTable.getValueAt(i, 2).toString()); // res.setLastStatus(logsTable.getValueAt(i, 3).toString()); // logs.add(res); // } mouseClick = true; }//GEN-LAST:event_logsTableMouseClicked private void logsTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_logsTableMousePressed // TODO add your handling code here: }//GEN-LAST:event_logsTableMousePressed private void logsTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_logsTableMouseReleased // TODO add your handling code here: if (mouseClick && logsTable.getSelectedRowCount() == 1) { if (evt.isPopupTrigger()) { javax.swing.JTable source = (javax.swing.JTable) evt.getSource(); row = source.rowAtPoint(evt.getPoint()); column = source.columnAtPoint(evt.getPoint()); if (!source.isRowSelected(row)) { source.changeSelection(row, column, false, false); } jPopupMenu1.show(evt.getComponent(), evt.getX(), evt.getY()); } } // mouseClick = false; }//GEN-LAST:event_logsTableMouseReleased private void sendMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendMessageActionPerformed // TODO add your handling code here: new SendMessage(this, true, logsTable.getValueAt(logsTable.getSelectedRow(), 0).toString(), logsTable.getValueAt(logsTable.getSelectedRow(), 1).toString(), client).setVisible(true); }//GEN-LAST:event_sendMessageActionPerformed private void homeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_homeMouseClicked // TODO add your handling code here: updaterClass.setRunning(false); timerThread.setRunning(false); this.dispose(); new Main(client, user).setVisible(true); }//GEN-LAST:event_homeMouseClicked private void sendEMailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendEMailActionPerformed // TODO add your handling code here: new SendEMail(this, true, logsTable.getValueAt(logsTable.getSelectedRow(), 0).toString(), logsTable.getValueAt(logsTable.getSelectedRow(), 1).toString(), client).setVisible(true); }//GEN-LAST:event_sendEMailActionPerformed private void profilePicMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_profilePicMouseClicked // TODO add your handling code here: profilePicPopup.show(evt.getComponent(), evt.getComponent().getWidth(), 1); }//GEN-LAST:event_profilePicMouseClicked private void editProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editProfileActionPerformed // TODO add your handling code here: updaterClass.setRunning(false); timerThread.setRunning(false); this.dispose(); new EditProfile("iLogbook", user, client).setVisible(true); }//GEN-LAST:event_editProfileActionPerformed private void changePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changePasswordActionPerformed // TODO add your handling code here: updaterClass.setRunning(false); timerThread.setRunning(false); this.dispose(); new ChangePassword("iLogbook", user, client).setVisible(true); }//GEN-LAST:event_changePasswordActionPerformed private void logoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutActionPerformed // TODO add your handling code here: updaterClass.setRunning(false); timerThread.setRunning(false); new Login().setVisible(true); this.dispose(); }//GEN-LAST:event_logoutActionPerformed private void adminListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adminListActionPerformed // TODO add your handling code here: updaterClass.setRunning(false); timerThread.setRunning(false); dispose(); new AdminList("iLogbook", user, client).setVisible(true); }//GEN-LAST:event_adminListActionPerformed private void updaterCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_updaterCaretUpdate // TODO add your handling code here: if (searchField.getText().trim().isEmpty()) { updaterMethod(); } }//GEN-LAST:event_updaterCaretUpdate private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing updaterClass.setRunning(false); timerThread.setRunning(false); }//GEN-LAST:event_formWindowClosing private void dateComboOnCommit(datechooser.events.CommitEvent evt) {//GEN-FIRST:event_dateComboOnCommit // TODO add your handling code here: // tableModel.getDataVector().removeAllElements(); // tableModel.fireTableDataChanged(); if (!dateChooserDate.equals(dateCombo.getText().trim())) { dateChooserDate = dateCombo.getText(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); ArrayList<ResidentImpl> logs; tableModel = (DefaultTableModel) logsTable.getModel(); try { logs = client.getAllLogsSearch(format.format(dateCombo.getDateFormat().parse(dateCombo.getText())), searchField.getText()); tableModel.getDataVector().removeAllElements(); tableModel.fireTableDataChanged(); for (ResidentImpl residentImpl : logs) { tableModel.addRow(new Object[] { residentImpl.getId(), residentImpl.getFullName(), residentImpl.getTime(), residentImpl.getLastStatus() }); } Rectangle rect = logsTable.getCellRect(tableModel.getRowCount(), 0, false); logsTable.scrollRectToVisible(rect); } catch (ParseException | RemoteException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } } }//GEN-LAST:event_dateComboOnCommit private void searchFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_searchFieldCaretUpdate SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; ArrayList<ResidentImpl> logs = new ArrayList<>(); tableModel = (DefaultTableModel) logsTable.getModel(); try { date = dateCombo.getDateFormat().parse(dateCombo.getText()); logs = client.getAllLogsSearch(format.format(date), searchField.getText()); tableModel.getDataVector().removeAllElements(); tableModel.fireTableDataChanged(); for (ResidentImpl residentImpl : logs) { tableModel.addRow(new Object[] { residentImpl.getId(), residentImpl.getFullName(), residentImpl.getTime(), residentImpl.getLastStatus() }); } } catch (ParseException | RemoteException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }//GEN-LAST:event_searchFieldCaretUpdate private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked // TODO add your handling code here: try { String path = ""; BufferedReader br = new BufferedReader(new FileReader("dir\\docs.txt")); try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } catch (IOException ex) { // Logger.getLogger(AdminArchiveFrame.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } finally { br.close(); } Desktop.getDesktop().browse(new File(path).toURI()); } catch (IOException ex) { new MessageDialog().error(this, ex.getMessage()); // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_jLabel2MouseClicked private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try { if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { String path = chooser.getSelectedFile().toString() + "\\" + new SimpleDateFormat("MMddyyyy") .format(dateCombo.getDateFormat().parse(dateCombo.getText())) + "logbook.pdf"; tableModel = (DefaultTableModel) logsTable.getModel(); Document document = new Document(); FileOutputStream fos = new FileOutputStream(path); PdfWriter.getInstance(document, fos); document.open(); Paragraph par = new Paragraph( "Date: " + new SimpleDateFormat("MMMM dd, yyyy") .format(dateCombo.getDateFormat().parse(dateCombo.getText())), new Font(FontFamily.TIMES_ROMAN, 12)); document.add(par); PdfPTable tab = new PdfPTable(tableModel.getColumnCount() - 1); for (int i = 1; i < tableModel.getColumnCount(); i++) { tab.addCell(tableModel.getColumnName(i)); } for (int i = 0; i < tableModel.getRowCount(); i++) { for (int j = 1; j < tableModel.getColumnCount(); j++) { tab.addCell(tableModel.getValueAt(i, j).toString()); } } document.add(tab); document.close(); fos.close(); new MessageDialog().successful(this, "File Saved."); } } catch (ParseException | DocumentException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (FileNotFoundException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (IOException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }//GEN-LAST:event_jButton1ActionPerformed public void UserAdmin() { try { welcome.setText("Welcome " + client.getUserAdmin(user).getFullName() + "!"); byte[] cc = client.getProfilePicture(user); if (cc != null) { InputStream in = new ByteArrayInputStream(cc); BufferedImage img = ImageIO.read(in); if (img != null) { Image image = img.getScaledInstance(profilePic.getWidth(), profilePic.getHeight(), Image.SCALE_SMOOTH); profilePic.setIcon(new ImageIcon(image)); } } } catch (RemoteException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (IOException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } } public void updaterMethod() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); ArrayList<ResidentImpl> logs; tableModel = (DefaultTableModel) logsTable.getModel(); try { logs = client.getAllLogsSearch(format.format(dateCombo.getDateFormat().parse(dateCombo.getText())), searchField.getText().trim()); if (!logs.isEmpty() && logs.size() > tableModel.getRowCount()) { tableModel.getDataVector().removeAllElements(); tableModel.fireTableDataChanged(); for (ResidentImpl residentImpl : logs) { tableModel.addRow(new Object[] { residentImpl.getId(), residentImpl.getFullName(), residentImpl.getTime(), residentImpl.getLastStatus() }); } } Rectangle rect = logsTable.getCellRect(tableModel.getRowCount(), 0, false); logsTable.scrollRectToVisible(rect); } catch (ParseException | RemoteException ex) { // Logger.getLogger(ILogbook.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } } /** * @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(ILogbook.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(ILogbook.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(ILogbook.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(ILogbook.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 ILogbook(new AccessibleServer()).setVisible(true); } });*/ } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenuItem adminList; private javax.swing.JMenuItem changePassword; private javax.swing.JFileChooser chooser; private javax.swing.JLabel date; private datechooser.beans.DateChooserCombo dateCombo; private javax.swing.JLabel day; private javax.swing.JMenuItem editProfile; private javax.swing.JLabel home; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLayeredPane jLayeredPane1; private javax.swing.JPanel jPanel1; private javax.swing.JPopupMenu jPopupMenu1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JMenuItem logout; private javax.swing.JTable logsTable; private javax.swing.JLabel profilePic; private javax.swing.JPopupMenu profilePicPopup; private javax.swing.ButtonGroup searchByButtons; private javax.swing.JTextField searchField; private javax.swing.JMenuItem sendEMail; private javax.swing.JMenuItem sendMessage; private javax.swing.JLabel time; private javax.swing.JTextField updater; private javax.swing.JLabel welcome; // End of variables declaration//GEN-END:variables }