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;
@ -16,31 +15,26 @@ public class ExplorerItem extends HBox
{ {
private boolean folder; private boolean folder;
private Object item; private Object item;
public ExplorerItem(boolean folder, Object item, final NotesExplorer explorer) public ExplorerItem(boolean folder, Object item, final NotesExplorer explorer)
{ {
this.folder = folder; this.folder = folder;
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));
}
} }
}); });
this.setAlignment(Pos.CENTER_LEFT); this.setAlignment(Pos.CENTER_LEFT);
this.setSpacing(10); this.setSpacing(10);
if (this.folder) if (this.folder)
{ {
FolderPath folderPath = (FolderPath) this.item; FolderPath folderPath = (FolderPath) this.item;
@ -58,17 +52,17 @@ public class ExplorerItem extends HBox
this.getChildren().add(noteNameLabel); this.getChildren().add(noteNameLabel);
} }
} }
public ExplorerItem setFolderIcon(String path) public ExplorerItem setFolderIcon(String path)
{ {
this.getChildren().clear(); this.getChildren().clear();
FolderPath folderPath = (FolderPath) this.item; FolderPath folderPath = (FolderPath) this.item;
this.getChildren().add(new ImageView(new Image(path))); this.getChildren().add(new ImageView(new Image(path)));
Label folderNameLabel = new Label(folderPath.getName()); Label folderNameLabel = new Label(folderPath.getName());
folderNameLabel.setId("noteItemName"); folderNameLabel.setId("noteItemName");
this.getChildren().add(folderNameLabel); this.getChildren().add(folderNameLabel);
return this; return this;
} }
} }

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;
@ -27,24 +26,24 @@ import javafx.util.Duration;
public class ListBox extends ScrollPane public class ListBox extends ScrollPane
{ {
private boolean editable; private boolean editable;
private VBox main; private VBox main;
private VBox listContainer; private VBox listContainer;
private Runnable listChangeListener; private Runnable listChangeListener;
public ListBox(boolean editable) public ListBox(boolean editable)
{ {
this.editable = editable; this.editable = editable;
this.setFitToHeight(true); this.setFitToHeight(true);
this.setFitToWidth(true); this.setFitToWidth(true);
this.main = new VBox(); this.main = new VBox();
this.main.setPadding(new Insets(0, 15, 0, 15)); this.main.setPadding(new Insets(0, 15, 0, 15));
this.listContainer = new VBox(); this.listContainer = new VBox();
this.main.getChildren().add(this.listContainer); this.main.getChildren().add(this.listContainer);
if (this.editable) if (this.editable)
{ {
final HBox addListItemBox = new HBox(); final HBox addListItemBox = new HBox();
@ -58,59 +57,44 @@ 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);
} }
this.setContent(this.main); this.setContent(this.main);
} }
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()));
} }
public void setListChangeListener(Runnable listener) public void setListChangeListener(Runnable listener)
{ {
this.listChangeListener = listener; this.listChangeListener = listener;
} }
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())
@ -118,22 +102,17 @@ public class ListBox extends ScrollPane
} }
return list; return list;
} }
private class ListBoxItem extends HBox private class ListBoxItem extends HBox
{ {
private ListCheckbox checkbox; private ListCheckbox checkbox;
private TextField field; private TextField field;
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,87 +126,48 @@ 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);
} }
public String getText() public String getText()
{ {
return this.field.getText(); return this.field.getText();
} }
public ListBoxItem setChecked(boolean checked) public ListBoxItem setChecked(boolean checked)
{ {
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();
} }
private class ListCheckbox extends VBox private class ListCheckbox extends VBox
{ {
private BooleanProperty checked = new SimpleBooleanProperty(); private BooleanProperty checked = new SimpleBooleanProperty();
public ListCheckbox() public ListCheckbox()
{ {
this.setId("imageButton"); this.setId("imageButton");
this.setAlignment(Pos.CENTER); this.setAlignment(Pos.CENTER);
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);
}
}); });
} }
public void setChecked(boolean checked) public void setChecked(boolean checked)
{ {
this.checked.set(checked); this.checked.set(checked);
@ -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;
@ -20,12 +19,12 @@ public class NoteColorSelector extends HBox
{ {
private List<NoteColor> noteColors = new ArrayList<NoteColor>(); private List<NoteColor> noteColors = new ArrayList<NoteColor>();
private ObjectProperty<NoteColor> selectedColor = new SimpleObjectProperty<NoteColor>(); private ObjectProperty<NoteColor> selectedColor = new SimpleObjectProperty<NoteColor>();
public NoteColorSelector() public NoteColorSelector()
{ {
this.setSpacing(10); this.setSpacing(10);
} }
public void addColor(NoteColor color) public void addColor(NoteColor color)
{ {
this.noteColors.add(color); this.noteColors.add(color);
@ -34,29 +33,32 @@ public class NoteColorSelector extends HBox
else else
this.updateBox(); this.updateBox();
} }
public void setSelectedColor(NoteColor color) public void setSelectedColor(NoteColor color)
{ {
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;
} }
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()))
{ {
@ -65,16 +67,11 @@ 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,13 +24,11 @@ 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;
private FolderPath currentFolder; private FolderPath currentFolder;
public NotesExplorer() public NotesExplorer()
{ {
this.saves = new SavesManager(); this.saves = new SavesManager();
@ -45,24 +42,24 @@ public class NotesExplorer extends VBox
} }
this.updateList(this.genRoot()); this.updateList(this.genRoot());
} }
private void updateList(FolderPath folder) private void updateList(FolderPath folder)
{ {
this.getChildren().clear(); this.getChildren().clear();
this.getChildren().add(this.titleBox); this.getChildren().add(this.titleBox);
this.setSpacing(50); this.setSpacing(50);
this.currentFolder = folder; this.currentFolder = folder;
VBox notesList = new VBox(); VBox notesList = new VBox();
notesList.setPadding(new Insets(0, 20, 0, 20)); notesList.setPadding(new Insets(0, 20, 0, 20));
notesList.setSpacing(15); notesList.setSpacing(15);
this.getChildren().add(notesList); this.getChildren().add(notesList);
if (folder.getParent() != null) if (folder.getParent() != null)
notesList.getChildren().add(new ExplorerItem(true, folder.getParent().setName("Previous folder"), this).setFolderIcon("/com/madeorsk/smartnotes/res/ReturnIcon.png")); notesList.getChildren().add(new ExplorerItem(true, folder.getParent().setName("Previous folder"), this).setFolderIcon("/com/madeorsk/smartnotes/res/ReturnIcon.png"));
for (Path p : folder.getContent()) for (Path p : folder.getContent())
{ {
if (p.isFolder()) 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)); notesList.getChildren().add(new ExplorerItem(false, this.notes.get(((NotePath) p).getNoteId()), this));
} }
} }
final HBox addNoteBox = new HBox(); final HBox addNoteBox = new HBox();
{ {
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)); NotesExplorer.this.saves.saveIndex(NotesExplorer.this.notes);
int id = NotesExplorer.this.getNextId(); note.save(NotesExplorer.this.saves, id);
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.setAlignment(Pos.CENTER_LEFT);
addNoteBox.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/AddIcon.png"))); addNoteBox.getChildren().add(new ImageView(new Image("/com/madeorsk/smartnotes/res/AddIcon.png")));
addNoteBox.setSpacing(10); addNoteBox.setSpacing(10);
@ -124,22 +106,22 @@ public class NotesExplorer extends VBox
} }
notesList.getChildren().add(addNoteBox); notesList.getChildren().add(addNoteBox);
} }
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);
@ -156,15 +138,17 @@ public class NotesExplorer extends VBox
} }
return root; return root;
} }
public void goToFolder(FolderPath path) public void goToFolder(FolderPath path)
{ {
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)
@ -178,10 +162,10 @@ public class NotesExplorer extends VBox
return updatedFolder; return updatedFolder;
} }
} }
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))
{ {
@ -190,45 +174,25 @@ 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())
if (this.notes.get(key).equals(note)) if (this.notes.get(key).equals(note))
note.load(this.saves, key); note.load(this.saves, key);
} }
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;
@ -236,7 +200,7 @@ public class NotesExplorer extends VBox
} }
return notes.keySet().size(); return notes.keySet().size();
} }
public void close() public void close()
{ {
this.saves.saveIndex(notes); this.saves.saveIndex(notes);

View File

@ -17,29 +17,30 @@ public class SavesManager
{ {
private static final String KEY = "Vivre et grandir à travers le commun"; private static final String KEY = "Vivre et grandir à travers le commun";
private static final File SAVE_FOLDER = new File("saves"); private static final File SAVE_FOLDER = new File("saves");
public SavesManager() public SavesManager()
{ {
if (!SAVE_FOLDER.exists()) if (!SAVE_FOLDER.exists())
SAVE_FOLDER.mkdirs(); SAVE_FOLDER.mkdirs();
} }
public void saveIndex(Map<Integer, Note> notes) public void saveIndex(Map<Integer, Note> notes)
{ {
File indexFile = new File(SAVE_FOLDER, "index"); File indexFile = new File(SAVE_FOLDER, "index");
if (indexFile.exists()) if (indexFile.exists())
indexFile.delete(); indexFile.delete();
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)
@ -70,12 +71,11 @@ public class SavesManager
else else
return new HashMap<Integer, Note>(); return new HashMap<Integer, Note>();
} }
public File getSaveFile(int id) public File getSaveFile(int id)
{ {
return new File(SAVE_FOLDER, id + ""); return new File(SAVE_FOLDER, id + "");
} }
public String readFile(File file) public String readFile(File file)
{ {
try try
@ -87,7 +87,7 @@ public class SavesManager
while ((n = fis.read(buffer)) > 0) while ((n = fis.read(buffer)) > 0)
baos.write(buffer, 0, n); baos.write(buffer, 0, n);
fis.close(); fis.close();
ByteArrayOutputStream stringBaos = new ByteArrayOutputStream(); ByteArrayOutputStream stringBaos = new ByteArrayOutputStream();
GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(this.byteFpeDecryption(baos.toByteArray(), KEY))); GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(this.byteFpeDecryption(baos.toByteArray(), KEY)));
while ((n = gzip.read(buffer)) > 0) while ((n = gzip.read(buffer)) > 0)
@ -110,7 +110,7 @@ public class SavesManager
gzip.write(content.getBytes(), 0, content.getBytes().length); gzip.write(content.getBytes(), 0, content.getBytes().length);
gzip.close(); gzip.close();
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file);
fos.write(this.byteFpeEncryption(bytes, KEY)); fos.write(this.byteFpeEncryption(bytes, KEY));
fos.flush(); fos.flush();
@ -121,41 +121,38 @@ public class SavesManager
e.printStackTrace(); e.printStackTrace();
} }
} }
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,8 +26,8 @@ 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)
{ {
System.out.println("Starting SmartNotes..."); System.out.println("Starting SmartNotes...");
@ -37,50 +35,45 @@ public class SmartNotes extends Application
launch(); launch();
System.out.println("SmartNotes closed."); System.out.println("SmartNotes closed.");
} }
public static SmartNotes instance; public static SmartNotes instance;
public static WebView webView; public static WebView webView;
private Scene scene; private Scene scene;
private VBox root; private VBox root;
private NotesExplorer explorer; private NotesExplorer explorer;
@Override @Override
public void start(Stage stage) throws Exception public void start(Stage stage) throws Exception
{ {
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);
@ -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 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.ttf"), 10);
Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Code Italic.ttf"), 10); Font.loadFont(this.getClass().getResourceAsStream("/com/madeorsk/smartnotes/res/Courier Prime Code Italic.ttf"), 10);
this.root = new VBox(); this.root = new VBox();
this.root.setStyle("-fx-background-color: #282828;"); this.root.setStyle("-fx-background-color: #282828;");
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();
} }
public void setContent(Region region) public void setContent(Region region)
{ {
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
@ -144,7 +130,7 @@ public class SmartNotes extends Application
this.root.getChildren().add(region); this.root.getChildren().add(region);
} }
} }
private void onStop() private void onStop()
{ {
try try
@ -157,7 +143,7 @@ public class SmartNotes extends Application
} }
Platform.exit(); Platform.exit();
} }
public class GlobalKeyListener implements NativeKeyListener public class GlobalKeyListener implements NativeKeyListener
{ // CTRL : 29 | ALT : 56 | n : 49 { // CTRL : 29 | ALT : 56 | n : 49
@Override @Override
@ -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,86 +42,67 @@ 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);
} }
private class TypeItem extends VBox private class TypeItem extends VBox
{ {
private boolean selected; private boolean selected;
public TypeItem(String typeIconPath) public TypeItem(String typeIconPath)
{ {
this.setId("imageButton"); this.setId("imageButton");
this.setCursor(Cursor.HAND); this.setCursor(Cursor.HAND);
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();
}
} }
}); });
} }
public void setSelected(boolean selected) public void setSelected(boolean selected)
{ {
this.selected = selected; this.selected = selected;
@ -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

@ -10,14 +10,14 @@ public class Utils
{ {
private static Parser parser = Parser.builder().build(); private static Parser parser = Parser.builder().build();
private static HtmlRenderer htmlRenderer = HtmlRenderer.builder().build(); private static HtmlRenderer htmlRenderer = HtmlRenderer.builder().build();
public static String loadText(String path) public static String loadText(String path)
{ {
try try
{ {
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();
@ -28,7 +28,7 @@ public class Utils
return null; return null;
} }
} }
public static String markdownToHtml(String markdown) public static String markdownToHtml(String markdown)
{ {
return htmlRenderer.render(parser.parse(markdown)); return htmlRenderer.render(parser.parse(markdown));

View File

@ -33,13 +33,13 @@ public class ListNote extends Note
{ {
private ListBox listBox; private ListBox listBox;
private boolean loading = false; private boolean loading = false;
public ListNote() 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.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); this.listBox = new ListBox(false);
} }
@Override @Override
public VBox getViewBox(final NotesExplorer explorer) public VBox getViewBox(final NotesExplorer explorer)
{ {
@ -48,136 +48,87 @@ public class ListNote extends Note
this.listBox.updateList(listBoxMap); this.listBox.updateList(listBoxMap);
VBox box = new VBox(); VBox box = new VBox();
box.setFillWidth(true); box.setFillWidth(true);
final Label nameField = new Label(); final Label nameField = new Label();
HBox titleBox = new HBox(); HBox titleBox = new HBox();
{ {
titleBox.setPadding(new Insets(10, 0, 0, 0)); titleBox.setPadding(new Insets(10, 0, 0, 0));
VBox returnButton = new VBox(); VBox returnButton = new VBox();
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);
VBox editButton = new VBox(); VBox editButton = new VBox();
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);
buttonsBox.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); buttonsBox.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2));
titleBox.getChildren().add(buttonsBox); titleBox.getChildren().add(buttonsBox);
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);
} }
box.getChildren().add(titleBox); box.getChildren().add(titleBox);
// NAME FIELD // NAME FIELD
{ {
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);
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);
return box; return box;
} }
@Override @Override
public VBox getEditBox(final NotesExplorer explorer) public VBox getEditBox(final NotesExplorer explorer)
{ {
@ -186,151 +137,126 @@ public class ListNote extends Note
this.listBox.updateList(listBoxMap); this.listBox.updateList(listBoxMap);
VBox box = new VBox(); VBox box = new VBox();
box.setFillWidth(true); box.setFillWidth(true);
final TextField nameField = new TextField(); final TextField nameField = new TextField();
HBox titleBox = new HBox(); HBox titleBox = new HBox();
{ {
titleBox.setPadding(new Insets(10, 0, 0, 0)); titleBox.setPadding(new Insets(10, 0, 0, 0));
VBox returnButton = new VBox(); VBox returnButton = new VBox();
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);
TypeSelector typeSelector = new TypeSelector(explorer, this); TypeSelector typeSelector = new TypeSelector(explorer, this);
typeSelector.setAlignment(Pos.CENTER); typeSelector.setAlignment(Pos.CENTER);
typeSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); typeSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2));
titleBox.getChildren().add(typeSelector); titleBox.getChildren().add(typeSelector);
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);
} }
box.getChildren().add(titleBox); box.getChildren().add(titleBox);
// NAME FIELD // NAME FIELD
{ {
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);
final TextArea textArea = new TextArea(); final TextArea textArea = new TextArea();
{ {
textArea.setId("text"); textArea.setId("text");
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);
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);
return box; return box;
} }
@Override @Override
public void save(SavesManager saves, int id) public void save(SavesManager saves, int id)
{ {
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)
{ {
if (saves.getSaveFile(id).exists()) if (saves.getSaveFile(id).exists())
{ {
this.loading = true; this.loading = true;
String saved = saves.readFile(saves.getSaveFile(id)); String saved = saves.readFile(saves.getSaveFile(id));
int separatorIndex = saved.indexOf('\n'); int separatorIndex = saved.indexOf('\n');
this.setName(saved.substring(0, separatorIndex)); this.setName(saved.substring(0, separatorIndex));
saved = saved.substring(separatorIndex + 1); saved = saved.substring(separatorIndex + 1);
separatorIndex = saved.indexOf('\n'); separatorIndex = saved.indexOf('\n');
this.setNoteColor(NoteColor.valueOf(saved.substring(0, separatorIndex))); this.setNoteColor(NoteColor.valueOf(saved.substring(0, separatorIndex)));
saved = saved.substring(separatorIndex + 1); saved = saved.substring(separatorIndex + 1);
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');
@ -339,18 +265,19 @@ public class ListNote extends Note
list.put(listItemString.substring(0, listItemSeparator), Boolean.parseBoolean(listItemString.substring(listItemSeparator + 1))); list.put(listItemString.substring(0, listItemSeparator), Boolean.parseBoolean(listItemString.substring(listItemSeparator + 1)));
} }
this.listBox.updateList(list); this.listBox.updateList(list);
if (separatorIndex < saved.length() - 1) if (separatorIndex < saved.length() - 1)
this.setTextContent(saved.substring(separatorIndex + 1)); this.setTextContent(saved.substring(separatorIndex + 1));
else else
this.setTextContent(""); this.setTextContent("");
this.loading = false; this.loading = false;
return true; return true;
} }
else else
return false; return false;
} }
@Override @Override
public void delete(SavesManager saves, int id) public void delete(SavesManager saves, int id)
{ {

View File

@ -17,58 +17,65 @@ public abstract class Note implements SavableNote
YELLOW(212, 208, 97), YELLOW(212, 208, 97),
RED(214, 102, 90), RED(214, 102, 90),
GREEN(100, 181, 106); GREEN(100, 181, 106);
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);
} }
} }
private String name; private String name;
private String textContent; private String textContent;
private NoteColor color = NoteColor.WHITE; private NoteColor color = NoteColor.WHITE;
protected List<String> paths = new ArrayList<String>(); protected List<String> paths = new ArrayList<String>();
public void setName(String name) public void setName(String name)
{ {
this.name = name; this.name = name;
} }
public String getName() public String getName()
{ {
return this.name; return this.name;
} }
public void setNoteColor(NoteColor color) public void setNoteColor(NoteColor color)
{ {
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;
} }
public void setTextContent(String content) public void setTextContent(String content)
{ {
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,19 +86,20 @@ 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);
} }
} }
} }
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

