diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a82df7f --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.* +!.gitignore +build/ +dist/ + diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..5055a5a --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,13 @@ +v1.2.0 [2021-07-26] +- (Fix) External USB drives weren't being detected on Windows 10. + +v1.1.0 [2009-02-02] +- (New) Suspected worm file extension list updated. Also removes any autorun.inf file found in the drive root. +- (New) Now can detect the following file extensions: exe, cmd, bat, vb, vbs, vbe, vbscript, js, jse, ws, wsf, wsh, pif, scr, sct, script. + +v1.0.1 [2008-09-08] +- (Fix) Newly attached mass storage devices weren't getting detected. + +v1.0.0 [2008-08-26] +- First release. + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..55f3f3f --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +USB Worm Protection License + +Copyright (c) 2021 Sharafat Ibn Mollah Mosharraf + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, and/or sublicense the Software, +and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +1. The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +2. If the source code is modified, the "About" section of the application shall +include "Original Software Credit: Sharafat Ibn Mollah Mosharraf (www.sharafat.co.uk)". +3. No commercial transactions are allowed. Therefore, the Software cannot be sold. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..98efc6a --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# USB Worm Protection +USB Worm Protection provides you with an easy and highly efficient way to scan your hard +disk and USB devices for computer worms. This reliable and intuitive piece of software +is a great tool for every computer user that wants to protect their systems against +these types of malware programs. + +USB Worm Protection is a simple-to-use program designed to rid your USB flash disks of +files infected with worms. It packs several handy features that can be figured out even +by users with little or no experience in antivirus systems. + +At initialization, the tool creates an icon in the system tray area, where you can access +options and configure settings. + +Aside from scanning the USB flash disks, USB Worm Protection is also capable of scanning +your local drives for worms. This process shows the total scanned, detected and suspected +items, start and finish time, and duration. Every detected worm or suspected file can be +deleted, skipped or sent to the quarantine. + +As far as program preferences go, you can enable silent scan mode, set the tool to prompt +for an action against suspected files, and configure scan notification options (e.g. remove +slide-in dialogs after the scan is done). A restart of USB Worm Protection is required to +apply the new changes. + +The application uses a moderate-to-high amount of CPU and RAM, but it doesn't interrupt user +activity, since it can run silently in the background, alongside other processes. + +[Description provided courtesy of Softpedia and Softoxi.] + +For more information, please visit [http://usbwp.sharafat.co.uk](http://usbwp.sharafat.co.uk) diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..d305965 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project USB Worm Protection. + + + diff --git a/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar b/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar new file mode 100644 index 0000000..3c8dd2f Binary files /dev/null and b/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar differ diff --git a/lib/hamcrest/hamcrest-core-1.3.jar b/lib/hamcrest/hamcrest-core-1.3.jar new file mode 100644 index 0000000..9d5fe16 Binary files /dev/null and b/lib/hamcrest/hamcrest-core-1.3.jar differ diff --git a/lib/junit_4/junit-4.13.1-javadoc.jar b/lib/junit_4/junit-4.13.1-javadoc.jar new file mode 100644 index 0000000..d284bd0 Binary files /dev/null and b/lib/junit_4/junit-4.13.1-javadoc.jar differ diff --git a/lib/junit_4/junit-4.13.1-sources.jar b/lib/junit_4/junit-4.13.1-sources.jar new file mode 100644 index 0000000..b68ac35 Binary files /dev/null and b/lib/junit_4/junit-4.13.1-sources.jar differ diff --git a/lib/junit_4/junit-4.13.1.jar b/lib/junit_4/junit-4.13.1.jar new file mode 100644 index 0000000..b376ffc Binary files /dev/null and b/lib/junit_4/junit-4.13.1.jar differ diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties new file mode 100644 index 0000000..1ebe18e --- /dev/null +++ b/lib/nblibraries.properties @@ -0,0 +1,16 @@ +libs.CopyLibs.classpath=\ + ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar +libs.CopyLibs.displayName=CopyLibs Task +libs.CopyLibs.prop-version=3.0 +libs.hamcrest.classpath=\ + ${base}/hamcrest/hamcrest-core-1.3.jar +libs.hamcrest.displayName=Hamcrest 1.3 +libs.hamcrest.prop-maven-dependencies=org.hamcrest:hamcrest-core:1.3:jar +libs.junit_4.classpath=\ + ${base}/junit_4/junit-4.13.1.jar +libs.junit_4.displayName=JUnit 4.12 +libs.junit_4.javadoc=\ + ${base}/junit_4/junit-4.13.1-javadoc.jar +libs.junit_4.prop-maven-dependencies=junit:junit:4.13.1:jar +libs.junit_4.src=\ + ${base}/junit_4/junit-4.13.1-sources.jar diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..8172051 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1796 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.src.dir + Must set test.test.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..8edf169 --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=c760dccb +build.xml.script.CRC32=6a848cfb +build.xml.stylesheet.CRC32=f85dc8f2@1.99.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=c760dccb +nbproject/build-impl.xml.script.CRC32=ea629f84 +nbproject/build-impl.xml.stylesheet.CRC32=d549e5cc@1.99.0.48 diff --git a/nbproject/private/config.properties b/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..e7eab02 --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,8 @@ +compile.on.save=true +do.depend=false +do.jar=true +do.jlink=true +javac.debug=true +javadoc.preview=true +jlink.strip=false +user.properties.file=/Users/sharafat/Library/Application Support/NetBeans/12.4/build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..4750962 --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..eccdbc2 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,84 @@ +#Mon Jul 26 18:50:12 BDT 2021 +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit_4.classpath}:\ + ${libs.hamcrest.classpath} +excludes= +javac.processorpath=\ + ${javac.classpath} +dist.javadoc.dir=${dist.dir}/javadoc +src.src.dir=src +run.modulepath=\ + ${javac.modulepath} +annotation.processing.enabled=true +build.sysclasspath=ignore +debug.modulepath=${run.modulepath} +javac.compilerargs= +javadoc.noindex=false +javadoc.private=false +javadoc.author=false +endorsed.classpath= +main.class=Main +junit.selected.version=3 +source.encoding=UTF-8 +javac.source=16 +includes=** +javadoc.use=true +jar.compress=true +javadoc.nonavbar=false +annotation.processing.enabled.in.editor=false +javadoc.notree=false +annotation.processing.processors.list= +application.vendor=sharafat +javac.deprecation=false +jlink.launcher=true +javadoc.additionalparam= +jlink.launcher.name=USB Worm Protection +build.generated.sources.dir=${build.dir}/generated-sources +javadoc.splitindex=true +javac.processormodulepath= +run.jvmargs= +jlink.additionalmodules= +javadoc.encoding=${source.encoding} +javac.classpath= +mkdist.disabled=false +run.test.modulepath=\ + ${javac.test.modulepath} +build.classes.excludes=**/*.java,**/*.form +dist.jlink.dir=${dist.dir}/jlink +dist.jar=${dist.dir}/USB_Worm_Protection.jar +build.classes.dir=${build.dir}/classes +debug.test.modulepath=${run.test.modulepath} +build.test.classes.dir=${build.dir}/test/classes +javadoc.windowtitle= +build.test.results.dir=${build.dir}/test/results +dist.dir=dist +build.dir=build +dist.archive.excludes= +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.generated.dir=${build.dir}/generated +javadoc.version=false +application.title=USB Worm Protection +javac.test.modulepath=\ + ${javac.modulepath} +debug.test.classpath=${run.test.classpath} +javac.external.vm=true +javac.target=16 +platform.active=default_platform +manifest.file=manifest.mf +javadoc.html5=false +javac.test.processorpath=${javac.test.classpath} +meta.inf.dir=${src.dir}/META-INF +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +dist.jlink.output=${dist.jlink.dir}/USB_Worm_Protection +annotation.processing.run.all.processors=true +javac.modulepath= +jlink.additionalparam= +debug.classpath=${run.classpath} +test.test.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..1c09b65 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,18 @@ + + + org.netbeans.modules.java.j2seproject + + + USB Worm Protection + + + + + + + + + ./lib/nblibraries.properties + + + diff --git a/src/About.form b/src/About.form new file mode 100644 index 0000000..9c6100f --- /dev/null +++ b/src/About.form @@ -0,0 +1,111 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/About.java b/src/About.java new file mode 100644 index 0000000..7bcd7e9 --- /dev/null +++ b/src/About.java @@ -0,0 +1,172 @@ +/* + * About.java + * + * Created on July 23, 2008, 12:37 PM + */ + +import java.net.URI; +import java.awt.*; + +/** + * + * @author Sharafat + */ +public class About extends javax.swing.JPanel { + + /** Creates new form About */ + public About() { + initComponents(); + if (Desktop.isDesktopSupported()) { + desktop = Desktop.getDesktop(); + } + } + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + licence = new javax.swing.JLabel(); + website = new javax.swing.JLabel(); + email = new javax.swing.JLabel(); + heading = new javax.swing.JLabel(); + logo = new javax.swing.JLabel(); + jLabel1 = new javax.swing.JLabel(); + + setBackground(new java.awt.Color(255, 255, 255)); + + licence.setText("License Agreement:
You are free to copy, modify and redistribute this program provided that -
  1. Commercial transactions might not be involved.
  2. If you modify this program, you must include at least the following line in the About section:

    \"Original software credit: Sharafat Ibn Mollah Mosharraf (www.sharafat.co.uk)\"

"); + + website.setText("www.sharafat.co.uk"); + website.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + websiteMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + websiteMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + websiteMouseExited(evt); + } + }); + + email.setText("sharafat_8271@yahoo.co.uk"); + email.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + emailMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + emailMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + emailMouseExited(evt); + } + }); + + heading.setText("

USB Worm Protection

