Code update and cleanup

This commit is contained in:
Madeorsk 2018-04-22 15:30:21 +02:00
parent 686b4bf228
commit 21b2e2fc4a
17 changed files with 448 additions and 672 deletions

2
SmartNotes/smartnotes/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
\.idea
*\.iml

View File

@ -1,39 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.madeorsk</groupId> <groupId>com.madeorsk</groupId>
<artifactId>smartnotes</artifactId> <artifactId>smartnotes</artifactId>
<version>1.0</version> <version>0.5</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>SmartNotes</name> <name>SmartNotes</name>
<url>https://smartnotes.madeorsk.com</url> <url>https://smartnotes.madeorsk.com</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.vladsch.flexmark</groupId> <groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark</artifactId> <artifactId>flexmark</artifactId>
<version>0.26.2</version> <version>0.26.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.1stleg</groupId> <groupId>com.1stleg</groupId>
<artifactId>jnativehook</artifactId> <artifactId>jnativehook</artifactId>
<version>2.1.0</version> <version>2.1.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<organization> <organization>
<name>Madeorsk</name> <name>Madeorsk</name>
<url>https://madeorsk.com</url> <url>https://madeorsk.com</url>
</organization> </organization>
</project> </project>

View File

@ -3,7 +3,6 @@ package com.madeorsk.smartnotes;
import com.madeorsk.smartnotes.notes.Note; import com.madeorsk.smartnotes.notes.Note;
import com.madeorsk.smartnotes.paths.FolderPath; import com.madeorsk.smartnotes.paths.FolderPath;
import javafx.event.EventHandler;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Cursor; import javafx.scene.Cursor;
import javafx.scene.control.Label; import javafx.scene.control.Label;
@ -23,18 +22,13 @@ public class ExplorerItem extends HBox
this.item = item; this.item = item;
this.setCursor(Cursor.HAND); this.setCursor(Cursor.HAND);
this.setOnMouseClicked(new EventHandler<MouseEvent>() this.setOnMouseClicked((MouseEvent event) -> {
{ if (ExplorerItem.this.folder)
@Override explorer.goToFolder((FolderPath) ExplorerItem.this.item);
public void handle(MouseEvent event) else
{ {
if (ExplorerItem.this.folder) explorer.requestLoad((Note) ExplorerItem.this.item);
explorer.goToFolder((FolderPath) ExplorerItem.this.item); SmartNotes.instance.setContent(((Note) ExplorerItem.this.item).getViewBox(explorer));
else
{
explorer.requestLoad((Note) ExplorerItem.this.item);
SmartNotes.instance.setContent(((Note) ExplorerItem.this.item).getViewBox(explorer));
}
} }
}); });

View File

