diff --git a/SmartNotes/lib/keyhook/jnativehook-2.1.0_beta1.jar b/SmartNotes/lib/keyhook/jnativehook-2.1.0_beta1.jar new file mode 100644 index 0000000..d6befac Binary files /dev/null and b/SmartNotes/lib/keyhook/jnativehook-2.1.0_beta1.jar differ diff --git a/SmartNotes/lib/asm-4.0.jar b/SmartNotes/lib/markdown/asm-4.0.jar similarity index 100% rename from SmartNotes/lib/asm-4.0.jar rename to SmartNotes/lib/markdown/asm-4.0.jar diff --git a/SmartNotes/lib/asm-analysis-4.0.jar b/SmartNotes/lib/markdown/asm-analysis-4.0.jar similarity index 100% rename from SmartNotes/lib/asm-analysis-4.0.jar rename to SmartNotes/lib/markdown/asm-analysis-4.0.jar diff --git a/SmartNotes/lib/asm-tree-4.0.jar b/SmartNotes/lib/markdown/asm-tree-4.0.jar similarity index 100% rename from SmartNotes/lib/asm-tree-4.0.jar rename to SmartNotes/lib/markdown/asm-tree-4.0.jar diff --git a/SmartNotes/lib/asm-util-4.0.jar b/SmartNotes/lib/markdown/asm-util-4.0.jar similarity index 100% rename from SmartNotes/lib/asm-util-4.0.jar rename to SmartNotes/lib/markdown/asm-util-4.0.jar diff --git a/SmartNotes/lib/parboiled-core-1.1.7.jar b/SmartNotes/lib/markdown/parboiled-core-1.1.7.jar similarity index 100% rename from SmartNotes/lib/parboiled-core-1.1.7.jar rename to SmartNotes/lib/markdown/parboiled-core-1.1.7.jar diff --git a/SmartNotes/lib/parboiled-java-1.1.7.jar b/SmartNotes/lib/markdown/parboiled-java-1.1.7.jar similarity index 100% rename from SmartNotes/lib/parboiled-java-1.1.7.jar rename to SmartNotes/lib/markdown/parboiled-java-1.1.7.jar diff --git a/SmartNotes/lib/pegdown-1.6.0.jar b/SmartNotes/lib/markdown/pegdown-1.6.0.jar similarity index 100% rename from SmartNotes/lib/pegdown-1.6.0.jar rename to SmartNotes/lib/markdown/pegdown-1.6.0.jar diff --git a/SmartNotes/src/com/madeorsk/smartnotes/NotesExplorer.java b/SmartNotes/src/com/madeorsk/smartnotes/NotesExplorer.java index bdea321..12bbb91 100644 --- a/SmartNotes/src/com/madeorsk/smartnotes/NotesExplorer.java +++ b/SmartNotes/src/com/madeorsk/smartnotes/NotesExplorer.java @@ -25,6 +25,8 @@ import javafx.util.Duration; public class NotesExplorer extends VBox { private SavesManager saves; + /*private Thread saveThread; + private Thread nextSaveThread;*/ private Map notes; private HBox titleBox; @@ -189,11 +191,32 @@ public class NotesExplorer extends VBox } } - public void requestSave(Note note) + public void requestSave(final Note note) { - for (int key : this.notes.keySet()) - if (this.notes.get(key).equals(note)) - note.save(this.saves, key); + /*Thread currentThread = new Thread(new Runnable() + { + @Override + public void run() + {*/ + for (int key : NotesExplorer.this.notes.keySet()) + if (NotesExplorer.this.notes.get(key).equals(note)) + note.save(NotesExplorer.this.saves, key); + /* + if (NotesExplorer.this.nextSaveThread != null && !NotesExplorer.this.nextSaveThread.equals(this)) + { + NotesExplorer.this.saveThread = NotesExplorer.this.nextSaveThread; + NotesExplorer.this.saveThread.start(); + } + } + }, "Save Thread"); + + if (this.saveThread != null && this.saveThread.isAlive()) + this.nextSaveThread = currentThread; + else + { + this.saveThread = currentThread; + this.saveThread.start(); + }*/ } public void requestLoad(Note note) { diff --git a/SmartNotes/src/com/madeorsk/smartnotes/SmartNotes.java b/SmartNotes/src/com/madeorsk/smartnotes/SmartNotes.java index 36d82f4..b0a4a7f 100644 --- a/SmartNotes/src/com/madeorsk/smartnotes/SmartNotes.java +++ b/SmartNotes/src/com/madeorsk/smartnotes/SmartNotes.java @@ -1,10 +1,18 @@ package com.madeorsk.smartnotes; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jnativehook.GlobalScreen; +import org.jnativehook.NativeHookException; +import org.jnativehook.keyboard.NativeKeyEvent; +import org.jnativehook.keyboard.NativeKeyListener; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; import javafx.application.Application; +import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.concurrent.Worker.State; @@ -39,6 +47,20 @@ public class SmartNotes extends Application @Override public void start(Stage stage) throws Exception { + try + { + Logger.getLogger(GlobalScreen.class.getPackage().getName()).setLevel(Level.OFF); + GlobalScreen.registerNativeHook(); + GlobalScreen.addNativeKeyListener(new GlobalKeyListener()); + } + catch (NativeHookException ex) + { + System.err.println("There was a problem registering the native hook."); + System.err.println(ex.getMessage()); + } + + Platform.setImplicitExit(false); + instance = this; webView = new WebView(); final String css = Utils.loadText("/com/madeorsk/smartnotes/webView.css"); @@ -54,7 +76,7 @@ public class SmartNotes extends Application Text styleContent = doc.createTextNode(css); styleNode.appendChild(styleContent); doc.getDocumentElement().getElementsByTagName("head").item(0).appendChild(styleNode); - System.out.println(webView.getEngine().executeScript("document.documentElement.innerHTML")); + //System.out.println(webView.getEngine().executeScript("document.documentElement.innerHTML")); } } }); @@ -92,6 +114,14 @@ public class SmartNotes extends Application stage.setScene(this.scene); stage.setTitle("SmartNotes " + version); + stage.setOnCloseRequest(new EventHandler() + { + @Override + public void handle(WindowEvent event) + { + SmartNotes.this.onStop(); + } + }); stage.show(); } @@ -114,4 +144,34 @@ public class SmartNotes extends Application this.root.getChildren().add(region); } } + + private void onStop() + { + try + { + GlobalScreen.unregisterNativeHook(); + } + catch (NativeHookException e) + { + e.printStackTrace(); + } + Platform.exit(); + } + + public class GlobalKeyListener implements NativeKeyListener + { // CTRL : 29 | ALT : 56 | n : 49 + @Override + public void nativeKeyPressed(NativeKeyEvent e) + { + //System.out.println("P == " + e.getKeyCode() + ":" + e.getKeyChar()); + } + @Override + public void nativeKeyReleased(NativeKeyEvent e) + { + //System.out.println("R == " + e.getKeyCode() + ":" + e.getKeyChar()); + } + @Override + public void nativeKeyTyped(NativeKeyEvent e) + {} + } } diff --git a/SmartNotes/src/com/madeorsk/smartnotes/notes/ListNote.java b/SmartNotes/src/com/madeorsk/smartnotes/notes/ListNote.java index fd9dbf7..2473af7 100644 --- a/SmartNotes/src/com/madeorsk/smartnotes/notes/ListNote.java +++ b/SmartNotes/src/com/madeorsk/smartnotes/notes/ListNote.java @@ -41,7 +41,7 @@ public class ListNote extends Note } @Override - public VBox getViewBox(NotesExplorer explorer) + public VBox getViewBox(final NotesExplorer explorer) { Map listBoxMap = this.listBox.getList(); this.listBox = new ListBox(false); @@ -49,7 +49,7 @@ public class ListNote extends Note VBox box = new VBox(); box.setFillWidth(true); - Label nameField = new Label(); + final Label nameField = new Label(); HBox titleBox = new HBox(); { diff --git a/SmartNotes/src/com/madeorsk/smartnotes/notes/TextNote.java b/SmartNotes/src/com/madeorsk/smartnotes/notes/TextNote.java index 87f7952..ee18145 100644 --- a/SmartNotes/src/com/madeorsk/smartnotes/notes/TextNote.java +++ b/SmartNotes/src/com/madeorsk/smartnotes/notes/TextNote.java @@ -34,12 +34,12 @@ public class TextNote extends Note } @Override - public VBox getViewBox(NotesExplorer explorer) + public VBox getViewBox(final NotesExplorer explorer) { VBox box = new VBox(); box.setFillWidth(true); - Label nameField = new Label(); + final Label nameField = new Label(); HBox titleBox = new HBox(); {