From 57d6b0c6b96097afa06a38cc2456997ad9b60187 Mon Sep 17 00:00:00 2001
From: Marko Živković
Date: Tue, 16 Dec 2014 02:05:55 +0000
Subject: - USB Stick Recognition, automatically propose workspace - New
Default Workspace in user home directory - Automatically select last active
user now works - Several bug fixes and minor changes
git-svn-id: https://svn.code.sf.net/p/xlogo4schools/svn/trunk@11 3b0d7934-f7ef-4143-9606-b51f2e2281fd
---
logo/build.xml | 21 +-
logo/log4j-api-2.1.jar | Bin 0 -> 133531 bytes
logo/log4j-core-2.1.jar | Bin 0 -> 824749 bytes
logo/manifest_start | 2 +-
logo/manifest_xlogo | 3 +-
logo/src/Lanceur.java | 65 +-
logo/src/log4j2.xml | 22 +
.../USBDeviceDetectorManager.java | 127 ++++
.../usbdrivedectector/USBStorageDevice.java | 130 ++++
.../detectors/AbstractStorageDeviceDetector.java | 92 +++
.../detectors/LinuxStorageDeviceDetector.java | 111 ++++
.../detectors/OSXStorageDeviceDetector.java | 80 +++
.../detectors/WindowsStorageDeviceDetector.java | 128 ++++
.../usbdrivedectector/events/DeviceEventType.java | 27 +
.../events/IUSBDriveListener.java | 28 +
.../usbdrivedectector/events/USBStorageEvent.java | 46 ++
.../process/CommandLineExecutor.java | 77 +++
logo/src/xlogo/AppSettings.java | 6 +
logo/src/xlogo/Application.java | 14 +-
logo/src/xlogo/Logo.java | 8 +-
logo/src/xlogo/MemoryChecker.java | 8 +-
logo/src/xlogo/MenuListener.java | 8 +-
logo/src/xlogo/Popup.java | 8 +-
logo/src/xlogo/Sound_Player.java | 8 +-
logo/src/xlogo/StyledDocument/DocumentLogo.java | 8 +-
.../xlogo/StyledDocument/DocumentLogoCommande.java | 8 +-
.../StyledDocument/DocumentLogoHistorique.java | 8 +-
logo/src/xlogo/gpl/x4s_info.html | 15 +-
logo/src/xlogo/gui/AImprimer.java | 8 +-
logo/src/xlogo/gui/Editor.java | 8 +-
logo/src/xlogo/gui/EditorTextArea.java | 8 +-
logo/src/xlogo/gui/EditorTextPane.java | 8 +-
logo/src/xlogo/gui/EditorTextZone.java | 8 +-
logo/src/xlogo/gui/HistoryPanel.java | 10 +-
logo/src/xlogo/gui/Lis.java | 8 +-
logo/src/xlogo/gui/MyTextAreaDialog.java | 8 +-
logo/src/xlogo/gui/MyToolBar.java | 8 +-
logo/src/xlogo/gui/ReplaceFrame.java | 8 +-
logo/src/xlogo/gui/SearchFrame.java | 8 +-
logo/src/xlogo/gui/Searchable.java | 8 +-
logo/src/xlogo/gui/Traduc.java | 8 +-
logo/src/xlogo/gui/ZoneCommande.java | 8 +-
logo/src/xlogo/gui/ZoneEdition.java | 8 +-
.../gui/components/ColorStyleSelectionPanel.java | 8 +-
logo/src/xlogo/gui/components/ProcedureSearch.java | 6 +-
logo/src/xlogo/gui/components/TurtleComboBox.java | 6 +-
logo/src/xlogo/gui/components/X4SComponent.java | 6 +-
logo/src/xlogo/gui/components/X4SFrame.java | 6 +-
logo/src/xlogo/gui/components/X4SGui.java | 6 +-
.../xlogo/gui/components/fileslist/FilesList.java | 6 +-
.../gui/components/fileslist/FilesListItem.java | 6 +-
.../gui/components/fileslist/IFilesListItem.java | 6 +-
.../xlogo/gui/preferences/AbstractPanelColor.java | 8 +-
logo/src/xlogo/gui/preferences/PanelColor.java | 8 +-
logo/src/xlogo/gui/translation/BottomPanel.java | 8 +-
logo/src/xlogo/gui/translation/FirstPanel.java | 8 +-
logo/src/xlogo/gui/translation/MyTable.java | 8 +-
logo/src/xlogo/gui/translation/TopPanel.java | 8 +-
logo/src/xlogo/gui/translation/TranslateXLogo.java | 10 +-
logo/src/xlogo/gui/welcome/WelcomeScreen.java | 447 +++++++-------
logo/src/xlogo/gui/welcome/WorkspaceSettings.java | 6 +-
.../settings/tabs/AbstractWorkspacePanel.java | 24 +-
.../gui/welcome/settings/tabs/ContestTab.java | 6 +-
.../xlogo/gui/welcome/settings/tabs/GlobalTab.java | 6 +-
.../settings/tabs/SyntaxHighlightingTab.java | 6 +-
.../settings/tabs/WorkspaceCreationPanel.java | 6 +-
.../gui/welcome/settings/tabs/WorkspaceTab.java | 22 +-
logo/src/xlogo/interfaces/BasicFileContainer.java | 6 +-
.../interfaces/BroadcasterErrorFileContainer.java | 6 +-
logo/src/xlogo/interfaces/ErrorDetector.java | 6 +-
logo/src/xlogo/interfaces/MessageBroadcaster.java | 6 +-
logo/src/xlogo/interfaces/ProcedureMapper.java | 6 +-
logo/src/xlogo/interfaces/X4SModeSwitcher.java | 6 +-
logo/src/xlogo/kernel/Affichage.java | 8 +-
logo/src/xlogo/kernel/DrawPanel.java | 8 +-
logo/src/xlogo/kernel/InstructionBuffer.java | 8 +-
logo/src/xlogo/kernel/Interprete.java | 8 +-
logo/src/xlogo/kernel/Kernel.java | 8 +-
logo/src/xlogo/kernel/LaunchPrimitive.java | 8 +-
logo/src/xlogo/kernel/LogoError.java | 6 +-
logo/src/xlogo/kernel/LoopFillPolygon.java | 8 +-
logo/src/xlogo/kernel/LoopFor.java | 8 +-
logo/src/xlogo/kernel/LoopForEach.java | 8 +-
logo/src/xlogo/kernel/LoopProperties.java | 8 +-
logo/src/xlogo/kernel/LoopRepeat.java | 8 +-
logo/src/xlogo/kernel/LoopWhile.java | 8 +-
logo/src/xlogo/kernel/MP3Player.java | 8 +-
logo/src/xlogo/kernel/MyCalculator.java | 8 +-
logo/src/xlogo/kernel/MyFlow.java | 8 +-
logo/src/xlogo/kernel/MyFlowReader.java | 8 +-
logo/src/xlogo/kernel/MyFlowWriter.java | 8 +-
logo/src/xlogo/kernel/Primitive.java | 8 +-
logo/src/xlogo/kernel/Turtle.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoException.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoList.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoNumber.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoParser.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoPrimitive.java | 8 +-
.../xlogo/kernel/grammar/LogoRightDelimiter.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoTree.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoType.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoTypeNull.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoVariable.java | 8 +-
logo/src/xlogo/kernel/grammar/LogoWord.java | 8 +-
logo/src/xlogo/kernel/gui/GuiButton.java | 8 +-
logo/src/xlogo/kernel/gui/GuiComponent.java | 8 +-
logo/src/xlogo/kernel/gui/GuiMap.java | 8 +-
logo/src/xlogo/kernel/gui/GuiMenu.java | 8 +-
logo/src/xlogo/kernel/network/ChatFrame.java | 8 +-
.../xlogo/kernel/network/NetworkClientChat.java | 8 +-
.../xlogo/kernel/network/NetworkClientExecute.java | 8 +-
.../xlogo/kernel/network/NetworkClientSend.java | 8 +-
logo/src/xlogo/kernel/network/NetworkServer.java | 8 +-
logo/src/xlogo/kernel/perspective/Conic.java | 8 +-
logo/src/xlogo/kernel/perspective/Element3D.java | 8 +-
logo/src/xlogo/kernel/perspective/ElementLine.java | 8 +-
.../src/xlogo/kernel/perspective/ElementPoint.java | 8 +-
.../xlogo/kernel/perspective/ElementPolygon.java | 8 +-
logo/src/xlogo/kernel/perspective/FogDialog.java | 8 +-
logo/src/xlogo/kernel/perspective/LightDialog.java | 8 +-
logo/src/xlogo/kernel/perspective/MyFog.java | 8 +-
logo/src/xlogo/kernel/perspective/MyLight.java | 8 +-
logo/src/xlogo/kernel/perspective/Viewer3D.java | 8 +-
logo/src/xlogo/kernel/perspective/World3D.java | 8 +-
logo/src/xlogo/kernel/userspace/ErrorManager.java | 6 +-
.../kernel/userspace/GlobalVariableTable.java | 6 +-
.../kernel/userspace/ProcedureErrorMessage.java | 6 +-
.../xlogo/kernel/userspace/PropertyListTable.java | 6 +-
logo/src/xlogo/kernel/userspace/UserSpace.java | 6 +-
.../kernel/userspace/context/ContextManager.java | 6 +-
.../kernel/userspace/context/ContextSwitcher.java | 6 +-
.../kernel/userspace/context/LogoContext.java | 10 +-
.../kernel/userspace/context/NetworkContext.java | 8 +-
.../kernel/userspace/context/RecordContext.java | 6 +-
.../kernel/userspace/context/UserContext.java | 6 +-
.../src/xlogo/kernel/userspace/files/LogoFile.java | 26 +-
.../kernel/userspace/files/LogoFileContainer.java | 6 +-
.../kernel/userspace/files/LogoFilesManager.java | 6 +-
.../xlogo/kernel/userspace/files/RecordFile.java | 12 +-
.../userspace/procedures/ExecutablesContainer.java | 6 +-
.../userspace/procedures/ExecutablesProvider.java | 6 +-
.../kernel/userspace/procedures/Procedure.java | 18 +-
.../userspace/procedures/ProcedureErrorType.java | 6 +-
.../userspace/procedures/ProceduresManager.java | 6 +-
logo/src/xlogo/messages/Message.java | 6 +-
logo/src/xlogo/messages/MessageKeys.java | 6 +-
logo/src/xlogo/messages/Messenger.java | 6 +-
.../messages/async/AbstractAsyncMessenger.java | 6 +-
.../xlogo/messages/async/AsyncMediumAdapter.java | 6 +-
logo/src/xlogo/messages/async/AsyncMessage.java | 6 +-
logo/src/xlogo/messages/async/AsyncMessenger.java | 6 +-
.../xlogo/messages/async/dialog/DialogMessage.java | 6 +-
.../messages/async/dialog/DialogMessenger.java | 6 +-
.../messages/async/history/HistoryMessage.java | 6 +-
.../messages/async/history/HistoryMessenger.java | 6 +-
.../messages/async/history/HistoryWriter.java | 6 +-
logo/src/xlogo/storage/Storable.java | 158 ++---
logo/src/xlogo/storage/StorableDocument.java | 14 +-
logo/src/xlogo/storage/StorableObject.java | 107 ++--
logo/src/xlogo/storage/WSManager.java | 6 +-
logo/src/xlogo/storage/global/GlobalConfig.java | 658 ++++++++++++++-------
logo/src/xlogo/storage/user/DrawQuality.java | 6 +-
logo/src/xlogo/storage/user/LookAndFeel.java | 6 +-
logo/src/xlogo/storage/user/PenShape.java | 6 +-
logo/src/xlogo/storage/user/UserConfig.java | 8 +-
.../src/xlogo/storage/workspace/ContestConfig.java | 6 +-
logo/src/xlogo/storage/workspace/Language.java | 6 +-
.../xlogo/storage/workspace/NumberOfBackups.java | 6 +-
.../storage/workspace/SyntaxHighlightConfig.java | 6 +-
.../xlogo/storage/workspace/WorkspaceConfig.java | 519 +++++++++-------
logo/src/xlogo/utils/ExtensionFichier.java | 8 +-
logo/src/xlogo/utils/Utils.java | 8 +-
logo/src/xlogo/utils/WebPage.java | 8 +-
logo/src/xlogo/utils/WriteImage.java | 8 +-
174 files changed, 2684 insertions(+), 1355 deletions(-)
create mode 100644 logo/log4j-api-2.1.jar
create mode 100644 logo/log4j-core-2.1.jar
create mode 100644 logo/src/log4j2.xml
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/USBDeviceDetectorManager.java
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/USBStorageDevice.java
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/detectors/AbstractStorageDeviceDetector.java
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/detectors/LinuxStorageDeviceDetector.java
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/detectors/OSXStorageDeviceDetector.java
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/detectors/WindowsStorageDeviceDetector.java
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/events/DeviceEventType.java
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/events/IUSBDriveListener.java
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/events/USBStorageEvent.java
create mode 100644 logo/src/net/samuelcampos/usbdrivedectector/process/CommandLineExecutor.java
diff --git a/logo/build.xml b/logo/build.xml
index 744b87a..81b1701 100644
--- a/logo/build.xml
+++ b/logo/build.xml
@@ -17,7 +17,7 @@
Does the Jar has to be signed ?
================================-->
-
+
-
-
+
+
+
@@ -149,13 +154,16 @@
+ srcdir="src" destdir="deploy/"
+ includeantruntime="false">
+
+
@@ -171,11 +179,14 @@
+
+
+
diff --git a/logo/log4j-api-2.1.jar b/logo/log4j-api-2.1.jar
new file mode 100644
index 0000000..d18d67c
Binary files /dev/null and b/logo/log4j-api-2.1.jar differ
diff --git a/logo/log4j-core-2.1.jar b/logo/log4j-core-2.1.jar
new file mode 100644
index 0000000..be2e917
Binary files /dev/null and b/logo/log4j-core-2.1.jar differ
diff --git a/logo/manifest_start b/logo/manifest_start
index 8c57194..975c025 100644
--- a/logo/manifest_start
+++ b/logo/manifest_start
@@ -1 +1 @@
-Main-Class: Lanceur
+Main-Class: Lanceur
\ No newline at end of file
diff --git a/logo/manifest_xlogo b/logo/manifest_xlogo
index 3753e91..c54efab 100644
--- a/logo/manifest_xlogo
+++ b/logo/manifest_xlogo
@@ -1,3 +1,2 @@
Main-Class: xlogo.Logo
-Class-Path: jh.jar vecmath.jar j3dcore.jar j3dutils.jar jl1.0.1.jar
-
+Class-Path: jh.jar vecmath.jar j3dcore.jar j3dutils.jar jl1.0.1.jar log4j-api-2.1.jar log4j-core-2.1.jar
\ No newline at end of file
diff --git a/logo/src/Lanceur.java b/logo/src/Lanceur.java
index ce65803..e45c397 100644
--- a/logo/src/Lanceur.java
+++ b/logo/src/Lanceur.java
@@ -1,4 +1,4 @@
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -16,13 +16,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* modifications, extensions, refactorings might have been applied by Marko Zivkovic
*/
@@ -68,7 +68,7 @@ public class Lanceur
* The temporary folder which contains all files to start XLogo
*/
private File tmpFolder = null;
- private File[] files = new File[10];
+ private File[] files = new File[12];
/**
* Main method
@@ -285,13 +285,24 @@ public class Lanceur
b = copier(src, files[4]);
System.out.println("Copying j3dutils.jar - success: " + b);
- // extract the file jl1.0.1 in this folder (JLayer library for mp3
- // playing)
+ // extract the file jl1.0.1 in this folder (JLayer library for mp3 playing)
src = Lanceur.class.getResourceAsStream("jl1.0.1.jar");
files[5] = new File(tmpFolder.getAbsolutePath() + File.separator + "jl1.0.1.jar");
b = copier(src, files[5]);
System.out.println("Copying jl1.0.1.jar - success: " + b);
+ // extract the file jl1.0.1 in this folder (JLayer library for mp3 playing)
+ src = Lanceur.class.getResourceAsStream("log4j-api-2.1.jar");
+ files[6] = new File(tmpFolder.getAbsolutePath() + File.separator + "log4j-api-2.1.jar");
+ b = copier(src, files[6]);
+ System.out.println("Copying log4j-api-2.1.jar - success: " + b);
+
+ // extract the file jl1.0.1 in this folder (JLayer library for mp3 playing)
+ src = Lanceur.class.getResourceAsStream("log4j-core-2.1.jar");
+ files[7] = new File(tmpFolder.getAbsolutePath() + File.separator + "log4j-core-2.1.jar");
+ b = copier(src, files[7]);
+ System.out.println("Copying log4j-core-2.1.jar - success: " + b);
+
// extract the native driver for java 3d in this folder
String os = System.getProperty("os.name").toLowerCase();
String arch = System.getProperty("os.arch");
@@ -304,17 +315,17 @@ public class Lanceur
if (arch.indexOf("86") != -1)
{
InputStream lib = Lanceur.class.getResourceAsStream("linux/x86/libj3dcore-ogl.so");
- files[6] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl.so");
- copier(lib, files[6]);
+ files[8] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl.so");
+ copier(lib, files[8]);
lib = Lanceur.class.getResourceAsStream("linux/x86/libj3dcore-ogl-cg.so");
- files[7] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl-cg.so");
- copier(lib, files[7]);
+ files[9] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl-cg.so");
+ copier(lib, files[9]);
}
else
{
InputStream lib = Lanceur.class.getResourceAsStream("linux/amd64/libj3dcore-ogl.so");
- files[6] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl.so");
- copier(lib, files[6]);
+ files[8] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl.so");
+ copier(lib, files[8]);
}
}
// windows
@@ -323,27 +334,27 @@ public class Lanceur
if (arch.indexOf("86") != -1)
{
InputStream lib = Lanceur.class.getResourceAsStream("windows/x86/j3dcore-d3d.dll");
- files[6] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-d3d.dll");
- b = copier(lib, files[6]);
+ files[8] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-d3d.dll");
+ b = copier(lib, files[8]);
System.out.println("Copying library 1 - success: " + b);
lib = Lanceur.class.getResourceAsStream("windows/x86/j3dcore-ogl.dll");
- files[7] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-ogl.dll");
- b = copier(lib, files[7]);
+ files[9] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-ogl.dll");
+ b = copier(lib, files[9]);
System.out.println("Copying library 2 - success: " + b);
lib = Lanceur.class.getResourceAsStream("windows/x86/j3dcore-ogl-cg.dll");
- files[8] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-ogl-cg.dll");
- b = copier(lib, files[8]);
+ files[10] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-ogl-cg.dll");
+ b = copier(lib, files[10]);
System.out.println("Copying library 3 - success: " + b);
lib = Lanceur.class.getResourceAsStream("windows/x86/j3dcore-ogl-chk.dll");
- files[9] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-ogl-chk.dll");
- b = copier(lib, files[9]);
+ files[11] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-ogl-chk.dll");
+ b = copier(lib, files[11]);
System.out.println("Copying library 4 - success: " + b);
}
else
{
InputStream lib = Lanceur.class.getResourceAsStream("windows/amd64/j3dcore-ogl.dll");
- files[6] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-ogl.dll");
- b = copier(lib, files[6]);
+ files[8] = new File(tmpFolder.getAbsolutePath() + File.separator + "j3dcore-ogl.dll");
+ b = copier(lib, files[8]);
System.out.println("Copying library 1 - success: " + b);
}
}
@@ -358,15 +369,15 @@ public class Lanceur
if (arch.indexOf("86") != -1)
{
InputStream lib = Lanceur.class.getResourceAsStream("solaris/i386/libj3dcore-ogl.so");
- files[6] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl.so");
- b = copier(lib, files[6]);
+ files[8] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl.so");
+ b = copier(lib, files[8]);
System.out.println("Copying library 1 - success: " + b);
}
else if (arch.indexOf("amd64") != -1)
{
InputStream lib = Lanceur.class.getResourceAsStream("solaris/amd64/libj3dcore-ogl.so");
- files[6] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl.so");
- b = copier(lib, files[6]);
+ files[8] = new File(tmpFolder.getAbsolutePath() + File.separator + "libj3dcore-ogl.so");
+ b = copier(lib, files[8]);
System.out.println("Copying library 1 - success: " + b);
}
}
diff --git a/logo/src/log4j2.xml b/logo/src/log4j2.xml
new file mode 100644
index 0000000..f425253
--- /dev/null
+++ b/logo/src/log4j2.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/USBDeviceDetectorManager.java b/logo/src/net/samuelcampos/usbdrivedectector/USBDeviceDetectorManager.java
new file mode 100644
index 0000000..a0d3de1
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/USBDeviceDetectorManager.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package net.samuelcampos.usbdrivedectector;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import net.samuelcampos.usbdrivedectector.detectors.AbstractStorageDeviceDetector;
+import net.samuelcampos.usbdrivedectector.events.DeviceEventType;
+import net.samuelcampos.usbdrivedectector.events.IUSBDriveListener;
+import net.samuelcampos.usbdrivedectector.events.USBStorageEvent;
+
+/**
+ * @author samuelcampos
+ */
+public class USBDeviceDetectorManager {
+
+ private static final Logger logger = LogManager
+ .getLogger(USBDeviceDetectorManager.class);
+
+ private static final long defaultPoolingInterval = 10 * 1000;
+
+ private Set connectedDevices;
+ private List listeners;
+ private Timer timer;
+
+ public USBDeviceDetectorManager() {
+ this(defaultPoolingInterval);
+ }
+
+ public USBDeviceDetectorManager(long poolingInterval) {
+ listeners = new ArrayList();
+
+ connectedDevices = new HashSet();
+
+ timer = new Timer();
+ timer.scheduleAtFixedRate(new ListenerTask(), poolingInterval, poolingInterval);
+ }
+
+ public synchronized boolean addDriveListener(IUSBDriveListener listener) {
+ if (listeners.contains(listener)) {
+ return false;
+ }
+
+ listeners.add(listener);
+
+ return true;
+ }
+
+ public synchronized boolean removeDriveListener(IUSBDriveListener listener) {
+ return listeners.remove(listener);
+ }
+
+ public List getRemovableDevices() {
+ return AbstractStorageDeviceDetector.getInstance().getRemovableDevices();
+ }
+
+ private void updateState(List actualConnectedDevices) {
+ USBStorageEvent event;
+
+ synchronized(this) {
+ Iterator itConnectedDevices = connectedDevices.iterator();
+
+ while (itConnectedDevices.hasNext()) {
+ USBStorageDevice device = itConnectedDevices.next();
+
+ if (!actualConnectedDevices.contains(device)) {
+ event = new USBStorageEvent(device, DeviceEventType.REMOVED);
+ sendEventToListeners(event);
+
+ itConnectedDevices.remove();
+ } else {
+ actualConnectedDevices.remove(device);
+ }
+ }
+
+ connectedDevices.addAll(actualConnectedDevices);
+ }
+
+ for(USBStorageDevice dev : actualConnectedDevices) {
+ event = new USBStorageEvent(dev, DeviceEventType.CONNECTED);
+ sendEventToListeners(event);
+ }
+ }
+
+ private void sendEventToListeners(USBStorageEvent event) {
+ for (IUSBDriveListener listener : listeners) {
+ listener.usbDriveEvent(event);
+ }
+ }
+
+ private class ListenerTask extends TimerTask {
+
+ @Override
+ public void run() {
+ logger.trace("Pooling refresh task is running");
+
+ List actualConnectedDevices = AbstractStorageDeviceDetector.getInstance().getRemovableDevices();
+
+ updateState(actualConnectedDevices);
+ }
+
+ }
+}
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/USBStorageDevice.java b/logo/src/net/samuelcampos/usbdrivedectector/USBStorageDevice.java
new file mode 100644
index 0000000..1f3eb85
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/USBStorageDevice.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.samuelcampos.usbdrivedectector;
+
+import java.io.File;
+import javax.swing.filechooser.FileSystemView;
+
+/**
+ * Class to represent a USB Storage Device connected on the computer
+ *
+ * @author samuelcampos
+ */
+public class USBStorageDevice {
+ private File rootDirectory;
+ private String deviceName;
+ private String systemDisplayName; // Marko Zivkovic: added this field, so the name is available even after the device was removed
+
+ public USBStorageDevice(File rootDirectory, String deviceName){
+ if(rootDirectory == null || !rootDirectory.isDirectory()){
+ throw new IllegalArgumentException("Invalid root file!");
+ }
+
+ this.rootDirectory = rootDirectory;
+
+ if(deviceName == null || deviceName.isEmpty()) {
+ deviceName = rootDirectory.getName();
+ }
+
+ this.deviceName = deviceName;
+ this.systemDisplayName = FileSystemView.getFileSystemView().getSystemDisplayName(rootDirectory);
+ }
+
+ public USBStorageDevice(File rootDirectory){
+ this(rootDirectory, null);
+ }
+
+ public File getRootDirectory() {
+ return rootDirectory;
+ }
+
+ /**
+ *
+ * @return the name of the USB storage device
+ */
+ public String getDeviceName() {
+ return deviceName;
+ }
+
+ /**
+ * Check if it is possible to read in this device.
+ *
+ * @see File#canRead()
+ *
+ * @return true if it is possible to perform read operations in this device, false otherwise.
+ */
+ public boolean canRead() {
+ return rootDirectory.canRead();
+ }
+
+ /**
+ * Check if it is possible to write in this device.
+ *
+ * @see File#canWrite()
+ *
+ * @return true if it is possible to perform write operations in this device, false otherwise.
+ */
+ public boolean canWrite() {
+ return rootDirectory.canWrite();
+ }
+
+ /**
+ * Check if the actual user has execute permissions in this drive.
+ *
+ * @see File#canWrite()
+ *
+ * @return true if it is possible to perform execute operations in this device, false otherwise.
+ */
+ public boolean canExecute() {
+ return rootDirectory.canExecute();
+ }
+
+ /**
+ * @see FileSystemView#getSystemDisplayName(java.io.File)
+ *
+ * @return the name of the root of this device as it would be displayed in a system file browser.
+ */
+ public String getSystemDisplayName() {
+ return systemDisplayName;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 89 * hash + (this.rootDirectory != null ? this.rootDirectory.hashCode() : 0);
+ hash = 89 * hash + (this.deviceName != null ? this.deviceName.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final USBStorageDevice other = (USBStorageDevice) obj;
+ return this.rootDirectory == other.rootDirectory || (this.rootDirectory != null && this.rootDirectory.equals(other.rootDirectory));
+ }
+
+ @Override
+ public String toString() {
+ return "RemovableDevice [Root=" + rootDirectory + ", Device Name=" + deviceName
+ + "]";
+ }
+}
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/detectors/AbstractStorageDeviceDetector.java b/logo/src/net/samuelcampos/usbdrivedectector/detectors/AbstractStorageDeviceDetector.java
new file mode 100644
index 0000000..8d33e4f
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/detectors/AbstractStorageDeviceDetector.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.samuelcampos.usbdrivedectector.detectors;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.LogManager;
+
+import net.samuelcampos.usbdrivedectector.USBStorageDevice;
+
+
+/**
+ * This class is prepared to:
+ *
+ * - Windows (XP or newer)
+ * - Mac OS X (10.7 or newer)
+ *
+ *
+ * @author samuelcampos
+ */
+public abstract class AbstractStorageDeviceDetector {
+
+ private static final Logger logger = LogManager.getLogger(AbstractStorageDeviceDetector.class);
+
+ private static final String OSName = System.getProperty("os.name")
+ .toLowerCase();
+
+ // private static final String OSVersion = System.getProperty("os.version");
+ // private static final String OSArch = System.getProperty("os.arch");
+ /**
+ * {@link AbstractStorageDeviceDetector} instance.
+ * This instance is created (Thread-Safe) when the JVM loads the class.
+ */
+ private static final AbstractStorageDeviceDetector instance;
+
+ static {
+ if (OSName.startsWith("win")) {
+ instance = new WindowsStorageDeviceDetector();
+ } else if (OSName.startsWith("linux")) {
+ instance = new LinuxStorageDeviceDetector();
+ } else if (OSName.startsWith("mac")) {
+ instance = new OSXStorageDeviceDetector();
+ } else {
+ instance = null;
+ }
+ }
+
+ public static AbstractStorageDeviceDetector getInstance() {
+ if (instance == null) {
+ throw new UnsupportedOperationException("Your Operative System (" + OSName + ") is not supported!");
+ }
+
+ return instance;
+ }
+
+ public AbstractStorageDeviceDetector() {
+ }
+
+ /**
+ * Returns the storage devices connected to the computer.
+ *
+ * @return the list of the USB storage devices
+ */
+ public abstract List getRemovableDevices();
+
+ protected static void addUSBDevice(List listDevices, String rootPath) {
+ File root = new File(rootPath);
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("Device found: " + root.getPath());
+ }
+ if (root.isDirectory()) { // Marko Zivkovic: Added this check, because otherwise an exception is thrown
+ USBStorageDevice device = new USBStorageDevice(root);
+ listDevices.add(device);
+ }
+ }
+}
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/detectors/LinuxStorageDeviceDetector.java b/logo/src/net/samuelcampos/usbdrivedectector/detectors/LinuxStorageDeviceDetector.java
new file mode 100644
index 0000000..b1eb042
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/detectors/LinuxStorageDeviceDetector.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.samuelcampos.usbdrivedectector.detectors;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import net.samuelcampos.usbdrivedectector.USBStorageDevice;
+import net.samuelcampos.usbdrivedectector.process.CommandLineExecutor;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ * Tested on Linux Ubuntu 13.10
+ *
+ * @author samuelcampos
+ */
+public class LinuxStorageDeviceDetector extends AbstractStorageDeviceDetector {
+
+ private static final Logger logger = LogManager.getLogger(LinuxStorageDeviceDetector.class);
+
+ private static final String linuxDetectUSBCommand1 = "df";
+ private static final Pattern command1Pattern = Pattern.compile("^(\\/[^ ]+)[^%]+%[ ]+(.+)$");
+ private static final String linuxDetectUSBCommand2 = "udevadm info -q property -n ";
+ private static final String strDeviceVerifier = "ID_USB_DRIVER=usb-storage";
+
+ private final CommandLineExecutor commandExecutor1, commandExecutor2;
+
+ public LinuxStorageDeviceDetector() {
+ super();
+
+ commandExecutor1 = new CommandLineExecutor();
+ commandExecutor2 = new CommandLineExecutor();
+ }
+
+ private boolean isUSBStorage(String device) {
+ String verifyCommand = linuxDetectUSBCommand2 + device;
+
+ try {
+ commandExecutor2.executeCommand(verifyCommand);
+
+ String outputLine;
+ while ((outputLine = commandExecutor2.readOutputLine()) != null) {
+ if (strDeviceVerifier.equals(outputLine)) {
+ return true;
+ }
+ }
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ } finally {
+ try {
+ commandExecutor2.close();
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public List getRemovableDevices() {
+ ArrayList listDevices = new ArrayList();
+
+ try {
+ commandExecutor1.executeCommand(linuxDetectUSBCommand1);
+
+ String outputLine;
+ while ((outputLine = commandExecutor1.readOutputLine()) != null) {
+ Matcher matcher = command1Pattern.matcher(outputLine);
+
+ if (matcher.matches()) {
+ String device = matcher.group(1);
+ String rootPath = matcher.group(2);
+
+ if (isUSBStorage(device)) {
+ addUSBDevice(listDevices, rootPath);
+ }
+ }
+ }
+
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ } finally {
+ try {
+ commandExecutor1.close();
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ return listDevices;
+ }
+}
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/detectors/OSXStorageDeviceDetector.java b/logo/src/net/samuelcampos/usbdrivedectector/detectors/OSXStorageDeviceDetector.java
new file mode 100644
index 0000000..c746a9f
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/detectors/OSXStorageDeviceDetector.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.samuelcampos.usbdrivedectector.detectors;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import net.samuelcampos.usbdrivedectector.USBStorageDevice;
+import net.samuelcampos.usbdrivedectector.process.CommandLineExecutor;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ *
+ * @author samuelcampos
+ */
+public class OSXStorageDeviceDetector extends AbstractStorageDeviceDetector {
+
+ private static final Logger logger = LogManager
+ .getLogger(OSXStorageDeviceDetector.class);
+
+ private static final String osXDetectUSBCommand = "system_profiler SPUSBDataType";
+ private static final Pattern macOSXPattern = Pattern.compile("^.*Mount Point: (.+)$");
+
+ private final CommandLineExecutor commandExecutor;
+
+ public OSXStorageDeviceDetector() {
+ super();
+
+ commandExecutor = new CommandLineExecutor();
+ }
+
+ @Override
+ public List getRemovableDevices() {
+ ArrayList listDevices = new ArrayList();
+
+ try {
+ /**
+ * system_profiler SPUSBDataType | grep "BSD Name:\|Mount Point:"
+ */
+ commandExecutor.executeCommand(osXDetectUSBCommand);
+
+ String outputLine;
+
+ while ((outputLine = commandExecutor.readOutputLine()) != null) {
+ Matcher matcher = macOSXPattern.matcher(outputLine);
+
+ if (matcher.matches()) {
+ addUSBDevice(listDevices, matcher.group(1));
+ }
+ }
+
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ } finally {
+ try {
+ commandExecutor.close();
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ return listDevices;
+ }
+}
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/detectors/WindowsStorageDeviceDetector.java b/logo/src/net/samuelcampos/usbdrivedectector/detectors/WindowsStorageDeviceDetector.java
new file mode 100644
index 0000000..e35246d
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/detectors/WindowsStorageDeviceDetector.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.samuelcampos.usbdrivedectector.detectors;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import net.samuelcampos.usbdrivedectector.USBStorageDevice;
+import net.samuelcampos.usbdrivedectector.process.CommandLineExecutor;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ *
+ * @author samuelcampos
+ */
+public class WindowsStorageDeviceDetector extends AbstractStorageDeviceDetector {
+
+ private static final Logger logger = LogManager
+ .getLogger(WindowsStorageDeviceDetector.class);
+
+ /**
+ * wmic logicaldisk where drivetype=2 get description,deviceid,volumename
+ */
+ private static final String windowsDetectUSBCommand = "wmic logicaldisk where drivetype=2 get deviceid";
+
+ private final CommandLineExecutor commandExecutor;
+
+ public WindowsStorageDeviceDetector() {
+ commandExecutor = new CommandLineExecutor();
+ }
+
+ @Override
+ public synchronized List getRemovableDevices() {
+ ArrayList listDevices = new ArrayList();
+
+ try {
+ commandExecutor.executeCommand(windowsDetectUSBCommand);
+
+ String outputLine;
+ while ((outputLine = commandExecutor.readOutputLine()) != null) {
+
+ if (!outputLine.isEmpty() && !"DeviceID".equals(outputLine)) {
+ addUSBDevice(listDevices, outputLine + File.separatorChar);
+ }
+ }
+
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ } finally {
+ try {
+ commandExecutor.close();
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ return listDevices;
+ }
+
+ /**
+ * Returns the list of the removable devices actually connected to the computer.
+ * This method was effectively tested on:
+ *
+ * - Windows 7 (English)
+ *
+ *
+ * @deprecated replaced by {@link #getWindowsRemovableDevicesCommand()}
+ *
+ * @return the list of removable devices
+ */
+// @SuppressWarnings("unused")
+// private ArrayList getWindowsRemovableDevicesList() {
+//
+// /**
+// * TODO: How to put this working in all languages?
+// */
+// String fileSystemDesc = "Removable Disk";
+//
+// ArrayList listDevices = new ArrayList();
+//
+// File[] roots = File.listRoots();
+//
+// if (roots == null) {
+// // TODO: raise an error?
+// return listDevices;
+// }
+//
+// for (File root : roots) {
+// if (root.canRead() && root.canWrite() && fsView.isDrive(root)
+// && !fsView.isFloppyDrive(root)) {
+//
+// if (fileSystemDesc.equalsIgnoreCase(fsView
+// .getSystemTypeDescription(root))) {
+// USBStorageDevice device = new USBStorageDevice(root,
+// fsView.getSystemDisplayName(root));
+// listDevices.add(device);
+// }
+//
+// System.out.println(fsView.getSystemDisplayName(root) + " - "
+// + fsView.getSystemTypeDescription(root));
+//
+// /*
+// * FileSystemView.getSystemTypeDescription();
+// *
+// * Windows (8): Windows (7): "Removable Disk" Windows (XP):
+// * Linux (Ubuntu): OSX (10.7):
+// */
+// }
+// }
+//
+// return listDevices;
+// }
+}
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/events/DeviceEventType.java b/logo/src/net/samuelcampos/usbdrivedectector/events/DeviceEventType.java
new file mode 100644
index 0000000..e62b29c
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/events/DeviceEventType.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.samuelcampos.usbdrivedectector.events;
+
+/**
+ * Type of events that occur to USB Storage devices
+ *
+ * @author samuelcampos
+ */
+public enum DeviceEventType {
+ REMOVED,
+ CONNECTED
+}
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/events/IUSBDriveListener.java b/logo/src/net/samuelcampos/usbdrivedectector/events/IUSBDriveListener.java
new file mode 100644
index 0000000..7150a2f
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/events/IUSBDriveListener.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.samuelcampos.usbdrivedectector.events;
+
+/**
+ * Interface to implement by the classes who want to receive notifications when
+ * there are devices Connected or Removed of the computer.
+ *
+ * @author samuelcampos
+ */
+public interface IUSBDriveListener {
+
+ public void usbDriveEvent(USBStorageEvent event);
+}
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/events/USBStorageEvent.java b/logo/src/net/samuelcampos/usbdrivedectector/events/USBStorageEvent.java
new file mode 100644
index 0000000..780b65c
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/events/USBStorageEvent.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.samuelcampos.usbdrivedectector.events;
+
+import net.samuelcampos.usbdrivedectector.USBStorageDevice;
+
+/**
+ *
+ * @author samuelcampos
+ */
+public class USBStorageEvent {
+ private final USBStorageDevice storageDevice;
+ private final DeviceEventType eventType;
+
+ public USBStorageEvent(USBStorageDevice storageDevice, DeviceEventType eventType) {
+ this.storageDevice = storageDevice;
+ this.eventType = eventType;
+ }
+
+ public USBStorageDevice getStorageDevice() {
+ return storageDevice;
+ }
+
+ public DeviceEventType getEventType() {
+ return eventType;
+ }
+
+ @Override
+ public String toString() {
+ return "USBStorageEvent{" + "storageDevice=" + storageDevice + ", eventType=" + eventType + '}';
+ }
+}
diff --git a/logo/src/net/samuelcampos/usbdrivedectector/process/CommandLineExecutor.java b/logo/src/net/samuelcampos/usbdrivedectector/process/CommandLineExecutor.java
new file mode 100644
index 0000000..c6bfdcd
--- /dev/null
+++ b/logo/src/net/samuelcampos/usbdrivedectector/process/CommandLineExecutor.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014 samuelcampos.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.samuelcampos.usbdrivedectector.process;
+
+import java.io.BufferedReader;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ *
+ * @author samuelcampos
+ */
+public class CommandLineExecutor implements Closeable {
+
+ private static final Logger logger = LogManager.getLogger(CommandLineExecutor.class);
+
+ private Process process = null;
+ private BufferedReader input = null;
+
+ public void executeCommand(String command) throws IOException {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Running command: " + command);
+ }
+
+ process = Runtime.getRuntime().exec(command);
+
+ input = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ }
+
+ public String readOutputLine() throws IOException {
+ if(input == null)
+ throw new IllegalStateException("You need to call 'executeCommand' method first");
+
+ String outputLine = input.readLine();
+
+ if(outputLine != null)
+ return outputLine.trim();
+
+ return null;
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (input != null) {
+ try {
+ input.close();
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ if (process != null) {
+ process.destroy();
+ }
+
+ input = null;
+ process = null;
+ }
+
+}
diff --git a/logo/src/xlogo/AppSettings.java b/logo/src/xlogo/AppSettings.java
index 60cc1e7..c746282 100644
--- a/logo/src/xlogo/AppSettings.java
+++ b/logo/src/xlogo/AppSettings.java
@@ -5,6 +5,9 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
import xlogo.storage.workspace.Language;
import xlogo.storage.workspace.SyntaxHighlightConfig;
@@ -17,6 +20,8 @@ import xlogo.storage.workspace.SyntaxHighlightConfig;
*/
public class AppSettings
{
+ private static Logger logger = LogManager.getLogger(AppSettings.class.getSimpleName());
+
private static AppSettings instance;
public static AppSettings getInstance()
@@ -41,6 +46,7 @@ public class AppSettings
{
if (language == this.language)
return;
+ logger.trace("Change language from " + this.language + " to " + language);
this.language = language;
Logo.generateLanguage(language);
notifyLanguageChanged();
diff --git a/logo/src/xlogo/Application.java b/logo/src/xlogo/Application.java
index 8e4d2b9..cd82b43 100644
--- a/logo/src/xlogo/Application.java
+++ b/logo/src/xlogo/Application.java
@@ -1,4 +1,4 @@
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -16,13 +16,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* a lot of modifications, extensions, refactorings might been applied by Marko Zivkovic
*/
@@ -86,7 +86,7 @@ import xlogo.messages.async.history.HistoryMessenger;
/**
* @author Marko
- * @author Loïc Le Coq
+ * @author Loic Le Coq
*/
public class Application extends X4SFrame
{
@@ -1397,7 +1397,7 @@ public class Application extends X4SFrame
// Ce qu'il se passe en validant dans la zone de texte
/**
* When the user types "Enter" in the Command Line
- * @author Loïc Le Coq
+ * @author Loic Le Coq
*/
public void commande_actionPerformed()
{
@@ -1498,7 +1498,7 @@ public class Application extends X4SFrame
*
* @param st
* List of instructions
- * @author Loïc Le Coq
+ * @author Loic Le Coq
* @author Marko Zivkovic - renamed (it was affichage_Start)
*/
public void startInterpretation(StringBuffer st)
diff --git a/logo/src/xlogo/Logo.java b/logo/src/xlogo/Logo.java
index 4e495df..0f7da76 100644
--- a/logo/src/xlogo/Logo.java
+++ b/logo/src/xlogo/Logo.java
@@ -1,4 +1,4 @@
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -16,13 +16,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* a lot of modifications, extensions, refactorings have been applied by Marko Zivkovic
*/
diff --git a/logo/src/xlogo/MemoryChecker.java b/logo/src/xlogo/MemoryChecker.java
index f35f73a..d9e1d0e 100644
--- a/logo/src/xlogo/MemoryChecker.java
+++ b/logo/src/xlogo/MemoryChecker.java
@@ -1,4 +1,4 @@
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -16,13 +16,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* a lot of modifications, extensions, refactorings have been applied by Marko Zivkovic
*/
diff --git a/logo/src/xlogo/MenuListener.java b/logo/src/xlogo/MenuListener.java
index a40fd99..aae8477 100644
--- a/logo/src/xlogo/MenuListener.java
+++ b/logo/src/xlogo/MenuListener.java
@@ -1,5 +1,5 @@
/**
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -17,13 +17,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* modifications, extensions, refactorings might have been applied by Marko Zivkovic
*/
diff --git a/logo/src/xlogo/Popup.java b/logo/src/xlogo/Popup.java
index a2acc2d..8eda3d9 100644
--- a/logo/src/xlogo/Popup.java
+++ b/logo/src/xlogo/Popup.java
@@ -1,4 +1,4 @@
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -16,13 +16,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* modifications, extensions, refactorings might have been applied by Marko Zivkovic
*/
diff --git a/logo/src/xlogo/Sound_Player.java b/logo/src/xlogo/Sound_Player.java
index 9940f23..eaf086b 100644
--- a/logo/src/xlogo/Sound_Player.java
+++ b/logo/src/xlogo/Sound_Player.java
@@ -1,4 +1,4 @@
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -16,13 +16,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* modifications, extensions, refactorings might have been applied by Marko Zivkovic
*/
diff --git a/logo/src/xlogo/StyledDocument/DocumentLogo.java b/logo/src/xlogo/StyledDocument/DocumentLogo.java
index 4fc0cc7..2676817 100644
--- a/logo/src/xlogo/StyledDocument/DocumentLogo.java
+++ b/logo/src/xlogo/StyledDocument/DocumentLogo.java
@@ -1,4 +1,4 @@
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -16,13 +16,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* modifications, extensions, refactorings might have been applied by Marko Zivkovic
*/package xlogo.StyledDocument;
diff --git a/logo/src/xlogo/StyledDocument/DocumentLogoCommande.java b/logo/src/xlogo/StyledDocument/DocumentLogoCommande.java
index f0a9efa..3349b11 100644
--- a/logo/src/xlogo/StyledDocument/DocumentLogoCommande.java
+++ b/logo/src/xlogo/StyledDocument/DocumentLogoCommande.java
@@ -1,4 +1,4 @@
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -16,13 +16,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* modifications, extensions, refactorings might have been applied by Marko Zivkovic
*/package xlogo.StyledDocument;
import javax.swing.text.AttributeSet;
diff --git a/logo/src/xlogo/StyledDocument/DocumentLogoHistorique.java b/logo/src/xlogo/StyledDocument/DocumentLogoHistorique.java
index 7dc4e37..9731068 100644
--- a/logo/src/xlogo/StyledDocument/DocumentLogoHistorique.java
+++ b/logo/src/xlogo/StyledDocument/DocumentLogoHistorique.java
@@ -1,4 +1,4 @@
-/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loïc Le Coq
+/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
* Copyright (C) 2013 Marko Zivkovic
*
* Contact Information: marko88zivkovic at gmail dot com
@@ -16,13 +16,13 @@
*
*
* This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
- * during his Bachelor thesis at the computer science department of ETH Zürich,
+ * during his Bachelor thesis at the computer science department of ETH Zurich,
* in the year 2013 and/or during future work.
*
- * It is a reengineered version of XLogo written by Loïc Le Coq, published
+ * It is a reengineered version of XLogo written by Loic Le Coq, published
* under the GPL License at http://xlogo.tuxfamily.org/
*
- * Contents of this file were initially written by Loïc Le Coq,
+ * Contents of this file were initially written by Loic Le Coq,
* modifications, extensions, refactorings might have been applied by Marko Zivkovic
*/package xlogo.StyledDocument;
import java.awt.Color;
diff --git a/logo/src/xlogo/gpl/x4s_info.html b/logo/src/xlogo/gpl/x4s_info.html
index be553dd..acbfc7f 100644
--- a/logo/src/xlogo/gpl/x4s_info.html
+++ b/logo/src/xlogo/gpl/x4s_info.html
@@ -5,10 +5,16 @@
XLogo4Schools
- Version 0.9.03beta-2014-11-03
+ Version 0.9.04beta-2014-12-16
XLogo4Schools is a modified, extended and reengineered version of Loïc Le Coq's XLogo. It is the result of a six month Bachelor's thesis conducted by Marko Živković at ETHZ, D-INFK department from March 2013 until September 2013.
-
+
+
Where can I find an XLogo language reference and documentation?
+ In most cases, XLogo4Schools is very similar to XLogo. Therefore you can use the XLogo language reference and documentation found.
+ Currently, there is no XLogo4Schools documentation, but it is planned. Thank you for your patience.
+
+ Credits
+
I want to thank Prof. Juraj Hromkovič for giving me the opportunity to dive into the world of Logo and for letting me do the reengineering of XLogo for my Bachelor's Thesis. Very special thanks go to Giovanni Serafini who acted as an excellent adviser and mentor during this project. I also want to thank Dr. Heidi Gebauer, Dr. Ivana Kosirova, Lucia Keller, and Björn Steffen from Prof. Hromkovič's chair for their intensive contributions during the requirements analysis phase. I enjoyed the many talks and discussions and appreciated every new idea from you. And finally I want to thank the other Logo tutors, Lukas Häfliger, Samuel Bryner, Alexander Viand, Petra Hromkovičova, Stefan Dietiker, and Christine Zeller, who contributed in numerous inspiring talks during the many Logo projects.
What was reengineered?
@@ -38,10 +44,5 @@
Measured on a Sierpinski Triangle of depth 9, XLogo4Schools is around 25% faster than XLogo (16s vs. 21s on my machine). It is even faster, when many procedures are added to the workspace. XLogo used a stack to manage its procedures which took O(N) string comparisons to find a procedure. Interestingly, the designated stack operations push and pop are not really used. For the same purpose, XLogo4Schools uses now a HashMap that usually works in O(1).
-
- Where can I find an XLogo language reference and documentation?
- In most cases, XLogo4Schools is very similar to XLogo. Therefore you can use the XLogo language reference and documentation found.
- Currently, there is no XLogo4Schools documentation, but it is planned. Thank you for your patience.
-