@ -9,7 +9,6 @@ import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableBooleanValue; import javafx.beans.value.ObservableBooleanValue;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Cursor; import javafx.scene.Cursor;
@ -58,35 +57,20 @@ public class ListBox extends ScrollPane
addListItemBox.setCursor(Cursor.HAND); addListItemBox.setCursor(Cursor.HAND);
// Fade and opacity // Fade and opacity
addListItemBox.setOpacity(0.4); addListItemBox.setOpacity(0.4);
addListItemBox.setOnMouseEntered(new EventHandler<MouseEvent>() addListItemBox.setOnMouseEntered((MouseEvent e) -> {
{ FadeTransition transition = new FadeTransition(Duration.millis(200), addListItemBox);
@Override transition.setFromValue(0.4);
public void handle(MouseEvent e) transition.setToValue(1.0);
{ transition.play();
FadeTransition transition = new FadeTransition(Duration.millis(200), addListItemBox);
transition.setFromValue(0.4);
transition.setToValue(1.0);
transition.play();
}
}); });
addListItemBox.setOnMouseExited(new EventHandler<MouseEvent>() addListItemBox.setOnMouseExited((MouseEvent e) -> {
{ FadeTransition transition = new FadeTransition(Duration.millis(200), addListItemBox);
@Override transition.setFromValue(1.0);
public void handle(MouseEvent e) transition.setToValue(0.4);
{ transition.play();
FadeTransition transition = new FadeTransition(Duration.millis(200), addListItemBox);
transition.setFromValue(1.0);
transition.setToValue(0.4);
transition.play();
}
}); });
addListItemBox.setOnMouseClicked(new EventHandler<MouseEvent>() addListItemBox.setOnMouseClicked((MouseEvent e) -> {
{ ListBox.this.listContainer.getChildren().add(new ListBoxItem("", ListBox.this.editable));
@Override
public void handle(MouseEvent e)
{
ListBox.this.listContainer.getChildren().add(new ListBoxItem("", ListBox.this.editable));
}
}); });
} }
this.main.getChildren().add(addListItemBox); this.main.getChildren().add(addListItemBox);
@ -98,7 +82,7 @@ public class ListBox extends ScrollPane
public void updateList(Map<String, Boolean> content) public void updateList(Map<String, Boolean> content)
{ {
this.listContainer.getChildren().clear(); this.listContainer.getChildren().clear();
for(String item : content.keySet()) for (String item : content.keySet())
this.listContainer.getChildren().add(new ListBoxItem(item, this.editable).setChecked(content.get(item).booleanValue())); this.listContainer.getChildren().add(new ListBoxItem(item, this.editable).setChecked(content.get(item).booleanValue()));
} }
@ -110,7 +94,7 @@ public class ListBox extends ScrollPane
public Map<String, Boolean> getList() public Map<String, Boolean> getList()
{ {
Map<String, Boolean> list = new HashMap<String, Boolean>(); Map<String, Boolean> list = new HashMap<String, Boolean>();
for(Node child : this.listContainer.getChildren()) for (Node child : this.listContainer.getChildren())
{ {
ListBoxItem item = (ListBoxItem) child; ListBoxItem item = (ListBoxItem) child;
if (item.getText() != null && !item.getText().isEmpty()) if (item.getText() != null && !item.getText().isEmpty())
@ -126,14 +110,9 @@ public class ListBox extends ScrollPane
public ListBoxItem(String text, boolean editable) public ListBoxItem(String text, boolean editable)
{ {
ChangeListener<Object> change = new ChangeListener<Object>() ChangeListener<Object> change = (ObservableValue<? extends Object> ov, Object oldValue, Object newValue) -> {
{ if (ListBox.this.listChangeListener != null)
@Override ListBox.this.listChangeListener.run();
public void changed(ObservableValue<? extends Object> ov, Object oldValue, Object newValue)
{
if (ListBox.this.listChangeListener != null)
ListBox.this.listChangeListener.run();
}
}; };
this.checkbox = new ListCheckbox(); this.checkbox = new ListCheckbox();
this.checkbox.checkedProperty().addListener(change); this.checkbox.checkedProperty().addListener(change);
@ -147,13 +126,8 @@ public class ListBox extends ScrollPane
else else
{ {
this.field.setCursor(Cursor.HAND); this.field.setCursor(Cursor.HAND);
this.field.setOnMouseClicked(new EventHandler<MouseEvent>() this.field.setOnMouseClicked((MouseEvent e) -> {
{ ListBoxItem.this.setChecked(!ListBoxItem.this.isChecked());
@Override
public void handle(MouseEvent e)
{
ListBoxItem.this.setChecked(!ListBoxItem.this.isChecked());
}
}); });
} }
this.getChildren().add(this.field); this.getChildren().add(this.field);
@ -169,6 +143,7 @@ public class ListBox extends ScrollPane
this.checkbox.setChecked(checked); this.checkbox.setChecked(checked);
return this; return this;
} }
public boolean isChecked() public boolean isChecked()
{ {
return this.checkbox.isChecked(); return this.checkbox.isChecked();
@ -185,46 +160,11 @@ public class ListBox extends ScrollPane
this.setCursor(Cursor.HAND); this.setCursor(Cursor.HAND);
this.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/Checkbox-unchecked.png"))); this.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/Checkbox-unchecked.png")));
/*this.setOpacity(0.4); this.setOnMouseClicked((MouseEvent e) -> {
this.setOnMouseEntered(new EventHandler<MouseEvent>() if (ListCheckbox.this.isChecked())
{ ListCheckbox.this.setChecked(false);
@Override else
public void handle(MouseEvent e) ListCheckbox.this.setChecked(true);
{
if (!ListCheckbox.this.isChecked())
{
FadeTransition transition = new FadeTransition(Duration.millis(200), ListCheckbox.this);
transition.setFromValue(0.4);
transition.setToValue(1.0);
transition.play();
}
}
});
this.setOnMouseExited(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent e)
{
if (!ListCheckbox.this.isChecked())
{
FadeTransition transition = new FadeTransition(Duration.millis(200), ListCheckbox.this);
transition.setFromValue(1.0);
transition.setToValue(0.4);
transition.play();
}
}
});*/
this.setOnMouseClicked(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent e)
{
if (ListCheckbox.this.isChecked())
ListCheckbox.this.setChecked(false);
else
ListCheckbox.this.setChecked(true);
}
}); });
} }
@ -237,10 +177,12 @@ public class ListBox extends ScrollPane
else else
ListCheckbox.this.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/Checkbox-unchecked.png"))); ListCheckbox.this.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/Checkbox-unchecked.png")));
} }
public ObservableBooleanValue checkedProperty() public ObservableBooleanValue checkedProperty()
{ {
return this.checked; return this.checked;
} }
public boolean isChecked() public boolean isChecked()
{ {
return this.checked.get(); return this.checked.get();

View File

@ -8,7 +8,6 @@ import com.madeorsk.smartnotes.notes.Note.NoteColor;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.scene.Cursor; import javafx.scene.Cursor;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
@ -40,10 +39,12 @@ public class NoteColorSelector extends HBox
this.selectedColor.set(color); this.selectedColor.set(color);
this.updateBox(); this.updateBox();
} }
public NoteColor getSelectedColor() public NoteColor getSelectedColor()
{ {
return this.selectedColor.getValue(); return this.selectedColor.getValue();
} }
public ObservableValue<NoteColor> selectedColorProperty() public ObservableValue<NoteColor> selectedColorProperty()
{ {
return this.selectedColor; return this.selectedColor;
@ -52,11 +53,12 @@ public class NoteColorSelector extends HBox
private void updateBox() private void updateBox()
{ {
this.getChildren().clear(); this.getChildren().clear();
for(final NoteColor color : this.noteColors) for (final NoteColor color : this.noteColors)
{ {
Canvas canvas = new Canvas(); Canvas canvas = new Canvas();
canvas.setCursor(Cursor.HAND); canvas.setCursor(Cursor.HAND);
canvas.setHeight(50); canvas.setWidth(50); canvas.setHeight(50);
canvas.setWidth(50);
GraphicsContext gc = canvas.getGraphicsContext2D(); GraphicsContext gc = canvas.getGraphicsContext2D();
if (color.equals(this.getSelectedColor())) if (color.equals(this.getSelectedColor()))
{ {
@ -66,13 +68,8 @@ public class NoteColorSelector extends HBox
gc.setFill(color.getColor()); gc.setFill(color.getColor());
gc.fillOval(3, 3, 44, 44); gc.fillOval(3, 3, 44, 44);
canvas.setOnMouseClicked(new EventHandler<MouseEvent>() canvas.setOnMouseClicked((MouseEvent event) -> {
{ NoteColorSelector.this.setSelectedColor(color);
@Override
public void handle(MouseEvent event)
{
NoteColorSelector.this.setSelectedColor(color);
}
}); });
this.getChildren().add(canvas); this.getChildren().add(canvas);

View File

@ -10,7 +10,6 @@ import com.madeorsk.smartnotes.paths.NotePath;
import com.madeorsk.smartnotes.paths.Path; import com.madeorsk.smartnotes.paths.Path;
import javafx.animation.FadeTransition; import javafx.animation.FadeTransition;
import javafx.event.EventHandler;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Cursor; import javafx.scene.Cursor;
@ -25,8 +24,6 @@ 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;
@ -78,41 +75,26 @@ public class NotesExplorer extends VBox
{ {
addNoteBox.setCursor(Cursor.HAND); addNoteBox.setCursor(Cursor.HAND);
addNoteBox.setOpacity(0.4); addNoteBox.setOpacity(0.4);
addNoteBox.setOnMouseEntered(new EventHandler<MouseEvent>() addNoteBox.setOnMouseEntered((MouseEvent e) -> {
{ FadeTransition transition = new FadeTransition(Duration.millis(200), addNoteBox);
@Override transition.setFromValue(0.4);
public void handle(MouseEvent e) transition.setToValue(1.0);
{ transition.play();
FadeTransition transition = new FadeTransition(Duration.millis(200), addNoteBox);
transition.setFromValue(0.4);
transition.setToValue(1.0);
transition.play();
}
}); });
addNoteBox.setOnMouseExited(new EventHandler<MouseEvent>() addNoteBox.setOnMouseExited((MouseEvent e) -> {
{ FadeTransition transition = new FadeTransition(Duration.millis(200), addNoteBox);
@Override transition.setFromValue(1.0);
public void handle(MouseEvent e) transition.setToValue(0.4);
{ transition.play();
FadeTransition transition = new FadeTransition(Duration.millis(200), addNoteBox);
transition.setFromValue(1.0);
transition.setToValue(0.4);
transition.play();
}
}); });
addNoteBox.setOnMouseClicked(new EventHandler<MouseEvent>() addNoteBox.setOnMouseClicked((MouseEvent event) -> {
{ TextNote note = new TextNote();
@Override SmartNotes.instance.setContent(note.getEditBox(NotesExplorer.this));
public void handle(MouseEvent event) int id = NotesExplorer.this.getNextId();
{ NotesExplorer.this.notes.put(id, note);
TextNote note = new TextNote();
SmartNotes.instance.setContent(note.getEditBox(NotesExplorer.this));
int id = NotesExplorer.this.getNextId();
NotesExplorer.this.notes.put(id, note);
NotesExplorer.this.saves.saveIndex(NotesExplorer.this.notes); NotesExplorer.this.saves.saveIndex(NotesExplorer.this.notes);
note.save(NotesExplorer.this.saves, id); note.save(NotesExplorer.this.saves, id);
}
}); });
addNoteBox.setAlignment(Pos.CENTER_LEFT); addNoteBox.setAlignment(Pos.CENTER_LEFT);
@ -128,18 +110,18 @@ public class NotesExplorer extends VBox
private FolderPath genRoot() private FolderPath genRoot()
{ {
FolderPath root = new FolderPath("/", null); FolderPath root = new FolderPath("/", null);
for(int key : this.notes.keySet()) for (int key : this.notes.keySet())
{ {
Note note = this.notes.get(key); Note note = this.notes.get(key);
if (note.getPaths().isEmpty()) if (note.getPaths().isEmpty())
root.addPath(new NotePath(key)); root.addPath(new NotePath(key));
else else
{ {
for(String path : note.getPaths()) for (String path : note.getPaths())
{ {
FolderPath putIn = root; FolderPath putIn = root;
String[] foldersString = (path.substring(1).contains("#")) ? path.substring(1).split("#") : Arrays.asList(path.substring(1)).toArray(new String[1]); String[] foldersString = (path.substring(1).contains("#")) ? path.substring(1).split("#") : Arrays.asList(path.substring(1)).toArray(new String[1]);
for(String folderString : foldersString) for (String folderString : foldersString)
{ {
if (putIn.containsFolder(folderString)) if (putIn.containsFolder(folderString))
putIn = putIn.getFolder(folderString); putIn = putIn.getFolder(folderString);
@ -161,10 +143,12 @@ public class NotesExplorer extends VBox
{ {
this.updateList(this.getUpdatedFolder(path)); this.updateList(this.getUpdatedFolder(path));
} }
public void updateCurrentFolder() public void updateCurrentFolder()
{ {
this.updateList(this.getUpdatedFolder(this.currentFolder)); this.updateList(this.getUpdatedFolder(this.currentFolder));
} }
private FolderPath getUpdatedFolder(FolderPath path) private FolderPath getUpdatedFolder(FolderPath path)
{ {
if (path.getParent() == null) if (path.getParent() == null)
@ -181,7 +165,7 @@ public class NotesExplorer extends VBox
public void replaceNote(Note oldNote, Note newNote) public void replaceNote(Note oldNote, Note newNote)
{ {
for(int key : this.notes.keySet()) for (int key : this.notes.keySet())
{ {
if (this.notes.get(key).equals(oldNote)) if (this.notes.get(key).equals(oldNote))
{ {
@ -193,31 +177,11 @@ public class NotesExplorer extends VBox
public void requestSave(final Note note) public void requestSave(final Note note)
{ {
/*Thread currentThread = new Thread(new Runnable() for (int key : NotesExplorer.this.notes.keySet())
{ if (NotesExplorer.this.notes.get(key).equals(note))
@Override note.save(NotesExplorer.this.saves, key);
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)
{ {
for (int key : this.notes.keySet()) for (int key : this.notes.keySet())
@ -228,7 +192,7 @@ public class NotesExplorer extends VBox
private int getNextId() private int getNextId()
{ {
int i = 0; int i = 0;
for(int key : notes.keySet()) for (int key : notes.keySet())
{ {
if (key != i) if (key != i)
return i; return i;

View File

@ -33,13 +33,14 @@ public class SavesManager
if (!notes.isEmpty()) if (!notes.isEmpty())
{ {
String indexString = ""; String indexString = "";
for(int key : notes.keySet()) for (int key : notes.keySet())
indexString += key + ":" + notes.get(key).getClass().getName() + "\n"; indexString += key + ":" + notes.get(key).getClass().getName() + "\n";
indexString = indexString.substring(0, indexString.length() - 1); indexString = indexString.substring(0, indexString.length() - 1);
this.writeFile(indexFile, indexString); this.writeFile(indexFile, indexString);
} }
} }
public Map<Integer, Note> loadIndex() public Map<Integer, Note> loadIndex()
{ {
File indexFile = new File(SAVE_FOLDER, "index"); File indexFile = new File(SAVE_FOLDER, "index");
@ -48,7 +49,7 @@ public class SavesManager
Map<Integer, Note> notes = new HashMap<Integer, Note>(); Map<Integer, Note> notes = new HashMap<Integer, Note>();
String indexString = this.readFile(indexFile); String indexString = this.readFile(indexFile);
String[] notesString = indexString.split("\n"); String[] notesString = indexString.split("\n");
for(String noteString : notesString) for (String noteString : notesString)
{ {
String[] decomposed = noteString.split(":"); String[] decomposed = noteString.split(":");
if (decomposed.length == 2) if (decomposed.length == 2)
@ -75,7 +76,6 @@ public class SavesManager
{ {
return new File(SAVE_FOLDER, id + ""); return new File(SAVE_FOLDER, id + "");
} }
public String readFile(File file) public String readFile(File file)
{ {
try try
@ -122,38 +122,35 @@ public class SavesManager
} }
} }
private byte[] byteFpeEncryption(byte[] bytes, String key) private static String createCipherFromKey(String key, int bytesLength)
{ {
String cipher = ""; String cipher = "";
int i = 0; int i = 0;
while (cipher.getBytes().length < bytes.length) while (cipher.getBytes().length < bytesLength)
{ {
cipher += key.getBytes()[i]; cipher += key.getBytes()[i];
i++; i++;
if (i >= key.getBytes().length) if (i >= key.getBytes().length)
i = 0; i = 0;
} }
return cipher;
}
private byte[] byteFpeEncryption(byte[] bytes, String key)
{
String cipher = createCipherFromKey(key, bytes.length);
byte[] encryptedBytes = new byte[bytes.length]; byte[] encryptedBytes = new byte[bytes.length];
for(i = 0; i < bytes.length; i++) for (int i = 0; i < bytes.length; i++)
encryptedBytes[i] = (byte) (bytes[i] + cipher.getBytes()[i]); encryptedBytes[i] = (byte) (bytes[i] + cipher.getBytes()[i]);
return encryptedBytes; return encryptedBytes;
} }
private byte[] byteFpeDecryption(byte[] bytes, String key) private byte[] byteFpeDecryption(byte[] bytes, String key)
{ {
String cipher = ""; String cipher = createCipherFromKey(key, bytes.length);
int i = 0;
while (cipher.getBytes().length < bytes.length)
{
cipher += key.getBytes()[i];
i++;
if (i >= key.getBytes().length)
i = 0;
}
byte[] decryptedBytes = new byte[bytes.length]; byte[] decryptedBytes = new byte[bytes.length];
for(i = 0; i < bytes.length; i++) for (int i = 0; i < bytes.length; i++)
decryptedBytes[i] = (byte) (bytes[i] - cipher.getBytes()[i]); decryptedBytes[i] = (byte) (bytes[i] - cipher.getBytes()[i]);
return decryptedBytes; return decryptedBytes;

View File

@ -13,10 +13,8 @@ import org.w3c.dom.Text;
import javafx.application.Application; import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
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;
import javafx.event.EventHandler;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
@ -28,7 +26,7 @@ import javafx.stage.WindowEvent;
public class SmartNotes extends Application public class SmartNotes extends Application
{ {
public static final String version = "alpha0.1"; public static final String version = "0.5";
public static void main(String[] args) public static void main(String[] args)
{ {
@ -50,37 +48,32 @@ public class SmartNotes extends Application
try try
{ {
Logger.getLogger(GlobalScreen.class.getPackage().getName()).setLevel(Level.OFF); Logger.getLogger(GlobalScreen.class.getPackage().getName()).setLevel(Level.OFF);
GlobalScreen.registerNativeHook(); GlobalScreen.registerNativeHook();
GlobalScreen.addNativeKeyListener(new GlobalKeyListener()); GlobalScreen.addNativeKeyListener(new GlobalKeyListener());
} }
catch (NativeHookException ex) catch (NativeHookException ex)
{ {
System.err.println("There was a problem registering the native hook."); System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage()); System.err.println(ex.getMessage());
} }
Platform.setImplicitExit(false); 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");
webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() webView.getEngine().getLoadWorker().stateProperty().addListener((ObservableValue<? extends State> ov, State oldValue, State newValue) -> {
{ if (newValue == State.SUCCEEDED)
@Override
public void changed(ObservableValue<? extends State> ov, State oldValue, State newValue)
{ {
if (newValue == State.SUCCEEDED) Document doc = webView.getEngine().getDocument();
{ Element styleNode = doc.createElement("style");
Document doc = webView.getEngine().getDocument(); Text styleContent = doc.createTextNode(css);
Element styleNode = doc.createElement("style"); styleNode.appendChild(styleContent);
Text styleContent = doc.createTextNode(css); doc.getDocumentElement().getElementsByTagName("head").item(0).appendChild(styleNode);
styleNode.appendChild(styleContent);
doc.getDocumentElement().getElementsByTagName("head").item(0).appendChild(styleNode);
//System.out.println(webView.getEngine().executeScript("document.documentElement.innerHTML"));
}
} }
}); });
// Registering font files.
Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Sans.ttf"), 10); Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Sans.ttf"), 10);
Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Sans Bold.ttf"), 10); Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Sans Bold.ttf"), 10);
Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Sans Italic.ttf"), 10); Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Sans Italic.ttf"), 10);
@ -97,30 +90,21 @@ public class SmartNotes extends Application
this.explorer = new NotesExplorer(); this.explorer = new NotesExplorer();
ScrollPane scrollPane = new ScrollPane(this.explorer); ScrollPane scrollPane = new ScrollPane(this.explorer);
scrollPane.setFitToHeight(true); scrollPane.setFitToWidth(true); scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
this.root.getChildren().add(scrollPane); this.root.getChildren().add(scrollPane);
this.scene = new Scene(this.root, 800, 600); this.scene = new Scene(this.root, 800, 600);
this.scene.getStylesheets().add("/com/madeorsk/smartnotes/style.css"); this.scene.getStylesheets().add("/com/madeorsk/smartnotes/style.css");
stage.setOnCloseRequest(new EventHandler<WindowEvent>() stage.setOnCloseRequest((WindowEvent e) -> {
{ SmartNotes.this.explorer.close();
@Override
public void handle(WindowEvent e)
{
SmartNotes.this.explorer.close();
}
}); });
stage.setScene(this.scene); stage.setScene(this.scene);
stage.setTitle("SmartNotes " + version); stage.setTitle("SmartNotes " + version);
stage.setOnCloseRequest(new EventHandler<WindowEvent>() stage.setOnCloseRequest((WindowEvent event) -> {
{ SmartNotes.this.onStop();
@Override
public void handle(WindowEvent event)
{
SmartNotes.this.onStop();
}
}); });
stage.show(); stage.show();
} }
@ -129,13 +113,15 @@ public class SmartNotes extends Application
{ {
this.setContent(region, false); this.setContent(region, false);
} }
public void setContent(Region region, boolean useScrollPane) public void setContent(Region region, boolean useScrollPane)
{ {
this.root.getChildren().clear(); this.root.getChildren().clear();
if (useScrollPane) if (useScrollPane)
{ {
ScrollPane scrollPane = new ScrollPane(region); ScrollPane scrollPane = new ScrollPane(region);
scrollPane.setFitToHeight(true); scrollPane.setFitToWidth(true); scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
this.root.getChildren().add(scrollPane); this.root.getChildren().add(scrollPane);
} }
else else
@ -165,13 +151,16 @@ public class SmartNotes extends Application
{ {
//System.out.println("P == " + e.getKeyCode() + ":" + e.getKeyChar()); //System.out.println("P == " + e.getKeyCode() + ":" + e.getKeyChar());
} }
@Override @Override
public void nativeKeyReleased(NativeKeyEvent e) public void nativeKeyReleased(NativeKeyEvent e)
{ {
//System.out.println("R == " + e.getKeyCode() + ":" + e.getKeyChar()); //System.out.println("R == " + e.getKeyCode() + ":" + e.getKeyChar());
} }
@Override @Override
public void nativeKeyTyped(NativeKeyEvent e) public void nativeKeyTyped(NativeKeyEvent e)
{} {
}
} }
} }

View File

@ -5,7 +5,6 @@ import com.madeorsk.smartnotes.notes.Note;
import com.madeorsk.smartnotes.notes.TextNote; import com.madeorsk.smartnotes.notes.TextNote;
import javafx.animation.FadeTransition; import javafx.animation.FadeTransition;
import javafx.event.EventHandler;
import javafx.scene.Cursor; import javafx.scene.Cursor;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
@ -25,18 +24,14 @@ public class TypeSelector extends HBox
textNoteItem.setSelected(true); textNoteItem.setSelected(true);
else else
{ {
textNoteItem.setOnMouseClicked(new EventHandler<MouseEvent>() textNoteItem.setOnMouseClicked((MouseEvent event) -> {
{ Note textNote = new TextNote();
public void handle(MouseEvent event) textNote.setName(note.getName());
{ textNote.setTextContent(note.getTextContent());
Note textNote = new TextNote(); textNote.setNoteColor(note.getNoteColor());
textNote.setName(note.getName()); explorer.replaceNote(note, textNote);
textNote.setTextContent(note.getTextContent()); explorer.requestSave(textNote);
textNote.setNoteColor(note.getNoteColor()); SmartNotes.instance.setContent(textNote.getEditBox(explorer));
explorer.replaceNote(note, textNote);
explorer.requestSave(textNote);
SmartNotes.instance.setContent(textNote.getEditBox(explorer));
}
}); });
} }
} }
@ -47,42 +42,33 @@ public class TypeSelector extends HBox
listNoteItem.setSelected(true); listNoteItem.setSelected(true);
else else
{ {
listNoteItem.setOnMouseClicked(new EventHandler<MouseEvent>() listNoteItem.setOnMouseClicked((MouseEvent event) -> {
{ Note listNote = new ListNote();
@Override listNote.setName(note.getName());
public void handle(MouseEvent event) listNote.setTextContent(note.getTextContent());
{ listNote.setNoteColor(note.getNoteColor());
Note listNote = new ListNote(); explorer.replaceNote(note, listNote);
listNote.setName(note.getName()); explorer.requestSave(listNote);
listNote.setTextContent(note.getTextContent()); SmartNotes.instance.setContent(listNote.getEditBox(explorer));
listNote.setNoteColor(note.getNoteColor());
explorer.replaceNote(note, listNote);
explorer.requestSave(listNote);
SmartNotes.instance.setContent(listNote.getEditBox(explorer));
}
}); });
} }
} }
this.getChildren().add(listNoteItem); this.getChildren().add(listNoteItem);
TypeItem imageNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/ImageNoteChoice.png"); TypeItem imageNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/ImageNoteChoice.png");
{ {
} //TODO Next versions.
}
this.getChildren().add(imageNoteItem); this.getChildren().add(imageNoteItem);
TypeItem soundNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/SoundNoteChoice.png"); TypeItem soundNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/SoundNoteChoice.png");
{ {
} //TODO Next versions.
}
this.getChildren().add(soundNoteItem); this.getChildren().add(soundNoteItem);
TypeItem videoNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/VideoNoteChoice.png"); TypeItem videoNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/VideoNoteChoice.png");
{ {
} //TODO Next versions.
}
this.getChildren().add(videoNoteItem); this.getChildren().add(videoNoteItem);
TypeItem positionNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/PositionNoteChoice.png"); TypeItem positionNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/PositionNoteChoice.png");
{ {
} //TODO Next versions.
}
this.getChildren().add(positionNoteItem); this.getChildren().add(positionNoteItem);
} }
@ -97,32 +83,22 @@ public class TypeSelector extends HBox
this.getChildren().add(new ImageView(new Image(typeIconPath))); this.getChildren().add(new ImageView(new Image(typeIconPath)));
this.setOpacity(0.4); this.setOpacity(0.4);
this.setOnMouseEntered(new EventHandler<MouseEvent>() this.setOnMouseEntered((MouseEvent e) -> {
{ if (!TypeItem.this.isSelected())
@Override
public void handle(MouseEvent e)
{ {
if (!TypeItem.this.isSelected()) FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this);
{ transition.setFromValue(0.4);
FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this); transition.setToValue(1.0);
transition.setFromValue(0.4); transition.play();
transition.setToValue(1.0);
transition.play();
}
} }
}); });
this.setOnMouseExited(new EventHandler<MouseEvent>() this.setOnMouseExited((MouseEvent e) -> {
{ if (!TypeItem.this.isSelected())
@Override
public void handle(MouseEvent e)
{ {
if (!TypeItem.this.isSelected()) FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this);
{ transition.setFromValue(1.0);
FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this); transition.setToValue(0.4);
transition.setFromValue(1.0); transition.play();
transition.setToValue(0.4);
transition.play();
}
} }
}); });
} }
@ -140,6 +116,7 @@ public class TypeSelector extends HBox
transition.play(); transition.play();
} }
} }
public boolean isSelected() public boolean isSelected()
{ {
return this.selected; return this.selected;

View File

@ -17,7 +17,7 @@ public class Utils
{ {
InputStream is = Utils.class.getResourceAsStream(path); InputStream is = Utils.class.getResourceAsStream(path);
String result = ""; String result = "";
byte[] buffer = new byte[1024*8]; byte[] buffer = new byte[1024 * 8];
while (is.read(buffer) > 0) while (is.read(buffer) > 0)
result += new String(buffer); result += new String(buffer);
return result.trim(); return result.trim();

View File

@ -59,14 +59,9 @@ public class ListNote extends Note
returnButton.setId("imageButton"); returnButton.setId("imageButton");
returnButton.setCursor(Cursor.HAND); returnButton.setCursor(Cursor.HAND);
returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png"))); returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png")));
returnButton.setOnMouseClicked(new EventHandler<MouseEvent>() returnButton.setOnMouseClicked((MouseEvent event) -> {
{ explorer.updateCurrentFolder();
@Override SmartNotes.instance.setContent(explorer, true);
public void handle(MouseEvent event)
{
explorer.updateCurrentFolder();
SmartNotes.instance.setContent(explorer, true);
}
}); });
titleBox.getChildren().add(returnButton); titleBox.getChildren().add(returnButton);
@ -74,13 +69,8 @@ public class ListNote extends Note
editButton.setId("imageButton"); editButton.setId("imageButton");
editButton.setCursor(Cursor.HAND); editButton.setCursor(Cursor.HAND);
editButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/EditIcon.png"))); editButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/EditIcon.png")));
editButton.setOnMouseClicked(new EventHandler<MouseEvent>() editButton.setOnMouseClicked((MouseEvent event) -> {
{ SmartNotes.instance.setContent(ListNote.this.getEditBox(explorer));
@Override
public void handle(MouseEvent event)
{
SmartNotes.instance.setContent(ListNote.this.getEditBox(explorer));
}
}); });
HBox buttonsBox = new HBox(); HBox buttonsBox = new HBox();
buttonsBox.getChildren().add(editButton); buttonsBox.getChildren().add(editButton);
@ -90,17 +80,16 @@ public class ListNote extends Note
NoteColorSelector colorSelector = new NoteColorSelector(); NoteColorSelector colorSelector = new NoteColorSelector();
colorSelector.setAlignment(Pos.CENTER); colorSelector.setAlignment(Pos.CENTER);
colorSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); colorSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2));
colorSelector.addColor(NoteColor.WHITE); colorSelector.addColor(NoteColor.BLUE); colorSelector.addColor(NoteColor.YELLOW); colorSelector.addColor(NoteColor.RED); colorSelector.addColor(NoteColor.GREEN); colorSelector.addColor(NoteColor.WHITE);
colorSelector.addColor(NoteColor.BLUE);
colorSelector.addColor(NoteColor.YELLOW);
colorSelector.addColor(NoteColor.RED);
colorSelector.addColor(NoteColor.GREEN);
colorSelector.setSelectedColor(this.getNoteColor()); colorSelector.setSelectedColor(this.getNoteColor());
colorSelector.selectedColorProperty().addListener(new ChangeListener<NoteColor>() colorSelector.selectedColorProperty().addListener((ObservableValue<? extends NoteColor> ov, NoteColor oldValue, NoteColor newValue) -> {
{ ListNote.this.setNoteColor(newValue);
@Override nameField.setStyle("-fx-text-fill: rgb(" + newValue.getColor().getRed() * 255 + "," + newValue.getColor().getGreen() * 255 + "," + newValue.getColor().getBlue() * 255 + ");");
public void changed(ObservableValue<? extends NoteColor> ov, NoteColor oldValue, NoteColor newValue) explorer.requestSave(ListNote.this);
{
ListNote.this.setNoteColor(newValue);
nameField.setStyle("-fx-text-fill: rgb(" + newValue.getColor().getRed()*255 + "," + newValue.getColor().getGreen()*255 + "," + newValue.getColor().getBlue()*255 + ");");
explorer.requestSave(ListNote.this);
}
}); });
titleBox.getChildren().add(colorSelector); titleBox.getChildren().add(colorSelector);
} }
@ -111,22 +100,15 @@ public class ListNote extends Note
nameField.prefWidthProperty().bind(box.widthProperty()); nameField.prefWidthProperty().bind(box.widthProperty());
nameField.setAlignment(Pos.CENTER); nameField.setAlignment(Pos.CENTER);
nameField.setId("nameField"); nameField.setId("nameField");
nameField.setStyle("-fx-text-fill: rgb(" + this.getNoteColor().getColor().getRed()*255 + "," + this.getNoteColor().getColor().getGreen()*255 + "," + this.getNoteColor().getColor().getBlue()*255 + ");"); nameField.setStyle("-fx-text-fill: rgb(" + this.getNoteColor().getColor().getRed() * 255 + "," + this.getNoteColor().getColor().getGreen() * 255 + "," + this.getNoteColor().getColor().getBlue() * 255 + ");");
nameField.setText(this.getName()); nameField.setText(this.getName());
nameField.textProperty().addListener(new ChangeListener<String>() nameField.textProperty().addListener((ObservableValue<? extends String> ov, String oldValue, String newValue) -> {
{ ListNote.this.setName(newValue);
@Override explorer.requestSave(ListNote.this);
public void changed(ObservableValue<? extends String> ov, String oldValue, String newValue)
{
ListNote.this.setName(newValue);
explorer.requestSave(ListNote.this);
}
}); });
} }
box.getChildren().add(nameField); box.getChildren().add(nameField);
//
HBox separator = new HBox(); HBox separator = new HBox();
separator.setId("separator"); separator.setId("separator");
separator.setPrefHeight(5); separator.setPrefHeight(5);
@ -134,44 +116,13 @@ public class ListNote extends Note
SmartNotes.webView.getEngine().loadContent(Utils.markdownToHtml(this.getTextContent())); SmartNotes.webView.getEngine().loadContent(Utils.markdownToHtml(this.getTextContent()));
SmartNotes.webView.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2)); SmartNotes.webView.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2));
box.getChildren().add(SmartNotes.webView); box.getChildren().add(SmartNotes.webView);
/*final TextArea textArea = new TextArea();
{
textArea.setId("text");
textArea.setWrapText(true);
textArea.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2));
textArea.setText(this.getTextContent());
textArea.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> ov, String oldValue, String newValue)
{
ListNote.this.setTextContent(newValue);
explorer.requestSave(ListNote.this);
}
});
Platform.runLater(new Runnable()
{
@Override
public void run()
{
textArea.requestFocus();
textArea.positionCaret(textArea.getLength());
}
});
}
box.getChildren().add(textArea);*/
box.getChildren().add(separator); box.getChildren().add(separator);
this.listBox.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2)); this.listBox.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2));
this.listBox.setListChangeListener(new Runnable() this.listBox.setListChangeListener(() -> {
{ if (!ListNote.this.loading)
@Override explorer.requestSave(ListNote.this);
public void run()
{
if (!ListNote.this.loading)
explorer.requestSave(ListNote.this);
}
}); });
box.getChildren().add(this.listBox); box.getChildren().add(this.listBox);
@ -197,14 +148,9 @@ public class ListNote extends Note
returnButton.setId("imageButton"); returnButton.setId("imageButton");
returnButton.setCursor(Cursor.HAND); returnButton.setCursor(Cursor.HAND);
returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png"))); returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png")));
returnButton.setOnMouseClicked(new EventHandler<MouseEvent>() returnButton.setOnMouseClicked((MouseEvent event) -> {
{ explorer.updateCurrentFolder();
@Override SmartNotes.instance.setContent(explorer, true);
public void handle(MouseEvent event)
{
explorer.updateCurrentFolder();
SmartNotes.instance.setContent(explorer, true);
}
}); });
titleBox.getChildren().add(returnButton); titleBox.getChildren().add(returnButton);
@ -216,17 +162,16 @@ public class ListNote extends Note
NoteColorSelector colorSelector = new NoteColorSelector(); NoteColorSelector colorSelector = new NoteColorSelector();
colorSelector.setAlignment(Pos.CENTER); colorSelector.setAlignment(Pos.CENTER);
colorSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); colorSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2));
colorSelector.addColor(NoteColor.WHITE); colorSelector.addColor(NoteColor.BLUE); colorSelector.addColor(NoteColor.YELLOW); colorSelector.addColor(NoteColor.RED); colorSelector.addColor(NoteColor.GREEN); colorSelector.addColor(NoteColor.WHITE);
colorSelector.addColor(NoteColor.BLUE);
colorSelector.addColor(NoteColor.YELLOW);
colorSelector.addColor(NoteColor.RED);
colorSelector.addColor(NoteColor.GREEN);
colorSelector.setSelectedColor(this.getNoteColor()); colorSelector.setSelectedColor(this.getNoteColor());
colorSelector.selectedColorProperty().addListener(new ChangeListener<NoteColor>() colorSelector.selectedColorProperty().addListener((ObservableValue<? extends NoteColor> ov, NoteColor oldValue, NoteColor newValue) -> {
{ ListNote.this.setNoteColor(newValue);
@Override nameField.setStyle("-fx-text-fill: rgb(" + newValue.getColor().getRed() * 255 + "," + newValue.getColor().getGreen() * 255 + "," + newValue.getColor().getBlue() * 255 + ");");
public void changed(ObservableValue<? extends NoteColor> ov, NoteColor oldValue, NoteColor newValue) explorer.requestSave(ListNote.this);
{
ListNote.this.setNoteColor(newValue);
nameField.setStyle("-fx-text-fill: rgb(" + newValue.getColor().getRed()*255 + "," + newValue.getColor().getGreen()*255 + "," + newValue.getColor().getBlue()*255 + ");");
explorer.requestSave(ListNote.this);
}
}); });
titleBox.getChildren().add(colorSelector); titleBox.getChildren().add(colorSelector);
} }
@ -236,16 +181,11 @@ public class ListNote extends Note
{ {
nameField.setAlignment(Pos.CENTER); nameField.setAlignment(Pos.CENTER);
nameField.setId("nameField"); nameField.setId("nameField");
nameField.setStyle("-fx-text-fill: rgb(" + this.getNoteColor().getColor().getRed()*255 + "," + this.getNoteColor().getColor().getGreen()*255 + "," + this.getNoteColor().getColor().getBlue()*255 + ");"); nameField.setStyle("-fx-text-fill: rgb(" + this.getNoteColor().getColor().getRed() * 255 + "," + this.getNoteColor().getColor().getGreen() * 255 + "," + this.getNoteColor().getColor().getBlue() * 255 + ");");
nameField.setText(this.getName()); nameField.setText(this.getName());
nameField.textProperty().addListener(new ChangeListener<String>() nameField.textProperty().addListener((ObservableValue<? extends String> ov, String oldValue, String newValue) -> {
{ ListNote.this.setName(newValue);
@Override explorer.requestSave(ListNote.this);
public void changed(ObservableValue<? extends String> ov, String oldValue, String newValue)
{
ListNote.this.setName(newValue);
explorer.requestSave(ListNote.this);
}
}); });
} }
box.getChildren().add(nameField); box.getChildren().add(nameField);
@ -262,23 +202,13 @@ public class ListNote extends Note
textArea.setWrapText(true); textArea.setWrapText(true);
textArea.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2)); textArea.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2));
textArea.setText(this.getTextContent()); textArea.setText(this.getTextContent());
textArea.textProperty().addListener(new ChangeListener<String>() textArea.textProperty().addListener((ObservableValue<? extends String> ov, String oldValue, String newValue) -> {
{ ListNote.this.setTextContent(newValue);
@Override explorer.requestSave(ListNote.this);
public void changed(ObservableValue<? extends String> ov, String oldValue, String newValue)
{
ListNote.this.setTextContent(newValue);
explorer.requestSave(ListNote.this);
}
}); });
Platform.runLater(new Runnable() Platform.runLater(() -> {
{ textArea.requestFocus();
@Override textArea.positionCaret(textArea.getLength());
public void run()
{
textArea.requestFocus();
textArea.positionCaret(textArea.getLength());
}
}); });
} }
box.getChildren().add(textArea); box.getChildren().add(textArea);
@ -286,14 +216,9 @@ public class ListNote extends Note
box.getChildren().add(separator); box.getChildren().add(separator);
this.listBox.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2)); this.listBox.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2));
this.listBox.setListChangeListener(new Runnable() this.listBox.setListChangeListener(() -> {
{ if (!ListNote.this.loading)
@Override explorer.requestSave(ListNote.this);
public void run()
{
if (!ListNote.this.loading)
explorer.requestSave(ListNote.this);
}
}); });
box.getChildren().add(this.listBox); box.getChildren().add(this.listBox);
@ -306,10 +231,11 @@ public class ListNote extends Note
String fileContent = this.getName() + "\n" + this.getNoteColor().name() + "\n"; String fileContent = this.getName() + "\n" + this.getNoteColor().name() + "\n";
Map<String, Boolean> list = this.listBox.getList(); Map<String, Boolean> list = this.listBox.getList();
fileContent += Integer.toUnsignedString(list.keySet().size(), 16) + "\n"; fileContent += Integer.toUnsignedString(list.keySet().size(), 16) + "\n";
for(String key : list.keySet()) for (String key : list.keySet())
fileContent += key + ":" + list.get(key).toString() + "\n"; fileContent += key + ":" + list.get(key).toString() + "\n";
saves.writeFile(saves.getSaveFile(id), fileContent + this.getTextContent()); saves.writeFile(saves.getSaveFile(id), fileContent + this.getTextContent());
} }
@Override @Override
public boolean load(SavesManager saves, int id) public boolean load(SavesManager saves, int id)
{ {
@ -330,7 +256,7 @@ public class ListNote extends Note
separatorIndex = saved.indexOf('\n'); separatorIndex = saved.indexOf('\n');
int listSize = Integer.parseUnsignedInt(saved.substring(0, separatorIndex), 16); int listSize = Integer.parseUnsignedInt(saved.substring(0, separatorIndex), 16);
Map<String, Boolean> list = new HashMap<String, Boolean>(); Map<String, Boolean> list = new HashMap<String, Boolean>();
for(int i = 0; i < listSize; i++) for (int i = 0; i < listSize; i++)
{ {
saved = saved.substring(separatorIndex + 1); saved = saved.substring(separatorIndex + 1);
separatorIndex = saved.indexOf('\n'); separatorIndex = saved.indexOf('\n');
@ -351,6 +277,7 @@ public class ListNote extends Note
else else
return false; return false;
} }
@Override @Override
public void delete(SavesManager saves, int id) public void delete(SavesManager saves, int id)
{ {

View File

@ -21,15 +21,17 @@ public abstract class Note implements SavableNote
private double r; private double r;
private double g; private double g;
private double b; private double b;
NoteColor(double red, double green, double blue) NoteColor(double red, double green, double blue)
{ {
this.r = red; this.r = red;
this.g = green; this.g = green;
this.b = blue; this.b = blue;
} }
public Color getColor() public Color getColor()
{ {
return new Color(this.r/255, this.g/255, this.b/255, 1); return new Color(this.r / 255, this.g / 255, this.b / 255, 1);
} }
} }
@ -42,6 +44,7 @@ public abstract class Note implements SavableNote
{ {
this.name = name; this.name = name;
} }
public String getName() public String getName()
{ {
return this.name; return this.name;
@ -51,10 +54,12 @@ public abstract class Note implements SavableNote
{ {
this.color = color; this.color = color;
} }
public NoteColor getNoteColor() public NoteColor getNoteColor()
{ {
return this.color; return this.color;
} }
public List<String> getPaths() public List<String> getPaths()
{ {
return this.paths; return this.paths;
@ -65,10 +70,12 @@ public abstract class Note implements SavableNote
this.textContent = content; this.textContent = content;
this.updatePaths(); this.updatePaths();
} }
public String getTextContent() public String getTextContent()
{ {
return this.textContent; return this.textContent;
} }
private void updatePaths() private void updatePaths()
{ {
this.paths.clear(); this.paths.clear();
@ -79,13 +86,13 @@ public abstract class Note implements SavableNote
{ {
String[] lines = text.split("\n"); String[] lines = text.split("\n");
String lastLine = lines[lines.length - 1]; String lastLine = lines[lines.length - 1];
for(String word : lastLine.split(" ")) for (String word : lastLine.split(" "))
if (word.startsWith("#") && !word.equals("#")) if (word.startsWith("#") && !word.equals("#"))
this.paths.add(word); this.paths.add(word);
} }
else else
{ {
for(String word : text.split(" ")) for (String word : text.split(" "))
if (word.startsWith("#") && !word.equals("#")) if (word.startsWith("#") && !word.equals("#"))
this.paths.add(word); this.paths.add(word);
} }
@ -93,5 +100,6 @@ public abstract class Note implements SavableNote
} }
public abstract VBox getViewBox(NotesExplorer explorer); public abstract VBox getViewBox(NotesExplorer explorer);
public abstract VBox getEditBox(NotesExplorer explorer); public abstract VBox getEditBox(NotesExplorer explorer);
} }

View File

@ -49,14 +49,9 @@ public class TextNote extends Note
returnButton.setId("imageButton"); returnButton.setId("imageButton");
returnButton.setCursor(Cursor.HAND); returnButton.setCursor(Cursor.HAND);
returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png"))); returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png")));
returnButton.setOnMouseClicked(new EventHandler<MouseEvent>() returnButton.setOnMouseClicked((MouseEvent event) -> {
{ explorer.updateCurrentFolder();
@Override SmartNotes.instance.setContent(explorer, true);
public void handle(MouseEvent event)
{
explorer.updateCurrentFolder();
SmartNotes.instance.setContent(explorer, true);
}
}); });
titleBox.getChildren().add(returnButton); titleBox.getChildren().add(returnButton);
@ -64,13 +59,8 @@ public class TextNote extends Note
editButton.setId("imageButton"); editButton.setId("imageButton");
editButton.setCursor(Cursor.HAND); editButton.setCursor(Cursor.HAND);
editButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/EditIcon.png"))); editButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/EditIcon.png")));
editButton.setOnMouseClicked(new EventHandler<MouseEvent>() editButton.setOnMouseClicked((MouseEvent event) -> {
{ SmartNotes.instance.setContent(TextNote.this.getEditBox(explorer));
@Override
public void handle(MouseEvent event)
{
SmartNotes.instance.setContent(TextNote.this.getEditBox(explorer));
}
}); });
HBox buttonsBox = new HBox(); HBox buttonsBox = new HBox();
buttonsBox.getChildren().add(editButton); buttonsBox.getChildren().add(editButton);
@ -80,17 +70,16 @@ public class TextNote extends Note
NoteColorSelector colorSelector = new NoteColorSelector(); NoteColorSelector colorSelector = new NoteColorSelector();
colorSelector.setAlignment(Pos.CENTER); colorSelector.setAlignment(Pos.CENTER);
colorSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); colorSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2));
colorSelector.addColor(NoteColor.WHITE); colorSelector.addColor(NoteColor.BLUE); colorSelector.addColor(NoteColor.YELLOW); colorSelector.addColor(NoteColor.RED); colorSelector.addColor(NoteColor.GREEN); colorSelector.addColor(NoteColor.WHITE);
colorSelector.addColor(NoteColor.BLUE);
colorSelector.addColor(NoteColor.YELLOW);
colorSelector.addColor(NoteColor.RED);
colorSelector.addColor(NoteColor.GREEN);
colorSelector.setSelectedColor(this.getNoteColor()); colorSelector.setSelectedColor(this.getNoteColor());
colorSelector.selectedColorProperty().addListener(new ChangeListener<NoteColor>() colorSelector.selectedColorProperty().addListener((ObservableValue<? extends NoteColor> ov, NoteColor oldValue, NoteColor newValue) -> {
{ TextNote.this.setNoteColor(newValue);
@Override nameField.setStyle("-fx-text-fill: rgb(" + newValue.getColor().getRed() * 255 + "," + newValue.getColor().getGreen() * 255 + "," + newValue.getColor().getBlue() * 255 + ");");
public void changed(ObservableValue<? extends NoteColor> ov, NoteColor oldValue, NoteColor newValue) explorer.requestSave(TextNote.this);
{
TextNote.this.setNoteColor(newValue);
nameField.setStyle("-fx-text-fill: rgb(" + newValue.getColor().getRed()*255 + "," + newValue.getColor().getGreen()*255 + "," + newValue.getColor().getBlue()*255 + ");");
explorer.requestSave(TextNote.this);
}
}); });
titleBox.getChildren().add(colorSelector); titleBox.getChildren().add(colorSelector);
} }
@ -101,16 +90,11 @@ public class TextNote extends Note
nameField.prefWidthProperty().bind(box.widthProperty()); nameField.prefWidthProperty().bind(box.widthProperty());
nameField.setAlignment(Pos.CENTER); nameField.setAlignment(Pos.CENTER);
nameField.setId("nameField"); nameField.setId("nameField");
nameField.setStyle("-fx-text-fill: rgb(" + this.getNoteColor().getColor().getRed()*255 + "," + this.getNoteColor().getColor().getGreen()*255 + "," + this.getNoteColor().getColor().getBlue()*255 + ");"); nameField.setStyle("-fx-text-fill: rgb(" + this.getNoteColor().getColor().getRed() * 255 + "," + this.getNoteColor().getColor().getGreen() * 255 + "," + this.getNoteColor().getColor().getBlue() * 255 + ");");
nameField.setText(this.getName()); nameField.setText(this.getName());
nameField.textProperty().addListener(new ChangeListener<String>() nameField.textProperty().addListener((ObservableValue<? extends String> ov, String oldValue, String newValue) -> {
{ TextNote.this.setName(newValue);
@Override explorer.requestSave(TextNote.this);
public void changed(ObservableValue<? extends String> ov, String oldValue, String newValue)
{
TextNote.this.setName(newValue);
explorer.requestSave(TextNote.this);
}
}); });
} }
box.getChildren().add(nameField); box.getChildren().add(nameField);
@ -138,14 +122,9 @@ public class TextNote extends Note
returnButton.setId("imageButton"); returnButton.setId("imageButton");
returnButton.setCursor(Cursor.HAND); returnButton.setCursor(Cursor.HAND);
returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png"))); returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png")));
returnButton.setOnMouseClicked(new EventHandler<MouseEvent>() returnButton.setOnMouseClicked((MouseEvent event) -> {
{ explorer.updateCurrentFolder();
@Override SmartNotes.instance.setContent(explorer, true);
public void handle(MouseEvent event)
{
explorer.updateCurrentFolder();
SmartNotes.instance.setContent(explorer, true);
}
}); });
titleBox.getChildren().add(returnButton); titleBox.getChildren().add(returnButton);
@ -157,17 +136,16 @@ public class TextNote extends Note
NoteColorSelector colorSelector = new NoteColorSelector(); NoteColorSelector colorSelector = new NoteColorSelector();
colorSelector.setAlignment(Pos.CENTER); colorSelector.setAlignment(Pos.CENTER);
colorSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); colorSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2));
colorSelector.addColor(NoteColor.WHITE); colorSelector.addColor(NoteColor.BLUE); colorSelector.addColor(NoteColor.YELLOW); colorSelector.addColor(NoteColor.RED); colorSelector.addColor(NoteColor.GREEN); colorSelector.addColor(NoteColor.WHITE);
colorSelector.addColor(NoteColor.BLUE);
colorSelector.addColor(NoteColor.YELLOW);
colorSelector.addColor(NoteColor.RED);
colorSelector.addColor(NoteColor.GREEN);
colorSelector.setSelectedColor(this.getNoteColor()); colorSelector.setSelectedColor(this.getNoteColor());
colorSelector.selectedColorProperty().addListener(new ChangeListener<NoteColor>() colorSelector.selectedColorProperty().addListener((ObservableValue<? extends NoteColor> ov, NoteColor oldValue, NoteColor newValue) -> {
{ TextNote.this.setNoteColor(newValue);
@Override nameField.setStyle("-fx-text-fill: rgb(" + newValue.getColor().getRed() * 255 + "," + newValue.getColor().getGreen() * 255 + "," + newValue.getColor().getBlue() * 255 + ");");
public void changed(ObservableValue<? extends NoteColor> ov, NoteColor oldValue, NoteColor newValue) explorer.requestSave(TextNote.this);
{
TextNote.this.setNoteColor(newValue);
nameField.setStyle("-fx-text-fill: rgb(" + newValue.getColor().getRed()*255 + "," + newValue.getColor().getGreen()*255 + "," + newValue.getColor().getBlue()*255 + ");");
explorer.requestSave(TextNote.this);
}
}); });
titleBox.getChildren().add(colorSelector); titleBox.getChildren().add(colorSelector);
} }
@ -177,16 +155,11 @@ public class TextNote extends Note
{ {
nameField.setAlignment(Pos.CENTER); nameField.setAlignment(Pos.CENTER);
nameField.setId("nameField"); nameField.setId("nameField");
nameField.setStyle("-fx-text-fill: rgb(" + this.getNoteColor().getColor().getRed()*255 + "," + this.getNoteColor().getColor().getGreen()*255 + "," + this.getNoteColor().getColor().getBlue()*255 + ");"); nameField.setStyle("-fx-text-fill: rgb(" + this.getNoteColor().getColor().getRed() * 255 + "," + this.getNoteColor().getColor().getGreen() * 255 + "," + this.getNoteColor().getColor().getBlue() * 255 + ");");
nameField.setText(this.getName()); nameField.setText(this.getName());
nameField.textProperty().addListener(new ChangeListener<String>() nameField.textProperty().addListener((ObservableValue<? extends String> ov, String oldValue, String newValue) -> {
{ TextNote.this.setName(newValue);
@Override explorer.requestSave(TextNote.this);
public void changed(ObservableValue<? extends String> ov, String oldValue, String newValue)
{
TextNote.this.setName(newValue);
explorer.requestSave(TextNote.this);
}
}); });
} }
box.getChildren().add(nameField); box.getChildren().add(nameField);
@ -197,23 +170,13 @@ public class TextNote extends Note
textArea.setWrapText(true); textArea.setWrapText(true);
textArea.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty())); textArea.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()));
textArea.setText(this.getTextContent()); textArea.setText(this.getTextContent());
textArea.textProperty().addListener(new ChangeListener<String>() textArea.textProperty().addListener((ObservableValue<? extends String> ov, String oldValue, String newValue) -> {
{ TextNote.this.setTextContent(newValue);
@Override explorer.requestSave(TextNote.this);
public void changed(ObservableValue<? extends String> ov, String oldValue, String newValue)
{
TextNote.this.setTextContent(newValue);
explorer.requestSave(TextNote.this);
}
}); });
Platform.runLater(new Runnable() Platform.runLater(() -> {
{ textArea.requestFocus();
@Override textArea.positionCaret(textArea.getLength());
public void run()
{
textArea.requestFocus();
textArea.positionCaret(textArea.getLength());
}
}); });
} }
box.getChildren().add(textArea); box.getChildren().add(textArea);
@ -226,6 +189,7 @@ public class TextNote extends Note
{ {
saves.writeFile(saves.getSaveFile(id), this.getName() + "\n" + this.getNoteColor().name() + "\n" + this.getTextContent()); saves.writeFile(saves.getSaveFile(id), this.getName() + "\n" + this.getNoteColor().name() + "\n" + this.getTextContent());
} }
@Override @Override
public boolean load(SavesManager saves, int id) public boolean load(SavesManager saves, int id)
{ {
@ -246,6 +210,7 @@ public class TextNote extends Note
else else
return false; return false;
} }
@Override @Override
public void delete(SavesManager saves, int id) public void delete(SavesManager saves, int id)
{ {

View File

@ -22,15 +22,16 @@ public class FolderPath implements Path
public FolderPath getFolder(String folderName) public FolderPath getFolder(String folderName)
{ {
for(Path path : this.content) for (Path path : this.content)
if (path.isFolder()) if (path.isFolder())
if (((FolderPath) path).getName().equalsIgnoreCase(folderName)) if (((FolderPath) path).getName().equalsIgnoreCase(folderName))
return (FolderPath) path; return (FolderPath) path;
return null; return null;
} }
public boolean containsFolder(String folderName) public boolean containsFolder(String folderName)
{ {
for(Path path : this.content) for (Path path : this.content)
if (path.isFolder()) if (path.isFolder())
if (((FolderPath) path).getName().equalsIgnoreCase(folderName)) if (((FolderPath) path).getName().equalsIgnoreCase(folderName))
return true; return true;
@ -42,14 +43,17 @@ public class FolderPath implements Path
this.name = name; this.name = name;
return this; return this;
} }
public String getName() public String getName()
{ {
return this.name; return this.name;
} }
public FolderPath getParent() public FolderPath getParent()
{ {
return this.parent; return this.parent;
} }
public List<Path> getContent() public List<Path> getContent()
{ {
return this.content; return this.content;

View File

@ -2,15 +2,18 @@
{ {
-fx-background-color: #282828; -fx-background-color: #282828;
} }
.scroll-bar .increment-button, .scroll-bar .decrement-button, .scroll-bar .increment-button .increment-arrow, .scroll-bar .decrement-button .decrement-arrow .scroll-bar .increment-button, .scroll-bar .decrement-button, .scroll-bar .increment-button .increment-arrow, .scroll-bar .decrement-button .decrement-arrow
{ {
-fx-font-size: 0; -fx-font-size: 0;
-fx-padding: 0; -fx-padding: 0;
} }
.scroll-bar .track .scroll-bar .track
{ {
-fx-background-color: transparent; -fx-background-color: transparent;
} }
.scroll-bar .thumb .scroll-bar .thumb
{ {
-fx-background-color: rgba(0, 0, 0, 0.15); -fx-background-color: rgba(0, 0, 0, 0.15);
@ -21,20 +24,24 @@
{ {
-fx-background-color: transparent; -fx-background-color: transparent;
} }
#nameField, #text, #noteItemName #nameField, #text, #noteItemName
{ {
-fx-text-fill: white; -fx-text-fill: white;
-fx-font-family: "Courier Prime Sans"; -fx-font-family: "Courier Prime Sans", monospace;
-fx-font-size: 32px; -fx-font-size: 32px;
} }
#noteItemName #noteItemName
{ {
-fx-font-size: 24px; -fx-font-size: 24px;
} }
#text #text
{ {
-fx-font-size: 20px; -fx-font-size: 20px;
} }
#separator #separator
{ {
-fx-background-color: rgba(0, 0, 0, 0.15); -fx-background-color: rgba(0, 0, 0, 0.15);

View File

@ -2,18 +2,19 @@ body
{ {
background: #282828; background: #282828;
color: white; color: white;
font-family: "Courier Prime Sans"; font-family: "Courier Prime Sans", monospace;
font-size: 20px; font-size: 20px;
} }
code code
{ {
display: inline-block; display: inline-block;
font-family: "Courier Prime Code"; font-family: "Courier Prime Code", monospace;
background: rgba(0, 0, 0, 0.1); background: rgba(0, 0, 0, 0.1);
padding: 5px; padding: 5px;
border-radius: 5px; border-radius: 5px;
} }
pre code pre code
{ {
width: 100%; width: 100%;
@ -22,7 +23,7 @@ pre code
blockquote blockquote
{ {
display: block; display: block;
font-family: "Courier Prime"; font-family: "Courier Prime", monospace;
padding: 0 10px 0 10px; padding: 0 10px 0 10px;
border-left: solid rgba(0, 0, 0, 0.25) 2px; border-left: solid rgba(0, 0, 0, 0.25) 2px;
} }