GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
Issues
4
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
mark.george
/
marking
Browse code
Add property to toggle 'copy ID to clipboard' feature.
master
1 parent
e230ddc
commit
f3c39edd3e887699ad1e7e218ad24ba3a9989d11
Mark George
authored
on 11 Apr
Patch
Showing
1 changed file
src/main/java/ui/SubmissionFrame.java
Ignore Space
Show notes
View
src/main/java/ui/SubmissionFrame.java
package ui; import dao.MarkingProperties; import dao.ResultDAO; import dao.ScheduleDAO; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.KeyEvent; /** * * @author Mark George <mark.george@otago.ac.nz> */ public class SubmissionFrame extends javax.swing.JFrame { private final ScheduleDAO scheduleDAO = new ScheduleDAO(); private Integer selectedRow = 0; private final BatchMailer batchMailer = new BatchMailer(this, true); /** * Creates new form SubmissionDialog */ public SubmissionFrame() { initComponents(); table.setModel(new ResultDAO().getSubmissions()); this.setTitle(scheduleDAO.getAssessmentName() + " (" + scheduleDAO.getComplete() + "% marked)"); } public BatchMailer getBatchMailer() { return batchMailer; } /** * 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() { scrollPane = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); btnMark = new javax.swing.JButton(); btnQuit = new javax.swing.JButton(); btnBatch = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setPreferredSize(new java.awt.Dimension(300, 800)); table.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { tableMouseClicked(evt); } }); table.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { tableKeyPressed(evt); } }); scrollPane.setViewportView(table); btnMark.setText("Mark Selected Student"); btnMark.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnMarkActionPerformed(evt); } }); btnQuit.setText("Quit"); btnQuit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnQuitActionPerformed(evt); } }); btnBatch.setText("Batch Report/Email"); btnBatch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBatchActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollPane) .addGroup(layout.createSequentialGroup() .addComponent(btnQuit) .addGap(18, 18, Short.MAX_VALUE) .addComponent(btnBatch) .addGap(18, 18, Short.MAX_VALUE) .addComponent(btnMark))) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnBatch, btnMark, btnQuit}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnMark) .addComponent(btnQuit) .addComponent(btnBatch)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void btnQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitActionPerformed System.exit(0); }//GEN-LAST:event_btnQuitActionPerformed private void btnMarkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMarkActionPerformed markSelected(); }//GEN-LAST:event_btnMarkActionPerformed private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked if (evt.getClickCount() >= 2) { markSelected(); } }//GEN-LAST:event_tableMouseClicked private void tableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) { evt.consume(); markSelected(); } }//GEN-LAST:event_tableKeyPressed private void btnBatchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBatchActionPerformed batchMailer.setLocationRelativeTo(this); batchMailer.setVisible(true); refresh(); }//GEN-LAST:event_btnBatchActionPerformed private void markSelected() { // get selected ID from table selectedRow = table.getSelectedRow(); String id = (String) table.getModel().getValueAt(selectedRow, 0); // copy selected ID to clipboard if (MarkingProperties.copyIdToClipboard()) { StringSelection stringSelection = new StringSelection(id); Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); clpbrd.setContents(stringSelection, null); } MarkingFrame frame = new MarkingFrame(this, scheduleDAO.getAssessmentName()); // load data into frame ScheduleDAO dao = new ScheduleDAO(); for (String cat : dao.getCategories()) { frame.addCategory(cat, dao.getCriteria(cat)); } frame.load(id); frame.display(); } public void refresh() { // refresh table to display new mark table.setModel(new ResultDAO().getSubmissions()); // update title to show latest completion % this.setTitle(scheduleDAO.getAssessmentName() + " (" + scheduleDAO.getComplete() + "% marked)"); // reselect the most recently selected row table.setRowSelectionInterval(selectedRow, selectedRow); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnBatch; private javax.swing.JButton btnMark; private javax.swing.JButton btnQuit; private javax.swing.JScrollPane scrollPane; private javax.swing.JTable table; // End of variables declaration//GEN-END:variables }
package ui; import dao.ResultDAO; import dao.ScheduleDAO; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.KeyEvent; /** * * @author Mark George <mark.george@otago.ac.nz> */ public class SubmissionFrame extends javax.swing.JFrame { private final ScheduleDAO scheduleDAO = new ScheduleDAO(); private Integer selectedRow = 0; private final BatchMailer batchMailer = new BatchMailer(this, true); /** * Creates new form SubmissionDialog */ public SubmissionFrame() { initComponents(); table.setModel(new ResultDAO().getSubmissions()); this.setTitle(scheduleDAO.getAssessmentName() + " (" + scheduleDAO.getComplete() + "% marked)"); } public BatchMailer getBatchMailer() { return batchMailer; } /** * 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() { scrollPane = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); btnMark = new javax.swing.JButton(); btnQuit = new javax.swing.JButton(); btnBatch = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setPreferredSize(new java.awt.Dimension(300, 800)); table.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { tableMouseClicked(evt); } }); table.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { tableKeyPressed(evt); } }); scrollPane.setViewportView(table); btnMark.setText("Mark Selected Student"); btnMark.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnMarkActionPerformed(evt); } }); btnQuit.setText("Quit"); btnQuit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnQuitActionPerformed(evt); } }); btnBatch.setText("Batch Report/Email"); btnBatch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBatchActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollPane) .addGroup(layout.createSequentialGroup() .addComponent(btnQuit) .addGap(18, 18, Short.MAX_VALUE) .addComponent(btnBatch) .addGap(18, 18, Short.MAX_VALUE) .addComponent(btnMark))) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnBatch, btnMark, btnQuit}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnMark) .addComponent(btnQuit) .addComponent(btnBatch)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void btnQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitActionPerformed System.exit(0); }//GEN-LAST:event_btnQuitActionPerformed private void btnMarkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMarkActionPerformed markSelected(); }//GEN-LAST:event_btnMarkActionPerformed private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked if (evt.getClickCount() >= 2) { markSelected(); } }//GEN-LAST:event_tableMouseClicked private void tableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) { evt.consume(); markSelected(); } }//GEN-LAST:event_tableKeyPressed private void btnBatchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBatchActionPerformed batchMailer.setLocationRelativeTo(this); batchMailer.setVisible(true); refresh(); }//GEN-LAST:event_btnBatchActionPerformed private void markSelected() { // get selected ID from table selectedRow = table.getSelectedRow(); String id = (String) table.getModel().getValueAt(selectedRow, 0); // copy selected ID to clipboard StringSelection stringSelection = new StringSelection(id); Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); clpbrd.setContents(stringSelection, null); MarkingFrame frame = new MarkingFrame(this, scheduleDAO.getAssessmentName()); // load data into frame ScheduleDAO dao = new ScheduleDAO(); for (String cat : dao.getCategories()) { frame.addCategory(cat, dao.getCriteria(cat)); } frame.load(id); frame.display(); } public void refresh() { // refresh table to display new mark table.setModel(new ResultDAO().getSubmissions()); // update title to show latest completion % this.setTitle(scheduleDAO.getAssessmentName() + " (" + scheduleDAO.getComplete() + "% marked)"); // reselect the most recently selected row table.setRowSelectionInterval(selectedRow, selectedRow); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnBatch; private javax.swing.JButton btnMark; private javax.swing.JButton btnQuit; private javax.swing.JScrollPane scrollPane; private javax.swing.JTable table; // End of variables declaration//GEN-END:variables }
Show line notes below