Started TypeSelector...

This commit is contained in:
Madeorsk 2016-11-01 20:29:22 +01:00
parent 101b3f0dd9
commit bc375669d0
4 changed files with 304 additions and 38 deletions

View File

@ -0,0 +1,115 @@
package com.madeorsk.smartnotes;
import com.madeorsk.smartnotes.notes.ListNote;
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;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.util.Duration;
public class TypeSelector extends HBox
{
public TypeSelector(NotesExplorer explorer, Note note)
{
this.setSpacing(15);
TypeItem textNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/TextNoteChoice.png");
{
if (note instanceof TextNote)
textNoteItem.setSelected(true);
}
this.getChildren().add(textNoteItem);
TypeItem listNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/ListNoteChoice.png");
{
if (note instanceof ListNote)
listNoteItem.setSelected(true);
}
this.getChildren().add(listNoteItem);
TypeItem imageNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/ImageNoteChoice.png");
{
}
this.getChildren().add(imageNoteItem);
TypeItem soundNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/SoundNoteChoice.png");
{
}
this.getChildren().add(soundNoteItem);
TypeItem videoNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/VideoNoteChoice.png");
{
}
this.getChildren().add(videoNoteItem);
TypeItem positionNoteItem = new TypeItem("/com/madeorsk/smartnotes/res/PositionNoteChoice.png");
{
}
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<MouseEvent>()
{
@Override
public void handle(MouseEvent e)
{
if (!TypeItem.this.isSelected())
{
FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this);
transition.setFromValue(0.4);
transition.setToValue(1.0);
transition.play();
}
}
});
this.setOnMouseExited(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent e)
{
if (!TypeItem.this.isSelected())
{
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;
if (this.selected)
this.setOpacity(1.0);
else
{
FadeTransition transition = new FadeTransition(Duration.millis(200), TypeItem.this);
transition.setFromValue(1.0);
transition.setToValue(0.4);
transition.play();
}
}
public boolean isSelected()
{
return this.selected;
}
}
}

View File

@ -0,0 +1,147 @@
package com.madeorsk.smartnotes.notes;
import java.util.Calendar;
import com.madeorsk.smartnotes.NoteColorSelector;
import com.madeorsk.smartnotes.NotesExplorer;
import com.madeorsk.smartnotes.SavesManager;
import com.madeorsk.smartnotes.SmartNotes;
import com.madeorsk.smartnotes.TypeSelector;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
public class ListNote extends Note
{
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));
}
@Override
public VBox getNoteBox(final NotesExplorer explorer)
{
VBox box = new VBox();
box.setFillWidth(true);
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<MouseEvent>()
{
@Override
public void handle(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.setSelectedColor(this.getNoteColor());
colorSelector.selectedColorProperty().addListener(new ChangeListener<NoteColor>()
{
@Override
public void changed(ObservableValue<? extends NoteColor> 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.setText(this.getName());
nameField.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> ov, String oldValue, String newValue)
{
ListNote.this.setName(newValue);
explorer.requestSave(ListNote.this);
}
});
}
box.getChildren().add(nameField);
TextArea textArea = new TextArea();
{
textArea.setId("textArea");
textArea.setWrapText(true);
textArea.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()));
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);
}
});
}
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)
{
if (saves.getSaveFile(id).exists())
{
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)));
if (separatorIndex < saved.length() - 1)
this.setTextContent(saved.substring(separatorIndex + 1));
else
this.setTextContent("");
return true;
}
else
return false;
}
}

View File

@ -34,6 +34,7 @@ public abstract class Note implements SavableNote
}
private String name;
private String textContent;
private NoteColor color = NoteColor.WHITE;
protected List<String> paths = new ArrayList<String>();
@ -59,5 +60,34 @@ public abstract class Note implements SavableNote
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();
String text = this.getTextContent();
if (text.contains("\n"))
{
String[] lines = text.split("\n");
String lastLine = lines[lines.length - 1];
for(String word : lastLine.split(" "))
if (word.startsWith("#") && !word.equals("#"))
this.paths.add(word);
}
else
{
for(String word : text.split(" "))
if (word.startsWith("#") && !word.equals("#"))
this.paths.add(word);
}
}
public abstract VBox getNoteBox(NotesExplorer explorer);
}

View File

@ -6,6 +6,7 @@ import com.madeorsk.smartnotes.NoteColorSelector;
import com.madeorsk.smartnotes.NotesExplorer;
import com.madeorsk.smartnotes.SavesManager;
import com.madeorsk.smartnotes.SmartNotes;
import com.madeorsk.smartnotes.TypeSelector;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
@ -23,8 +24,6 @@ import javafx.scene.layout.VBox;
public class TextNote extends Note
{
private String content;
public TextNote()
{
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));
@ -57,9 +56,14 @@ public class TextNote extends Note
});
titleBox.getChildren().add(returnButton);
//TODO Type selector
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.setSelectedColor(this.getNoteColor());
colorSelector.selectedColorProperty().addListener(new ChangeListener<NoteColor>()
@ -99,13 +103,13 @@ public class TextNote extends Note
textArea.setId("textArea");
textArea.setWrapText(true);
textArea.prefHeightProperty().bind(box.heightProperty().subtract(nameField.heightProperty()).subtract(titleBox.heightProperty()));
textArea.setText(this.getContent());
textArea.setText(this.getTextContent());
textArea.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> ov, String oldValue, String newValue)
{
TextNote.this.setContent(newValue);
TextNote.this.setTextContent(newValue);
explorer.requestSave(TextNote.this);
}
});
@ -115,40 +119,10 @@ public class TextNote extends Note
return box;
}
public void setContent(String content)
{
this.content = content;
this.updatePaths();
}
public String getContent()
{
return this.content;
}
private void updatePaths()
{
this.paths.clear();
String text = this.getContent();
if (text.contains("\n"))
{
String[] lines = text.split("\n");
String lastLine = lines[lines.length - 1];
for(String word : lastLine.split(" "))
if (word.startsWith("#") && !word.equals("#"))
this.paths.add(word);
}
else
{
for(String word : text.split(" "))
if (word.startsWith("#") && !word.equals("#"))
this.paths.add(word);
}
}
@Override
public void save(SavesManager saves, int id)
{
saves.writeFile(saves.getSaveFile(id), this.getName() + "\n" + this.getNoteColor().name() + "\n" + this.getContent());
saves.writeFile(saves.getSaveFile(id), this.getName() + "\n" + this.getNoteColor().name() + "\n" + this.getTextContent());
}
@Override
public boolean load(SavesManager saves, int id)
@ -162,9 +136,9 @@ public class TextNote extends Note
separatorIndex = saved.indexOf('\n');
this.setNoteColor(NoteColor.valueOf(saved.substring(0, separatorIndex)));
if (separatorIndex < saved.length() - 1)
this.setContent(saved.substring(separatorIndex + 1));
this.setTextContent(saved.substring(separatorIndex + 1));
else
this.setContent("");
this.setTextContent("");
return true;
}
else