Version: 1.2 Build 2021.07.26"); + heading.setVerticalAlignment(javax.swing.SwingConstants.TOP); + + logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/USBWP_logo.png"))); // NOI18N + logo.setVerticalAlignment(javax.swing.SwingConstants.TOP); + + jLabel1.setText("Crafted with Love by:
Sharafat Ibn Mollah Mosharraf
Founder & CEO, Eximus Technologies
www.eximustech.com"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(29, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(website) + .addGroup(layout.createSequentialGroup() + .addComponent(logo) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(heading, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(licence, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(10, 10, 10)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(logo) + .addComponent(heading)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel1) + .addGap(0, 0, 0) + .addComponent(email) + .addGap(0, 0, 0) + .addComponent(website) + .addGap(18, 18, 18) + .addComponent(licence) + .addContainerGap()) + ); + + website.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + }//
//GEN-END:initComponents + +private void emailMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_emailMouseClicked + if (desktop.isSupported(Desktop.Action.MAIL)) { + try { + uri = new URI("mailto", "sharafat_8271@yahoo.co.uk", null); + desktop.mail(uri); + } catch (Exception ex) {} + } +}//GEN-LAST:event_emailMouseClicked + +private void emailMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_emailMouseEntered + if (desktop.isSupported(Desktop.Action.MAIL)) { + email.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + email.setForeground(Color.RED); + } +}//GEN-LAST:event_emailMouseEntered + +private void websiteMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_websiteMouseEntered + if (desktop.isSupported(Desktop.Action.MAIL)) { + website.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + website.setForeground(Color.RED); + } +}//GEN-LAST:event_websiteMouseEntered + +private void websiteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_websiteMouseClicked + if (desktop.isSupported(Desktop.Action.BROWSE)) { + try { + uri = new URI("http://www.sharafat.co.uk"); + desktop.browse(uri); + } catch (Exception ex) {} + } +}//GEN-LAST:event_websiteMouseClicked + +private void websiteMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_websiteMouseExited + if (desktop != null) { + website.setForeground(Color.BLACK); + } +}//GEN-LAST:event_websiteMouseExited + +private void emailMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_emailMouseExited + if (desktop != null) { + email.setForeground(Color.BLACK); + } +}//GEN-LAST:event_emailMouseExited + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel email; + private javax.swing.JLabel heading; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel licence; + private javax.swing.JLabel logo; + private javax.swing.JLabel website; + // End of variables declaration//GEN-END:variables + + // Custom Field declarations + private Desktop desktop; + private URI uri; +} diff --git a/src/DetectRemovableDevices.java b/src/DetectRemovableDevices.java new file mode 100644 index 0000000..b685884 --- /dev/null +++ b/src/DetectRemovableDevices.java @@ -0,0 +1,146 @@ +import java.util.ArrayList; +import java.io.File; +import javax.swing.filechooser.FileSystemView; + +/** + * + * @author Sharafat + */ +public class DetectRemovableDevices implements Runnable { + public Thread t; + private ScansManager scansManager; + private boolean isProtectionEnabled = true; + private ArrayList permanentDrives = new ArrayList(10); + private ArrayList newDrives = new ArrayList(10); + private ArrayList detectedDrives = new ArrayList(10); + private File[] currentDrives; + + DetectRemovableDevices(ScansManager scansManager) { + this.scansManager = scansManager; + t = new Thread(this, "Removable Media Detection"); + t.start(); + } + + public void run() { + // Detect currently attached drives and treat those as permanent drives + File[] permaDrives = File.listRoots(); + for (File drive : permaDrives) { + String description = FileSystemView.getFileSystemView().getSystemTypeDescription(drive); + if (description != null && "Local Disk".equalsIgnoreCase(description)) { + permanentDrives.add(drive); + } + } + + // Start detecting removable devices + while (isProtectionEnabled) { + continuouslyDetectRemovableDevices(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) {} + } + } + + private void continuouslyDetectRemovableDevices() { + currentDrives = File.listRoots(); + + if ((currentDrives.length - detectedDrives.size()) < permanentDrives.size()) { + boolean notPresentInDetectedDrives = true; + for (int i = 0; i < detectedDrives.size(); i++) { + File testPresenceOfDetectedDrives = detectedDrives.get(i); + if (!testPresenceOfDetectedDrives.exists()) { + notPresentInDetectedDrives = false; + detectedDrives.remove(i); + } + } + if (notPresentInDetectedDrives) { + for (int i = 0; i < permanentDrives.size(); i++) { + boolean isInCurrentDrives = false; + for (int j = 0; j < currentDrives.length; j++) { + if (permanentDrives.get(i).toString() + .equals(currentDrives[j].getAbsolutePath())) { + isInCurrentDrives = true; + break; + } + } + if (!isInCurrentDrives) { + permanentDrives.remove(i--); + if (i < 0) { + i = 0; + } + } + } + } + return; + } else if ((currentDrives.length - detectedDrives.size()) > permanentDrives.size()) { + //Detect newly added drives + int j = 0; + for (int i = 0; i < currentDrives.length; i++) { + try { + if (!permanentDrives.get(j).toString() + .equals(currentDrives[i].toString())) { + boolean isAvailableInDetectedDrives = false; + for (int k = 0; k < detectedDrives.size(); k++) { + if (detectedDrives.get(k).toString() + .equals(currentDrives[i].toString())) { + isAvailableInDetectedDrives = true; + break; + } + } + if (!isAvailableInDetectedDrives) { + newDrives.add(currentDrives[i]); + } + continue; + } + } catch (IndexOutOfBoundsException e) { + boolean isAvailableInDetectedDrives = false; + for (int k = 0; k < detectedDrives.size(); k++) { + if (detectedDrives.get(k).toString().equals(currentDrives[i].toString())) { + isAvailableInDetectedDrives = true; + break; + } + } + if (!isAvailableInDetectedDrives) { + newDrives.add(currentDrives[i]); + } + } + j++; + } + + //Start scanning newly added drives + int newDrivesSize = newDrives.size(); + for (int i = 0; i < newDrivesSize; i++) { + // Check for drives without disks, e.g., card readers without memory cards inserted + if (FileSystemView.getFileSystemView().getSystemDisplayName(newDrives.get(0)).equals("")) { + detectedDrives.add(newDrives.get(0)); + newDrives.remove(0); + continue; + } + + // If the new drive is scannable, call ScansManager for scanning + String driveType = FileSystemView.getFileSystemView() + .getSystemTypeDescription(newDrives.get(0)); + if (driveType != null + && (driveType.equalsIgnoreCase("Local Disk") + || driveType.equalsIgnoreCase("Removable Disk") + || driveType.equalsIgnoreCase("USB Drive") + || driveType.equalsIgnoreCase("Network Drive"))) { + scansManager.performScan(newDrives.get(0)); + } + + // Mark this drive as detected + detectedDrives.add(newDrives.get(0)); + newDrives.remove(0); + } + } + + } + + public void disableProtection(){ + isProtectionEnabled = false; + } + + public void enableProtection(){ + isProtectionEnabled = true; + } + +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..54b4f5c --- /dev/null +++ b/src/Main.java @@ -0,0 +1,112 @@ +import javax.swing.*; +import java.io.*; + +/** + * + * @author Sharafat + */ +public class Main { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + // Set Windows Look-&-Feel + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception e) {} + + // Construct the preferences panel + PreferencesPanel prefPanel = new PreferencesPanel(); + + // Load the default preference values + boolean shouldDoSilentScan = true; + int suspectedFileAction = 0; // 0 = Prompt, 1 = Delete, 2 = Quarantine, 3 = Leave + int protectionEnableStatus = 0; // 0 = Enabled or Enable at next program restart, + // 1 = Enable at user request only + boolean shouldShowSlideInScanDialog = true; + boolean shouldRemoveSlideInDialogAfterScan = false; + boolean shouldAlwaysDisplayScanDetails = false; + + // Change the default preference values if necessary + File prefFile = new File("preferences.dat"); + boolean prefFileExists = prefFile.exists(); + if (prefFileExists) { + // Read the preferences and set the values + Preferences preferences = new Preferences(); + ObjectInputStream obin = null; + try { + obin = new ObjectInputStream(new FileInputStream("preferences.dat")); + preferences = (Preferences) obin.readObject(); + + shouldDoSilentScan = preferences.shouldDoSilentScan; + suspectedFileAction = preferences.suspectedFileAction; + protectionEnableStatus = preferences.protectionEnableStatus; + shouldShowSlideInScanDialog = preferences.shouldShowSlideInScanDialog; + shouldRemoveSlideInDialogAfterScan = preferences.shouldRemoveSlideInDialogAfterScan; + shouldAlwaysDisplayScanDetails = preferences.shouldAlwaysDisplayScanDetails; + } catch (Exception e) { + } finally { + try { + obin.close(); + } catch (Exception e) {} + } + + // Modify the preferences panel according to user's selected preferences + prefPanel.setPreferences(preferences); + } + + // Start Scans Manager + Object[] param = {shouldDoSilentScan, suspectedFileAction, shouldShowSlideInScanDialog, + shouldRemoveSlideInDialogAfterScan, shouldAlwaysDisplayScanDetails}; + + ScansManager scansManager = new ScansManager(param); + + // Construct the Scan and About panels + ScanPanel scanPanel = new ScanPanel(scansManager); + About aboutPanel = new About(); + + // Construct the main window + MainWindow mainWindow = new MainWindow(aboutPanel, scanPanel, prefPanel); + + // Start detecting removable devices + DetectRemovableDevices detectRemDev = new DetectRemovableDevices(scansManager); + + // Construct the system tray according to protection status + if (protectionEnableStatus == 1) { // i.e. "Enable at user request only" + // Disable on-access protection + detectRemDev.disableProtection(); + + // Construct tray icon with the disabled icon + new ProgramTrayIcon(mainWindow, scansManager, detectRemDev, false); + + // Display a slide-in message warning the user about the disabled protection + SlideInDialog protectDisabledMsg = new SlideInDialog(); + protectDisabledMsg.bodyPanel.add(new JLabel( + "Protection against worms is disabled.", + new ImageIcon(getClass().getResource("/images/attention.png")), + SwingConstants.CENTER)); + protectDisabledMsg.background.setIcon(new ImageIcon(getClass() + .getResource("/images/background_yellow.png"))); + new SlideInNotification(protectDisabledMsg); + } else { + // Construct tray icon with the enabled icon + new ProgramTrayIcon(mainWindow, scansManager, detectRemDev, true); + } + + } + }); + } + + /** + * Method for checking another instance of the program. (Used by JavaExe) + * @param args + * @return true + */ + public static boolean isOneInstance(String[] args) { + return true; + }; + +} diff --git a/src/MainWindow.form b/src/MainWindow.form new file mode 100644 index 0000000..524db6b --- /dev/null +++ b/src/MainWindow.form @@ -0,0 +1,276 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/MainWindow.java b/src/MainWindow.java new file mode 100644 index 0000000..5edf389 --- /dev/null +++ b/src/MainWindow.java @@ -0,0 +1,315 @@ +/* + * MainWindow.java + * + * Created on July 23, 2008, 5:31 AM + */ + +import java.awt.*; + +/** + * + * @author Sharafat + */ +public class MainWindow extends javax.swing.JFrame { + About aboutPanel; + ScanPanel scanPanel; + PreferencesPanel prefPanel; + + /** Creates new form MainWindow + * @param aboutPanel The About Panel + * @param scanPanel The Scan Panel + * @param prefPanel The Preferences Panel + * @param scanFrame The Scan Frame + */ + public MainWindow(About aboutPanel, ScanPanel scanPanel, PreferencesPanel prefPanel) { + this.aboutPanel = aboutPanel; + this.scanPanel = scanPanel; + this.prefPanel = prefPanel; + initComponents(); + panel.add(scanPanel); + } + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + panel = new javax.swing.JPanel(); + jLayeredPane1 = new javax.swing.JLayeredPane(); + scanLbl = new javax.swing.JLabel(); + jLabel1 = new javax.swing.JLabel(); + jLayeredPane2 = new javax.swing.JLayeredPane(); + prefLbl = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + jLayeredPane3 = new javax.swing.JLayeredPane(); + aboutLbl = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + jLayeredPane4 = new javax.swing.JLayeredPane(); + title = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + + setTitle("USB Worm Protection"); + setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); + setIconImage(Toolkit.getDefaultToolkit().getImage(Main.class.getResource("images/icon.png"))); + setResizable(false); + + panel.setBackground(new java.awt.Color(255, 255, 255)); + panel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); + + scanLbl.setBackground(new java.awt.Color(255, 255, 255)); + scanLbl.setFont(new java.awt.Font("Arial", 1, 12)); + scanLbl.setForeground(new java.awt.Color(255, 255, 255)); + scanLbl.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/scan.png"))); // NOI18N + scanLbl.setText("Scan"); + scanLbl.setIconTextGap(7); + scanLbl.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + scanLblMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + scanLblMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + scanLblMouseExited(evt); + } + }); + scanLbl.setBounds(10, 0, 160, 27); + jLayeredPane1.add(scanLbl, javax.swing.JLayeredPane.DEFAULT_LAYER); + scanLbl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/header_blue.png"))); // NOI18N + jLabel1.setBounds(0, 0, 170, 27); + jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER); + + prefLbl.setBackground(new java.awt.Color(255, 255, 255)); + prefLbl.setFont(new java.awt.Font("Arial", 0, 12)); + prefLbl.setForeground(new java.awt.Color(255, 255, 255)); + prefLbl.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/preferences.png"))); // NOI18N + prefLbl.setText("Preferences"); + prefLbl.setIconTextGap(7); + prefLbl.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + prefLblMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + prefLblMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + prefLblMouseExited(evt); + } + }); + prefLbl.setBounds(10, 0, 160, 25); + jLayeredPane2.add(prefLbl, javax.swing.JLayeredPane.DEFAULT_LAYER); + prefLbl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/header_blue.png"))); // NOI18N + jLabel2.setBounds(0, 0, 170, 27); + jLayeredPane2.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER); + + aboutLbl.setBackground(new java.awt.Color(255, 255, 255)); + aboutLbl.setFont(new java.awt.Font("Arial", 0, 12)); + aboutLbl.setForeground(new java.awt.Color(255, 255, 255)); + aboutLbl.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/about.png"))); // NOI18N + aboutLbl.setText("About"); + aboutLbl.setIconTextGap(7); + aboutLbl.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + aboutLblMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + aboutLblMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + aboutLblMouseExited(evt); + } + }); + aboutLbl.setBounds(10, 0, 160, 27); + jLayeredPane3.add(aboutLbl, javax.swing.JLayeredPane.DEFAULT_LAYER); + aboutLbl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/header_blue.png"))); // NOI18N + jLabel3.setBounds(0, 0, 170, 27); + jLayeredPane3.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER); + + title.setBackground(new java.awt.Color(255, 255, 255)); + title.setFont(new java.awt.Font("Arial", 1, 12)); + title.setForeground(new java.awt.Color(255, 255, 255)); + title.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/scan.png"))); // NOI18N + title.setText("Scan"); + title.setIconTextGap(7); + title.setBounds(6, 0, 430, 27); + jLayeredPane4.add(title, javax.swing.JLayeredPane.DEFAULT_LAYER); + + jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/header_blue_2.png"))); // NOI18N + jLabel4.setBounds(0, 0, 436, 27); + jLayeredPane4.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER); + + 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(jLayeredPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE) + .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE) + .addComponent(jLayeredPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE) + .addComponent(jLayeredPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 436, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jLayeredPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLayeredPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + protected void scanLabelClicked() { + prefLbl.setFont(new Font("Arial", 0, 12)); + prefLbl.setText("Preferences"); + scanLbl.setFont(new Font("Arial", 1, 12)); + aboutLbl.setFont(new Font("Arial", 0, 12)); + aboutLbl.setText("About"); + + title.setIcon(new javax.swing.ImageIcon( + getClass().getResource("/images/scan.png"))); + title.setText("Scan"); + + scanPanel.displayDrives(); + panel.removeAll(); + validate(); + panel.repaint(); + panel.add(scanPanel); + } + + protected void preferencesLabelClicked() { + prefLbl.setFont(new Font("Arial", 1, 12)); + scanLbl.setFont(new Font("Arial", 0, 12)); + scanLbl.setText("Scan"); + aboutLbl.setFont(new Font("Arial", 0, 12)); + aboutLbl.setText("About"); + + title.setIcon(new javax.swing.ImageIcon( + getClass().getResource("/images/preferences.png"))); + title.setText("Preferences"); + + panel.removeAll(); + validate(); + panel.repaint(); + panel.add(prefPanel); + } + + protected void aboutLabelClicked() { + prefLbl.setFont(new Font("Arial", 0, 12)); + prefLbl.setText("Preferences"); + scanLbl.setFont(new Font("Arial", 0, 12)); + scanLbl.setText("Scan"); + aboutLbl.setFont(new Font("Arial", 1, 12)); + + title.setIcon(new javax.swing.ImageIcon( + getClass().getResource("/images/about.png"))); + title.setText("About"); + + panel.removeAll(); + validate(); + panel.repaint(); + panel.add(aboutPanel); + } + +private void scanLblMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_scanLblMouseClicked + scanLabelClicked(); +}//GEN-LAST:event_scanLblMouseClicked + +private void prefLblMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_prefLblMouseClicked + preferencesLabelClicked(); +}//GEN-LAST:event_prefLblMouseClicked + +private void aboutLblMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_aboutLblMouseClicked + aboutLabelClicked(); +}//GEN-LAST:event_aboutLblMouseClicked + +private void scanLblMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_scanLblMouseEntered + if (scanLbl.getFont().isBold()) { + scanLbl.setText("Scan"); + } else { + scanLbl.setText("Scan"); + } +}//GEN-LAST:event_scanLblMouseEntered + +private void scanLblMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_scanLblMouseExited + if (scanLbl.getFont().isBold()) { + scanLbl.setText("Scan"); + } else { + scanLbl.setText("Scan"); + } +}//GEN-LAST:event_scanLblMouseExited + +private void prefLblMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_prefLblMouseEntered + if (prefLbl.getFont().isBold()) { + prefLbl.setText("Preferences"); + } else { + prefLbl.setText("Preferences"); + } +}//GEN-LAST:event_prefLblMouseEntered + +private void prefLblMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_prefLblMouseExited + if (prefLbl.getFont().isBold()) { + prefLbl.setText("Preferences"); + } else { + prefLbl.setText("Preferences"); + } +}//GEN-LAST:event_prefLblMouseExited + +private void aboutLblMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_aboutLblMouseEntered + if (aboutLbl.getFont().isBold()) { + aboutLbl.setText("About"); + } else { + aboutLbl.setText("About"); + } +}//GEN-LAST:event_aboutLblMouseEntered + +private void aboutLblMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_aboutLblMouseExited + if (aboutLbl.getFont().isBold()) { + aboutLbl.setText("About"); + } else { + aboutLbl.setText("About"); + } +}//GEN-LAST:event_aboutLblMouseExited + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel aboutLbl; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLayeredPane jLayeredPane1; + private javax.swing.JLayeredPane jLayeredPane2; + private javax.swing.JLayeredPane jLayeredPane3; + private javax.swing.JLayeredPane jLayeredPane4; + protected javax.swing.JPanel panel; + private javax.swing.JLabel prefLbl; + private javax.swing.JLabel scanLbl; + private javax.swing.JLabel title; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/Main_SystemEventManagement.java b/src/Main_SystemEventManagement.java new file mode 100644 index 0000000..59129d0 Binary files /dev/null and b/src/Main_SystemEventManagement.java differ diff --git a/src/PauseProtection.form b/src/PauseProtection.form new file mode 100644 index 0000000..b254026 --- /dev/null +++ b/src/PauseProtection.form @@ -0,0 +1,309 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/PauseProtection.java b/src/PauseProtection.java new file mode 100644 index 0000000..bafea73 --- /dev/null +++ b/src/PauseProtection.java @@ -0,0 +1,406 @@ +/* + * PauseProtection.java + * + * Created on July 25, 2008, 1:42 PM + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.io.*; + +/** + * + * @author Sharafat + */ +public class PauseProtection extends javax.swing.JDialog { + private boolean[] isProtectionEnabled; + private MenuItem protectionStatus; + private DetectRemovableDevices detectRemDev; + private ScansManager scansManager; + protected Timer timer; + + /** Creates new form PauseProtection */ + public PauseProtection(Frame parent, boolean modal, Object[] param) { + super(parent, modal); + isProtectionEnabled = (boolean[]) param[0]; + protectionStatus = (MenuItem) param[1]; + detectRemDev = (DetectRemovableDevices) param[2]; + scansManager = (ScansManager) param[3]; + initComponents(); + } + + private void pauseProtection() { + isProtectionEnabled[0] = false; + protectionStatus.setLabel("Resume Protection"); + TrayIcon[] trayIcon = SystemTray.getSystemTray().getTrayIcons(); + trayIcon[0].setImage(new ImageIcon(Main.class.getResource( + "/images/disabledTrayIcon.png"), "Tray Icon (Disabled)").getImage()); + trayIcon[0].setToolTip("USB Worm Protection (Protection Disabled)"); + detectRemDev.disableProtection(); + } + + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + warning = new javax.swing.JLabel(); + cancel = new javax.swing.JButton(); + mainPanel = new javax.swing.JPanel(); + inPanel = new javax.swing.JLayeredPane(); + time = new javax.swing.JComboBox(); + inLabel = new javax.swing.JLabel(); + inHeadingLabel = new javax.swing.JLabel(); + jLabel1 = new javax.swing.JLabel(); + bgInPanel = new javax.swing.JLabel(); + nextPanel = new javax.swing.JLayeredPane(); + nextLabel = new javax.swing.JLabel(); + nextLabelHeading = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + bgNextPanel = new javax.swing.JLabel(); + userRequestPanel = new javax.swing.JLayeredPane(); + userRequestLabel = new javax.swing.JLabel(); + userRequestHeadingLabel = new javax.swing.JLabel(); + jLabel3 = new javax.swing.JLabel(); + bgUserReqPanel = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("USB Worm Protection"); + setName("pauseDialog"); // NOI18N + setResizable(false); + + warning.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/warning.png"))); // NOI18N + warning.setText("Protection will be suspended.
Enable protection again:Protection will be suspended; it will be resumed automatically in 1 minute."); + inLabel.setBounds(40, 30, 188, 32); + inPanel.add(inLabel, javax.swing.JLayeredPane.DEFAULT_LAYER); + + inHeadingLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + inHeadingLabel.setForeground(new java.awt.Color(0, 0, 153)); + inHeadingLabel.setText("In"); + inHeadingLabel.setBounds(40, 10, 12, 14); + inPanel.add(inHeadingLabel, javax.swing.JLayeredPane.DEFAULT_LAYER); + + jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/pauseDialog.png"))); // NOI18N + jLabel1.setBounds(10, 10, 20, 20); + inPanel.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER); + bgInPanel.setBounds(0, 0, 254, 70); + inPanel.add(bgInPanel, javax.swing.JLayeredPane.DEFAULT_LAYER); + + nextPanel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + nextPanelMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + nextPanelMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + nextPanelMouseExited(evt); + } + }); + + nextLabel.setText("Protection will be suspended until application restart."); + nextLabel.setBounds(40, 30, 188, 32); + nextPanel.add(nextLabel, javax.swing.JLayeredPane.DEFAULT_LAYER); + + nextLabelHeading.setFont(new java.awt.Font("Tahoma", 1, 11)); + nextLabelHeading.setForeground(new java.awt.Color(0, 0, 153)); + nextLabelHeading.setText("At next program restart"); + nextLabelHeading.setBounds(40, 10, 137, 14); + nextPanel.add(nextLabelHeading, javax.swing.JLayeredPane.DEFAULT_LAYER); + + jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/pauseDialog.png"))); // NOI18N + jLabel2.setBounds(10, 10, 20, 20); + nextPanel.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER); + bgNextPanel.setBounds(0, 0, 254, 70); + nextPanel.add(bgNextPanel, javax.swing.JLayeredPane.DEFAULT_LAYER); + + userRequestPanel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + userRequestPanelMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + userRequestPanelMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + userRequestPanelMouseExited(evt); + } + }); + + userRequestLabel.setText("Protection will be suspended until the user enables it again."); + userRequestLabel.setBounds(40, 30, 188, 32); + userRequestPanel.add(userRequestLabel, javax.swing.JLayeredPane.DEFAULT_LAYER); + + userRequestHeadingLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); + userRequestHeadingLabel.setForeground(new java.awt.Color(0, 0, 153)); + userRequestHeadingLabel.setText("By user request only"); + userRequestHeadingLabel.setBounds(40, 10, 116, 14); + userRequestPanel.add(userRequestHeadingLabel, javax.swing.JLayeredPane.DEFAULT_LAYER); + + jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/pauseDialog.png"))); // NOI18N + jLabel3.setBounds(10, 10, 20, 20); + userRequestPanel.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER); + bgUserReqPanel.setBounds(0, 0, 254, 70); + userRequestPanel.add(bgUserReqPanel, javax.swing.JLayeredPane.DEFAULT_LAYER); + + javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(userRequestPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE) + .addComponent(nextPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(inPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)) + .addContainerGap()) + ); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(inPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(nextPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(userRequestPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 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() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(warning) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(cancel) + .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(12, Short.MAX_VALUE) + .addComponent(warning) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(cancel) + .addContainerGap()) + ); + + pack(); + }//
//GEN-END:initComponents + +private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed + dispose(); +}//GEN-LAST:event_cancelActionPerformed + +private void timeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timeActionPerformed +inLabel.setText("Protection will be suspended; it will be resumed automatically in " + + time.getSelectedItem().toString() + "."); +}//GEN-LAST:event_timeActionPerformed + +private void inPanelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_inPanelMouseEntered + setCursor(new Cursor(Cursor.HAND_CURSOR)); + bgInPanel.setIcon(new ImageIcon(getClass().getResource("/images/overlay.png"))); +}//GEN-LAST:event_inPanelMouseEntered + +private void inPanelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_inPanelMouseExited + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + bgInPanel.setIcon(null); +}//GEN-LAST:event_inPanelMouseExited + +private void nextPanelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nextPanelMouseEntered + setCursor(new Cursor(Cursor.HAND_CURSOR)); + bgNextPanel.setIcon(new ImageIcon(getClass().getResource("/images/overlay.png"))); +}//GEN-LAST:event_nextPanelMouseEntered + +private void nextPanelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nextPanelMouseExited + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + bgNextPanel.setIcon(null); +}//GEN-LAST:event_nextPanelMouseExited + +private void userRequestPanelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_userRequestPanelMouseEntered + setCursor(new Cursor(Cursor.HAND_CURSOR)); + bgUserReqPanel.setIcon(new ImageIcon(getClass().getResource("/images/overlay.png"))); +}//GEN-LAST:event_userRequestPanelMouseEntered + +private void userRequestPanelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_userRequestPanelMouseExited + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + bgUserReqPanel.setIcon(null); +}//GEN-LAST:event_userRequestPanelMouseExited + +private void inPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_inPanelMouseClicked + // Get duration of disabling protection + int duration = 0; + switch (time.getSelectedIndex()) { + case 0 : duration = 1 * 60 * 1000; break; // 1 min. + case 1 : duration = 3 * 60 * 1000; break; // 3 min. + case 2 : duration = 5 * 60 * 1000; break; // 5 min. + case 3 : duration = 10 * 60 * 1000; break; // 10 min. + case 4 : duration = 15 * 60 * 1000; break; // 15 min. + case 5 : duration = 30 * 60 * 1000; break; // 30 min + case 6 : duration = 1 * 60 * 60 * 1000; break; // 1 hour + case 7 : duration = 3 * 60 * 60 * 1000; break; // 3 hour + case 8 : duration = 5 * 60 * 60 * 1000; // 5 hour + } + + // Start timer + ActionListener timerTaskPerformer = new ActionListener() { + public void actionPerformed(ActionEvent evt) { + isProtectionEnabled[0] = true; + protectionStatus.setLabel("Disable Protection"); + TrayIcon[] trayIcon = SystemTray.getSystemTray().getTrayIcons(); + trayIcon[0].setImage(new ImageIcon(Main.class.getResource("/images/icon.png"), + "Tray Icon").getImage()); + trayIcon[0].setToolTip("USB Worm Protection"); + detectRemDev = new DetectRemovableDevices(scansManager); + + // Notify user of the enabling of protection + SlideInDialog protectDisabledMsg = new SlideInDialog(); + protectDisabledMsg.bodyPanel.add(new JLabel( + "Protection against worms is enabled.", + new ImageIcon(getClass().getResource("/images/info.png")), + SwingConstants.CENTER)); + new SlideInNotification(protectDisabledMsg); + } + }; + timer = new Timer(duration, timerTaskPerformer); + timer.setRepeats(false); + timer.start(); + + // Write in file the protection status + writeProtectionStatus(0); + + // Disable protection + pauseProtection(); + + // Dispose the dialog + dispose(); +}//GEN-LAST:event_inPanelMouseClicked + +private void nextPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nextPanelMouseClicked + // Write in file the protection status + writeProtectionStatus(0); + + // Disable protection + pauseProtection(); + + // Dispose the dialog + dispose(); +}//GEN-LAST:event_nextPanelMouseClicked + +private void userRequestPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_userRequestPanelMouseClicked + // Write in file the protection status + writeProtectionStatus(1); + + // Disable protection + pauseProtection(); + + // Dispose the dialog + dispose(); +}//GEN-LAST:event_userRequestPanelMouseClicked + +private void writeProtectionStatus(int status) { + File prefFile = new File("preferences.dat"); + boolean prefFileExists = prefFile.exists(); + Preferences preferences = new Preferences(); + if (prefFileExists) { + ObjectInputStream obin = null; + ObjectOutputStream obout = null; + try { + obin = new ObjectInputStream(new FileInputStream("preferences.dat")); + preferences = (Preferences) obin.readObject(); + obin.close(); + preferences.protectionEnableStatus = status; + obout = new ObjectOutputStream(new FileOutputStream("preferences.dat")); + obout.writeObject(preferences); + } catch (Exception e) { + } finally { + try { + obout.close(); + obin.close(); + } catch (Exception e) {} + } + } else { + ObjectOutputStream obout = null; + try { + preferences.protectionEnableStatus = status; + obout = new ObjectOutputStream(new FileOutputStream("preferences.dat")); + obout.writeObject(preferences); + } catch (Exception e) { + } finally { + try { + obout.close(); + } catch (Exception e) {} + } + } +} + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel bgInPanel; + private javax.swing.JLabel bgNextPanel; + private javax.swing.JLabel bgUserReqPanel; + private javax.swing.JButton cancel; + private javax.swing.JLabel inHeadingLabel; + private javax.swing.JLabel inLabel; + private javax.swing.JLayeredPane inPanel; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JPanel mainPanel; + private javax.swing.JLabel nextLabel; + private javax.swing.JLabel nextLabelHeading; + private javax.swing.JLayeredPane nextPanel; + private javax.swing.JComboBox time; + private javax.swing.JLabel userRequestHeadingLabel; + private javax.swing.JLabel userRequestLabel; + private javax.swing.JLayeredPane userRequestPanel; + private javax.swing.JLabel warning; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/Preferences.java b/src/Preferences.java new file mode 100644 index 0000000..26af2e8 --- /dev/null +++ b/src/Preferences.java @@ -0,0 +1,11 @@ +import java.io.Serializable; + +public class Preferences implements Serializable { + boolean shouldDoSilentScan = true; + int suspectedFileAction = 0; // 0 = Prompt, 1 = Delete, 2 = Quarantine, 3 = Leave + int protectionEnableStatus = 0; // 0 = Enabled or Enable at next program restart, + // 1 = Enable at user request only + boolean shouldShowSlideInScanDialog = true; + boolean shouldRemoveSlideInDialogAfterScan = false; + boolean shouldAlwaysDisplayScanDetails = false; +} \ No newline at end of file diff --git a/src/PreferencesPanel.form b/src/PreferencesPanel.form new file mode 100644 index 0000000..9a543ee --- /dev/null +++ b/src/PreferencesPanel.form @@ -0,0 +1,321 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/PreferencesPanel.java b/src/PreferencesPanel.java new file mode 100644 index 0000000..476e0b2 --- /dev/null +++ b/src/PreferencesPanel.java @@ -0,0 +1,495 @@ +/* + * PreferencesPanel.java + * + * Created on July 23, 2008, 9:27 PM + */ + +import java.io.*; +import javax.swing.*; + +/** + * + * @author Sharafat + */ +public class PreferencesPanel extends javax.swing.JPanel { + + /** Creates new form PreferencesPanel */ + public PreferencesPanel() { + initComponents(); + } + + void setPreferences(Preferences preferences) { + if (!preferences.shouldDoSilentScan) { + silentScan.setSelected(false); + } + if (preferences.suspectedFileAction == 1) { + promptSuspect.setSelected(false); + delSuspect.setSelected(true); + } else if (preferences.suspectedFileAction == 2) { + promptSuspect.setSelected(false); + quarantineSuspect.setSelected(true); + } else if (preferences.suspectedFileAction == 3) { + promptSuspect.setSelected(false); + leaveSuspect.setSelected(true); + } + if (!preferences.shouldShowSlideInScanDialog) { + showSlidingMsg.setSelected(false); + } + if (preferences.shouldRemoveSlideInDialogAfterScan) { + removeSlidingMsg.setSelected(true); + } + if (preferences.shouldAlwaysDisplayScanDetails) { + displayScanWindow.setSelected(true); + } + } + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + suspectActionGroup = new javax.swing.ButtonGroup(); + explanationPanel = new javax.swing.JPanel(); + explanation = new javax.swing.JLabel(); + jPanel1 = new javax.swing.JPanel(); + delSuspect = new javax.swing.JRadioButton(); + silentScan = new javax.swing.JCheckBox(); + quarantineSuspect = new javax.swing.JRadioButton(); + leaveSuspect = new javax.swing.JRadioButton(); + promptSuspect = new javax.swing.JCheckBox(); + balloonMsgDisplay = new javax.swing.JPanel(); + removeSlidingMsg = new javax.swing.JCheckBox(); + showSlidingMsg = new javax.swing.JCheckBox(); + displayScanWindow = new javax.swing.JCheckBox(); + save = new javax.swing.JButton(); + + setBackground(new java.awt.Color(255, 255, 255)); + + explanationPanel.setBackground(new java.awt.Color(255, 255, 255)); + explanationPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Explanation")); + + explanation.setVerticalAlignment(javax.swing.SwingConstants.TOP); + + javax.swing.GroupLayout explanationPanelLayout = new javax.swing.GroupLayout(explanationPanel); + explanationPanel.setLayout(explanationPanelLayout); + explanationPanelLayout.setHorizontalGroup( + explanationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(explanation, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE) + ); + explanationPanelLayout.setVerticalGroup( + explanationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(explanation, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE) + ); + + jPanel1.setBackground(new java.awt.Color(255, 255, 255)); + jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Scanning Options")); + + delSuspect.setBackground(new java.awt.Color(255, 255, 255)); + suspectActionGroup.add(delSuspect); + delSuspect.setMnemonic('D'); + delSuspect.setText("Delete all suspected files"); + delSuspect.setEnabled(false); + delSuspect.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + delSuspect.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + delSuspectMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + delSuspectMouseExited(evt); + } + }); + + silentScan.setBackground(new java.awt.Color(255, 255, 255)); + silentScan.setMnemonic('I'); + silentScan.setSelected(true); + silentScan.setText("Silent scan (Recommended)"); + silentScan.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + silentScanMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + silentScanMouseExited(evt); + } + }); + + quarantineSuspect.setBackground(new java.awt.Color(255, 255, 255)); + suspectActionGroup.add(quarantineSuspect); + quarantineSuspect.setMnemonic('Q'); + quarantineSuspect.setText("Quarantine all suspected files"); + quarantineSuspect.setEnabled(false); + quarantineSuspect.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + quarantineSuspect.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + quarantineSuspectMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + quarantineSuspectMouseExited(evt); + } + }); + + leaveSuspect.setBackground(new java.awt.Color(255, 255, 255)); + suspectActionGroup.add(leaveSuspect); + leaveSuspect.setMnemonic('L'); + leaveSuspect.setSelected(true); + leaveSuspect.setText("Leave all suspected files"); + leaveSuspect.setEnabled(false); + leaveSuspect.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + leaveSuspect.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + leaveSuspectMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + leaveSuspectMouseExited(evt); + } + }); + + promptSuspect.setBackground(new java.awt.Color(255, 255, 255)); + promptSuspect.setMnemonic('P'); + promptSuspect.setSelected(true); + promptSuspect.setText("Prompt for action against suspected files (Highly Recommended)"); + promptSuspect.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + promptSuspectMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + promptSuspectMouseExited(evt); + } + }); + promptSuspect.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + promptSuspectStateChanged(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(promptSuspect) + .addComponent(silentScan) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(21, 21, 21) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(delSuspect) + .addComponent(leaveSuspect) + .addComponent(quarantineSuspect, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addContainerGap(53, Short.MAX_VALUE)) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(silentScan) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(promptSuspect) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(delSuspect) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(quarantineSuspect) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(leaveSuspect)) + ); + + jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {delSuspect, leaveSuspect, quarantineSuspect}); + + balloonMsgDisplay.setBackground(new java.awt.Color(255, 255, 255)); + balloonMsgDisplay.setBorder(javax.swing.BorderFactory.createTitledBorder("Scan Notification Options")); + balloonMsgDisplay.setName("balloonMsgDisplay"); // NOI18N + + removeSlidingMsg.setBackground(new java.awt.Color(255, 255, 255)); + removeSlidingMsg.setMnemonic('F'); + removeSlidingMsg.setText("Remove slide-in dialogs after scanning is finished"); + removeSlidingMsg.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + removeSlidingMsg.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + removeSlidingMsgMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + removeSlidingMsgMouseExited(evt); + } + }); + + showSlidingMsg.setBackground(new java.awt.Color(255, 255, 255)); + showSlidingMsg.setMnemonic('E'); + showSlidingMsg.setSelected(true); + showSlidingMsg.setText("Show scanning progress in slide-in dialog form"); + showSlidingMsg.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + showSlidingMsg.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + showSlidingMsgMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + showSlidingMsgMouseExited(evt); + } + }); + showSlidingMsg.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + showSlidingMsgStateChanged(evt); + } + }); + + displayScanWindow.setBackground(new java.awt.Color(255, 255, 255)); + displayScanWindow.setMnemonic('A'); + displayScanWindow.setText("Always display Scanning Details window"); + displayScanWindow.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + displayScanWindow.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseEntered(java.awt.event.MouseEvent evt) { + displayScanWindowMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + displayScanWindowMouseExited(evt); + } + }); + + javax.swing.GroupLayout balloonMsgDisplayLayout = new javax.swing.GroupLayout(balloonMsgDisplay); + balloonMsgDisplay.setLayout(balloonMsgDisplayLayout); + balloonMsgDisplayLayout.setHorizontalGroup( + balloonMsgDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(balloonMsgDisplayLayout.createSequentialGroup() + .addContainerGap() + .addGroup(balloonMsgDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(showSlidingMsg) + .addComponent(removeSlidingMsg) + .addComponent(displayScanWindow)) + .addContainerGap(127, Short.MAX_VALUE)) + ); + balloonMsgDisplayLayout.setVerticalGroup( + balloonMsgDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(balloonMsgDisplayLayout.createSequentialGroup() + .addComponent(showSlidingMsg) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(removeSlidingMsg) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(displayScanWindow)) + ); + + save.setBackground(new java.awt.Color(255, 255, 255)); + save.setMnemonic('C'); + save.setText("Save Changes"); + save.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + saveActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.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(explanationPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(balloonMsgDisplay, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(save)) + .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) + .addGap(2, 2, 2) + .addComponent(balloonMsgDisplay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(2, 2, 2) + .addComponent(explanationPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(save)) + ); + }// //GEN-END:initComponents + +private void silentScanMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_silentScanMouseEntered + explanation.setText("

