Cross JDK fixes and preparations
- Windows JDK fixes - Prepared key listeners for future keyboard shortcuts - Prepared Save Thread for saving safely and whithout blocking frame
This commit is contained in:
parent
ae7980caae
commit
413ed38306
BIN
SmartNotes/lib/keyhook/jnativehook-2.1.0_beta1.jar
Normal file
BIN
SmartNotes/lib/keyhook/jnativehook-2.1.0_beta1.jar
Normal file
Binary file not shown.
@ -25,6 +25,8 @@ import javafx.util.Duration;
|
|||||||
public class NotesExplorer extends VBox
|
public class NotesExplorer extends VBox
|
||||||
{
|
{
|
||||||
private SavesManager saves;
|
private SavesManager saves;
|
||||||
|
/*private Thread saveThread;
|
||||||
|
private Thread nextSaveThread;*/
|
||||||
private Map<Integer, Note> notes;
|
private Map<Integer, Note> notes;
|
||||||
|
|
||||||
private HBox titleBox;
|
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())
|
/*Thread currentThread = new Thread(new Runnable()
|
||||||
if (this.notes.get(key).equals(note))
|
{
|
||||||
note.save(this.saves, key);
|
@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)
|
public void requestLoad(Note note)
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
package com.madeorsk.smartnotes;
|
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.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Text;
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.concurrent.Worker.State;
|
import javafx.concurrent.Worker.State;
|
||||||
@ -39,6 +47,20 @@ public class SmartNotes extends Application
|
|||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws Exception
|
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;
|
instance = this;
|
||||||
webView = new WebView();
|
webView = new WebView();
|
||||||
final String css = Utils.loadText("/com/madeorsk/smartnotes/webView.css");
|
final String css = Utils.loadText("/com/madeorsk/smartnotes/webView.css");
|
||||||
@ -54,7 +76,7 @@ public class SmartNotes extends Application
|
|||||||
Text styleContent = doc.createTextNode(css);
|
Text styleContent = doc.createTextNode(css);
|
||||||
styleNode.appendChild(styleContent);
|
styleNode.appendChild(styleContent);
|
||||||
doc.getDocumentElement().getElementsByTagName("head").item(0).appendChild(styleNode);
|
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.setScene(this.scene);
|
||||||
stage.setTitle("SmartNotes " + version);
|
stage.setTitle("SmartNotes " + version);
|
||||||
|
stage.setOnCloseRequest(new EventHandler<WindowEvent>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void handle(WindowEvent event)
|
||||||
|
{
|
||||||
|
SmartNotes.this.onStop();
|
||||||
|
}
|
||||||
|
});
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,4 +144,34 @@ public class SmartNotes extends Application
|
|||||||
this.root.getChildren().add(region);
|
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)
|
||||||
|
{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class ListNote extends Note
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VBox getViewBox(NotesExplorer explorer)
|
public VBox getViewBox(final NotesExplorer explorer)
|
||||||
{
|
{
|
||||||
Map<String, Boolean> listBoxMap = this.listBox.getList();
|
Map<String, Boolean> listBoxMap = this.listBox.getList();
|
||||||
this.listBox = new ListBox(false);
|
this.listBox = new ListBox(false);
|
||||||
@ -49,7 +49,7 @@ public class ListNote extends Note
|
|||||||
VBox box = new VBox();
|
VBox box = new VBox();
|
||||||
box.setFillWidth(true);
|
box.setFillWidth(true);
|
||||||
|
|
||||||
Label nameField = new Label();
|
final Label nameField = new Label();
|
||||||
|
|
||||||
HBox titleBox = new HBox();
|
HBox titleBox = new HBox();
|
||||||
{
|
{
|
||||||
|
@ -34,12 +34,12 @@ public class TextNote extends Note
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VBox getViewBox(NotesExplorer explorer)
|
public VBox getViewBox(final NotesExplorer explorer)
|
||||||
{
|
{
|
||||||
VBox box = new VBox();
|
VBox box = new VBox();
|
||||||
box.setFillWidth(true);
|
box.setFillWidth(true);
|
||||||
|
|
||||||
Label nameField = new Label();
|
final Label nameField = new Label();
|
||||||
|
|
||||||
HBox titleBox = new HBox();
|
HBox titleBox = new HBox();
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user