From 21b2e2fc4aa7cfc7ab93c2ac0caaa99cbfdf4706 Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Sun, 22 Apr 2018 15:30:21 +0200 Subject: [PATCH] Code update and cleanup --- SmartNotes/smartnotes/.gitignore | 2 + SmartNotes/smartnotes/pom.xml | 68 ++--- .../com/madeorsk/smartnotes/ExplorerItem.java | 32 +-- .../java/com/madeorsk/smartnotes/ListBox.java | 148 ++++------- .../smartnotes/NoteColorSelector.java | 29 +-- .../madeorsk/smartnotes/NotesExplorer.java | 126 ++++----- .../com/madeorsk/smartnotes/SavesManager.java | 53 ++-- .../com/madeorsk/smartnotes/SmartNotes.java | 97 ++++--- .../com/madeorsk/smartnotes/TypeSelector.java | 97 +++---- .../java/com/madeorsk/smartnotes/Utils.java | 6 +- .../madeorsk/smartnotes/notes/ListNote.java | 239 ++++++------------ .../com/madeorsk/smartnotes/notes/Note.java | 26 +- .../madeorsk/smartnotes/notes/TextNote.java | 157 +++++------- .../madeorsk/smartnotes/paths/FolderPath.java | 18 +- .../madeorsk/smartnotes/paths/NotePath.java | 6 +- .../java/com/madeorsk/smartnotes/style.css | 9 +- .../java/com/madeorsk/smartnotes/webView.css | 7 +- 17 files changed, 448 insertions(+), 672 deletions(-) create mode 100644 SmartNotes/smartnotes/.gitignore diff --git a/SmartNotes/smartnotes/.gitignore b/SmartNotes/smartnotes/.gitignore new file mode 100644 index 0000000..66892a0 --- /dev/null +++ b/SmartNotes/smartnotes/.gitignore @@ -0,0 +1,2 @@ +\.idea +*\.iml diff --git a/SmartNotes/smartnotes/pom.xml b/SmartNotes/smartnotes/pom.xml index 8df9c24..7eeaa71 100644 --- a/SmartNotes/smartnotes/pom.xml +++ b/SmartNotes/smartnotes/pom.xml @@ -1,39 +1,41 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - com.madeorsk - smartnotes - 1.0 - jar + com.madeorsk + smartnotes + 0.5 + jar - SmartNotes - https://smartnotes.madeorsk.com + SmartNotes + https://smartnotes.madeorsk.com - - UTF-8 - + + UTF-8 + 1.8 + 1.8 + - - - junit - junit - 3.8.1 - test - - - com.vladsch.flexmark - flexmark - 0.26.2 - - - com.1stleg - jnativehook - 2.1.0 - - - - Madeorsk - https://madeorsk.com - + + + junit + junit + 3.8.1 + test + + + com.vladsch.flexmark + flexmark + 0.26.2 + + + com.1stleg + jnativehook + 2.1.0 + + + + Madeorsk + https://madeorsk.com + diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/ExplorerItem.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/ExplorerItem.java index 241bac7..fb99efb 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/ExplorerItem.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/ExplorerItem.java @@ -3,7 +3,6 @@ package com.madeorsk.smartnotes; import com.madeorsk.smartnotes.notes.Note; import com.madeorsk.smartnotes.paths.FolderPath; -import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Cursor; import javafx.scene.control.Label; @@ -16,31 +15,26 @@ public class ExplorerItem extends HBox { private boolean folder; private Object item; - + public ExplorerItem(boolean folder, Object item, final NotesExplorer explorer) { this.folder = folder; this.item = item; - + this.setCursor(Cursor.HAND); - this.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) + this.setOnMouseClicked((MouseEvent event) -> { + if (ExplorerItem.this.folder) + explorer.goToFolder((FolderPath) ExplorerItem.this.item); + else { - if (ExplorerItem.this.folder) - explorer.goToFolder((FolderPath) ExplorerItem.this.item); - else - { - explorer.requestLoad((Note) ExplorerItem.this.item); - SmartNotes.instance.setContent(((Note) ExplorerItem.this.item).getViewBox(explorer)); - } + explorer.requestLoad((Note) ExplorerItem.this.item); + SmartNotes.instance.setContent(((Note) ExplorerItem.this.item).getViewBox(explorer)); } }); - + this.setAlignment(Pos.CENTER_LEFT); this.setSpacing(10); - + if (this.folder) { FolderPath folderPath = (FolderPath) this.item; @@ -58,17 +52,17 @@ public class ExplorerItem extends HBox this.getChildren().add(noteNameLabel); } } - + public ExplorerItem setFolderIcon(String path) { this.getChildren().clear(); - + FolderPath folderPath = (FolderPath) this.item; this.getChildren().add(new ImageView(new Image(path))); Label folderNameLabel = new Label(folderPath.getName()); folderNameLabel.setId("noteItemName"); this.getChildren().add(folderNameLabel); - + return this; } } diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/ListBox.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/ListBox.java index 7444666..64133e6 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/ListBox.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/ListBox.java @@ -9,7 +9,6 @@ import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableBooleanValue; import javafx.beans.value.ObservableValue; -import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Cursor; @@ -27,24 +26,24 @@ import javafx.util.Duration; public class ListBox extends ScrollPane { private boolean editable; - + private VBox main; private VBox listContainer; - + private Runnable listChangeListener; - + public ListBox(boolean editable) { this.editable = editable; - + this.setFitToHeight(true); this.setFitToWidth(true); - + this.main = new VBox(); this.main.setPadding(new Insets(0, 15, 0, 15)); this.listContainer = new VBox(); this.main.getChildren().add(this.listContainer); - + if (this.editable) { final HBox addListItemBox = new HBox(); @@ -58,59 +57,44 @@ public class ListBox extends ScrollPane addListItemBox.setCursor(Cursor.HAND); // Fade and opacity addListItemBox.setOpacity(0.4); - addListItemBox.setOnMouseEntered(new EventHandler() - { - @Override - public void handle(MouseEvent e) - { - FadeTransition transition = new FadeTransition(Duration.millis(200), addListItemBox); - transition.setFromValue(0.4); - transition.setToValue(1.0); - transition.play(); - } + addListItemBox.setOnMouseEntered((MouseEvent e) -> { + FadeTransition transition = new FadeTransition(Duration.millis(200), addListItemBox); + transition.setFromValue(0.4); + transition.setToValue(1.0); + transition.play(); }); - addListItemBox.setOnMouseExited(new EventHandler() - { - @Override - public void handle(MouseEvent e) - { - FadeTransition transition = new FadeTransition(Duration.millis(200), addListItemBox); - transition.setFromValue(1.0); - transition.setToValue(0.4); - transition.play(); - } + addListItemBox.setOnMouseExited((MouseEvent e) -> { + FadeTransition transition = new FadeTransition(Duration.millis(200), addListItemBox); + transition.setFromValue(1.0); + transition.setToValue(0.4); + transition.play(); }); - addListItemBox.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent e) - { - ListBox.this.listContainer.getChildren().add(new ListBoxItem("", ListBox.this.editable)); - } + addListItemBox.setOnMouseClicked((MouseEvent e) -> { + ListBox.this.listContainer.getChildren().add(new ListBoxItem("", ListBox.this.editable)); }); } this.main.getChildren().add(addListItemBox); } - + this.setContent(this.main); } - + public void updateList(Map content) { 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())); } - + public void setListChangeListener(Runnable listener) { this.listChangeListener = listener; } - + public Map getList() { Map list = new HashMap(); - for(Node child : this.listContainer.getChildren()) + for (Node child : this.listContainer.getChildren()) { ListBoxItem item = (ListBoxItem) child; if (item.getText() != null && !item.getText().isEmpty()) @@ -118,22 +102,17 @@ public class ListBox extends ScrollPane } return list; } - + private class ListBoxItem extends HBox { private ListCheckbox checkbox; private TextField field; - + public ListBoxItem(String text, boolean editable) { - ChangeListener change = new ChangeListener() - { - @Override - public void changed(ObservableValue ov, Object oldValue, Object newValue) - { - if (ListBox.this.listChangeListener != null) - ListBox.this.listChangeListener.run(); - } + ChangeListener change = (ObservableValue ov, Object oldValue, Object newValue) -> { + if (ListBox.this.listChangeListener != null) + ListBox.this.listChangeListener.run(); }; this.checkbox = new ListCheckbox(); this.checkbox.checkedProperty().addListener(change); @@ -147,87 +126,48 @@ public class ListBox extends ScrollPane else { this.field.setCursor(Cursor.HAND); - this.field.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent e) - { - ListBoxItem.this.setChecked(!ListBoxItem.this.isChecked()); - } + this.field.setOnMouseClicked((MouseEvent e) -> { + ListBoxItem.this.setChecked(!ListBoxItem.this.isChecked()); }); } this.getChildren().add(this.field); } - + public String getText() { return this.field.getText(); } - + public ListBoxItem setChecked(boolean checked) { this.checkbox.setChecked(checked); return this; } + public boolean isChecked() { return this.checkbox.isChecked(); } - + private class ListCheckbox extends VBox { private BooleanProperty checked = new SimpleBooleanProperty(); - + public ListCheckbox() { this.setId("imageButton"); this.setAlignment(Pos.CENTER); this.setCursor(Cursor.HAND); this.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/Checkbox-unchecked.png"))); - - /*this.setOpacity(0.4); - this.setOnMouseEntered(new EventHandler() - { - @Override - public void handle(MouseEvent e) - { - 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() - { - @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() - { - @Override - public void handle(MouseEvent e) - { - if (ListCheckbox.this.isChecked()) - ListCheckbox.this.setChecked(false); - else - ListCheckbox.this.setChecked(true); - } + + this.setOnMouseClicked((MouseEvent e) -> { + if (ListCheckbox.this.isChecked()) + ListCheckbox.this.setChecked(false); + else + ListCheckbox.this.setChecked(true); }); } - + public void setChecked(boolean checked) { this.checked.set(checked); @@ -237,10 +177,12 @@ public class ListBox extends ScrollPane else ListCheckbox.this.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/Checkbox-unchecked.png"))); } + public ObservableBooleanValue checkedProperty() { return this.checked; } + public boolean isChecked() { return this.checked.get(); diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/NoteColorSelector.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/NoteColorSelector.java index 1aa3341..1addea2 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/NoteColorSelector.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/NoteColorSelector.java @@ -8,7 +8,6 @@ import com.madeorsk.smartnotes.notes.Note.NoteColor; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ObservableValue; -import javafx.event.EventHandler; import javafx.scene.Cursor; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; @@ -20,12 +19,12 @@ public class NoteColorSelector extends HBox { private List noteColors = new ArrayList(); private ObjectProperty selectedColor = new SimpleObjectProperty(); - + public NoteColorSelector() { this.setSpacing(10); } - + public void addColor(NoteColor color) { this.noteColors.add(color); @@ -34,29 +33,32 @@ public class NoteColorSelector extends HBox else this.updateBox(); } - + public void setSelectedColor(NoteColor color) { this.selectedColor.set(color); this.updateBox(); } + public NoteColor getSelectedColor() { return this.selectedColor.getValue(); } + public ObservableValue selectedColorProperty() { return this.selectedColor; } - + private void updateBox() { this.getChildren().clear(); - for(final NoteColor color : this.noteColors) + for (final NoteColor color : this.noteColors) { Canvas canvas = new Canvas(); canvas.setCursor(Cursor.HAND); - canvas.setHeight(50); canvas.setWidth(50); + canvas.setHeight(50); + canvas.setWidth(50); GraphicsContext gc = canvas.getGraphicsContext2D(); if (color.equals(this.getSelectedColor())) { @@ -65,16 +67,11 @@ public class NoteColorSelector extends HBox } gc.setFill(color.getColor()); gc.fillOval(3, 3, 44, 44); - - canvas.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) - { - NoteColorSelector.this.setSelectedColor(color); - } + + canvas.setOnMouseClicked((MouseEvent event) -> { + NoteColorSelector.this.setSelectedColor(color); }); - + this.getChildren().add(canvas); } } diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/NotesExplorer.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/NotesExplorer.java index 12bbb91..7466438 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/NotesExplorer.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/NotesExplorer.java @@ -10,7 +10,6 @@ import com.madeorsk.smartnotes.paths.NotePath; import com.madeorsk.smartnotes.paths.Path; import javafx.animation.FadeTransition; -import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Cursor; @@ -25,13 +24,11 @@ import javafx.util.Duration; public class NotesExplorer extends VBox { private SavesManager saves; - /*private Thread saveThread; - private Thread nextSaveThread;*/ private Map notes; - + private HBox titleBox; private FolderPath currentFolder; - + public NotesExplorer() { this.saves = new SavesManager(); @@ -45,24 +42,24 @@ public class NotesExplorer extends VBox } this.updateList(this.genRoot()); } - + private void updateList(FolderPath folder) { this.getChildren().clear(); this.getChildren().add(this.titleBox); - + this.setSpacing(50); - + this.currentFolder = folder; - + VBox notesList = new VBox(); notesList.setPadding(new Insets(0, 20, 0, 20)); notesList.setSpacing(15); this.getChildren().add(notesList); - + if (folder.getParent() != null) notesList.getChildren().add(new ExplorerItem(true, folder.getParent().setName("Previous folder"), this).setFolderIcon("/com/madeorsk/smartnotes/res/ReturnIcon.png")); - + for (Path p : folder.getContent()) { if (p.isFolder()) @@ -73,48 +70,33 @@ public class NotesExplorer extends VBox notesList.getChildren().add(new ExplorerItem(false, this.notes.get(((NotePath) p).getNoteId()), this)); } } - + final HBox addNoteBox = new HBox(); { addNoteBox.setCursor(Cursor.HAND); addNoteBox.setOpacity(0.4); - addNoteBox.setOnMouseEntered(new EventHandler() - { - @Override - public void handle(MouseEvent e) - { - FadeTransition transition = new FadeTransition(Duration.millis(200), addNoteBox); - transition.setFromValue(0.4); - transition.setToValue(1.0); - transition.play(); - } + addNoteBox.setOnMouseEntered((MouseEvent e) -> { + FadeTransition transition = new FadeTransition(Duration.millis(200), addNoteBox); + transition.setFromValue(0.4); + transition.setToValue(1.0); + transition.play(); }); - addNoteBox.setOnMouseExited(new EventHandler() - { - @Override - public void handle(MouseEvent e) - { - FadeTransition transition = new FadeTransition(Duration.millis(200), addNoteBox); - transition.setFromValue(1.0); - transition.setToValue(0.4); - transition.play(); - } + addNoteBox.setOnMouseExited((MouseEvent e) -> { + FadeTransition transition = new FadeTransition(Duration.millis(200), addNoteBox); + transition.setFromValue(1.0); + transition.setToValue(0.4); + transition.play(); }); - addNoteBox.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) - { - 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); - note.save(NotesExplorer.this.saves, id); - } + addNoteBox.setOnMouseClicked((MouseEvent event) -> { + 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); + note.save(NotesExplorer.this.saves, id); }); - + addNoteBox.setAlignment(Pos.CENTER_LEFT); addNoteBox.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/AddIcon.png"))); addNoteBox.setSpacing(10); @@ -124,22 +106,22 @@ public class NotesExplorer extends VBox } notesList.getChildren().add(addNoteBox); } - + private FolderPath genRoot() { FolderPath root = new FolderPath("/", null); - for(int key : this.notes.keySet()) + for (int key : this.notes.keySet()) { Note note = this.notes.get(key); if (note.getPaths().isEmpty()) root.addPath(new NotePath(key)); else { - for(String path : note.getPaths()) + for (String path : note.getPaths()) { FolderPath putIn = root; 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)) putIn = putIn.getFolder(folderString); @@ -156,15 +138,17 @@ public class NotesExplorer extends VBox } return root; } - + public void goToFolder(FolderPath path) { this.updateList(this.getUpdatedFolder(path)); } + public void updateCurrentFolder() { this.updateList(this.getUpdatedFolder(this.currentFolder)); } + private FolderPath getUpdatedFolder(FolderPath path) { if (path.getParent() == null) @@ -178,10 +162,10 @@ public class NotesExplorer extends VBox return updatedFolder; } } - + 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)) { @@ -190,45 +174,25 @@ public class NotesExplorer extends VBox } } } - + public void requestSave(final Note note) { - /*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(); - }*/ + for (int key : NotesExplorer.this.notes.keySet()) + if (NotesExplorer.this.notes.get(key).equals(note)) + note.save(NotesExplorer.this.saves, key); } + public void requestLoad(Note note) { for (int key : this.notes.keySet()) if (this.notes.get(key).equals(note)) note.load(this.saves, key); } - + private int getNextId() { int i = 0; - for(int key : notes.keySet()) + for (int key : notes.keySet()) { if (key != i) return i; @@ -236,7 +200,7 @@ public class NotesExplorer extends VBox } return notes.keySet().size(); } - + public void close() { this.saves.saveIndex(notes); diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/SavesManager.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/SavesManager.java index 4ac0c7f..d2eb354 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/SavesManager.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/SavesManager.java @@ -17,29 +17,30 @@ public class SavesManager { private static final String KEY = "Vivre et grandir à travers le commun"; private static final File SAVE_FOLDER = new File("saves"); - + public SavesManager() { if (!SAVE_FOLDER.exists()) SAVE_FOLDER.mkdirs(); } - + public void saveIndex(Map notes) { File indexFile = new File(SAVE_FOLDER, "index"); if (indexFile.exists()) indexFile.delete(); - + if (!notes.isEmpty()) { String indexString = ""; - for(int key : notes.keySet()) + for (int key : notes.keySet()) indexString += key + ":" + notes.get(key).getClass().getName() + "\n"; - + indexString = indexString.substring(0, indexString.length() - 1); this.writeFile(indexFile, indexString); } } + public Map loadIndex() { File indexFile = new File(SAVE_FOLDER, "index"); @@ -48,7 +49,7 @@ public class SavesManager Map notes = new HashMap(); String indexString = this.readFile(indexFile); String[] notesString = indexString.split("\n"); - for(String noteString : notesString) + for (String noteString : notesString) { String[] decomposed = noteString.split(":"); if (decomposed.length == 2) @@ -70,12 +71,11 @@ public class SavesManager else return new HashMap(); } - + public File getSaveFile(int id) { return new File(SAVE_FOLDER, id + ""); } - public String readFile(File file) { try @@ -87,7 +87,7 @@ public class SavesManager while ((n = fis.read(buffer)) > 0) baos.write(buffer, 0, n); fis.close(); - + ByteArrayOutputStream stringBaos = new ByteArrayOutputStream(); GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(this.byteFpeDecryption(baos.toByteArray(), KEY))); while ((n = gzip.read(buffer)) > 0) @@ -110,7 +110,7 @@ public class SavesManager gzip.write(content.getBytes(), 0, content.getBytes().length); gzip.close(); byte[] bytes = baos.toByteArray(); - + FileOutputStream fos = new FileOutputStream(file); fos.write(this.byteFpeEncryption(bytes, KEY)); fos.flush(); @@ -121,41 +121,38 @@ public class SavesManager e.printStackTrace(); } } - - private byte[] byteFpeEncryption(byte[] bytes, String key) + + private static String createCipherFromKey(String key, int bytesLength) { String cipher = ""; int i = 0; - while (cipher.getBytes().length < bytes.length) + while (cipher.getBytes().length < bytesLength) { cipher += key.getBytes()[i]; i++; if (i >= key.getBytes().length) i = 0; } - + return cipher; + } + private byte[] byteFpeEncryption(byte[] bytes, String key) + { + String cipher = createCipherFromKey(key, 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]); - + return encryptedBytes; } private byte[] byteFpeDecryption(byte[] bytes, String key) { - String cipher = ""; - int i = 0; - while (cipher.getBytes().length < bytes.length) - { - cipher += key.getBytes()[i]; - i++; - if (i >= key.getBytes().length) - i = 0; - } - + String cipher = createCipherFromKey(key, 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]); - + return decryptedBytes; } } diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/SmartNotes.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/SmartNotes.java index b0a4a7f..2429bef 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/SmartNotes.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/SmartNotes.java @@ -13,10 +13,8 @@ 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; -import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.ScrollPane; import javafx.scene.layout.Region; @@ -28,8 +26,8 @@ import javafx.stage.WindowEvent; 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) { System.out.println("Starting SmartNotes..."); @@ -37,50 +35,45 @@ public class SmartNotes extends Application launch(); System.out.println("SmartNotes closed."); } - + public static SmartNotes instance; public static WebView webView; private Scene scene; private VBox root; private NotesExplorer explorer; - + @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) + 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()); - } - + 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"); - webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, State oldValue, State newValue) + webView.getEngine().getLoadWorker().stateProperty().addListener((ObservableValue ov, State oldValue, State newValue) -> { + if (newValue == State.SUCCEEDED) { - if (newValue == State.SUCCEEDED) - { - Document doc = webView.getEngine().getDocument(); - Element styleNode = doc.createElement("style"); - 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")); - } + Document doc = webView.getEngine().getDocument(); + Element styleNode = doc.createElement("style"); + Text styleContent = doc.createTextNode(css); + styleNode.appendChild(styleContent); + doc.getDocumentElement().getElementsByTagName("head").item(0).appendChild(styleNode); } }); - + + // 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 Bold.ttf"), 10); Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Sans Italic.ttf"), 10); @@ -91,51 +84,44 @@ public class SmartNotes extends Application Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Bold Italic.ttf"), 10); Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Code.ttf"), 10); Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Code Italic.ttf"), 10); - + this.root = new VBox(); this.root.setStyle("-fx-background-color: #282828;"); - + this.explorer = new NotesExplorer(); ScrollPane scrollPane = new ScrollPane(this.explorer); - scrollPane.setFitToHeight(true); scrollPane.setFitToWidth(true); + scrollPane.setFitToHeight(true); + scrollPane.setFitToWidth(true); this.root.getChildren().add(scrollPane); - + this.scene = new Scene(this.root, 800, 600); this.scene.getStylesheets().add("/com/madeorsk/smartnotes/style.css"); - - stage.setOnCloseRequest(new EventHandler() - { - @Override - public void handle(WindowEvent e) - { - SmartNotes.this.explorer.close(); - } + + stage.setOnCloseRequest((WindowEvent e) -> { + SmartNotes.this.explorer.close(); }); - + stage.setScene(this.scene); stage.setTitle("SmartNotes " + version); - stage.setOnCloseRequest(new EventHandler() - { - @Override - public void handle(WindowEvent event) - { - SmartNotes.this.onStop(); - } + stage.setOnCloseRequest((WindowEvent event) -> { + SmartNotes.this.onStop(); }); stage.show(); } - + public void setContent(Region region) { this.setContent(region, false); } + public void setContent(Region region, boolean useScrollPane) { this.root.getChildren().clear(); if (useScrollPane) { ScrollPane scrollPane = new ScrollPane(region); - scrollPane.setFitToHeight(true); scrollPane.setFitToWidth(true); + scrollPane.setFitToHeight(true); + scrollPane.setFitToWidth(true); this.root.getChildren().add(scrollPane); } else @@ -144,7 +130,7 @@ public class SmartNotes extends Application this.root.getChildren().add(region); } } - + private void onStop() { try @@ -157,7 +143,7 @@ public class SmartNotes extends Application } Platform.exit(); } - + public class GlobalKeyListener implements NativeKeyListener { // CTRL : 29 | ALT : 56 | n : 49 @Override @@ -165,13 +151,16 @@ public class SmartNotes extends Application { //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/smartnotes/src/main/java/com/madeorsk/smartnotes/TypeSelector.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/TypeSelector.java index f27c60c..fa064e4 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/TypeSelector.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/TypeSelector.java @@ -5,7 +5,6 @@ import com.madeorsk.smartnotes.notes.Note; import com.madeorsk.smartnotes.notes.TextNote; import javafx.animation.FadeTransition; -import javafx.event.EventHandler; import javafx.scene.Cursor; import javafx.scene.image.Image; import javafx.scene.image.ImageView; @@ -25,18 +24,14 @@ public class TypeSelector extends HBox textNoteItem.setSelected(true); else { - textNoteItem.setOnMouseClicked(new EventHandler() - { - public void handle(MouseEvent event) - { - Note textNote = new TextNote(); - textNote.setName(note.getName()); - textNote.setTextContent(note.getTextContent()); - textNote.setNoteColor(note.getNoteColor()); - explorer.replaceNote(note, textNote); - explorer.requestSave(textNote); - SmartNotes.instance.setContent(textNote.getEditBox(explorer)); - } + textNoteItem.setOnMouseClicked((MouseEvent event) -> { + Note textNote = new TextNote(); + textNote.setName(note.getName()); + textNote.setTextContent(note.getTextContent()); + textNote.setNoteColor(note.getNoteColor()); + explorer.replaceNote(note, textNote); + explorer.requestSave(textNote); + SmartNotes.instance.setContent(textNote.getEditBox(explorer)); }); } } @@ -47,86 +42,67 @@ public class TypeSelector extends HBox listNoteItem.setSelected(true); else { - listNoteItem.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) - { - Note listNote = new ListNote(); - listNote.setName(note.getName()); - listNote.setTextContent(note.getTextContent()); - listNote.setNoteColor(note.getNoteColor()); - explorer.replaceNote(note, listNote); - explorer.requestSave(listNote); - SmartNotes.instance.setContent(listNote.getEditBox(explorer)); - } + listNoteItem.setOnMouseClicked((MouseEvent event) -> { + Note listNote = new ListNote(); + listNote.setName(note.getName()); + listNote.setTextContent(note.getTextContent()); + listNote.setNoteColor(note.getNoteColor()); + explorer.replaceNote(note, listNote); + explorer.requestSave(listNote); + SmartNotes.instance.setContent(listNote.getEditBox(explorer)); }); } } this.getChildren().add(listNoteItem); TypeItem imageNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/ImageNoteChoice.png"); { - - } + } //TODO Next versions. this.getChildren().add(imageNoteItem); TypeItem soundNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/SoundNoteChoice.png"); { - - } + } //TODO Next versions. this.getChildren().add(soundNoteItem); TypeItem videoNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/VideoNoteChoice.png"); { - - } + } //TODO Next versions. this.getChildren().add(videoNoteItem); TypeItem positionNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/PositionNoteChoice.png"); { - - } + } //TODO Next versions. this.getChildren().add(positionNoteItem); } - + private class TypeItem extends VBox { private boolean selected; - + public TypeItem(String typeIconPath) { this.setId("imageButton"); this.setCursor(Cursor.HAND); this.getChildren().add(new ImageView(new Image(typeIconPath))); - + this.setOpacity(0.4); - this.setOnMouseEntered(new EventHandler() - { - @Override - public void handle(MouseEvent e) + this.setOnMouseEntered((MouseEvent e) -> { + if (!TypeItem.this.isSelected()) { - if (!TypeItem.this.isSelected()) - { - FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this); - transition.setFromValue(0.4); - transition.setToValue(1.0); - transition.play(); - } + FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this); + transition.setFromValue(0.4); + transition.setToValue(1.0); + transition.play(); } }); - this.setOnMouseExited(new EventHandler() - { - @Override - public void handle(MouseEvent e) + this.setOnMouseExited((MouseEvent e) -> { + if (!TypeItem.this.isSelected()) { - if (!TypeItem.this.isSelected()) - { - FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this); - transition.setFromValue(1.0); - transition.setToValue(0.4); - transition.play(); - } + FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this); + transition.setFromValue(1.0); + transition.setToValue(0.4); + transition.play(); } }); } - + public void setSelected(boolean selected) { this.selected = selected; @@ -140,6 +116,7 @@ public class TypeSelector extends HBox transition.play(); } } + public boolean isSelected() { return this.selected; diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/Utils.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/Utils.java index cf07e1f..f87239f 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/Utils.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/Utils.java @@ -10,14 +10,14 @@ public class Utils { private static Parser parser = Parser.builder().build(); private static HtmlRenderer htmlRenderer = HtmlRenderer.builder().build(); - + public static String loadText(String path) { try { InputStream is = Utils.class.getResourceAsStream(path); String result = ""; - byte[] buffer = new byte[1024*8]; + byte[] buffer = new byte[1024 * 8]; while (is.read(buffer) > 0) result += new String(buffer); return result.trim(); @@ -28,7 +28,7 @@ public class Utils return null; } } - + public static String markdownToHtml(String markdown) { return htmlRenderer.render(parser.parse(markdown)); diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/ListNote.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/ListNote.java index 2473af7..e6c6225 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/ListNote.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/ListNote.java @@ -33,13 +33,13 @@ public class ListNote extends Note { private ListBox listBox; private boolean loading = false; - + public ListNote() { this.setName("Text_" + Calendar.getInstance().get(Calendar.YEAR) + "." + Calendar.getInstance().get(Calendar.MONTH) + "." + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "-" + Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + ":" + Calendar.getInstance().get(Calendar.MINUTE)); this.listBox = new ListBox(false); } - + @Override public VBox getViewBox(final NotesExplorer explorer) { @@ -48,136 +48,87 @@ public class ListNote extends Note this.listBox.updateList(listBoxMap); VBox box = new VBox(); box.setFillWidth(true); - + final Label nameField = new Label(); - + HBox titleBox = new HBox(); { titleBox.setPadding(new Insets(10, 0, 0, 0)); - + VBox returnButton = new VBox(); returnButton.setId("imageButton"); returnButton.setCursor(Cursor.HAND); returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png"))); - returnButton.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) - { - explorer.updateCurrentFolder(); - SmartNotes.instance.setContent(explorer, true); - } + returnButton.setOnMouseClicked((MouseEvent event) -> { + explorer.updateCurrentFolder(); + SmartNotes.instance.setContent(explorer, true); }); titleBox.getChildren().add(returnButton); - + VBox editButton = new VBox(); editButton.setId("imageButton"); editButton.setCursor(Cursor.HAND); editButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/EditIcon.png"))); - editButton.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) - { - SmartNotes.instance.setContent(ListNote.this.getEditBox(explorer)); - } + editButton.setOnMouseClicked((MouseEvent event) -> { + SmartNotes.instance.setContent(ListNote.this.getEditBox(explorer)); }); HBox buttonsBox = new HBox(); buttonsBox.getChildren().add(editButton); buttonsBox.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); titleBox.getChildren().add(buttonsBox); - + NoteColorSelector colorSelector = new NoteColorSelector(); colorSelector.setAlignment(Pos.CENTER); 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.selectedColorProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, NoteColor oldValue, NoteColor newValue) - { - 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); - } + colorSelector.selectedColorProperty().addListener((ObservableValue ov, NoteColor oldValue, NoteColor newValue) -> { + 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); } box.getChildren().add(titleBox); - + // NAME FIELD { nameField.prefWidthProperty().bind(box.widthProperty()); nameField.setAlignment(Pos.CENTER); 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.textProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, String oldValue, String newValue) - { - ListNote.this.setName(newValue); - explorer.requestSave(ListNote.this); - } + nameField.textProperty().addListener((ObservableValue ov, String oldValue, String newValue) -> { + ListNote.this.setName(newValue); + explorer.requestSave(ListNote.this); }); } box.getChildren().add(nameField); - - // - + HBox separator = new HBox(); separator.setId("separator"); separator.setPrefHeight(5); - + 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)); 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() - { - @Override - public void changed(ObservableValue 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); - + this.listBox.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2)); - this.listBox.setListChangeListener(new Runnable() - { - @Override - public void run() - { - if (!ListNote.this.loading) - explorer.requestSave(ListNote.this); - } + this.listBox.setListChangeListener(() -> { + if (!ListNote.this.loading) + explorer.requestSave(ListNote.this); }); box.getChildren().add(this.listBox); - + return box; } - + @Override public VBox getEditBox(final NotesExplorer explorer) { @@ -186,151 +137,126 @@ public class ListNote extends Note this.listBox.updateList(listBoxMap); VBox box = new VBox(); box.setFillWidth(true); - + final TextField nameField = new TextField(); - + HBox titleBox = new HBox(); { titleBox.setPadding(new Insets(10, 0, 0, 0)); - + VBox returnButton = new VBox(); returnButton.setId("imageButton"); returnButton.setCursor(Cursor.HAND); returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png"))); - returnButton.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) - { - explorer.updateCurrentFolder(); - SmartNotes.instance.setContent(explorer, true); - } + returnButton.setOnMouseClicked((MouseEvent event) -> { + explorer.updateCurrentFolder(); + SmartNotes.instance.setContent(explorer, true); }); titleBox.getChildren().add(returnButton); - + TypeSelector typeSelector = new TypeSelector(explorer, this); typeSelector.setAlignment(Pos.CENTER); typeSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); titleBox.getChildren().add(typeSelector); - + NoteColorSelector colorSelector = new NoteColorSelector(); colorSelector.setAlignment(Pos.CENTER); 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.selectedColorProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, NoteColor oldValue, NoteColor newValue) - { - 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); - } + colorSelector.selectedColorProperty().addListener((ObservableValue ov, NoteColor oldValue, NoteColor newValue) -> { + 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); } box.getChildren().add(titleBox); - + // NAME FIELD { nameField.setAlignment(Pos.CENTER); 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.textProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, String oldValue, String newValue) - { - ListNote.this.setName(newValue); - explorer.requestSave(ListNote.this); - } + nameField.textProperty().addListener((ObservableValue ov, String oldValue, String newValue) -> { + ListNote.this.setName(newValue); + explorer.requestSave(ListNote.this); }); } box.getChildren().add(nameField); - + // - + HBox separator = new HBox(); separator.setId("separator"); separator.setPrefHeight(5); - + 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() - { - @Override - public void changed(ObservableValue ov, String oldValue, String newValue) - { - ListNote.this.setTextContent(newValue); - explorer.requestSave(ListNote.this); - } + textArea.textProperty().addListener((ObservableValue 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()); - } + Platform.runLater(() -> { + textArea.requestFocus(); + textArea.positionCaret(textArea.getLength()); }); } box.getChildren().add(textArea); - + box.getChildren().add(separator); - + this.listBox.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()).subtract(separator.heightProperty()).divide(2)); - this.listBox.setListChangeListener(new Runnable() - { - @Override - public void run() - { - if (!ListNote.this.loading) - explorer.requestSave(ListNote.this); - } + this.listBox.setListChangeListener(() -> { + if (!ListNote.this.loading) + explorer.requestSave(ListNote.this); }); box.getChildren().add(this.listBox); - + return box; } - + @Override public void save(SavesManager saves, int id) { String fileContent = this.getName() + "\n" + this.getNoteColor().name() + "\n"; Map list = this.listBox.getList(); 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"; saves.writeFile(saves.getSaveFile(id), fileContent + this.getTextContent()); } + @Override public boolean load(SavesManager saves, int id) { if (saves.getSaveFile(id).exists()) { this.loading = true; - + String saved = saves.readFile(saves.getSaveFile(id)); - + int separatorIndex = saved.indexOf('\n'); this.setName(saved.substring(0, separatorIndex)); saved = saved.substring(separatorIndex + 1); - + separatorIndex = saved.indexOf('\n'); this.setNoteColor(NoteColor.valueOf(saved.substring(0, separatorIndex))); saved = saved.substring(separatorIndex + 1); - + separatorIndex = saved.indexOf('\n'); int listSize = Integer.parseUnsignedInt(saved.substring(0, separatorIndex), 16); Map list = new HashMap(); - for(int i = 0; i < listSize; i++) + for (int i = 0; i < listSize; i++) { saved = saved.substring(separatorIndex + 1); separatorIndex = saved.indexOf('\n'); @@ -339,18 +265,19 @@ public class ListNote extends Note list.put(listItemString.substring(0, listItemSeparator), Boolean.parseBoolean(listItemString.substring(listItemSeparator + 1))); } this.listBox.updateList(list); - + if (separatorIndex < saved.length() - 1) this.setTextContent(saved.substring(separatorIndex + 1)); else this.setTextContent(""); - + this.loading = false; return true; } else return false; } + @Override public void delete(SavesManager saves, int id) { diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/Note.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/Note.java index ebf6ab7..8550c14 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/Note.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/Note.java @@ -17,58 +17,65 @@ public abstract class Note implements SavableNote YELLOW(212, 208, 97), RED(214, 102, 90), GREEN(100, 181, 106); - + private double r; private double g; private double b; + NoteColor(double red, double green, double blue) { this.r = red; this.g = green; this.b = blue; } + 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); } } - + private String name; private String textContent; private NoteColor color = NoteColor.WHITE; protected List paths = new ArrayList(); - + public void setName(String name) { this.name = name; } + public String getName() { return this.name; } - + public void setNoteColor(NoteColor color) { this.color = color; } + public NoteColor getNoteColor() { return this.color; } + public List getPaths() { return this.paths; } - + public void setTextContent(String content) { this.textContent = content; this.updatePaths(); } + public String getTextContent() { return this.textContent; } + private void updatePaths() { this.paths.clear(); @@ -79,19 +86,20 @@ public abstract class Note implements SavableNote { String[] lines = text.split("\n"); String lastLine = lines[lines.length - 1]; - for(String word : lastLine.split(" ")) + for (String word : lastLine.split(" ")) if (word.startsWith("#") && !word.equals("#")) this.paths.add(word); } else { - for(String word : text.split(" ")) + for (String word : text.split(" ")) if (word.startsWith("#") && !word.equals("#")) this.paths.add(word); } } } - + public abstract VBox getViewBox(NotesExplorer explorer); + public abstract VBox getEditBox(NotesExplorer explorer); } diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/TextNote.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/TextNote.java index ee18145..7d0ea54 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/TextNote.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/notes/TextNote.java @@ -32,200 +32,164 @@ public class TextNote extends Note { this.setName("Text_" + Calendar.getInstance().get(Calendar.YEAR) + "." + Calendar.getInstance().get(Calendar.MONTH) + "." + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "-" + Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + ":" + Calendar.getInstance().get(Calendar.MINUTE)); } - + @Override public VBox getViewBox(final NotesExplorer explorer) { VBox box = new VBox(); box.setFillWidth(true); - + final Label nameField = new Label(); - + HBox titleBox = new HBox(); { titleBox.setPadding(new Insets(10, 0, 0, 0)); - + VBox returnButton = new VBox(); returnButton.setId("imageButton"); returnButton.setCursor(Cursor.HAND); returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png"))); - returnButton.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) - { - explorer.updateCurrentFolder(); - SmartNotes.instance.setContent(explorer, true); - } + returnButton.setOnMouseClicked((MouseEvent event) -> { + explorer.updateCurrentFolder(); + SmartNotes.instance.setContent(explorer, true); }); titleBox.getChildren().add(returnButton); - + VBox editButton = new VBox(); editButton.setId("imageButton"); editButton.setCursor(Cursor.HAND); editButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/EditIcon.png"))); - editButton.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) - { - SmartNotes.instance.setContent(TextNote.this.getEditBox(explorer)); - } + editButton.setOnMouseClicked((MouseEvent event) -> { + SmartNotes.instance.setContent(TextNote.this.getEditBox(explorer)); }); HBox buttonsBox = new HBox(); buttonsBox.getChildren().add(editButton); buttonsBox.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); titleBox.getChildren().add(buttonsBox); - + NoteColorSelector colorSelector = new NoteColorSelector(); colorSelector.setAlignment(Pos.CENTER); 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.selectedColorProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, NoteColor oldValue, NoteColor newValue) - { - 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); - } + colorSelector.selectedColorProperty().addListener((ObservableValue ov, NoteColor oldValue, NoteColor newValue) -> { + 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); } box.getChildren().add(titleBox); - + // NAME FIELD { nameField.prefWidthProperty().bind(box.widthProperty()); nameField.setAlignment(Pos.CENTER); 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.textProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, String oldValue, String newValue) - { - TextNote.this.setName(newValue); - explorer.requestSave(TextNote.this); - } + nameField.textProperty().addListener((ObservableValue ov, String oldValue, String newValue) -> { + TextNote.this.setName(newValue); + explorer.requestSave(TextNote.this); }); } box.getChildren().add(nameField); - + SmartNotes.webView.getEngine().loadContent(Utils.markdownToHtml(this.getTextContent())); SmartNotes.webView.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty())); box.getChildren().add(SmartNotes.webView); - + return box; } - + @Override public VBox getEditBox(final NotesExplorer explorer) { VBox box = new VBox(); box.setFillWidth(true); - + final TextField nameField = new TextField(); - + HBox titleBox = new HBox(); { titleBox.setPadding(new Insets(10, 0, 0, 0)); - + VBox returnButton = new VBox(); returnButton.setId("imageButton"); returnButton.setCursor(Cursor.HAND); returnButton.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/ReturnIcon.png"))); - returnButton.setOnMouseClicked(new EventHandler() - { - @Override - public void handle(MouseEvent event) - { - explorer.updateCurrentFolder(); - SmartNotes.instance.setContent(explorer, true); - } + returnButton.setOnMouseClicked((MouseEvent event) -> { + explorer.updateCurrentFolder(); + SmartNotes.instance.setContent(explorer, true); }); titleBox.getChildren().add(returnButton); - + TypeSelector typeSelector = new TypeSelector(explorer, this); typeSelector.setAlignment(Pos.CENTER); typeSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); titleBox.getChildren().add(typeSelector); - + NoteColorSelector colorSelector = new NoteColorSelector(); colorSelector.setAlignment(Pos.CENTER); 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.selectedColorProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, NoteColor oldValue, NoteColor newValue) - { - 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); - } + colorSelector.selectedColorProperty().addListener((ObservableValue ov, NoteColor oldValue, NoteColor newValue) -> { + 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); } box.getChildren().add(titleBox); - + // NAME FIELD { nameField.setAlignment(Pos.CENTER); 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.textProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, String oldValue, String newValue) - { - TextNote.this.setName(newValue); - explorer.requestSave(TextNote.this); - } + nameField.textProperty().addListener((ObservableValue ov, String oldValue, String newValue) -> { + TextNote.this.setName(newValue); + explorer.requestSave(TextNote.this); }); } box.getChildren().add(nameField); - + final TextArea textArea = new TextArea(); { textArea.setId("text"); textArea.setWrapText(true); textArea.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty())); textArea.setText(this.getTextContent()); - textArea.textProperty().addListener(new ChangeListener() - { - @Override - public void changed(ObservableValue ov, String oldValue, String newValue) - { - TextNote.this.setTextContent(newValue); - explorer.requestSave(TextNote.this); - } + textArea.textProperty().addListener((ObservableValue ov, String oldValue, String newValue) -> { + TextNote.this.setTextContent(newValue); + explorer.requestSave(TextNote.this); }); - Platform.runLater(new Runnable() - { - @Override - public void run() - { - textArea.requestFocus(); - textArea.positionCaret(textArea.getLength()); - } + Platform.runLater(() -> { + textArea.requestFocus(); + textArea.positionCaret(textArea.getLength()); }); } box.getChildren().add(textArea); - + return box; } - + @Override public void save(SavesManager saves, int id) { saves.writeFile(saves.getSaveFile(id), this.getName() + "\n" + this.getNoteColor().name() + "\n" + this.getTextContent()); } + @Override public boolean load(SavesManager saves, int id) { @@ -246,6 +210,7 @@ public class TextNote extends Note else return false; } + @Override public void delete(SavesManager saves, int id) { diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/paths/FolderPath.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/paths/FolderPath.java index b562afe..11dec4c 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/paths/FolderPath.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/paths/FolderPath.java @@ -8,53 +8,57 @@ public class FolderPath implements Path private String name; private FolderPath parent; private List content = new ArrayList(); - + public FolderPath(String name, FolderPath parent) { this.name = name; this.parent = parent; } - + public void addPath(Path path) { this.content.add(path); } - + public FolderPath getFolder(String folderName) { - for(Path path : this.content) + for (Path path : this.content) if (path.isFolder()) if (((FolderPath) path).getName().equalsIgnoreCase(folderName)) return (FolderPath) path; return null; } + public boolean containsFolder(String folderName) { - for(Path path : this.content) + for (Path path : this.content) if (path.isFolder()) if (((FolderPath) path).getName().equalsIgnoreCase(folderName)) return true; return false; } - + public FolderPath setName(String name) { this.name = name; return this; } + public String getName() { return this.name; } + public FolderPath getParent() { return this.parent; } + public List getContent() { return this.content; } - + @Override public boolean isFolder() { diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/paths/NotePath.java b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/paths/NotePath.java index 7dc2a70..49200d5 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/paths/NotePath.java +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/paths/NotePath.java @@ -3,17 +3,17 @@ package com.madeorsk.smartnotes.paths; public class NotePath implements Path { private int noteId; - + public NotePath(int id) { this.noteId = id; } - + public int getNoteId() { return this.noteId; } - + @Override public boolean isFolder() { diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/style.css b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/style.css index 4919994..24632f9 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/style.css +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/style.css @@ -2,15 +2,18 @@ { -fx-background-color: #282828; } + .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-padding: 0; } + .scroll-bar .track { -fx-background-color: transparent; } + .scroll-bar .thumb { -fx-background-color: rgba(0, 0, 0, 0.15); @@ -21,20 +24,24 @@ { -fx-background-color: transparent; } + #nameField, #text, #noteItemName { -fx-text-fill: white; - -fx-font-family: "Courier Prime Sans"; + -fx-font-family: "Courier Prime Sans", monospace; -fx-font-size: 32px; } + #noteItemName { -fx-font-size: 24px; } + #text { -fx-font-size: 20px; } + #separator { -fx-background-color: rgba(0, 0, 0, 0.15); diff --git a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/webView.css b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/webView.css index ba21b90..5be1227 100644 --- a/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/webView.css +++ b/SmartNotes/smartnotes/src/main/java/com/madeorsk/smartnotes/webView.css @@ -2,18 +2,19 @@ body { background: #282828; color: white; - font-family: "Courier Prime Sans"; + font-family: "Courier Prime Sans", monospace; font-size: 20px; } code { display: inline-block; - font-family: "Courier Prime Code"; + font-family: "Courier Prime Code", monospace; background: rgba(0, 0, 0, 0.1); padding: 5px; border-radius: 5px; } + pre code { width: 100%; @@ -22,7 +23,7 @@ pre code blockquote { display: block; - font-family: "Courier Prime"; + font-family: "Courier Prime", monospace; padding: 0 10px 0 10px; border-left: solid rgba(0, 0, 0, 0.25) 2px; } \ No newline at end of file