Silent scan
Automatically " + + "deletes detected worm files if selected. " + + "Prompts for action if not selected.
Recommended for most general users.

"); +}//GEN-LAST:event_silentScanMouseEntered + +private void silentScanMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_silentScanMouseExited + explanation.setText(""); +}//GEN-LAST:event_silentScanMouseExited + +private void promptSuspectMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_promptSuspectMouseEntered + explanation.setText("

Prompt for action against suspected " + + "files
If selected, the program will display those files which it suspects as worms, " + + "but is not confident enough to delete them.
It is highly recommended to select this " + + "option as some of those files might be worm files and leaving them might result in " + + "worm attack; or, some of those files migt be genuine files and deleting them might cause " + + "loss of data.

"); +}//GEN-LAST:event_promptSuspectMouseEntered + +private void promptSuspectMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_promptSuspectMouseExited + explanation.setText(""); +}//GEN-LAST:event_promptSuspectMouseExited + +private void delSuspectMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_delSuspectMouseEntered + explanation.setText("Delete all suspected files
" + + "Deletes all suspected files without user's approval."); +}//GEN-LAST:event_delSuspectMouseEntered + +private void delSuspectMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_delSuspectMouseExited + explanation.setText(""); +}//GEN-LAST:event_delSuspectMouseExited + +private void quarantineSuspectMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_quarantineSuspectMouseEntered + explanation.setText("Quarantine all suspected files
" + + "Quarantines all suspected files without user's approval."); +}//GEN-LAST:event_quarantineSuspectMouseEntered + +private void quarantineSuspectMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_quarantineSuspectMouseExited + explanation.setText(""); +}//GEN-LAST:event_quarantineSuspectMouseExited + +private void leaveSuspectMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_leaveSuspectMouseEntered + explanation.setText("Leave all suspected files
" + + "Leaves all suspected files as they are."); +}//GEN-LAST:event_leaveSuspectMouseEntered + +private void leaveSuspectMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_leaveSuspectMouseExited + explanation.setText(""); +}//GEN-LAST:event_leaveSuspectMouseExited + +private void removeSlidingMsgMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeSlidingMsgMouseEntered + explanation.setText("

Remove slide-in dialogs after scanning is finished
" + + "If checked, removes the scanning progress slide-in dialogs at the end of scanning." + + "
If unchecked, keeps the dialogs on-screen even after scanning is finished.

"); +}//GEN-LAST:event_removeSlidingMsgMouseEntered + +private void removeSlidingMsgMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeSlidingMsgMouseExited + explanation.setText(""); +}//GEN-LAST:event_removeSlidingMsgMouseExited + +private void displayScanWindowMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_displayScanWindowMouseEntered + explanation.setText("

Always display Scanning Details window
" + + "If checked, the Scanning Details window will be displayed " + + "whenever scanning a USB mass storage device is started.
If this option is unchecked, however, the window can " + + "still be accessed anytime from the main window or by clicking on the \"Details\" link on the slide-in dialogs.

"); +}//GEN-LAST:event_displayScanWindowMouseEntered + +private void displayScanWindowMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_displayScanWindowMouseExited + explanation.setText(""); +}//GEN-LAST:event_displayScanWindowMouseExited + +private void showSlidingMsgMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showSlidingMsgMouseEntered + explanation.setText("

Show scanning progress in slide-in dialog form
" + + "If selected, a slide-in dialog appears at the bottom-right corner of the screen " + + "whenever a new drive is detected. The dialog displays the scanning progress of the current " + + "drive.
If this option is unchecked, the user will not be notified of the commence of a " + + "scan unless the \"Always display Scanning Details window\" option is selected.