@ -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)); 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 @Override
public VBox getViewBox(final NotesExplorer explorer) public VBox getViewBox(final NotesExplorer explorer)
{ {
VBox box = new VBox(); VBox box = new VBox();
box.setFillWidth(true); box.setFillWidth(true);
final Label nameField = new Label(); final Label nameField = new Label();
HBox titleBox = new HBox(); HBox titleBox = new HBox();
{ {
titleBox.setPadding(new Insets(10, 0, 0, 0)); titleBox.setPadding(new Insets(10, 0, 0, 0));
VBox returnButton = new VBox(); VBox returnButton = new VBox();
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);
VBox editButton = new VBox(); VBox editButton = new VBox();
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);
buttonsBox.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); buttonsBox.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2));
titleBox.getChildren().add(buttonsBox); titleBox.getChildren().add(buttonsBox);
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);
} }
box.getChildren().add(titleBox); box.getChildren().add(titleBox);
// NAME FIELD // NAME FIELD
{ {
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);
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())); SmartNotes.webView.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()));
box.getChildren().add(SmartNotes.webView); box.getChildren().add(SmartNotes.webView);
return box; return box;
} }
@Override @Override
public VBox getEditBox(final NotesExplorer explorer) public VBox getEditBox(final NotesExplorer explorer)
{ {
VBox box = new VBox(); VBox box = new VBox();
box.setFillWidth(true); box.setFillWidth(true);
final TextField nameField = new TextField(); final TextField nameField = new TextField();
HBox titleBox = new HBox(); HBox titleBox = new HBox();
{ {
titleBox.setPadding(new Insets(10, 0, 0, 0)); titleBox.setPadding(new Insets(10, 0, 0, 0));
VBox returnButton = new VBox(); VBox returnButton = new VBox();
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);
TypeSelector typeSelector = new TypeSelector(explorer, this); TypeSelector typeSelector = new TypeSelector(explorer, this);
typeSelector.setAlignment(Pos.CENTER); typeSelector.setAlignment(Pos.CENTER);
typeSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2)); typeSelector.prefWidthProperty().bind(titleBox.widthProperty().subtract(returnButton.widthProperty()).divide(2));
titleBox.getChildren().add(typeSelector); titleBox.getChildren().add(typeSelector);
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);
} }
box.getChildren().add(titleBox); box.getChildren().add(titleBox);
// NAME FIELD // NAME FIELD
{ {
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);
final TextArea textArea = new TextArea(); final TextArea textArea = new TextArea();
{ {
textArea.setId("text"); textArea.setId("text");
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);
return box; return box;
} }
@Override @Override
public void save(SavesManager saves, int id) public void save(SavesManager saves, int id)
{ {
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

@ -8,53 +8,57 @@ public class FolderPath implements Path
private String name; private String name;
private FolderPath parent; private FolderPath parent;
private List<Path> content = new ArrayList<Path>(); private List<Path> content = new ArrayList<Path>();
public FolderPath(String name, FolderPath parent) public FolderPath(String name, FolderPath parent)
{ {
this.name = name; this.name = name;
this.parent = parent; this.parent = parent;
} }
public void addPath(Path path) public void addPath(Path path)
{ {
this.content.add(path); this.content.add(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;
return false; return false;
} }
public FolderPath setName(String name) public FolderPath setName(String name)
{ {
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;
} }
@Override @Override
public boolean isFolder() public boolean isFolder()
{ {

View File

@ -3,17 +3,17 @@ package com.madeorsk.smartnotes.paths;
public class NotePath implements Path public class NotePath implements Path
{ {
private int noteId; private int noteId;
public NotePath(int id) public NotePath(int id)
{ {
this.noteId = id; this.noteId = id;
} }
public int getNoteId() public int getNoteId()
{ {
return this.noteId; return this.noteId;
} }
@Override @Override
public boolean isFolder() public boolean isFolder()
{ {

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;
} }