From 0ecfbab7e3f6069576612e68787a2bfe4517d9a6 Mon Sep 17 00:00:00 2001 From: Antti Leinonen Date: Thu, 5 Apr 2018 13:58:20 +0300 Subject: [PATCH] Add a dialog for snapshot collection --- .../cs/tmc/tailoring/DefaultTailoring.java | 5 +- .../cs/tmc/ui/AllowSnapshotsDialog.form | 122 ++++++++++++++ .../cs/tmc/ui/AllowSnapshotsDialog.java | 158 ++++++++++++++++++ .../fi/helsinki/cs/tmc/ui/Bundle.properties | 6 +- .../helsinki/cs/tmc/ui/CourseListWindow.java | 23 ++- .../fi/helsinki/cs/tmc/ui/LoginDialog.java | 6 +- .../helsinki/cs/tmc/ui/PreferencesPanel.form | 3 + .../helsinki/cs/tmc/ui/PreferencesPanel.java | 9 + .../src/fi/helsinki/cs/tmc/ui/check.png | Bin 0 -> 773 bytes .../src/fi/helsinki/cs/tmc/ui/cross.png | Bin 0 -> 379 bytes 10 files changed, 319 insertions(+), 13 deletions(-) create mode 100644 tmc-plugin/src/fi/helsinki/cs/tmc/ui/AllowSnapshotsDialog.form create mode 100644 tmc-plugin/src/fi/helsinki/cs/tmc/ui/AllowSnapshotsDialog.java create mode 100644 tmc-plugin/src/fi/helsinki/cs/tmc/ui/check.png create mode 100644 tmc-plugin/src/fi/helsinki/cs/tmc/ui/cross.png diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/tailoring/DefaultTailoring.java b/tmc-plugin/src/fi/helsinki/cs/tmc/tailoring/DefaultTailoring.java index d59c3f2c..7ad8e438 100644 --- a/tmc-plugin/src/fi/helsinki/cs/tmc/tailoring/DefaultTailoring.java +++ b/tmc-plugin/src/fi/helsinki/cs/tmc/tailoring/DefaultTailoring.java @@ -32,12 +32,13 @@ protected String getSystemUsername() { @Override public boolean isSpywareEnabledByDefault() { - return true; + return false; } + // TODO: Should this be removed? @Override public boolean isDetailedSpywareEnabledByDefault() { - return true; + return false; } @Override diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/AllowSnapshotsDialog.form b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/AllowSnapshotsDialog.form new file mode 100644 index 00000000..e7378a72 --- /dev/null +++ b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/AllowSnapshotsDialog.form @@ -0,0 +1,122 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/AllowSnapshotsDialog.java b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/AllowSnapshotsDialog.java new file mode 100644 index 00000000..0098e7cb --- /dev/null +++ b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/AllowSnapshotsDialog.java @@ -0,0 +1,158 @@ +package fi.helsinki.cs.tmc.ui; + +import fi.helsinki.cs.tmc.actions.ShowSettingsAction; +import fi.helsinki.cs.tmc.core.holders.TmcSettingsHolder; +import fi.helsinki.cs.tmc.coreimpl.TmcCoreSettingsImpl; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JDialog; + +import org.openide.windows.WindowManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AllowSnapshotsDialog extends JDialog { + + private PreferencesPanel panel; + private static final Logger LOG = LoggerFactory.getLogger(AllowSnapshotsDialog.class); + private static boolean answered; + + public static void ask() throws InterruptedException { + answered = false; + + LOG.info("Asking the user if they consent to collecting analytics."); + display(); + } + + public static void display() { + PreferencesPanel prefPanel; + if (PreferencesUIFactory.getInstance().getCurrentUI() == null) { + prefPanel = (PreferencesPanel) PreferencesUIFactory.getInstance().createCurrentPreferencesUI(); + } else { + prefPanel = (PreferencesPanel) PreferencesUIFactory.getInstance().getCurrentUI(); + } + + AllowSnapshotsDialog dialog = new AllowSnapshotsDialog(prefPanel); + dialog.setLocationRelativeTo(null); + dialog.setVisible(true); + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + if (!answered) { + display(); + } else { + new ShowSettingsAction().run(); + } + } + }); + } + + private AllowSnapshotsDialog(PreferencesPanel panel) { + super(WindowManager.getDefault().getMainWindow(), false); + initComponents(); + this.panel = panel; + } + + private void setSpywareEnabledAndCloseDialog(boolean spywareEnabled) { + this.panel.setSpywareEnabled(spywareEnabled); + TmcCoreSettingsImpl settings = (TmcCoreSettingsImpl)TmcSettingsHolder.get(); + settings.setIsSpywareEnabled(spywareEnabled); + answered = true; + this.setVisible(false); + this.dispose(); + } + + /** + * 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") + // //GEN-BEGIN:initComponents + private void initComponents() { + + titleLabel = new javax.swing.JLabel(); + disagreeButton = new javax.swing.JButton(); + agreeButton = new javax.swing.JButton(); + informationScrollPane = new javax.swing.JScrollPane(); + informationTextArea = new javax.swing.JTextArea(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setMinimumSize(new java.awt.Dimension(670, 250)); + + titleLabel.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(AllowSnapshotsDialog.class, "AllowSnapshotsDialog.titleLabel.text")); // NOI18N + + disagreeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fi/helsinki/cs/tmc/ui/cross.png"))); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(disagreeButton, org.openide.util.NbBundle.getMessage(AllowSnapshotsDialog.class, "AllowSnapshotsDialog.disagreeButton.text")); // NOI18N + disagreeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + disagreeButtonActionPerformed(evt); + } + }); + + agreeButton.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N + agreeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fi/helsinki/cs/tmc/ui/check.png"))); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(agreeButton, org.openide.util.NbBundle.getMessage(AllowSnapshotsDialog.class, "AllowSnapshotsDialog.agreeButton.text")); // NOI18N + agreeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + agreeButtonActionPerformed(evt); + } + }); + + informationTextArea.setEditable(false); + informationTextArea.setColumns(20); + informationTextArea.setLineWrap(true); + informationTextArea.setRows(5); + informationTextArea.setText(org.openide.util.NbBundle.getMessage(AllowSnapshotsDialog.class, "AllowSnapshotsDialog.informationTextArea.text")); // NOI18N + informationTextArea.setWrapStyleWord(true); + informationScrollPane.setViewportView(informationTextArea); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(disagreeButton, javax.swing.GroupLayout.DEFAULT_SIZE, 765, Short.MAX_VALUE) + .addComponent(agreeButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(informationScrollPane) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(titleLabel) + .addGap(0, 0, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(titleLabel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(informationScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(agreeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(disagreeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void agreeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agreeButtonActionPerformed + this.setSpywareEnabledAndCloseDialog(true); + }//GEN-LAST:event_agreeButtonActionPerformed + + private void disagreeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disagreeButtonActionPerformed + this.setSpywareEnabledAndCloseDialog(false); + }//GEN-LAST:event_disagreeButtonActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton agreeButton; + private javax.swing.JButton disagreeButton; + private javax.swing.JScrollPane informationScrollPane; + private javax.swing.JTextArea informationTextArea; + private javax.swing.JLabel titleLabel; + // End of variables declaration//GEN-END:variables +} diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/Bundle.properties b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/Bundle.properties index e0e0e12e..e293eb60 100644 --- a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/Bundle.properties +++ b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/Bundle.properties @@ -38,7 +38,7 @@ SuccessfulSubmissionDialog.yayLabel.text=All tests passed on the server. PreferencesPanel.checkForUpdatesInBackgroundCheckbox.text=Check for new or updated exercises regularly PreferencesPanel.checkForUnopenedExercisesCheckbox.text=Check that all active exercises are open on startup PreferencesPanel.checkForUnopenedExercisesCheckbox.toolTipText=Leave this on unless you like to close exercises after you're done with them. -PreferencesPanel.spywareEnabledCheckbox.text=Send snapshots of your progress for study +PreferencesPanel.spywareEnabledCheckbox.text=Allow the collection of snapshot data from course assignments PreferencesPanel.spywareEnabledCheckbox.toolTipText=Regularly send snapshots of your code to the server. We respectfully ask you keep this on as this helps us understand the kinds of problems students have with exercises. PreferencesPanel.errorMsgLocaleLabel.text=Preferred error message language PreferencesPanel.errorMsgLocaleLabel.toolTipText=Some (but not nearly all) error messages in some exercises' tests have been translated. @@ -96,3 +96,7 @@ PreferencesPanel.selectedCourseLabel.text=No course selected PreferencesPanel.loginLabel.text=Not logged in! PreferencesPanel.logoutButton.text=Logout PreferencesPanel.selectedOrganizationLabel.text=No organization selected +AllowSnapshotsDialog.informationTextArea.text=Dear student,\n\nTest My Code can collect data from your programming process. \n\nThis data is collected only from course assignments that have been downloaded by Test My Code. \nTest My Code does _not_ collect data from your own projects or any other resources on your computer. \n\nSome courses require that you allow the collection of such data for grading purposes. You can change your preferences later through TMC Settings by checking or unchecking the option "Allow the collection of snapshot data from course assignments". +AllowSnapshotsDialog.agreeButton.text=\ I allow the collection of snapshot data from course assignments. +AllowSnapshotsDialog.disagreeButton.text=\u00a0 I do not allow the collection of snapshot data from course assignments.
\u00a0Selecting this means that completed assignments may not count in e.g. course grading. +AllowSnapshotsDialog.titleLabel.text=Collection of snapshot data diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/CourseListWindow.java b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/CourseListWindow.java index 8b1b1013..137e8a80 100644 --- a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/CourseListWindow.java +++ b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/CourseListWindow.java @@ -16,6 +16,7 @@ import java.awt.event.MouseEvent; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; +import java.lang.reflect.InvocationTargetException; import java.util.List; import javax.swing.BoxLayout; @@ -30,6 +31,7 @@ import javax.swing.ListModel; import javax.swing.ListSelectionModel; import javax.swing.border.EmptyBorder; +import org.openide.util.Exceptions; public class CourseListWindow extends JPanel { @@ -80,11 +82,11 @@ public void mouseClicked(MouseEvent event) { public static void display() throws Exception { PreferencesPanel prefPanel; - if (PreferencesUIFactory.getInstance().getCurrentUI() == null) { - prefPanel = (PreferencesPanel) PreferencesUIFactory.getInstance().createCurrentPreferencesUI(); - } else { - prefPanel = (PreferencesPanel) PreferencesUIFactory.getInstance().getCurrentUI(); - } + if (PreferencesUIFactory.getInstance().getCurrentUI() == null) { + prefPanel = (PreferencesPanel) PreferencesUIFactory.getInstance().createCurrentPreferencesUI(); + } else { + prefPanel = (PreferencesPanel) PreferencesUIFactory.getInstance().getCurrentUI(); + } if (frame == null) { frame = new JFrame("Courses"); } @@ -165,7 +167,16 @@ public void actionPerformed(ActionEvent e) { prefPanel.setSelectedCourse(courses.getSelectedValue().getCourse()); frame.setVisible(false); frame.dispose(); - new ShowSettingsAction().run(); + + if (prefPanel.getSpywareEnabled()) { + new ShowSettingsAction().run(); + } else { + try { + AllowSnapshotsDialog.ask(); + } catch (InterruptedException ex) { + Exceptions.printStackTrace(ex); + } + } } } } diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/LoginDialog.java b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/LoginDialog.java index fa2a664a..0a625383 100644 --- a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/LoginDialog.java +++ b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/LoginDialog.java @@ -1,15 +1,13 @@ package fi.helsinki.cs.tmc.ui; import fi.helsinki.cs.tmc.core.holders.TmcSettingsHolder; -import fi.helsinki.cs.tmc.core.utilities.TmcServerAddressNormalizer; import fi.helsinki.cs.tmc.coreimpl.TmcCoreSettingsImpl; +import fi.helsinki.cs.tmc.utilities.LoginListener; import com.google.common.base.Optional; -import fi.helsinki.cs.tmc.utilities.LoginListener; import org.openide.windows.WindowManager; -import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JOptionPane; @@ -36,7 +34,7 @@ public void windowClosed(WindowEvent e) { /** * Creates new form LoginForm */ - public LoginDialog(LoginListener onLogin) { + private LoginDialog(LoginListener onLogin) { super(WindowManager.getDefault().getMainWindow(), false); initComponents(); diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/PreferencesPanel.form b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/PreferencesPanel.form index d2273b8e..f4bac249 100644 --- a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/PreferencesPanel.form +++ b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/PreferencesPanel.form @@ -223,6 +223,9 @@ + + + diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/PreferencesPanel.java b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/PreferencesPanel.java index 682c3e2f..7d936e3a 100644 --- a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/PreferencesPanel.java +++ b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/PreferencesPanel.java @@ -322,6 +322,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { spywareEnabledCheckbox.setText(org.openide.util.NbBundle.getMessage(PreferencesPanel.class, "PreferencesPanel.spywareEnabledCheckbox.text")); // NOI18N spywareEnabledCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(PreferencesPanel.class, "PreferencesPanel.spywareEnabledCheckbox.toolTipText")); // NOI18N + spywareEnabledCheckbox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + spywareEnabledCheckboxActionPerformed(evt); + } + }); errorMsgLocaleLabel.setText(org.openide.util.NbBundle.getMessage(PreferencesPanel.class, "PreferencesPanel.errorMsgLocaleLabel.text")); // NOI18N errorMsgLocaleLabel.setToolTipText(org.openide.util.NbBundle.getMessage(PreferencesPanel.class, "PreferencesPanel.errorMsgLocaleLabel.toolTipText")); // NOI18N @@ -536,6 +541,10 @@ private void logoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN- BgTask.start("Logged out. Asking to log in.", new LoginTask()); }//GEN-LAST:event_logoutButtonActionPerformed + private void spywareEnabledCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spywareEnabledCheckboxActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_spywareEnabledCheckboxActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton changeCourseButton; private javax.swing.JButton changeOrganizationButton; diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/check.png b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/check.png new file mode 100644 index 0000000000000000000000000000000000000000..2629ffbf8279b8e8dc4a3ccbda53b2d6dc515528 GIT binary patch literal 773 zcmV+g1N!`lP)3ki~<&~GUi}|cG zH2l3{gJ0RY4q%TDZ6${_2o+w_v8jtS2;F`>5goe{da_WlL1t%d3~2D7<$%HbqHKdl zbDdj7w6_fEc&s@&mtO>mGj=+92B`nDW6OBgp~t_AbHSyROTa!K@tj(6w-_iKxt)%l zQsmt~bY2|29t$TY0g|am&@pBX*zaTTG9I$e6$6C{6zOMeaZp7j?3w5k!Zim8mm%(8 zaeF-|03$Q;6C(P-qcA7vk|MiGsVg$s9!j*W#|?mp_HQgHgykm=s2IKFmN3aw(10Ejo*KjL9K;)rPh-j^!)&r@{3m*WN| z(y=y0?hAUrt58Lz+nW=|{0v+lyLiZ+s9nq)5z#*2r)y_U>Af%T{0PZZq`?t$2jN1Y zA!Rlevcn=?M_++KKJ0X~MUf$((J|(9N7KkuIdy*lfE2?+QS9Nr00000NkvXXu0mjf D1R7eG literal 0 HcmV?d00001 diff --git a/tmc-plugin/src/fi/helsinki/cs/tmc/ui/cross.png b/tmc-plugin/src/fi/helsinki/cs/tmc/ui/cross.png new file mode 100644 index 0000000000000000000000000000000000000000..8dfa4770ee4e893a1c41ff0c0e2fd8d7a927d4fd GIT binary patch literal 379 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjEX7WqAsj$Z!;#Vf2?- zdJtyZvF%JJkRe&(8c`CQpH@mmtT}V`<;yxP|*)h7sn8f z&b`wdxegf!xXy2K{~#y!MQ7JWJ)7z5A?01tTkFg@kC?n%BE-wWHMeqorqyI86PDfw zDmRXOFLK^cYS}A#gJWHj-v^C}7C&M?6z$CHOiGV4q}`)J*4Hks`A6+=%erS z&#v1NyWMeFXwSY_{o1C|2Vc4}96oXK3l+JiZTllU$;8Iv$K8eUo~!