"); +}//GEN-LAST:event_showSlidingMsgMouseEntered + +private void showSlidingMsgMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showSlidingMsgMouseExited + explanation.setText(""); +}//GEN-LAST:event_showSlidingMsgMouseExited + +private void promptSuspectStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_promptSuspectStateChanged + if (promptSuspect.isSelected()) { + delSuspect.setEnabled(false); + quarantineSuspect.setEnabled(false); + leaveSuspect.setEnabled(false); + } else { + delSuspect.setEnabled(true); + quarantineSuspect.setEnabled(true); + leaveSuspect.setEnabled(true); + } +}//GEN-LAST:event_promptSuspectStateChanged + +private void showSlidingMsgStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_showSlidingMsgStateChanged + if (showSlidingMsg.isSelected()) { + removeSlidingMsg.setEnabled(true); + } else { + removeSlidingMsg.setEnabled(false); + } +}//GEN-LAST:event_showSlidingMsgStateChanged + +private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed + Preferences preferences = new Preferences(); + + File prefFile = new File("preferences.dat"); + boolean prefFileExists = prefFile.exists(); + if (prefFileExists) { + ObjectInputStream obin = null; + try { + obin = new ObjectInputStream(new FileInputStream("preferences.dat")); + preferences = (Preferences) obin.readObject(); + } catch (Exception e) { + } finally { + try { + obin.close(); + } catch (Exception e) {} + } + } + + if (silentScan.isSelected()) { + preferences.shouldDoSilentScan = true; + } else { + preferences.shouldDoSilentScan = false; + } + + if (promptSuspect.isSelected()) { + preferences.suspectedFileAction = 0; + } else if (delSuspect.isSelected()) { + preferences.suspectedFileAction = 1; + } else if (quarantineSuspect.isSelected()) { + preferences.suspectedFileAction = 2; + } else { + preferences.suspectedFileAction = 3; + } + + if (showSlidingMsg.isSelected()){ + preferences.shouldShowSlideInScanDialog = true; + } else { + preferences.shouldShowSlideInScanDialog = false; + } + + if (removeSlidingMsg.isSelected()) { + preferences.shouldRemoveSlideInDialogAfterScan = true; + } else { + preferences.shouldRemoveSlideInDialogAfterScan = false; + } + + if (displayScanWindow.isSelected()) { + preferences.shouldAlwaysDisplayScanDetails = true; + } else { + preferences.shouldAlwaysDisplayScanDetails = false; + } + + ObjectOutputStream obout = null; + try { + obout = new ObjectOutputStream(new FileOutputStream("preferences.dat")); + obout.writeObject(preferences); + } catch (IOException e) { + JOptionPane.showMessageDialog(this, "Error: Cannot save preferences:\n" + e, + "USB Worm Protection", JOptionPane.ERROR_MESSAGE); + } finally { + try { + obout.close(); + } catch (IOException e) {} + } + + JOptionPane.showMessageDialog(this, "Changes will take effect the next time" + + " USB Worm Protection is started.", "USB Worm Protection", + JOptionPane.INFORMATION_MESSAGE); +}//GEN-LAST:event_saveActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel balloonMsgDisplay; + private javax.swing.JRadioButton delSuspect; + private javax.swing.JCheckBox displayScanWindow; + private javax.swing.JLabel explanation; + private javax.swing.JPanel explanationPanel; + private javax.swing.JPanel jPanel1; + private javax.swing.JRadioButton leaveSuspect; + private javax.swing.JCheckBox promptSuspect; + private javax.swing.JRadioButton quarantineSuspect; + private javax.swing.JCheckBox removeSlidingMsg; + private javax.swing.JButton save; + private javax.swing.JCheckBox showSlidingMsg; + private javax.swing.JCheckBox silentScan; + private javax.swing.ButtonGroup suspectActionGroup; + // End of variables declaration//GEN-END:variables +} diff --git a/src/ProgramTrayIcon.java b/src/ProgramTrayIcon.java new file mode 100644 index 0000000..a0786c5 --- /dev/null +++ b/src/ProgramTrayIcon.java @@ -0,0 +1,215 @@ +import java.awt.*; +import java.awt.event.*; +import java.io.*; +import java.util.ArrayList; +import javax.swing.*; +import javax.swing.filechooser.FileSystemView; + +/** + * + * @author Sharafat + */ +public class ProgramTrayIcon { + private PopupMenu popup = new PopupMenu(); + private TrayIcon trayIcon; + private SystemTray tray; + private MainWindow mainWindow; + private ScansManager scansManager; + private DetectRemovableDevices detectRemDev; + private PauseProtection pauseProtection; + private boolean[] isProtectionEnabled = new boolean[1]; // Used array so that it can be passed + // as a reference to PauseProtection + + /** + * @param mainWin Reference of the Main Window + * @param scanManager Reference of the ScanManager object + * @param detRemDev Reference of the DetectRemovableDevices objects + * @param protectStatus Protection status: true = enabled, false = disabled + */ + ProgramTrayIcon(MainWindow mainWin,ScansManager scanManager, + DetectRemovableDevices detRemDev, boolean protectStatus) { + mainWindow = mainWin; + scansManager = scanManager; + detectRemDev = detRemDev; + isProtectionEnabled[0] = protectStatus; + + // Create popup menus + MenuItem scanMyComputer = new MenuItem("Scan My Computer"); + popup.add(scanMyComputer); + MenuItem scan = new MenuItem("Scan for Worms"); + popup.add(scan); + popup.addSeparator(); + MenuItem openMainWindow = new MenuItem("Open USB Worm Protection"); + popup.add(openMainWindow); + MenuItem preferences = new MenuItem("Preferences"); + popup.add(preferences); + MenuItem about = new MenuItem("About"); + popup.add(about); + popup.addSeparator(); + final MenuItem protectionStatus; + if (isProtectionEnabled[0]) { + protectionStatus = new MenuItem("Pause Protection"); + } else { + protectionStatus = new MenuItem("Resume Protection"); + } + popup.add(protectionStatus); + MenuItem exit = new MenuItem("Exit"); + popup.add(exit); + + //Create System Tray + if (isProtectionEnabled[0]) { + trayIcon = new TrayIcon( + (new ImageIcon(Main.class.getResource("/images/icon.png"), "Tray Icon")) + .getImage(), "USB Worm Protection", popup); + } else { + trayIcon = new TrayIcon( + (new ImageIcon(Main.class.getResource( + "/images/disabledTrayIcon.png"), "Tray Icon (Disabled)")).getImage(), + "USB Worm Protection (Protection Disabled)", popup); + } + tray = SystemTray.getSystemTray(); + try { + tray.add(trayIcon); + } catch (AWTException e) { + JOptionPane.showMessageDialog(null, + "Cannot display tray icon. Possible reason:\n" + + e.getMessage() + "\n\nProgram will now exit.", + "USB Worm Protection", JOptionPane.ERROR_MESSAGE); + System.exit(1); + } + + // Detect screen size to display dialogs in the center of the window + final Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); + + // Add action listeners + scanMyComputer.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + // Get the local hard disk drive letters + File[] allDrives = File.listRoots(); + ArrayList drives = new ArrayList(1); + for (File drive : allDrives) { + if (FileSystemView.getFileSystemView() + .getSystemTypeDescription(drive).equalsIgnoreCase("Local Disk")) { + drives.add(drive); + } + } + + // Call ScansManager to start scanning + drives.trimToSize(); + File[] drivesList = new File[drives.size()]; + scansManager.performScan(drives.toArray(drivesList)); + } + }); + + scan.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + mainWindow.scanLabelClicked(); + mainWindow.setLocation(((screenDim.width - mainWindow.getWidth()) / 2), + ((screenDim.height - mainWindow.getHeight()) / 2)); + mainWindow.setVisible(true); + mainWindow.setExtendedState(JFrame.NORMAL); + mainWindow.toFront(); + } + }); + + openMainWindow.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + mainWindow.scanLabelClicked(); + mainWindow.setLocation(((screenDim.width - mainWindow.getWidth()) / 2), + ((screenDim.height - mainWindow.getHeight()) / 2)); + mainWindow.setVisible(true); + mainWindow.setExtendedState(JFrame.NORMAL); + mainWindow.toFront(); + } + }); + + preferences.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + mainWindow.preferencesLabelClicked(); + mainWindow.setLocation(((screenDim.width - mainWindow.getWidth()) / 2), + ((screenDim.height - mainWindow.getHeight()) / 2)); + mainWindow.setVisible(true); + mainWindow.setExtendedState(JFrame.NORMAL); + mainWindow.toFront(); + } + }); + + about.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + mainWindow.aboutLabelClicked(); + mainWindow.setLocation(((screenDim.width - mainWindow.getWidth()) / 2), + ((screenDim.height - mainWindow.getHeight()) / 2)); + mainWindow.setVisible(true); + mainWindow.setExtendedState(JFrame.NORMAL); + mainWindow.toFront(); + } + }); + + protectionStatus.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e){ + if (isProtectionEnabled[0]) { + // Display Pause Protection dialog + Object[] param = {isProtectionEnabled, protectionStatus, + detectRemDev, scansManager}; + pauseProtection = new PauseProtection(null, false, param); + pauseProtection.setLocation( + ((screenDim.width - pauseProtection.getWidth()) / 2), + ((screenDim.height - pauseProtection.getHeight()) / 2)); + pauseProtection.setVisible(true); + } else { + if ((pauseProtection != null) && (pauseProtection.timer != null)) { + pauseProtection.timer.stop(); + } + isProtectionEnabled[0] = true; + protectionStatus.setLabel("Disable Protection"); + trayIcon.setImage(new ImageIcon(Main.class.getResource("/images/icon.png"), + "Tray Icon").getImage()); + trayIcon.setToolTip("USB Worm Protection"); + detectRemDev = new DetectRemovableDevices(scansManager); + //detectRemDev.enableProtection(); + + // Write preferences into file + Preferences preferences = new Preferences(); + File prefFile = new File("preferences.dat"); + boolean prefFileExists = prefFile.exists(); + if (prefFileExists) { + ObjectInputStream obin = null; + try { + obin = new ObjectInputStream(new FileInputStream("preferences.dat")); + preferences = (Preferences) obin.readObject(); + } catch (Exception e1) { + } finally { + try { + obin.close(); + } catch (Exception e2) {} + } + } + + preferences.protectionEnableStatus = 0; + + ObjectOutputStream obout = null; + try { + obout = new ObjectOutputStream(new FileOutputStream("preferences.dat")); + obout.writeObject(preferences); + } catch (IOException e3) { + JOptionPane.showMessageDialog(null, "Error: Cannot save protection status:\n" + e, + "USB Worm Protection", JOptionPane.ERROR_MESSAGE); + } finally { + try { + obout.close(); + } catch (IOException e4) {} + } + + } + } + }); + + exit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + + } + +} diff --git a/src/Scan.form b/src/Scan.form new file mode 100644 index 0000000..95cd574 --- /dev/null +++ b/src/Scan.form @@ -0,0 +1,811 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/Scan.java b/src/Scan.java new file mode 100644 index 0000000..fd8624e --- /dev/null +++ b/src/Scan.java @@ -0,0 +1,2356 @@ +/* + * Scan.java + * + * Created on July 24, 2008, 10:35 AM + */ + +import java.awt.event.ActionEvent; +import java.io.*; +import java.awt.*; +import java.awt.event.ActionListener; +import java.text.DateFormat; +import java.util.ArrayList; +import java.util.Date; +import javax.swing.*; +import javax.swing.filechooser.FileSystemView; +import javax.swing.table.*; +import javax.swing.border.*; + +/** + * + * @author Sharafat + */ +public class Scan extends javax.swing.JPanel { + private ScanFrame scanFrame; + protected DoScan doScan; + + // Preferences (set from the constructor parameters) + private boolean shouldDoSilentScan; + private int suspectedFileAction; // 0 = Prompt, 1 = Delete, + // 2 = Quarantine, 3 = Leave + private boolean shouldShowSlideInScanDialog; + private boolean shouldRemoveSlideInDialogAfterScan; + private boolean shouldAlwaysDisplayScanDetails; + + private Scan previousScan; + private Scan nextScan; + + // Stores scan duration for the timer + private Timer timer; + private int hour, min, sec; + + // Checks for pause/stop scanning command + protected boolean shouldStopScanning = false; + protected boolean shouldPauseScanning = false; + + /** Creates new single-drive scanning service (only for plugged-in USB mass storage devices) + * @param drive String containing the Drive letter of the drive to be filesScanned + * @param scanFrame The Scan dialog in which this Scan Panel is contained + * @param preferences The preferences put together in a single array of type Object + * @param previousScan + */ + public Scan(File drive, ScanFrame scanFrame, Object[] preferences, + Scan previousScan) { + this.scanFrame = scanFrame; + shouldDoSilentScan = (Boolean) preferences[0]; + suspectedFileAction = (Integer) preferences[1]; + shouldShowSlideInScanDialog = (Boolean) preferences[2]; + shouldRemoveSlideInDialogAfterScan = (Boolean) preferences[3]; + shouldAlwaysDisplayScanDetails = (Boolean) preferences[4]; + this.previousScan = previousScan; + initComponents(); + initialGUIUpdates(); + doScan = new DoScan(drive, this); + doScan.execute(); + } + + /** Creates new multiple-drives scanning service (drives selected through scan panel) + * @param drives Array of type File containing the drives to be filesScanned + * @param scanFrame The Scan dialog in which this Scan Panel is contained + * @param preferences The preferences put together in a single array of type Object + * @param previousScan + */ + public Scan(File[] drives, ScanFrame scanFrame, Object[] preferences, + Scan previousScan) { + this.scanFrame = scanFrame; + shouldDoSilentScan = false; + suspectedFileAction = (Integer) preferences[1]; + shouldShowSlideInScanDialog = (Boolean) preferences[2]; + shouldRemoveSlideInDialogAfterScan = (Boolean) preferences[3]; + shouldAlwaysDisplayScanDetails = true; + this.previousScan = previousScan; + initComponents(); + initialGUIUpdates(); + doScan = new DoScan(drives); + doScan.execute(); + } + + private void initialGUIUpdates() { + // Enable Previous Scan button + if (previousScan != null) { + prev.setEnabled(true); + } + + // Add to scan frame + scanFrame.panel.removeAll(); + scanFrame.validate(); + scanFrame.panel.repaint(); + scanFrame.panel.add(this); + + // Display scanning details + if (shouldAlwaysDisplayScanDetails) { + Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); + scanFrame.setLocation(((screenDim.width - scanFrame.getWidth()) / 2), + ((screenDim.height - scanFrame.getHeight()) / 2)); + scanFrame.setVisible(true); + } + + // Set scan start time + startTime.setText(DateFormat.getDateTimeInstance().format(new Date())); + + // Start timer to calculate duration + timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent e) { + if ((++sec) >= 60) { + if ((++min) >= 60) { + hour++; + hourLbl.setText(formatTime(hour)); + min = 0; + minLbl.setText("00"); + } else { + minLbl.setText(formatTime(min)); + } + sec = 0; + secLbl.setText("00"); + } else { + secLbl.setText(formatTime(sec)); + } + } + + private String formatTime(int time) { + if (time < 10) { + return "0" + time; + } else { + return Integer.toString(time); + } + } + }); + timer.start(); + } + + protected void setNextScan(Scan nextScan) { + this.nextScan = nextScan; + next.setEnabled(true); + } + + class DoScan extends SwingWorker { + // Array of Drives to be scanned + private File[] root; + + // Fields for updating the progress bar + private long driveSize = 0; + private long scannedFilesSize; + private SlideInScanPanel slideInScanPanel; + private SlideInDialog slideInDialog; + + // Fields for updating the GUI + private ImageIcon scan_endImage = new ImageIcon(getClass().getResource("/images/scan_end.png")); + private ImageIcon scanImage = new ImageIcon(getClass().getResource("/images/scan.gif")); + protected boolean isCurrentlyShowing = true; + private String title = "Scanning "; + private String titleWithPercentage; + private int totalFilesScanned = 0; + private int totalFilesDetected = 0; + private int totalFilesSuspected = 0; + private int totalFilesDeleted = 0; + private int totalFilesQuarantined = 0; + private int totalFilesSkipped = 0; + private int localFilesScanned = 0; + private int localFilesDetected = 0; + private int localFilesSuspected = 0; + private int localFilesDeleted = 0; + private int localFilesQuarantined = 0; + private int localFilesSkipped = 0; + + // Fields for updating the tables + protected DefaultTableModel detectedTableModel = (DefaultTableModel) detectedTable.getModel(); + protected DefaultTableModel suspectedTableModel = (DefaultTableModel) suspectedTable.getModel(); + private DefaultTableModel statTableModel = (DefaultTableModel) statTable.getModel(); + private JLabel fileStatus; + private int currentStatTableDriveRowNo = 1; // To update Stat Table statistics + + // Fields for differentiating between detection and suspicion + private ArrayList detectedFiles = new ArrayList(2); + private ArrayList suspectedFiles = new ArrayList(5); + + /** + * Constructor for scanning removable media + * @param drive The drive to be filesScanned + */ + DoScan(File drive, Scan scan) { + root = new File[1]; + root[0] = drive; + + // Get total drive space + driveSize = drive.getTotalSpace() - drive.getFreeSpace(); + + // Show slide-in scanning dialog + if (shouldShowSlideInScanDialog) { + slideInScanPanel = new SlideInScanPanel(scan, this, scanFrame); + slideInScanPanel.scanning.setText("Scanning " + FileSystemView + .getFileSystemView().getSystemDisplayName(drive) + "..."); + slideInDialog = new SlideInDialog(); + slideInDialog.bodyPanel.add(slideInScanPanel); + new SlideInNotification(slideInDialog); + } + + // Add rows to Statistics table + statTable.getColumnModel().getColumn(0).setCellRenderer(new StatTableCellRenderer()); + JLabel allLabel = new JLabel("All", + new javax.swing.ImageIcon(getClass().getResource("/images/info2.png")), + SwingConstants.LEADING); + statTableModel.addRow(new Object[]{allLabel, 0, 0, 0, 0, 0, 0}); + JLabel driveLabel = new JLabel(FileSystemView.getFileSystemView() + .getSystemDisplayName(drive), + FileSystemView.getFileSystemView().getSystemIcon(drive), + SwingConstants.LEADING); + statTableModel.addRow(new Object[]{driveLabel, 0, 0, 0, 0, 0, 0}); + } + + /** + * Constructor for scanning drives selected from the main window + * @param drives The array of drives to be filesScanned + */ + DoScan(File[] drives) { + root = drives; + + // Get total file size for all the drives + for (File drive : drives) { + driveSize += (drive.getTotalSpace() - drive.getFreeSpace()); + } + + // Add rows to Statistics table + statTable.getColumnModel().getColumn(0).setCellRenderer(new StatTableCellRenderer()); + JLabel allLabel = new JLabel("All", + new javax.swing.ImageIcon(getClass().getResource("/images/info2.png")), + SwingConstants.LEADING); + statTableModel.addRow(new Object[]{allLabel, 0, 0, 0, 0, 0, 0}); + for (File drive : drives) { + JLabel driveLabel = new JLabel(FileSystemView.getFileSystemView() + .getSystemDisplayName(drive), + FileSystemView.getFileSystemView().getSystemIcon(drive), + SwingConstants.LEADING); + statTableModel.addRow(new Object[]{driveLabel, 0, 0, 0, 0, 0, 0}); + } + } + + @Override + public Void doInBackground() { + // Set Scan Frame title + for (File drive : root) { + title += FileSystemView.getFileSystemView() + .getSystemDisplayName(drive) + ", "; + } + title = title.substring(0, title.length() - 2); + titleWithPercentage = title; + scanFrame.setTitle(title); + + // Start scanning + for (File drive : root) { + scan(drive); + + currentStatTableDriveRowNo++; + + localFilesScanned = 0; + localFilesDetected = 0; + localFilesSuspected = 0; + localFilesDeleted = 0; + localFilesQuarantined = 0; + localFilesSkipped = 0; + } + + // Update GUI with messages indicating scanning finished + if (!isCancelled()) { + nowScanning.setText("Finished"); + location.setText(""); + progress.setValue(100); + titleWithPercentage = "(100%) " + title; + if (isCurrentlyShowing) { + scanFrame.setTitle(titleWithPercentage); + } + finishTime.setText(DateFormat.getDateTimeInstance().format(new Date())); + timer.stop(); + if (slideInScanPanel != null) { + slideInScanPanel.scanning.setText("Finished scanning " + FileSystemView.getFileSystemView().getSystemDisplayName(root[0]) + "."); + slideInScanPanel.progress.setValue(100); + + slideInScanPanel.pause.removeMouseListener(slideInScanPanel.pause.getMouseListeners()[0]); + slideInScanPanel.pause.removeMouseListener(slideInScanPanel.pause.getMouseListeners()[0]); + slideInScanPanel.pause.setForeground(Color.DARK_GRAY); + slideInScanPanel.pause.setText("Pause"); + slideInScanPanel.pause.setCursor(Cursor.getDefaultCursor()); + slideInScanPanel.stop.removeMouseListener(slideInScanPanel.stop.getMouseListeners()[0]); + slideInScanPanel.stop.removeMouseListener(slideInScanPanel.stop.getMouseListeners()[0]); + slideInScanPanel.stop.setForeground(Color.DARK_GRAY); + slideInScanPanel.stop.setText("Stop"); + slideInScanPanel.stop.setCursor(Cursor.getDefaultCursor()); + } + pause.setEnabled(false); + stop.setEnabled(false); + } + + // Change the animating image to still image + img.setIcon(scan_endImage); + + // Remove Slide-in dialog + if (shouldRemoveSlideInDialogAfterScan) { + slideInDialog.removeDialog(); + } + + // Decrease number of currently running scans + ScansManager.noOfRunningScans--; + ScanPanel.scanningsLbl.setText("There are currently " + + ScansManager.noOfRunningScans + " scan(s) in progress."); + + // Enable Action... buttons and display tips in Detected & Suspected tables + if (detectedTableModel.getRowCount() > 0) { + detectedAction.setEnabled(true); + detectedMsg.setIcon(new ImageIcon(getClass().getResource("/images/tip.png"))); + } + if (suspectedTableModel.getRowCount() > 0) { + suspectedAction.setEnabled(true); + suspectedMsg.setIcon(new ImageIcon(getClass().getResource("/images/tip.png"))); + } + + // Show lists of detected or suspected files if exist + if ((detectedTableModel.getRowCount() > 0) && !shouldDoSilentScan) { + tabs.setSelectedIndex(0); + if (!scanFrame.isVisible()) { + Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); + scanFrame.setLocation(((screenDim.width - scanFrame.getWidth()) / 2), + ((screenDim.height - scanFrame.getHeight()) / 2)); + scanFrame.setVisible(true); + } + } else if ((suspectedTableModel.getRowCount() > 0) && (suspectedFileAction == 0)) { + tabs.setSelectedIndex(1); + if (!scanFrame.isVisible()) { + Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); + scanFrame.setLocation(((screenDim.width - scanFrame.getWidth()) / 2), + ((screenDim.height - scanFrame.getHeight()) / 2)); + scanFrame.setVisible(true); + } + } + + return null; + } + + protected synchronized void resume() { + shouldPauseScanning = false; + pause.setText("Pause"); + img.setIcon(scanImage); + stop.setEnabled(true); + notify(); + } + + private void scan(File root) { + File[] folders = null; + File[] files; + try { + files = root.listFiles(new FileFilter() { + public boolean accept(File file) { + if (file.isFile()) { + return true; + } else { + return false; + } + } + }); + + folders = root.listFiles(new FileFilter() { + public boolean accept(File file) { + if (file.isDirectory()) { + return true; + } else { + return false; + } + } + }); + + // Check for pausing scan + synchronized (this) { + while (shouldPauseScanning) { + try { + pause.setEnabled(true); + img.setIcon(scan_endImage); + wait(); + } catch (InterruptedException e) {} + } + } + + // Search for worm files + if (files != null) { + for (File currFile : files) { + // Check for pausing scan + synchronized (this) { + while (shouldPauseScanning) { + try { + pause.setEnabled(true); + img.setIcon(scan_endImage); + wait(); + } catch (InterruptedException e) {} + } + } + + if (!shouldStopScanning) { + // Update GUI + updateUIBeforeFileScan(currFile); + + long fileLength = currFile.length(); + String ext = currFile.getName().substring(currFile.getName().length() - 3); + + // Check for hidden exe, cmd, bat, vb, vbs, vbe, vbscript, js, jse, ws, wsf, wsh, pif, + // scr, sct, script files + if (currFile.isHidden() && (ext.equalsIgnoreCase("exe") || ext.equalsIgnoreCase("cmd") + || ext.equalsIgnoreCase("bat") || ext.equalsIgnoreCase("vb") + || ext.equalsIgnoreCase("vbs") || ext.equalsIgnoreCase("vbe") + || ext.equalsIgnoreCase("vbscript") + || ext.equalsIgnoreCase("js") || ext.equalsIgnoreCase("jse") + || ext.equalsIgnoreCase("ws") || ext.equalsIgnoreCase("wsf") + || ext.equalsIgnoreCase("wsh") || ext.equalsIgnoreCase("pif") + || ext.equalsIgnoreCase("scr") || ext.equalsIgnoreCase("sct") + || ext.equalsIgnoreCase("script"))) { + // Worm file - take action + takeDetectedAction(currFile); + } // Check for hidden com files + else if (currFile.isHidden() && (ext.equalsIgnoreCase("com"))) { + // Check whether this is the NTDETECT.COM system file + if (currFile.getName().equalsIgnoreCase("NTDETECT.COM")) { + boolean isSystemFile = false; + for (File sys : files) { + if (sys.getName().substring(sys.getName().length() - 3).equalsIgnoreCase("sys")) { + isSystemFile = true; + break; + } + } + if (!isSystemFile) { + // Worm file - take action + takeDetectedAction(currFile); + } + } else { + // Worm file - take action + takeDetectedAction(currFile); + } + } // Check whether this is New Folder.exe worm file + else if (currFile.getName().equalsIgnoreCase("New Folder.exe") + || currFile.getName().equalsIgnoreCase("Flashy.exe")) { + // Worm file - take action + takeDetectedAction(currFile); + } // Check whether this is a Brontok worm file + else if (currFile.getName().toUpperCase().contains("DATA") && ext.equalsIgnoreCase("exe")) { + // Worm file - take action + takeDetectedAction(currFile); + } // Check whether this is the autorun.inf file + else if (currFile.getName().equalsIgnoreCase("autorun.inf")) { + // autorun.inf file - take action + takeDetectedAction(currFile); + } + + // Update GUI + updateUIAfterFileScan(fileLength); + } else { + cancel(true); + updateUIForScanAbortion(); + return; + } + } + } + + // Check for pausing scan + synchronized (this) { + while (shouldPauseScanning) { + try { + pause.setEnabled(true); + img.setIcon(scan_endImage); + wait(); + } catch (InterruptedException e) {} + } + } + + // Check the folders for the existence of a file name identical to the + // name of the folder with .exe extension + if (folders != null) { + for (File currFolder : folders) { + for (File file : files) { + // Check for pausing scan + synchronized (this) { + while (shouldPauseScanning) { + try { + pause.setEnabled(true); + img.setIcon(scan_endImage); + wait(); + } catch (InterruptedException e) {} + } + } + + if (!shouldStopScanning) { + if (file.getName().contains(currFolder.getName() + ".exe")) { + // Worm file - take action + takeDetectedAction(file); + + // Unhide the folder if it is hidden + if (currFolder.isHidden()) { + try { + String cmdLine = new String("attrib -H \"" + + currFolder.getCanonicalPath() + "\""); + Runtime.getRuntime().exec(cmdLine); + } catch (Throwable t) { + } + } + break; + } + } else { + cancel(true); + updateUIForScanAbortion(); + return; + } + } + } + } + } catch (Exception e) {} + + // Now start scanning the drive entirely, i.e. inside the current folders + if (folders != null) { + for (File folder : folders) { + if (!shouldStopScanning) { + scanFiles(folder); + } else { + updateUIForScanAbortion(); + return; + } + } + } + } + + private void scanFiles(File folder) { + File[] folders = null; + File[] files; + try { + files = folder.listFiles(new FileFilter() { + public boolean accept(File file) { + try { + Thread.sleep(10); + } catch (Exception e) {} + if ((file.getName().length() > 3) && + file.getName().substring(file.getName() + .length() - 3).equalsIgnoreCase("exe")) { + return true; + } else { + if (file.isFile()) { + try { + updateUIBeforeFileScan(file); + } catch (IOException ex) { + } + updateUIAfterFileScan(file.length()); + } + return false; + } + } + }); + + folders = folder.listFiles(new FileFilter() { + public boolean accept(File file) { + if (file.isDirectory()) { + return true; + } else { + return false; + } + } + }); + + // Check for pausing scan + synchronized (this) { + while (shouldPauseScanning) { + try { + pause.setEnabled(true); + img.setIcon(scan_endImage); + wait(); + } catch (InterruptedException e) {} + } + } + + // Search for worm files + if (files != null) { + for (File file : files) { + // Check for pausing scan + synchronized (this) { + while (shouldPauseScanning) { + try { + pause.setEnabled(true); + img.setIcon(scan_endImage); + wait(); + } catch (InterruptedException e) {} + } + } + + if (!shouldStopScanning) { + updateUIBeforeFileScan(file); + long fileLength = file.length(); + if (file.getName().contains(file.getParentFile().getName()) && + file.getName().length() <= + (file.getParentFile().getName().length() + 5)) { + // Suspected worm file - take action + if (isUndoubtedlyWorm(file)) { + takeDetectedAction(file); + } else { + takeSuspectedAction(file); + } + } + updateUIAfterFileScan(fileLength); + } else { + cancel(true); + updateUIForScanAbortion(); + return; + } + } + } + } catch (Exception e) {} + + // Check for pausing scan + synchronized (this) { + while (shouldPauseScanning) { + try { + pause.setEnabled(true); + img.setIcon(scan_endImage); + wait(); + } catch (InterruptedException e) {} + } + } + + // Start scanning inside the children folders + if (folders != null) { + for (File currFolder : folders) { + // Check for pausing scan + synchronized (this) { + while (shouldPauseScanning) { + try { + pause.setEnabled(true); + img.setIcon(scan_endImage); + wait(); + } catch (InterruptedException e) {} + } + } + + if (!shouldStopScanning) { + scanFiles(currFolder); + } else { + cancel(true); + updateUIForScanAbortion(); + return; + } + } + } + } + + private void updateUIBeforeFileScan(File currFile) throws IOException { + nowScanning.setText(currFile.getName()); + location.setText(currFile.getCanonicalPath()); + } + + private void updateUIAfterFileScan(long fileLength) { + scannedFilesSize += fileLength; + int completed = (int) (((float) scannedFilesSize / (float) driveSize) * 100); + progress.setValue(completed); + titleWithPercentage = "(" + completed + "%) " + title; + if (isCurrentlyShowing) { + scanFrame.setTitle(titleWithPercentage); + } + scanned.setText(Integer.toString(++totalFilesScanned)); + statTableModel.setValueAt(totalFilesScanned, 0, 1); + statTableModel.setValueAt(++localFilesScanned, currentStatTableDriveRowNo, 1); + + // Update progress bar in slide-in dialog + if (slideInScanPanel != null) { + slideInScanPanel.progress.setValue(completed); + } + } + + private void updateUIForScanAbortion() { + nowScanning.setText("Aborted"); + location.setText(""); + finishTime.setText(DateFormat.getDateTimeInstance().format(new Date())); + timer.stop(); + if (slideInScanPanel != null) { + try { + slideInScanPanel.scanning.setText("Aborted scanning " + FileSystemView + .getFileSystemView().getSystemDisplayName(root[0]) + "."); + } catch (Exception e) { + slideInScanPanel.scanning.setText("Scanning Aborted."); + } + } + } + + private boolean isUndoubtedlyWorm(File currFile) throws IOException { + for (File confirmedSize : detectedFiles) { + if (currFile.length() == confirmedSize.length()) { + return true; + } + } + + int count = 0; + for (File suspected : suspectedFiles) { + if (currFile.length() == suspected.length()) { + count++; + } + } + if (count >= 2) { + // Clean-up suspected files for the current length + try { + for (int i = 0; i < suspectedFiles.size(); i++) { + if (currFile.length() == suspectedFiles.get(i).length()) { + takeDetectedAction(suspectedFiles.get(i)); + suspected.setText(Integer.toString(--totalFilesSuspected)); + suspectedTableModel.removeRow(i); + suspectedFiles.remove(i); + statTableModel.setValueAt(totalFilesSuspected, 0, 3); + statTableModel.setValueAt(--localFilesSuspected, currentStatTableDriveRowNo, 3); + } + } + } catch (ArrayIndexOutOfBoundsException e) {} + return true; + } else { + return false; + } + } + + private void takeDetectedAction(File currFile) throws IOException { + detectedFiles.add(currFile); + JLabel file = new JLabel(currFile.getCanonicalPath(), + FileSystemView.getFileSystemView().getSystemIcon(currFile), + SwingConstants.LEADING); + if (shouldDoSilentScan) { + try { + currFile.delete(); + fileStatus = new JLabel("Deleted", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + statTableModel.setValueAt(++totalFilesDeleted, 0, 4); + statTableModel.setValueAt(++localFilesDeleted, currentStatTableDriveRowNo, 4); + } catch (Exception e) { + fileStatus = new JLabel("Cannot Delete", + new javax.swing.ImageIcon(getClass().getResource("/images/detected.png")), + SwingConstants.LEADING); + fileStatus.setToolTipText(e.getMessage()); + detectedMsg.setText("Some errors occurred. For details, hover " + + "mouse on the 'Cannot Delete' messages and pause for a while."); + detectedMsg.setIcon(null); + statTableModel.setValueAt(++totalFilesSkipped, 0, 4); + statTableModel.setValueAt(++localFilesSkipped, currentStatTableDriveRowNo, 6); + } + } else { + fileStatus = new JLabel("Detected", + new javax.swing.ImageIcon(getClass().getResource("/images/detected.png")), + SwingConstants.LEADING); + } + detectedTableModel.addRow(new Object[]{fileStatus, file}); + detected.setText(Integer.toString(++totalFilesDetected)); + statTableModel.setValueAt(totalFilesDetected, 0, 2); + statTableModel.setValueAt(++localFilesDetected, currentStatTableDriveRowNo, 2); + } + + private void takeSuspectedAction(File currFile) throws IOException { + suspectedFiles.add(currFile); + JLabel file = new JLabel(currFile.getCanonicalPath(), + FileSystemView.getFileSystemView().getSystemIcon(currFile), + SwingConstants.LEADING); + switch(suspectedFileAction) { + case 0: // Prompt for action + fileStatus = new JLabel("Suspected", + new javax.swing.ImageIcon(getClass().getResource("/images/suspected.png")), + SwingConstants.LEADING); + break; + case 1: // Delete + try { + currFile.delete(); + fileStatus = new JLabel("Deleted", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + statTableModel.setValueAt(++totalFilesDeleted, 0, 2); + statTableModel.setValueAt(++localFilesDeleted, currentStatTableDriveRowNo, 2); + } catch (Exception e) { + fileStatus = new JLabel("Cannot Delete", + new javax.swing.ImageIcon(getClass().getResource("/images/detected.png")), + SwingConstants.LEADING); + fileStatus.setToolTipText(e.getMessage()); + detectedMsg.setText("Some errors occurred. For details, hover " + + "mouse on the 'Cannot Delete' messages and pause for a while."); + detectedMsg.setIcon(null); + statTableModel.setValueAt(++totalFilesSkipped, 0, 6); + statTableModel.setValueAt(++localFilesSkipped, currentStatTableDriveRowNo, 6); + } + break; + case 2: // Quarantine + BufferedInputStream bin = null; + BufferedOutputStream bout = null; + try { + bin = new BufferedInputStream(new FileInputStream(currFile)); + bout = new BufferedOutputStream(new FileOutputStream("Quarantine/" + + currFile.getName().substring(0, currFile.getName().length() - 4) + + "~" + System.currentTimeMillis() + + currFile.getName().substring(currFile.getName().length() - 4))); + while (bin.available() > 0) { + bout.write(bin.read()); + } + bin.close(); + currFile.delete(); + fileStatus = new JLabel("Quarantined", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + statTableModel.setValueAt(++totalFilesQuarantined, 0, 5); + statTableModel.setValueAt(++localFilesQuarantined, currentStatTableDriveRowNo, 5); + } catch (Exception e) { + fileStatus = new JLabel("Cannot Quarantine", + new javax.swing.ImageIcon(getClass().getResource("/images/detected.png")), + SwingConstants.LEADING); + fileStatus.setToolTipText(e.getMessage()); + detectedMsg.setText("Some errors occurred. For details, hover " + + "mouse on the 'Cannot Delete' messages and pause for a while."); + detectedMsg.setIcon(null); + statTableModel.setValueAt(++totalFilesSkipped, 0, 6); + statTableModel.setValueAt(++localFilesSkipped, currentStatTableDriveRowNo, 6); + } finally { + try { + bout.close(); + bin.close(); + } catch (Exception e) {} + } + break; + case 3: // Leave + fileStatus = new JLabel("Skipped", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + statTableModel.setValueAt(++totalFilesSkipped, 0, 6); + statTableModel.setValueAt(++localFilesSkipped, currentStatTableDriveRowNo, 6); + } + suspectedTableModel.addRow(new Object[]{fileStatus, file}); + suspected.setText(Integer.toString(++totalFilesSuspected)); + statTableModel.setValueAt(totalFilesSuspected, 0, 3); + statTableModel.setValueAt(++localFilesSuspected, currentStatTableDriveRowNo, 3); + } + + } + + class JLabelRenderer extends DefaultTableCellRenderer { + @Override + public Component getTableCellRendererComponent( + JTable table, Object value, + boolean isSelected, boolean hasFocus, + int row, int column) { + Color fg = null; + Color bg = null; + + JTable.DropLocation dropLocation = table.getDropLocation(); + if (dropLocation != null + && !dropLocation.isInsertRow() + && !dropLocation.isInsertColumn() + && dropLocation.getRow() == row + && dropLocation.getColumn() == column) { + + fg = UIManager.getColor("Table.dropCellForeground"); + bg = UIManager.getColor("Table.dropCellBackground"); + + isSelected = true; + } + + if (isSelected) { + super.setForeground(fg == null ? table.getSelectionForeground() + : fg); + super.setBackground(bg == null ? table.getSelectionBackground() + : bg); + } else { + super.setForeground(table.getForeground()); + super.setBackground(table.getBackground()); + } + + setFont(table.getFont()); + + if (hasFocus) { + Border border = null; + if (isSelected) { + border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); + } + if (border == null) { + border = UIManager.getBorder("Table.focusCellHighlightBorder"); + } + setBorder(border); + + if (!isSelected && table.isCellEditable(row, column)) { + Color col; + col = UIManager.getColor("Table.focusCellForeground"); + if (col != null) { + super.setForeground(col); + } + col = UIManager.getColor("Table.focusCellBackground"); + if (col != null) { + super.setBackground(col); + } + } + } else { + if (System.getSecurityManager() != null) { + setBorder(new EmptyBorder(1, 1, 1, 1)); + } else { + setBorder(new EmptyBorder(1, 1, 1, 1)); + } + } + + JLabel label = (JLabel) value; + setText(label.getText()); + setIcon(label.getIcon()); + if ((column == 0) && (label.getToolTipText() != null)) { + setToolTipText(label.getToolTipText()); + } + if (column == 1) { + setToolTipText(label.getText()); + } + return this; + } + } + + class StatTableCellRenderer extends DefaultTableCellRenderer { + @Override + public Component getTableCellRendererComponent( + JTable table, Object value, + boolean isSelected, boolean hasFocus, + int row, int column) { + Color fg = null; + Color bg = null; + + JTable.DropLocation dropLocation = table.getDropLocation(); + if (dropLocation != null + && !dropLocation.isInsertRow() + && !dropLocation.isInsertColumn() + && dropLocation.getRow() == row + && dropLocation.getColumn() == column) { + + fg = UIManager.getColor("Table.dropCellForeground"); + bg = UIManager.getColor("Table.dropCellBackground"); + + isSelected = true; + } + + if (isSelected) { + super.setForeground(fg == null ? table.getSelectionForeground() + : fg); + super.setBackground(bg == null ? table.getSelectionBackground() + : bg); + } else { + super.setForeground(table.getForeground()); + super.setBackground(table.getBackground()); + } + + setFont(table.getFont()); + + if (hasFocus) { + Border border = null; + if (isSelected) { + border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); + } + if (border == null) { + border = UIManager.getBorder("Table.focusCellHighlightBorder"); + } + setBorder(border); + + if (!isSelected && table.isCellEditable(row, column)) { + Color col; + col = UIManager.getColor("Table.focusCellForeground"); + if (col != null) { + super.setForeground(col); + } + col = UIManager.getColor("Table.focusCellBackground"); + if (col != null) { + super.setBackground(col); + } + } + } else { + if (System.getSecurityManager() != null) { + setBorder(new EmptyBorder(1, 1, 1, 1)); + } else { + setBorder(new EmptyBorder(1, 1, 1, 1)); + } + } + + JLabel label = (JLabel) value; + setText(label.getText()); + if (column == 0) { + setIcon(label.getIcon()); + } + return this; + } + } + + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + detectedPopupMenu = new javax.swing.JPopupMenu(); + detectedDelete = new javax.swing.JMenuItem(); + detectedDeleteAll = new javax.swing.JMenuItem(); + detectedSkip = new javax.swing.JMenuItem(); + detectedQuarantine = new javax.swing.JMenuItem(); + suspectedPopupMenu = new javax.swing.JPopupMenu(); + suspectedDelete = new javax.swing.JMenuItem(); + suspectedDeleteAll = new javax.swing.JMenuItem(); + suspectedSkip = new javax.swing.JMenuItem(); + suspectedQuarantine = new javax.swing.JMenuItem(); + imgPanel = new javax.swing.JPanel(); + img = new javax.swing.JLabel(); + mainPanel = new javax.swing.JPanel(); + nowScanningLbl = new javax.swing.JLabel(); + locationLbl = new javax.swing.JLabel(); + nowScanning = new javax.swing.JLabel(); + location = new javax.swing.JLabel(); + progress = new javax.swing.JProgressBar(); + scannedLbl = new javax.swing.JLabel(); + detectedLbl = new javax.swing.JLabel(); + suspectedLbl = new javax.swing.JLabel(); + scanned = new javax.swing.JLabel(); + detected = new javax.swing.JLabel(); + suspected = new javax.swing.JLabel(); + startTimeLbl = new javax.swing.JLabel(); + durationLbl = new javax.swing.JLabel(); + finishTimeLbl = new javax.swing.JLabel(); + startTime = new javax.swing.JLabel(); + hourLbl = new javax.swing.JLabel(); + finishTime = new javax.swing.JLabel(); + duration1 = new javax.swing.JLabel(); + minLbl = new javax.swing.JLabel(); + secLbl = new javax.swing.JLabel(); + duration4 = new javax.swing.JLabel(); + tabs = new javax.swing.JTabbedPane(); + detectedTab = new javax.swing.JPanel(); + jScrollPane1 = new javax.swing.JScrollPane(); + detectedTable = new javax.swing.JTable(); + detectedAction = new javax.swing.JButton(); + detectedMsg = new javax.swing.JLabel(); + suspectedTab = new javax.swing.JPanel(); + jScrollPane2 = new javax.swing.JScrollPane(); + suspectedTable = new javax.swing.JTable(); + suspectedAction = new javax.swing.JButton(); + suspectedMsg = new javax.swing.JLabel(); + statTab = new javax.swing.JPanel(); + jScrollPane3 = new javax.swing.JScrollPane(); + statTable = new javax.swing.JTable(); + btnPanel = new javax.swing.JPanel(); + close = new javax.swing.JButton(); + stop = new javax.swing.JButton(); + pause = new javax.swing.JButton(); + prev = new javax.swing.JButton(); + next = new javax.swing.JButton(); + + detectedDelete.setMnemonic('D'); + detectedDelete.setText("Delete"); + detectedDelete.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + detectedDeleteActionPerformed(evt); + } + }); + detectedPopupMenu.add(detectedDelete); + + detectedDeleteAll.setMnemonic('A'); + detectedDeleteAll.setText("Delete All"); + detectedDeleteAll.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + detectedDeleteAllActionPerformed(evt); + } + }); + detectedPopupMenu.add(detectedDeleteAll); + + detectedSkip.setMnemonic('S'); + detectedSkip.setText("Skip"); + detectedSkip.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + detectedSkipActionPerformed(evt); + } + }); + detectedPopupMenu.add(detectedSkip); + + detectedQuarantine.setMnemonic('Q'); + detectedQuarantine.setText("Quarantine"); + detectedQuarantine.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + detectedQuarantineActionPerformed(evt); + } + }); + detectedPopupMenu.add(detectedQuarantine); + + suspectedDelete.setMnemonic('D'); + suspectedDelete.setText("Delete"); + suspectedDelete.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + suspectedDeleteActionPerformed(evt); + } + }); + suspectedPopupMenu.add(suspectedDelete); + + suspectedDeleteAll.setMnemonic('A'); + suspectedDeleteAll.setText("Delete All"); + suspectedDeleteAll.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + suspectedDeleteAllActionPerformed(evt); + } + }); + suspectedPopupMenu.add(suspectedDeleteAll); + + suspectedSkip.setMnemonic('S'); + suspectedSkip.setText("Skip"); + suspectedSkip.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + suspectedSkipActionPerformed(evt); + } + }); + suspectedPopupMenu.add(suspectedSkip); + + suspectedQuarantine.setMnemonic('Q'); + suspectedQuarantine.setText("Quarantine"); + suspectedQuarantine.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + suspectedQuarantineActionPerformed(evt); + } + }); + suspectedPopupMenu.add(suspectedQuarantine); + + setBackground(new java.awt.Color(224, 223, 227)); + setName("scanPanel"); // NOI18N + + imgPanel.setBackground(new java.awt.Color(224, 223, 227)); + + img.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/scan.gif"))); // NOI18N + + javax.swing.GroupLayout imgPanelLayout = new javax.swing.GroupLayout(imgPanel); + imgPanel.setLayout(imgPanelLayout); + imgPanelLayout.setHorizontalGroup( + imgPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(img, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + imgPanelLayout.setVerticalGroup( + imgPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(imgPanelLayout.createSequentialGroup() + .addGap(10, 10, 10) + .addComponent(img)) + ); + + mainPanel.setBackground(new java.awt.Color(224, 223, 227)); + + nowScanningLbl.setText("Now Scanning:"); + + locationLbl.setText("Location:"); + + progress.setDoubleBuffered(true); + progress.setStringPainted(true); + + scannedLbl.setText("Scanned:"); + + detectedLbl.setText("Detected:"); + + suspectedLbl.setText("Suspected:"); + + scanned.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + scanned.setText("0"); + + detected.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + detected.setText("0"); + + suspected.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + suspected.setText("0"); + + startTimeLbl.setText("Start Time:"); + + durationLbl.setText("Duration"); + + finishTimeLbl.setText("Finish Time:"); + + startTime.setText("0"); + + hourLbl.setText("00"); + + finishTime.setText("Unknown"); + + duration1.setText(":"); + + minLbl.setText("00"); + + secLbl.setText("00"); + + duration4.setText(":"); + + javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(progress, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE) + .addGroup(mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(locationLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(nowScanningLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(location, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(nowScanning, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(scannedLbl) + .addComponent(detectedLbl) + .addComponent(suspectedLbl)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(detected, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(scanned, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(suspected, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(startTimeLbl) + .addComponent(durationLbl) + .addComponent(finishTimeLbl)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(startTime, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(finishTime, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(hourLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, 0) + .addComponent(duration1) + .addGap(0, 0, 0) + .addComponent(minLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, 0) + .addComponent(duration4) + .addGap(0, 0, 0) + .addComponent(secLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))))) + .addContainerGap()) + ); + + mainPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {detected, scanned, suspected}); + + mainPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {finishTime, startTime}); + + mainPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {durationLbl, finishTimeLbl, startTimeLbl}); + + mainPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {detectedLbl, scannedLbl, suspectedLbl}); + + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(nowScanningLbl) + .addComponent(nowScanning, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(2, 2, 2) + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(locationLbl) + .addComponent(location, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(scannedLbl) + .addGap(2, 2, 2) + .addComponent(detectedLbl) + .addGap(2, 2, 2) + .addComponent(suspectedLbl)) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(scanned, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(2, 2, 2) + .addComponent(detected, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(2, 2, 2) + .addComponent(suspected)) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(startTimeLbl) + .addGap(2, 2, 2) + .addComponent(durationLbl) + .addGap(2, 2, 2) + .addComponent(finishTimeLbl)) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(startTime, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(2, 2, 2) + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(hourLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(duration1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(minLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(duration4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(secLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(2, 2, 2) + .addComponent(finishTime))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + tabs.setBackground(new java.awt.Color(255, 255, 255)); + tabs.setDoubleBuffered(true); + + detectedTab.setBackground(new java.awt.Color(255, 255, 255)); + + jScrollPane1.setBackground(new java.awt.Color(255, 255, 255)); + + detectedTable.setAutoCreateRowSorter(true); + detectedTable.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "Status", "File" + } + ) { + Class[] types = new Class [] { + javax.swing.JLabel.class, javax.swing.JLabel.class + }; + + boolean[] canEdit = new boolean [] { + false, false + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return canEdit [columnIndex]; + } + }); + detectedTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS); + detectedTable.setDoubleBuffered(true); + detectedTable.setFillsViewportHeight(true); + detectedTable.setIntercellSpacing(new java.awt.Dimension(0, 0)); + detectedTable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + detectedTable.setShowHorizontalLines(false); + detectedTable.setShowVerticalLines(false); + detectedTable.getTableHeader().setReorderingAllowed(false); + detectedTable.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + detectedTableMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + detectedTableMouseReleased(evt); + } + }); + jScrollPane1.setViewportView(detectedTable); + detectedTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); + detectedTable.setDefaultRenderer(JLabel.class, new JLabelRenderer()); + + detectedAction.setText("Action..."); + detectedAction.setEnabled(false); + detectedAction.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + detectedActionMouseClicked(evt); + } + }); + + javax.swing.GroupLayout detectedTabLayout = new javax.swing.GroupLayout(detectedTab); + detectedTab.setLayout(detectedTabLayout); + detectedTabLayout.setHorizontalGroup( + detectedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, detectedTabLayout.createSequentialGroup() + .addContainerGap() + .addGroup(detectedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE) + .addGroup(detectedTabLayout.createSequentialGroup() + .addComponent(detectedMsg, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE) + .addGap(10, 10, 10) + .addComponent(detectedAction))) + .addContainerGap()) + ); + detectedTabLayout.setVerticalGroup( + detectedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, detectedTabLayout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(detectedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(detectedMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(detectedAction, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + + tabs.addTab("Detected", detectedTab); + + suspectedTab.setBackground(new java.awt.Color(255, 255, 255)); + + jScrollPane2.setBackground(new java.awt.Color(255, 255, 255)); + + suspectedTable.setAutoCreateRowSorter(true); + suspectedTable.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "Status", "File" + } + ) { + Class[] types = new Class [] { + javax.swing.JLabel.class, javax.swing.JLabel.class + }; + boolean[] canEdit = new boolean [] { + false, false + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return canEdit [columnIndex]; + } + }); + suspectedTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS); + suspectedTable.setDoubleBuffered(true); + suspectedTable.setFillsViewportHeight(true); + suspectedTable.setIntercellSpacing(new java.awt.Dimension(0, 0)); + suspectedTable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + suspectedTable.setShowHorizontalLines(false); + suspectedTable.setShowVerticalLines(false); + suspectedTable.getTableHeader().setReorderingAllowed(false); + suspectedTable.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + suspectedTableMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + suspectedTableMouseReleased(evt); + } + }); + jScrollPane2.setViewportView(suspectedTable); + suspectedTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); + suspectedTable.setDefaultRenderer(JLabel.class, new JLabelRenderer()); + + suspectedAction.setText("Action..."); + suspectedAction.setEnabled(false); + suspectedAction.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + suspectedActionMouseClicked(evt); + } + }); + + javax.swing.GroupLayout suspectedTabLayout = new javax.swing.GroupLayout(suspectedTab); + suspectedTab.setLayout(suspectedTabLayout); + suspectedTabLayout.setHorizontalGroup( + suspectedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, suspectedTabLayout.createSequentialGroup() + .addContainerGap() + .addGroup(suspectedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE) + .addGroup(suspectedTabLayout.createSequentialGroup() + .addComponent(suspectedMsg, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(suspectedAction))) + .addContainerGap()) + ); + suspectedTabLayout.setVerticalGroup( + suspectedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, suspectedTabLayout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(suspectedTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(suspectedAction) + .addComponent(suspectedMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + + tabs.addTab("Suspected", suspectedTab); + + statTab.setBackground(new java.awt.Color(255, 255, 255)); + + jScrollPane3.setBackground(new java.awt.Color(255, 255, 255)); + + statTable.setAutoCreateRowSorter(true); + statTable.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "Drives", "Scanned", "Detected", "Suspected", "Deleted", "Quarantined", "Skipped" + } + ) { + Class[] types = new Class [] { + javax.swing.JLabel.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class + }; + boolean[] canEdit = new boolean [] { + false, false, false, false, false, false, false + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return canEdit [columnIndex]; + } + }); + statTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS); + statTable.setDoubleBuffered(true); + statTable.setFillsViewportHeight(true); + statTable.setIntercellSpacing(new java.awt.Dimension(0, 0)); + statTable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + statTable.setShowHorizontalLines(false); + statTable.setShowVerticalLines(false); + statTable.getTableHeader().setReorderingAllowed(false); + statTable.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + statTableMousePressed(evt); + } + }); + jScrollPane3.setViewportView(statTable); + statTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); + + javax.swing.GroupLayout statTabLayout = new javax.swing.GroupLayout(statTab); + statTab.setLayout(statTabLayout); + statTabLayout.setHorizontalGroup( + statTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(statTabLayout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE) + .addContainerGap()) + ); + statTabLayout.setVerticalGroup( + statTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(statTabLayout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE) + .addContainerGap()) + ); + + tabs.addTab("Statistics", statTab); + + btnPanel.setBackground(new java.awt.Color(224, 223, 227)); + + close.setText("Close"); + close.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + closeActionPerformed(evt); + } + }); + + stop.setText("Stop"); + stop.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + stopActionPerformed(evt); + } + }); + + pause.setText("Pause"); + pause.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + pauseActionPerformed(evt); + } + }); + + prev.setText("<<"); + prev.setToolTipText("View previous scan"); + prev.setEnabled(false); + prev.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + prevActionPerformed(evt); + } + }); + + next.setText(">>"); + next.setToolTipText("View next scan"); + next.setEnabled(false); + next.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + nextActionPerformed(evt); + } + }); + + javax.swing.GroupLayout btnPanelLayout = new javax.swing.GroupLayout(btnPanel); + btnPanel.setLayout(btnPanelLayout); + btnPanelLayout.setHorizontalGroup( + btnPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, btnPanelLayout.createSequentialGroup() + .addComponent(prev) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(next) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 274, Short.MAX_VALUE) + .addComponent(pause) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(stop) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(close, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)) + ); + + btnPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {close, pause, stop}); + + btnPanelLayout.setVerticalGroup( + btnPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(btnPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(close) + .addComponent(pause) + .addComponent(stop) + .addComponent(next) + .addComponent(prev)) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.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(tabs, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addComponent(imgPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(btnPanel, javax.swing.GroupLayout.Alignment.LEADING, 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() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(21, 21, 21) + .addComponent(imgPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(tabs, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(btnPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + }// //GEN-END:initComponents + +private void closeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeActionPerformed + scanFrame.setVisible(false); +}//GEN-LAST:event_closeActionPerformed + +private void nextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextActionPerformed + doScan.isCurrentlyShowing = false; + scanFrame.panel.removeAll(); + scanFrame.panel.validate(); + scanFrame.panel.repaint(); + scanFrame.panel.add(nextScan); + nextScan.doScan.isCurrentlyShowing = true; + scanFrame.setTitle(nextScan.doScan.titleWithPercentage); +}//GEN-LAST:event_nextActionPerformed + +private void prevActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevActionPerformed + doScan.isCurrentlyShowing = false; + scanFrame.panel.removeAll(); + scanFrame.panel.validate(); + scanFrame.panel.repaint(); + scanFrame.panel.add(previousScan); + previousScan.doScan.isCurrentlyShowing = true; + scanFrame.setTitle(previousScan.doScan.titleWithPercentage); +}//GEN-LAST:event_prevActionPerformed + +private void stopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopActionPerformed + shouldStopScanning = true; + stop.setEnabled(false); + pause.setEnabled(false); + if (doScan.detectedTableModel.getRowCount() > 0) { + detectedAction.setEnabled(true); + } + if (doScan.suspectedTableModel.getRowCount() > 0) { + suspectedAction.setEnabled(true); + } + if (doScan.slideInScanPanel != null) { + doScan.slideInScanPanel.pause.removeMouseListener(doScan.slideInScanPanel.pause.getMouseListeners()[0]); + doScan.slideInScanPanel.pause.removeMouseListener(doScan.slideInScanPanel.pause.getMouseListeners()[0]); + doScan.slideInScanPanel.pause.setForeground(Color.DARK_GRAY); + doScan.slideInScanPanel.pause.setText("Pause"); + doScan.slideInScanPanel.pause.setCursor(Cursor.getDefaultCursor()); + doScan.slideInScanPanel.stop.removeMouseListener(doScan.slideInScanPanel.stop.getMouseListeners()[0]); + doScan.slideInScanPanel.stop.removeMouseListener(doScan.slideInScanPanel.stop.getMouseListeners()[0]); + doScan.slideInScanPanel.stop.setForeground(Color.DARK_GRAY); + doScan.slideInScanPanel.stop.setText("Stop"); + doScan.slideInScanPanel.stop.setCursor(Cursor.getDefaultCursor()); + } +}//GEN-LAST:event_stopActionPerformed + +private void pauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseActionPerformed + if (shouldPauseScanning) { + doScan.resume(); + if (doScan.slideInScanPanel != null) { + doScan.slideInScanPanel.isPaused = false; + doScan.slideInScanPanel.pause.setText("PauseResume 3) { + detectedPopupMenu.getComponent(1).setVisible(false); + } + detectedPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); + } +}//GEN-LAST:event_detectedTableMouseReleased + +private void detectedActionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_detectedActionMouseClicked + if (SwingUtilities.isLeftMouseButton(evt) && detectedAction.isEnabled()) { + if (detectedTable.getSelectedRowCount() == 0) { + detectedDelete.setEnabled(false); + detectedQuarantine.setEnabled(false); + detectedSkip.setEnabled(false); + } else { + detectedDelete.setEnabled(true); + detectedQuarantine.setEnabled(true); + detectedSkip.setEnabled(true); + } + detectedDeleteAll.setVisible(true); + detectedDeleteAll.setEnabled(true); + detectedPopupMenu.show(detectedAction, (detectedAction.getWidth() - 89) / 2, + detectedAction.getHeight() - 59); + } +}//GEN-LAST:event_detectedActionMouseClicked + +private void suspectedTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_suspectedTableMousePressed + if (SwingUtilities.isRightMouseButton(evt)) { + int currentRow = suspectedTable.rowAtPoint(evt.getPoint()); + suspectedTable.getSelectionModel().addSelectionInterval(currentRow, currentRow); + suspectedDelete.setEnabled(true); + suspectedDelete.setEnabled(true); + suspectedDeleteAll.setVisible(false); + suspectedQuarantine.setEnabled(true); + suspectedSkip.setEnabled(true); + } else if ((suspectedTable.rowAtPoint(evt.getPoint()) == -1) + && (suspectedTable.getSelectedRowCount() != 0)) { + suspectedTable.removeRowSelectionInterval(0, suspectedTable.getRowCount() - 1); + } +}//GEN-LAST:event_suspectedTableMousePressed + +private void suspectedTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_suspectedTableMouseReleased + if (evt.isPopupTrigger() && suspectedAction.isEnabled() + && (suspectedTable.rowAtPoint(evt.getPoint()) != -1)) { + if (suspectedPopupMenu.getComponentCount() > 3) { + suspectedPopupMenu.getComponent(1).setVisible(false); + } + suspectedPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); + } +}//GEN-LAST:event_suspectedTableMouseReleased + +private void suspectedActionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_suspectedActionMouseClicked + if (SwingUtilities.isLeftMouseButton(evt) && suspectedAction.isEnabled()) { + if (suspectedTable.getSelectedRowCount() == 0) { + suspectedDelete.setEnabled(false); + suspectedQuarantine.setEnabled(false); + suspectedSkip.setEnabled(false); + } else { + suspectedDelete.setEnabled(true); + suspectedQuarantine.setEnabled(true); + suspectedSkip.setEnabled(true); + } + suspectedDeleteAll.setVisible(true); + suspectedDeleteAll.setEnabled(true); + suspectedPopupMenu.show(suspectedAction, (suspectedAction.getWidth() - 89) / 2, + suspectedAction.getHeight() - 59); + } +}//GEN-LAST:event_suspectedActionMouseClicked + +private void detectedDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detectedDeleteActionPerformed + new DetectedDeleteAction(); +}//GEN-LAST:event_detectedDeleteActionPerformed + +private void detectedSkipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detectedSkipActionPerformed + class DetectedSkipAction implements Runnable { + DetectedSkipAction() { + new Thread(this).start(); + } + + public void run() { + JLabel status; + int[] selectedRowsIndexes = detectedTable.getSelectedRows(); + for (int i = 0; i < detectedTable.getSelectedRowCount(); i++) { + // Check whether the file is already deleted or quarantined + if (!doScan.detectedFiles.get(selectedRowsIndexes[i]).exists()) { + continue; + } + + // Check whether the file is already skipped + JLabel label = (JLabel) doScan.detectedTableModel.getValueAt(selectedRowsIndexes[i], 0); + if (label.getText().equalsIgnoreCase("Skipped")) { + continue; + } + + // Update status + status = new JLabel("Skipped", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + doScan.detectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + doScan.statTableModel.setValueAt(++doScan.totalFilesSkipped, 0, 6); + + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.detectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(++skippedFiles, j, 6); + break; + } + } + } catch (IOException iOException) {} + } + } + } + + new DetectedSkipAction(); +}//GEN-LAST:event_detectedSkipActionPerformed + +private void detectedQuarantineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detectedQuarantineActionPerformed + class DetectedQuarantineAction implements Runnable { + DetectedQuarantineAction() { + new Thread(this).start(); + } + + public void run() { + JLabel status; + int[] selectedRowsIndexes = detectedTable.getSelectedRows(); + File quarantine = new File("Quarantine"); + if (!quarantine.exists()) { + quarantine.mkdir(); + } + + BufferedInputStream bin = null; + BufferedOutputStream bout = null; + for (int i = 0; i < detectedTable.getSelectedRowCount(); i++) { + try { + // Check whether the file is already quarantined + File currFile = doScan.detectedFiles.get(selectedRowsIndexes[i]); + if (!currFile.exists()) { + continue; + } + + // Check whether the file is already skipped; if skipped, then decrement number of skipped files + JLabel label = (JLabel) doScan.detectedTableModel.getValueAt(selectedRowsIndexes[i], 0); + if (label.getText().equalsIgnoreCase("Skipped")) { + doScan.statTableModel.setValueAt(--doScan.totalFilesSkipped, 0, 6); + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.detectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(--skippedFiles, j, 6); + break; + } + } + } catch (IOException iOException) {} + } + + // Quarantine file & update status + bin = new BufferedInputStream(new FileInputStream(currFile)); + bout = new BufferedOutputStream(new FileOutputStream("Quarantine/" + + currFile.getName().substring(0, currFile.getName().length() - 4) + + "~" + System.currentTimeMillis() + + currFile.getName().substring(currFile.getName().length() - 4))); + while (bin.available() > 0) { + bout.write(bin.read()); + } + bin.close(); + currFile.delete(); + + status = new JLabel("Quarantined", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + doScan.detectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + doScan.statTableModel.setValueAt(++doScan.totalFilesQuarantined, 0, 5); + + // Update number of files deleted for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(currFile.getCanonicalPath().substring(0, 1))) { + int quarantinedFiles = (Integer) doScan.statTableModel.getValueAt(j, 5); + doScan.statTableModel.setValueAt(++quarantinedFiles, j, 5); + break; + } + } + } catch (IOException iOException) {} + + } catch (Exception e) { + status = new JLabel("Cannot Quarantine", + new javax.swing.ImageIcon(getClass().getResource("/images/detected.png")), + SwingConstants.LEADING); + status.setToolTipText(e.getMessage()); + doScan.detectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + detectedMsg.setText("Some errors occurred. For details, hover " + + "mouse on the 'Cannot Delete' messages and pause for a while."); + detectedMsg.setIcon(null); + doScan.statTableModel.setValueAt(++doScan.totalFilesSkipped, 0, 4); + + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.detectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(++skippedFiles, j, 6); + break; + } + } + } catch (Exception Exception) {} + + } finally { + try { + bin.close(); + bout.close(); + } catch (Exception e) {} + } + } + } + } + + new DetectedQuarantineAction(); +}//GEN-LAST:event_detectedQuarantineActionPerformed + +private void suspectedDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_suspectedDeleteActionPerformed + new SuspectedDeleteAction(); +}//GEN-LAST:event_suspectedDeleteActionPerformed + +private void suspectedSkipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_suspectedSkipActionPerformed + class SuspectedSkipAction implements Runnable { + SuspectedSkipAction() { + new Thread(this).start(); + } + + public void run() { + JLabel status; + int[] selectedRowsIndexes = suspectedTable.getSelectedRows(); + for (int i = 0; i < suspectedTable.getSelectedRowCount(); i++) { + if (!doScan.suspectedFiles.get(selectedRowsIndexes[i]).exists()) { + continue; + } + + // Check whether the file is already skipped + JLabel label = (JLabel) doScan.suspectedTableModel.getValueAt(selectedRowsIndexes[i], 0); + if (label.getText().equalsIgnoreCase("Skipped")) { + continue; + } + + // Update status + status = new JLabel("Skipped", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + doScan.suspectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + doScan.statTableModel.setValueAt(++doScan.totalFilesSkipped, 0, 6); + + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.suspectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(++skippedFiles, j, 6); + break; + } + } + } catch (IOException iOException) {} + } + } + } + + new SuspectedSkipAction(); +}//GEN-LAST:event_suspectedSkipActionPerformed + +private void suspectedQuarantineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_suspectedQuarantineActionPerformed + class SuspectedQuarantineAction implements Runnable { + SuspectedQuarantineAction() { + new Thread(this).start(); + } + + public void run() { + JLabel status; + int[] selectedRowsIndexes = suspectedTable.getSelectedRows(); + File quarantine = new File("Quarantine"); + if (!quarantine.exists()) { + quarantine.mkdir(); + } + + BufferedInputStream bin = null; + BufferedOutputStream bout = null; + for (int i = 0; i < suspectedTable.getSelectedRowCount(); i++) { + try { + File currFile = doScan.suspectedFiles.get(selectedRowsIndexes[i]); + if (!currFile.exists()) { + continue; + } + + // Check whether the file is already skipped; if skipped, then decrement number of skipped files + JLabel label = (JLabel) doScan.suspectedTableModel.getValueAt(selectedRowsIndexes[i], 0); + if (label.getText().equalsIgnoreCase("Skipped")) { + doScan.statTableModel.setValueAt(--doScan.totalFilesSkipped, 0, 6); + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.suspectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(--skippedFiles, j, 6); + break; + } + } + } catch (IOException iOException) {} + } + + // Quarantine file & update status + bin = new BufferedInputStream(new FileInputStream(currFile)); + bout = new BufferedOutputStream(new FileOutputStream("Quarantine/" + + currFile.getName().substring(0, currFile.getName().length() - 4) + + "~" + System.currentTimeMillis() + + currFile.getName().substring(currFile.getName().length() - 4))); + while (bin.available() > 0) { + bout.write(bin.read()); + } + bin.close(); + currFile.delete(); + + status = new JLabel("Quarantined", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + doScan.suspectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + doScan.statTableModel.setValueAt(++doScan.totalFilesQuarantined, 0, 5); + + // Update number of files deleted for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(currFile.getCanonicalPath().substring(0, 1))) { + int quarantinedFiles = (Integer) doScan.statTableModel.getValueAt(j, 5); + doScan.statTableModel.setValueAt(++quarantinedFiles, j, 5); + break; + } + } + } catch (IOException iOException) {} + + } catch (Exception e) { + status = new JLabel("Cannot Quarantine", + new javax.swing.ImageIcon(getClass().getResource("/images/detected.png")), + SwingConstants.LEADING); + status.setToolTipText(e.getMessage()); + doScan.suspectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + suspectedMsg.setText("Some errors occurred. For details, hover " + + "mouse on the 'Cannot Delete' messages and pause for a while."); + suspectedMsg.setIcon(null); + doScan.statTableModel.setValueAt(++doScan.totalFilesSkipped, 0, 4); + + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.suspectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(++skippedFiles, j, 6); + break; + } + } + } catch (Exception Exception) {} + + } finally { + try { + bin.close(); + bout.close(); + } catch (Exception e) {} + } + } + } + } + + new SuspectedQuarantineAction(); +}//GEN-LAST:event_suspectedQuarantineActionPerformed + +private void statTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_statTableMousePressed + if ((statTable.rowAtPoint(evt.getPoint()) == -1) + && (statTable.getSelectedRowCount() != 0)) { + statTable.removeRowSelectionInterval(0, statTable.getRowCount() - 1); + } +}//GEN-LAST:event_statTableMousePressed + +private void detectedDeleteAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detectedDeleteAllActionPerformed + detectedTable.selectAll(); + new DetectedDeleteAction(); +}//GEN-LAST:event_detectedDeleteAllActionPerformed + +private void suspectedDeleteAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_suspectedDeleteAllActionPerformed + suspectedTable.selectAll(); + new SuspectedDeleteAction(); +}//GEN-LAST:event_suspectedDeleteAllActionPerformed + +class DetectedDeleteAction implements Runnable { + DetectedDeleteAction() { + new Thread(this).start(); + } + + public void run() { + JLabel status; + int[] selectedRowsIndexes = detectedTable.getSelectedRows(); + for (int i = 0; i < detectedTable.getSelectedRowCount(); i++) { + try { + // Check whether the file is already deleted or quarantined + if (doScan.detectedFiles.get(selectedRowsIndexes[i]).exists()) { + doScan.detectedFiles.get(selectedRowsIndexes[i]).delete(); + } else { + continue; + } + + // Check whether the file is already skipped; if skipped, then decrement number of skipped files + JLabel label = (JLabel) doScan.detectedTableModel.getValueAt(selectedRowsIndexes[i], 0); + if (label.getText().equalsIgnoreCase("Skipped")) { + doScan.statTableModel.setValueAt(--doScan.totalFilesSkipped, 0, 6); + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.detectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(--skippedFiles, j, 6); + break; + } + } + } catch (IOException iOException) {} + } + + // Update status + status = new JLabel("Deleted", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + doScan.detectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + doScan.statTableModel.setValueAt(++doScan.totalFilesDeleted, 0, 4); + + // Update number of files deleted for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.detectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int deletedFiles = (Integer) doScan.statTableModel.getValueAt(j, 4); + doScan.statTableModel.setValueAt(++deletedFiles, j, 4); + break; + } + } + } catch (IOException iOException) {} + + } catch (Exception e) { + status = new JLabel("Cannot Delete", + new javax.swing.ImageIcon(getClass().getResource("/images/detected.png")), + SwingConstants.LEADING); + status.setToolTipText(e.getMessage()); + doScan.detectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + detectedMsg.setText("Some errors occurred. For details, hover " + + "mouse on the 'Cannot Delete' messages and pause for a while."); + detectedMsg.setIcon(null); + doScan.statTableModel.setValueAt(++doScan.totalFilesSkipped, 0, 4); + + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.detectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(++skippedFiles, j, 6); + break; + } + } + } catch (IOException iOException) {} + + } + } + } +} + +class SuspectedDeleteAction implements Runnable { + SuspectedDeleteAction() { + new Thread(this).start(); + } + + public void run() { + JLabel status; + int[] selectedRowsIndexes = suspectedTable.getSelectedRows(); + for (int i = 0; i < suspectedTable.getSelectedRowCount(); i++) { + try { + // Check whether the file is already deleted or quarantined + if (doScan.suspectedFiles.get(selectedRowsIndexes[i]).exists()) { + doScan.suspectedFiles.get(selectedRowsIndexes[i]).delete(); + } else { + continue; + } + + // Check whether the file is already skipped; if skipped, then decrement number of skipped files + JLabel label = (JLabel) doScan.suspectedTableModel.getValueAt(selectedRowsIndexes[i], 0); + if (label.getText().equalsIgnoreCase("Skipped")) { + doScan.statTableModel.setValueAt(--doScan.totalFilesSkipped, 0, 6); + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.suspectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(--skippedFiles, j, 6); + break; + } + } + } catch (IOException iOException) {} + } + + // Update status + status = new JLabel("Deleted", + new javax.swing.ImageIcon(getClass().getResource("/images/deleted.png")), + SwingConstants.LEADING); + doScan.suspectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + doScan.statTableModel.setValueAt(++doScan.totalFilesDeleted, 0, 4); + + // Update number of files deleted for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.suspectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int deletedFiles = (Integer) doScan.statTableModel.getValueAt(j, 4); + doScan.statTableModel.setValueAt(++deletedFiles, j, 4); + break; + } + } + } catch (IOException iOException) {} + + } catch (Exception e) { + status = new JLabel("Cannot Delete", + new javax.swing.ImageIcon(getClass().getResource("/images/suspected.png")), + SwingConstants.LEADING); + status.setToolTipText(e.getMessage()); + doScan.suspectedTableModel.setValueAt(status, selectedRowsIndexes[i], 0); + suspectedMsg.setText("Some errors occurred. For details, hover " + + "mouse on the 'Cannot Delete' messages and pause for a while."); + suspectedMsg.setIcon(null); + doScan.statTableModel.setValueAt(++doScan.totalFilesSkipped, 0, 4); + + // Update number of files skipped for each drive + try { + for (int j = 1; j < statTable.getRowCount(); j++) { + JLabel driveLabel = (JLabel) doScan.statTableModel.getValueAt(j, 0); + if (Character.toString(driveLabel.getText().charAt(driveLabel.getText().length() - 3)) + .equalsIgnoreCase(doScan.suspectedFiles.get(selectedRowsIndexes[i]) + .getCanonicalPath().substring(0, 1))) { + int skippedFiles = (Integer) doScan.statTableModel.getValueAt(j, 6); + doScan.statTableModel.setValueAt(++skippedFiles, j, 6); + break; + } + } + } catch (IOException iOException) {} + + } + } + } +} + + // Variables declaration - do not modify//GEN-BEGIN:variables + protected javax.swing.JPanel btnPanel; + private javax.swing.JButton close; + private javax.swing.JLabel detected; + protected javax.swing.JButton detectedAction; + private javax.swing.JMenuItem detectedDelete; + private javax.swing.JMenuItem detectedDeleteAll; + private javax.swing.JLabel detectedLbl; + private javax.swing.JLabel detectedMsg; + private javax.swing.JPopupMenu detectedPopupMenu; + private javax.swing.JMenuItem detectedQuarantine; + private javax.swing.JMenuItem detectedSkip; + private javax.swing.JPanel detectedTab; + private javax.swing.JTable detectedTable; + private javax.swing.JLabel duration1; + private javax.swing.JLabel duration4; + private javax.swing.JLabel durationLbl; + private javax.swing.JLabel finishTime; + private javax.swing.JLabel finishTimeLbl; + private javax.swing.JLabel hourLbl; + private javax.swing.JLabel img; + private javax.swing.JPanel imgPanel; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JScrollPane jScrollPane3; + private javax.swing.JLabel location; + private javax.swing.JLabel locationLbl; + private javax.swing.JPanel mainPanel; + private javax.swing.JLabel minLbl; + protected javax.swing.JButton next; + private javax.swing.JLabel nowScanning; + private javax.swing.JLabel nowScanningLbl; + protected javax.swing.JButton pause; + private javax.swing.JButton prev; + private javax.swing.JProgressBar progress; + private javax.swing.JLabel scanned; + private javax.swing.JLabel scannedLbl; + private javax.swing.JLabel secLbl; + private javax.swing.JLabel startTime; + private javax.swing.JLabel startTimeLbl; + private javax.swing.JPanel statTab; + private javax.swing.JTable statTable; + protected javax.swing.JButton stop; + private javax.swing.JLabel suspected; + protected javax.swing.JButton suspectedAction; + private javax.swing.JMenuItem suspectedDelete; + private javax.swing.JMenuItem suspectedDeleteAll; + private javax.swing.JLabel suspectedLbl; + private javax.swing.JLabel suspectedMsg; + private javax.swing.JPopupMenu suspectedPopupMenu; + private javax.swing.JMenuItem suspectedQuarantine; + private javax.swing.JMenuItem suspectedSkip; + private javax.swing.JPanel suspectedTab; + private javax.swing.JTable suspectedTable; + private javax.swing.JTabbedPane tabs; + // End of variables declaration//GEN-END:variables + +} \ No newline at end of file diff --git a/src/ScanFrame.form b/src/ScanFrame.form new file mode 100644 index 0000000..f7fb91a --- /dev/null +++ b/src/ScanFrame.form @@ -0,0 +1,54 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/ScanFrame.java b/src/ScanFrame.java new file mode 100644 index 0000000..cfbf1ae --- /dev/null +++ b/src/ScanFrame.java @@ -0,0 +1,56 @@ +/* + * ScanFrame.java + * + * Created on July 24, 2008, 8:51 AM + */ + +import java.awt.Toolkit; + +/** + * + * @author Sharafat + */ +public class ScanFrame extends javax.swing.JFrame { + + /** Creates new form ScanFrame */ + public ScanFrame() { + initComponents(); + } + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + panel = new javax.swing.JPanel(); + + setTitle("Scan"); + setIconImage(Toolkit.getDefaultToolkit().getImage(Main.class.getResource("images/icon.png"))); + setMinimumSize(new java.awt.Dimension(656, 520)); + setName("scanFrame"); // NOI18N + + panel.setPreferredSize(new java.awt.Dimension(0, 0)); + panel.setLayout(new java.awt.BorderLayout()); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, 10, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, 10, Short.MAX_VALUE) + ); + + pack(); + }// //GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + protected javax.swing.JPanel panel; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/ScanPanel.form b/src/ScanPanel.form new file mode 100644 index 0000000..35f3ec9 --- /dev/null +++ b/src/ScanPanel.form @@ -0,0 +1,306 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/ScanPanel.java b/src/ScanPanel.java new file mode 100644 index 0000000..a59ed84 --- /dev/null +++ b/src/ScanPanel.java @@ -0,0 +1,446 @@ +/* + * ScanPanel.java + * + * Created on July 23, 2008, 1:23 PM + */ + +import java.awt.*; +import javax.swing.*; +import javax.swing.GroupLayout.*; +import javax.swing.filechooser.FileSystemView; +import java.io.File; +import javax.swing.event.*; + +/** + * + * @author Sharafat + */ +public class ScanPanel extends javax.swing.JPanel { + private ScansManager scansManager; + private File[] currentScannableDrives; + protected File[] drivesToBeScanned; + private JCheckBox[] ch; + private JLabel[] label; + + /** Creates new form ScanPanel + * @param scansManager The ScansManager object + */ + public ScanPanel(ScansManager scansManager) { + this.scansManager = scansManager; + initComponents(); + } + + protected void displayDrives() { + File[] currentDrives = File.listRoots(); + FileSystemView fileSystem = FileSystemView.getFileSystemView(); + String driveDescription; + + // Get scannable Drives + int noOfScannableDrives = 0; + for (File drive : currentDrives) { + driveDescription = fileSystem.getSystemTypeDescription(drive); + if (driveDescription == null) { + continue; + } + if ((driveDescription.equalsIgnoreCase("Local Disk")) || + (driveDescription.equalsIgnoreCase("Removable Disk")) || + (driveDescription.equalsIgnoreCase("USB Drive")) || + (driveDescription.equalsIgnoreCase("Network Drive"))){ + noOfScannableDrives++; + } + } + currentScannableDrives = new File[noOfScannableDrives]; + int count = 0; + for (File drive : currentDrives) { + driveDescription = fileSystem.getSystemTypeDescription(drive); + if (driveDescription == null) { + continue; + } + if ((driveDescription.equalsIgnoreCase("Local Disk")) || + (driveDescription.equalsIgnoreCase("Removable Disk")) || + (driveDescription.equalsIgnoreCase("USB Drive")) || + (driveDescription.equalsIgnoreCase("Network Drive"))){ + currentScannableDrives[count++] = drive; + } + } + ch = new JCheckBox[currentScannableDrives.length]; + label = new JLabel[currentScannableDrives.length]; + + // Display the drives + for (int i = 0; i < currentScannableDrives.length; i++) { + ch[i] = new JCheckBox(); + ch[i].setBackground(Color.WHITE); + + // Add ChangeListener to check box to enable/disable the Start Scan button + final int j = i; // Workaround for using this index inside inner class + ch[i].addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + if (ch[j].isSelected()) { + startScan.setEnabled(true); + } else { + boolean isAnyCheckBoxSelected = false; + for (int k = 0; k < ch.length; k++) { + if (ch[k].isSelected()) { + isAnyCheckBoxSelected = true; + break; + } + } + if (!isAnyCheckBoxSelected) { + startScan.setEnabled(false); + } + } + } + }); + + // Add MouseListener to label to simulate click on check box + label[i] = new JLabel( + fileSystem.getSystemDisplayName(currentScannableDrives[i]), + fileSystem.getSystemIcon(currentScannableDrives[i]), JLabel.LEFT); + label[i].addMouseListener(new java.awt.event.MouseAdapter() { + @Override + public void mouseClicked(java.awt.event.MouseEvent evt) { + if (ch[j].isSelected()) { + ch[j].setSelected(false); + } else { + ch[j].setSelected(true); + } + } + }); + } + + drivesListPanel.removeAll(); + startScan.setEnabled(false); + + GroupLayout layout = new GroupLayout(drivesListPanel); + drivesListPanel.setLayout(layout); + layout.setAutoCreateGaps(true); + layout.setAutoCreateContainerGaps(true); + + SequentialGroup seqGroup1 = layout.createSequentialGroup(); + SequentialGroup seqGroup2 = layout.createSequentialGroup(); + ParallelGroup horParGroup1 = layout.createParallelGroup(GroupLayout.Alignment.LEADING); + ParallelGroup horParGroup2 = layout.createParallelGroup(GroupLayout.Alignment.LEADING); + + for (int i = 0; i < currentScannableDrives.length; i++) { + horParGroup1 = horParGroup1.addComponent(ch[i]); + horParGroup2 = horParGroup2.addComponent(label[i]); + seqGroup2.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) + .addComponent(ch[i]).addComponent(label[i])); + } + layout.setHorizontalGroup(seqGroup1.addGroup(horParGroup1).addGroup(horParGroup2)); + layout.setVerticalGroup(seqGroup2); + + validate(); + + // Enable View Quarantined Files button if necessary + File quarantineFolder = new File("Quarantine"); + String[] quarantinedFiles = quarantineFolder.list(); + if ((quarantinedFiles != null) && (quarantinedFiles.length != 0)) { + viewQuarantine.setEnabled(true); + quarantineLbl.setText("There are " + quarantinedFiles.length + " file(s) quarantined."); + } else { + viewQuarantine.setEnabled(false); + quarantineLbl.setText("There is no file quarantined."); + } + } + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + driveScanPanel = new javax.swing.JPanel(); + refreshListBtn = new javax.swing.JButton(); + deselectAllBtn = new javax.swing.JButton(); + selectAllBtn = new javax.swing.JButton(); + scrollPane = new javax.swing.JScrollPane(); + drivesListPanel = new javax.swing.JPanel(); + startScan = new javax.swing.JButton(); + scansPanel = new javax.swing.JPanel(); + scanningsLbl = new javax.swing.JLabel(); + scanDetails = new javax.swing.JButton(); + quarantinePanel = new javax.swing.JPanel(); + viewQuarantine = new javax.swing.JButton(); + quarantineLbl = new javax.swing.JLabel(); + + setBackground(new java.awt.Color(255, 255, 255)); + + driveScanPanel.setBackground(new java.awt.Color(255, 255, 255)); + driveScanPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Select Drives to Scan")); + + refreshListBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/reload.png"))); // NOI18N + refreshListBtn.setMnemonic('R'); + refreshListBtn.setText("Refresh List"); + refreshListBtn.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + refreshListBtn.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + refreshListBtnActionPerformed(evt); + } + }); + + deselectAllBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/deselectAll.png"))); // NOI18N + deselectAllBtn.setMnemonic('D'); + deselectAllBtn.setText("Deselect All"); + deselectAllBtn.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + deselectAllBtn.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deselectAllBtnActionPerformed(evt); + } + }); + + selectAllBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/selectAll.png"))); // NOI18N + selectAllBtn.setMnemonic('E'); + selectAllBtn.setText("Select All"); + selectAllBtn.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + selectAllBtn.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + selectAllBtnActionPerformed(evt); + } + }); + + scrollPane.setBackground(new java.awt.Color(255, 255, 255)); + + drivesListPanel.setBackground(new java.awt.Color(255, 255, 255)); + + javax.swing.GroupLayout drivesListPanelLayout = new javax.swing.GroupLayout(drivesListPanel); + drivesListPanel.setLayout(drivesListPanelLayout); + drivesListPanelLayout.setHorizontalGroup( + drivesListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 232, Short.MAX_VALUE) + ); + drivesListPanelLayout.setVerticalGroup( + drivesListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 516, Short.MAX_VALUE) + ); + + scrollPane.setViewportView(drivesListPanel); + + startScan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/scan.png"))); // NOI18N + startScan.setMnemonic('S'); + startScan.setText("Start Scan"); + startScan.setEnabled(false); + startScan.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); + startScan.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + startScanActionPerformed(evt); + } + }); + + javax.swing.GroupLayout driveScanPanelLayout = new javax.swing.GroupLayout(driveScanPanel); + driveScanPanel.setLayout(driveScanPanelLayout); + driveScanPanelLayout.setHorizontalGroup( + driveScanPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(driveScanPanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(scrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(driveScanPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(startScan) + .addComponent(deselectAllBtn) + .addComponent(selectAllBtn) + .addComponent(refreshListBtn)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + driveScanPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deselectAllBtn, refreshListBtn, selectAllBtn, startScan}); + + driveScanPanelLayout.setVerticalGroup( + driveScanPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(driveScanPanelLayout.createSequentialGroup() + .addGroup(driveScanPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(scrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, driveScanPanelLayout.createSequentialGroup() + .addComponent(refreshListBtn) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(selectAllBtn) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(deselectAllBtn) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(startScan))) + .addContainerGap()) + ); + + driveScanPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {deselectAllBtn, refreshListBtn, selectAllBtn, startScan}); + + scansPanel.setBackground(new java.awt.Color(255, 255, 255)); + scansPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Scan Details")); + + scanningsLbl.setText("There are currently 0 scan(s) in progress."); + + scanDetails.setBackground(new java.awt.Color(255, 255, 255)); + scanDetails.setMnemonic('V'); + scanDetails.setText("View Scanning Details..."); + scanDetails.setEnabled(false); + scanDetails.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + scanDetails.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + scanDetailsActionPerformed(evt); + } + }); + + javax.swing.GroupLayout scansPanelLayout = new javax.swing.GroupLayout(scansPanel); + scansPanel.setLayout(scansPanelLayout); + scansPanelLayout.setHorizontalGroup( + scansPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(scansPanelLayout.createSequentialGroup() + .addComponent(scanningsLbl, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE) + .addContainerGap()) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, scansPanelLayout.createSequentialGroup() + .addContainerGap(242, Short.MAX_VALUE) + .addComponent(scanDetails)) + ); + scansPanelLayout.setVerticalGroup( + scansPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(scansPanelLayout.createSequentialGroup() + .addComponent(scanningsLbl) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scanDetails) + .addContainerGap()) + ); + + quarantinePanel.setBackground(new java.awt.Color(255, 255, 255)); + quarantinePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Quarantine")); + + viewQuarantine.setBackground(new java.awt.Color(255, 255, 255)); + viewQuarantine.setMnemonic('M'); + viewQuarantine.setText("View Quarantined Files"); + viewQuarantine.setEnabled(false); + viewQuarantine.setPreferredSize(new java.awt.Dimension(147, 23)); + viewQuarantine.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + viewQuarantineActionPerformed(evt); + } + }); + + quarantineLbl.setText("There is no file quarantined."); + + javax.swing.GroupLayout quarantinePanelLayout = new javax.swing.GroupLayout(quarantinePanel); + quarantinePanel.setLayout(quarantinePanelLayout); + quarantinePanelLayout.setHorizontalGroup( + quarantinePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(quarantineLbl, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, quarantinePanelLayout.createSequentialGroup() + .addContainerGap() + .addComponent(viewQuarantine, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + ); + quarantinePanelLayout.setVerticalGroup( + quarantinePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(quarantinePanelLayout.createSequentialGroup() + .addComponent(quarantineLbl) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(viewQuarantine, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(scansPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(driveScanPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(quarantinePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(driveScanPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(scansPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(quarantinePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + }// //GEN-END:initComponents + +private void refreshListBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshListBtnActionPerformed + drivesListPanel.removeAll(); + repaint(); + displayDrives(); + startScan.setEnabled(false); +}//GEN-LAST:event_refreshListBtnActionPerformed + +private void selectAllBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllBtnActionPerformed + for (int i = 0; i < currentScannableDrives.length; i++) { + ch[i].setSelected(true); + } + startScan.setEnabled(true); +}//GEN-LAST:event_selectAllBtnActionPerformed + +private void deselectAllBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllBtnActionPerformed + for (int i = 0; i < currentScannableDrives.length; i++) { + ch[i].setSelected(false); + } + startScan.setEnabled(false); +}//GEN-LAST:event_deselectAllBtnActionPerformed + +private void startScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startScanActionPerformed + // Get the drives to be scanned + int count = 0; + for (int i = 0; i < currentScannableDrives.length; i++) { + if (ch[i].isSelected()) { + count++; + } + } + drivesToBeScanned = new File[count]; + count = 0; + for (int i = 0; i < currentScannableDrives.length; i++) { + if (ch[i].isSelected()) { + drivesToBeScanned[count++] = currentScannableDrives[i]; + } + } + + // Call ScansManager to start scanning + scansManager.performScan(drivesToBeScanned); +}//GEN-LAST:event_startScanActionPerformed + +private void scanDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scanDetailsActionPerformed + if (!ScansManager.scanFrame.isVisible()) { + ScansManager.scanFrame.panel.removeAll(); + ScansManager.scanFrame.validate(); + ScansManager.scanFrame.panel.repaint(); + ScansManager.scanFrame.panel.add(ScansManager.scanQueue.get(0)); + Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); + ScansManager.scanFrame.setLocation(((screenDim.width - ScansManager.scanFrame.getWidth()) / 2), + ((screenDim.height - ScansManager.scanFrame.getHeight()) / 2)); + ScansManager.scanFrame.setVisible(true); + } else { + ScansManager.scanFrame.setExtendedState(Frame.NORMAL); + ScansManager.scanFrame.toFront(); + } +}//GEN-LAST:event_scanDetailsActionPerformed + +private void viewQuarantineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewQuarantineActionPerformed + File quarantineFolder = new File("Quarantine"); + if (quarantineFolder.exists()) { + try { + Runtime.getRuntime().exec("cmd.exe /C explorer \"" + + quarantineFolder.getCanonicalPath() + "\""); + } catch (Exception e) {} + } +}//GEN-LAST:event_viewQuarantineActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton deselectAllBtn; + private javax.swing.JPanel driveScanPanel; + private javax.swing.JPanel drivesListPanel; + private javax.swing.JLabel quarantineLbl; + private javax.swing.JPanel quarantinePanel; + private javax.swing.JButton refreshListBtn; + protected static javax.swing.JButton scanDetails; + protected static javax.swing.JLabel scanningsLbl; + private javax.swing.JPanel scansPanel; + private javax.swing.JScrollPane scrollPane; + private javax.swing.JButton selectAllBtn; + private javax.swing.JButton startScan; + private javax.swing.JButton viewQuarantine; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/ScansManager.java b/src/ScansManager.java new file mode 100644 index 0000000..9c22b0f --- /dev/null +++ b/src/ScansManager.java @@ -0,0 +1,63 @@ +import java.io.File; +import java.util.ArrayList; + +/** + * + * @author Sharafat + */ +public class ScansManager { + // The main scan frame + protected static ScanFrame scanFrame = new ScanFrame(); + // Scan queue + protected static ArrayList scanQueue = new ArrayList(5); + // Number of scans currently running + protected static int noOfRunningScans = 0; + // The preferences + private Object[] preferences; + + + /** + * Constructs a new ScansManager object. + * @param preferences The preferences put together in a single array of type Object + */ + ScansManager(Object[] preferences) { + this.preferences = preferences; + } + + /** + * Scans a removable media (single drive) when it is plugged in. + * @param drive String containing the Drive letter of the drive to be scanned + */ + public void performScan(File drive) { + if (scanQueue.size() > 0) { + scanQueue.add(new Scan(drive, scanFrame, preferences, scanQueue.get(scanQueue.size() - 1))); + scanQueue.get(scanQueue.size() - 2).setNextScan(scanQueue.get(scanQueue.size() - 1)); + scanQueue.get(scanQueue.size() - 2).doScan.isCurrentlyShowing = false; + } else { + scanQueue.add(new Scan(drive, scanFrame, preferences, null)); + } + noOfRunningScans++; + ScanPanel.scanningsLbl.setText("There are currently " + + noOfRunningScans + " scan(s) in progress."); + ScanPanel.scanDetails.setEnabled(true); + } + + /** + * Scans the drives selected in the scan panel in main window. + * @param drives Array of Strings containing the drive letters + */ + public void performScan(File[] drives) { + if (scanQueue.size() > 0) { + scanQueue.add(new Scan(drives, scanFrame, preferences, scanQueue.get(scanQueue.size() - 1))); + scanQueue.get(scanQueue.size() - 2).setNextScan(scanQueue.get(scanQueue.size() - 1)); + scanQueue.get(scanQueue.size() - 2).doScan.isCurrentlyShowing = false; + } else { + scanQueue.add(new Scan(drives, scanFrame, preferences, null)); + } + noOfRunningScans++; + ScanPanel.scanningsLbl.setText("There are currently " + + noOfRunningScans + " scan(s) in progress."); + ScanPanel.scanDetails.setEnabled(true); + } + +} diff --git a/src/SlideInDialog.form b/src/SlideInDialog.form new file mode 100644 index 0000000..c67066c --- /dev/null +++ b/src/SlideInDialog.form @@ -0,0 +1,137 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SlideInDialog.java b/src/SlideInDialog.java new file mode 100644 index 0000000..34e7657 --- /dev/null +++ b/src/SlideInDialog.java @@ -0,0 +1,152 @@ +/* + * SlideInDialog.java + * + * Created on July 27, 2008, 2:11 AM + */ + +import java.awt.Cursor; +import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.*; + +/** + * + * @author Sharafat + */ +public class SlideInDialog extends javax.swing.JPanel { + private JWindow holdingWindow; + + // Previous position of mouse pointer (for the case of dragging the slide-in-dialog) + private int previousPosX; + private int previousPosY; + + /** Creates new form SlideInDialog */ + public SlideInDialog() { + initComponents(); + } + + /** + * + * @param holdingWindow Reference of the window holding the slide-in dialog panel + */ + public void setHoldingWindow(JWindow holdingWindow) { + this.holdingWindow = holdingWindow; + } + + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + titlePanel = new javax.swing.JLayeredPane(); + title = new javax.swing.JLabel(); + close = new javax.swing.JLabel(); + background = new javax.swing.JLabel(); + bodyPanel = new javax.swing.JPanel(); + + setBackground(new java.awt.Color(255, 255, 255)); + setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true)); + + titlePanel.setBackground(new java.awt.Color(255, 255, 255)); + titlePanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 255), 1, true)); + titlePanel.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + titlePanelMousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + titlePanelMouseReleased(evt); + } + }); + titlePanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { + public void mouseDragged(java.awt.event.MouseEvent evt) { + titlePanelMouseDragged(evt); + } + }); + + title.setFont(new java.awt.Font("Tahoma", 1, 11)); + title.setForeground(new java.awt.Color(255, 255, 255)); + title.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon.png"))); // NOI18N + title.setText("USB Worm Protection"); + title.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); + title.setBounds(3, 0, 150, 20); + titlePanel.add(title, javax.swing.JLayeredPane.DEFAULT_LAYER); + + close.setBackground(new java.awt.Color(255, 255, 255)); + close.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/disabledTrayIcon.png"))); // NOI18N + close.setToolTipText("Hide This Dialog"); + close.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); + close.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + closeMouseClicked(evt); + } + }); + close.setBounds(250, 0, 16, 20); + titlePanel.add(close, javax.swing.JLayeredPane.DEFAULT_LAYER); + + background.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/background_blue.png"))); // NOI18N + background.setText("jLabel1"); + background.setBounds(0, 0, 268, 23); + titlePanel.add(background, javax.swing.JLayeredPane.DEFAULT_LAYER); + + bodyPanel.setBackground(new java.awt.Color(255, 255, 255)); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(titlePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE) + .addComponent(bodyPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(titlePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, 0) + .addComponent(bodyPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + +private void closeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_closeMouseClicked + removeDialog(); +}//GEN-LAST:event_closeMouseClicked + +private void titlePanelMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_titlePanelMousePressed + previousPosX = evt.getX(); + previousPosY = evt.getY(); + setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); +}//GEN-LAST:event_titlePanelMousePressed + +private void titlePanelMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_titlePanelMouseDragged + holdingWindow.setLocation(holdingWindow.getX() + evt.getX() - previousPosX, + holdingWindow.getY() + evt.getY() - previousPosY); +}//GEN-LAST:event_titlePanelMouseDragged + +private void titlePanelMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_titlePanelMouseReleased + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); +}//GEN-LAST:event_titlePanelMouseReleased + +protected void removeDialog() { + while (holdingWindow.getLocation().y <= Toolkit.getDefaultToolkit().getScreenSize().height) { + holdingWindow.setLocation(holdingWindow.getX(), holdingWindow.getY() + 1); + try { + Thread.sleep(SlideInNotification.ANIMATION_DELAY / 20); + } catch (InterruptedException e) {} + } + holdingWindow.dispose(); +} + + // Variables declaration - do not modify//GEN-BEGIN:variables + protected javax.swing.JLabel background; + protected javax.swing.JPanel bodyPanel; + private javax.swing.JLabel close; + private javax.swing.JLabel title; + private javax.swing.JLayeredPane titlePanel; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/SlideInNotification.java b/src/SlideInNotification.java new file mode 100644 index 0000000..17a648f --- /dev/null +++ b/src/SlideInNotification.java @@ -0,0 +1,152 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.image.*; + +public class SlideInNotification { + protected static final int ANIMATION_TIME = 500; + protected static final float ANIMATION_TIME_F = (float) ANIMATION_TIME; + protected static final int ANIMATION_DELAY = 50; + protected JWindow window; + private JComponent contents; + private AnimatingSheet animatingSheet; + private Rectangle desktopBounds; + private Dimension tempWindowSize; + private Timer animationTimer; + private int showX, startY; + private long animationStart; + + /** + * + * @param contents The slide-in dialog panel to be displayed + */ + public SlideInNotification(SlideInDialog contents) { + initDesktopBounds(); + setContents(contents); + show(); + } + + protected void initDesktopBounds() { + GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); + desktopBounds = env.getMaximumWindowBounds(); + } + + public void setContents(SlideInDialog contents) { + this.contents = contents; + JWindow tempWindow = new JWindow(); + tempWindow.getContentPane().add (contents); + tempWindow.pack(); + tempWindowSize = tempWindow.getSize(); + tempWindow.getContentPane().removeAll(); + window = new JWindow(); + animatingSheet = new AnimatingSheet(); + animatingSheet.setSource(contents); + window.getContentPane().add(animatingSheet); + contents.setHoldingWindow(window); + } + + /** + * Create a window with an animating sheet, copy over its contents from + * the temp window and animate it. When done, remove animating sheet and + * add real contents + * @param slideInDialogWidth Width of the slide-in dialog panel + */ + public void show() { + showX = desktopBounds.width - contents.getWidth() - 2; + startY = desktopBounds.y + desktopBounds.height; + + ActionListener animationLogic = new ActionListener() { + public void actionPerformed(ActionEvent e) { + long elapsed = System.currentTimeMillis() - animationStart; + if (elapsed > ANIMATION_TIME) { + // Put real contents in window and show + window.getContentPane().removeAll(); + window.getContentPane().add(contents); + window.pack(); + window.setLocation(showX, startY - window.getSize().height); + window.setVisible(true); + window.repaint(); + animationTimer.stop(); + animationTimer = null; + } else { + // Calculate percentage done + float progress = (float) elapsed / ANIMATION_TIME_F; + // Get height to show + int animatingHeight = (int) (progress * tempWindowSize.getHeight()); + animatingHeight = Math.max(animatingHeight, 1); + animatingSheet.setAnimatingHeight(animatingHeight); + window.pack(); + window.setLocation(showX, startY - window.getHeight()); + window.setVisible(true); + window.repaint(); + } + } + }; + animationTimer = new Timer(ANIMATION_DELAY, animationLogic); + animationStart = System.currentTimeMillis(); + animationTimer.start(); + } + + /** AnimatingSheet inner class + * + */ + class AnimatingSheet extends JComponent { + Dimension animatingSize = new Dimension (0, 1); + JComponent source; + BufferedImage offscreenImage; + + public AnimatingSheet() { + setOpaque(true); + } + + public void setSource(JComponent source) { + this.source = source; + animatingSize.width = source.getWidth( ); + makeOffscreenImage(source); + } + + public void setAnimatingHeight(int height) { + animatingSize.height = height; + setSize(animatingSize); + } + + private void makeOffscreenImage(JComponent source) { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsConfiguration gfxConfig = ge.getDefaultScreenDevice().getDefaultConfiguration(); + offscreenImage = gfxConfig.createCompatibleImage(source.getWidth(), source.getHeight()); + Graphics2D offscreenGraphics = (Graphics2D) offscreenImage.getGraphics(); + + // Workaround for Windows OS problem + offscreenGraphics.setColor(source.getBackground()); + offscreenGraphics.fillRect(0, 0, source.getWidth(), source.getHeight()); + + // Paint from source to offscreen buffer + source.paint(offscreenGraphics); + } + + @Override + public Dimension getPreferredSize() { return animatingSize; } + + @Override + public Dimension getMinimumSize() { return animatingSize; } + + @Override + public Dimension getMaximumSize() { return animatingSize; } + + @Override + // Override to eliminate flicker from unnecessary clear + public void update(Graphics g) { + paint(g); + } + + @Override + public void paint(Graphics g) { + // Get the top-most n pixels of source and paint them into g, where n is height + BufferedImage fragment = offscreenImage.getSubimage( + 0, 0, source.getWidth(), animatingSize.height); + g.drawImage(fragment, 0, 0, this); + } + + } + +} diff --git a/src/SlideInScanPanel.form b/src/SlideInScanPanel.form new file mode 100644 index 0000000..bee4ca3 --- /dev/null +++ b/src/SlideInScanPanel.form @@ -0,0 +1,151 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/SlideInScanPanel.java b/src/SlideInScanPanel.java new file mode 100644 index 0000000..2c8749c --- /dev/null +++ b/src/SlideInScanPanel.java @@ -0,0 +1,244 @@ +/* + * SlideInScanPanel.java + * + * Created on July 25, 2008, 6:56 AM + */ + +import java.awt.*; +import javax.swing.JFrame; + +/** + * + * @author Sharafat + */ +public class SlideInScanPanel extends javax.swing.JPanel { + private Scan scan; + private Scan.DoScan doScan; + private ScanFrame scanFrame; + protected boolean isPaused = false; + + + /** Creates new form SlideInScanPanel */ + SlideInScanPanel(Scan currScan, Scan.DoScan doScan, ScanFrame scanFrame) { + this.scan = currScan; + this.doScan = doScan; + this.scanFrame = scanFrame; + initComponents(); + } + + /** 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. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + pause = new javax.swing.JLabel(); + stop = new javax.swing.JLabel(); + progress = new javax.swing.JProgressBar(); + separator1 = new javax.swing.JLabel(); + details = new javax.swing.JLabel(); + separator2 = new javax.swing.JLabel(); + scanning = new javax.swing.JLabel(); + + setBackground(new java.awt.Color(255, 255, 255)); + + pause.setBackground(new java.awt.Color(255, 255, 255)); + pause.setText("PauseStop"); + stop.setToolTipText("Stop Scanning"); + stop.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); + stop.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + stopMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + stopMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + stopMouseExited(evt); + } + }); + + progress.setBackground(new java.awt.Color(255, 255, 255)); + progress.setStringPainted(true); + + separator1.setText("|"); + + details.setText("Details..."); + details.setToolTipText("Show Scanning Details"); + details.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); + details.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseClicked(java.awt.event.MouseEvent evt) { + detailsMouseClicked(evt); + } + public void mouseEntered(java.awt.event.MouseEvent evt) { + detailsMouseEntered(evt); + } + public void mouseExited(java.awt.event.MouseEvent evt) { + detailsMouseExited(evt); + } + }); + + separator2.setText("|"); + + scanning.setBackground(new java.awt.Color(255, 255, 255)); + scanning.setText("Scanning..."); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(29, 29, 29) + .addComponent(pause, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(separator2, javax.swing.GroupLayout.PREFERRED_SIZE, 4, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(10, 10, 10) + .addComponent(stop, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(separator1, javax.swing.GroupLayout.PREFERRED_SIZE, 4, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(details, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE) + .addGap(31, 31, 31)) + .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(scanning, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(scanning) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(separator1) + .addComponent(stop) + .addComponent(separator2) + .addComponent(details) + .addComponent(pause)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pause.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + stop.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + details.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + }// //GEN-END:initComponents + +private void pauseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pauseMouseClicked + if (scan.shouldPauseScanning) { + isPaused = false; + pause.setText("PauseResumeResume"); + } else { + pause.setText("Pause"); + } +}//GEN-LAST:event_pauseMouseEntered + +private void pauseMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pauseMouseExited + if (isPaused) { + pause.setText("Resume"); + } else { + pause.setText("Pause"); + } +}//GEN-LAST:event_pauseMouseExited + +private void stopMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stopMouseClicked + scan.shouldStopScanning = true; + scan.stop.setEnabled(false); + scan.pause.setEnabled(false); + + if (doScan.detectedTableModel.getRowCount() > 0) { + scan.detectedAction.setEnabled(true); + } + if (doScan.suspectedTableModel.getRowCount() > 0) { + scan.suspectedAction.setEnabled(true); + } + + pause.removeMouseListener(pause.getMouseListeners()[0]); + pause.removeMouseListener(pause.getMouseListeners()[0]); + pause.setForeground(Color.DARK_GRAY); + pause.setText("Pause"); + pause.setCursor(Cursor.getDefaultCursor()); + + stop.removeMouseListener(stop.getMouseListeners()[0]); + stop.removeMouseListener(stop.getMouseListeners()[0]); + stop.setForeground(Color.DARK_GRAY); + stop.setText("Stop"); + stop.setCursor(Cursor.getDefaultCursor()); +}//GEN-LAST:event_stopMouseClicked + +private void stopMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stopMouseEntered + stop.setText("Stop"); +}//GEN-LAST:event_stopMouseEntered + +private void stopMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stopMouseExited + stop.setText("Stop"); +}//GEN-LAST:event_stopMouseExited + +private void detailsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_detailsMouseClicked + scanFrame.panel.removeAll(); + scanFrame.validate(); + scanFrame.panel.repaint(); + scanFrame.panel.add(scan); + Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); + scanFrame.setLocation(((screenDim.width - scanFrame.getWidth()) / 2), + ((screenDim.height - scanFrame.getHeight()) / 2)); + scanFrame.setVisible(true); + scanFrame.setExtendedState(JFrame.NORMAL); + scanFrame.toFront(); +}//GEN-LAST:event_detailsMouseClicked + +private void detailsMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_detailsMouseEntered + details.setText("Details..."); +}//GEN-LAST:event_detailsMouseEntered + +private void detailsMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_detailsMouseExited + details.setText("Details..."); +}//GEN-LAST:event_detailsMouseExited + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel details; + protected javax.swing.JLabel pause; + protected javax.swing.JProgressBar progress; + protected javax.swing.JLabel scanning; + private javax.swing.JLabel separator1; + private javax.swing.JLabel separator2; + protected javax.swing.JLabel stop; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/images/USBWP_logo.png b/src/images/USBWP_logo.png new file mode 100644 index 0000000..c174b0c Binary files /dev/null and b/src/images/USBWP_logo.png differ diff --git a/src/images/about.png b/src/images/about.png new file mode 100644 index 0000000..8770087 Binary files /dev/null and b/src/images/about.png differ diff --git a/src/images/attention.png b/src/images/attention.png new file mode 100644 index 0000000..10b9ed0 Binary files /dev/null and b/src/images/attention.png differ diff --git a/src/images/background_blue.png b/src/images/background_blue.png new file mode 100644 index 0000000..477e540 Binary files /dev/null and b/src/images/background_blue.png differ diff --git a/src/images/background_yellow.png b/src/images/background_yellow.png new file mode 100644 index 0000000..0b18f0b Binary files /dev/null and b/src/images/background_yellow.png differ diff --git a/src/images/deleted.png b/src/images/deleted.png new file mode 100644 index 0000000..aa13242 Binary files /dev/null and b/src/images/deleted.png differ diff --git a/src/images/deselectAll.png b/src/images/deselectAll.png new file mode 100644 index 0000000..776b0bb Binary files /dev/null and b/src/images/deselectAll.png differ diff --git a/src/images/detected.png b/src/images/detected.png new file mode 100644 index 0000000..6754c48 Binary files /dev/null and b/src/images/detected.png differ diff --git a/src/images/disabledTrayIcon.png b/src/images/disabledTrayIcon.png new file mode 100644 index 0000000..f455aab Binary files /dev/null and b/src/images/disabledTrayIcon.png differ diff --git a/src/images/header_blue.png b/src/images/header_blue.png new file mode 100644 index 0000000..2b3f4d0 Binary files /dev/null and b/src/images/header_blue.png differ diff --git a/src/images/header_blue_2.png b/src/images/header_blue_2.png new file mode 100644 index 0000000..6107511 Binary files /dev/null and b/src/images/header_blue_2.png differ diff --git a/src/images/icon.png b/src/images/icon.png new file mode 100644 index 0000000..c473ac6 Binary files /dev/null and b/src/images/icon.png differ diff --git a/src/images/info.png b/src/images/info.png new file mode 100644 index 0000000..8b4d67b Binary files /dev/null and b/src/images/info.png differ diff --git a/src/images/info2.png b/src/images/info2.png new file mode 100644 index 0000000..26c1e62 Binary files /dev/null and b/src/images/info2.png differ diff --git a/src/images/overlay.png b/src/images/overlay.png new file mode 100644 index 0000000..4118ce7 Binary files /dev/null and b/src/images/overlay.png differ diff --git a/src/images/pauseDialog.png b/src/images/pauseDialog.png new file mode 100644 index 0000000..cdd7a52 Binary files /dev/null and b/src/images/pauseDialog.png differ diff --git a/src/images/preferences.png b/src/images/preferences.png new file mode 100644 index 0000000..0386f8a Binary files /dev/null and b/src/images/preferences.png differ diff --git a/src/images/reload.png b/src/images/reload.png new file mode 100644 index 0000000..4cb8c78 Binary files /dev/null and b/src/images/reload.png differ diff --git a/src/images/scan.gif b/src/images/scan.gif new file mode 100644 index 0000000..fa67c3b Binary files /dev/null and b/src/images/scan.gif differ diff --git a/src/images/scan.png b/src/images/scan.png new file mode 100644 index 0000000..23b4e69 Binary files /dev/null and b/src/images/scan.png differ diff --git a/src/images/scan_end.png b/src/images/scan_end.png new file mode 100644 index 0000000..66c23ca Binary files /dev/null and b/src/images/scan_end.png differ diff --git a/src/images/selectAll.png b/src/images/selectAll.png new file mode 100644 index 0000000..be34d17 Binary files /dev/null and b/src/images/selectAll.png differ diff --git a/src/images/suspected.png b/src/images/suspected.png new file mode 100644 index 0000000..3b8cab4 Binary files /dev/null and b/src/images/suspected.png differ diff --git a/src/images/tip.png b/src/images/tip.png new file mode 100644 index 0000000..93fceee Binary files /dev/null and b/src/images/tip.png differ diff --git a/src/images/warning.png b/src/images/warning.png new file mode 100644 index 0000000..bbbc25f Binary files /dev/null and b/src/images/warning.png differ